/[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.40 - (hide annotations) (download)
Tue Jan 22 12:47:26 2008 UTC (16 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.39: +17 -2 lines
++ whatpm/t/ChangeLog	22 Jan 2008 12:47:21 -0000
2008-01-22  Wakaba  <wakaba@suika.fam.cx>

	* css-1.dat: Basic tests for forward compatible parsing
	are added.

	* CSS-Parser-1.t: Support for |#errors| validation.

++ whatpm/Whatpm/CSS/ChangeLog	22 Jan 2008 12:44:31 -0000
2008-01-22  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm (new {onerror}): The default error handler (outputting
	to the standard error output) is defined.
	(parse_char_string {get_char}): Set the next number to the
	column number of the last character as the column of the
	end of file pseudo-character.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24