/[suikacvs]/markup/html/whatpm/Whatpm/CSS/Parser.pm
Suika

Contents of /markup/html/whatpm/Whatpm/CSS/Parser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.52 - (hide annotations) (download)
Sun Jan 27 07:19:05 2008 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.51: +51 -18 lines
++ whatpm/t/ChangeLog	27 Jan 2008 07:19:02 -0000
	* CSS-Parser-1.t: Files |css-text.dat| and |css-paged.dat|
	are added.

	* css-visual.dat: New test data for 'background-position' are
	added.

	* css-text.dat: New test file.

	* css-paged.dat: New test file.

2008-01-27  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/CSS/ChangeLog	27 Jan 2008 07:18:18 -0000
	* Parser.pm ($parse_color): Support for '+'.  HSL to RGB
	convertion was wrong.
	('orphans', 'background-position' parse): Support for '+'.

2008-01-27  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package Whatpm::CSS::Parser;
2     use strict;
3     use Whatpm::CSS::Tokenizer qw(:token);
4     require Whatpm::CSS::SelectorsParser;
5    
6     sub new ($) {
7 wakaba 1.40 my $self = bless {must_level => 'm',
8 wakaba 1.5 message_level => 'w',
9 wakaba 1.3 unsupported_level => 'unsupported'}, shift;
10 wakaba 1.11 # $self->{base_uri}
11 wakaba 1.18 # $self->{unitless_px} = 1/0
12 wakaba 1.28 # $self->{hashless_rgb} = 1/0
13    
14 wakaba 1.40 ## Default error handler
15     $self->{onerror} = sub {
16     my %opt = @_;
17     require Carp;
18     Carp::carp
19     (sprintf 'Document <%s>: Line %d column %d (token %s): %s%s',
20     defined $opt{uri} ? ${$opt{uri}} : 'thisdocument:/',
21     $opt{token}->{line},
22     $opt{token}->{column},
23     Whatpm::CSS::Tokenizer->serialize_token ($opt{token}),
24     $opt{type},
25     defined $opt{value} ? " (value $opt{value})" : '');
26     };
27    
28 wakaba 1.28 ## Media-dependent RGB color range clipper
29     $self->{clip_color} = sub {
30     shift; #my $self = shift;
31     my $value = shift;
32     if (defined $value and $value->[0] eq 'RGBA') {
33     my ($r, $g, $b) = @$value[1, 2, 3];
34     $r = 0 if $r < 0; $r = 255 if $r > 255;
35     $g = 0 if $g < 0; $g = 255 if $g > 255;
36     $b = 0 if $b < 0; $b = 255 if $b > 255;
37     return ['RGBA', $r, $g, $b, $value->[4]];
38     }
39     return $value;
40     };
41 wakaba 1.1
42 wakaba 1.31 ## System dependent font expander
43     $self->{get_system_font} = sub {
44     #my ($self, $normalized_system_font_name, $font_properties) = @_;
45     ## Modify $font_properties hash (except for 'font-family' property).
46     return $_[2];
47     };
48    
49 wakaba 1.1 return $self;
50     } # new
51    
52     sub BEFORE_STATEMENT_STATE () { 0 }
53     sub BEFORE_DECLARATION_STATE () { 1 }
54     sub IGNORED_STATEMENT_STATE () { 2 }
55     sub IGNORED_DECLARATION_STATE () { 3 }
56    
57 wakaba 1.5 our $Prop; ## By CSS property name
58     our $Attr; ## By CSSOM attribute name
59     our $Key; ## By internal key
60    
61 wakaba 1.1 sub parse_char_string ($$) {
62     my $self = $_[0];
63    
64     my $s = $_[1];
65     pos ($s) = 0;
66 wakaba 1.2 my $line = 1;
67     my $column = 0;
68 wakaba 1.1
69     my $tt = Whatpm::CSS::Tokenizer->new;
70 wakaba 1.38 my $onerror = $tt->{onerror} = $self->{onerror};
71 wakaba 1.37 $tt->{get_char} = sub ($) {
72 wakaba 1.1 if (pos $s < length $s) {
73 wakaba 1.2 my $c = ord substr $s, pos ($s)++, 1;
74     if ($c == 0x000A) {
75     $line++;
76     $column = 0;
77     } elsif ($c == 0x000D) {
78     unless (substr ($s, pos ($s), 1) eq "\x0A") {
79     $line++;
80     $column = 0;
81     } else {
82     $column++;
83     }
84     } else {
85     $column++;
86     }
87 wakaba 1.47 $_[0]->{line} = $line;
88     $_[0]->{column} = $column;
89 wakaba 1.2 return $c;
90 wakaba 1.1 } else {
91 wakaba 1.47 $_[0]->{column} = $column + 1; ## Set the same number always.
92 wakaba 1.1 return -1;
93     }
94     }; # $tt->{get_char}
95     $tt->init;
96    
97     my $sp = Whatpm::CSS::SelectorsParser->new;
98 wakaba 1.38 $sp->{onerror} = $self->{onerror};
99 wakaba 1.1 $sp->{must_level} = $self->{must_level};
100 wakaba 1.2 $sp->{pseudo_element} = $self->{pseudo_element};
101     $sp->{pseudo_class} = $self->{pseudo_class};
102 wakaba 1.1
103 wakaba 1.33 my $nsmap = {prefix_to_uri => {}, uri_to_prefixes => {}};
104     # $nsmap->{prefix_to_uri}->{p/""} = uri/undef
105     # $nsmap->{uri_to_prefixes}->{uri} = ["p|"/"",...]/undef
106     # $nsmap->{has_namespace} = 1/0
107 wakaba 1.4 $sp->{lookup_namespace_uri} = sub {
108 wakaba 1.33 return $nsmap->{prefix_to_uri}->{$_[0]}; # $_[0] is '' (default) or prefix
109 wakaba 1.4 }; # $sp->{lookup_namespace_uri}
110 wakaba 1.1
111     require Message::DOM::CSSStyleSheet;
112     require Message::DOM::CSSRule;
113     require Message::DOM::CSSStyleDeclaration;
114    
115 wakaba 1.11 $self->{base_uri} = $self->{href} unless defined $self->{base_uri};
116 wakaba 1.38 $sp->{href} = $self->{href};
117 wakaba 1.11
118 wakaba 1.1 my $state = BEFORE_STATEMENT_STATE;
119     my $t = $tt->get_next_token;
120    
121     my $open_rules = [[]];
122     my $current_rules = $open_rules->[-1];
123     my $current_decls;
124     my $closing_tokens = [];
125 wakaba 1.3 my $charset_allowed = 1;
126 wakaba 1.4 my $namespace_allowed = 1;
127 wakaba 1.1
128     S: {
129     if ($state == BEFORE_STATEMENT_STATE) {
130     $t = $tt->get_next_token
131     while $t->{type} == S_TOKEN or
132     $t->{type} == CDO_TOKEN or
133     $t->{type} == CDC_TOKEN;
134    
135     if ($t->{type} == ATKEYWORD_TOKEN) {
136 wakaba 1.5 if (lc $t->{value} eq 'namespace') { ## TODO: case folding
137 wakaba 1.4 $t = $tt->get_next_token;
138     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
139    
140     my $prefix;
141     if ($t->{type} == IDENT_TOKEN) {
142     $prefix = lc $t->{value};
143 wakaba 1.33 ## TODO: case (Unicode lowercase)
144 wakaba 1.4
145     $t = $tt->get_next_token;
146     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
147     }
148    
149     if ($t->{type} == STRING_TOKEN or $t->{type} == URI_TOKEN) {
150     my $uri = $t->{value};
151    
152     $t = $tt->get_next_token;
153     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
154    
155     ## ISSUE: On handling of empty namespace URI, Firefox 2 and
156     ## Opera 9 work differently (See SuikaWiki:namespace).
157     ## TODO: We need to check what we do once it is specced.
158    
159     if ($t->{type} == SEMICOLON_TOKEN) {
160     if ($namespace_allowed) {
161 wakaba 1.33 my $p = $prefix;
162     $nsmap->{has_namespace} = 1;
163     if (defined $prefix) {
164     $nsmap->{prefix_to_uri}->{$prefix} = $uri;
165     $p .= '|';
166     } else {
167     $nsmap->{prefix_to_uri}->{''} = $uri;
168     $p = '';
169     }
170     for my $u (keys %{$nsmap->{uri_to_prefixes}}) {
171     next if $u eq $uri;
172     my $list = $nsmap->{uri_to_prefixes}->{$u};
173     next unless $list;
174     for (reverse 0..$#$list) {
175     splice @$list, $_, 1, () if $list->[$_] eq $p;
176     }
177     }
178     push @{$nsmap->{uri_to_prefixes}->{$uri} ||= []}, $p;
179 wakaba 1.4 push @$current_rules,
180     Message::DOM::CSSNamespaceRule->____new ($prefix, $uri);
181     undef $charset_allowed;
182     } else {
183 wakaba 1.39 $onerror->(type => 'at-rule not allowed:namespace',
184 wakaba 1.4 level => $self->{must_level},
185 wakaba 1.38 uri => \$self->{href},
186 wakaba 1.4 token => $t);
187     }
188    
189     $t = $tt->get_next_token;
190     ## Stay in the state.
191     redo S;
192     } else {
193     #
194     }
195     } else {
196     #
197     }
198    
199 wakaba 1.39 $onerror->(type => 'at-rule syntax error:namespace',
200 wakaba 1.4 level => $self->{must_level},
201 wakaba 1.38 uri => \$self->{href},
202 wakaba 1.4 token => $t);
203     #
204 wakaba 1.5 } elsif (lc $t->{value} eq 'charset') { ## TODO: case folding
205 wakaba 1.3 $t = $tt->get_next_token;
206     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
207    
208     if ($t->{type} == STRING_TOKEN) {
209     my $encoding = $t->{value};
210    
211     $t = $tt->get_next_token;
212     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
213    
214     if ($t->{type} == SEMICOLON_TOKEN) {
215     if ($charset_allowed) {
216     push @$current_rules,
217     Message::DOM::CSSCharsetRule->____new ($encoding);
218     undef $charset_allowed;
219     } else {
220 wakaba 1.39 $onerror->(type => 'at-rule not allowed:charset',
221 wakaba 1.3 level => $self->{must_level},
222 wakaba 1.38 uri => \$self->{href},
223 wakaba 1.3 token => $t);
224     }
225    
226     ## TODO: Detect the conformance errors for @charset...
227    
228     $t = $tt->get_next_token;
229     ## Stay in the state.
230     redo S;
231     } else {
232     #
233     }
234     } else {
235     #
236     }
237    
238 wakaba 1.39 $onerror->(type => 'at-rule syntax error:charset',
239 wakaba 1.3 level => $self->{must_level},
240 wakaba 1.38 uri => \$self->{href},
241 wakaba 1.3 token => $t);
242 wakaba 1.4 #
243 wakaba 1.3 ## NOTE: When adding support for new at-rule, insert code
244 wakaba 1.4 ## "undef $charset_allowed" and "undef $namespace_token" as
245     ## appropriate.
246 wakaba 1.3 } else {
247 wakaba 1.39 $onerror->(type => 'at-rule not supported',
248 wakaba 1.3 level => $self->{unsupported_level},
249 wakaba 1.38 uri => \$self->{href},
250 wakaba 1.39 token => $t,
251     value => $t->{value});
252 wakaba 1.3 }
253 wakaba 1.1
254     $t = $tt->get_next_token;
255     $state = IGNORED_STATEMENT_STATE;
256     redo S;
257     } elsif (@$open_rules > 1 and $t->{type} == RBRACE_TOKEN) {
258     pop @$open_rules;
259     ## Stay in the state.
260     $t = $tt->get_next_token;
261     redo S;
262     } elsif ($t->{type} == EOF_TOKEN) {
263     if (@$open_rules > 1) {
264 wakaba 1.39 $onerror->(type => 'block not closed',
265 wakaba 1.2 level => $self->{must_level},
266 wakaba 1.38 uri => \$self->{href},
267 wakaba 1.2 token => $t);
268 wakaba 1.1 }
269    
270     last S;
271     } else {
272 wakaba 1.3 undef $charset_allowed;
273 wakaba 1.4 undef $namespace_allowed;
274 wakaba 1.3
275 wakaba 1.1 ($t, my $selectors) = $sp->_parse_selectors_with_tokenizer
276     ($tt, LBRACE_TOKEN, $t);
277    
278     $t = $tt->get_next_token
279     while $t->{type} != LBRACE_TOKEN and $t->{type} != EOF_TOKEN;
280    
281     if ($t->{type} == LBRACE_TOKEN) {
282     $current_decls = Message::DOM::CSSStyleDeclaration->____new;
283     my $rs = Message::DOM::CSSStyleRule->____new
284     ($selectors, $current_decls);
285     push @{$current_rules}, $rs if defined $selectors;
286    
287     $state = BEFORE_DECLARATION_STATE;
288     $t = $tt->get_next_token;
289     redo S;
290     } else {
291 wakaba 1.39 $onerror->(type => 'no declaration block',
292 wakaba 1.2 level => $self->{must_level},
293 wakaba 1.38 uri => \$self->{href},
294 wakaba 1.2 token => $t);
295 wakaba 1.1
296     ## Stay in the state.
297     $t = $tt->get_next_token;
298     redo S;
299     }
300     }
301     } elsif ($state == BEFORE_DECLARATION_STATE) {
302     ## NOTE: DELIM? in declaration will be removed:
303     ## <http://csswg.inkedblade.net/spec/css2.1?s=declaration%20delim#issue-2>.
304    
305 wakaba 1.5 my $prop_def;
306     my $prop_value;
307 wakaba 1.35 my $prop_flag = '';
308 wakaba 1.1 $t = $tt->get_next_token while $t->{type} == S_TOKEN;
309     if ($t->{type} == IDENT_TOKEN) { # property
310 wakaba 1.5 my $prop_name = lc $t->{value}; ## TODO: case folding
311     $t = $tt->get_next_token;
312 wakaba 1.29 $t = $tt->get_next_token while $t->{type} == S_TOKEN;
313 wakaba 1.5 if ($t->{type} == COLON_TOKEN) {
314     $t = $tt->get_next_token;
315     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
316    
317     $prop_def = $Prop->{$prop_name};
318 wakaba 1.6 if ($prop_def and $self->{prop}->{$prop_name}) {
319 wakaba 1.5 ($t, $prop_value)
320     = $prop_def->{parse}->($self, $prop_name, $tt, $t, $onerror);
321     if ($prop_value) {
322     ## NOTE: {parse} don't have to consume trailing spaces.
323     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
324    
325     if ($t->{type} == EXCLAMATION_TOKEN) {
326     $t = $tt->get_next_token;
327     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
328     if ($t->{type} == IDENT_TOKEN and
329     lc $t->{value} eq 'important') { ## TODO: case folding
330     $prop_flag = 'important';
331    
332     $t = $tt->get_next_token;
333     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
334    
335     #
336     } else {
337 wakaba 1.39 $onerror->(type => 'priority syntax error',
338 wakaba 1.5 level => $self->{must_level},
339 wakaba 1.38 uri => \$self->{href},
340 wakaba 1.5 token => $t);
341    
342     ## Reprocess.
343     $state = IGNORED_DECLARATION_STATE;
344     redo S;
345     }
346     }
347    
348     #
349     } else {
350     ## Syntax error.
351    
352     ## Reprocess.
353     $state = IGNORED_DECLARATION_STATE;
354     redo S;
355     }
356     } else {
357 wakaba 1.39 $onerror->(type => 'property not supported',
358 wakaba 1.5 level => $self->{unsupported_level},
359 wakaba 1.38 token => $t, value => $prop_name,
360     uri => \$self->{href});
361 wakaba 1.5
362     #
363     $state = IGNORED_DECLARATION_STATE;
364     redo S;
365     }
366     } else {
367 wakaba 1.39 $onerror->(type => 'no property colon',
368 wakaba 1.5 level => $self->{must_level},
369 wakaba 1.38 uri => \$self->{href},
370 wakaba 1.5 token => $t);
371 wakaba 1.1
372 wakaba 1.5 #
373     $state = IGNORED_DECLARATION_STATE;
374     redo S;
375     }
376     }
377    
378     if ($t->{type} == RBRACE_TOKEN) {
379 wakaba 1.1 $t = $tt->get_next_token;
380 wakaba 1.5 $state = BEFORE_STATEMENT_STATE;
381     #redo S;
382     } elsif ($t->{type} == SEMICOLON_TOKEN) {
383 wakaba 1.1 $t = $tt->get_next_token;
384 wakaba 1.5 ## Stay in the state.
385     #redo S;
386 wakaba 1.1 } elsif ($t->{type} == EOF_TOKEN) {
387 wakaba 1.39 $onerror->(type => 'block not closed',
388 wakaba 1.2 level => $self->{must_level},
389 wakaba 1.38 uri => \$self->{href},
390 wakaba 1.2 token => $t);
391 wakaba 1.1 ## Reprocess.
392     $state = BEFORE_STATEMENT_STATE;
393 wakaba 1.5 #redo S;
394     } else {
395     if ($prop_value) {
396 wakaba 1.39 $onerror->(type => 'no property semicolon',
397 wakaba 1.5 level => $self->{must_level},
398 wakaba 1.38 uri => \$self->{href},
399 wakaba 1.5 token => $t);
400     } else {
401 wakaba 1.39 $onerror->(type => 'no property name',
402 wakaba 1.5 level => $self->{must_level},
403 wakaba 1.38 uri => \$self->{href},
404 wakaba 1.5 token => $t);
405     }
406    
407     #
408     $state = IGNORED_DECLARATION_STATE;
409 wakaba 1.1 redo S;
410     }
411    
412 wakaba 1.35 my $important = ($prop_flag eq 'important');
413 wakaba 1.7 for my $set_prop_name (keys %{$prop_value or {}}) {
414     my $set_prop_def = $Prop->{$set_prop_name};
415     $$current_decls->{$set_prop_def->{key}}
416     = [$prop_value->{$set_prop_name}, $prop_flag]
417     if $important or
418     not $$current_decls->{$set_prop_def->{key}} or
419 wakaba 1.42 $$current_decls->{$set_prop_def->{key}}->[1] ne 'important';
420 wakaba 1.5 }
421 wakaba 1.1 redo S;
422     } elsif ($state == IGNORED_STATEMENT_STATE or
423     $state == IGNORED_DECLARATION_STATE) {
424     if (@$closing_tokens) { ## Something is yet in opening state.
425     if ($t->{type} == EOF_TOKEN) {
426     @$closing_tokens = ();
427     ## Reprocess.
428     $state = $state == IGNORED_STATEMENT_STATE
429     ? BEFORE_STATEMENT_STATE : BEFORE_DECLARATION_STATE;
430     redo S;
431     } elsif ($t->{type} == $closing_tokens->[-1]) {
432     pop @$closing_tokens;
433     if (@$closing_tokens == 0 and
434     $t->{type} == RBRACE_TOKEN and
435     $state == IGNORED_STATEMENT_STATE) {
436     $t = $tt->get_next_token;
437     $state = BEFORE_STATEMENT_STATE;
438     redo S;
439     } else {
440     $t = $tt->get_next_token;
441     ## Stay in the state.
442     redo S;
443     }
444 wakaba 1.28 } elsif ({
445     RBRACE_TOKEN, 1,
446     #RBRACKET_TOKEN, 1,
447     #RPAREN_TOKEN, 1,
448     SEMICOLON_TOKEN, 1,
449     }->{$t->{type}}) {
450     $t = $tt->get_next_token;
451     ## Stay in the state.
452     #
453 wakaba 1.1 } else {
454     #
455     }
456     } else {
457     if ($t->{type} == SEMICOLON_TOKEN) {
458     $t = $tt->get_next_token;
459     $state = $state == IGNORED_STATEMENT_STATE
460     ? BEFORE_STATEMENT_STATE : BEFORE_DECLARATION_STATE;
461     redo S;
462 wakaba 1.28 } elsif ($t->{type} == RBRACE_TOKEN) {
463     if ($state == IGNORED_DECLARATION_STATE) {
464     $t = $tt->get_next_token;
465     $state = BEFORE_STATEMENT_STATE;
466     redo S;
467     } else {
468     ## NOTE: Maybe this state cannot be reached.
469     $t = $tt->get_next_token;
470     ## Stay in the state.
471     redo S;
472     }
473 wakaba 1.1 } elsif ($t->{type} == EOF_TOKEN) {
474     ## Reprocess.
475     $state = $state == IGNORED_STATEMENT_STATE
476     ? BEFORE_STATEMENT_STATE : BEFORE_DECLARATION_STATE;
477     redo S;
478 wakaba 1.28 #} elsif ($t->{type} == RBRACKET_TOKEN or $t->{type} == RPAREN_TOKEN) {
479     # $t = $tt->get_next_token;
480     # ## Stay in the state.
481     # #
482 wakaba 1.1 } else {
483     #
484     }
485     }
486    
487     while (not {
488     EOF_TOKEN, 1,
489     RBRACE_TOKEN, 1,
490 wakaba 1.28 ## NOTE: ']' and ')' are disabled for browser compatibility.
491     #RBRACKET_TOKEN, 1,
492     #RPAREN_TOKEN, 1,
493 wakaba 1.1 SEMICOLON_TOKEN, 1,
494     }->{$t->{type}}) {
495     if ($t->{type} == LBRACE_TOKEN) {
496     push @$closing_tokens, RBRACE_TOKEN;
497 wakaba 1.28 #} elsif ($t->{type} == LBRACKET_TOKEN) {
498     # push @$closing_tokens, RBRACKET_TOKEN;
499     #} elsif ($t->{type} == LPAREN_TOKEN or $t->{type} == FUNCTION_TOKEN) {
500     # push @$closing_tokens, RPAREN_TOKEN;
501 wakaba 1.1 }
502    
503     $t = $tt->get_next_token;
504     }
505    
506     #
507     ## Stay in the state.
508     redo S;
509     } else {
510     die "$0: parse_char_string: Unknown state: $state";
511     }
512     } # S
513    
514     my $ss = Message::DOM::CSSStyleSheet->____new
515 wakaba 1.11 (manakai_base_uri => $self->{base_uri},
516     css_rules => $open_rules->[0],
517 wakaba 1.1 ## TODO: href
518     ## TODO: owner_node
519     ## TODO: media
520     type => 'text/css', ## TODO: OK?
521 wakaba 1.33 _parser => $self, _nsmap => $nsmap);
522 wakaba 1.1 return $ss;
523     } # parse_char_string
524    
525 wakaba 1.9 my $compute_as_specified = sub ($$$$) {
526     #my ($self, $element, $prop_name, $specified_value) = @_;
527     return $_[3];
528     }; # $compute_as_specified
529    
530 wakaba 1.11 my $default_serializer = sub {
531     my ($self, $prop_name, $value) = @_;
532 wakaba 1.15 if ($value->[0] eq 'NUMBER' or $value->[0] eq 'WEIGHT') {
533     ## TODO: What we currently do for 'font-weight' is different from
534     ## any browser for lighter/bolder cases. We need to fix this, but
535     ## how?
536 wakaba 1.11 return $value->[1]; ## TODO: big or small number cases?
537 wakaba 1.18 } elsif ($value->[0] eq 'DIMENSION') {
538     return $value->[1] . $value->[2]; ## NOTE: This is what browsers do.
539 wakaba 1.22 } elsif ($value->[0] eq 'PERCENTAGE') {
540     return $value->[1] . '%';
541 wakaba 1.11 } elsif ($value->[0] eq 'KEYWORD') {
542     return $value->[1];
543     } elsif ($value->[0] eq 'URI') {
544     ## NOTE: This is what browsers do.
545     return 'url('.$value->[1].')';
546 wakaba 1.28 } elsif ($value->[0] eq 'RGBA') {
547     if ($value->[4] == 1) {
548     return 'rgb('.$value->[1].', '.$value->[2].', '.$value->[3].')';
549     } elsif ($value->[4] == 0) {
550     ## TODO: check what browsers do...
551     return 'transparent';
552     } else {
553     return 'rgba('.$value->[1].', '.$value->[2].', '.$value->[3].', '
554     .$value->[4].')';
555     }
556 wakaba 1.11 } elsif ($value->[0] eq 'INHERIT') {
557     return 'inherit';
558 wakaba 1.16 } elsif ($value->[0] eq 'DECORATION') {
559     my @v = ();
560     push @v, 'underline' if $value->[1];
561     push @v, 'overline' if $value->[2];
562     push @v, 'line-through' if $value->[3];
563     push @v, 'blink' if $value->[4];
564     return 'none' unless @v;
565     return join ' ', @v;
566 wakaba 1.11 } else {
567 wakaba 1.34 return '';
568 wakaba 1.11 }
569     }; # $default_serializer
570    
571 wakaba 1.28 my $x11_colors = {
572     'aliceblue' => [0xf0, 0xf8, 0xff],
573     'antiquewhite' => [0xfa, 0xeb, 0xd7],
574     'aqua' => [0x00, 0xff, 0xff],
575     'aquamarine' => [0x7f, 0xff, 0xd4],
576     'azure' => [0xf0, 0xff, 0xff],
577     'beige' => [0xf5, 0xf5, 0xdc],
578     'bisque' => [0xff, 0xe4, 0xc4],
579     'black' => [0x00, 0x00, 0x00],
580     'blanchedalmond' => [0xff, 0xeb, 0xcd],
581     'blue' => [0x00, 0x00, 0xff],
582     'blueviolet' => [0x8a, 0x2b, 0xe2],
583     'brown' => [0xa5, 0x2a, 0x2a],
584     'burlywood' => [0xde, 0xb8, 0x87],
585     'cadetblue' => [0x5f, 0x9e, 0xa0],
586     'chartreuse' => [0x7f, 0xff, 0x00],
587     'chocolate' => [0xd2, 0x69, 0x1e],
588     'coral' => [0xff, 0x7f, 0x50],
589     'cornflowerblue' => [0x64, 0x95, 0xed],
590     'cornsilk' => [0xff, 0xf8, 0xdc],
591     'crimson' => [0xdc, 0x14, 0x3c],
592     'cyan' => [0x00, 0xff, 0xff],
593     'darkblue' => [0x00, 0x00, 0x8b],
594     'darkcyan' => [0x00, 0x8b, 0x8b],
595     'darkgoldenrod' => [0xb8, 0x86, 0x0b],
596     'darkgray' => [0xa9, 0xa9, 0xa9],
597     'darkgreen' => [0x00, 0x64, 0x00],
598     'darkgrey' => [0xa9, 0xa9, 0xa9],
599     'darkkhaki' => [0xbd, 0xb7, 0x6b],
600     'darkmagenta' => [0x8b, 0x00, 0x8b],
601     'darkolivegreen' => [0x55, 0x6b, 0x2f],
602     'darkorange' => [0xff, 0x8c, 0x00],
603     'darkorchid' => [0x99, 0x32, 0xcc],
604     'darkred' => [0x8b, 0x00, 0x00],
605     'darksalmon' => [0xe9, 0x96, 0x7a],
606     'darkseagreen' => [0x8f, 0xbc, 0x8f],
607     'darkslateblue' => [0x48, 0x3d, 0x8b],
608     'darkslategray' => [0x2f, 0x4f, 0x4f],
609     'darkslategrey' => [0x2f, 0x4f, 0x4f],
610     'darkturquoise' => [0x00, 0xce, 0xd1],
611     'darkviolet' => [0x94, 0x00, 0xd3],
612     'deeppink' => [0xff, 0x14, 0x93],
613     'deepskyblue' => [0x00, 0xbf, 0xff],
614     'dimgray' => [0x69, 0x69, 0x69],
615     'dimgrey' => [0x69, 0x69, 0x69],
616     'dodgerblue' => [0x1e, 0x90, 0xff],
617     'firebrick' => [0xb2, 0x22, 0x22],
618     'floralwhite' => [0xff, 0xfa, 0xf0],
619     'forestgreen' => [0x22, 0x8b, 0x22],
620     'fuchsia' => [0xff, 0x00, 0xff],
621     'gainsboro' => [0xdc, 0xdc, 0xdc],
622     'ghostwhite' => [0xf8, 0xf8, 0xff],
623     'gold' => [0xff, 0xd7, 0x00],
624     'goldenrod' => [0xda, 0xa5, 0x20],
625     'gray' => [0x80, 0x80, 0x80],
626     'green' => [0x00, 0x80, 0x00],
627     'greenyellow' => [0xad, 0xff, 0x2f],
628     'grey' => [0x80, 0x80, 0x80],
629     'honeydew' => [0xf0, 0xff, 0xf0],
630     'hotpink' => [0xff, 0x69, 0xb4],
631     'indianred' => [0xcd, 0x5c, 0x5c],
632     'indigo' => [0x4b, 0x00, 0x82],
633     'ivory' => [0xff, 0xff, 0xf0],
634     'khaki' => [0xf0, 0xe6, 0x8c],
635     'lavender' => [0xe6, 0xe6, 0xfa],
636     'lavenderblush' => [0xff, 0xf0, 0xf5],
637     'lawngreen' => [0x7c, 0xfc, 0x00],
638     'lemonchiffon' => [0xff, 0xfa, 0xcd],
639     'lightblue' => [0xad, 0xd8, 0xe6],
640     'lightcoral' => [0xf0, 0x80, 0x80],
641     'lightcyan' => [0xe0, 0xff, 0xff],
642     'lightgoldenrodyellow' => [0xfa, 0xfa, 0xd2],
643     'lightgray' => [0xd3, 0xd3, 0xd3],
644     'lightgreen' => [0x90, 0xee, 0x90],
645     'lightgrey' => [0xd3, 0xd3, 0xd3],
646     'lightpink' => [0xff, 0xb6, 0xc1],
647     'lightsalmon' => [0xff, 0xa0, 0x7a],
648     'lightseagreen' => [0x20, 0xb2, 0xaa],
649     'lightskyblue' => [0x87, 0xce, 0xfa],
650     'lightslategray' => [0x77, 0x88, 0x99],
651     'lightslategrey' => [0x77, 0x88, 0x99],
652     'lightsteelblue' => [0xb0, 0xc4, 0xde],
653     'lightyellow' => [0xff, 0xff, 0xe0],
654     'lime' => [0x00, 0xff, 0x00],
655     'limegreen' => [0x32, 0xcd, 0x32],
656     'linen' => [0xfa, 0xf0, 0xe6],
657     'magenta' => [0xff, 0x00, 0xff],
658     'maroon' => [0x80, 0x00, 0x00],
659     'mediumaquamarine' => [0x66, 0xcd, 0xaa],
660     'mediumblue' => [0x00, 0x00, 0xcd],
661     'mediumorchid' => [0xba, 0x55, 0xd3],
662     'mediumpurple' => [0x93, 0x70, 0xdb],
663     'mediumseagreen' => [0x3c, 0xb3, 0x71],
664     'mediumslateblue' => [0x7b, 0x68, 0xee],
665     'mediumspringgreen' => [0x00, 0xfa, 0x9a],
666     'mediumturquoise' => [0x48, 0xd1, 0xcc],
667     'mediumvioletred' => [0xc7, 0x15, 0x85],
668     'midnightblue' => [0x19, 0x19, 0x70],
669     'mintcream' => [0xf5, 0xff, 0xfa],
670     'mistyrose' => [0xff, 0xe4, 0xe1],
671     'moccasin' => [0xff, 0xe4, 0xb5],
672     'navajowhite' => [0xff, 0xde, 0xad],
673     'navy' => [0x00, 0x00, 0x80],
674     'oldlace' => [0xfd, 0xf5, 0xe6],
675     'olive' => [0x80, 0x80, 0x00],
676     'olivedrab' => [0x6b, 0x8e, 0x23],
677     'orange' => [0xff, 0xa5, 0x00],
678     'orangered' => [0xff, 0x45, 0x00],
679     'orchid' => [0xda, 0x70, 0xd6],
680     'palegoldenrod' => [0xee, 0xe8, 0xaa],
681     'palegreen' => [0x98, 0xfb, 0x98],
682     'paleturquoise' => [0xaf, 0xee, 0xee],
683     'palevioletred' => [0xdb, 0x70, 0x93],
684     'papayawhip' => [0xff, 0xef, 0xd5],
685     'peachpuff' => [0xff, 0xda, 0xb9],
686     'peru' => [0xcd, 0x85, 0x3f],
687     'pink' => [0xff, 0xc0, 0xcb],
688     'plum' => [0xdd, 0xa0, 0xdd],
689     'powderblue' => [0xb0, 0xe0, 0xe6],
690     'purple' => [0x80, 0x00, 0x80],
691     'red' => [0xff, 0x00, 0x00],
692     'rosybrown' => [0xbc, 0x8f, 0x8f],
693     'royalblue' => [0x41, 0x69, 0xe1],
694     'saddlebrown' => [0x8b, 0x45, 0x13],
695     'salmon' => [0xfa, 0x80, 0x72],
696     'sandybrown' => [0xf4, 0xa4, 0x60],
697     'seagreen' => [0x2e, 0x8b, 0x57],
698     'seashell' => [0xff, 0xf5, 0xee],
699     'sienna' => [0xa0, 0x52, 0x2d],
700     'silver' => [0xc0, 0xc0, 0xc0],
701     'skyblue' => [0x87, 0xce, 0xeb],
702     'slateblue' => [0x6a, 0x5a, 0xcd],
703     'slategray' => [0x70, 0x80, 0x90],
704     'slategrey' => [0x70, 0x80, 0x90],
705     'snow' => [0xff, 0xfa, 0xfa],
706     'springgreen' => [0x00, 0xff, 0x7f],
707     'steelblue' => [0x46, 0x82, 0xb4],
708     'tan' => [0xd2, 0xb4, 0x8c],
709     'teal' => [0x00, 0x80, 0x80],
710     'thistle' => [0xd8, 0xbf, 0xd8],
711     'tomato' => [0xff, 0x63, 0x47],
712     'turquoise' => [0x40, 0xe0, 0xd0],
713     'violet' => [0xee, 0x82, 0xee],
714     'wheat' => [0xf5, 0xde, 0xb3],
715     'white' => [0xff, 0xff, 0xff],
716     'whitesmoke' => [0xf5, 0xf5, 0xf5],
717     'yellow' => [0xff, 0xff, 0x00],
718     'yellowgreen' => [0x9a, 0xcd, 0x32],
719     }; # $x11_colors
720    
721     my $system_colors = {
722     activeborder => 1, activecaption => 1, appworkspace => 1, background => 1,
723     buttonface => 1, buttonhighlight => 1, buttonshadow => 1, buttontext => 1,
724     captiontext => 1, graytext => 1, highlight => 1, highlighttext => 1,
725     inactiveborder => 1, inactivecaption => 1, inactivecaptiontext => 1,
726     infobackground => 1, infotext => 1, menu => 1, menutext => 1,
727     scrollbar => 1, threeddarkshadow => 1, threedface => 1, threedhighlight => 1,
728     threedlightshadow => 1, threedshadow => 1, window => 1, windowframe => 1,
729     windowtext => 1,
730     }; # $system_colors
731    
732     my $parse_color = sub {
733     my ($self, $prop_name, $tt, $t, $onerror) = @_;
734    
735     ## See
736     ## <http://suika.fam.cx/gate/2005/sw/%3Ccolor%3E>,
737     ## <http://suika.fam.cx/gate/2005/sw/rgb>,
738     ## <http://suika.fam.cx/gate/2005/sw/-moz-rgba>,
739     ## <http://suika.fam.cx/gate/2005/sw/hsl>,
740     ## <http://suika.fam.cx/gate/2005/sw/-moz-hsla>, and
741     ## <http://suika.fam.cx/gate/2005/sw/color>
742     ## for browser compatibility issue.
743    
744     ## NOTE: Implementing CSS3 Color CR (2003), except for attr(),
745     ## rgba(), and hsla().
746     ## NOTE: rgb(...{EOF} is not supported (only Opera does).
747    
748     if ($t->{type} == IDENT_TOKEN) {
749     my $value = lc $t->{value}; ## TODO: case
750     if ($x11_colors->{$value} or
751     $system_colors->{$value}) {
752 wakaba 1.31 ## NOTE: "For systems that do not have a corresponding value, the
753     ## specified value should be mapped to the nearest system value, or to
754     ## a default color." [CSS 2.1].
755 wakaba 1.28 $t = $tt->get_next_token;
756     return ($t, {$prop_name => ['KEYWORD', $value]});
757     } elsif ({
758     transparent => 1, ## For 'background-color' in CSS2.1, everywhre in CSS3.
759     flavor => 1, ## CSS3.
760     invert => 1, ## For 'outline-color' in CSS2.1.
761     '-moz-use-text-color' => 1, ## For <border-color> in Gecko.
762     '-manakai-default' => 1, ## CSS2.1 initial for 'color'
763     '-manakai-invert-or-currentcolor' => 1, ## CSS2.1 initial4'outline-color'
764     }->{$value} and $self->{prop_value}->{$prop_name}->{$value}) {
765     $t = $tt->get_next_token;
766     return ($t, {$prop_name => ['KEYWORD', $value]});
767     } elsif ($value eq 'currentcolor' or $value eq '-moz-use-text-color') {
768     $t = $tt->get_next_token;
769     if ($prop_name eq 'color') {
770     return ($t, {$prop_name => ['INHERIT']});
771     } else {
772     return ($t, {$prop_name => ['KEYWORD', $value]});
773     }
774     } elsif ($value eq 'inherit') {
775     $t = $tt->get_next_token;
776     return ($t, {$prop_name => ['INHERIT']});
777     }
778     }
779    
780     if ($t->{type} == HASH_TOKEN or
781 wakaba 1.29 ($self->{hashless_rgb} and {
782     IDENT_TOKEN, 1,
783     NUMBER_TOKEN, 1,
784     DIMENSION_TOKEN, 1,
785     }->{$t->{type}})) {
786     my $v = lc (defined $t->{number} ? $t->{number} : '' . $t->{value}); ## TODO: case
787 wakaba 1.28 if ($v =~ /\A([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})\z/) {
788     $t = $tt->get_next_token;
789     return ($t, {$prop_name => ['RGBA', hex $1, hex $2, hex $3, 1]});
790     } elsif ($v =~ /\A([0-9a-f])([0-9a-f])([0-9a-f])\z/) {
791     $t = $tt->get_next_token;
792     return ($t, {$prop_name => ['RGBA', hex $1.$1, hex $2.$2,
793     hex $3.$3, 1]});
794     }
795     }
796    
797     if ($t->{type} == FUNCTION_TOKEN) {
798     my $func = lc $t->{value}; ## TODO: case
799     if ($func eq 'rgb') {
800     $t = $tt->get_next_token;
801     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
802     my $sign = 1;
803     if ($t->{type} == MINUS_TOKEN) {
804     $sign = -1;
805     $t = $tt->get_next_token;
806 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
807     $t = $tt->get_next_token;
808 wakaba 1.28 }
809     if ($t->{type} == NUMBER_TOKEN) {
810     my $r = $t->{number} * $sign;
811     $t = $tt->get_next_token;
812     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
813     if ($t->{type} == COMMA_TOKEN) {
814     $t = $tt->get_next_token;
815     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
816     $sign = 1;
817     if ($t->{type} == MINUS_TOKEN) {
818     $sign = -1;
819     $t = $tt->get_next_token;
820 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
821     $t = $tt->get_next_token;
822     }
823 wakaba 1.28 if ($t->{type} == NUMBER_TOKEN) {
824     my $g = $t->{number} * $sign;
825     $t = $tt->get_next_token;
826     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
827     if ($t->{type} == COMMA_TOKEN) {
828     $t = $tt->get_next_token;
829     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
830     $sign = 1;
831     if ($t->{type} == MINUS_TOKEN) {
832     $sign = -1;
833     $t = $tt->get_next_token;
834 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
835     $t = $tt->get_next_token;
836     }
837 wakaba 1.28 if ($t->{type} == NUMBER_TOKEN) {
838     my $b = $t->{number} * $sign;
839     $t = $tt->get_next_token;
840     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
841     if ($t->{type} == RPAREN_TOKEN) {
842     $t = $tt->get_next_token;
843     return ($t,
844     {$prop_name =>
845     $self->{clip_color}->($self,
846     ['RGBA', $r, $g, $b, 1])});
847     }
848     }
849     }
850     }
851     }
852     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
853     my $r = $t->{number} * 255 / 100 * $sign;
854     $t = $tt->get_next_token;
855     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
856     if ($t->{type} == COMMA_TOKEN) {
857     $t = $tt->get_next_token;
858     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
859     $sign = 1;
860     if ($t->{type} == MINUS_TOKEN) {
861     $sign = -1;
862     $t = $tt->get_next_token;
863 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
864     $t = $tt->get_next_token;
865     }
866 wakaba 1.28 if ($t->{type} == PERCENTAGE_TOKEN) {
867     my $g = $t->{number} * 255 / 100 * $sign;
868     $t = $tt->get_next_token;
869     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
870     if ($t->{type} == COMMA_TOKEN) {
871     $t = $tt->get_next_token;
872     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
873     $sign = 1;
874     if ($t->{type} == MINUS_TOKEN) {
875     $sign = -1;
876     $t = $tt->get_next_token;
877 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
878     $t = $tt->get_next_token;
879     }
880 wakaba 1.28 if ($t->{type} == PERCENTAGE_TOKEN) {
881     my $b = $t->{number} * 255 / 100 * $sign;
882     $t = $tt->get_next_token;
883     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
884     if ($t->{type} == RPAREN_TOKEN) {
885     $t = $tt->get_next_token;
886     return ($t,
887     {$prop_name =>
888     $self->{clip_color}->($self,
889     ['RGBA', $r, $g, $b, 1])});
890     }
891     }
892     }
893     }
894     }
895     }
896     } elsif ($func eq 'hsl') {
897     $t = $tt->get_next_token;
898     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
899     my $sign = 1;
900     if ($t->{type} == MINUS_TOKEN) {
901     $sign = -1;
902     $t = $tt->get_next_token;
903 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
904     $t = $tt->get_next_token;
905 wakaba 1.28 }
906     if ($t->{type} == NUMBER_TOKEN) {
907     my $h = (((($t->{number} * $sign) % 360) + 360) % 360) / 360;
908     $t = $tt->get_next_token;
909     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
910     if ($t->{type} == COMMA_TOKEN) {
911     $t = $tt->get_next_token;
912     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
913     $sign = 1;
914     if ($t->{type} == MINUS_TOKEN) {
915     $sign = -1;
916     $t = $tt->get_next_token;
917 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
918     $t = $tt->get_next_token;
919     }
920 wakaba 1.28 if ($t->{type} == PERCENTAGE_TOKEN) {
921     my $s = $t->{number} * $sign / 100;
922     $s = 0 if $s < 0;
923     $s = 1 if $s > 1;
924     $t = $tt->get_next_token;
925     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
926     if ($t->{type} == COMMA_TOKEN) {
927     $t = $tt->get_next_token;
928     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
929     $sign = 1;
930     if ($t->{type} == MINUS_TOKEN) {
931     $sign = -1;
932     $t = $tt->get_next_token;
933 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
934     $t = $tt->get_next_token;
935     }
936 wakaba 1.28 if ($t->{type} == PERCENTAGE_TOKEN) {
937     my $l = $t->{number} * $sign / 100;
938     $l = 0 if $l < 0;
939     $l = 1 if $l > 1;
940     $t = $tt->get_next_token;
941     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
942     if ($t->{type} == RPAREN_TOKEN) {
943     my $m2 = $l <= 0.5 ? $l * ($s + 1) : $l + $s - $l * $s;
944     my $m1 = $l * 2 - $m2;
945     my $hue2rgb = sub ($$$) {
946     my ($m1, $m2, $h) = @_;
947     $h++ if $h < 0;
948     $h-- if $h > 1;
949     return $m1 + ($m2 - $m1) * $h * 6 if $h * 6 < 1;
950     return $m2 if $h * 2 < 1;
951     return $m1 + ($m2 - $m1) * (2/3 - $h) * 6 if $h * 3 < 2;
952     return $m1;
953     };
954     $t = $tt->get_next_token;
955     return ($t,
956     {$prop_name =>
957     $self->{clip_color}
958     ->($self,
959     ['RGBA',
960 wakaba 1.52 $hue2rgb->($m1, $m2, $h + 1/3) * 255,
961     $hue2rgb->($m1, $m2, $h) * 255,
962     $hue2rgb->($m1, $m2, $h - 1/3) * 255, 1])});
963 wakaba 1.28 }
964     }
965     }
966     }
967     }
968     }
969     }
970     }
971    
972 wakaba 1.39 $onerror->(type => 'syntax error:color',
973 wakaba 1.28 level => $self->{must_level},
974 wakaba 1.38 uri => \$self->{href},
975 wakaba 1.28 token => $t);
976    
977     return ($t, undef);
978     }; # $parse_color
979    
980 wakaba 1.5 $Prop->{color} = {
981     css => 'color',
982     dom => 'color',
983     key => 'color',
984 wakaba 1.28 parse => $parse_color,
985     serialize => $default_serializer,
986     initial => ['KEYWORD', '-manakai-default'],
987     inherited => 1,
988     compute => sub ($$$$) {
989     my ($self, $element, $prop_name, $specified_value) = @_;
990 wakaba 1.5
991 wakaba 1.28 if (defined $specified_value) {
992     if ($specified_value->[0] eq 'KEYWORD') {
993     if ($x11_colors->{$specified_value->[1]}) {
994     return ['RGBA', @{$x11_colors->{$specified_value->[1]}}, 1];
995     } elsif ($specified_value->[1] eq 'transparent') {
996     return ['RGBA', 0, 0, 0, 0];
997     } elsif ($specified_value->[1] eq 'currentcolor' or
998     $specified_value->[1] eq '-moz-use-text-color' or
999     ($specified_value->[1] eq '-manakai-invert-or-currentcolor'and
1000     not $self->{has_invert})) {
1001     unless ($prop_name eq 'color') {
1002     return $self->get_computed_value ($element, 'color');
1003     } else {
1004     ## NOTE: This is an error, since it should have been
1005     ## converted to 'inherit' at parse time.
1006     return ['KEYWORD', '-manakai-default'];
1007     }
1008     } elsif ($specified_value->[1] eq '-manakai-invert-or-currentcolor') {
1009     return ['KEYWORD', 'invert'];
1010     }
1011 wakaba 1.5 }
1012     }
1013    
1014 wakaba 1.28 return $specified_value;
1015 wakaba 1.5 },
1016     };
1017     $Attr->{color} = $Prop->{color};
1018     $Key->{color} = $Prop->{color};
1019    
1020 wakaba 1.28 $Prop->{'background-color'} = {
1021     css => 'background-color',
1022     dom => 'background_color',
1023     key => 'background_color',
1024     parse => $parse_color,
1025     serialize => $default_serializer,
1026 wakaba 1.30 serialize_multiple => sub {
1027     my $self = shift;
1028    
1029     my $r = {};
1030     my $has_all;
1031    
1032     my $x = $self->background_position_x;
1033     my $y = $self->background_position_y;
1034     my $xi = $self->get_property_priority ('background-position-x');
1035     my $yi = $self->get_property_priority ('background-position-y');
1036 wakaba 1.34 if (length $x) {
1037     if (length $y) {
1038 wakaba 1.30 if ($xi eq $yi) {
1039 wakaba 1.48 if ($x eq 'inherit') {
1040     if ($y eq 'inherit') {
1041     $r->{'background-position'} = ['inherit', $xi];
1042     $has_all = 1;
1043     } else {
1044     $r->{'background-position-x'} = [$x, $xi];
1045     $r->{'background-position-y'} = [$y, $yi];
1046     }
1047     } elsif ($y eq 'inherit') {
1048     $r->{'background-position-x'} = [$x, $xi];
1049     $r->{'background-position-y'} = [$y, $yi];
1050     } else {
1051     $r->{'background-position'} = [$x . ' ' . $y, $xi];
1052     $has_all = 1;
1053     }
1054 wakaba 1.30 } else {
1055 wakaba 1.43 $r->{'background-position-x'} = [$x, $xi];
1056     $r->{'background-position-y'} = [$y, $yi];
1057 wakaba 1.30 }
1058     } else {
1059 wakaba 1.43 $r->{'background-position-x'} = [$x, $xi];
1060 wakaba 1.30 }
1061     } else {
1062 wakaba 1.34 if (length $y) {
1063 wakaba 1.43 $r->{'background-position-y'} = [$y, $yi];
1064 wakaba 1.30 } else {
1065     #
1066     }
1067     }
1068    
1069     for my $prop (qw/color image repeat attachment/) {
1070     my $prop_name = 'background_'.$prop;
1071     my $value = $self->$prop_name;
1072 wakaba 1.34 if (length $value) {
1073 wakaba 1.30 my $i = $self->get_property_priority ('background-'.$prop);
1074 wakaba 1.48 undef $has_all unless $xi eq $i;
1075 wakaba 1.45 $r->{'background-'.$prop} = [$value, $i];
1076 wakaba 1.30 } else {
1077     undef $has_all;
1078     }
1079     }
1080    
1081     if ($has_all) {
1082     my @v;
1083     push @v, $r->{'background-color'}
1084 wakaba 1.43 unless $r->{'background-color'}->[0] eq 'transparent';
1085 wakaba 1.30 push @v, $r->{'background-image'}
1086 wakaba 1.43 unless $r->{'background-image'}->[0] eq 'none';
1087 wakaba 1.30 push @v, $r->{'background-repeat'}
1088 wakaba 1.43 unless $r->{'background-repeat'}->[0] eq 'repeat';
1089 wakaba 1.30 push @v, $r->{'background-attachment'}
1090 wakaba 1.43 unless $r->{'background-attachment'}->[0] eq 'scroll';
1091 wakaba 1.30 push @v, $r->{'background-position'}
1092 wakaba 1.43 unless $r->{'background-position'}->[0] eq '0% 0%';
1093 wakaba 1.30 if (@v) {
1094 wakaba 1.48 my $inherit = 0;
1095     for (@v) {
1096     $inherit++ if $_->[0] eq 'inherit';
1097     }
1098     if ($inherit == 5) {
1099     return {background => ['inherit', $xi]};
1100     } elsif ($inherit) {
1101     return $r;
1102     } else {
1103     return {background => [(join ' ', map {$_->[0]} @v), $xi]};
1104     }
1105 wakaba 1.30 } else {
1106 wakaba 1.48 return {background => ['transparent none repeat scroll 0% 0%', $xi]};
1107 wakaba 1.30 }
1108     } else {
1109     return $r;
1110     }
1111     },
1112 wakaba 1.28 initial => ['KEYWORD', 'transparent'],
1113     #inherited => 0,
1114     compute => $Prop->{color}->{compute},
1115     };
1116     $Attr->{background_color} = $Prop->{'background-color'};
1117     $Key->{background_color} = $Prop->{'background-color'};
1118    
1119     $Prop->{'border-top-color'} = {
1120     css => 'border-top-color',
1121     dom => 'border_top_color',
1122     key => 'border_top_color',
1123     parse => $parse_color,
1124     serialize => $default_serializer,
1125 wakaba 1.29 serialize_multiple => sub {
1126     my $self = shift;
1127     ## NOTE: This algorithm returns the same result as that of Firefox 2
1128     ## in many case, but not always.
1129     my $r = {
1130 wakaba 1.46 'border-top-color' => [$self->border_top_color,
1131     $self->get_property_priority
1132     ('border-top-color')],
1133     'border-top-style' => [$self->border_top_style,
1134     $self->get_property_priority
1135     ('border-top-style')],
1136     'border-top-width' => [$self->border_top_width,
1137     $self->get_property_priority
1138     ('border-top-width')],
1139     'border-right-color' => [$self->border_right_color,
1140     $self->get_property_priority
1141     ('border-right-color')],
1142     'border-right-style' => [$self->border_right_style,
1143     $self->get_property_priority
1144     ('border-right-style')],
1145     'border-right-width' => [$self->border_right_width,
1146     $self->get_property_priority
1147     ('border-right-width')],
1148     'border-bottom-color' => [$self->border_bottom_color,
1149     $self->get_property_priority
1150     ('border-bottom-color')],
1151     'border-bottom-style' => [$self->border_bottom_style,
1152     $self->get_property_priority
1153     ('border-bottom-style')],
1154     'border-bottom-width' => [$self->border_bottom_width,
1155     $self->get_property_priority
1156     ('border-bottom-width')],
1157     'border-left-color' => [$self->border_left_color,
1158     $self->get_property_priority
1159     ('border-leftcolor')],
1160     'border-left-style' => [$self->border_left_style,
1161     $self->get_property_priority
1162     ('border-left-style')],
1163     'border-left-width' => [$self->border_left_width,
1164     $self->get_property_priority
1165     ('border-left-width')],
1166 wakaba 1.29 };
1167     my $i = 0;
1168     for my $prop (qw/border-top border-right border-bottom border-left/) {
1169 wakaba 1.43 if (length $r->{$prop.'-color'}->[0] and
1170     length $r->{$prop.'-style'}->[0] and
1171 wakaba 1.46 length $r->{$prop.'-width'}->[0] and
1172     $r->{$prop.'-color'}->[1] eq $r->{$prop.'-style'}->[1] and
1173     $r->{$prop.'-color'}->[1] eq $r->{$prop.'-width'}->[1]) {
1174     my $inherit = 0;
1175     $inherit++ if $r->{$prop.'-color'}->[0] eq 'inherit';
1176     $inherit++ if $r->{$prop.'-style'}->[0] eq 'inherit';
1177     $inherit++ if $r->{$prop.'-width'}->[0] eq 'inherit';
1178     if ($inherit == 3) {
1179     $r->{$prop} = $r->{$prop.'-color'};
1180     } elsif ($inherit) {
1181     next;
1182     } else {
1183     $r->{$prop} = [$r->{$prop.'-width'}->[0] . ' ' .
1184     $r->{$prop.'-style'}->[0] . ' ' .
1185     $r->{$prop.'-color'}->[0],
1186     $r->{$prop.'-color'}->[1]];
1187     }
1188 wakaba 1.29 delete $r->{$prop.'-width'};
1189     delete $r->{$prop.'-style'};
1190     delete $r->{$prop.'-color'};
1191     $i++;
1192     }
1193     }
1194 wakaba 1.46 if ($i == 4 and
1195     $r->{'border-top'}->[0] eq $r->{'border-right'}->[0] and
1196 wakaba 1.43 $r->{'border-right'}->[0] eq $r->{'border-bottom'}->[0] and
1197 wakaba 1.46 $r->{'border-bottom'}->[0] eq $r->{'border-left'}->[0] and
1198     $r->{'border-top'}->[1] eq $r->{'border-right'}->[1] and
1199     $r->{'border-right'}->[1] eq $r->{'border-bottom'}->[1] and
1200     $r->{'border-bottom'}->[1] eq $r->{'border-left'}->[1]) {
1201 wakaba 1.29 return {border => $r->{'border-top'}};
1202     }
1203    
1204     unless ($i) {
1205     for my $prop (qw/color style width/) {
1206     if (defined $r->{'border-top-'.$prop} and
1207     defined $r->{'border-bottom-'.$prop} and
1208     defined $r->{'border-right-'.$prop} and
1209 wakaba 1.46 defined $r->{'border-left-'.$prop} and
1210     length $r->{'border-top-'.$prop}->[0] and
1211     length $r->{'border-bottom-'.$prop}->[0] and
1212     length $r->{'border-right-'.$prop}->[0] and
1213     length $r->{'border-left-'.$prop}->[0] and
1214     $r->{'border-top-'.$prop}->[1]
1215     eq $r->{'border-bottom-'.$prop}->[1] and
1216     $r->{'border-top-'.$prop}->[1]
1217     eq $r->{'border-right-'.$prop}->[1] and
1218     $r->{'border-top-'.$prop}->[1]
1219     eq $r->{'border-left-'.$prop}->[1]) {
1220 wakaba 1.29 my @v = ($r->{'border-top-'.$prop},
1221     $r->{'border-right-'.$prop},
1222     $r->{'border-bottom-'.$prop},
1223     $r->{'border-left-'.$prop});
1224 wakaba 1.46 my $inherit = 0;
1225     for (@v) {
1226     $inherit++ if $_->[0] eq 'inherit';
1227     }
1228     if ($inherit == 4) {
1229     $r->{'border-'.$prop}
1230     = ['inherit', $r->{'border-top-'.$prop}->[1]];
1231     } elsif ($inherit) {
1232     next;
1233     } else {
1234     pop @v
1235     if $r->{'border-right-'.$prop}->[0]
1236     eq $r->{'border-left-'.$prop}->[0];
1237     pop @v
1238     if $r->{'border-bottom-'.$prop}->[0]
1239     eq $r->{'border-top-'.$prop}->[0];
1240     pop @v
1241     if $r->{'border-right-'.$prop}->[0]
1242     eq $r->{'border-top-'.$prop}->[0];
1243     $r->{'border-'.$prop} = [(join ' ', map {$_->[0]} @v),
1244     $r->{'border-top-'.$prop}->[1]];
1245     }
1246 wakaba 1.29 delete $r->{'border-top-'.$prop};
1247     delete $r->{'border-bottom-'.$prop};
1248     delete $r->{'border-right-'.$prop};
1249     delete $r->{'border-left-'.$prop};
1250     }
1251     }
1252     }
1253    
1254 wakaba 1.43 delete $r->{$_} for grep {not length $r->{$_}->[0]} keys %$r;
1255 wakaba 1.29 return $r;
1256     },
1257 wakaba 1.28 initial => ['KEYWORD', 'currentcolor'],
1258     #inherited => 0,
1259     compute => $Prop->{color}->{compute},
1260     };
1261     $Attr->{border_top_color} = $Prop->{'border-top-color'};
1262     $Key->{border_top_color} = $Prop->{'border-top-color'};
1263    
1264     $Prop->{'border-right-color'} = {
1265     css => 'border-right-color',
1266     dom => 'border_right_color',
1267     key => 'border_right_color',
1268     parse => $parse_color,
1269     serialize => $default_serializer,
1270 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
1271 wakaba 1.28 initial => ['KEYWORD', 'currentcolor'],
1272     #inherited => 0,
1273     compute => $Prop->{color}->{compute},
1274     };
1275 wakaba 1.29 $Attr->{border_right_color} = $Prop->{'border-right-color'};
1276     $Key->{border_right_color} = $Prop->{'border-right-color'};
1277 wakaba 1.28
1278     $Prop->{'border-bottom-color'} = {
1279     css => 'border-bottom-color',
1280     dom => 'border_bottom_color',
1281     key => 'border_bottom_color',
1282     parse => $parse_color,
1283     serialize => $default_serializer,
1284 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
1285 wakaba 1.28 initial => ['KEYWORD', 'currentcolor'],
1286     #inherited => 0,
1287     compute => $Prop->{color}->{compute},
1288     };
1289     $Attr->{border_bottom_color} = $Prop->{'border-bottom-color'};
1290     $Key->{border_bottom_color} = $Prop->{'border-bottom-color'};
1291    
1292     $Prop->{'border-left-color'} = {
1293     css => 'border-left-color',
1294     dom => 'border_left_color',
1295     key => 'border_left_color',
1296     parse => $parse_color,
1297     serialize => $default_serializer,
1298 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
1299 wakaba 1.28 initial => ['KEYWORD', 'currentcolor'],
1300     #inherited => 0,
1301     compute => $Prop->{color}->{compute},
1302     };
1303     $Attr->{border_left_color} = $Prop->{'border-left-color'};
1304     $Key->{border_left_color} = $Prop->{'border-left-color'};
1305    
1306     $Prop->{'outline-color'} = {
1307     css => 'outline-color',
1308     dom => 'outline_color',
1309     key => 'outline_color',
1310     parse => $parse_color,
1311     serialize => $default_serializer,
1312 wakaba 1.29 serialize_multiple => sub {
1313     my $self = shift;
1314     my $oc = $self->outline_color;
1315     my $os = $self->outline_style;
1316     my $ow = $self->outline_width;
1317     my $r = {};
1318 wakaba 1.34 if (length $oc and length $os and length $ow) {
1319 wakaba 1.43 $r->{outline} = [$ow . ' ' . $os . ' ' . $oc];
1320 wakaba 1.29 } else {
1321 wakaba 1.43 $r->{'outline-color'} = [$oc] if length $oc;
1322     $r->{'outline-style'} = [$os] if length $os;
1323     $r->{'outline-width'} = [$ow] if length $ow;
1324 wakaba 1.29 }
1325     return $r;
1326     },
1327 wakaba 1.28 initial => ['KEYWORD', '-manakai-invert-or-currentcolor'],
1328     #inherited => 0,
1329     compute => $Prop->{color}->{compute},
1330     };
1331     $Attr->{outline_color} = $Prop->{'outline-color'};
1332     $Key->{outline_color} = $Prop->{'outline-color'};
1333    
1334 wakaba 1.6 my $one_keyword_parser = sub {
1335     my ($self, $prop_name, $tt, $t, $onerror) = @_;
1336    
1337     if ($t->{type} == IDENT_TOKEN) {
1338     my $prop_value = lc $t->{value}; ## TODO: case folding
1339     $t = $tt->get_next_token;
1340     if ($Prop->{$prop_name}->{keyword}->{$prop_value} and
1341     $self->{prop_value}->{$prop_name}->{$prop_value}) {
1342 wakaba 1.7 return ($t, {$prop_name => ["KEYWORD", $prop_value]});
1343 wakaba 1.6 } elsif ($prop_value eq 'inherit') {
1344 wakaba 1.10 return ($t, {$prop_name => ['INHERIT']});
1345 wakaba 1.6 }
1346     }
1347    
1348 wakaba 1.39 $onerror->(type => "syntax error:'".$prop_name."'",
1349 wakaba 1.6 level => $self->{must_level},
1350 wakaba 1.38 uri => \$self->{href},
1351 wakaba 1.6 token => $t);
1352     return ($t, undef);
1353     };
1354    
1355     $Prop->{display} = {
1356     css => 'display',
1357     dom => 'display',
1358     key => 'display',
1359     parse => $one_keyword_parser,
1360 wakaba 1.11 serialize => $default_serializer,
1361 wakaba 1.6 keyword => {
1362     block => 1, inline => 1, 'inline-block' => 1, 'inline-table' => 1,
1363     'list-item' => 1, none => 1,
1364     table => 1, 'table-caption' => 1, 'table-cell' => 1, 'table-column' => 1,
1365     'table-column-group' => 1, 'table-header-group' => 1,
1366     'table-footer-group' => 1, 'table-row' => 1, 'table-row-group' => 1,
1367     },
1368 wakaba 1.9 initial => ["KEYWORD", "inline"],
1369     #inherited => 0,
1370     compute => sub {
1371     my ($self, $element, $prop_name, $specified_value) = @_;
1372     ## NOTE: CSS 2.1 Section 9.7.
1373    
1374     ## WARNING: |compute| for 'float' property invoke this CODE
1375     ## in some case. Careless modification might cause a infinite loop.
1376    
1377 wakaba 1.17 if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
1378 wakaba 1.9 if ($specified_value->[1] eq 'none') {
1379     ## Case 1 [CSS 2.1]
1380     return $specified_value;
1381     } else {
1382     my $position = $self->get_computed_value ($element, 'position');
1383     if ($position->[0] eq 'KEYWORD' and
1384     ($position->[1] eq 'absolute' or
1385     $position->[1] eq 'fixed')) {
1386     ## Case 2 [CSS 2.1]
1387     #
1388     } else {
1389     my $float = $self->get_computed_value ($element, 'float');
1390     if ($float->[0] eq 'KEYWORD' and $float->[1] ne 'none') {
1391     ## Caes 3 [CSS 2.1]
1392     #
1393     } elsif (not defined $element->manakai_parent_element) {
1394     ## Case 4 [CSS 2.1]
1395     #
1396     } else {
1397     ## Case 5 [CSS 2.1]
1398     return $specified_value;
1399     }
1400     }
1401    
1402     return ["KEYWORD",
1403     {
1404     'inline-table' => 'table',
1405     inline => 'block',
1406     'run-in' => 'block',
1407     'table-row-group' => 'block',
1408     'table-column' => 'block',
1409     'table-column-group' => 'block',
1410     'table-header-group' => 'block',
1411     'table-footer-group' => 'block',
1412     'table-row' => 'block',
1413     'table-cell' => 'block',
1414     'table-caption' => 'block',
1415     'inline-block' => 'block',
1416     }->{$specified_value->[1]} || $specified_value->[1]];
1417     }
1418     } else {
1419     return $specified_value; ## Maybe an error of the implementation.
1420     }
1421     },
1422 wakaba 1.6 };
1423     $Attr->{display} = $Prop->{display};
1424     $Key->{display} = $Prop->{display};
1425    
1426     $Prop->{position} = {
1427     css => 'position',
1428     dom => 'position',
1429     key => 'position',
1430     parse => $one_keyword_parser,
1431 wakaba 1.11 serialize => $default_serializer,
1432 wakaba 1.6 keyword => {
1433     static => 1, relative => 1, absolute => 1, fixed => 1,
1434     },
1435 wakaba 1.10 initial => ["KEYWORD", "static"],
1436 wakaba 1.9 #inherited => 0,
1437     compute => $compute_as_specified,
1438 wakaba 1.6 };
1439     $Attr->{position} = $Prop->{position};
1440     $Key->{position} = $Prop->{position};
1441    
1442     $Prop->{float} = {
1443     css => 'float',
1444     dom => 'css_float',
1445     key => 'float',
1446     parse => $one_keyword_parser,
1447 wakaba 1.11 serialize => $default_serializer,
1448 wakaba 1.6 keyword => {
1449     left => 1, right => 1, none => 1,
1450     },
1451 wakaba 1.9 initial => ["KEYWORD", "none"],
1452     #inherited => 0,
1453     compute => sub {
1454     my ($self, $element, $prop_name, $specified_value) = @_;
1455     ## NOTE: CSS 2.1 Section 9.7.
1456    
1457     ## WARNING: |compute| for 'display' property invoke this CODE
1458     ## in some case. Careless modification might cause a infinite loop.
1459    
1460 wakaba 1.17 if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
1461 wakaba 1.9 if ($specified_value->[1] eq 'none') {
1462     ## Case 1 [CSS 2.1]
1463     return $specified_value;
1464     } else {
1465     my $position = $self->get_computed_value ($element, 'position');
1466     if ($position->[0] eq 'KEYWORD' and
1467     ($position->[1] eq 'absolute' or
1468     $position->[1] eq 'fixed')) {
1469     ## Case 2 [CSS 2.1]
1470     return ["KEYWORD", "none"];
1471     }
1472     }
1473     }
1474    
1475     ## ISSUE: CSS 2.1 section 9.7 and 9.5.1 ('float' definition) disagree
1476     ## on computed value of 'float' property.
1477    
1478     ## Case 3, 4, and 5 [CSS 2.1]
1479     return $specified_value;
1480     },
1481 wakaba 1.6 };
1482     $Attr->{css_float} = $Prop->{float};
1483     $Attr->{style_float} = $Prop->{float}; ## NOTE: IEism
1484     $Key->{float} = $Prop->{float};
1485    
1486     $Prop->{clear} = {
1487     css => 'clear',
1488     dom => 'clear',
1489     key => 'clear',
1490     parse => $one_keyword_parser,
1491 wakaba 1.11 serialize => $default_serializer,
1492 wakaba 1.6 keyword => {
1493     left => 1, right => 1, none => 1, both => 1,
1494     },
1495 wakaba 1.9 initial => ["KEYWORD", "none"],
1496     #inherited => 0,
1497     compute => $compute_as_specified,
1498 wakaba 1.6 };
1499     $Attr->{clear} = $Prop->{clear};
1500     $Key->{clear} = $Prop->{clear};
1501    
1502     $Prop->{direction} = {
1503     css => 'direction',
1504     dom => 'direction',
1505     key => 'direction',
1506     parse => $one_keyword_parser,
1507 wakaba 1.11 serialize => $default_serializer,
1508 wakaba 1.6 keyword => {
1509     ltr => 1, rtl => 1,
1510     },
1511 wakaba 1.9 initial => ["KEYWORD", "ltr"],
1512     inherited => 1,
1513     compute => $compute_as_specified,
1514 wakaba 1.6 };
1515     $Attr->{direction} = $Prop->{direction};
1516     $Key->{direction} = $Prop->{direction};
1517    
1518     $Prop->{'unicode-bidi'} = {
1519     css => 'unicode-bidi',
1520     dom => 'unicode_bidi',
1521     key => 'unicode_bidi',
1522     parse => $one_keyword_parser,
1523 wakaba 1.11 serialize => $default_serializer,
1524 wakaba 1.6 keyword => {
1525     normal => 1, embed => 1, 'bidi-override' => 1,
1526     },
1527 wakaba 1.9 initial => ["KEYWORD", "normal"],
1528     #inherited => 0,
1529     compute => $compute_as_specified,
1530 wakaba 1.6 };
1531     $Attr->{unicode_bidi} = $Prop->{'unicode-bidi'};
1532     $Key->{unicode_bidi} = $Prop->{'unicode-bidi'};
1533    
1534 wakaba 1.11 $Prop->{overflow} = {
1535     css => 'overflow',
1536     dom => 'overflow',
1537     key => 'overflow',
1538     parse => $one_keyword_parser,
1539     serialize => $default_serializer,
1540     keyword => {
1541     visible => 1, hidden => 1, scroll => 1, auto => 1,
1542     },
1543     initial => ["KEYWORD", "visible"],
1544     #inherited => 0,
1545     compute => $compute_as_specified,
1546     };
1547     $Attr->{overflow} = $Prop->{overflow};
1548     $Key->{overflow} = $Prop->{overflow};
1549    
1550     $Prop->{visibility} = {
1551     css => 'visibility',
1552     dom => 'visibility',
1553     key => 'visibility',
1554     parse => $one_keyword_parser,
1555     serialize => $default_serializer,
1556     keyword => {
1557     visible => 1, hidden => 1, collapse => 1,
1558     },
1559     initial => ["KEYWORD", "visible"],
1560     #inherited => 0,
1561     compute => $compute_as_specified,
1562     };
1563     $Attr->{visibility} = $Prop->{visibility};
1564     $Key->{visibility} = $Prop->{visibility};
1565    
1566     $Prop->{'list-style-type'} = {
1567     css => 'list-style-type',
1568     dom => 'list_style_type',
1569     key => 'list_style_type',
1570     parse => $one_keyword_parser,
1571     serialize => $default_serializer,
1572     keyword => {
1573     qw/
1574     disc 1 circle 1 square 1 decimal 1 decimal-leading-zero 1
1575     lower-roman 1 upper-roman 1 lower-greek 1 lower-latin 1
1576     upper-latin 1 armenian 1 georgian 1 lower-alpha 1 upper-alpha 1
1577     none 1
1578     /,
1579     },
1580     initial => ["KEYWORD", 'disc'],
1581     inherited => 1,
1582     compute => $compute_as_specified,
1583     };
1584     $Attr->{list_style_type} = $Prop->{'list-style-type'};
1585     $Key->{list_style_type} = $Prop->{'list-style-type'};
1586    
1587     $Prop->{'list-style-position'} = {
1588     css => 'list-style-position',
1589     dom => 'list_style_position',
1590     key => 'list_style_position',
1591     parse => $one_keyword_parser,
1592     serialize => $default_serializer,
1593     keyword => {
1594     inside => 1, outside => 1,
1595     },
1596     initial => ["KEYWORD", 'outside'],
1597     inherited => 1,
1598     compute => $compute_as_specified,
1599     };
1600     $Attr->{list_style_position} = $Prop->{'list-style-position'};
1601     $Key->{list_style_position} = $Prop->{'list-style-position'};
1602    
1603 wakaba 1.12 $Prop->{'page-break-before'} = {
1604     css => 'page-break-before',
1605     dom => 'page_break_before',
1606     key => 'page_break_before',
1607     parse => $one_keyword_parser,
1608     serialize => $default_serializer,
1609     keyword => {
1610     auto => 1, always => 1, avoid => 1, left => 1, right => 1,
1611     },
1612     initial => ["KEYWORD", 'auto'],
1613 wakaba 1.15 #inherited => 0,
1614 wakaba 1.12 compute => $compute_as_specified,
1615     };
1616     $Attr->{page_break_before} = $Prop->{'page-break-before'};
1617     $Key->{page_break_before} = $Prop->{'page-break-before'};
1618    
1619     $Prop->{'page-break-after'} = {
1620     css => 'page-break-after',
1621     dom => 'page_break_after',
1622     key => 'page_break_after',
1623     parse => $one_keyword_parser,
1624     serialize => $default_serializer,
1625     keyword => {
1626     auto => 1, always => 1, avoid => 1, left => 1, right => 1,
1627     },
1628     initial => ["KEYWORD", 'auto'],
1629 wakaba 1.15 #inherited => 0,
1630 wakaba 1.12 compute => $compute_as_specified,
1631     };
1632     $Attr->{page_break_after} = $Prop->{'page-break-after'};
1633     $Key->{page_break_after} = $Prop->{'page-break-after'};
1634    
1635     $Prop->{'page-break-inside'} = {
1636     css => 'page-break-inside',
1637     dom => 'page_break_inside',
1638     key => 'page_break_inside',
1639     parse => $one_keyword_parser,
1640     serialize => $default_serializer,
1641     keyword => {
1642     auto => 1, avoid => 1,
1643     },
1644     initial => ["KEYWORD", 'auto'],
1645     inherited => 1,
1646     compute => $compute_as_specified,
1647     };
1648     $Attr->{page_break_inside} = $Prop->{'page-break-inside'};
1649     $Key->{page_break_inside} = $Prop->{'page-break-inside'};
1650    
1651 wakaba 1.15 $Prop->{'background-repeat'} = {
1652     css => 'background-repeat',
1653     dom => 'background_repeat',
1654     key => 'background_repeat',
1655     parse => $one_keyword_parser,
1656     serialize => $default_serializer,
1657 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
1658 wakaba 1.15 keyword => {
1659     repeat => 1, 'repeat-x' => 1, 'repeat-y' => 1, 'no-repeat' => 1,
1660     },
1661     initial => ["KEYWORD", 'repeat'],
1662     #inherited => 0,
1663     compute => $compute_as_specified,
1664     };
1665     $Attr->{background_repeat} = $Prop->{'background-repeat'};
1666     $Key->{backgroud_repeat} = $Prop->{'background-repeat'};
1667    
1668     $Prop->{'background-attachment'} = {
1669     css => 'background-attachment',
1670     dom => 'background_attachment',
1671     key => 'background_attachment',
1672     parse => $one_keyword_parser,
1673     serialize => $default_serializer,
1674 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
1675 wakaba 1.15 keyword => {
1676     scroll => 1, fixed => 1,
1677     },
1678     initial => ["KEYWORD", 'scroll'],
1679     #inherited => 0,
1680     compute => $compute_as_specified,
1681     };
1682     $Attr->{background_attachment} = $Prop->{'background-attachment'};
1683     $Key->{backgroud_attachment} = $Prop->{'background-attachment'};
1684    
1685     $Prop->{'font-style'} = {
1686     css => 'font-style',
1687 wakaba 1.18 dom => 'font_style',
1688     key => 'font_style',
1689 wakaba 1.15 parse => $one_keyword_parser,
1690     serialize => $default_serializer,
1691     keyword => {
1692     normal => 1, italic => 1, oblique => 1,
1693     },
1694     initial => ["KEYWORD", 'normal'],
1695     inherited => 1,
1696     compute => $compute_as_specified,
1697     };
1698     $Attr->{font_style} = $Prop->{'font-style'};
1699     $Key->{font_style} = $Prop->{'font-style'};
1700    
1701     $Prop->{'font-variant'} = {
1702     css => 'font-variant',
1703     dom => 'font_variant',
1704     key => 'font_variant',
1705     parse => $one_keyword_parser,
1706     serialize => $default_serializer,
1707     keyword => {
1708     normal => 1, 'small-caps' => 1,
1709     },
1710     initial => ["KEYWORD", 'normal'],
1711     inherited => 1,
1712     compute => $compute_as_specified,
1713     };
1714     $Attr->{font_variant} = $Prop->{'font-variant'};
1715     $Key->{font_variant} = $Prop->{'font-variant'};
1716    
1717 wakaba 1.16 $Prop->{'text-align'} = {
1718     css => 'text-align',
1719     dom => 'text_align',
1720     key => 'text_align',
1721     parse => $one_keyword_parser,
1722     serialize => $default_serializer,
1723     keyword => {
1724     left => 1, right => 1, center => 1, justify => 1, ## CSS 2
1725     begin => 1, end => 1, ## CSS 3
1726     },
1727     initial => ["KEYWORD", 'begin'],
1728     inherited => 1,
1729     compute => $compute_as_specified,
1730     };
1731     $Attr->{text_align} = $Prop->{'text-align'};
1732     $Key->{text_align} = $Prop->{'text-align'};
1733    
1734     $Prop->{'text-transform'} = {
1735     css => 'text-transform',
1736     dom => 'text_transform',
1737     key => 'text_transform',
1738     parse => $one_keyword_parser,
1739     serialize => $default_serializer,
1740     keyword => {
1741     capitalize => 1, uppercase => 1, lowercase => 1, none => 1,
1742     },
1743     initial => ["KEYWORD", 'none'],
1744     inherited => 1,
1745     compute => $compute_as_specified,
1746     };
1747     $Attr->{text_transform} = $Prop->{'text-transform'};
1748     $Key->{text_transform} = $Prop->{'text-transform'};
1749    
1750     $Prop->{'white-space'} = {
1751     css => 'white-space',
1752     dom => 'white_space',
1753     key => 'white_space',
1754     parse => $one_keyword_parser,
1755     serialize => $default_serializer,
1756     keyword => {
1757     normal => 1, pre => 1, nowrap => 1, 'pre-wrap' => 1, 'pre-line' => 1,
1758     },
1759     initial => ["KEYWORD", 'normal'],
1760     inherited => 1,
1761     compute => $compute_as_specified,
1762     };
1763     $Attr->{white_space} = $Prop->{'white-space'};
1764     $Key->{white_space} = $Prop->{'white-space'};
1765    
1766     $Prop->{'caption-side'} = {
1767     css => 'caption-side',
1768     dom => 'caption_side',
1769     key => 'caption_side',
1770     parse => $one_keyword_parser,
1771     serialize => $default_serializer,
1772     keyword => {
1773     top => 1, bottom => 1,
1774     },
1775     initial => ['KEYWORD', 'top'],
1776     inherited => 1,
1777     compute => $compute_as_specified,
1778     };
1779     $Attr->{caption_side} = $Prop->{'caption-side'};
1780     $Key->{caption_side} = $Prop->{'caption-side'};
1781    
1782     $Prop->{'table-layout'} = {
1783     css => 'table-layout',
1784     dom => 'table_layout',
1785     key => 'table_layout',
1786     parse => $one_keyword_parser,
1787     serialize => $default_serializer,
1788     keyword => {
1789     auto => 1, fixed => 1,
1790     },
1791     initial => ['KEYWORD', 'auto'],
1792     #inherited => 0,
1793     compute => $compute_as_specified,
1794     };
1795     $Attr->{table_layout} = $Prop->{'table-layout'};
1796     $Key->{table_layout} = $Prop->{'table-layout'};
1797    
1798     $Prop->{'border-collapse'} = {
1799     css => 'border-collapse',
1800     dom => 'border_collapse',
1801     key => 'border_collapse',
1802     parse => $one_keyword_parser,
1803     serialize => $default_serializer,
1804     keyword => {
1805     collapse => 1, separate => 1,
1806     },
1807     initial => ['KEYWORD', 'separate'],
1808     inherited => 1,
1809     compute => $compute_as_specified,
1810     };
1811     $Attr->{border_collapse} = $Prop->{'border-collapse'};
1812     $Key->{border_collapse} = $Prop->{'border-collapse'};
1813    
1814     $Prop->{'empty-cells'} = {
1815     css => 'empty-cells',
1816     dom => 'empty_cells',
1817     key => 'empty_cells',
1818     parse => $one_keyword_parser,
1819     serialize => $default_serializer,
1820     keyword => {
1821     show => 1, hide => 1,
1822     },
1823     initial => ['KEYWORD', 'show'],
1824     inherited => 1,
1825     compute => $compute_as_specified,
1826     };
1827     $Attr->{empty_cells} = $Prop->{'empty-cells'};
1828     $Key->{empty_cells} = $Prop->{'empty-cells'};
1829    
1830 wakaba 1.11 $Prop->{'z-index'} = {
1831     css => 'z-index',
1832     dom => 'z_index',
1833     key => 'z_index',
1834     parse => sub {
1835     my ($self, $prop_name, $tt, $t, $onerror) = @_;
1836    
1837 wakaba 1.51 my $has_sign;
1838 wakaba 1.12 my $sign = 1;
1839     if ($t->{type} == MINUS_TOKEN) {
1840     $sign = -1;
1841 wakaba 1.51 $has_sign = 1;
1842     $t = $tt->get_next_token;
1843     } elsif ($t->{type} == PLUS_TOKEN) {
1844     $has_sign = 1;
1845 wakaba 1.12 $t = $tt->get_next_token;
1846     }
1847    
1848 wakaba 1.11 if ($t->{type} == NUMBER_TOKEN) {
1849     ## ISSUE: See <http://suika.fam.cx/gate/2005/sw/z-index> for
1850     ## browser compatibility issue.
1851     my $value = $t->{number};
1852     $t = $tt->get_next_token;
1853 wakaba 1.12 return ($t, {$prop_name => ["NUMBER", $sign * int ($value / 1)]});
1854 wakaba 1.51 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
1855 wakaba 1.11 my $value = lc $t->{value}; ## TODO: case
1856     if ($value eq 'auto') {
1857     ## NOTE: |z-index| is the default value and therefore it must be
1858     ## supported anyway.
1859 wakaba 1.51 $t = $tt->get_next_token;
1860 wakaba 1.11 return ($t, {$prop_name => ["KEYWORD", 'auto']});
1861     } elsif ($value eq 'inherit') {
1862 wakaba 1.51 $t = $tt->get_next_token;
1863 wakaba 1.11 return ($t, {$prop_name => ['INHERIT']});
1864     }
1865     }
1866    
1867 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
1868 wakaba 1.11 level => $self->{must_level},
1869 wakaba 1.38 uri => \$self->{href},
1870 wakaba 1.11 token => $t);
1871     return ($t, undef);
1872     },
1873     serialize => $default_serializer,
1874     initial => ['KEYWORD', 'auto'],
1875     #inherited => 0,
1876     compute => $compute_as_specified,
1877     };
1878     $Attr->{z_index} = $Prop->{'z-index'};
1879     $Key->{z_index} = $Prop->{'z-index'};
1880    
1881 wakaba 1.12 $Prop->{orphans} = {
1882     css => 'orphans',
1883     dom => 'orphans',
1884     key => 'orphans',
1885     parse => sub {
1886     my ($self, $prop_name, $tt, $t, $onerror) = @_;
1887    
1888 wakaba 1.52 my $has_sign;
1889 wakaba 1.12 my $sign = 1;
1890     if ($t->{type} == MINUS_TOKEN) {
1891     $t = $tt->get_next_token;
1892 wakaba 1.52 $has_sign = 1;
1893 wakaba 1.12 $sign = -1;
1894 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
1895     $t = $tt->get_next_token;
1896     $has_sign = 1;
1897 wakaba 1.12 }
1898    
1899     if ($t->{type} == NUMBER_TOKEN) {
1900     ## ISSUE: See <http://suika.fam.cx/gate/2005/sw/orphans> and
1901     ## <http://suika.fam.cx/gate/2005/sw/widows> for
1902     ## browser compatibility issue.
1903     my $value = $t->{number};
1904     $t = $tt->get_next_token;
1905     return ($t, {$prop_name => ["NUMBER", $sign * int ($value / 1)]});
1906 wakaba 1.52 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
1907 wakaba 1.12 my $value = lc $t->{value}; ## TODO: case
1908     if ($value eq 'inherit') {
1909 wakaba 1.52 $t = $tt->get_next_token;
1910 wakaba 1.12 return ($t, {$prop_name => ['INHERIT']});
1911     }
1912     }
1913    
1914 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
1915 wakaba 1.12 level => $self->{must_level},
1916 wakaba 1.38 uri => \$self->{href},
1917 wakaba 1.12 token => $t);
1918     return ($t, undef);
1919     },
1920     serialize => $default_serializer,
1921     initial => ['NUMBER', 2],
1922     inherited => 1,
1923     compute => $compute_as_specified,
1924     };
1925     $Attr->{orphans} = $Prop->{orphans};
1926     $Key->{orphans} = $Prop->{orphans};
1927    
1928     $Prop->{widows} = {
1929     css => 'widows',
1930     dom => 'widows',
1931     key => 'widows',
1932     parse => $Prop->{orphans}->{parse},
1933     serialize => $default_serializer,
1934     initial => ['NUMBER', 2],
1935     inherited => 1,
1936     compute => $compute_as_specified,
1937     };
1938     $Attr->{widows} = $Prop->{widows};
1939     $Key->{widows} = $Prop->{widows};
1940    
1941 wakaba 1.32 $Prop->{opacity} = {
1942     css => 'opacity',
1943     dom => 'opacity',
1944     key => 'opacity',
1945     parse => sub {
1946     my ($self, $prop_name, $tt, $t, $onerror) = @_;
1947    
1948     my $sign = 1;
1949     if ($t->{type} == MINUS_TOKEN) {
1950     $t = $tt->get_next_token;
1951     $sign = -1;
1952     }
1953    
1954     if ($t->{type} == NUMBER_TOKEN) {
1955     ## ISSUE: See <http://suika.fam.cx/gate/2005/sw/opacity> for
1956     ## browser compatibility issue.
1957     my $value = $t->{number};
1958     $t = $tt->get_next_token;
1959     return ($t, {$prop_name => ["NUMBER", $sign * $value]});
1960     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
1961     my $value = lc $t->{value}; ## TODO: case
1962     $t = $tt->get_next_token;
1963     if ($value eq 'inherit') {
1964     return ($t, {$prop_name => ['INHERIT']});
1965     }
1966     }
1967    
1968 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
1969 wakaba 1.32 level => $self->{must_level},
1970 wakaba 1.38 uri => \$self->{href},
1971 wakaba 1.32 token => $t);
1972     return ($t, undef);
1973     },
1974     serialize => $default_serializer,
1975     initial => ['NUMBER', 2],
1976     inherited => 1,
1977     compute => sub {
1978     my ($self, $element, $prop_name, $specified_value) = @_;
1979    
1980     if (defined $specified_value) {
1981     if ($specified_value->[0] eq 'NUMBER') {
1982     if ($specified_value->[1] < 0) {
1983     return ['NUMBER', 0];
1984     } elsif ($specified_value->[1] > 1) {
1985     return ['NUMBER', 1];
1986     }
1987     }
1988     }
1989    
1990     return $specified_value;
1991     },
1992     serialize_multiple => sub {
1993     ## NOTE: This CODE is necessary to avoid two 'opacity' properties
1994     ## are outputed in |cssText| (for 'opacity' and for '-moz-opacity').
1995 wakaba 1.43 return {opacity => [shift->opacity]},
1996 wakaba 1.32 },
1997     };
1998     $Attr->{opacity} = $Prop->{opacity};
1999     $Key->{opacity} = $Prop->{opacity};
2000    
2001     $Prop->{'-moz-opacity'} = $Prop->{opacity};
2002 wakaba 1.36 $Attr->{_moz_opacity} = $Attr->{opacity};
2003 wakaba 1.32
2004 wakaba 1.19 my $length_unit = {
2005     em => 1, ex => 1, px => 1,
2006     in => 1, cm => 1, mm => 1, pt => 1, pc => 1,
2007     };
2008    
2009 wakaba 1.18 $Prop->{'font-size'} = {
2010     css => 'font-size',
2011     dom => 'font_size',
2012     key => 'font_size',
2013     parse => sub {
2014     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2015    
2016 wakaba 1.49 my $has_sign;
2017 wakaba 1.18 my $sign = 1;
2018     if ($t->{type} == MINUS_TOKEN) {
2019     $t = $tt->get_next_token;
2020     $sign = -1;
2021 wakaba 1.49 $has_sign = 1;
2022     } elsif ($t->{type} == PLUS_TOKEN) {
2023     $t = $tt->get_next_token;
2024     $has_sign = 1;
2025 wakaba 1.18 }
2026    
2027     if ($t->{type} == DIMENSION_TOKEN) {
2028     my $value = $t->{number} * $sign;
2029     my $unit = lc $t->{value}; ## TODO: case
2030 wakaba 1.19 if ($length_unit->{$unit} and $value >= 0) {
2031 wakaba 1.49 $t = $tt->get_next_token;
2032 wakaba 1.18 return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2033     }
2034     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
2035     my $value = $t->{number} * $sign;
2036 wakaba 1.49 if ($value >= 0) {
2037     $t = $tt->get_next_token;
2038     return ($t, {$prop_name => ['PERCENTAGE', $value]});
2039     }
2040 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
2041 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
2042 wakaba 1.18 my $value = $t->{number} * $sign;
2043 wakaba 1.49 if ($value >= 0) {
2044     $t = $tt->get_next_token;
2045     return ($t, {$prop_name => ['DIMENSION', $value, 'px']});
2046     }
2047     } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
2048 wakaba 1.18 my $value = lc $t->{value}; ## TODO: case
2049     if ({
2050     'xx-small' => 1, 'x-small' => 1, small => 1, medium => 1,
2051     large => 1, 'x-large' => 1, 'xx-large' => 1,
2052 wakaba 1.49 '-manakai-xxx-large' => 1, '-webkit-xxx-large' => 1,
2053 wakaba 1.18 larger => 1, smaller => 1,
2054     }->{$value}) {
2055 wakaba 1.49 $t = $tt->get_next_token;
2056 wakaba 1.18 return ($t, {$prop_name => ['KEYWORD', $value]});
2057     } elsif ($value eq 'inherit') {
2058 wakaba 1.49 $t = $tt->get_next_token;
2059 wakaba 1.18 return ($t, {$prop_name => ['INHERIT']});
2060     }
2061     }
2062    
2063 wakaba 1.49 $onerror->(type => "syntax error:'$prop_name'",
2064 wakaba 1.18 level => $self->{must_level},
2065 wakaba 1.38 uri => \$self->{href},
2066 wakaba 1.18 token => $t);
2067     return ($t, undef);
2068     },
2069     serialize => $default_serializer,
2070     initial => ['KEYWORD', 'medium'],
2071     inherited => 1,
2072     compute => sub {
2073     my ($self, $element, $prop_name, $specified_value) = @_;
2074    
2075     if (defined $specified_value) {
2076     if ($specified_value->[0] eq 'DIMENSION') {
2077     my $unit = $specified_value->[2];
2078     my $value = $specified_value->[1];
2079    
2080     if ($unit eq 'em' or $unit eq 'ex') {
2081     $value *= 0.5 if $unit eq 'ex';
2082     ## TODO: Preferred way to determine the |ex| size is defined
2083     ## in CSS 2.1.
2084    
2085     my $parent_element = $element->manakai_parent_element;
2086     if (defined $parent_element) {
2087     $value *= $self->get_computed_value ($parent_element, $prop_name)
2088     ->[1];
2089     } else {
2090     $value *= $self->{font_size}->[3]; # medium
2091     }
2092     $unit = 'px';
2093     } elsif ({in => 1, cm => 1, mm => 1, pt => 1, pc => 1}->{$unit}) {
2094     ($value *= 12, $unit = 'pc') if $unit eq 'pc';
2095     ($value /= 72, $unit = 'in') if $unit eq 'pt';
2096     ($value *= 2.54, $unit = 'cm') if $unit eq 'in';
2097     ($value *= 10, $unit = 'mm') if $unit eq 'cm';
2098     ($value /= 0.26, $unit = 'px') if $unit eq 'mm';
2099     }
2100 wakaba 1.19 ## else: consistency error
2101 wakaba 1.18
2102     return ['DIMENSION', $value, $unit];
2103     } elsif ($specified_value->[0] eq 'PERCENTAGE') {
2104     my $parent_element = $element->manakai_parent_element;
2105     my $parent_cv;
2106     if (defined $parent_element) {
2107     $parent_cv = $self->get_computed_value
2108     ($parent_element, $prop_name);
2109     } else {
2110     $parent_cv = [undef, $self->{font_size}->[3]];
2111     }
2112     return ['DIMENSION', $parent_cv->[1] * $specified_value->[1] / 100,
2113     'px'];
2114     } elsif ($specified_value->[0] eq 'KEYWORD') {
2115     if ($specified_value->[1] eq 'larger') {
2116     my $parent_element = $element->manakai_parent_element;
2117     if (defined $parent_element) {
2118     my $parent_cv = $self->get_computed_value
2119     ($parent_element, $prop_name);
2120     return ['DIMENSION',
2121     $self->{get_larger_font_size}->($self, $parent_cv->[1]),
2122     'px'];
2123     } else { ## 'larger' relative to 'medium', initial of 'font-size'
2124     return ['DIMENSION', $self->{font_size}->[4], 'px'];
2125     }
2126     } elsif ($specified_value->[1] eq 'smaller') {
2127     my $parent_element = $element->manakai_parent_element;
2128     if (defined $parent_element) {
2129     my $parent_cv = $self->get_computed_value
2130     ($parent_element, $prop_name);
2131     return ['DIMENSION',
2132     $self->{get_smaller_font_size}->($self, $parent_cv->[1]),
2133     'px'];
2134     } else { ## 'smaller' relative to 'medium', initial of 'font-size'
2135     return ['DIMENSION', $self->{font_size}->[2], 'px'];
2136     }
2137     } else {
2138 wakaba 1.49 ## TODO: different computation in quirks mode?
2139 wakaba 1.18 return ['DIMENSION', $self->{font_size}->[{
2140     'xx-small' => 0,
2141     'x-small' => 1,
2142     small => 2,
2143     medium => 3,
2144     large => 4,
2145     'x-large' => 5,
2146     'xx-large' => 6,
2147     '-manakai-xxx-large' => 7,
2148 wakaba 1.49 '-webkit-xxx-large' => 7,
2149 wakaba 1.18 }->{$specified_value->[1]}], 'px'];
2150     }
2151     }
2152     }
2153    
2154     return $specified_value;
2155     },
2156     };
2157     $Attr->{font_size} = $Prop->{'font-size'};
2158     $Key->{font_size} = $Prop->{'font-size'};
2159    
2160 wakaba 1.19 my $compute_length = sub {
2161     my ($self, $element, $prop_name, $specified_value) = @_;
2162    
2163     if (defined $specified_value) {
2164     if ($specified_value->[0] eq 'DIMENSION') {
2165     my $unit = $specified_value->[2];
2166     my $value = $specified_value->[1];
2167    
2168     if ($unit eq 'em' or $unit eq 'ex') {
2169     $value *= 0.5 if $unit eq 'ex';
2170     ## TODO: Preferred way to determine the |ex| size is defined
2171     ## in CSS 2.1.
2172    
2173     $value *= $self->get_computed_value ($element, 'font-size')->[1];
2174     $unit = 'px';
2175     } elsif ({in => 1, cm => 1, mm => 1, pt => 1, pc => 1}->{$unit}) {
2176     ($value *= 12, $unit = 'pc') if $unit eq 'pc';
2177     ($value /= 72, $unit = 'in') if $unit eq 'pt';
2178     ($value *= 2.54, $unit = 'cm') if $unit eq 'in';
2179     ($value *= 10, $unit = 'mm') if $unit eq 'cm';
2180     ($value /= 0.26, $unit = 'px') if $unit eq 'mm';
2181     }
2182    
2183     return ['DIMENSION', $value, $unit];
2184     }
2185     }
2186    
2187     return $specified_value;
2188     }; # $compute_length
2189    
2190 wakaba 1.23 $Prop->{'letter-spacing'} = {
2191     css => 'letter-spacing',
2192     dom => 'letter_spacing',
2193     key => 'letter_spacing',
2194     parse => sub {
2195     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2196    
2197 wakaba 1.24 ## NOTE: Used also for 'word-spacing', '-manakai-border-spacing-x',
2198     ## and '-manakai-border-spacing-y'.
2199 wakaba 1.23
2200     my $sign = 1;
2201     if ($t->{type} == MINUS_TOKEN) {
2202     $t = $tt->get_next_token;
2203     $sign = -1;
2204     }
2205     my $allow_negative = $Prop->{$prop_name}->{allow_negative};
2206    
2207     if ($t->{type} == DIMENSION_TOKEN) {
2208     my $value = $t->{number} * $sign;
2209     my $unit = lc $t->{value}; ## TODO: case
2210     $t = $tt->get_next_token;
2211 wakaba 1.24 if ($length_unit->{$unit} and ($allow_negative or $value >= 0)) {
2212 wakaba 1.23 return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2213     }
2214     } elsif ($t->{type} == NUMBER_TOKEN and
2215     ($self->{unitless_px} or $t->{number} == 0)) {
2216     my $value = $t->{number} * $sign;
2217     $t = $tt->get_next_token;
2218 wakaba 1.24 return ($t, {$prop_name => ['DIMENSION', $value, 'px']})
2219     if $allow_negative or $value >= 0;
2220 wakaba 1.23 } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
2221     my $value = lc $t->{value}; ## TODO: case
2222     $t = $tt->get_next_token;
2223 wakaba 1.24 if ($Prop->{$prop_name}->{keyword}->{$value}) {
2224 wakaba 1.23 return ($t, {$prop_name => ['KEYWORD', $value]});
2225     } elsif ($value eq 'inherit') {
2226     return ($t, {$prop_name => ['INHERIT']});
2227     }
2228     }
2229    
2230 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2231 wakaba 1.23 level => $self->{must_level},
2232 wakaba 1.38 uri => \$self->{href},
2233 wakaba 1.23 token => $t);
2234     return ($t, undef);
2235     },
2236 wakaba 1.24 allow_negative => 1,
2237     keyword => {normal => 1},
2238 wakaba 1.23 serialize => $default_serializer,
2239     initial => ['KEYWORD', 'normal'],
2240     inherited => 1,
2241     compute => $compute_length,
2242     };
2243     $Attr->{letter_spacing} = $Prop->{'letter-spacing'};
2244     $Key->{letter_spacing} = $Prop->{'letter-spacing'};
2245    
2246     $Prop->{'word-spacing'} = {
2247     css => 'word-spacing',
2248     dom => 'word_spacing',
2249     key => 'word_spacing',
2250     parse => $Prop->{'letter-spacing'}->{parse},
2251 wakaba 1.24 allow_negative => 1,
2252     keyword => {normal => 1},
2253 wakaba 1.23 serialize => $default_serializer,
2254     initial => ['KEYWORD', 'normal'],
2255     inherited => 1,
2256     compute => $compute_length,
2257     };
2258     $Attr->{word_spacing} = $Prop->{'word-spacing'};
2259     $Key->{word_spacing} = $Prop->{'word-spacing'};
2260    
2261 wakaba 1.24 $Prop->{'-manakai-border-spacing-x'} = {
2262     css => '-manakai-border-spacing-x',
2263     dom => '_manakai_border_spacing_x',
2264     key => 'border_spacing_x',
2265     parse => $Prop->{'letter-spacing'}->{parse},
2266     #allow_negative => 0,
2267     #keyword => {},
2268     serialize => $default_serializer,
2269 wakaba 1.25 serialize_multiple => sub {
2270     my $self = shift;
2271    
2272     local $Error::Depth = $Error::Depth + 1;
2273     my $x = $self->_manakai_border_spacing_x;
2274     my $y = $self->_manakai_border_spacing_y;
2275     my $xi = $self->get_property_priority ('-manakai-border-spacing-x');
2276     my $yi = $self->get_property_priority ('-manakai-border-spacing-y');
2277 wakaba 1.34 if (length $x) {
2278     if (length $y) {
2279 wakaba 1.26 if ($xi eq $yi) {
2280 wakaba 1.25 if ($x eq $y) {
2281 wakaba 1.43 return {'border-spacing' => [$x, $xi]};
2282 wakaba 1.25 } else {
2283 wakaba 1.43 return {'border-spacing' => [$x . ' ' . $y, $xi]};
2284 wakaba 1.25 }
2285     } else {
2286 wakaba 1.43 return {'-manakai-border-spacing-x' => [$x, $xi],
2287     '-manakai-border-spacing-y' => [$y, $yi]};
2288 wakaba 1.25 }
2289     } else {
2290 wakaba 1.43 return {'-manakai-border-spacing-x' => [$x, $xi]};
2291 wakaba 1.25 }
2292     } else {
2293 wakaba 1.34 if (length $y) {
2294 wakaba 1.43 return {'-manakai-border-spacing-y' => [$y, $yi]};
2295 wakaba 1.25 } else {
2296     return {};
2297     }
2298     }
2299     },
2300 wakaba 1.24 initial => ['DIMENSION', 0, 'px'],
2301     inherited => 1,
2302     compute => $compute_length,
2303     };
2304     $Attr->{_manakai_border_spacing_x} = $Prop->{'-manakai-border-spacing-x'};
2305     $Key->{border_spacing_x} = $Prop->{'-manakai-border-spacing-x'};
2306    
2307     $Prop->{'-manakai-border-spacing-y'} = {
2308     css => '-manakai-border-spacing-y',
2309     dom => '_manakai_border_spacing_y',
2310     key => 'border_spacing_y',
2311     parse => $Prop->{'letter-spacing'}->{parse},
2312     #allow_negative => 0,
2313     #keyword => {},
2314     serialize => $default_serializer,
2315 wakaba 1.25 serialize_multiple => $Prop->{'-manakai-border-spacing-x'}
2316     ->{serialize_multiple},
2317 wakaba 1.24 initial => ['DIMENSION', 0, 'px'],
2318     inherited => 1,
2319     compute => $compute_length,
2320     };
2321     $Attr->{_manakai_border_spacing_y} = $Prop->{'-manakai-border-spacing-y'};
2322     $Key->{border_spacing_y} = $Prop->{'-manakai-border-spacing-y'};
2323    
2324 wakaba 1.19 $Prop->{'margin-top'} = {
2325     css => 'margin-top',
2326     dom => 'margin_top',
2327     key => 'margin_top',
2328     parse => sub {
2329     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2330    
2331 wakaba 1.21 ## NOTE: Used for 'margin-top', 'margin-right', 'margin-bottom',
2332 wakaba 1.22 ## 'margin-left', 'top', 'right', 'bottom', 'left', 'padding-top',
2333     ## 'padding-right', 'padding-bottom', 'padding-left',
2334     ## 'border-top-width', 'border-right-width', 'border-bottom-width',
2335 wakaba 1.27 ## 'border-left-width', 'text-indent', 'background-position-x',
2336     ## and 'background-position-y'.
2337 wakaba 1.21
2338 wakaba 1.19 my $sign = 1;
2339 wakaba 1.41 my $has_sign;
2340 wakaba 1.19 if ($t->{type} == MINUS_TOKEN) {
2341     $t = $tt->get_next_token;
2342 wakaba 1.41 $has_sign = 1;
2343 wakaba 1.19 $sign = -1;
2344 wakaba 1.41 } elsif ($t->{type} == PLUS_TOKEN) {
2345     $t = $tt->get_next_token;
2346     $has_sign = 1;
2347 wakaba 1.19 }
2348 wakaba 1.22 my $allow_negative = $Prop->{$prop_name}->{allow_negative};
2349 wakaba 1.19
2350     if ($t->{type} == DIMENSION_TOKEN) {
2351     my $value = $t->{number} * $sign;
2352     my $unit = lc $t->{value}; ## TODO: case
2353 wakaba 1.22 if ($length_unit->{$unit} and ($allow_negative or $value >= 0)) {
2354 wakaba 1.51 $t = $tt->get_next_token;
2355 wakaba 1.19 return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2356     }
2357     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
2358     my $value = $t->{number} * $sign;
2359 wakaba 1.51 if ($allow_negative or $value >= 0) {
2360     $t = $tt->get_next_token;
2361     return ($t, {$prop_name => ['PERCENTAGE', $value]});
2362     }
2363 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
2364 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
2365     my $value = $t->{number} * $sign;
2366 wakaba 1.51 if ($allow_negative or $value >=0) {
2367     $t = $tt->get_next_token;
2368     return ($t, {$prop_name => ['DIMENSION', $value, 'px']});
2369     }
2370 wakaba 1.41 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
2371 wakaba 1.19 my $value = lc $t->{value}; ## TODO: case
2372 wakaba 1.22 if ($Prop->{$prop_name}->{keyword}->{$value}) {
2373 wakaba 1.29 $t = $tt->get_next_token;
2374 wakaba 1.19 return ($t, {$prop_name => ['KEYWORD', $value]});
2375     } elsif ($value eq 'inherit') {
2376 wakaba 1.29 $t = $tt->get_next_token;
2377 wakaba 1.19 return ($t, {$prop_name => ['INHERIT']});
2378     }
2379 wakaba 1.29 ## NOTE: In the "else" case, don't procede the |$t| pointer
2380     ## for the support of 'border-top' property (and similar ones).
2381 wakaba 1.19 }
2382    
2383 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2384 wakaba 1.19 level => $self->{must_level},
2385 wakaba 1.38 uri => \$self->{href},
2386 wakaba 1.19 token => $t);
2387     return ($t, undef);
2388     },
2389 wakaba 1.22 allow_negative => 1,
2390     keyword => {auto => 1},
2391 wakaba 1.19 serialize => $default_serializer,
2392 wakaba 1.42 serialize_multiple => sub {
2393     my $self = shift;
2394    
2395 wakaba 1.43 ## NOTE: Same as |serialize_multiple| of 'padding-top'.
2396    
2397 wakaba 1.42 my $use_shorthand = 1;
2398     my $t = $self->margin_top;
2399     undef $use_shorthand unless length $t;
2400     my $t_i = $self->get_property_priority ('margin-top');
2401     my $r = $self->margin_right;
2402     undef $use_shorthand
2403     if not length $r or
2404     ($r eq 'inherit' and $t ne 'inherit') or
2405     ($t eq 'inherit' and $r ne 'inherit');
2406     my $r_i = $self->get_property_priority ('margin-right');
2407     undef $use_shorthand unless $r_i eq $t_i;
2408     my $b = $self->margin_bottom;
2409     undef $use_shorthand
2410     if not length $b or
2411     ($b eq 'inherit' and $t ne 'inherit') or
2412     ($t eq 'inherit' and $b ne 'inherit');
2413     my $b_i = $self->get_property_priority ('margin-bottom');
2414     undef $use_shorthand unless $b_i eq $t_i;
2415     my $l = $self->margin_left;
2416     undef $use_shorthand
2417     if not length $l or
2418     ($l eq 'inherit' and $t ne 'inherit') or
2419     ($t eq 'inherit' and $l ne 'inherit');
2420     my $l_i = $self->get_property_priority ('margin-left');
2421     undef $use_shorthand unless $l_i eq $t_i;
2422    
2423     if ($use_shorthand) {
2424     $b .= ' ' . $l if $r ne $l;
2425     $r .= ' ' . $b if $t ne $b;
2426     $t .= ' ' . $r if $t ne $r;
2427 wakaba 1.45 return {margin => [$t, $t_i]};
2428 wakaba 1.42 } else {
2429     my $v = {};
2430     if (length $t) {
2431 wakaba 1.45 $v->{'margin-top'} = [$t, $t_i];
2432 wakaba 1.42 }
2433     if (length $r) {
2434 wakaba 1.45 $v->{'margin-right'} = [$r, $r_i];
2435 wakaba 1.42 }
2436     if (length $b) {
2437 wakaba 1.45 $v->{'margin-bottom'} = [$b, $b_i];
2438 wakaba 1.42 }
2439     if (length $l) {
2440 wakaba 1.45 $v->{'margin-left'} = [$l, $l_i];
2441 wakaba 1.42 }
2442     return $v;
2443     }
2444     },
2445 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2446     #inherited => 0,
2447     compute => $compute_length,
2448     };
2449     $Attr->{margin_top} = $Prop->{'margin-top'};
2450     $Key->{margin_top} = $Prop->{'margin-top'};
2451    
2452     $Prop->{'margin-bottom'} = {
2453     css => 'margin-bottom',
2454     dom => 'margin_bottom',
2455     key => 'margin_bottom',
2456     parse => $Prop->{'margin-top'}->{parse},
2457 wakaba 1.22 allow_negative => 1,
2458     keyword => {auto => 1},
2459 wakaba 1.19 serialize => $default_serializer,
2460 wakaba 1.42 serialize_multiple => $Prop->{'margin-top'}->{serialize_multiple},
2461 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2462     #inherited => 0,
2463     compute => $compute_length,
2464     };
2465     $Attr->{margin_bottom} = $Prop->{'margin-bottom'};
2466     $Key->{margin_bottom} = $Prop->{'margin-bottom'};
2467    
2468     $Prop->{'margin-right'} = {
2469     css => 'margin-right',
2470     dom => 'margin_right',
2471     key => 'margin_right',
2472     parse => $Prop->{'margin-top'}->{parse},
2473 wakaba 1.22 allow_negative => 1,
2474     keyword => {auto => 1},
2475 wakaba 1.19 serialize => $default_serializer,
2476 wakaba 1.42 serialize_multiple => $Prop->{'margin-top'}->{serialize_multiple},
2477 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2478     #inherited => 0,
2479     compute => $compute_length,
2480     };
2481     $Attr->{margin_right} = $Prop->{'margin-right'};
2482     $Key->{margin_right} = $Prop->{'margin-right'};
2483    
2484     $Prop->{'margin-left'} = {
2485     css => 'margin-left',
2486     dom => 'margin_left',
2487     key => 'margin_left',
2488     parse => $Prop->{'margin-top'}->{parse},
2489 wakaba 1.22 allow_negative => 1,
2490     keyword => {auto => 1},
2491 wakaba 1.19 serialize => $default_serializer,
2492 wakaba 1.42 serialize_multiple => $Prop->{'margin-top'}->{serialize_multiple},
2493 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2494     #inherited => 0,
2495     compute => $compute_length,
2496     };
2497     $Attr->{margin_left} = $Prop->{'margin-left'};
2498     $Key->{margin_left} = $Prop->{'margin-left'};
2499    
2500 wakaba 1.21 $Prop->{top} = {
2501     css => 'top',
2502     dom => 'top',
2503     key => 'top',
2504     parse => $Prop->{'margin-top'}->{parse},
2505 wakaba 1.22 allow_negative => 1,
2506     keyword => {auto => 1},
2507 wakaba 1.21 serialize => $default_serializer,
2508     initial => ['KEYWORD', 'auto'],
2509     #inherited => 0,
2510     compute_multiple => sub {
2511     my ($self, $element, $eid, $prop_name) = @_;
2512    
2513     my $pos_value = $self->get_computed_value ($element, 'position');
2514     if (defined $pos_value and $pos_value->[0] eq 'KEYWORD') {
2515     if ($pos_value->[1] eq 'static') {
2516     $self->{computed_value}->{$eid}->{top} = ['KEYWORD', 'auto'];
2517     $self->{computed_value}->{$eid}->{bottom} = ['KEYWORD', 'auto'];
2518     return;
2519     } elsif ($pos_value->[1] eq 'relative') {
2520     my $top_specified = $self->get_specified_value_no_inherit
2521     ($element, 'top');
2522     if (defined $top_specified and
2523     ($top_specified->[0] eq 'DIMENSION' or
2524     $top_specified->[0] eq 'PERCENTAGE')) {
2525     my $tv = $self->{computed_value}->{$eid}->{top}
2526     = $compute_length->($self, $element, 'top', $top_specified);
2527     $self->{computed_value}->{$eid}->{bottom}
2528     = [$tv->[0], -$tv->[1], $tv->[2]];
2529     } else { # top: auto
2530     my $bottom_specified = $self->get_specified_value_no_inherit
2531     ($element, 'bottom');
2532     if (defined $bottom_specified and
2533     ($bottom_specified->[0] eq 'DIMENSION' or
2534     $bottom_specified->[0] eq 'PERCENTAGE')) {
2535     my $tv = $self->{computed_value}->{$eid}->{bottom}
2536     = $compute_length->($self, $element, 'bottom',
2537     $bottom_specified);
2538     $self->{computed_value}->{$eid}->{top}
2539     = [$tv->[0], -$tv->[1], $tv->[2]];
2540     } else { # bottom: auto
2541     $self->{computed_value}->{$eid}->{top} = ['DIMENSION', 0, 'px'];
2542     $self->{computed_value}->{$eid}->{bottom} = ['DIMENSION', 0, 'px'];
2543     }
2544     }
2545     return;
2546     }
2547     }
2548    
2549     my $top_specified = $self->get_specified_value_no_inherit
2550     ($element, 'top');
2551     $self->{computed_value}->{$eid}->{top}
2552     = $compute_length->($self, $element, 'top', $top_specified);
2553     my $bottom_specified = $self->get_specified_value_no_inherit
2554     ($element, 'bottom');
2555     $self->{computed_value}->{$eid}->{bottom}
2556     = $compute_length->($self, $element, 'bottom', $bottom_specified);
2557     },
2558     };
2559     $Attr->{top} = $Prop->{top};
2560     $Key->{top} = $Prop->{top};
2561    
2562     $Prop->{bottom} = {
2563     css => 'bottom',
2564     dom => 'bottom',
2565     key => 'bottom',
2566     parse => $Prop->{'margin-top'}->{parse},
2567 wakaba 1.22 allow_negative => 1,
2568     keyword => {auto => 1},
2569 wakaba 1.21 serialize => $default_serializer,
2570     initial => ['KEYWORD', 'auto'],
2571     #inherited => 0,
2572     compute_multiple => $Prop->{top}->{compute_multiple},
2573     };
2574     $Attr->{bottom} = $Prop->{bottom};
2575     $Key->{bottom} = $Prop->{bottom};
2576    
2577     $Prop->{left} = {
2578     css => 'left',
2579     dom => 'left',
2580     key => 'left',
2581     parse => $Prop->{'margin-top'}->{parse},
2582 wakaba 1.22 allow_negative => 1,
2583     keyword => {auto => 1},
2584 wakaba 1.21 serialize => $default_serializer,
2585     initial => ['KEYWORD', 'auto'],
2586     #inherited => 0,
2587     compute_multiple => sub {
2588     my ($self, $element, $eid, $prop_name) = @_;
2589    
2590     my $pos_value = $self->get_computed_value ($element, 'position');
2591     if (defined $pos_value and $pos_value->[0] eq 'KEYWORD') {
2592     if ($pos_value->[1] eq 'static') {
2593     $self->{computed_value}->{$eid}->{left} = ['KEYWORD', 'auto'];
2594     $self->{computed_value}->{$eid}->{right} = ['KEYWORD', 'auto'];
2595     return;
2596     } elsif ($pos_value->[1] eq 'relative') {
2597     my $left_specified = $self->get_specified_value_no_inherit
2598     ($element, 'left');
2599     if (defined $left_specified and
2600     ($left_specified->[0] eq 'DIMENSION' or
2601     $left_specified->[0] eq 'PERCENTAGE')) {
2602     my $right_specified = $self->get_specified_value_no_inherit
2603     ($element, 'right');
2604     if (defined $right_specified and
2605     ($right_specified->[0] eq 'DIMENSION' or
2606     $right_specified->[0] eq 'PERCENTAGE')) {
2607     my $direction = $self->get_computed_value ($element, 'direction');
2608     if (defined $direction and $direction->[0] eq 'KEYWORD' and
2609     $direction->[0] eq 'ltr') {
2610     my $tv = $self->{computed_value}->{$eid}->{left}
2611     = $compute_length->($self, $element, 'left',
2612     $left_specified);
2613     $self->{computed_value}->{$eid}->{right}
2614     = [$tv->[0], -$tv->[1], $tv->[2]];
2615     } else {
2616     my $tv = $self->{computed_value}->{$eid}->{right}
2617     = $compute_length->($self, $element, 'right',
2618     $right_specified);
2619     $self->{computed_value}->{$eid}->{left}
2620     = [$tv->[0], -$tv->[1], $tv->[2]];
2621     }
2622     } else {
2623     my $tv = $self->{computed_value}->{$eid}->{left}
2624     = $compute_length->($self, $element, 'left', $left_specified);
2625     $self->{computed_value}->{$eid}->{right}
2626     = [$tv->[0], -$tv->[1], $tv->[2]];
2627     }
2628     } else { # left: auto
2629     my $right_specified = $self->get_specified_value_no_inherit
2630     ($element, 'right');
2631     if (defined $right_specified and
2632     ($right_specified->[0] eq 'DIMENSION' or
2633     $right_specified->[0] eq 'PERCENTAGE')) {
2634     my $tv = $self->{computed_value}->{$eid}->{right}
2635     = $compute_length->($self, $element, 'right',
2636     $right_specified);
2637     $self->{computed_value}->{$eid}->{left}
2638     = [$tv->[0], -$tv->[1], $tv->[2]];
2639     } else { # right: auto
2640     $self->{computed_value}->{$eid}->{left} = ['DIMENSION', 0, 'px'];
2641     $self->{computed_value}->{$eid}->{right} = ['DIMENSION', 0, 'px'];
2642     }
2643     }
2644     return;
2645     }
2646     }
2647    
2648     my $left_specified = $self->get_specified_value_no_inherit
2649     ($element, 'left');
2650     $self->{computed_value}->{$eid}->{left}
2651     = $compute_length->($self, $element, 'left', $left_specified);
2652     my $right_specified = $self->get_specified_value_no_inherit
2653     ($element, 'right');
2654     $self->{computed_value}->{$eid}->{right}
2655     = $compute_length->($self, $element, 'right', $right_specified);
2656     },
2657     };
2658     $Attr->{left} = $Prop->{left};
2659     $Key->{left} = $Prop->{left};
2660    
2661     $Prop->{right} = {
2662     css => 'right',
2663     dom => 'right',
2664     key => 'right',
2665     parse => $Prop->{'margin-top'}->{parse},
2666 wakaba 1.51 allow_negative => 1,
2667     keyword => {auto => 1},
2668 wakaba 1.21 serialize => $default_serializer,
2669     initial => ['KEYWORD', 'auto'],
2670     #inherited => 0,
2671     compute_multiple => $Prop->{left}->{compute_multiple},
2672     };
2673     $Attr->{right} = $Prop->{right};
2674     $Key->{right} = $Prop->{right};
2675    
2676 wakaba 1.22 $Prop->{width} = {
2677     css => 'width',
2678     dom => 'width',
2679     key => 'width',
2680     parse => $Prop->{'margin-top'}->{parse},
2681     #allow_negative => 0,
2682     keyword => {auto => 1},
2683     serialize => $default_serializer,
2684     initial => ['KEYWORD', 'auto'],
2685     #inherited => 0,
2686     compute => $compute_length,
2687     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/width> for
2688     ## browser compatibility issues.
2689     };
2690     $Attr->{width} = $Prop->{width};
2691     $Key->{width} = $Prop->{width};
2692    
2693     $Prop->{'min-width'} = {
2694     css => 'min-width',
2695     dom => 'min_width',
2696     key => 'min_width',
2697     parse => $Prop->{'margin-top'}->{parse},
2698     #allow_negative => 0,
2699     #keyword => {},
2700     serialize => $default_serializer,
2701     initial => ['DIMENSION', 0, 'px'],
2702     #inherited => 0,
2703     compute => $compute_length,
2704     };
2705     $Attr->{min_width} = $Prop->{'min-width'};
2706     $Key->{min_width} = $Prop->{'min-width'};
2707    
2708     $Prop->{'max-width'} = {
2709     css => 'max-width',
2710     dom => 'max_width',
2711     key => 'max_width',
2712     parse => $Prop->{'margin-top'}->{parse},
2713     #allow_negative => 0,
2714     keyword => {none => 1},
2715     serialize => $default_serializer,
2716     initial => ['KEYWORD', 'none'],
2717     #inherited => 0,
2718     compute => $compute_length,
2719     };
2720     $Attr->{max_width} = $Prop->{'max-width'};
2721     $Key->{max_width} = $Prop->{'max-width'};
2722    
2723     $Prop->{height} = {
2724     css => 'height',
2725     dom => 'height',
2726     key => 'height',
2727     parse => $Prop->{'margin-top'}->{parse},
2728     #allow_negative => 0,
2729     keyword => {auto => 1},
2730     serialize => $default_serializer,
2731     initial => ['KEYWORD', 'auto'],
2732     #inherited => 0,
2733     compute => $compute_length,
2734     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/height> for
2735     ## browser compatibility issues.
2736     };
2737     $Attr->{height} = $Prop->{height};
2738     $Key->{height} = $Prop->{height};
2739    
2740     $Prop->{'min-height'} = {
2741     css => 'min-height',
2742     dom => 'min_height',
2743     key => 'min_height',
2744     parse => $Prop->{'margin-top'}->{parse},
2745     #allow_negative => 0,
2746     #keyword => {},
2747     serialize => $default_serializer,
2748     initial => ['DIMENSION', 0, 'px'],
2749     #inherited => 0,
2750     compute => $compute_length,
2751     };
2752     $Attr->{min_height} = $Prop->{'min-height'};
2753     $Key->{min_height} = $Prop->{'min-height'};
2754    
2755     $Prop->{'max-height'} = {
2756     css => 'max-height',
2757     dom => 'max_height',
2758     key => 'max_height',
2759     parse => $Prop->{'margin-top'}->{parse},
2760     #allow_negative => 0,
2761     keyword => {none => 1},
2762     serialize => $default_serializer,
2763     initial => ['KEYWORD', 'none'],
2764     #inherited => 0,
2765     compute => $compute_length,
2766     };
2767     $Attr->{max_height} = $Prop->{'max-height'};
2768     $Key->{max_height} = $Prop->{'max-height'};
2769    
2770     $Prop->{'line-height'} = {
2771     css => 'line-height',
2772     dom => 'line_height',
2773     key => 'line_height',
2774 wakaba 1.19 parse => sub {
2775     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2776    
2777 wakaba 1.22 ## NOTE: Similar to 'margin-top', but different handling
2778     ## for unitless numbers.
2779    
2780 wakaba 1.51 my $has_sign;
2781 wakaba 1.19 my $sign = 1;
2782     if ($t->{type} == MINUS_TOKEN) {
2783     $t = $tt->get_next_token;
2784     $sign = -1;
2785 wakaba 1.51 $has_sign = 1;
2786     } elsif ($t->{type} == PLUS_TOKEN) {
2787     $t = $tt->get_next_token;
2788     $has_sign = 1;
2789 wakaba 1.19 }
2790    
2791     if ($t->{type} == DIMENSION_TOKEN) {
2792     my $value = $t->{number} * $sign;
2793     my $unit = lc $t->{value}; ## TODO: case
2794     if ($length_unit->{$unit} and $value >= 0) {
2795 wakaba 1.51 $t = $tt->get_next_token;
2796 wakaba 1.19 return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2797     }
2798     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
2799     my $value = $t->{number} * $sign;
2800 wakaba 1.51 if ($value >= 0) {
2801     $t = $tt->get_next_token;
2802     return ($t, {$prop_name => ['PERCENTAGE', $value]});
2803     }
2804 wakaba 1.22 } elsif ($t->{type} == NUMBER_TOKEN) {
2805 wakaba 1.19 my $value = $t->{number} * $sign;
2806 wakaba 1.51 if ($value >= 0) {
2807     $t = $tt->get_next_token;
2808     return ($t, {$prop_name => ['NUMBER', $value]});
2809     }
2810     } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
2811 wakaba 1.19 my $value = lc $t->{value}; ## TODO: case
2812 wakaba 1.22 if ($value eq 'normal') {
2813 wakaba 1.51 $t = $tt->get_next_token;
2814 wakaba 1.22 return ($t, {$prop_name => ['KEYWORD', $value]});
2815     } elsif ($value eq 'inherit') {
2816 wakaba 1.51 $t = $tt->get_next_token;
2817 wakaba 1.19 return ($t, {$prop_name => ['INHERIT']});
2818     }
2819     }
2820    
2821 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2822 wakaba 1.19 level => $self->{must_level},
2823 wakaba 1.38 uri => \$self->{href},
2824 wakaba 1.19 token => $t);
2825     return ($t, undef);
2826     },
2827     serialize => $default_serializer,
2828 wakaba 1.22 initial => ['KEYWORD', 'normal'],
2829     inherited => 1,
2830     compute => $compute_length,
2831     };
2832     $Attr->{line_height} = $Prop->{'line-height'};
2833     $Key->{line_height} = $Prop->{'line-height'};
2834    
2835     $Prop->{'vertical-align'} = {
2836     css => 'vertical-align',
2837     dom => 'vertical_align',
2838     key => 'vertical_align',
2839     parse => $Prop->{'margin-top'}->{parse},
2840     allow_negative => 1,
2841     keyword => {
2842     baseline => 1, sub => 1, super => 1, top => 1, 'text-top' => 1,
2843     middle => 1, bottom => 1, 'text-bottom' => 1,
2844     },
2845     ## NOTE: Currently, we don't support option to select subset of keywords
2846     ## supported by application (i.e.
2847     ## $parser->{prop_value}->{'line-height'->{$keyword}). Should we support
2848     ## it?
2849     serialize => $default_serializer,
2850     initial => ['KEYWORD', 'baseline'],
2851     #inherited => 0,
2852     compute => $compute_length,
2853     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/vertical-align> for
2854     ## browser compatibility issues.
2855     };
2856     $Attr->{vertical_align} = $Prop->{'vertical-align'};
2857     $Key->{vertical_align} = $Prop->{'vertical-align'};
2858    
2859 wakaba 1.23 $Prop->{'text-indent'} = {
2860     css => 'text-indent',
2861     dom => 'text_indent',
2862     key => 'text_indent',
2863     parse => $Prop->{'margin-top'}->{parse},
2864     allow_negative => 1,
2865     keyword => {},
2866     serialize => $default_serializer,
2867     initial => ['DIMENSION', 0, 'px'],
2868     inherited => 1,
2869     compute => $compute_length,
2870     };
2871     $Attr->{text_indent} = $Prop->{'text-indent'};
2872     $Key->{text_indent} = $Prop->{'text-indent'};
2873    
2874 wakaba 1.27 $Prop->{'background-position-x'} = {
2875     css => 'background-position-x',
2876     dom => 'background_position_x',
2877     key => 'background_position_x',
2878     parse => $Prop->{'margin-top'}->{parse},
2879     allow_negative => 1,
2880     keyword => {left => 1, center => 1, right => 1},
2881     serialize => $default_serializer,
2882     initial => ['PERCENTAGE', 0],
2883     #inherited => 0,
2884     compute => sub {
2885     my ($self, $element, $prop_name, $specified_value) = @_;
2886    
2887     if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
2888     my $v = {
2889     left => 0, center => 50, right => 100, top => 0, bottom => 100,
2890     }->{$specified_value->[1]};
2891     if (defined $v) {
2892     return ['PERCENTAGE', $v];
2893     } else {
2894     return $specified_value;
2895     }
2896     } else {
2897     return $compute_length->(@_);
2898     }
2899     },
2900 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
2901 wakaba 1.27 };
2902     $Attr->{background_position_x} = $Prop->{'background-position-x'};
2903     $Key->{background_position_x} = $Prop->{'background-position-x'};
2904    
2905     $Prop->{'background-position-y'} = {
2906     css => 'background-position-y',
2907     dom => 'background_position_y',
2908     key => 'background_position_y',
2909     parse => $Prop->{'margin-top'}->{parse},
2910     allow_negative => 1,
2911     keyword => {top => 1, center => 1, bottom => 1},
2912     serialize => $default_serializer,
2913 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
2914 wakaba 1.27 initial => ['PERCENTAGE', 0],
2915     #inherited => 0,
2916     compute => $Prop->{'background-position-x'}->{compute},
2917     };
2918     $Attr->{background_position_y} = $Prop->{'background-position-y'};
2919     $Key->{background_position_y} = $Prop->{'background-position-y'};
2920    
2921 wakaba 1.22 $Prop->{'padding-top'} = {
2922     css => 'padding-top',
2923     dom => 'padding_top',
2924     key => 'padding_top',
2925     parse => $Prop->{'margin-top'}->{parse},
2926     #allow_negative => 0,
2927     #keyword => {},
2928     serialize => $default_serializer,
2929 wakaba 1.43 serialize_multiple => sub {
2930     my $self = shift;
2931    
2932     ## NOTE: Same as |serialize_multiple| of 'margin-top'.
2933    
2934     my $use_shorthand = 1;
2935     my $t = $self->padding_top;
2936     undef $use_shorthand unless length $t;
2937     my $t_i = $self->get_property_priority ('padding-top');
2938     my $r = $self->padding_right;
2939     undef $use_shorthand
2940     if not length $r or
2941     ($r eq 'inherit' and $t ne 'inherit') or
2942     ($t eq 'inherit' and $r ne 'inherit');
2943     my $r_i = $self->get_property_priority ('padding-right');
2944     undef $use_shorthand unless $r_i eq $t_i;
2945     my $b = $self->padding_bottom;
2946     undef $use_shorthand
2947     if not length $b or
2948     ($b eq 'inherit' and $t ne 'inherit') or
2949     ($t eq 'inherit' and $b ne 'inherit');
2950     my $b_i = $self->get_property_priority ('padding-bottom');
2951     undef $use_shorthand unless $b_i eq $t_i;
2952     my $l = $self->padding_left;
2953     undef $use_shorthand
2954     if not length $l or
2955     ($l eq 'inherit' and $t ne 'inherit') or
2956     ($t eq 'inherit' and $l ne 'inherit');
2957     my $l_i = $self->get_property_priority ('padding-left');
2958     undef $use_shorthand unless $l_i eq $t_i;
2959    
2960     if ($use_shorthand) {
2961     $b .= ' ' . $l if $r ne $l;
2962     $r .= ' ' . $b if $t ne $b;
2963     $t .= ' ' . $r if $t ne $r;
2964 wakaba 1.45 return {padding => [$t, $t_i]};
2965 wakaba 1.43 } else {
2966     my $v = {};
2967     if (length $t) {
2968 wakaba 1.45 $v->{'padding-top'} = [$t, $t_i];
2969 wakaba 1.43 }
2970     if (length $r) {
2971 wakaba 1.45 $v->{'padding-right'} = [$r, $r_i];
2972 wakaba 1.43 }
2973     if (length $b) {
2974 wakaba 1.45 $v->{'padding-bottom'} = [$b, $b_i];
2975 wakaba 1.43 }
2976     if (length $l) {
2977 wakaba 1.45 $v->{'padding-left'} = [$l, $l_i];
2978 wakaba 1.43 }
2979     return $v;
2980     }
2981     },
2982 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2983     #inherited => 0,
2984     compute => $compute_length,
2985     };
2986     $Attr->{padding_top} = $Prop->{'padding-top'};
2987     $Key->{padding_top} = $Prop->{'padding-top'};
2988    
2989     $Prop->{'padding-bottom'} = {
2990     css => 'padding-bottom',
2991     dom => 'padding_bottom',
2992     key => 'padding_bottom',
2993     parse => $Prop->{'padding-top'}->{parse},
2994 wakaba 1.22 #allow_negative => 0,
2995     #keyword => {},
2996 wakaba 1.19 serialize => $default_serializer,
2997 wakaba 1.43 serialize_multiple => $Prop->{'padding-top'}->{serialize_multiple},
2998 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2999     #inherited => 0,
3000     compute => $compute_length,
3001     };
3002     $Attr->{padding_bottom} = $Prop->{'padding-bottom'};
3003     $Key->{padding_bottom} = $Prop->{'padding-bottom'};
3004    
3005     $Prop->{'padding-right'} = {
3006     css => 'padding-right',
3007     dom => 'padding_right',
3008     key => 'padding_right',
3009     parse => $Prop->{'padding-top'}->{parse},
3010 wakaba 1.22 #allow_negative => 0,
3011     #keyword => {},
3012 wakaba 1.19 serialize => $default_serializer,
3013 wakaba 1.43 serialize_multiple => $Prop->{'padding-top'}->{serialize_multiple},
3014 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
3015     #inherited => 0,
3016     compute => $compute_length,
3017     };
3018     $Attr->{padding_right} = $Prop->{'padding-right'};
3019     $Key->{padding_right} = $Prop->{'padding-right'};
3020    
3021     $Prop->{'padding-left'} = {
3022     css => 'padding-left',
3023     dom => 'padding_left',
3024     key => 'padding_left',
3025     parse => $Prop->{'padding-top'}->{parse},
3026 wakaba 1.22 #allow_negative => 0,
3027     #keyword => {},
3028 wakaba 1.19 serialize => $default_serializer,
3029 wakaba 1.43 serialize_multiple => $Prop->{'padding-top'}->{serialize_multiple},
3030 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
3031     #inherited => 0,
3032     compute => $compute_length,
3033     };
3034     $Attr->{padding_left} = $Prop->{'padding-left'};
3035     $Key->{padding_left} = $Prop->{'padding-left'};
3036    
3037 wakaba 1.20 $Prop->{'border-top-width'} = {
3038     css => 'border-top-width',
3039     dom => 'border_top_width',
3040     key => 'border_top_width',
3041 wakaba 1.22 parse => $Prop->{'margin-top'}->{parse},
3042     #allow_negative => 0,
3043     keyword => {thin => 1, medium => 1, thick => 1},
3044 wakaba 1.20 serialize => $default_serializer,
3045 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3046 wakaba 1.20 initial => ['KEYWORD', 'medium'],
3047     #inherited => 0,
3048     compute => sub {
3049     my ($self, $element, $prop_name, $specified_value) = @_;
3050    
3051 wakaba 1.23 ## NOTE: Used for 'border-top-width', 'border-right-width',
3052     ## 'border-bottom-width', 'border-right-width', and
3053     ## 'outline-width'.
3054    
3055 wakaba 1.20 my $style_prop = $prop_name;
3056     $style_prop =~ s/width/style/;
3057     my $style = $self->get_computed_value ($element, $style_prop);
3058     if (defined $style and $style->[0] eq 'KEYWORD' and
3059     ($style->[1] eq 'none' or $style->[1] eq 'hidden')) {
3060     return ['DIMENSION', 0, 'px'];
3061     }
3062    
3063     my $value = $compute_length->(@_);
3064     if (defined $value and $value->[0] eq 'KEYWORD') {
3065     if ($value->[1] eq 'thin') {
3066     return ['DIMENSION', 1, 'px']; ## Firefox/Opera
3067     } elsif ($value->[1] eq 'medium') {
3068     return ['DIMENSION', 3, 'px']; ## Firefox/Opera
3069     } elsif ($value->[1] eq 'thick') {
3070     return ['DIMENSION', 5, 'px']; ## Firefox
3071     }
3072     }
3073     return $value;
3074     },
3075 wakaba 1.23 ## NOTE: CSS3 will allow <percentage> as an option in <border-width>.
3076     ## Opera 9 has already implemented it.
3077 wakaba 1.20 };
3078     $Attr->{border_top_width} = $Prop->{'border-top-width'};
3079     $Key->{border_top_width} = $Prop->{'border-top-width'};
3080    
3081     $Prop->{'border-right-width'} = {
3082     css => 'border-right-width',
3083     dom => 'border_right_width',
3084     key => 'border_right_width',
3085     parse => $Prop->{'border-top-width'}->{parse},
3086 wakaba 1.22 #allow_negative => 0,
3087     keyword => {thin => 1, medium => 1, thick => 1},
3088 wakaba 1.20 serialize => $default_serializer,
3089 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3090 wakaba 1.20 initial => ['KEYWORD', 'medium'],
3091     #inherited => 0,
3092     compute => $Prop->{'border-top-width'}->{compute},
3093     };
3094     $Attr->{border_right_width} = $Prop->{'border-right-width'};
3095     $Key->{border_right_width} = $Prop->{'border-right-width'};
3096    
3097     $Prop->{'border-bottom-width'} = {
3098     css => 'border-bottom-width',
3099     dom => 'border_bottom_width',
3100     key => 'border_bottom_width',
3101     parse => $Prop->{'border-top-width'}->{parse},
3102 wakaba 1.22 #allow_negative => 0,
3103     keyword => {thin => 1, medium => 1, thick => 1},
3104 wakaba 1.20 serialize => $default_serializer,
3105 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3106 wakaba 1.20 initial => ['KEYWORD', 'medium'],
3107     #inherited => 0,
3108     compute => $Prop->{'border-top-width'}->{compute},
3109     };
3110     $Attr->{border_bottom_width} = $Prop->{'border-bottom-width'};
3111     $Key->{border_bottom_width} = $Prop->{'border-bottom-width'};
3112    
3113     $Prop->{'border-left-width'} = {
3114     css => 'border-left-width',
3115     dom => 'border_left_width',
3116     key => 'border_left_width',
3117     parse => $Prop->{'border-top-width'}->{parse},
3118 wakaba 1.22 #allow_negative => 0,
3119     keyword => {thin => 1, medium => 1, thick => 1},
3120 wakaba 1.20 serialize => $default_serializer,
3121 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3122 wakaba 1.20 initial => ['KEYWORD', 'medium'],
3123     #inherited => 0,
3124     compute => $Prop->{'border-top-width'}->{compute},
3125     };
3126     $Attr->{border_left_width} = $Prop->{'border-left-width'};
3127     $Key->{border_left_width} = $Prop->{'border-left-width'};
3128    
3129 wakaba 1.23 $Prop->{'outline-width'} = {
3130     css => 'outline-width',
3131     dom => 'outline_width',
3132     key => 'outline_width',
3133     parse => $Prop->{'border-top-width'}->{parse},
3134     #allow_negative => 0,
3135     keyword => {thin => 1, medium => 1, thick => 1},
3136     serialize => $default_serializer,
3137 wakaba 1.29 serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
3138 wakaba 1.23 initial => ['KEYWORD', 'medium'],
3139     #inherited => 0,
3140     compute => $Prop->{'border-top-width'}->{compute},
3141     };
3142     $Attr->{outline_width} = $Prop->{'outline-width'};
3143     $Key->{outline_width} = $Prop->{'outline-width'};
3144    
3145 wakaba 1.15 $Prop->{'font-weight'} = {
3146     css => 'font-weight',
3147     dom => 'font_weight',
3148     key => 'font_weight',
3149     parse => sub {
3150     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3151    
3152 wakaba 1.50 my $has_sign;
3153     if ($t->{type} == PLUS_TOKEN) {
3154     $has_sign = 1;
3155     $t = $tt->get_next_token;
3156     }
3157    
3158 wakaba 1.15 if ($t->{type} == NUMBER_TOKEN) {
3159     ## ISSUE: See <http://suika.fam.cx/gate/2005/sw/font-weight> for
3160     ## browser compatibility issue.
3161     my $value = $t->{number};
3162     $t = $tt->get_next_token;
3163     if ($value % 100 == 0 and 100 <= $value and $value <= 900) {
3164     return ($t, {$prop_name => ['WEIGHT', $value, 0]});
3165     }
3166 wakaba 1.50 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
3167 wakaba 1.15 my $value = lc $t->{value}; ## TODO: case
3168     if ({
3169     normal => 1, bold => 1, bolder => 1, lighter => 1,
3170     }->{$value}) {
3171 wakaba 1.50 $t = $tt->get_next_token;
3172 wakaba 1.15 return ($t, {$prop_name => ['KEYWORD', $value]});
3173     } elsif ($value eq 'inherit') {
3174 wakaba 1.50 $t = $tt->get_next_token;
3175 wakaba 1.15 return ($t, {$prop_name => ['INHERIT']});
3176     }
3177     }
3178    
3179 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3180 wakaba 1.15 level => $self->{must_level},
3181 wakaba 1.38 uri => \$self->{href},
3182 wakaba 1.15 token => $t);
3183     return ($t, undef);
3184     },
3185     serialize => $default_serializer,
3186     initial => ['KEYWORD', 'normal'],
3187     inherited => 1,
3188     compute => sub {
3189     my ($self, $element, $prop_name, $specified_value) = @_;
3190    
3191 wakaba 1.17 if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
3192 wakaba 1.15 if ($specified_value->[1] eq 'normal') {
3193     return ['WEIGHT', 400, 0];
3194     } elsif ($specified_value->[1] eq 'bold') {
3195     return ['WEIGHT', 700, 0];
3196     } elsif ($specified_value->[1] eq 'bolder') {
3197     my $parent_element = $element->manakai_parent_element;
3198     if (defined $parent_element) {
3199     my $parent_value = $self->get_cascaded_value
3200     ($parent_element, $prop_name); ## NOTE: What Firefox does.
3201     return ['WEIGHT', $parent_value->[1], $parent_value->[2] + 1];
3202     } else {
3203     return ['WEIGHT', 400, 1];
3204     }
3205     } elsif ($specified_value->[1] eq 'lighter') {
3206     my $parent_element = $element->manakai_parent_element;
3207     if (defined $parent_element) {
3208     my $parent_value = $self->get_cascaded_value
3209     ($parent_element, $prop_name); ## NOTE: What Firefox does.
3210     return ['WEIGHT', $parent_value->[1], $parent_value->[2] - 1];
3211     } else {
3212     return ['WEIGHT', 400, 1];
3213     }
3214     }
3215 wakaba 1.17 #} elsif (defined $specified_value and $specified_value->[0] eq 'WEIGHT') {
3216 wakaba 1.15 #
3217     }
3218    
3219     return $specified_value;
3220     },
3221     };
3222     $Attr->{font_weight} = $Prop->{'font-weight'};
3223     $Key->{font_weight} = $Prop->{'font-weight'};
3224    
3225 wakaba 1.13 my $uri_or_none_parser = sub {
3226 wakaba 1.11 my ($self, $prop_name, $tt, $t, $onerror) = @_;
3227    
3228 wakaba 1.13 if ($t->{type} == URI_TOKEN) {
3229 wakaba 1.11 my $value = $t->{value};
3230     $t = $tt->get_next_token;
3231     return ($t, {$prop_name => ['URI', $value, \($self->{base_uri})]});
3232     } elsif ($t->{type} == IDENT_TOKEN) {
3233     my $value = lc $t->{value}; ## TODO: case
3234     $t = $tt->get_next_token;
3235     if ($value eq 'none') {
3236     ## NOTE: |none| is the default value and therefore it must be
3237     ## supported anyway.
3238     return ($t, {$prop_name => ["KEYWORD", 'none']});
3239     } elsif ($value eq 'inherit') {
3240     return ($t, {$prop_name => ['INHERIT']});
3241     }
3242     ## NOTE: None of Firefox2, WinIE6, and Opera9 support this case.
3243     #} elsif ($t->{type} == URI_INVALID_TOKEN) {
3244     # my $value = $t->{value};
3245     # $t = $tt->get_next_token;
3246     # if ($t->{type} == EOF_TOKEN) {
3247 wakaba 1.39 # $onerror->(type => 'uri not closed',
3248 wakaba 1.11 # level => $self->{must_level},
3249 wakaba 1.38 # uri => \$self->{href},
3250 wakaba 1.11 # token => $t);
3251     #
3252     # return ($t, {$prop_name => ['URI', $value, \($self->{base_uri})]});
3253     # }
3254     }
3255    
3256 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3257 wakaba 1.11 level => $self->{must_level},
3258 wakaba 1.38 uri => \$self->{href},
3259 wakaba 1.11 token => $t);
3260     return ($t, undef);
3261 wakaba 1.13 }; # $uri_or_none_parser
3262    
3263 wakaba 1.14 my $compute_uri_or_none = sub {
3264 wakaba 1.11 my ($self, $element, $prop_name, $specified_value) = @_;
3265    
3266     if (defined $specified_value and
3267     $specified_value->[0] eq 'URI' and
3268     defined $specified_value->[2]) {
3269     require Message::DOM::DOMImplementation;
3270     return ['URI',
3271     Message::DOM::DOMImplementation->create_uri_reference
3272     ($specified_value->[1])
3273     ->get_absolute_reference (${$specified_value->[2]})
3274     ->get_uri_reference,
3275     $specified_value->[2]];
3276     }
3277    
3278     return $specified_value;
3279 wakaba 1.14 }; # $compute_uri_or_none
3280    
3281     $Prop->{'list-style-image'} = {
3282     css => 'list-style-image',
3283     dom => 'list_style_image',
3284     key => 'list_style_image',
3285     parse => $uri_or_none_parser,
3286     serialize => $default_serializer,
3287     initial => ['KEYWORD', 'none'],
3288     inherited => 1,
3289     compute => $compute_uri_or_none,
3290 wakaba 1.11 };
3291     $Attr->{list_style_image} = $Prop->{'list-style-image'};
3292     $Key->{list_style_image} = $Prop->{'list-style-image'};
3293    
3294 wakaba 1.15 $Prop->{'background-image'} = {
3295     css => 'background-image',
3296     dom => 'background_image',
3297     key => 'background_image',
3298     parse => $uri_or_none_parser,
3299     serialize => $default_serializer,
3300 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
3301 wakaba 1.15 initial => ['KEYWORD', 'none'],
3302     #inherited => 0,
3303     compute => $compute_uri_or_none,
3304     };
3305     $Attr->{background_image} = $Prop->{'background-image'};
3306     $Key->{background_image} = $Prop->{'background-image'};
3307    
3308 wakaba 1.7 my $border_style_keyword = {
3309     none => 1, hidden => 1, dotted => 1, dashed => 1, solid => 1,
3310     double => 1, groove => 1, ridge => 1, inset => 1, outset => 1,
3311     };
3312    
3313     $Prop->{'border-top-style'} = {
3314     css => 'border-top-style',
3315     dom => 'border_top_style',
3316     key => 'border_top_style',
3317     parse => $one_keyword_parser,
3318 wakaba 1.11 serialize => $default_serializer,
3319 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3320 wakaba 1.7 keyword => $border_style_keyword,
3321 wakaba 1.9 initial => ["KEYWORD", "none"],
3322     #inherited => 0,
3323     compute => $compute_as_specified,
3324 wakaba 1.7 };
3325     $Attr->{border_top_style} = $Prop->{'border-top-style'};
3326     $Key->{border_top_style} = $Prop->{'border-top-style'};
3327    
3328     $Prop->{'border-right-style'} = {
3329     css => 'border-right-style',
3330     dom => 'border_right_style',
3331     key => 'border_right_style',
3332     parse => $one_keyword_parser,
3333 wakaba 1.11 serialize => $default_serializer,
3334 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3335 wakaba 1.7 keyword => $border_style_keyword,
3336 wakaba 1.9 initial => ["KEYWORD", "none"],
3337     #inherited => 0,
3338     compute => $compute_as_specified,
3339 wakaba 1.7 };
3340     $Attr->{border_right_style} = $Prop->{'border-right-style'};
3341     $Key->{border_right_style} = $Prop->{'border-right-style'};
3342    
3343     $Prop->{'border-bottom-style'} = {
3344     css => 'border-bottom-style',
3345     dom => 'border_bottom_style',
3346     key => 'border_bottom_style',
3347     parse => $one_keyword_parser,
3348 wakaba 1.11 serialize => $default_serializer,
3349 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3350 wakaba 1.7 keyword => $border_style_keyword,
3351 wakaba 1.9 initial => ["KEYWORD", "none"],
3352     #inherited => 0,
3353     compute => $compute_as_specified,
3354 wakaba 1.7 };
3355     $Attr->{border_bottom_style} = $Prop->{'border-bottom-style'};
3356     $Key->{border_bottom_style} = $Prop->{'border-bottom-style'};
3357    
3358     $Prop->{'border-left-style'} = {
3359     css => 'border-left-style',
3360     dom => 'border_left_style',
3361     key => 'border_left_style',
3362     parse => $one_keyword_parser,
3363 wakaba 1.11 serialize => $default_serializer,
3364 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3365 wakaba 1.7 keyword => $border_style_keyword,
3366 wakaba 1.9 initial => ["KEYWORD", "none"],
3367     #inherited => 0,
3368     compute => $compute_as_specified,
3369 wakaba 1.7 };
3370     $Attr->{border_left_style} = $Prop->{'border-left-style'};
3371     $Key->{border_left_style} = $Prop->{'border-left-style'};
3372    
3373 wakaba 1.16 $Prop->{'outline-style'} = {
3374     css => 'outline-style',
3375     dom => 'outline_style',
3376     key => 'outline_style',
3377     parse => $one_keyword_parser,
3378     serialize => $default_serializer,
3379 wakaba 1.29 serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
3380 wakaba 1.23 keyword => {%$border_style_keyword},
3381 wakaba 1.16 initial => ['KEYWORD', 'none'],
3382     #inherited => 0,
3383     compute => $compute_as_specified,
3384     };
3385     $Attr->{outline_style} = $Prop->{'outline-style'};
3386     $Key->{outline_style} = $Prop->{'outline-style'};
3387 wakaba 1.23 delete $Prop->{'outline-style'}->{keyword}->{hidden};
3388 wakaba 1.16
3389 wakaba 1.44 my $generic_font_keywords = {
3390 wakaba 1.31 serif => 1, 'sans-serif' => 1, cursive => 1,
3391     fantasy => 1, monospace => 1, '-manakai-default' => 1,
3392     '-manakai-caption' => 1, '-manakai-icon' => 1,
3393     '-manakai-menu' => 1, '-manakai-message-box' => 1,
3394     '-manakai-small-caption' => 1, '-manakai-status-bar' => 1,
3395     };
3396     ## NOTE: "All five generic font families are defined to exist in all CSS
3397     ## implementations (they need not necessarily map to five distinct actual
3398     ## fonts)." [CSS 2.1].
3399     ## NOTE: "If no font with the indicated characteristics exists on a given
3400     ## platform, the user agent should either intelligently substitute (e.g., a
3401     ## smaller version of the 'caption' font might be used for the 'small-caption'
3402     ## font), or substitute a user agent default font." [CSS 2.1].
3403    
3404 wakaba 1.15 $Prop->{'font-family'} = {
3405     css => 'font-family',
3406     dom => 'font_family',
3407     key => 'font_family',
3408     parse => sub {
3409     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3410    
3411     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/font-family> for
3412     ## how chaotic browsers are!
3413    
3414     my @prop_value;
3415    
3416     my $font_name = '';
3417     my $may_be_generic = 1;
3418 wakaba 1.31 my $may_be_inherit = ($prop_name ne 'font');
3419 wakaba 1.15 my $has_s = 0;
3420     F: {
3421     if ($t->{type} == IDENT_TOKEN) {
3422     undef $may_be_inherit if $has_s or length $font_name;
3423     undef $may_be_generic if $has_s or length $font_name;
3424     $font_name .= ' ' if $has_s;
3425     $font_name .= $t->{value};
3426     undef $has_s;
3427     $t = $tt->get_next_token;
3428     } elsif ($t->{type} == STRING_TOKEN) {
3429     $font_name .= ' ' if $has_s;
3430     $font_name .= $t->{value};
3431     undef $may_be_inherit;
3432     undef $may_be_generic;
3433     undef $has_s;
3434     $t = $tt->get_next_token;
3435 wakaba 1.31 } elsif ($t->{type} == COMMA_TOKEN) { ## TODO: case
3436     if ($may_be_generic and $generic_font_keywords->{lc $font_name}) {
3437 wakaba 1.15 push @prop_value, ['KEYWORD', $font_name];
3438     } elsif (not $may_be_generic or length $font_name) {
3439     push @prop_value, ["STRING", $font_name];
3440     }
3441     undef $may_be_inherit;
3442     $may_be_generic = 1;
3443     undef $has_s;
3444     $font_name = '';
3445     $t = $tt->get_next_token;
3446     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3447     } elsif ($t->{type} == S_TOKEN) {
3448     $has_s = 1;
3449     $t = $tt->get_next_token;
3450     } else {
3451 wakaba 1.31 if ($may_be_generic and $generic_font_keywords->{lc $font_name}) {
3452     push @prop_value, ['KEYWORD', $font_name]; ## TODO: case
3453 wakaba 1.15 } elsif (not $may_be_generic or length $font_name) {
3454     push @prop_value, ['STRING', $font_name];
3455     } else {
3456 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3457 wakaba 1.15 level => $self->{must_level},
3458 wakaba 1.38 uri => \$self->{href},
3459 wakaba 1.15 token => $t);
3460     return ($t, undef);
3461     }
3462     last F;
3463     }
3464     redo F;
3465     } # F
3466    
3467     if ($may_be_inherit and
3468     @prop_value == 1 and
3469     $prop_value[0]->[0] eq 'STRING' and
3470     lc $prop_value[0]->[1] eq 'inherit') { ## TODO: case
3471     return ($t, {$prop_name => ['INHERIT']});
3472     } else {
3473     unshift @prop_value, 'FONT';
3474     return ($t, {$prop_name => \@prop_value});
3475     }
3476     },
3477     serialize => sub {
3478     my ($self, $prop_name, $value) = @_;
3479    
3480     if ($value->[0] eq 'FONT') {
3481     return join ', ', map {
3482     if ($_->[0] eq 'STRING') {
3483     '"'.$_->[1].'"'; ## NOTE: This is what Firefox does.
3484     } elsif ($_->[0] eq 'KEYWORD') {
3485     $_->[1]; ## NOTE: This is what Firefox does.
3486     } else {
3487     ## NOTE: This should be an error.
3488     '""';
3489     }
3490     } @$value[1..$#$value];
3491     } elsif ($value->[0] eq 'INHERIT') {
3492     return 'inherit';
3493     } else {
3494 wakaba 1.34 return '';
3495 wakaba 1.15 }
3496     },
3497     initial => ['FONT', ['KEYWORD', '-manakai-default']],
3498     inherited => 1,
3499     compute => $compute_as_specified,
3500     };
3501     $Attr->{font_family} = $Prop->{'font-family'};
3502     $Key->{font_family} = $Prop->{'font-family'};
3503    
3504 wakaba 1.17 $Prop->{cursor} = {
3505     css => 'cursor',
3506     dom => 'cursor',
3507     key => 'cursor',
3508     parse => sub {
3509     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3510    
3511     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/cursor> for browser
3512     ## compatibility issues.
3513    
3514     my @prop_value = ('CURSOR');
3515    
3516     F: {
3517     if ($t->{type} == IDENT_TOKEN) {
3518     my $v = lc $t->{value}; ## TODO: case
3519     $t = $tt->get_next_token;
3520     if ($Prop->{$prop_name}->{keyword}->{$v}) {
3521     push @prop_value, ['KEYWORD', $v];
3522     last F;
3523     } elsif ($v eq 'inherit' and @prop_value == 1) {
3524     return ($t, {$prop_name => ['INHERIT']});
3525     } else {
3526 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3527 wakaba 1.17 level => $self->{must_level},
3528 wakaba 1.38 uri => \$self->{href},
3529 wakaba 1.17 token => $t);
3530     return ($t, undef);
3531     }
3532     } elsif ($t->{type} == URI_TOKEN) {
3533     push @prop_value, ['URI', $t->{value}, \($self->{base_uri})];
3534     $t = $tt->get_next_token;
3535     } else {
3536 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3537 wakaba 1.17 level => $self->{must_level},
3538 wakaba 1.38 uri => \$self->{href},
3539 wakaba 1.17 token => $t);
3540     return ($t, undef);
3541     }
3542    
3543     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3544     if ($t->{type} == COMMA_TOKEN) {
3545     $t = $tt->get_next_token;
3546     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3547     redo F;
3548     }
3549     } # F
3550    
3551     return ($t, {$prop_name => \@prop_value});
3552     },
3553     serialize => sub {
3554     my ($self, $prop_name, $value) = @_;
3555    
3556     if ($value->[0] eq 'CURSOR') {
3557     return join ', ', map {
3558     if ($_->[0] eq 'URI') {
3559     'url('.$_->[1].')'; ## NOTE: This is what Firefox does.
3560     } elsif ($_->[0] eq 'KEYWORD') {
3561     $_->[1];
3562     } else {
3563     ## NOTE: This should be an error.
3564     '""';
3565     }
3566     } @$value[1..$#$value];
3567     } elsif ($value->[0] eq 'INHERIT') {
3568     return 'inherit';
3569     } else {
3570 wakaba 1.34 return '';
3571 wakaba 1.17 }
3572     },
3573     keyword => {
3574     auto => 1, crosshair => 1, default => 1, pointer => 1, move => 1,
3575     'e-resize' => 1, 'ne-resize' => 1, 'nw-resize' => 1, 'n-resize' => 1,
3576     'n-resize' => 1, 'se-resize' => 1, 'sw-resize' => 1, 's-resize' => 1,
3577     'w-resize' => 1, text => 1, wait => 1, help => 1, progress => 1,
3578     },
3579     initial => ['CURSOR', ['KEYWORD', 'auto']],
3580     inherited => 1,
3581     compute => sub {
3582     my ($self, $element, $prop_name, $specified_value) = @_;
3583    
3584     if (defined $specified_value and $specified_value->[0] eq 'CURSOR') {
3585     my @new_value = ('CURSOR');
3586     for my $value (@$specified_value[1..$#$specified_value]) {
3587     if ($value->[0] eq 'URI') {
3588     if (defined $value->[2]) {
3589     require Message::DOM::DOMImplementation;
3590     push @new_value, ['URI',
3591     Message::DOM::DOMImplementation
3592     ->create_uri_reference ($value->[1])
3593     ->get_absolute_reference (${$value->[2]})
3594     ->get_uri_reference,
3595     $value->[2]];
3596     } else {
3597     push @new_value, $value;
3598     }
3599     } else {
3600     push @new_value, $value;
3601     }
3602     }
3603     return \@new_value;
3604     }
3605    
3606     return $specified_value;
3607     },
3608     };
3609     $Attr->{cursor} = $Prop->{cursor};
3610     $Key->{cursor} = $Prop->{cursor};
3611    
3612 wakaba 1.7 $Prop->{'border-style'} = {
3613     css => 'border-style',
3614     dom => 'border_style',
3615     parse => sub {
3616     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3617    
3618     my %prop_value;
3619     if ($t->{type} == IDENT_TOKEN) {
3620     my $prop_value = lc $t->{value}; ## TODO: case folding
3621     $t = $tt->get_next_token;
3622     if ($border_style_keyword->{$prop_value} and
3623     $self->{prop_value}->{'border-top-style'}->{$prop_value}) {
3624     $prop_value{'border-top-style'} = ["KEYWORD", $prop_value];
3625     } elsif ($prop_value eq 'inherit') {
3626 wakaba 1.10 $prop_value{'border-top-style'} = ["INHERIT"];
3627 wakaba 1.19 $prop_value{'border-right-style'} = $prop_value{'border-top-style'};
3628     $prop_value{'border-bottom-style'} = $prop_value{'border-top-style'};
3629     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3630     return ($t, \%prop_value);
3631 wakaba 1.7 } else {
3632 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3633 wakaba 1.7 level => $self->{must_level},
3634 wakaba 1.38 uri => \$self->{href},
3635 wakaba 1.7 token => $t);
3636     return ($t, undef);
3637     }
3638     $prop_value{'border-right-style'} = $prop_value{'border-top-style'};
3639     $prop_value{'border-bottom-style'} = $prop_value{'border-top-style'};
3640     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3641     } else {
3642 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3643 wakaba 1.7 level => $self->{must_level},
3644 wakaba 1.38 uri => \$self->{href},
3645 wakaba 1.7 token => $t);
3646     return ($t, undef);
3647     }
3648    
3649     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3650     if ($t->{type} == IDENT_TOKEN) {
3651     my $prop_value = lc $t->{value}; ## TODO: case folding
3652     $t = $tt->get_next_token;
3653 wakaba 1.19 if ($border_style_keyword->{$prop_value} and
3654 wakaba 1.7 $self->{prop_value}->{'border-right-style'}->{$prop_value}) {
3655     $prop_value{'border-right-style'} = ["KEYWORD", $prop_value];
3656     } else {
3657 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3658 wakaba 1.7 level => $self->{must_level},
3659 wakaba 1.38 uri => \$self->{href},
3660 wakaba 1.7 token => $t);
3661     return ($t, undef);
3662     }
3663     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3664    
3665     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3666     if ($t->{type} == IDENT_TOKEN) {
3667     my $prop_value = lc $t->{value}; ## TODO: case folding
3668     $t = $tt->get_next_token;
3669     if ($border_style_keyword->{$prop_value} and
3670     $self->{prop_value}->{'border-bottom-style'}->{$prop_value}) {
3671     $prop_value{'border-bottom-style'} = ["KEYWORD", $prop_value];
3672     } else {
3673 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3674 wakaba 1.7 level => $self->{must_level},
3675 wakaba 1.38 uri => \$self->{href},
3676 wakaba 1.7 token => $t);
3677     return ($t, undef);
3678     }
3679    
3680     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3681     if ($t->{type} == IDENT_TOKEN) {
3682     my $prop_value = lc $t->{value}; ## TODO: case folding
3683     $t = $tt->get_next_token;
3684     if ($border_style_keyword->{$prop_value} and
3685     $self->{prop_value}->{'border-left-style'}->{$prop_value}) {
3686     $prop_value{'border-left-style'} = ["KEYWORD", $prop_value];
3687     } else {
3688 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3689 wakaba 1.7 level => $self->{must_level},
3690 wakaba 1.38 uri => \$self->{href},
3691 wakaba 1.7 token => $t);
3692     return ($t, undef);
3693     }
3694     }
3695     }
3696     }
3697    
3698     return ($t, \%prop_value);
3699     },
3700 wakaba 1.43 serialize_shorthand => sub {
3701     my $self = shift;
3702    
3703 wakaba 1.7 my @v;
3704     push @v, $self->border_top_style;
3705 wakaba 1.43 my $i = $self->get_property_priority ('border-top-style');
3706 wakaba 1.45 return {} unless length $v[-1];
3707 wakaba 1.7 push @v, $self->border_right_style;
3708 wakaba 1.45 return {} unless length $v[-1];
3709     return {} unless $i eq $self->get_property_priority ('border-right-style');
3710 wakaba 1.7 push @v, $self->border_bottom_style;
3711 wakaba 1.45 return {} unless length $v[-1];
3712     return {} unless $i eq $self->get_property_priority ('border-bottom-style');
3713 wakaba 1.19 push @v, $self->border_left_style;
3714 wakaba 1.45 return {} unless length $v[-1];
3715     return {} unless $i eq $self->get_property_priority ('border-left-style');
3716 wakaba 1.43
3717     my $v = 0;
3718     for (0..3) {
3719     $v++ if $v[$_] eq 'inherit';
3720     }
3721     if ($v == 4) {
3722 wakaba 1.45 return {'border-style' => ['inherit', $i]};
3723 wakaba 1.43 } elsif ($v) {
3724     return {};
3725     }
3726 wakaba 1.7
3727     pop @v if $v[1] eq $v[3];
3728     pop @v if $v[0] eq $v[2];
3729     pop @v if $v[0] eq $v[1];
3730 wakaba 1.45 return {'border-style' => [(join ' ', @v), $i]};
3731 wakaba 1.7 },
3732 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3733 wakaba 1.7 };
3734     $Attr->{border_style} = $Prop->{'border-style'};
3735    
3736 wakaba 1.29 $Prop->{'border-color'} = {
3737     css => 'border-color',
3738     dom => 'border_color',
3739     parse => sub {
3740     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3741    
3742     my %prop_value;
3743     ($t, my $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3744     if (not defined $pv) {
3745     return ($t, undef);
3746     }
3747     $prop_value{'border-top-color'} = $pv->{'border-color'};
3748     $prop_value{'border-bottom-color'} = $prop_value{'border-top-color'};
3749     $prop_value{'border-right-color'} = $prop_value{'border-top-color'};
3750     $prop_value{'border-left-color'}= $prop_value{'border-right-color'};
3751     if ($prop_value{'border-top-color'}->[0] eq 'INHERIT') {
3752     return ($t, \%prop_value);
3753     }
3754    
3755     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3756     if ({
3757     IDENT_TOKEN, 1,
3758     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3759     FUNCTION_TOKEN, 1,
3760     }->{$t->{type}}) {
3761     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3762     if (not defined $pv) {
3763     return ($t, undef);
3764     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3765 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3766 wakaba 1.29 level => $self->{must_level},
3767 wakaba 1.38 uri => \$self->{href},
3768 wakaba 1.29 token => $t);
3769     return ($t, undef);
3770     }
3771     $prop_value{'border-right-color'} = $pv->{'border-color'};
3772     $prop_value{'border-left-color'}= $prop_value{'border-right-color'};
3773    
3774     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3775     if ({
3776     IDENT_TOKEN, 1,
3777     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3778     FUNCTION_TOKEN, 1,
3779     }->{$t->{type}}) {
3780     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3781     if (not defined $pv) {
3782     return ($t, undef);
3783     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3784 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3785 wakaba 1.29 level => $self->{must_level},
3786 wakaba 1.38 uri => \$self->{href},
3787 wakaba 1.29 token => $t);
3788     return ($t, undef);
3789     }
3790     $prop_value{'border-bottom-color'} = $pv->{'border-color'};
3791    
3792     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3793     if ({
3794     IDENT_TOKEN, 1,
3795     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3796     FUNCTION_TOKEN, 1,
3797     }->{$t->{type}}) {
3798     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3799     if (not defined $pv) {
3800     return ($t, undef);
3801     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3802 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3803 wakaba 1.29 level => $self->{must_level},
3804 wakaba 1.38 uri => \$self->{href},
3805 wakaba 1.29 token => $t);
3806     return ($t, undef);
3807     }
3808     $prop_value{'border-left-color'} = $pv->{'border-color'};
3809     }
3810     }
3811     }
3812    
3813     return ($t, \%prop_value);
3814     },
3815 wakaba 1.43 serialize_shorthand => sub {
3816     my $self = shift;
3817    
3818 wakaba 1.29 my @v;
3819     push @v, $self->border_top_color;
3820 wakaba 1.43 my $i = $self->get_property_priority ('border-top-color');
3821 wakaba 1.45 return {} unless length $v[-1];
3822 wakaba 1.29 push @v, $self->border_right_color;
3823 wakaba 1.45 return {} unless length $v[-1];
3824     return {} unless $i eq $self->get_property_priority ('border-right-color');
3825 wakaba 1.29 push @v, $self->border_bottom_color;
3826 wakaba 1.45 return {} unless length $v[-1];
3827     return {} unless $i eq $self->get_property_priority ('border-bottom-color');
3828 wakaba 1.29 push @v, $self->border_left_color;
3829 wakaba 1.45 return {} unless length $v[-1];
3830     return {} unless $i eq $self->get_property_priority ('border-left-color');
3831 wakaba 1.43
3832     my $v = 0;
3833     for (0..3) {
3834     $v++ if $v[$_] eq 'inherit';
3835     }
3836     if ($v == 4) {
3837 wakaba 1.45 return {'border-color' => ['inherit', $i]};
3838 wakaba 1.43 } elsif ($v) {
3839     return {};
3840     }
3841 wakaba 1.29
3842     pop @v if $v[1] eq $v[3];
3843     pop @v if $v[0] eq $v[2];
3844     pop @v if $v[0] eq $v[1];
3845 wakaba 1.45 return {'border-color' => [(join ' ', @v), $i]};
3846 wakaba 1.29 },
3847     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3848     };
3849     $Attr->{border_color} = $Prop->{'border-color'};
3850    
3851     $Prop->{'border-top'} = {
3852     css => 'border-top',
3853     dom => 'border_top',
3854     parse => sub {
3855     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3856    
3857     my %prop_value;
3858     my $pv;
3859     ## NOTE: Since $onerror is disabled for three invocations below,
3860     ## some informative warning messages (if they are added someday) will not
3861     ## be reported.
3862     ($t, $pv) = $parse_color->($self, $prop_name.'-color', $tt, $t, sub {});
3863     if (defined $pv) {
3864     if ($pv->{$prop_name.'-color'}->[0] eq 'INHERIT') {
3865     return ($t, {$prop_name.'-color' => ['INHERIT'],
3866     $prop_name.'-style' => ['INHERIT'],
3867     $prop_name.'-width' => ['INHERIT']});
3868     } else {
3869     $prop_value{$prop_name.'-color'} = $pv->{$prop_name.'-color'};
3870     }
3871     } else {
3872     ($t, $pv) = $Prop->{'border-top-width'}->{parse}
3873     ->($self, $prop_name.'-width', $tt, $t, sub {});
3874     if (defined $pv) {
3875     $prop_value{$prop_name.'-width'} = $pv->{$prop_name.'-width'};
3876     } else {
3877     ($t, $pv) = $Prop->{'border-top-style'}->{parse}
3878     ->($self, $prop_name.'-style', $tt, $t, sub {});
3879     if (defined $pv) {
3880     $prop_value{$prop_name.'-style'} = $pv->{$prop_name.'-style'};
3881     } else {
3882 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3883 wakaba 1.29 level => $self->{must_level},
3884 wakaba 1.38 uri => \$self->{href},
3885 wakaba 1.29 token => $t);
3886     return ($t, undef);
3887     }
3888     }
3889     }
3890    
3891     for (1..2) {
3892     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3893     if ($t->{type} == IDENT_TOKEN) {
3894     my $prop_value = lc $t->{value}; ## TODO: case
3895     if ($border_style_keyword->{$prop_value} and
3896     $self->{prop_value}->{'border-top-style'}->{$prop_value} and
3897     not defined $prop_value{$prop_name.'-style'}) {
3898     $prop_value{$prop_name.'-style'} = ['KEYWORD', $prop_value];
3899     $t = $tt->get_next_token;
3900     next;
3901     } elsif ({thin => 1, medium => 1, thick => 1}->{$prop_value} and
3902     not defined $prop_value{$prop_name.'-width'}) {
3903     $prop_value{$prop_name.'-width'} = ['KEYWORD', $prop_value];
3904     $t = $tt->get_next_token;
3905     next;
3906     }
3907     }
3908    
3909     undef $pv;
3910     ($t, $pv) = $parse_color->($self, $prop_name.'-color', $tt, $t, $onerror)
3911     if not defined $prop_value{$prop_name.'-color'} and
3912     {
3913     IDENT_TOKEN, 1,
3914     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3915     FUNCTION_TOKEN, 1,
3916     }->{$t->{type}};
3917     if (defined $pv) {
3918     if ($pv->{$prop_name.'-color'}->[0] eq 'INHERIT') {
3919 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3920 wakaba 1.29 level => $self->{must_level},
3921 wakaba 1.38 uri => \$self->{href},
3922 wakaba 1.29 token => $t);
3923     } else {
3924     $prop_value{$prop_name.'-color'} = $pv->{$prop_name.'-color'};
3925     }
3926     } else {
3927     undef $pv;
3928     ($t, $pv) = $Prop->{'border-top-width'}->{parse}
3929     ->($self, $prop_name.'-width',
3930     $tt, $t, $onerror)
3931     if not defined $prop_value{$prop_name.'-width'} and
3932     {
3933     DIMENSION_TOKEN, 1,
3934     NUMBER_TOKEN, 1,
3935     IDENT_TOKEN, 1,
3936     MINUS_TOKEN, 1,
3937     }->{$t->{type}};
3938     if (defined $pv) {
3939     if ($pv->{$prop_name.'-width'}->[0] eq 'INHERIT') {
3940 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3941 wakaba 1.29 level => $self->{must_level},
3942 wakaba 1.38 uri => \$self->{href},
3943 wakaba 1.29 token => $t);
3944     } else {
3945     $prop_value{$prop_name.'-width'} = $pv->{$prop_name.'-width'};
3946     }
3947     } else {
3948     last;
3949     }
3950     }
3951     }
3952    
3953     $prop_value{$prop_name.'-color'}
3954     ||= $Prop->{$prop_name.'-color'}->{initial};
3955     $prop_value{$prop_name.'-width'}
3956     ||= $Prop->{$prop_name.'-width'}->{initial};
3957     $prop_value{$prop_name.'-style'}
3958     ||= $Prop->{$prop_name.'-style'}->{initial};
3959    
3960     return ($t, \%prop_value);
3961     },
3962 wakaba 1.43 serialize_shorthand => sub {
3963     my $self = shift;
3964    
3965     my $w = $self->border_top_width;
3966     return {} unless length $w;
3967     my $i = $self->get_property_priority ('border-top-width');
3968     my $s = $self->border_top_style;
3969     return {} unless length $s;
3970     return {} unless $i eq $self->get_property_priority ('border-top-style');
3971     my $c = $self->border_top_color;
3972     return {} unless length $c;
3973     return {} unless $i eq $self->get_property_priority ('border-top-color');
3974    
3975     my $v = 0;
3976     $v++ if $w eq 'inherit';
3977     $v++ if $s eq 'inherit';
3978     $v++ if $c eq 'inherit';
3979     if ($v == 3) {
3980     return {'border-top' => ['inherit', $i]};
3981     } elsif ($v) {
3982     return {};
3983     }
3984 wakaba 1.29
3985 wakaba 1.43 return {'border-top' => [$w . ' ' . $s . ' ' . $c, $i]};
3986 wakaba 1.29 },
3987     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3988     };
3989     $Attr->{border_top} = $Prop->{'border-top'};
3990    
3991     $Prop->{'border-right'} = {
3992     css => 'border-right',
3993     dom => 'border_right',
3994     parse => $Prop->{'border-top'}->{parse},
3995 wakaba 1.43 serialize_shorthand => sub {
3996     my $self = shift;
3997    
3998     my $w = $self->border_right_width;
3999     return {} unless length $w;
4000     my $i = $self->get_property_priority ('border-right-width');
4001     my $s = $self->border_right_style;
4002     return {} unless length $s;
4003     return {} unless $i eq $self->get_property_priority ('border-right-style');
4004     my $c = $self->border_right_color;
4005     return {} unless length $c;
4006     return {} unless $i eq $self->get_property_priority ('border-right-color');
4007    
4008     my $v = 0;
4009     $v++ if $w eq 'inherit';
4010     $v++ if $s eq 'inherit';
4011     $v++ if $c eq 'inherit';
4012     if ($v == 3) {
4013     return {'border-right' => ['inherit', $i]};
4014     } elsif ($v) {
4015     return {};
4016     }
4017    
4018     return {'border-right' => [$w . ' ' . $s . ' ' . $c, $i]};
4019     },
4020 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
4021     };
4022     $Attr->{border_right} = $Prop->{'border-right'};
4023    
4024     $Prop->{'border-bottom'} = {
4025     css => 'border-bottom',
4026     dom => 'border_bottom',
4027     parse => $Prop->{'border-top'}->{parse},
4028 wakaba 1.43 serialize_shorthand => sub {
4029     my $self = shift;
4030    
4031     my $w = $self->border_bottom_width;
4032     return {} unless length $w;
4033     my $i = $self->get_property_priority ('border-bottom-width');
4034     my $s = $self->border_bottom_style;
4035     return {} unless length $s;
4036     return {} unless $i eq $self->get_property_priority ('border-bottom-style');
4037     my $c = $self->border_bottom_color;
4038     return {} unless length $c;
4039     return {} unless $i eq $self->get_property_priority ('border-bottom-color');
4040    
4041     my $v = 0;
4042     $v++ if $w eq 'inherit';
4043     $v++ if $s eq 'inherit';
4044     $v++ if $c eq 'inherit';
4045     if ($v == 3) {
4046     return {'border-bottom' => ['inherit', $i]};
4047     } elsif ($v) {
4048     return {};
4049     }
4050    
4051     return {'border-bottom' => [$w . ' ' . $s . ' ' . $c, $i]};
4052     },
4053 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
4054     };
4055     $Attr->{border_bottom} = $Prop->{'border-bottom'};
4056    
4057     $Prop->{'border-left'} = {
4058     css => 'border-left',
4059     dom => 'border_left',
4060     parse => $Prop->{'border-top'}->{parse},
4061 wakaba 1.43 serialize_shorthand => sub {
4062     my $self = shift;
4063    
4064     my $w = $self->border_left_width;
4065     return {} unless length $w;
4066     my $i = $self->get_property_priority ('border-left-width');
4067     my $s = $self->border_left_style;
4068     return {} unless length $s;
4069     return {} unless $i eq $self->get_property_priority ('border-left-style');
4070     my $c = $self->border_left_color;
4071     return {} unless length $c;
4072     return {} unless $i eq $self->get_property_priority ('border-left-color');
4073    
4074     my $v = 0;
4075     $v++ if $w eq 'inherit';
4076     $v++ if $s eq 'inherit';
4077     $v++ if $c eq 'inherit';
4078     if ($v == 3) {
4079     return {'border-left' => ['inherit', $i]};
4080     } elsif ($v) {
4081     return {};
4082     }
4083    
4084     return {'border-left' => [$w . ' ' . $s . ' ' . $c, $i]};
4085     },
4086 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
4087     };
4088     $Attr->{border_left} = $Prop->{'border-left'};
4089    
4090     $Prop->{outline} = {
4091     css => 'outline',
4092     dom => 'outline',
4093     parse => $Prop->{'border-top'}->{parse},
4094     serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
4095     };
4096     $Attr->{outline} = $Prop->{outline};
4097    
4098     $Prop->{border} = {
4099     css => 'border',
4100     dom => 'border',
4101     parse => sub {
4102     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4103     my $prop_value;
4104     ($t, $prop_value) = $Prop->{'border-top'}->{parse}
4105     ->($self, 'border-top', $tt, $t, $onerror);
4106     return ($t, undef) unless defined $prop_value;
4107    
4108     for (qw/border-right border-bottom border-left/) {
4109     $prop_value->{$_.'-color'} = $prop_value->{'border-top-color'}
4110     if defined $prop_value->{'border-top-color'};
4111     $prop_value->{$_.'-style'} = $prop_value->{'border-top-style'}
4112     if defined $prop_value->{'border-top-style'};
4113     $prop_value->{$_.'-width'} = $prop_value->{'border-top-width'}
4114     if defined $prop_value->{'border-top-width'};
4115     }
4116     return ($t, $prop_value);
4117     },
4118     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
4119     };
4120     $Attr->{border} = $Prop->{border};
4121    
4122 wakaba 1.19 $Prop->{margin} = {
4123     css => 'margin',
4124     dom => 'margin',
4125     parse => sub {
4126     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4127    
4128     my %prop_value;
4129    
4130     my $sign = 1;
4131 wakaba 1.42 my $has_sign;
4132 wakaba 1.19 if ($t->{type} == MINUS_TOKEN) {
4133     $t = $tt->get_next_token;
4134 wakaba 1.42 $has_sign = 1;
4135 wakaba 1.19 $sign = -1;
4136 wakaba 1.42 } elsif ($t->{type} == PLUS_TOKEN) {
4137     $t = $tt->get_next_token;
4138     $has_sign = 1;
4139 wakaba 1.19 }
4140    
4141     if ($t->{type} == DIMENSION_TOKEN) {
4142     my $value = $t->{number} * $sign;
4143     my $unit = lc $t->{value}; ## TODO: case
4144     $t = $tt->get_next_token;
4145     if ($length_unit->{$unit}) {
4146     $prop_value{'margin-top'} = ['DIMENSION', $value, $unit];
4147     } else {
4148 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4149 wakaba 1.19 level => $self->{must_level},
4150 wakaba 1.38 uri => \$self->{href},
4151 wakaba 1.19 token => $t);
4152     return ($t, undef);
4153     }
4154     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4155     my $value = $t->{number} * $sign;
4156     $t = $tt->get_next_token;
4157     $prop_value{'margin-top'} = ['PERCENTAGE', $value];
4158 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4159 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4160     my $value = $t->{number} * $sign;
4161     $t = $tt->get_next_token;
4162     $prop_value{'margin-top'} = ['DIMENSION', $value, 'px'];
4163 wakaba 1.42 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4164 wakaba 1.19 my $prop_value = lc $t->{value}; ## TODO: case folding
4165     $t = $tt->get_next_token;
4166     if ($prop_value eq 'auto') {
4167     $prop_value{'margin-top'} = ['KEYWORD', $prop_value];
4168     } elsif ($prop_value eq 'inherit') {
4169     $prop_value{'margin-top'} = ['INHERIT'];
4170     $prop_value{'margin-right'} = $prop_value{'margin-top'};
4171     $prop_value{'margin-bottom'} = $prop_value{'margin-top'};
4172     $prop_value{'margin-left'} = $prop_value{'margin-right'};
4173     return ($t, \%prop_value);
4174     } else {
4175 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4176 wakaba 1.19 level => $self->{must_level},
4177 wakaba 1.38 uri => \$self->{href},
4178 wakaba 1.19 token => $t);
4179     return ($t, undef);
4180     }
4181     } else {
4182 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4183 wakaba 1.19 level => $self->{must_level},
4184 wakaba 1.38 uri => \$self->{href},
4185 wakaba 1.19 token => $t);
4186     return ($t, undef);
4187     }
4188     $prop_value{'margin-right'} = $prop_value{'margin-top'};
4189     $prop_value{'margin-bottom'} = $prop_value{'margin-top'};
4190     $prop_value{'margin-left'} = $prop_value{'margin-right'};
4191    
4192     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4193 wakaba 1.42 undef $has_sign;
4194 wakaba 1.19 $sign = 1;
4195     if ($t->{type} == MINUS_TOKEN) {
4196     $t = $tt->get_next_token;
4197 wakaba 1.42 $has_sign = 1;
4198 wakaba 1.19 $sign = -1;
4199 wakaba 1.42 } elsif ($t->{type} == PLUS_TOKEN) {
4200     $t = $tt->get_next_token;
4201     $has_sign = 1;
4202 wakaba 1.19 }
4203    
4204     if ($t->{type} == DIMENSION_TOKEN) {
4205     my $value = $t->{number} * $sign;
4206     my $unit = lc $t->{value}; ## TODO: case
4207     $t = $tt->get_next_token;
4208     if ($length_unit->{$unit}) {
4209     $prop_value{'margin-right'} = ['DIMENSION', $value, $unit];
4210     } else {
4211 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4212 wakaba 1.19 level => $self->{must_level},
4213 wakaba 1.38 uri => \$self->{href},
4214 wakaba 1.19 token => $t);
4215     return ($t, undef);
4216     }
4217     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4218     my $value = $t->{number} * $sign;
4219     $t = $tt->get_next_token;
4220     $prop_value{'margin-right'} = ['PERCENTAGE', $value];
4221 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4222 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4223     my $value = $t->{number} * $sign;
4224     $t = $tt->get_next_token;
4225     $prop_value{'margin-right'} = ['DIMENSION', $value, 'px'];
4226 wakaba 1.42 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4227 wakaba 1.19 my $prop_value = lc $t->{value}; ## TODO: case folding
4228     $t = $tt->get_next_token;
4229     if ($prop_value eq 'auto') {
4230     $prop_value{'margin-right'} = ['KEYWORD', $prop_value];
4231     } else {
4232 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4233 wakaba 1.19 level => $self->{must_level},
4234 wakaba 1.38 uri => \$self->{href},
4235 wakaba 1.19 token => $t);
4236     return ($t, undef);
4237     }
4238     } else {
4239 wakaba 1.42 if ($has_sign) {
4240 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4241 wakaba 1.24 level => $self->{must_level},
4242 wakaba 1.38 uri => \$self->{href},
4243 wakaba 1.24 token => $t);
4244     return ($t, undef);
4245     }
4246 wakaba 1.19 return ($t, \%prop_value);
4247     }
4248     $prop_value{'margin-left'} = $prop_value{'margin-right'};
4249    
4250     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4251 wakaba 1.42 undef $has_sign;
4252 wakaba 1.19 $sign = 1;
4253     if ($t->{type} == MINUS_TOKEN) {
4254     $t = $tt->get_next_token;
4255 wakaba 1.42 $has_sign = 1;
4256 wakaba 1.19 $sign = -1;
4257 wakaba 1.42 } elsif ($t->{type} == PLUS_TOKEN) {
4258     $t = $tt->get_next_token;
4259     $has_sign = 1;
4260 wakaba 1.19 }
4261    
4262     if ($t->{type} == DIMENSION_TOKEN) {
4263     my $value = $t->{number} * $sign;
4264     my $unit = lc $t->{value}; ## TODO: case
4265     $t = $tt->get_next_token;
4266     if ($length_unit->{$unit}) {
4267     $prop_value{'margin-bottom'} = ['DIMENSION', $value, $unit];
4268     } else {
4269 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4270 wakaba 1.19 level => $self->{must_level},
4271 wakaba 1.38 uri => \$self->{href},
4272 wakaba 1.19 token => $t);
4273     return ($t, undef);
4274     }
4275     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4276     my $value = $t->{number} * $sign;
4277     $t = $tt->get_next_token;
4278     $prop_value{'margin-bottom'} = ['PERCENTAGE', $value];
4279 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4280 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4281     my $value = $t->{number} * $sign;
4282     $t = $tt->get_next_token;
4283     $prop_value{'margin-bottom'} = ['DIMENSION', $value, 'px'];
4284 wakaba 1.42 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4285 wakaba 1.19 my $prop_value = lc $t->{value}; ## TODO: case folding
4286     $t = $tt->get_next_token;
4287     if ($prop_value eq 'auto') {
4288     $prop_value{'margin-bottom'} = ['KEYWORD', $prop_value];
4289     } else {
4290 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4291 wakaba 1.19 level => $self->{must_level},
4292 wakaba 1.38 uri => \$self->{href},
4293 wakaba 1.19 token => $t);
4294     return ($t, undef);
4295     }
4296     } else {
4297 wakaba 1.42 if ($has_sign) {
4298 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4299 wakaba 1.24 level => $self->{must_level},
4300 wakaba 1.38 uri => \$self->{href},
4301 wakaba 1.24 token => $t);
4302     return ($t, undef);
4303     }
4304 wakaba 1.19 return ($t, \%prop_value);
4305     }
4306    
4307     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4308 wakaba 1.42 undef $has_sign;
4309 wakaba 1.19 $sign = 1;
4310     if ($t->{type} == MINUS_TOKEN) {
4311     $t = $tt->get_next_token;
4312 wakaba 1.42 $has_sign = 1;
4313 wakaba 1.19 $sign = -1;
4314 wakaba 1.42 } elsif ($t->{type} == PLUS_TOKEN) {
4315     $t = $tt->get_next_token;
4316     $has_sign = 1;
4317 wakaba 1.19 }
4318    
4319     if ($t->{type} == DIMENSION_TOKEN) {
4320     my $value = $t->{number} * $sign;
4321     my $unit = lc $t->{value}; ## TODO: case
4322     $t = $tt->get_next_token;
4323     if ($length_unit->{$unit}) {
4324     $prop_value{'margin-left'} = ['DIMENSION', $value, $unit];
4325     } else {
4326 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4327 wakaba 1.19 level => $self->{must_level},
4328 wakaba 1.38 uri => \$self->{href},
4329 wakaba 1.19 token => $t);
4330     return ($t, undef);
4331     }
4332     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4333     my $value = $t->{number} * $sign;
4334     $t = $tt->get_next_token;
4335     $prop_value{'margin-left'} = ['PERCENTAGE', $value];
4336 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4337 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4338     my $value = $t->{number} * $sign;
4339     $t = $tt->get_next_token;
4340     $prop_value{'margin-left'} = ['DIMENSION', $value, 'px'];
4341 wakaba 1.42 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4342 wakaba 1.19 my $prop_value = lc $t->{value}; ## TODO: case folding
4343     $t = $tt->get_next_token;
4344     if ($prop_value eq 'auto') {
4345     $prop_value{'margin-left'} = ['KEYWORD', $prop_value];
4346     } else {
4347 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4348 wakaba 1.19 level => $self->{must_level},
4349 wakaba 1.38 uri => \$self->{href},
4350 wakaba 1.19 token => $t);
4351     return ($t, undef);
4352     }
4353     } else {
4354 wakaba 1.42 if ($has_sign) {
4355 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4356 wakaba 1.24 level => $self->{must_level},
4357 wakaba 1.38 uri => \$self->{href},
4358 wakaba 1.24 token => $t);
4359     return ($t, undef);
4360     }
4361 wakaba 1.19 return ($t, \%prop_value);
4362     }
4363    
4364     return ($t, \%prop_value);
4365     },
4366 wakaba 1.42 serialize_multiple => $Prop->{'margin-top'}->{serialize_multiple},
4367 wakaba 1.19 };
4368     $Attr->{margin} = $Prop->{margin};
4369    
4370     $Prop->{padding} = {
4371     css => 'padding',
4372     dom => 'padding',
4373     parse => sub {
4374     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4375    
4376     my %prop_value;
4377    
4378     my $sign = 1;
4379     if ($t->{type} == MINUS_TOKEN) {
4380     $t = $tt->get_next_token;
4381     $sign = -1;
4382     }
4383    
4384     if ($t->{type} == DIMENSION_TOKEN) {
4385     my $value = $t->{number} * $sign;
4386     my $unit = lc $t->{value}; ## TODO: case
4387     $t = $tt->get_next_token;
4388     if ($length_unit->{$unit} and $value >= 0) {
4389     $prop_value{'padding-top'} = ['DIMENSION', $value, $unit];
4390     } else {
4391 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4392 wakaba 1.19 level => $self->{must_level},
4393 wakaba 1.38 uri => \$self->{href},
4394 wakaba 1.19 token => $t);
4395     return ($t, undef);
4396     }
4397     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4398     my $value = $t->{number} * $sign;
4399     $t = $tt->get_next_token;
4400     $prop_value{'padding-top'} = ['PERCENTAGE', $value];
4401     unless ($value >= 0) {
4402 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4403 wakaba 1.19 level => $self->{must_level},
4404 wakaba 1.38 uri => \$self->{href},
4405 wakaba 1.19 token => $t);
4406     return ($t, undef);
4407     }
4408 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4409 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4410     my $value = $t->{number} * $sign;
4411     $t = $tt->get_next_token;
4412     $prop_value{'padding-top'} = ['DIMENSION', $value, 'px'];
4413     unless ($value >= 0) {
4414 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4415 wakaba 1.19 level => $self->{must_level},
4416 wakaba 1.38 uri => \$self->{href},
4417 wakaba 1.19 token => $t);
4418     return ($t, undef);
4419     }
4420     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4421     my $prop_value = lc $t->{value}; ## TODO: case folding
4422     $t = $tt->get_next_token;
4423     if ($prop_value eq 'inherit') {
4424     $prop_value{'padding-top'} = ['INHERIT'];
4425     $prop_value{'padding-right'} = $prop_value{'padding-top'};
4426     $prop_value{'padding-bottom'} = $prop_value{'padding-top'};
4427     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4428     return ($t, \%prop_value);
4429     } else {
4430 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4431 wakaba 1.19 level => $self->{must_level},
4432 wakaba 1.38 uri => \$self->{href},
4433 wakaba 1.19 token => $t);
4434     return ($t, undef);
4435     }
4436     } else {
4437 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4438 wakaba 1.19 level => $self->{must_level},
4439 wakaba 1.38 uri => \$self->{href},
4440 wakaba 1.19 token => $t);
4441     return ($t, undef);
4442     }
4443     $prop_value{'padding-right'} = $prop_value{'padding-top'};
4444     $prop_value{'padding-bottom'} = $prop_value{'padding-top'};
4445     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4446    
4447     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4448     $sign = 1;
4449     if ($t->{type} == MINUS_TOKEN) {
4450     $t = $tt->get_next_token;
4451     $sign = -1;
4452     }
4453    
4454     if ($t->{type} == DIMENSION_TOKEN) {
4455     my $value = $t->{number} * $sign;
4456     my $unit = lc $t->{value}; ## TODO: case
4457     $t = $tt->get_next_token;
4458     if ($length_unit->{$unit} and $value >= 0) {
4459     $prop_value{'padding-right'} = ['DIMENSION', $value, $unit];
4460     } else {
4461 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4462 wakaba 1.19 level => $self->{must_level},
4463 wakaba 1.38 uri => \$self->{href},
4464 wakaba 1.19 token => $t);
4465     return ($t, undef);
4466     }
4467     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4468     my $value = $t->{number} * $sign;
4469     $t = $tt->get_next_token;
4470     $prop_value{'padding-right'} = ['PERCENTAGE', $value];
4471     unless ($value >= 0) {
4472 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4473 wakaba 1.19 level => $self->{must_level},
4474 wakaba 1.38 uri => \$self->{href},
4475 wakaba 1.19 token => $t);
4476     return ($t, undef);
4477     }
4478 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4479 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4480     my $value = $t->{number} * $sign;
4481     $t = $tt->get_next_token;
4482     $prop_value{'padding-right'} = ['DIMENSION', $value, 'px'];
4483     unless ($value >= 0) {
4484 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4485 wakaba 1.19 level => $self->{must_level},
4486 wakaba 1.38 uri => \$self->{href},
4487 wakaba 1.19 token => $t);
4488     return ($t, undef);
4489     }
4490     } else {
4491 wakaba 1.24 if ($sign < 0) {
4492 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4493 wakaba 1.24 level => $self->{must_level},
4494 wakaba 1.38 uri => \$self->{href},
4495 wakaba 1.24 token => $t);
4496     return ($t, undef);
4497     }
4498 wakaba 1.19 return ($t, \%prop_value);
4499     }
4500     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4501    
4502     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4503     $sign = 1;
4504     if ($t->{type} == MINUS_TOKEN) {
4505     $t = $tt->get_next_token;
4506     $sign = -1;
4507     }
4508    
4509     if ($t->{type} == DIMENSION_TOKEN) {
4510     my $value = $t->{number} * $sign;
4511     my $unit = lc $t->{value}; ## TODO: case
4512     $t = $tt->get_next_token;
4513     if ($length_unit->{$unit} and $value >= 0) {
4514     $prop_value{'padding-bottom'} = ['DIMENSION', $value, $unit];
4515     } else {
4516 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4517 wakaba 1.19 level => $self->{must_level},
4518 wakaba 1.38 uri => \$self->{href},
4519 wakaba 1.19 token => $t);
4520     return ($t, undef);
4521     }
4522     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4523     my $value = $t->{number} * $sign;
4524     $t = $tt->get_next_token;
4525     $prop_value{'padding-bottom'} = ['PERCENTAGE', $value];
4526     unless ($value >= 0) {
4527 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4528 wakaba 1.19 level => $self->{must_level},
4529 wakaba 1.38 uri => \$self->{href},
4530 wakaba 1.19 token => $t);
4531     return ($t, undef);
4532     }
4533 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4534 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4535     my $value = $t->{number} * $sign;
4536     $t = $tt->get_next_token;
4537     $prop_value{'padding-bottom'} = ['DIMENSION', $value, 'px'];
4538     unless ($value >= 0) {
4539 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4540 wakaba 1.19 level => $self->{must_level},
4541 wakaba 1.38 uri => \$self->{href},
4542 wakaba 1.19 token => $t);
4543     return ($t, undef);
4544     }
4545     } else {
4546 wakaba 1.24 if ($sign < 0) {
4547 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4548 wakaba 1.24 level => $self->{must_level},
4549 wakaba 1.38 uri => \$self->{href},
4550 wakaba 1.24 token => $t);
4551     return ($t, undef);
4552     }
4553 wakaba 1.19 return ($t, \%prop_value);
4554     }
4555    
4556     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4557     $sign = 1;
4558     if ($t->{type} == MINUS_TOKEN) {
4559     $t = $tt->get_next_token;
4560     $sign = -1;
4561     }
4562    
4563     if ($t->{type} == DIMENSION_TOKEN) {
4564     my $value = $t->{number} * $sign;
4565     my $unit = lc $t->{value}; ## TODO: case
4566     $t = $tt->get_next_token;
4567     if ($length_unit->{$unit} and $value >= 0) {
4568     $prop_value{'padding-left'} = ['DIMENSION', $value, $unit];
4569     } else {
4570 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4571 wakaba 1.19 level => $self->{must_level},
4572 wakaba 1.38 uri => \$self->{href},
4573 wakaba 1.19 token => $t);
4574     return ($t, undef);
4575     }
4576     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4577     my $value = $t->{number} * $sign;
4578     $t = $tt->get_next_token;
4579     $prop_value{'padding-left'} = ['PERCENTAGE', $value];
4580     unless ($value >= 0) {
4581 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4582 wakaba 1.19 level => $self->{must_level},
4583 wakaba 1.38 uri => \$self->{href},
4584 wakaba 1.19 token => $t);
4585     return ($t, undef);
4586     }
4587 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4588 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4589     my $value = $t->{number} * $sign;
4590     $t = $tt->get_next_token;
4591     $prop_value{'padding-left'} = ['DIMENSION', $value, 'px'];
4592     unless ($value >= 0) {
4593 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4594 wakaba 1.19 level => $self->{must_level},
4595 wakaba 1.38 uri => \$self->{href},
4596 wakaba 1.19 token => $t);
4597     return ($t, undef);
4598     }
4599     } else {
4600 wakaba 1.24 if ($sign < 0) {
4601 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4602 wakaba 1.24 level => $self->{must_level},
4603 wakaba 1.38 uri => \$self->{href},
4604 wakaba 1.24 token => $t);
4605     return ($t, undef);
4606     }
4607 wakaba 1.19 return ($t, \%prop_value);
4608     }
4609    
4610     return ($t, \%prop_value);
4611     },
4612 wakaba 1.43 serialize_multiple => $Prop->{'padding-top'}->{serialize_multiple},
4613 wakaba 1.19 };
4614     $Attr->{padding} = $Prop->{padding};
4615    
4616 wakaba 1.24 $Prop->{'border-spacing'} = {
4617     css => 'border-spacing',
4618     dom => 'border_spacing',
4619     parse => sub {
4620     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4621    
4622     my %prop_value;
4623    
4624     my $sign = 1;
4625     if ($t->{type} == MINUS_TOKEN) {
4626     $t = $tt->get_next_token;
4627     $sign = -1;
4628     }
4629    
4630     if ($t->{type} == DIMENSION_TOKEN) {
4631     my $value = $t->{number} * $sign;
4632     my $unit = lc $t->{value}; ## TODO: case
4633     $t = $tt->get_next_token;
4634     if ($length_unit->{$unit} and $value >= 0) {
4635     $prop_value{'-manakai-border-spacing-x'} = ['DIMENSION', $value, $unit];
4636     } else {
4637 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4638 wakaba 1.24 level => $self->{must_level},
4639 wakaba 1.38 uri => \$self->{href},
4640 wakaba 1.24 token => $t);
4641     return ($t, undef);
4642     }
4643     } elsif ($t->{type} == NUMBER_TOKEN and
4644     ($self->{unitless_px} or $t->{number} == 0)) {
4645     my $value = $t->{number} * $sign;
4646     $t = $tt->get_next_token;
4647     $prop_value{'-manakai-border-spacing-x'} = ['DIMENSION', $value, 'px'];
4648     unless ($value >= 0) {
4649 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4650 wakaba 1.24 level => $self->{must_level},
4651 wakaba 1.38 uri => \$self->{href},
4652 wakaba 1.24 token => $t);
4653     return ($t, undef);
4654     }
4655     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4656     my $prop_value = lc $t->{value}; ## TODO: case folding
4657     $t = $tt->get_next_token;
4658     if ($prop_value eq 'inherit') {
4659     $prop_value{'-manakai-border-spacing-x'} = ['INHERIT'];
4660     $prop_value{'-manakai-border-spacing-y'}
4661     = $prop_value{'-manakai-border-spacing-x'};
4662     return ($t, \%prop_value);
4663     } else {
4664 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4665 wakaba 1.24 level => $self->{must_level},
4666 wakaba 1.38 uri => \$self->{href},
4667 wakaba 1.24 token => $t);
4668     return ($t, undef);
4669     }
4670     } else {
4671 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4672 wakaba 1.24 level => $self->{must_level},
4673 wakaba 1.38 uri => \$self->{href},
4674 wakaba 1.24 token => $t);
4675     return ($t, undef);
4676     }
4677     $prop_value{'-manakai-border-spacing-y'}
4678     = $prop_value{'-manakai-border-spacing-x'};
4679    
4680     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4681     $sign = 1;
4682     if ($t->{type} == MINUS_TOKEN) {
4683     $t = $tt->get_next_token;
4684     $sign = -1;
4685     }
4686    
4687     if ($t->{type} == DIMENSION_TOKEN) {
4688     my $value = $t->{number} * $sign;
4689     my $unit = lc $t->{value}; ## TODO: case
4690     $t = $tt->get_next_token;
4691     if ($length_unit->{$unit} and $value >= 0) {
4692     $prop_value{'-manakai-border-spacing-y'} = ['DIMENSION', $value, $unit];
4693     } else {
4694 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4695 wakaba 1.24 level => $self->{must_level},
4696 wakaba 1.38 uri => \$self->{href},
4697 wakaba 1.24 token => $t);
4698     return ($t, undef);
4699     }
4700     } elsif ($t->{type} == NUMBER_TOKEN and
4701     ($self->{unitless_px} or $t->{number} == 0)) {
4702     my $value = $t->{number} * $sign;
4703     $t = $tt->get_next_token;
4704     $prop_value{'-manakai-border-spacing-y'} = ['DIMENSION', $value, 'px'];
4705     unless ($value >= 0) {
4706 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4707 wakaba 1.24 level => $self->{must_level},
4708 wakaba 1.38 uri => \$self->{href},
4709 wakaba 1.24 token => $t);
4710     return ($t, undef);
4711     }
4712     } else {
4713     if ($sign < 0) {
4714 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4715 wakaba 1.24 level => $self->{must_level},
4716 wakaba 1.38 uri => \$self->{href},
4717 wakaba 1.24 token => $t);
4718     return ($t, undef);
4719     }
4720     return ($t, \%prop_value);
4721     }
4722    
4723     return ($t, \%prop_value);
4724     },
4725     serialize => sub {
4726     my ($self, $prop_name, $value) = @_;
4727    
4728     local $Error::Depth = $Error::Depth + 1;
4729     my @v;
4730     push @v, $self->_manakai_border_spacing_x;
4731 wakaba 1.34 return '' unless length $v[-1];
4732 wakaba 1.24 push @v, $self->_manakai_border_spacing_y;
4733 wakaba 1.34 return '' unless length $v[-1];
4734 wakaba 1.24
4735     pop @v if $v[0] eq $v[1];
4736     return join ' ', @v;
4737     },
4738 wakaba 1.25 serialize_multiple => $Prop->{'-manakai-border-spacing-x'}
4739     ->{serialize_multiple},
4740 wakaba 1.24 };
4741     $Attr->{border_spacing} = $Prop->{'border-spacing'};
4742    
4743 wakaba 1.27 ## NOTE: See <http://suika.fam.cx/gate/2005/sw/background-position> for
4744     ## browser compatibility problems.
4745     $Prop->{'background-position'} = {
4746     css => 'background-position',
4747     dom => 'background_position',
4748     parse => sub {
4749     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4750    
4751     my %prop_value;
4752    
4753     my $sign = 1;
4754 wakaba 1.52 my $has_sign;
4755 wakaba 1.27 if ($t->{type} == MINUS_TOKEN) {
4756     $t = $tt->get_next_token;
4757 wakaba 1.52 $has_sign = 1;
4758 wakaba 1.27 $sign = -1;
4759 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
4760     $t = $tt->get_next_token;
4761     $has_sign = 1;
4762 wakaba 1.27 }
4763    
4764     if ($t->{type} == DIMENSION_TOKEN) {
4765     my $value = $t->{number} * $sign;
4766     my $unit = lc $t->{value}; ## TODO: case
4767     if ($length_unit->{$unit}) {
4768 wakaba 1.52 $t = $tt->get_next_token;
4769 wakaba 1.27 $prop_value{'background-position-x'} = ['DIMENSION', $value, $unit];
4770     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4771     } else {
4772 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4773 wakaba 1.27 level => $self->{must_level},
4774 wakaba 1.38 uri => \$self->{href},
4775 wakaba 1.27 token => $t);
4776     return ($t, undef);
4777     }
4778     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4779     my $value = $t->{number} * $sign;
4780     $t = $tt->get_next_token;
4781     $prop_value{'background-position-x'} = ['PERCENTAGE', $value];
4782     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4783     } elsif ($t->{type} == NUMBER_TOKEN and
4784     ($self->{unitless_px} or $t->{number} == 0)) {
4785     my $value = $t->{number} * $sign;
4786     $t = $tt->get_next_token;
4787     $prop_value{'background-position-x'} = ['DIMENSION', $value, 'px'];
4788     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4789 wakaba 1.52 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4790 wakaba 1.27 my $prop_value = lc $t->{value}; ## TODO: case folding
4791     if ({left => 1, center => 1, right => 1}->{$prop_value}) {
4792 wakaba 1.52 $t = $tt->get_next_token;
4793 wakaba 1.27 $prop_value{'background-position-x'} = ['KEYWORD', $prop_value];
4794     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4795     } elsif ($prop_value eq 'top' or $prop_value eq 'bottom') {
4796 wakaba 1.52 $t = $tt->get_next_token;
4797 wakaba 1.27 $prop_value{'background-position-y'} = ['KEYWORD', $prop_value];
4798    
4799     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4800     if ($t->{type} == IDENT_TOKEN) {
4801     my $prop_value = lc $t->{value}; ## TODO: case folding
4802     if ({left => 1, center => 1, right => 1}->{$prop_value}) {
4803     $prop_value{'background-position-x'} = ['KEYWORD', $prop_value];
4804     $t = $tt->get_next_token;
4805     return ($t, \%prop_value);
4806     }
4807     }
4808     $prop_value{'background-position-x'} = ['KEYWORD', 'center'];
4809     return ($t, \%prop_value);
4810     } elsif ($prop_value eq 'inherit') {
4811 wakaba 1.52 $t = $tt->get_next_token;
4812 wakaba 1.27 $prop_value{'background-position-x'} = ['INHERIT'];
4813     $prop_value{'background-position-y'} = ['INHERIT'];
4814     return ($t, \%prop_value);
4815     } else {
4816 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4817 wakaba 1.27 level => $self->{must_level},
4818 wakaba 1.38 uri => \$self->{href},
4819 wakaba 1.27 token => $t);
4820     return ($t, undef);
4821     }
4822     } else {
4823 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4824 wakaba 1.27 level => $self->{must_level},
4825 wakaba 1.38 uri => \$self->{href},
4826 wakaba 1.27 token => $t);
4827     return ($t, undef);
4828     }
4829    
4830     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4831 wakaba 1.52 undef $has_sign;
4832 wakaba 1.27 $sign = 1;
4833     if ($t->{type} == MINUS_TOKEN) {
4834     $t = $tt->get_next_token;
4835 wakaba 1.52 $has_sign = 1;
4836 wakaba 1.27 $sign = -1;
4837 wakaba 1.52 } elsif ($t->{type} == PLUS_TOKEN) {
4838     $t = $tt->get_next_token;
4839     $has_sign = 1;
4840 wakaba 1.27 }
4841    
4842     if ($t->{type} == DIMENSION_TOKEN) {
4843     my $value = $t->{number} * $sign;
4844     my $unit = lc $t->{value}; ## TODO: case
4845     if ($length_unit->{$unit}) {
4846 wakaba 1.52 $t = $tt->get_next_token;
4847 wakaba 1.27 $prop_value{'background-position-y'} = ['DIMENSION', $value, $unit];
4848     } else {
4849 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4850 wakaba 1.27 level => $self->{must_level},
4851 wakaba 1.38 uri => \$self->{href},
4852 wakaba 1.27 token => $t);
4853     return ($t, undef);
4854     }
4855     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4856     my $value = $t->{number} * $sign;
4857     $t = $tt->get_next_token;
4858     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
4859 wakaba 1.30 } elsif ($t->{type} == NUMBER_TOKEN and
4860     ($self->{unitless_px} or $t->{number} == 0)) {
4861 wakaba 1.27 my $value = $t->{number} * $sign;
4862     $t = $tt->get_next_token;
4863     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
4864 wakaba 1.52 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
4865 wakaba 1.27 my $value = lc $t->{value}; ## TODO: case
4866     if ({top => 1, center => 1, bottom => 1}->{$value}) {
4867     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4868     $t = $tt->get_next_token;
4869     }
4870     } else {
4871 wakaba 1.52 if ($has_sign) {
4872 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4873 wakaba 1.27 level => $self->{must_level},
4874 wakaba 1.38 uri => \$self->{href},
4875 wakaba 1.27 token => $t);
4876     return ($t, undef);
4877     }
4878     return ($t, \%prop_value);
4879     }
4880    
4881     return ($t, \%prop_value);
4882     },
4883 wakaba 1.48 serialize_shorthand => sub {
4884     my $self = shift;
4885    
4886     my $r = {};
4887    
4888 wakaba 1.27 my $x = $self->background_position_x;
4889     my $y = $self->background_position_y;
4890 wakaba 1.48 my $xi = $self->get_property_priority ('background-position-x');
4891     my $yi = $self->get_property_priority ('background-position-y');
4892     if (length $x) {
4893     if (length $y) {
4894     if ($xi eq $yi) {
4895     if ($x eq 'inherit') {
4896     if ($y eq 'inherit') {
4897     $r->{'background-position'} = ['inherit', $xi];
4898     } else {
4899     $r->{'background-position-x'} = [$x, $xi];
4900     $r->{'background-position-y'} = [$y, $yi];
4901     }
4902     } elsif ($y eq 'inherit') {
4903     $r->{'background-position-x'} = [$x, $xi];
4904     $r->{'background-position-y'} = [$y, $yi];
4905     } else {
4906     $r->{'background-position'} = [$x . ' ' . $y, $xi];
4907     }
4908     } else {
4909     $r->{'background-position-x'} = [$x, $xi];
4910     $r->{'background-position-y'} = [$y, $yi];
4911     }
4912     } else {
4913     $r->{'background-position-x'} = [$x, $xi];
4914     }
4915     } else {
4916     if (length $y) {
4917     $r->{'background-position-y'} = [$y, $yi];
4918     } else {
4919     #
4920     }
4921     }
4922    
4923     return $r;
4924 wakaba 1.27 },
4925 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
4926 wakaba 1.27 };
4927     $Attr->{background_position} = $Prop->{'background-position'};
4928    
4929 wakaba 1.30 $Prop->{background} = {
4930     css => 'background',
4931     dom => 'background',
4932     parse => sub {
4933     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4934     my %prop_value;
4935     B: for (1..5) {
4936 wakaba 1.48 my $has_sign;
4937 wakaba 1.30 my $sign = 1;
4938     if ($t->{type} == MINUS_TOKEN) {
4939     $sign = -1;
4940 wakaba 1.48 $has_sign = 1;
4941     $t = $tt->get_next_token;
4942     } elsif ($t->{type} == PLUS_TOKEN) {
4943     $has_sign = 1;
4944 wakaba 1.30 $t = $tt->get_next_token;
4945     }
4946    
4947 wakaba 1.48 if (not $has_sign and $t->{type} == IDENT_TOKEN) {
4948 wakaba 1.30 my $value = lc $t->{value}; ## TODO: case
4949     if ($Prop->{'background-repeat'}->{keyword}->{$value} and
4950     $self->{prop_value}->{'background-repeat'}->{$value} and
4951     not defined $prop_value{'background-repeat'}) {
4952     $prop_value{'background-repeat'} = ['KEYWORD', $value];
4953     $t = $tt->get_next_token;
4954     } elsif ($Prop->{'background-attachment'}->{keyword}->{$value} and
4955     $self->{prop_value}->{'background-attachment'}->{$value} and
4956     not defined $prop_value{'background-attachment'}) {
4957     $prop_value{'background-attachment'} = ['KEYWORD', $value];
4958     $t = $tt->get_next_token;
4959     } elsif ($value eq 'none' and
4960     not defined $prop_value{'background-image'}) {
4961     $prop_value{'background-image'} = ['KEYWORD', $value];
4962     $t = $tt->get_next_token;
4963     } elsif ({left => 1, center => 1, right => 1}->{$value} and
4964     not defined $prop_value{'background-position-x'}) {
4965     $prop_value{'background-position-x'} = ['KEYWORD', $value];
4966     $t = $tt->get_next_token;
4967     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4968     my $sign = 1;
4969 wakaba 1.48 my $has_sign;
4970 wakaba 1.30 if ($t->{type} == MINUS_TOKEN) {
4971     $sign = -1;
4972 wakaba 1.48 $has_sign = 1;
4973     $t = $tt->get_next_token;
4974     } elsif ($t->{type} == PLUS_TOKEN) {
4975     $has_sign = 1;
4976 wakaba 1.30 $t = $tt->get_next_token;
4977     }
4978 wakaba 1.48 if (not $has_sign and $t->{type} == IDENT_TOKEN) {
4979 wakaba 1.30 my $value = lc $t->{value}; ## TODO: case
4980     if ({top => 1, bottom => 1, center => 1}->{$value}) {
4981     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4982     $t = $tt->get_next_token;
4983     } elsif ($prop_value{'background-position-x'}->[1] eq 'center' and
4984     $value eq 'left' or $value eq 'right') {
4985     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4986     $prop_value{'background-position-x'} = ['KEYWORD', $value];
4987     $t = $tt->get_next_token;
4988     } else {
4989     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4990     }
4991     } elsif ($t->{type} == DIMENSION_TOKEN) {
4992     my $value = $t->{number} * $sign;
4993     my $unit = lc $t->{value}; ## TODO: case
4994     $t = $tt->get_next_token;
4995     if ($length_unit->{$unit}) {
4996     $prop_value{'background-position-y'}
4997     = ['DIMENSION', $value, $unit];
4998     } else {
4999 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5000 wakaba 1.30 level => $self->{must_level},
5001 wakaba 1.38 uri => \$self->{href},
5002 wakaba 1.30 token => $t);
5003 wakaba 1.48 return ($t, undef);
5004 wakaba 1.30 }
5005     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
5006     my $value = $t->{number} * $sign;
5007     $t = $tt->get_next_token;
5008     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
5009     } elsif ($t->{type} == NUMBER_TOKEN and
5010     ($self->{unitless_px} or $t->{number} == 0)) {
5011     my $value = $t->{number} * $sign;
5012     $t = $tt->get_next_token;
5013     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
5014 wakaba 1.48 } elsif ($has_sign) {
5015 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5016 wakaba 1.30 level => $self->{must_level},
5017 wakaba 1.38 uri => \$self->{href},
5018 wakaba 1.30 token => $t);
5019 wakaba 1.48 return ($t, undef);
5020     } else {
5021     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
5022 wakaba 1.30 }
5023     } elsif (($value eq 'top' or $value eq 'bottom') and
5024     not defined $prop_value{'background-position-y'}) {
5025     $prop_value{'background-position-y'} = ['KEYWORD', $value];
5026     $t = $tt->get_next_token;
5027     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5028     if ($t->{type} == IDENT_TOKEN and ## TODO: case
5029 wakaba 1.48 {
5030     left => 1, center => 1, right => 1,
5031     }->{my $value = lc $t->{value}}) {
5032 wakaba 1.30 $prop_value{'background-position-x'} = ['KEYWORD', $value];
5033     $t = $tt->get_next_token;
5034     } else {
5035     $prop_value{'background-position-x'} = ['KEYWORD', 'center'];
5036     }
5037     } elsif ($value eq 'inherit' and not keys %prop_value) {
5038     $prop_value{'background-color'} =
5039     $prop_value{'background-image'} =
5040     $prop_value{'background-repeat'} =
5041     $prop_value{'background-attachment'} =
5042     $prop_value{'background-position-x'} =
5043     $prop_value{'background-position-y'} = ['INHERIT'];
5044     $t = $tt->get_next_token;
5045     return ($t, \%prop_value);
5046     } elsif (not defined $prop_value{'background-color'} or
5047     not keys %prop_value) {
5048     ($t, my $pv) = $parse_color->($self, 'background', $tt, $t,
5049     $onerror);
5050     if (defined $pv) {
5051     $prop_value{'background-color'} = $pv->{background};
5052     } else {
5053     ## NOTE: An error should already be raiased.
5054     return ($t, undef);
5055     }
5056     }
5057     } elsif (($t->{type} == DIMENSION_TOKEN or
5058     $t->{type} == PERCENTAGE_TOKEN or
5059     ($t->{type} == NUMBER_TOKEN and
5060 wakaba 1.48 ($t->{unitless_px} or $t->{number} == 0))) and
5061 wakaba 1.30 not defined $prop_value{'background-position-x'}) {
5062     if ($t->{type} == DIMENSION_TOKEN) {
5063     my $value = $t->{number} * $sign;
5064     my $unit = lc $t->{value}; ## TODO: case
5065     $t = $tt->get_next_token;
5066     if ($length_unit->{$unit}) {
5067     $prop_value{'background-position-x'}
5068     = ['DIMENSION', $value, $unit];
5069     } else {
5070 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5071 wakaba 1.30 level => $self->{must_level},
5072 wakaba 1.38 uri => \$self->{href},
5073 wakaba 1.30 token => $t);
5074 wakaba 1.48 return ($t, undef);
5075 wakaba 1.30 }
5076     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
5077     my $value = $t->{number} * $sign;
5078     $t = $tt->get_next_token;
5079     $prop_value{'background-position-x'} = ['PERCENTAGE', $value];
5080     } elsif ($t->{type} == NUMBER_TOKEN and
5081     ($self->{unitless_px} or $t->{number} == 0)) {
5082     my $value = $t->{number} * $sign;
5083     $t = $tt->get_next_token;
5084     $prop_value{'background-position-x'} = ['DIMENSION', $value, 'px'];
5085     } else {
5086     ## NOTE: Should not be happened.
5087     last B;
5088     }
5089    
5090     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5091     if ($t->{type} == MINUS_TOKEN) {
5092     $sign = -1;
5093 wakaba 1.48 $has_sign = 1;
5094     $t = $tt->get_next_token;
5095     } elsif ($t->{type} == PLUS_TOKEN) {
5096     $has_sign = 1;
5097 wakaba 1.30 $t = $tt->get_next_token;
5098     } else {
5099 wakaba 1.48 undef $has_sign;
5100 wakaba 1.30 $sign = 1;
5101     }
5102    
5103     if ($t->{type} == DIMENSION_TOKEN) {
5104     my $value = $t->{number} * $sign;
5105     my $unit = lc $t->{value}; ## TODO: case
5106     $t = $tt->get_next_token;
5107     if ($length_unit->{$unit}) {
5108     $prop_value{'background-position-y'}
5109     = ['DIMENSION', $value, $unit];
5110     } else {
5111 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5112 wakaba 1.30 level => $self->{must_level},
5113 wakaba 1.38 uri => \$self->{href},
5114 wakaba 1.30 token => $t);
5115 wakaba 1.48 return ($t, undef);
5116 wakaba 1.30 }
5117     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
5118     my $value = $t->{number} * $sign;
5119     $t = $tt->get_next_token;
5120     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
5121     } elsif ($t->{type} == NUMBER_TOKEN and
5122     ($self->{unitless_px} or $t->{number} == 0)) {
5123     my $value = $t->{number} * $sign;
5124     $t = $tt->get_next_token;
5125     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
5126     } elsif ($t->{type} == IDENT_TOKEN) {
5127     my $value = lc $t->{value}; ## TODO: case
5128     if ({top => 1, center => 1, bottom => 1}->{$value}) {
5129     $prop_value{'background-position-y'} = ['KEYWORD', $value];
5130     $t = $tt->get_next_token;
5131     } else {
5132     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
5133     }
5134     } else {
5135 wakaba 1.48 $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
5136     if ($has_sign) {
5137 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5138 wakaba 1.30 level => $self->{must_level},
5139 wakaba 1.38 uri => \$self->{href},
5140 wakaba 1.30 token => $t);
5141 wakaba 1.48 return ($t, undef);
5142 wakaba 1.30 }
5143     }
5144 wakaba 1.48 } elsif (not $has_sign and
5145     $t->{type} == URI_TOKEN and
5146 wakaba 1.30 not defined $prop_value{'background-image'}) {
5147 wakaba 1.48 $prop_value{'background-image'}
5148     = ['URI', $t->{value}, \($self->{base_uri})];
5149 wakaba 1.30 $t = $tt->get_next_token;
5150     } else {
5151 wakaba 1.48 if (keys %prop_value and not $has_sign) {
5152 wakaba 1.30 last B;
5153     } else {
5154 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5155 wakaba 1.30 level => $self->{must_level},
5156 wakaba 1.38 uri => \$self->{href},
5157 wakaba 1.30 token => $t);
5158 wakaba 1.48 return ($t, undef);
5159 wakaba 1.30 }
5160     }
5161    
5162     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5163     } # B
5164    
5165     $prop_value{$_} ||= $Prop->{$_}->{initial}
5166     for qw/background-image background-attachment background-repeat
5167     background-color background-position-x background-position-y/;
5168    
5169     return ($t, \%prop_value);
5170     },
5171     serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
5172     };
5173     $Attr->{background} = $Prop->{background};
5174    
5175 wakaba 1.31 $Prop->{font} = {
5176     css => 'font',
5177     dom => 'font',
5178     parse => sub {
5179     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5180    
5181     my %prop_value;
5182    
5183     A: for (1..3) {
5184     if ($t->{type} == IDENT_TOKEN) {
5185     my $value = lc $t->{value}; ## TODO: case
5186     if ($value eq 'normal') {
5187     $t = $tt->get_next_token;
5188     } elsif ($Prop->{'font-style'}->{keyword}->{$value} and
5189     $self->{prop_value}->{'font-style'}->{$value} and
5190     not defined $prop_value{'font-style'}) {
5191     $prop_value{'font-style'} = ['KEYWORD', $value];
5192     $t = $tt->get_next_token;
5193     } elsif ($Prop->{'font-variant'}->{keyword}->{$value} and
5194     $self->{prop_value}->{'font-variant'}->{$value} and
5195     not defined $prop_value{'font-variant'}) {
5196     $prop_value{'font-variant'} = ['KEYWORD', $value];
5197     $t = $tt->get_next_token;
5198     } elsif ({normal => 1, bold => 1,
5199     bolder => 1, lighter => 1}->{$value} and
5200     not defined $prop_value{'font-weight'}) {
5201     $prop_value{'font-weight'} = ['KEYWORD', $value];
5202     $t = $tt->get_next_token;
5203     } elsif ($value eq 'inherit' and 0 == keys %prop_value) {
5204     $t = $tt->get_next_token;
5205     return ($t, {'font-style' => ['INHERIT'],
5206     'font-variant' => ['INHERIT'],
5207     'font-weight' => ['INHERIT'],
5208     'font-size' => ['INHERIT'],
5209     'line-height' => ['INHERIT'],
5210     'font-family' => ['INHERIT']});
5211     } elsif ({
5212     caption => 1, icon => 1, menu => 1,
5213     'message-box' => 1, 'small-caption' => 1, 'status-bar' => 1,
5214     }->{$value} and 0 == keys %prop_value) {
5215     $t = $tt->get_next_token;
5216     return ($t, $self->{get_system_font}->($self, $value, {
5217     'font-style' => $Prop->{'font-style'}->{initial},
5218     'font-variant' => $Prop->{'font-variant'}->{initial},
5219     'font-weight' => $Prop->{'font-weight'}->{initial},
5220     'font-size' => $Prop->{'font-size'}->{initial},
5221     'line-height' => $Prop->{'line-height'}->{initial},
5222     'font-family' => ['FONT', ['KEYWORD', '-manakai-'.$value]],
5223     }));
5224     } else {
5225     if (keys %prop_value) {
5226     last A;
5227     } else {
5228 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5229 wakaba 1.31 level => $self->{must_level},
5230 wakaba 1.38 uri => \$self->{href},
5231 wakaba 1.31 token => $t);
5232     return ($t, undef);
5233     }
5234     }
5235     } elsif ($t->{type} == NUMBER_TOKEN) {
5236     if ({100 => 1, 200 => 1, 300 => 1, 400 => 1, 500 => 1,
5237 wakaba 1.49 600 => 1, 700 => 1, 800 => 1, 900 => 1}->{$t->{number}}) {
5238     $prop_value{'font-weight'} = ['WEIGHT', $t->{number}, 0];
5239 wakaba 1.31 $t = $tt->get_next_token;
5240     } else {
5241     last A;
5242     }
5243 wakaba 1.49 } elsif ($t->{type} == PLUS_TOKEN) {
5244     $t = $tt->get_next_token;
5245     if ($t->{type} == NUMBER_TOKEN) {
5246     if ({100 => 1, 200 => 1, 300 => 1, 400 => 1, 500 => 1,
5247     600 => 1, 700 => 1, 800 => 1, 900 => 1}->{$t->{number}}) {
5248     $prop_value{'font-weight'} = ['WEIGHT', $t->{number}, 0];
5249     $t = $tt->get_next_token;
5250     } else {
5251     ## NOTE: <'font-size'> or invalid
5252     last A;
5253     }
5254     } elsif ($t->{type} == DIMENSION_TOKEN or
5255     $t->{type} == PERCENTAGE_TOKEN) {
5256     ## NOTE: <'font-size'> or invalid
5257     last A;
5258     } else {
5259     $onerror->(type => "syntax error:'$prop_name'",
5260     level => $self->{must_level},
5261     uri => \$self->{href},
5262     token => $t);
5263     return ($t, undef);
5264     }
5265     } else {
5266     last A;
5267 wakaba 1.31 }
5268    
5269     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5270     } # A
5271    
5272     for (qw/font-style font-variant font-weight/) {
5273     $prop_value{$_} = $Prop->{$_}->{initial} unless defined $prop_value{$_};
5274     }
5275    
5276     ($t, my $pv) = $Prop->{'font-size'}->{parse}
5277     ->($self, 'font', $tt, $t, $onerror);
5278     return ($t, undef) unless defined $pv;
5279     if ($pv->{font}->[0] eq 'INHERIT') {
5280 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5281 wakaba 1.31 level => $self->{must_level},
5282 wakaba 1.38 uri => \$self->{href},
5283 wakaba 1.31 token => $t);
5284     return ($t, undef);
5285     }
5286     $prop_value{'font-size'} = $pv->{font};
5287    
5288     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5289     if ($t->{type} == DELIM_TOKEN and $t->{value} eq '/') {
5290     $t = $tt->get_next_token;
5291     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5292     ($t, my $pv) = $Prop->{'line-height'}->{parse}
5293     ->($self, 'font', $tt, $t, $onerror);
5294     return ($t, undef) unless defined $pv;
5295     if ($pv->{font}->[0] eq 'INHERIT') {
5296 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5297 wakaba 1.31 level => $self->{must_level},
5298 wakaba 1.38 uri => \$self->{href},
5299 wakaba 1.31 token => $t);
5300     return ($t, undef);
5301     }
5302     $prop_value{'line-height'} = $pv->{font};
5303     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5304     } else {
5305     $prop_value{'line-height'} = $Prop->{'line-height'}->{initial};
5306     }
5307    
5308     undef $pv;
5309     ($t, $pv) = $Prop->{'font-family'}->{parse}
5310     ->($self, 'font', $tt, $t, $onerror);
5311     return ($t, undef) unless defined $pv;
5312     $prop_value{'font-family'} = $pv->{font};
5313    
5314     return ($t, \%prop_value);
5315     },
5316 wakaba 1.44 serialize_shorthand => sub {
5317     my $self = shift;
5318 wakaba 1.31
5319     local $Error::Depth = $Error::Depth + 1;
5320     my $style = $self->font_style;
5321     my $i = $self->get_property_priority ('font-style');
5322 wakaba 1.44 return {} unless length $style;
5323 wakaba 1.31 my $variant = $self->font_variant;
5324 wakaba 1.44 return {} unless length $variant;
5325     return {} if $i ne $self->get_property_priority ('font-variant');
5326 wakaba 1.31 my $weight = $self->font_weight;
5327 wakaba 1.44 return {} unless length $weight;
5328     return {} if $i ne $self->get_property_priority ('font-weight');
5329 wakaba 1.31 my $size = $self->font_size;
5330 wakaba 1.44 return {} unless length $size;
5331     return {} if $i ne $self->get_property_priority ('font-size');
5332 wakaba 1.31 my $height = $self->line_height;
5333 wakaba 1.44 return {} unless length $height;
5334     return {} if $i ne $self->get_property_priority ('line-height');
5335 wakaba 1.31 my $family = $self->font_family;
5336 wakaba 1.44 return {} unless length $family;
5337     return {} if $i ne $self->get_property_priority ('font-family');
5338    
5339     my $v = 0;
5340     for ($style, $variant, $weight, $size, $height, $family) {
5341     $v++ if $_ eq 'inherit';
5342     }
5343     if ($v == 6) {
5344 wakaba 1.45 return {font => ['inherit', $i]};
5345 wakaba 1.44 } elsif ($v) {
5346     return {};
5347     }
5348 wakaba 1.31
5349     my @v;
5350     push @v, $style unless $style eq 'normal';
5351     push @v, $variant unless $variant eq 'normal';
5352     push @v, $weight unless $weight eq 'normal';
5353     push @v, $size.($height eq 'normal' ? '' : '/'.$height);
5354     push @v, $family;
5355 wakaba 1.45 return {font => [(join ' ', @v), $i]};
5356 wakaba 1.31 },
5357     };
5358     $Attr->{font} = $Prop->{font};
5359    
5360 wakaba 1.20 $Prop->{'border-width'} = {
5361     css => 'border-width',
5362     dom => 'border_width',
5363     parse => sub {
5364     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5365    
5366     my %prop_value;
5367    
5368 wakaba 1.51 my $has_sign;
5369 wakaba 1.20 my $sign = 1;
5370     if ($t->{type} == MINUS_TOKEN) {
5371     $t = $tt->get_next_token;
5372 wakaba 1.51 $has_sign = 1;
5373 wakaba 1.20 $sign = -1;
5374 wakaba 1.51 } elsif ($t->{type} == PLUS_TOKEN) {
5375     $t = $tt->get_next_token;
5376     $has_sign = 1;
5377 wakaba 1.20 }
5378    
5379     if ($t->{type} == DIMENSION_TOKEN) {
5380     my $value = $t->{number} * $sign;
5381     my $unit = lc $t->{value}; ## TODO: case
5382     if ($length_unit->{$unit} and $value >= 0) {
5383     $prop_value{'border-top-width'} = ['DIMENSION', $value, $unit];
5384 wakaba 1.51 $t = $tt->get_next_token;
5385 wakaba 1.20 } else {
5386 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5387 wakaba 1.20 level => $self->{must_level},
5388 wakaba 1.38 uri => \$self->{href},
5389 wakaba 1.20 token => $t);
5390     return ($t, undef);
5391     }
5392     } elsif ($t->{type} == NUMBER_TOKEN and
5393     ($self->{unitless_px} or $t->{number} == 0)) {
5394     my $value = $t->{number} * $sign;
5395 wakaba 1.51 if ($value >= 0) {
5396     $prop_value{'border-top-width'} = ['DIMENSION', $value, 'px'];
5397     $t = $tt->get_next_token;
5398     } else {
5399 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5400 wakaba 1.20 level => $self->{must_level},
5401 wakaba 1.38 uri => \$self->{href},
5402 wakaba 1.20 token => $t);
5403     return ($t, undef);
5404     }
5405 wakaba 1.51 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
5406 wakaba 1.20 my $prop_value = lc $t->{value}; ## TODO: case folding
5407     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5408 wakaba 1.51 $t = $tt->get_next_token;
5409 wakaba 1.20 $prop_value{'border-top-width'} = ['KEYWORD', $prop_value];
5410     } elsif ($prop_value eq 'inherit') {
5411 wakaba 1.51 $t = $tt->get_next_token;
5412 wakaba 1.20 $prop_value{'border-top-width'} = ['INHERIT'];
5413     $prop_value{'border-right-width'} = $prop_value{'border-top-width'};
5414     $prop_value{'border-bottom-width'} = $prop_value{'border-top-width'};
5415     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5416     return ($t, \%prop_value);
5417     } else {
5418 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5419 wakaba 1.20 level => $self->{must_level},
5420 wakaba 1.38 uri => \$self->{href},
5421 wakaba 1.20 token => $t);
5422     return ($t, undef);
5423     }
5424     } else {
5425 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5426 wakaba 1.20 level => $self->{must_level},
5427 wakaba 1.38 uri => \$self->{href},
5428 wakaba 1.20 token => $t);
5429     return ($t, undef);
5430     }
5431     $prop_value{'border-right-width'} = $prop_value{'border-top-width'};
5432     $prop_value{'border-bottom-width'} = $prop_value{'border-top-width'};
5433     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5434    
5435     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5436     if ($t->{type} == MINUS_TOKEN) {
5437     $t = $tt->get_next_token;
5438 wakaba 1.51 $has_sign = 1;
5439 wakaba 1.20 $sign = -1;
5440 wakaba 1.51 } elsif ($t->{type} == PLUS_TOKEN) {
5441     $t = $tt->get_next_token;
5442     $has_sign = 1;
5443     $sign = 1;
5444     } else {
5445     undef $has_sign;
5446     $sign = 1;
5447 wakaba 1.20 }
5448    
5449     if ($t->{type} == DIMENSION_TOKEN) {
5450     my $value = $t->{number} * $sign;
5451     my $unit = lc $t->{value}; ## TODO: case
5452     if ($length_unit->{$unit} and $value >= 0) {
5453 wakaba 1.51 $t = $tt->get_next_token;
5454 wakaba 1.20 $prop_value{'border-right-width'} = ['DIMENSION', $value, $unit];
5455     } else {
5456 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5457 wakaba 1.20 level => $self->{must_level},
5458 wakaba 1.38 uri => \$self->{href},
5459 wakaba 1.20 token => $t);
5460     return ($t, undef);
5461     }
5462     } elsif ($t->{type} == NUMBER_TOKEN and
5463     ($self->{unitless_px} or $t->{number} == 0)) {
5464     my $value = $t->{number} * $sign;
5465 wakaba 1.51 if ($value >= 0) {
5466     $t = $tt->get_next_token;
5467     $prop_value{'border-right-width'} = ['DIMENSION', $value, 'px'];
5468     } else {
5469 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5470 wakaba 1.20 level => $self->{must_level},
5471 wakaba 1.38 uri => \$self->{href},
5472 wakaba 1.20 token => $t);
5473     return ($t, undef);
5474     }
5475 wakaba 1.51 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
5476 wakaba 1.20 my $prop_value = lc $t->{value}; ## TODO: case
5477     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5478     $prop_value{'border-right-width'} = ['KEYWORD', $prop_value];
5479     $t = $tt->get_next_token;
5480     }
5481     } else {
5482 wakaba 1.51 if ($has_sign) {
5483 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5484 wakaba 1.24 level => $self->{must_level},
5485 wakaba 1.38 uri => \$self->{href},
5486 wakaba 1.24 token => $t);
5487     return ($t, undef);
5488     }
5489 wakaba 1.20 return ($t, \%prop_value);
5490     }
5491     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5492    
5493     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5494     if ($t->{type} == MINUS_TOKEN) {
5495     $t = $tt->get_next_token;
5496 wakaba 1.51 $has_sign = 1;
5497 wakaba 1.20 $sign = -1;
5498 wakaba 1.51 } elsif ($t->{type} == PLUS_TOKEN) {
5499     $t = $tt->get_next_token;
5500     $has_sign = 1;
5501     $sign = 1;
5502     } else {
5503     undef $has_sign;
5504     $sign = 1;
5505 wakaba 1.20 }
5506    
5507     if ($t->{type} == DIMENSION_TOKEN) {
5508     my $value = $t->{number} * $sign;
5509     my $unit = lc $t->{value}; ## TODO: case
5510     if ($length_unit->{$unit} and $value >= 0) {
5511 wakaba 1.51 $t = $tt->get_next_token;
5512 wakaba 1.20 $prop_value{'border-bottom-width'} = ['DIMENSION', $value, $unit];
5513     } else {
5514 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5515 wakaba 1.20 level => $self->{must_level},
5516 wakaba 1.38 uri => \$self->{href},
5517 wakaba 1.20 token => $t);
5518     return ($t, undef);
5519     }
5520     } elsif ($t->{type} == NUMBER_TOKEN and
5521     ($self->{unitless_px} or $t->{number} == 0)) {
5522     my $value = $t->{number} * $sign;
5523 wakaba 1.51 if ($value >= 0) {
5524     $t = $tt->get_next_token;
5525     $prop_value{'border-bottom-width'} = ['DIMENSION', $value, 'px'];
5526     } else {
5527 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5528 wakaba 1.20 level => $self->{must_level},
5529 wakaba 1.38 uri => \$self->{href},
5530 wakaba 1.20 token => $t);
5531     return ($t, undef);
5532     }
5533 wakaba 1.51 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
5534 wakaba 1.20 my $prop_value = lc $t->{value}; ## TODO: case
5535     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5536     $prop_value{'border-bottom-width'} = ['KEYWORD', $prop_value];
5537     $t = $tt->get_next_token;
5538     }
5539     } else {
5540 wakaba 1.51 if ($has_sign) {
5541 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5542 wakaba 1.24 level => $self->{must_level},
5543 wakaba 1.38 uri => \$self->{href},
5544 wakaba 1.24 token => $t);
5545     return ($t, undef);
5546     }
5547 wakaba 1.20 return ($t, \%prop_value);
5548     }
5549    
5550     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5551     if ($t->{type} == MINUS_TOKEN) {
5552     $t = $tt->get_next_token;
5553 wakaba 1.51 $has_sign = 1;
5554 wakaba 1.20 $sign = -1;
5555 wakaba 1.51 } elsif ($t->{type} == PLUS_TOKEN) {
5556     $t = $tt->get_next_token;
5557     $has_sign = 1;
5558     $sign = 1;
5559     } else {
5560     undef $has_sign;
5561     $sign = 1;
5562 wakaba 1.20 }
5563    
5564     if ($t->{type} == DIMENSION_TOKEN) {
5565     my $value = $t->{number} * $sign;
5566     my $unit = lc $t->{value}; ## TODO: case
5567     if ($length_unit->{$unit} and $value >= 0) {
5568 wakaba 1.51 $t = $tt->get_next_token;
5569 wakaba 1.20 $prop_value{'border-left-width'} = ['DIMENSION', $value, $unit];
5570     } else {
5571 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5572 wakaba 1.20 level => $self->{must_level},
5573 wakaba 1.38 uri => \$self->{href},
5574 wakaba 1.20 token => $t);
5575     return ($t, undef);
5576     }
5577     } elsif ($t->{type} == NUMBER_TOKEN and
5578     ($self->{unitless_px} or $t->{number} == 0)) {
5579     my $value = $t->{number} * $sign;
5580 wakaba 1.51 if ($value >= 0) {
5581     $t = $tt->get_next_token;
5582     $prop_value{'border-left-width'} = ['DIMENSION', $value, 'px'];
5583     } else {
5584 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5585 wakaba 1.20 level => $self->{must_level},
5586 wakaba 1.38 uri => \$self->{href},
5587 wakaba 1.20 token => $t);
5588     return ($t, undef);
5589     }
5590 wakaba 1.51 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
5591 wakaba 1.20 my $prop_value = lc $t->{value}; ## TODO: case
5592     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5593     $prop_value{'border-left-width'} = ['KEYWORD', $prop_value];
5594     $t = $tt->get_next_token;
5595     }
5596     } else {
5597 wakaba 1.51 if ($has_sign) {
5598 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5599 wakaba 1.24 level => $self->{must_level},
5600 wakaba 1.38 uri => \$self->{href},
5601 wakaba 1.24 token => $t);
5602     return ($t, undef);
5603     }
5604 wakaba 1.20 return ($t, \%prop_value);
5605     }
5606    
5607     return ($t, \%prop_value);
5608     },
5609 wakaba 1.43 serialize_shorthand => sub {
5610     my $self = shift;
5611    
5612 wakaba 1.20 my @v;
5613 wakaba 1.24 push @v, $self->border_top_width;
5614 wakaba 1.43 my $i = $self->get_property_priority ('border-top-width');
5615 wakaba 1.45 return {} unless length $v[-1];
5616 wakaba 1.24 push @v, $self->border_right_width;
5617 wakaba 1.45 return {} unless length $v[-1];
5618     return {} unless $i eq $self->get_property_priority ('border-right-width');
5619 wakaba 1.24 push @v, $self->border_bottom_width;
5620 wakaba 1.45 return {} unless length $v[-1];
5621     return {} unless $i eq $self->get_property_priority ('border-bottom-width');
5622 wakaba 1.24 push @v, $self->border_left_width;
5623 wakaba 1.45 return {} unless length $v[-1];
5624     return {} unless $i eq $self->get_property_priority ('border-left-width');
5625 wakaba 1.43
5626     my $v = 0;
5627     for (0..3) {
5628     $v++ if $v[$_] eq 'inherit';
5629     }
5630     if ($v == 4) {
5631 wakaba 1.45 return {'border-width' => ['inherit', $i]};
5632 wakaba 1.43 } elsif ($v) {
5633     return {};
5634     }
5635 wakaba 1.20
5636     pop @v if $v[1] eq $v[3];
5637     pop @v if $v[0] eq $v[2];
5638     pop @v if $v[0] eq $v[1];
5639 wakaba 1.45 return {'border-width' => [(join ' ', @v), $i]};
5640 wakaba 1.20 },
5641 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
5642 wakaba 1.20 };
5643 wakaba 1.24 $Attr->{border_width} = $Prop->{'border-width'};
5644 wakaba 1.20
5645 wakaba 1.12 $Prop->{'list-style'} = {
5646     css => 'list-style',
5647     dom => 'list_style',
5648     parse => sub {
5649     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5650    
5651     my %prop_value;
5652     my $none = 0;
5653    
5654     F: for my $f (1..3) {
5655     if ($t->{type} == IDENT_TOKEN) {
5656     my $prop_value = lc $t->{value}; ## TODO: case folding
5657     $t = $tt->get_next_token;
5658    
5659     if ($prop_value eq 'none') {
5660     $none++;
5661     } elsif ($Prop->{'list-style-type'}->{keyword}->{$prop_value}) {
5662     if (exists $prop_value{'list-style-type'}) {
5663 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5664 wakaba 1.12 level => $self->{must_level},
5665 wakaba 1.38 uri => \$self->{href},
5666 wakaba 1.12 token => $t);
5667     return ($t, undef);
5668     } else {
5669     $prop_value{'list-style-type'} = ['KEYWORD', $prop_value];
5670     }
5671     } elsif ($Prop->{'list-style-position'}->{keyword}->{$prop_value}) {
5672     if (exists $prop_value{'list-style-position'}) {
5673 wakaba 1.39 $onerror->(type => "duplication:'list-style-position'",
5674 wakaba 1.12 level => $self->{must_level},
5675 wakaba 1.38 uri => \$self->{href},
5676 wakaba 1.12 token => $t);
5677     return ($t, undef);
5678     }
5679    
5680     $prop_value{'list-style-position'} = ['KEYWORD', $prop_value];
5681     } elsif ($f == 1 and $prop_value eq 'inherit') {
5682     $prop_value{'list-style-type'} = ["INHERIT"];
5683     $prop_value{'list-style-position'} = ["INHERIT"];
5684     $prop_value{'list-style-image'} = ["INHERIT"];
5685     last F;
5686     } else {
5687     if ($f == 1) {
5688 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5689 wakaba 1.12 level => $self->{must_level},
5690 wakaba 1.38 uri => \$self->{href},
5691 wakaba 1.12 token => $t);
5692     return ($t, undef);
5693     } else {
5694     last F;
5695     }
5696     }
5697     } elsif ($t->{type} == URI_TOKEN) {
5698     if (exists $prop_value{'list-style-image'}) {
5699 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5700 wakaba 1.38 uri => \$self->{href},
5701 wakaba 1.12 level => $self->{must_level},
5702     token => $t);
5703     return ($t, undef);
5704     }
5705    
5706     $prop_value{'list-style-image'}
5707 wakaba 1.13 = ['URI', $t->{value}, \($self->{base_uri})];
5708 wakaba 1.12 $t = $tt->get_next_token;
5709     } else {
5710     if ($f == 1) {
5711 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5712 wakaba 1.12 level => $self->{must_level},
5713 wakaba 1.38 uri => \$self->{href},
5714 wakaba 1.12 token => $t);
5715     return ($t, undef);
5716     } else {
5717     last F;
5718     }
5719     }
5720    
5721     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5722     } # F
5723     ## NOTE: No browser support |list-style: url(xxx|{EOF}.
5724    
5725     if ($none == 1) {
5726     if (exists $prop_value{'list-style-type'}) {
5727     if (exists $prop_value{'list-style-image'}) {
5728 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5729 wakaba 1.38 uri => \$self->{href},
5730 wakaba 1.12 level => $self->{must_level},
5731     token => $t);
5732     return ($t, undef);
5733     } else {
5734     $prop_value{'list-style-image'} = ['KEYWORD', 'none'];
5735     }
5736     } else {
5737     $prop_value{'list-style-type'} = ['KEYWORD', 'none'];
5738     $prop_value{'list-style-image'} = ['KEYWORD', 'none']
5739     unless exists $prop_value{'list-style-image'};
5740     }
5741     } elsif ($none == 2) {
5742     if (exists $prop_value{'list-style-type'}) {
5743 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5744 wakaba 1.38 uri => \$self->{href},
5745 wakaba 1.12 level => $self->{must_level},
5746     token => $t);
5747     return ($t, undef);
5748     }
5749     if (exists $prop_value{'list-style-image'}) {
5750 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5751 wakaba 1.38 uri => \$self->{href},
5752 wakaba 1.12 level => $self->{must_level},
5753     token => $t);
5754     return ($t, undef);
5755     }
5756    
5757     $prop_value{'list-style-type'} = ['KEYWORD', 'none'];
5758     $prop_value{'list-style-image'} = ['KEYWORD', 'none'];
5759     } elsif ($none == 3) {
5760 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5761 wakaba 1.38 uri => \$self->{href},
5762 wakaba 1.12 level => $self->{must_level},
5763     token => $t);
5764     return ($t, undef);
5765     }
5766    
5767     for (qw/list-style-type list-style-position list-style-image/) {
5768     $prop_value{$_} = $Prop->{$_}->{initial} unless exists $prop_value{$_};
5769     }
5770    
5771     return ($t, \%prop_value);
5772     },
5773 wakaba 1.43 ## NOTE: We don't merge longhands in |css_text| serialization,
5774     ## since no browser does.
5775     serialize_shorthand => sub {
5776     my $self = shift;
5777    
5778     ## NOTE: Don't omit any value even if it is the initial value,
5779     ## since WinIE is buggy.
5780 wakaba 1.12
5781 wakaba 1.43 my $type = $self->list_style_type;
5782     return {} unless length $type;
5783     my $type_i = $self->get_property_priority ('list-style-type');
5784     my $image = $self->list_style_image;
5785     return {} unless length $image;
5786     my $image_i = $self->get_property_priority ('list-style-image');
5787     return {} unless $type_i eq $image_i;
5788     my $position = $self->list_style_position;
5789     return {} unless length $position;
5790     my $position_i = $self->get_property_priority ('list-style-position');
5791     return {} unless $type_i eq $position_i;
5792    
5793 wakaba 1.45 return {'list-style' => [$type . ' ' . $image . ' ' . $position, $type_i]};
5794 wakaba 1.12 },
5795     };
5796     $Attr->{list_style} = $Prop->{'list-style'};
5797    
5798 wakaba 1.16 ## NOTE: Future version of the implementation will change the way to
5799     ## store the parsed value to support CSS 3 properties.
5800     $Prop->{'text-decoration'} = {
5801     css => 'text-decoration',
5802     dom => 'text_decoration',
5803     key => 'text_decoration',
5804     parse => sub {
5805     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5806    
5807     my $value = ['DECORATION']; # , underline, overline, line-through, blink
5808    
5809     if ($t->{type} == IDENT_TOKEN) {
5810     my $v = lc $t->{value}; ## TODO: case
5811     $t = $tt->get_next_token;
5812     if ($v eq 'inherit') {
5813     return ($t, {$prop_name => ['INHERIT']});
5814     } elsif ($v eq 'none') {
5815     return ($t, {$prop_name => $value});
5816     } elsif ($v eq 'underline' and
5817     $self->{prop_value}->{$prop_name}->{$v}) {
5818     $value->[1] = 1;
5819     } elsif ($v eq 'overline' and
5820     $self->{prop_value}->{$prop_name}->{$v}) {
5821     $value->[2] = 1;
5822     } elsif ($v eq 'line-through' and
5823     $self->{prop_value}->{$prop_name}->{$v}) {
5824     $value->[3] = 1;
5825     } elsif ($v eq 'blink' and
5826     $self->{prop_value}->{$prop_name}->{$v}) {
5827     $value->[4] = 1;
5828     } else {
5829 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5830 wakaba 1.16 level => $self->{must_level},
5831 wakaba 1.38 uri => \$self->{href},
5832 wakaba 1.16 token => $t);
5833     return ($t, undef);
5834     }
5835     }
5836    
5837     F: {
5838     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5839     last F unless $t->{type} == IDENT_TOKEN;
5840    
5841     my $v = lc $t->{value}; ## TODO: case
5842     $t = $tt->get_next_token;
5843     if ($v eq 'underline' and
5844     $self->{prop_value}->{$prop_name}->{$v}) {
5845     $value->[1] = 1;
5846     } elsif ($v eq 'overline' and
5847     $self->{prop_value}->{$prop_name}->{$v}) {
5848     $value->[1] = 2;
5849     } elsif ($v eq 'line-through' and
5850     $self->{prop_value}->{$prop_name}->{$v}) {
5851     $value->[1] = 3;
5852     } elsif ($v eq 'blink' and
5853     $self->{prop_value}->{$prop_name}->{$v}) {
5854     $value->[1] = 4;
5855     } else {
5856     last F;
5857     }
5858    
5859     redo F;
5860     } # F
5861    
5862     return ($t, {$prop_name => $value});
5863     },
5864     serialize => $default_serializer,
5865     initial => ["KEYWORD", "none"],
5866     #inherited => 0,
5867     compute => $compute_as_specified,
5868     };
5869     $Attr->{text_decoration} = $Prop->{'text-decoration'};
5870     $Key->{text_decoration} = $Prop->{'text-decoration'};
5871    
5872 wakaba 1.1 1;
5873 wakaba 1.52 ## $Date: 2008/01/27 06:42:05 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24