/[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.41 - (hide annotations) (download)
Thu Jan 24 12:12:34 2008 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.40: +7 -2 lines
++ whatpm/t/ChangeLog	24 Jan 2008 12:12:26 -0000
	* CSS-Parser-1.t: Test data file |css-visual.dat| is added.
	Support for the quirks mode.

	* css-visual.dat: New file.

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

++ whatpm/Whatpm/CSS/ChangeLog	24 Jan 2008 12:11:54 -0000
2008-01-24  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm: Support for the |+| sign in 'margin-top' and
	similar properties.

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 wakaba 1.41 my $has_sign;
2217 wakaba 1.19 if ($t->{type} == MINUS_TOKEN) {
2218     $t = $tt->get_next_token;
2219 wakaba 1.41 $has_sign = 1;
2220 wakaba 1.19 $sign = -1;
2221 wakaba 1.41 } elsif ($t->{type} == PLUS_TOKEN) {
2222     $t = $tt->get_next_token;
2223     $has_sign = 1;
2224 wakaba 1.19 }
2225 wakaba 1.22 my $allow_negative = $Prop->{$prop_name}->{allow_negative};
2226 wakaba 1.19
2227     if ($t->{type} == DIMENSION_TOKEN) {
2228     my $value = $t->{number} * $sign;
2229     my $unit = lc $t->{value}; ## TODO: case
2230     $t = $tt->get_next_token;
2231 wakaba 1.22 if ($length_unit->{$unit} and ($allow_negative or $value >= 0)) {
2232 wakaba 1.19 return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2233     }
2234     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
2235     my $value = $t->{number} * $sign;
2236     $t = $tt->get_next_token;
2237 wakaba 1.22 return ($t, {$prop_name => ['PERCENTAGE', $value]})
2238     if $allow_negative or $value >= 0;
2239 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
2240 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
2241     my $value = $t->{number} * $sign;
2242     $t = $tt->get_next_token;
2243 wakaba 1.22 return ($t, {$prop_name => ['DIMENSION', $value, 'px']})
2244     if $allow_negative or $value >= 0;
2245 wakaba 1.41 } elsif (not $has_sign and $t->{type} == IDENT_TOKEN) {
2246 wakaba 1.19 my $value = lc $t->{value}; ## TODO: case
2247 wakaba 1.22 if ($Prop->{$prop_name}->{keyword}->{$value}) {
2248 wakaba 1.29 $t = $tt->get_next_token;
2249 wakaba 1.19 return ($t, {$prop_name => ['KEYWORD', $value]});
2250     } elsif ($value eq 'inherit') {
2251 wakaba 1.29 $t = $tt->get_next_token;
2252 wakaba 1.19 return ($t, {$prop_name => ['INHERIT']});
2253     }
2254 wakaba 1.29 ## NOTE: In the "else" case, don't procede the |$t| pointer
2255     ## for the support of 'border-top' property (and similar ones).
2256 wakaba 1.19 }
2257    
2258 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2259 wakaba 1.19 level => $self->{must_level},
2260 wakaba 1.38 uri => \$self->{href},
2261 wakaba 1.19 token => $t);
2262     return ($t, undef);
2263     },
2264 wakaba 1.22 allow_negative => 1,
2265     keyword => {auto => 1},
2266 wakaba 1.19 serialize => $default_serializer,
2267     initial => ['DIMENSION', 0, 'px'],
2268     #inherited => 0,
2269     compute => $compute_length,
2270     };
2271     $Attr->{margin_top} = $Prop->{'margin-top'};
2272     $Key->{margin_top} = $Prop->{'margin-top'};
2273    
2274     $Prop->{'margin-bottom'} = {
2275     css => 'margin-bottom',
2276     dom => 'margin_bottom',
2277     key => 'margin_bottom',
2278     parse => $Prop->{'margin-top'}->{parse},
2279 wakaba 1.22 allow_negative => 1,
2280     keyword => {auto => 1},
2281 wakaba 1.19 serialize => $default_serializer,
2282     initial => ['DIMENSION', 0, 'px'],
2283     #inherited => 0,
2284     compute => $compute_length,
2285     };
2286     $Attr->{margin_bottom} = $Prop->{'margin-bottom'};
2287     $Key->{margin_bottom} = $Prop->{'margin-bottom'};
2288    
2289     $Prop->{'margin-right'} = {
2290     css => 'margin-right',
2291     dom => 'margin_right',
2292     key => 'margin_right',
2293     parse => $Prop->{'margin-top'}->{parse},
2294 wakaba 1.22 allow_negative => 1,
2295     keyword => {auto => 1},
2296 wakaba 1.19 serialize => $default_serializer,
2297     initial => ['DIMENSION', 0, 'px'],
2298     #inherited => 0,
2299     compute => $compute_length,
2300     };
2301     $Attr->{margin_right} = $Prop->{'margin-right'};
2302     $Key->{margin_right} = $Prop->{'margin-right'};
2303    
2304     $Prop->{'margin-left'} = {
2305     css => 'margin-left',
2306     dom => 'margin_left',
2307     key => 'margin_left',
2308     parse => $Prop->{'margin-top'}->{parse},
2309 wakaba 1.22 allow_negative => 1,
2310     keyword => {auto => 1},
2311 wakaba 1.19 serialize => $default_serializer,
2312     initial => ['DIMENSION', 0, 'px'],
2313     #inherited => 0,
2314     compute => $compute_length,
2315     };
2316     $Attr->{margin_left} = $Prop->{'margin-left'};
2317     $Key->{margin_left} = $Prop->{'margin-left'};
2318    
2319 wakaba 1.21 $Prop->{top} = {
2320     css => 'top',
2321     dom => 'top',
2322     key => 'top',
2323     parse => $Prop->{'margin-top'}->{parse},
2324 wakaba 1.22 allow_negative => 1,
2325     keyword => {auto => 1},
2326 wakaba 1.21 serialize => $default_serializer,
2327     initial => ['KEYWORD', 'auto'],
2328     #inherited => 0,
2329     compute_multiple => sub {
2330     my ($self, $element, $eid, $prop_name) = @_;
2331    
2332     my $pos_value = $self->get_computed_value ($element, 'position');
2333     if (defined $pos_value and $pos_value->[0] eq 'KEYWORD') {
2334     if ($pos_value->[1] eq 'static') {
2335     $self->{computed_value}->{$eid}->{top} = ['KEYWORD', 'auto'];
2336     $self->{computed_value}->{$eid}->{bottom} = ['KEYWORD', 'auto'];
2337     return;
2338     } elsif ($pos_value->[1] eq 'relative') {
2339     my $top_specified = $self->get_specified_value_no_inherit
2340     ($element, 'top');
2341     if (defined $top_specified and
2342     ($top_specified->[0] eq 'DIMENSION' or
2343     $top_specified->[0] eq 'PERCENTAGE')) {
2344     my $tv = $self->{computed_value}->{$eid}->{top}
2345     = $compute_length->($self, $element, 'top', $top_specified);
2346     $self->{computed_value}->{$eid}->{bottom}
2347     = [$tv->[0], -$tv->[1], $tv->[2]];
2348     } else { # top: auto
2349     my $bottom_specified = $self->get_specified_value_no_inherit
2350     ($element, 'bottom');
2351     if (defined $bottom_specified and
2352     ($bottom_specified->[0] eq 'DIMENSION' or
2353     $bottom_specified->[0] eq 'PERCENTAGE')) {
2354     my $tv = $self->{computed_value}->{$eid}->{bottom}
2355     = $compute_length->($self, $element, 'bottom',
2356     $bottom_specified);
2357     $self->{computed_value}->{$eid}->{top}
2358     = [$tv->[0], -$tv->[1], $tv->[2]];
2359     } else { # bottom: auto
2360     $self->{computed_value}->{$eid}->{top} = ['DIMENSION', 0, 'px'];
2361     $self->{computed_value}->{$eid}->{bottom} = ['DIMENSION', 0, 'px'];
2362     }
2363     }
2364     return;
2365     }
2366     }
2367    
2368     my $top_specified = $self->get_specified_value_no_inherit
2369     ($element, 'top');
2370     $self->{computed_value}->{$eid}->{top}
2371     = $compute_length->($self, $element, 'top', $top_specified);
2372     my $bottom_specified = $self->get_specified_value_no_inherit
2373     ($element, 'bottom');
2374     $self->{computed_value}->{$eid}->{bottom}
2375     = $compute_length->($self, $element, 'bottom', $bottom_specified);
2376     },
2377     };
2378     $Attr->{top} = $Prop->{top};
2379     $Key->{top} = $Prop->{top};
2380    
2381     $Prop->{bottom} = {
2382     css => 'bottom',
2383     dom => 'bottom',
2384     key => 'bottom',
2385     parse => $Prop->{'margin-top'}->{parse},
2386 wakaba 1.22 allow_negative => 1,
2387     keyword => {auto => 1},
2388 wakaba 1.21 serialize => $default_serializer,
2389     initial => ['KEYWORD', 'auto'],
2390     #inherited => 0,
2391     compute_multiple => $Prop->{top}->{compute_multiple},
2392     };
2393     $Attr->{bottom} = $Prop->{bottom};
2394     $Key->{bottom} = $Prop->{bottom};
2395    
2396     $Prop->{left} = {
2397     css => 'left',
2398     dom => 'left',
2399     key => 'left',
2400     parse => $Prop->{'margin-top'}->{parse},
2401 wakaba 1.22 allow_negative => 1,
2402     keyword => {auto => 1},
2403 wakaba 1.21 serialize => $default_serializer,
2404     initial => ['KEYWORD', 'auto'],
2405     #inherited => 0,
2406     compute_multiple => sub {
2407     my ($self, $element, $eid, $prop_name) = @_;
2408    
2409     my $pos_value = $self->get_computed_value ($element, 'position');
2410     if (defined $pos_value and $pos_value->[0] eq 'KEYWORD') {
2411     if ($pos_value->[1] eq 'static') {
2412     $self->{computed_value}->{$eid}->{left} = ['KEYWORD', 'auto'];
2413     $self->{computed_value}->{$eid}->{right} = ['KEYWORD', 'auto'];
2414     return;
2415     } elsif ($pos_value->[1] eq 'relative') {
2416     my $left_specified = $self->get_specified_value_no_inherit
2417     ($element, 'left');
2418     if (defined $left_specified and
2419     ($left_specified->[0] eq 'DIMENSION' or
2420     $left_specified->[0] eq 'PERCENTAGE')) {
2421     my $right_specified = $self->get_specified_value_no_inherit
2422     ($element, 'right');
2423     if (defined $right_specified and
2424     ($right_specified->[0] eq 'DIMENSION' or
2425     $right_specified->[0] eq 'PERCENTAGE')) {
2426     my $direction = $self->get_computed_value ($element, 'direction');
2427     if (defined $direction and $direction->[0] eq 'KEYWORD' and
2428     $direction->[0] eq 'ltr') {
2429     my $tv = $self->{computed_value}->{$eid}->{left}
2430     = $compute_length->($self, $element, 'left',
2431     $left_specified);
2432     $self->{computed_value}->{$eid}->{right}
2433     = [$tv->[0], -$tv->[1], $tv->[2]];
2434     } else {
2435     my $tv = $self->{computed_value}->{$eid}->{right}
2436     = $compute_length->($self, $element, 'right',
2437     $right_specified);
2438     $self->{computed_value}->{$eid}->{left}
2439     = [$tv->[0], -$tv->[1], $tv->[2]];
2440     }
2441     } else {
2442     my $tv = $self->{computed_value}->{$eid}->{left}
2443     = $compute_length->($self, $element, 'left', $left_specified);
2444     $self->{computed_value}->{$eid}->{right}
2445     = [$tv->[0], -$tv->[1], $tv->[2]];
2446     }
2447     } else { # left: auto
2448     my $right_specified = $self->get_specified_value_no_inherit
2449     ($element, 'right');
2450     if (defined $right_specified and
2451     ($right_specified->[0] eq 'DIMENSION' or
2452     $right_specified->[0] eq 'PERCENTAGE')) {
2453     my $tv = $self->{computed_value}->{$eid}->{right}
2454     = $compute_length->($self, $element, 'right',
2455     $right_specified);
2456     $self->{computed_value}->{$eid}->{left}
2457     = [$tv->[0], -$tv->[1], $tv->[2]];
2458     } else { # right: auto
2459     $self->{computed_value}->{$eid}->{left} = ['DIMENSION', 0, 'px'];
2460     $self->{computed_value}->{$eid}->{right} = ['DIMENSION', 0, 'px'];
2461     }
2462     }
2463     return;
2464     }
2465     }
2466    
2467     my $left_specified = $self->get_specified_value_no_inherit
2468     ($element, 'left');
2469     $self->{computed_value}->{$eid}->{left}
2470     = $compute_length->($self, $element, 'left', $left_specified);
2471     my $right_specified = $self->get_specified_value_no_inherit
2472     ($element, 'right');
2473     $self->{computed_value}->{$eid}->{right}
2474     = $compute_length->($self, $element, 'right', $right_specified);
2475     },
2476     };
2477     $Attr->{left} = $Prop->{left};
2478     $Key->{left} = $Prop->{left};
2479    
2480     $Prop->{right} = {
2481     css => 'right',
2482     dom => 'right',
2483     key => 'right',
2484     parse => $Prop->{'margin-top'}->{parse},
2485     serialize => $default_serializer,
2486     initial => ['KEYWORD', 'auto'],
2487     #inherited => 0,
2488     compute_multiple => $Prop->{left}->{compute_multiple},
2489     };
2490     $Attr->{right} = $Prop->{right};
2491     $Key->{right} = $Prop->{right};
2492    
2493 wakaba 1.22 $Prop->{width} = {
2494     css => 'width',
2495     dom => 'width',
2496     key => 'width',
2497     parse => $Prop->{'margin-top'}->{parse},
2498     #allow_negative => 0,
2499     keyword => {auto => 1},
2500     serialize => $default_serializer,
2501     initial => ['KEYWORD', 'auto'],
2502     #inherited => 0,
2503     compute => $compute_length,
2504     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/width> for
2505     ## browser compatibility issues.
2506     };
2507     $Attr->{width} = $Prop->{width};
2508     $Key->{width} = $Prop->{width};
2509    
2510     $Prop->{'min-width'} = {
2511     css => 'min-width',
2512     dom => 'min_width',
2513     key => 'min_width',
2514     parse => $Prop->{'margin-top'}->{parse},
2515     #allow_negative => 0,
2516     #keyword => {},
2517     serialize => $default_serializer,
2518     initial => ['DIMENSION', 0, 'px'],
2519     #inherited => 0,
2520     compute => $compute_length,
2521     };
2522     $Attr->{min_width} = $Prop->{'min-width'};
2523     $Key->{min_width} = $Prop->{'min-width'};
2524    
2525     $Prop->{'max-width'} = {
2526     css => 'max-width',
2527     dom => 'max_width',
2528     key => 'max_width',
2529     parse => $Prop->{'margin-top'}->{parse},
2530     #allow_negative => 0,
2531     keyword => {none => 1},
2532     serialize => $default_serializer,
2533     initial => ['KEYWORD', 'none'],
2534     #inherited => 0,
2535     compute => $compute_length,
2536     };
2537     $Attr->{max_width} = $Prop->{'max-width'};
2538     $Key->{max_width} = $Prop->{'max-width'};
2539    
2540     $Prop->{height} = {
2541     css => 'height',
2542     dom => 'height',
2543     key => 'height',
2544     parse => $Prop->{'margin-top'}->{parse},
2545     #allow_negative => 0,
2546     keyword => {auto => 1},
2547     serialize => $default_serializer,
2548     initial => ['KEYWORD', 'auto'],
2549     #inherited => 0,
2550     compute => $compute_length,
2551     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/height> for
2552     ## browser compatibility issues.
2553     };
2554     $Attr->{height} = $Prop->{height};
2555     $Key->{height} = $Prop->{height};
2556    
2557     $Prop->{'min-height'} = {
2558     css => 'min-height',
2559     dom => 'min_height',
2560     key => 'min_height',
2561     parse => $Prop->{'margin-top'}->{parse},
2562     #allow_negative => 0,
2563     #keyword => {},
2564     serialize => $default_serializer,
2565     initial => ['DIMENSION', 0, 'px'],
2566     #inherited => 0,
2567     compute => $compute_length,
2568     };
2569     $Attr->{min_height} = $Prop->{'min-height'};
2570     $Key->{min_height} = $Prop->{'min-height'};
2571    
2572     $Prop->{'max-height'} = {
2573     css => 'max-height',
2574     dom => 'max_height',
2575     key => 'max_height',
2576     parse => $Prop->{'margin-top'}->{parse},
2577     #allow_negative => 0,
2578     keyword => {none => 1},
2579     serialize => $default_serializer,
2580     initial => ['KEYWORD', 'none'],
2581     #inherited => 0,
2582     compute => $compute_length,
2583     };
2584     $Attr->{max_height} = $Prop->{'max-height'};
2585     $Key->{max_height} = $Prop->{'max-height'};
2586    
2587     $Prop->{'line-height'} = {
2588     css => 'line-height',
2589     dom => 'line_height',
2590     key => 'line_height',
2591 wakaba 1.19 parse => sub {
2592     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2593    
2594 wakaba 1.22 ## NOTE: Similar to 'margin-top', but different handling
2595     ## for unitless numbers.
2596    
2597 wakaba 1.19 my $sign = 1;
2598     if ($t->{type} == MINUS_TOKEN) {
2599     $t = $tt->get_next_token;
2600     $sign = -1;
2601     }
2602 wakaba 1.22 my $allow_negative = $Prop->{$prop_name}->{allow_negative};
2603 wakaba 1.19
2604     if ($t->{type} == DIMENSION_TOKEN) {
2605     my $value = $t->{number} * $sign;
2606     my $unit = lc $t->{value}; ## TODO: case
2607     $t = $tt->get_next_token;
2608     if ($length_unit->{$unit} and $value >= 0) {
2609     return ($t, {$prop_name => ['DIMENSION', $value, $unit]});
2610     }
2611     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
2612     my $value = $t->{number} * $sign;
2613     $t = $tt->get_next_token;
2614 wakaba 1.22 return ($t, {$prop_name => ['PERCENTAGE', $value]})
2615     if $value >= 0;
2616     } elsif ($t->{type} == NUMBER_TOKEN) {
2617 wakaba 1.19 my $value = $t->{number} * $sign;
2618     $t = $tt->get_next_token;
2619 wakaba 1.22 return ($t, {$prop_name => ['NUMBER', $value]}) if $value >= 0;
2620 wakaba 1.19 } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
2621     my $value = lc $t->{value}; ## TODO: case
2622     $t = $tt->get_next_token;
2623 wakaba 1.22 if ($value eq 'normal') {
2624     return ($t, {$prop_name => ['KEYWORD', $value]});
2625     } elsif ($value eq 'inherit') {
2626 wakaba 1.19 return ($t, {$prop_name => ['INHERIT']});
2627     }
2628     }
2629    
2630 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2631 wakaba 1.19 level => $self->{must_level},
2632 wakaba 1.38 uri => \$self->{href},
2633 wakaba 1.19 token => $t);
2634     return ($t, undef);
2635     },
2636     serialize => $default_serializer,
2637 wakaba 1.22 initial => ['KEYWORD', 'normal'],
2638     inherited => 1,
2639     compute => $compute_length,
2640     };
2641     $Attr->{line_height} = $Prop->{'line-height'};
2642     $Key->{line_height} = $Prop->{'line-height'};
2643    
2644     $Prop->{'vertical-align'} = {
2645     css => 'vertical-align',
2646     dom => 'vertical_align',
2647     key => 'vertical_align',
2648     parse => $Prop->{'margin-top'}->{parse},
2649     allow_negative => 1,
2650     keyword => {
2651     baseline => 1, sub => 1, super => 1, top => 1, 'text-top' => 1,
2652     middle => 1, bottom => 1, 'text-bottom' => 1,
2653     },
2654     ## NOTE: Currently, we don't support option to select subset of keywords
2655     ## supported by application (i.e.
2656     ## $parser->{prop_value}->{'line-height'->{$keyword}). Should we support
2657     ## it?
2658     serialize => $default_serializer,
2659     initial => ['KEYWORD', 'baseline'],
2660     #inherited => 0,
2661     compute => $compute_length,
2662     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/vertical-align> for
2663     ## browser compatibility issues.
2664     };
2665     $Attr->{vertical_align} = $Prop->{'vertical-align'};
2666     $Key->{vertical_align} = $Prop->{'vertical-align'};
2667    
2668 wakaba 1.23 $Prop->{'text-indent'} = {
2669     css => 'text-indent',
2670     dom => 'text_indent',
2671     key => 'text_indent',
2672     parse => $Prop->{'margin-top'}->{parse},
2673     allow_negative => 1,
2674     keyword => {},
2675     serialize => $default_serializer,
2676     initial => ['DIMENSION', 0, 'px'],
2677     inherited => 1,
2678     compute => $compute_length,
2679     };
2680     $Attr->{text_indent} = $Prop->{'text-indent'};
2681     $Key->{text_indent} = $Prop->{'text-indent'};
2682    
2683 wakaba 1.27 $Prop->{'background-position-x'} = {
2684     css => 'background-position-x',
2685     dom => 'background_position_x',
2686     key => 'background_position_x',
2687     parse => $Prop->{'margin-top'}->{parse},
2688     allow_negative => 1,
2689     keyword => {left => 1, center => 1, right => 1},
2690     serialize => $default_serializer,
2691     initial => ['PERCENTAGE', 0],
2692     #inherited => 0,
2693     compute => sub {
2694     my ($self, $element, $prop_name, $specified_value) = @_;
2695    
2696     if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
2697     my $v = {
2698     left => 0, center => 50, right => 100, top => 0, bottom => 100,
2699     }->{$specified_value->[1]};
2700     if (defined $v) {
2701     return ['PERCENTAGE', $v];
2702     } else {
2703     return $specified_value;
2704     }
2705     } else {
2706     return $compute_length->(@_);
2707     }
2708     },
2709 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
2710 wakaba 1.27 };
2711     $Attr->{background_position_x} = $Prop->{'background-position-x'};
2712     $Key->{background_position_x} = $Prop->{'background-position-x'};
2713    
2714     $Prop->{'background-position-y'} = {
2715     css => 'background-position-y',
2716     dom => 'background_position_y',
2717     key => 'background_position_y',
2718     parse => $Prop->{'margin-top'}->{parse},
2719     allow_negative => 1,
2720     keyword => {top => 1, center => 1, bottom => 1},
2721     serialize => $default_serializer,
2722 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
2723 wakaba 1.27 initial => ['PERCENTAGE', 0],
2724     #inherited => 0,
2725     compute => $Prop->{'background-position-x'}->{compute},
2726     };
2727     $Attr->{background_position_y} = $Prop->{'background-position-y'};
2728     $Key->{background_position_y} = $Prop->{'background-position-y'};
2729    
2730 wakaba 1.22 $Prop->{'padding-top'} = {
2731     css => 'padding-top',
2732     dom => 'padding_top',
2733     key => 'padding_top',
2734     parse => $Prop->{'margin-top'}->{parse},
2735     #allow_negative => 0,
2736     #keyword => {},
2737     serialize => $default_serializer,
2738 wakaba 1.19 initial => ['DIMENSION', 0, 'px'],
2739     #inherited => 0,
2740     compute => $compute_length,
2741     };
2742     $Attr->{padding_top} = $Prop->{'padding-top'};
2743     $Key->{padding_top} = $Prop->{'padding-top'};
2744    
2745     $Prop->{'padding-bottom'} = {
2746     css => 'padding-bottom',
2747     dom => 'padding_bottom',
2748     key => 'padding_bottom',
2749     parse => $Prop->{'padding-top'}->{parse},
2750 wakaba 1.22 #allow_negative => 0,
2751     #keyword => {},
2752 wakaba 1.19 serialize => $default_serializer,
2753     initial => ['DIMENSION', 0, 'px'],
2754     #inherited => 0,
2755     compute => $compute_length,
2756     };
2757     $Attr->{padding_bottom} = $Prop->{'padding-bottom'};
2758     $Key->{padding_bottom} = $Prop->{'padding-bottom'};
2759    
2760     $Prop->{'padding-right'} = {
2761     css => 'padding-right',
2762     dom => 'padding_right',
2763     key => 'padding_right',
2764     parse => $Prop->{'padding-top'}->{parse},
2765 wakaba 1.22 #allow_negative => 0,
2766     #keyword => {},
2767 wakaba 1.19 serialize => $default_serializer,
2768     initial => ['DIMENSION', 0, 'px'],
2769     #inherited => 0,
2770     compute => $compute_length,
2771     };
2772     $Attr->{padding_right} = $Prop->{'padding-right'};
2773     $Key->{padding_right} = $Prop->{'padding-right'};
2774    
2775     $Prop->{'padding-left'} = {
2776     css => 'padding-left',
2777     dom => 'padding_left',
2778     key => 'padding_left',
2779     parse => $Prop->{'padding-top'}->{parse},
2780 wakaba 1.22 #allow_negative => 0,
2781     #keyword => {},
2782 wakaba 1.19 serialize => $default_serializer,
2783     initial => ['DIMENSION', 0, 'px'],
2784     #inherited => 0,
2785     compute => $compute_length,
2786     };
2787     $Attr->{padding_left} = $Prop->{'padding-left'};
2788     $Key->{padding_left} = $Prop->{'padding-left'};
2789    
2790 wakaba 1.20 $Prop->{'border-top-width'} = {
2791     css => 'border-top-width',
2792     dom => 'border_top_width',
2793     key => 'border_top_width',
2794 wakaba 1.22 parse => $Prop->{'margin-top'}->{parse},
2795     #allow_negative => 0,
2796     keyword => {thin => 1, medium => 1, thick => 1},
2797 wakaba 1.20 serialize => $default_serializer,
2798 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
2799 wakaba 1.20 initial => ['KEYWORD', 'medium'],
2800     #inherited => 0,
2801     compute => sub {
2802     my ($self, $element, $prop_name, $specified_value) = @_;
2803    
2804 wakaba 1.23 ## NOTE: Used for 'border-top-width', 'border-right-width',
2805     ## 'border-bottom-width', 'border-right-width', and
2806     ## 'outline-width'.
2807    
2808 wakaba 1.20 my $style_prop = $prop_name;
2809     $style_prop =~ s/width/style/;
2810     my $style = $self->get_computed_value ($element, $style_prop);
2811     if (defined $style and $style->[0] eq 'KEYWORD' and
2812     ($style->[1] eq 'none' or $style->[1] eq 'hidden')) {
2813     return ['DIMENSION', 0, 'px'];
2814     }
2815    
2816     my $value = $compute_length->(@_);
2817     if (defined $value and $value->[0] eq 'KEYWORD') {
2818     if ($value->[1] eq 'thin') {
2819     return ['DIMENSION', 1, 'px']; ## Firefox/Opera
2820     } elsif ($value->[1] eq 'medium') {
2821     return ['DIMENSION', 3, 'px']; ## Firefox/Opera
2822     } elsif ($value->[1] eq 'thick') {
2823     return ['DIMENSION', 5, 'px']; ## Firefox
2824     }
2825     }
2826     return $value;
2827     },
2828 wakaba 1.23 ## NOTE: CSS3 will allow <percentage> as an option in <border-width>.
2829     ## Opera 9 has already implemented it.
2830 wakaba 1.20 };
2831     $Attr->{border_top_width} = $Prop->{'border-top-width'};
2832     $Key->{border_top_width} = $Prop->{'border-top-width'};
2833    
2834     $Prop->{'border-right-width'} = {
2835     css => 'border-right-width',
2836     dom => 'border_right_width',
2837     key => 'border_right_width',
2838     parse => $Prop->{'border-top-width'}->{parse},
2839 wakaba 1.22 #allow_negative => 0,
2840     keyword => {thin => 1, medium => 1, thick => 1},
2841 wakaba 1.20 serialize => $default_serializer,
2842 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
2843 wakaba 1.20 initial => ['KEYWORD', 'medium'],
2844     #inherited => 0,
2845     compute => $Prop->{'border-top-width'}->{compute},
2846     };
2847     $Attr->{border_right_width} = $Prop->{'border-right-width'};
2848     $Key->{border_right_width} = $Prop->{'border-right-width'};
2849    
2850     $Prop->{'border-bottom-width'} = {
2851     css => 'border-bottom-width',
2852     dom => 'border_bottom_width',
2853     key => 'border_bottom_width',
2854     parse => $Prop->{'border-top-width'}->{parse},
2855 wakaba 1.22 #allow_negative => 0,
2856     keyword => {thin => 1, medium => 1, thick => 1},
2857 wakaba 1.20 serialize => $default_serializer,
2858 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
2859 wakaba 1.20 initial => ['KEYWORD', 'medium'],
2860     #inherited => 0,
2861     compute => $Prop->{'border-top-width'}->{compute},
2862     };
2863     $Attr->{border_bottom_width} = $Prop->{'border-bottom-width'};
2864     $Key->{border_bottom_width} = $Prop->{'border-bottom-width'};
2865    
2866     $Prop->{'border-left-width'} = {
2867     css => 'border-left-width',
2868     dom => 'border_left_width',
2869     key => 'border_left_width',
2870     parse => $Prop->{'border-top-width'}->{parse},
2871 wakaba 1.22 #allow_negative => 0,
2872     keyword => {thin => 1, medium => 1, thick => 1},
2873 wakaba 1.20 serialize => $default_serializer,
2874 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
2875 wakaba 1.20 initial => ['KEYWORD', 'medium'],
2876     #inherited => 0,
2877     compute => $Prop->{'border-top-width'}->{compute},
2878     };
2879     $Attr->{border_left_width} = $Prop->{'border-left-width'};
2880     $Key->{border_left_width} = $Prop->{'border-left-width'};
2881    
2882 wakaba 1.23 $Prop->{'outline-width'} = {
2883     css => 'outline-width',
2884     dom => 'outline_width',
2885     key => 'outline_width',
2886     parse => $Prop->{'border-top-width'}->{parse},
2887     #allow_negative => 0,
2888     keyword => {thin => 1, medium => 1, thick => 1},
2889     serialize => $default_serializer,
2890 wakaba 1.29 serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
2891 wakaba 1.23 initial => ['KEYWORD', 'medium'],
2892     #inherited => 0,
2893     compute => $Prop->{'border-top-width'}->{compute},
2894     };
2895     $Attr->{outline_width} = $Prop->{'outline-width'};
2896     $Key->{outline_width} = $Prop->{'outline-width'};
2897    
2898 wakaba 1.15 $Prop->{'font-weight'} = {
2899     css => 'font-weight',
2900     dom => 'font_weight',
2901     key => 'font_weight',
2902     parse => sub {
2903     my ($self, $prop_name, $tt, $t, $onerror) = @_;
2904    
2905     if ($t->{type} == NUMBER_TOKEN) {
2906     ## ISSUE: See <http://suika.fam.cx/gate/2005/sw/font-weight> for
2907     ## browser compatibility issue.
2908     my $value = $t->{number};
2909     $t = $tt->get_next_token;
2910     if ($value % 100 == 0 and 100 <= $value and $value <= 900) {
2911     return ($t, {$prop_name => ['WEIGHT', $value, 0]});
2912     }
2913     } elsif ($t->{type} == IDENT_TOKEN) {
2914     my $value = lc $t->{value}; ## TODO: case
2915     $t = $tt->get_next_token;
2916     if ({
2917     normal => 1, bold => 1, bolder => 1, lighter => 1,
2918     }->{$value}) {
2919     return ($t, {$prop_name => ['KEYWORD', $value]});
2920     } elsif ($value eq 'inherit') {
2921     return ($t, {$prop_name => ['INHERIT']});
2922     }
2923     }
2924    
2925 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
2926 wakaba 1.15 level => $self->{must_level},
2927 wakaba 1.38 uri => \$self->{href},
2928 wakaba 1.15 token => $t);
2929     return ($t, undef);
2930     },
2931     serialize => $default_serializer,
2932     initial => ['KEYWORD', 'normal'],
2933     inherited => 1,
2934     compute => sub {
2935     my ($self, $element, $prop_name, $specified_value) = @_;
2936    
2937 wakaba 1.17 if (defined $specified_value and $specified_value->[0] eq 'KEYWORD') {
2938 wakaba 1.15 if ($specified_value->[1] eq 'normal') {
2939     return ['WEIGHT', 400, 0];
2940     } elsif ($specified_value->[1] eq 'bold') {
2941     return ['WEIGHT', 700, 0];
2942     } elsif ($specified_value->[1] eq 'bolder') {
2943     my $parent_element = $element->manakai_parent_element;
2944     if (defined $parent_element) {
2945     my $parent_value = $self->get_cascaded_value
2946     ($parent_element, $prop_name); ## NOTE: What Firefox does.
2947     return ['WEIGHT', $parent_value->[1], $parent_value->[2] + 1];
2948     } else {
2949     return ['WEIGHT', 400, 1];
2950     }
2951     } elsif ($specified_value->[1] eq 'lighter') {
2952     my $parent_element = $element->manakai_parent_element;
2953     if (defined $parent_element) {
2954     my $parent_value = $self->get_cascaded_value
2955     ($parent_element, $prop_name); ## NOTE: What Firefox does.
2956     return ['WEIGHT', $parent_value->[1], $parent_value->[2] - 1];
2957     } else {
2958     return ['WEIGHT', 400, 1];
2959     }
2960     }
2961 wakaba 1.17 #} elsif (defined $specified_value and $specified_value->[0] eq 'WEIGHT') {
2962 wakaba 1.15 #
2963     }
2964    
2965     return $specified_value;
2966     },
2967     };
2968     $Attr->{font_weight} = $Prop->{'font-weight'};
2969     $Key->{font_weight} = $Prop->{'font-weight'};
2970    
2971 wakaba 1.13 my $uri_or_none_parser = sub {
2972 wakaba 1.11 my ($self, $prop_name, $tt, $t, $onerror) = @_;
2973    
2974 wakaba 1.13 if ($t->{type} == URI_TOKEN) {
2975 wakaba 1.11 my $value = $t->{value};
2976     $t = $tt->get_next_token;
2977     return ($t, {$prop_name => ['URI', $value, \($self->{base_uri})]});
2978     } elsif ($t->{type} == IDENT_TOKEN) {
2979     my $value = lc $t->{value}; ## TODO: case
2980     $t = $tt->get_next_token;
2981     if ($value eq 'none') {
2982     ## NOTE: |none| is the default value and therefore it must be
2983     ## supported anyway.
2984     return ($t, {$prop_name => ["KEYWORD", 'none']});
2985     } elsif ($value eq 'inherit') {
2986     return ($t, {$prop_name => ['INHERIT']});
2987     }
2988     ## NOTE: None of Firefox2, WinIE6, and Opera9 support this case.
2989     #} elsif ($t->{type} == URI_INVALID_TOKEN) {
2990     # my $value = $t->{value};
2991     # $t = $tt->get_next_token;
2992     # if ($t->{type} == EOF_TOKEN) {
2993 wakaba 1.39 # $onerror->(type => 'uri not closed',
2994 wakaba 1.11 # level => $self->{must_level},
2995 wakaba 1.38 # uri => \$self->{href},
2996 wakaba 1.11 # token => $t);
2997     #
2998     # return ($t, {$prop_name => ['URI', $value, \($self->{base_uri})]});
2999     # }
3000     }
3001    
3002 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3003 wakaba 1.11 level => $self->{must_level},
3004 wakaba 1.38 uri => \$self->{href},
3005 wakaba 1.11 token => $t);
3006     return ($t, undef);
3007 wakaba 1.13 }; # $uri_or_none_parser
3008    
3009 wakaba 1.14 my $compute_uri_or_none = sub {
3010 wakaba 1.11 my ($self, $element, $prop_name, $specified_value) = @_;
3011    
3012     if (defined $specified_value and
3013     $specified_value->[0] eq 'URI' and
3014     defined $specified_value->[2]) {
3015     require Message::DOM::DOMImplementation;
3016     return ['URI',
3017     Message::DOM::DOMImplementation->create_uri_reference
3018     ($specified_value->[1])
3019     ->get_absolute_reference (${$specified_value->[2]})
3020     ->get_uri_reference,
3021     $specified_value->[2]];
3022     }
3023    
3024     return $specified_value;
3025 wakaba 1.14 }; # $compute_uri_or_none
3026    
3027     $Prop->{'list-style-image'} = {
3028     css => 'list-style-image',
3029     dom => 'list_style_image',
3030     key => 'list_style_image',
3031     parse => $uri_or_none_parser,
3032     serialize => $default_serializer,
3033     initial => ['KEYWORD', 'none'],
3034     inherited => 1,
3035     compute => $compute_uri_or_none,
3036 wakaba 1.11 };
3037     $Attr->{list_style_image} = $Prop->{'list-style-image'};
3038     $Key->{list_style_image} = $Prop->{'list-style-image'};
3039    
3040 wakaba 1.15 $Prop->{'background-image'} = {
3041     css => 'background-image',
3042     dom => 'background_image',
3043     key => 'background_image',
3044     parse => $uri_or_none_parser,
3045     serialize => $default_serializer,
3046 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
3047 wakaba 1.15 initial => ['KEYWORD', 'none'],
3048     #inherited => 0,
3049     compute => $compute_uri_or_none,
3050     };
3051     $Attr->{background_image} = $Prop->{'background-image'};
3052     $Key->{background_image} = $Prop->{'background-image'};
3053    
3054 wakaba 1.7 my $border_style_keyword = {
3055     none => 1, hidden => 1, dotted => 1, dashed => 1, solid => 1,
3056     double => 1, groove => 1, ridge => 1, inset => 1, outset => 1,
3057     };
3058    
3059     $Prop->{'border-top-style'} = {
3060     css => 'border-top-style',
3061     dom => 'border_top_style',
3062     key => 'border_top_style',
3063     parse => $one_keyword_parser,
3064 wakaba 1.11 serialize => $default_serializer,
3065 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3066 wakaba 1.7 keyword => $border_style_keyword,
3067 wakaba 1.9 initial => ["KEYWORD", "none"],
3068     #inherited => 0,
3069     compute => $compute_as_specified,
3070 wakaba 1.7 };
3071     $Attr->{border_top_style} = $Prop->{'border-top-style'};
3072     $Key->{border_top_style} = $Prop->{'border-top-style'};
3073    
3074     $Prop->{'border-right-style'} = {
3075     css => 'border-right-style',
3076     dom => 'border_right_style',
3077     key => 'border_right_style',
3078     parse => $one_keyword_parser,
3079 wakaba 1.11 serialize => $default_serializer,
3080 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3081 wakaba 1.7 keyword => $border_style_keyword,
3082 wakaba 1.9 initial => ["KEYWORD", "none"],
3083     #inherited => 0,
3084     compute => $compute_as_specified,
3085 wakaba 1.7 };
3086     $Attr->{border_right_style} = $Prop->{'border-right-style'};
3087     $Key->{border_right_style} = $Prop->{'border-right-style'};
3088    
3089     $Prop->{'border-bottom-style'} = {
3090     css => 'border-bottom-style',
3091     dom => 'border_bottom_style',
3092     key => 'border_bottom_style',
3093     parse => $one_keyword_parser,
3094 wakaba 1.11 serialize => $default_serializer,
3095 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3096 wakaba 1.7 keyword => $border_style_keyword,
3097 wakaba 1.9 initial => ["KEYWORD", "none"],
3098     #inherited => 0,
3099     compute => $compute_as_specified,
3100 wakaba 1.7 };
3101     $Attr->{border_bottom_style} = $Prop->{'border-bottom-style'};
3102     $Key->{border_bottom_style} = $Prop->{'border-bottom-style'};
3103    
3104     $Prop->{'border-left-style'} = {
3105     css => 'border-left-style',
3106     dom => 'border_left_style',
3107     key => 'border_left_style',
3108     parse => $one_keyword_parser,
3109 wakaba 1.11 serialize => $default_serializer,
3110 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3111 wakaba 1.7 keyword => $border_style_keyword,
3112 wakaba 1.9 initial => ["KEYWORD", "none"],
3113     #inherited => 0,
3114     compute => $compute_as_specified,
3115 wakaba 1.7 };
3116     $Attr->{border_left_style} = $Prop->{'border-left-style'};
3117     $Key->{border_left_style} = $Prop->{'border-left-style'};
3118    
3119 wakaba 1.16 $Prop->{'outline-style'} = {
3120     css => 'outline-style',
3121     dom => 'outline_style',
3122     key => 'outline_style',
3123     parse => $one_keyword_parser,
3124     serialize => $default_serializer,
3125 wakaba 1.29 serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
3126 wakaba 1.23 keyword => {%$border_style_keyword},
3127 wakaba 1.16 initial => ['KEYWORD', 'none'],
3128     #inherited => 0,
3129     compute => $compute_as_specified,
3130     };
3131     $Attr->{outline_style} = $Prop->{'outline-style'};
3132     $Key->{outline_style} = $Prop->{'outline-style'};
3133 wakaba 1.23 delete $Prop->{'outline-style'}->{keyword}->{hidden};
3134 wakaba 1.16
3135 wakaba 1.31 my $generic_font_keywords => {
3136     serif => 1, 'sans-serif' => 1, cursive => 1,
3137     fantasy => 1, monospace => 1, '-manakai-default' => 1,
3138     '-manakai-caption' => 1, '-manakai-icon' => 1,
3139     '-manakai-menu' => 1, '-manakai-message-box' => 1,
3140     '-manakai-small-caption' => 1, '-manakai-status-bar' => 1,
3141     };
3142     ## NOTE: "All five generic font families are defined to exist in all CSS
3143     ## implementations (they need not necessarily map to five distinct actual
3144     ## fonts)." [CSS 2.1].
3145     ## NOTE: "If no font with the indicated characteristics exists on a given
3146     ## platform, the user agent should either intelligently substitute (e.g., a
3147     ## smaller version of the 'caption' font might be used for the 'small-caption'
3148     ## font), or substitute a user agent default font." [CSS 2.1].
3149    
3150 wakaba 1.15 $Prop->{'font-family'} = {
3151     css => 'font-family',
3152     dom => 'font_family',
3153     key => 'font_family',
3154     parse => sub {
3155     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3156    
3157     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/font-family> for
3158     ## how chaotic browsers are!
3159    
3160     my @prop_value;
3161    
3162     my $font_name = '';
3163     my $may_be_generic = 1;
3164 wakaba 1.31 my $may_be_inherit = ($prop_name ne 'font');
3165 wakaba 1.15 my $has_s = 0;
3166     F: {
3167     if ($t->{type} == IDENT_TOKEN) {
3168     undef $may_be_inherit if $has_s or length $font_name;
3169     undef $may_be_generic if $has_s or length $font_name;
3170     $font_name .= ' ' if $has_s;
3171     $font_name .= $t->{value};
3172     undef $has_s;
3173     $t = $tt->get_next_token;
3174     } elsif ($t->{type} == STRING_TOKEN) {
3175     $font_name .= ' ' if $has_s;
3176     $font_name .= $t->{value};
3177     undef $may_be_inherit;
3178     undef $may_be_generic;
3179     undef $has_s;
3180     $t = $tt->get_next_token;
3181 wakaba 1.31 } elsif ($t->{type} == COMMA_TOKEN) { ## TODO: case
3182     if ($may_be_generic and $generic_font_keywords->{lc $font_name}) {
3183 wakaba 1.15 push @prop_value, ['KEYWORD', $font_name];
3184     } elsif (not $may_be_generic or length $font_name) {
3185     push @prop_value, ["STRING", $font_name];
3186     }
3187     undef $may_be_inherit;
3188     $may_be_generic = 1;
3189     undef $has_s;
3190     $font_name = '';
3191     $t = $tt->get_next_token;
3192     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3193     } elsif ($t->{type} == S_TOKEN) {
3194     $has_s = 1;
3195     $t = $tt->get_next_token;
3196     } else {
3197 wakaba 1.31 if ($may_be_generic and $generic_font_keywords->{lc $font_name}) {
3198     push @prop_value, ['KEYWORD', $font_name]; ## TODO: case
3199 wakaba 1.15 } elsif (not $may_be_generic or length $font_name) {
3200     push @prop_value, ['STRING', $font_name];
3201     } else {
3202 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3203 wakaba 1.15 level => $self->{must_level},
3204 wakaba 1.38 uri => \$self->{href},
3205 wakaba 1.15 token => $t);
3206     return ($t, undef);
3207     }
3208     last F;
3209     }
3210     redo F;
3211     } # F
3212    
3213     if ($may_be_inherit and
3214     @prop_value == 1 and
3215     $prop_value[0]->[0] eq 'STRING' and
3216     lc $prop_value[0]->[1] eq 'inherit') { ## TODO: case
3217     return ($t, {$prop_name => ['INHERIT']});
3218     } else {
3219     unshift @prop_value, 'FONT';
3220     return ($t, {$prop_name => \@prop_value});
3221     }
3222     },
3223     serialize => sub {
3224     my ($self, $prop_name, $value) = @_;
3225    
3226     if ($value->[0] eq 'FONT') {
3227     return join ', ', map {
3228     if ($_->[0] eq 'STRING') {
3229     '"'.$_->[1].'"'; ## NOTE: This is what Firefox does.
3230     } elsif ($_->[0] eq 'KEYWORD') {
3231     $_->[1]; ## NOTE: This is what Firefox does.
3232     } else {
3233     ## NOTE: This should be an error.
3234     '""';
3235     }
3236     } @$value[1..$#$value];
3237     } elsif ($value->[0] eq 'INHERIT') {
3238     return 'inherit';
3239     } else {
3240 wakaba 1.34 return '';
3241 wakaba 1.15 }
3242     },
3243     initial => ['FONT', ['KEYWORD', '-manakai-default']],
3244     inherited => 1,
3245     compute => $compute_as_specified,
3246     };
3247     $Attr->{font_family} = $Prop->{'font-family'};
3248     $Key->{font_family} = $Prop->{'font-family'};
3249    
3250 wakaba 1.17 $Prop->{cursor} = {
3251     css => 'cursor',
3252     dom => 'cursor',
3253     key => 'cursor',
3254     parse => sub {
3255     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3256    
3257     ## NOTE: See <http://suika.fam.cx/gate/2005/sw/cursor> for browser
3258     ## compatibility issues.
3259    
3260     my @prop_value = ('CURSOR');
3261    
3262     F: {
3263     if ($t->{type} == IDENT_TOKEN) {
3264     my $v = lc $t->{value}; ## TODO: case
3265     $t = $tt->get_next_token;
3266     if ($Prop->{$prop_name}->{keyword}->{$v}) {
3267     push @prop_value, ['KEYWORD', $v];
3268     last F;
3269     } elsif ($v eq 'inherit' and @prop_value == 1) {
3270     return ($t, {$prop_name => ['INHERIT']});
3271     } else {
3272 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3273 wakaba 1.17 level => $self->{must_level},
3274 wakaba 1.38 uri => \$self->{href},
3275 wakaba 1.17 token => $t);
3276     return ($t, undef);
3277     }
3278     } elsif ($t->{type} == URI_TOKEN) {
3279     push @prop_value, ['URI', $t->{value}, \($self->{base_uri})];
3280     $t = $tt->get_next_token;
3281     } else {
3282 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3283 wakaba 1.17 level => $self->{must_level},
3284 wakaba 1.38 uri => \$self->{href},
3285 wakaba 1.17 token => $t);
3286     return ($t, undef);
3287     }
3288    
3289     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3290     if ($t->{type} == COMMA_TOKEN) {
3291     $t = $tt->get_next_token;
3292     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3293     redo F;
3294     }
3295     } # F
3296    
3297     return ($t, {$prop_name => \@prop_value});
3298     },
3299     serialize => sub {
3300     my ($self, $prop_name, $value) = @_;
3301    
3302     if ($value->[0] eq 'CURSOR') {
3303     return join ', ', map {
3304     if ($_->[0] eq 'URI') {
3305     'url('.$_->[1].')'; ## NOTE: This is what Firefox does.
3306     } elsif ($_->[0] eq 'KEYWORD') {
3307     $_->[1];
3308     } else {
3309     ## NOTE: This should be an error.
3310     '""';
3311     }
3312     } @$value[1..$#$value];
3313     } elsif ($value->[0] eq 'INHERIT') {
3314     return 'inherit';
3315     } else {
3316 wakaba 1.34 return '';
3317 wakaba 1.17 }
3318     },
3319     keyword => {
3320     auto => 1, crosshair => 1, default => 1, pointer => 1, move => 1,
3321     'e-resize' => 1, 'ne-resize' => 1, 'nw-resize' => 1, 'n-resize' => 1,
3322     'n-resize' => 1, 'se-resize' => 1, 'sw-resize' => 1, 's-resize' => 1,
3323     'w-resize' => 1, text => 1, wait => 1, help => 1, progress => 1,
3324     },
3325     initial => ['CURSOR', ['KEYWORD', 'auto']],
3326     inherited => 1,
3327     compute => sub {
3328     my ($self, $element, $prop_name, $specified_value) = @_;
3329    
3330     if (defined $specified_value and $specified_value->[0] eq 'CURSOR') {
3331     my @new_value = ('CURSOR');
3332     for my $value (@$specified_value[1..$#$specified_value]) {
3333     if ($value->[0] eq 'URI') {
3334     if (defined $value->[2]) {
3335     require Message::DOM::DOMImplementation;
3336     push @new_value, ['URI',
3337     Message::DOM::DOMImplementation
3338     ->create_uri_reference ($value->[1])
3339     ->get_absolute_reference (${$value->[2]})
3340     ->get_uri_reference,
3341     $value->[2]];
3342     } else {
3343     push @new_value, $value;
3344     }
3345     } else {
3346     push @new_value, $value;
3347     }
3348     }
3349     return \@new_value;
3350     }
3351    
3352     return $specified_value;
3353     },
3354     };
3355     $Attr->{cursor} = $Prop->{cursor};
3356     $Key->{cursor} = $Prop->{cursor};
3357    
3358 wakaba 1.7 $Prop->{'border-style'} = {
3359     css => 'border-style',
3360     dom => 'border_style',
3361     parse => sub {
3362     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3363    
3364     my %prop_value;
3365     if ($t->{type} == IDENT_TOKEN) {
3366     my $prop_value = lc $t->{value}; ## TODO: case folding
3367     $t = $tt->get_next_token;
3368     if ($border_style_keyword->{$prop_value} and
3369     $self->{prop_value}->{'border-top-style'}->{$prop_value}) {
3370     $prop_value{'border-top-style'} = ["KEYWORD", $prop_value];
3371     } elsif ($prop_value eq 'inherit') {
3372 wakaba 1.10 $prop_value{'border-top-style'} = ["INHERIT"];
3373 wakaba 1.19 $prop_value{'border-right-style'} = $prop_value{'border-top-style'};
3374     $prop_value{'border-bottom-style'} = $prop_value{'border-top-style'};
3375     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3376     return ($t, \%prop_value);
3377 wakaba 1.7 } else {
3378 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3379 wakaba 1.7 level => $self->{must_level},
3380 wakaba 1.38 uri => \$self->{href},
3381 wakaba 1.7 token => $t);
3382     return ($t, undef);
3383     }
3384     $prop_value{'border-right-style'} = $prop_value{'border-top-style'};
3385     $prop_value{'border-bottom-style'} = $prop_value{'border-top-style'};
3386     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3387     } else {
3388 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3389 wakaba 1.7 level => $self->{must_level},
3390 wakaba 1.38 uri => \$self->{href},
3391 wakaba 1.7 token => $t);
3392     return ($t, undef);
3393     }
3394    
3395     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3396     if ($t->{type} == IDENT_TOKEN) {
3397     my $prop_value = lc $t->{value}; ## TODO: case folding
3398     $t = $tt->get_next_token;
3399 wakaba 1.19 if ($border_style_keyword->{$prop_value} and
3400 wakaba 1.7 $self->{prop_value}->{'border-right-style'}->{$prop_value}) {
3401     $prop_value{'border-right-style'} = ["KEYWORD", $prop_value];
3402     } else {
3403 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3404 wakaba 1.7 level => $self->{must_level},
3405 wakaba 1.38 uri => \$self->{href},
3406 wakaba 1.7 token => $t);
3407     return ($t, undef);
3408     }
3409     $prop_value{'border-left-style'} = $prop_value{'border-right-style'};
3410    
3411     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3412     if ($t->{type} == IDENT_TOKEN) {
3413     my $prop_value = lc $t->{value}; ## TODO: case folding
3414     $t = $tt->get_next_token;
3415     if ($border_style_keyword->{$prop_value} and
3416     $self->{prop_value}->{'border-bottom-style'}->{$prop_value}) {
3417     $prop_value{'border-bottom-style'} = ["KEYWORD", $prop_value];
3418     } else {
3419 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3420 wakaba 1.7 level => $self->{must_level},
3421 wakaba 1.38 uri => \$self->{href},
3422 wakaba 1.7 token => $t);
3423     return ($t, undef);
3424     }
3425    
3426     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3427     if ($t->{type} == IDENT_TOKEN) {
3428     my $prop_value = lc $t->{value}; ## TODO: case folding
3429     $t = $tt->get_next_token;
3430     if ($border_style_keyword->{$prop_value} and
3431     $self->{prop_value}->{'border-left-style'}->{$prop_value}) {
3432     $prop_value{'border-left-style'} = ["KEYWORD", $prop_value];
3433     } else {
3434 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3435 wakaba 1.7 level => $self->{must_level},
3436 wakaba 1.38 uri => \$self->{href},
3437 wakaba 1.7 token => $t);
3438     return ($t, undef);
3439     }
3440     }
3441     }
3442     }
3443    
3444     return ($t, \%prop_value);
3445     },
3446     serialize => sub {
3447     my ($self, $prop_name, $value) = @_;
3448    
3449     local $Error::Depth = $Error::Depth + 1;
3450     my @v;
3451     push @v, $self->border_top_style;
3452 wakaba 1.34 return '' unless length $v[-1];
3453 wakaba 1.7 push @v, $self->border_right_style;
3454 wakaba 1.34 return '' unless length $v[-1];
3455 wakaba 1.7 push @v, $self->border_bottom_style;
3456 wakaba 1.34 return '' unless length $v[-1];
3457 wakaba 1.19 push @v, $self->border_left_style;
3458 wakaba 1.34 return '' unless length $v[-1];
3459 wakaba 1.7
3460     pop @v if $v[1] eq $v[3];
3461     pop @v if $v[0] eq $v[2];
3462     pop @v if $v[0] eq $v[1];
3463     return join ' ', @v;
3464     },
3465 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3466 wakaba 1.7 };
3467     $Attr->{border_style} = $Prop->{'border-style'};
3468    
3469 wakaba 1.29 $Prop->{'border-color'} = {
3470     css => 'border-color',
3471     dom => 'border_color',
3472     parse => sub {
3473     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3474    
3475     my %prop_value;
3476     ($t, my $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3477     if (not defined $pv) {
3478     return ($t, undef);
3479     }
3480     $prop_value{'border-top-color'} = $pv->{'border-color'};
3481     $prop_value{'border-bottom-color'} = $prop_value{'border-top-color'};
3482     $prop_value{'border-right-color'} = $prop_value{'border-top-color'};
3483     $prop_value{'border-left-color'}= $prop_value{'border-right-color'};
3484     if ($prop_value{'border-top-color'}->[0] eq 'INHERIT') {
3485     return ($t, \%prop_value);
3486     }
3487    
3488     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3489     if ({
3490     IDENT_TOKEN, 1,
3491     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3492     FUNCTION_TOKEN, 1,
3493     }->{$t->{type}}) {
3494     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3495     if (not defined $pv) {
3496     return ($t, undef);
3497     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3498 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3499 wakaba 1.29 level => $self->{must_level},
3500 wakaba 1.38 uri => \$self->{href},
3501 wakaba 1.29 token => $t);
3502     return ($t, undef);
3503     }
3504     $prop_value{'border-right-color'} = $pv->{'border-color'};
3505     $prop_value{'border-left-color'}= $prop_value{'border-right-color'};
3506    
3507     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3508     if ({
3509     IDENT_TOKEN, 1,
3510     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3511     FUNCTION_TOKEN, 1,
3512     }->{$t->{type}}) {
3513     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3514     if (not defined $pv) {
3515     return ($t, undef);
3516     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3517 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3518 wakaba 1.29 level => $self->{must_level},
3519 wakaba 1.38 uri => \$self->{href},
3520 wakaba 1.29 token => $t);
3521     return ($t, undef);
3522     }
3523     $prop_value{'border-bottom-color'} = $pv->{'border-color'};
3524    
3525     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3526     if ({
3527     IDENT_TOKEN, 1,
3528     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3529     FUNCTION_TOKEN, 1,
3530     }->{$t->{type}}) {
3531     ($t, $pv) = $parse_color->($self, 'border-color', $tt, $t, $onerror);
3532     if (not defined $pv) {
3533     return ($t, undef);
3534     } elsif ($pv->{'border-color'}->[0] eq 'INHERIT') {
3535 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3536 wakaba 1.29 level => $self->{must_level},
3537 wakaba 1.38 uri => \$self->{href},
3538 wakaba 1.29 token => $t);
3539     return ($t, undef);
3540     }
3541     $prop_value{'border-left-color'} = $pv->{'border-color'};
3542     }
3543     }
3544     }
3545    
3546     return ($t, \%prop_value);
3547     },
3548     serialize => sub {
3549     my ($self, $prop_name, $value) = @_;
3550    
3551     local $Error::Depth = $Error::Depth + 1;
3552     my @v;
3553     push @v, $self->border_top_color;
3554 wakaba 1.34 return '' unless length $v[-1];
3555 wakaba 1.29 push @v, $self->border_right_color;
3556 wakaba 1.34 return '' unless length $v[-1];
3557 wakaba 1.29 push @v, $self->border_bottom_color;
3558 wakaba 1.34 return '' unless length $v[-1];
3559 wakaba 1.29 push @v, $self->border_left_color;
3560 wakaba 1.34 return '' unless length $v[-1];
3561 wakaba 1.29
3562     pop @v if $v[1] eq $v[3];
3563     pop @v if $v[0] eq $v[2];
3564     pop @v if $v[0] eq $v[1];
3565     return join ' ', @v;
3566     },
3567     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3568     };
3569     $Attr->{border_color} = $Prop->{'border-color'};
3570    
3571     $Prop->{'border-top'} = {
3572     css => 'border-top',
3573     dom => 'border_top',
3574     parse => sub {
3575     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3576    
3577     my %prop_value;
3578     my $pv;
3579     ## NOTE: Since $onerror is disabled for three invocations below,
3580     ## some informative warning messages (if they are added someday) will not
3581     ## be reported.
3582     ($t, $pv) = $parse_color->($self, $prop_name.'-color', $tt, $t, sub {});
3583     if (defined $pv) {
3584     if ($pv->{$prop_name.'-color'}->[0] eq 'INHERIT') {
3585     return ($t, {$prop_name.'-color' => ['INHERIT'],
3586     $prop_name.'-style' => ['INHERIT'],
3587     $prop_name.'-width' => ['INHERIT']});
3588     } else {
3589     $prop_value{$prop_name.'-color'} = $pv->{$prop_name.'-color'};
3590     }
3591     } else {
3592     ($t, $pv) = $Prop->{'border-top-width'}->{parse}
3593     ->($self, $prop_name.'-width', $tt, $t, sub {});
3594     if (defined $pv) {
3595     $prop_value{$prop_name.'-width'} = $pv->{$prop_name.'-width'};
3596     } else {
3597     ($t, $pv) = $Prop->{'border-top-style'}->{parse}
3598     ->($self, $prop_name.'-style', $tt, $t, sub {});
3599     if (defined $pv) {
3600     $prop_value{$prop_name.'-style'} = $pv->{$prop_name.'-style'};
3601     } else {
3602 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3603 wakaba 1.29 level => $self->{must_level},
3604 wakaba 1.38 uri => \$self->{href},
3605 wakaba 1.29 token => $t);
3606     return ($t, undef);
3607     }
3608     }
3609     }
3610    
3611     for (1..2) {
3612     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3613     if ($t->{type} == IDENT_TOKEN) {
3614     my $prop_value = lc $t->{value}; ## TODO: case
3615     if ($border_style_keyword->{$prop_value} and
3616     $self->{prop_value}->{'border-top-style'}->{$prop_value} and
3617     not defined $prop_value{$prop_name.'-style'}) {
3618     $prop_value{$prop_name.'-style'} = ['KEYWORD', $prop_value];
3619     $t = $tt->get_next_token;
3620     next;
3621     } elsif ({thin => 1, medium => 1, thick => 1}->{$prop_value} and
3622     not defined $prop_value{$prop_name.'-width'}) {
3623     $prop_value{$prop_name.'-width'} = ['KEYWORD', $prop_value];
3624     $t = $tt->get_next_token;
3625     next;
3626     }
3627     }
3628    
3629     undef $pv;
3630     ($t, $pv) = $parse_color->($self, $prop_name.'-color', $tt, $t, $onerror)
3631     if not defined $prop_value{$prop_name.'-color'} and
3632     {
3633     IDENT_TOKEN, 1,
3634     HASH_TOKEN, 1, NUMBER_TOKEN, 1, DIMENSION_TOKEN, 1,
3635     FUNCTION_TOKEN, 1,
3636     }->{$t->{type}};
3637     if (defined $pv) {
3638     if ($pv->{$prop_name.'-color'}->[0] eq 'INHERIT') {
3639 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3640 wakaba 1.29 level => $self->{must_level},
3641 wakaba 1.38 uri => \$self->{href},
3642 wakaba 1.29 token => $t);
3643     } else {
3644     $prop_value{$prop_name.'-color'} = $pv->{$prop_name.'-color'};
3645     }
3646     } else {
3647     undef $pv;
3648     ($t, $pv) = $Prop->{'border-top-width'}->{parse}
3649     ->($self, $prop_name.'-width',
3650     $tt, $t, $onerror)
3651     if not defined $prop_value{$prop_name.'-width'} and
3652     {
3653     DIMENSION_TOKEN, 1,
3654     NUMBER_TOKEN, 1,
3655     IDENT_TOKEN, 1,
3656     MINUS_TOKEN, 1,
3657     }->{$t->{type}};
3658     if (defined $pv) {
3659     if ($pv->{$prop_name.'-width'}->[0] eq 'INHERIT') {
3660 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3661 wakaba 1.29 level => $self->{must_level},
3662 wakaba 1.38 uri => \$self->{href},
3663 wakaba 1.29 token => $t);
3664     } else {
3665     $prop_value{$prop_name.'-width'} = $pv->{$prop_name.'-width'};
3666     }
3667     } else {
3668     last;
3669     }
3670     }
3671     }
3672    
3673     $prop_value{$prop_name.'-color'}
3674     ||= $Prop->{$prop_name.'-color'}->{initial};
3675     $prop_value{$prop_name.'-width'}
3676     ||= $Prop->{$prop_name.'-width'}->{initial};
3677     $prop_value{$prop_name.'-style'}
3678     ||= $Prop->{$prop_name.'-style'}->{initial};
3679    
3680     return ($t, \%prop_value);
3681     },
3682     serialize => sub {
3683     my ($self, $prop_name, $value) = @_;
3684    
3685     local $Error::Depth = $Error::Depth + 1;
3686     my $width_prop = $prop_name . '_width'; $width_prop =~ tr/-/_/;
3687     my $width_value = $self->$width_prop;
3688 wakaba 1.34 return '' unless length $width_value;
3689 wakaba 1.29 my $style_prop = $prop_name . '_style'; $style_prop =~ tr/-/_/;
3690     my $style_value = $self->$style_prop;
3691 wakaba 1.34 return '' unless length $style_value;
3692 wakaba 1.29 my $color_prop = $prop_name . '_color'; $color_prop =~ tr/-/_/;
3693     my $color_value = $self->$color_prop;
3694 wakaba 1.34 return '' unless length $color_value;
3695 wakaba 1.29
3696     return $width_value . ' ' . $style_value . ' ' . $color_value;
3697     },
3698     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3699     };
3700     $Attr->{border_top} = $Prop->{'border-top'};
3701    
3702     $Prop->{'border-right'} = {
3703     css => 'border-right',
3704     dom => 'border_right',
3705     parse => $Prop->{'border-top'}->{parse},
3706     serialize => $Prop->{'border-top'}->{serialize},
3707     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3708     };
3709     $Attr->{border_right} = $Prop->{'border-right'};
3710    
3711     $Prop->{'border-bottom'} = {
3712     css => 'border-bottom',
3713     dom => 'border_bottom',
3714     parse => $Prop->{'border-top'}->{parse},
3715     serialize => $Prop->{'border-top'}->{serialize},
3716     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3717     };
3718     $Attr->{border_bottom} = $Prop->{'border-bottom'};
3719    
3720     $Prop->{'border-left'} = {
3721     css => 'border-left',
3722     dom => 'border_left',
3723     parse => $Prop->{'border-top'}->{parse},
3724     serialize => $Prop->{'border-top'}->{serialize},
3725     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3726     };
3727     $Attr->{border_left} = $Prop->{'border-left'};
3728    
3729     $Prop->{outline} = {
3730     css => 'outline',
3731     dom => 'outline',
3732     parse => $Prop->{'border-top'}->{parse},
3733     serialize => $Prop->{'border-top'}->{serialize},
3734     serialize_multiple => $Prop->{'outline-color'}->{serialize_multiple},
3735     };
3736     $Attr->{outline} = $Prop->{outline};
3737    
3738     $Prop->{border} = {
3739     css => 'border',
3740     dom => 'border',
3741     parse => sub {
3742     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3743     my $prop_value;
3744     ($t, $prop_value) = $Prop->{'border-top'}->{parse}
3745     ->($self, 'border-top', $tt, $t, $onerror);
3746     return ($t, undef) unless defined $prop_value;
3747    
3748     for (qw/border-right border-bottom border-left/) {
3749     $prop_value->{$_.'-color'} = $prop_value->{'border-top-color'}
3750     if defined $prop_value->{'border-top-color'};
3751     $prop_value->{$_.'-style'} = $prop_value->{'border-top-style'}
3752     if defined $prop_value->{'border-top-style'};
3753     $prop_value->{$_.'-width'} = $prop_value->{'border-top-width'}
3754     if defined $prop_value->{'border-top-width'};
3755     }
3756     return ($t, $prop_value);
3757     },
3758     serialize => sub {
3759     my ($self, $prop_name, $value) = @_;
3760    
3761     local $Error::Depth = $Error::Depth + 1;
3762     my $bt = $self->border_top;
3763 wakaba 1.34 return '' unless length $bt;
3764 wakaba 1.29 my $br = $self->border_right;
3765 wakaba 1.34 return '' unless length $br;
3766     return '' unless $bt eq $br;
3767 wakaba 1.29 my $bb = $self->border_bottom;
3768 wakaba 1.34 return '' unless length $bb;
3769     return '' unless $bt eq $bb;
3770 wakaba 1.29 my $bl = $self->border_left;
3771 wakaba 1.34 return '' unless length $bl;
3772     return '' unless $bt eq $bl;
3773 wakaba 1.29
3774     return $bt;
3775     },
3776     serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
3777     };
3778     $Attr->{border} = $Prop->{border};
3779    
3780 wakaba 1.19 $Prop->{margin} = {
3781     css => 'margin',
3782     dom => 'margin',
3783     parse => sub {
3784     my ($self, $prop_name, $tt, $t, $onerror) = @_;
3785    
3786     my %prop_value;
3787    
3788     my $sign = 1;
3789     if ($t->{type} == MINUS_TOKEN) {
3790     $t = $tt->get_next_token;
3791     $sign = -1;
3792     }
3793    
3794     if ($t->{type} == DIMENSION_TOKEN) {
3795     my $value = $t->{number} * $sign;
3796     my $unit = lc $t->{value}; ## TODO: case
3797     $t = $tt->get_next_token;
3798     if ($length_unit->{$unit}) {
3799     $prop_value{'margin-top'} = ['DIMENSION', $value, $unit];
3800     } else {
3801 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3802 wakaba 1.19 level => $self->{must_level},
3803 wakaba 1.38 uri => \$self->{href},
3804 wakaba 1.19 token => $t);
3805     return ($t, undef);
3806     }
3807     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
3808     my $value = $t->{number} * $sign;
3809     $t = $tt->get_next_token;
3810     $prop_value{'margin-top'} = ['PERCENTAGE', $value];
3811 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
3812 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
3813     my $value = $t->{number} * $sign;
3814     $t = $tt->get_next_token;
3815     $prop_value{'margin-top'} = ['DIMENSION', $value, 'px'];
3816     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
3817     my $prop_value = lc $t->{value}; ## TODO: case folding
3818     $t = $tt->get_next_token;
3819     if ($prop_value eq 'auto') {
3820     $prop_value{'margin-top'} = ['KEYWORD', $prop_value];
3821     } elsif ($prop_value eq 'inherit') {
3822     $prop_value{'margin-top'} = ['INHERIT'];
3823     $prop_value{'margin-right'} = $prop_value{'margin-top'};
3824     $prop_value{'margin-bottom'} = $prop_value{'margin-top'};
3825     $prop_value{'margin-left'} = $prop_value{'margin-right'};
3826     return ($t, \%prop_value);
3827     } else {
3828 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3829 wakaba 1.19 level => $self->{must_level},
3830 wakaba 1.38 uri => \$self->{href},
3831 wakaba 1.19 token => $t);
3832     return ($t, undef);
3833     }
3834     } else {
3835 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3836 wakaba 1.19 level => $self->{must_level},
3837 wakaba 1.38 uri => \$self->{href},
3838 wakaba 1.19 token => $t);
3839     return ($t, undef);
3840     }
3841     $prop_value{'margin-right'} = $prop_value{'margin-top'};
3842     $prop_value{'margin-bottom'} = $prop_value{'margin-top'};
3843     $prop_value{'margin-left'} = $prop_value{'margin-right'};
3844    
3845     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3846     $sign = 1;
3847     if ($t->{type} == MINUS_TOKEN) {
3848     $t = $tt->get_next_token;
3849     $sign = -1;
3850     }
3851    
3852     if ($t->{type} == DIMENSION_TOKEN) {
3853     my $value = $t->{number} * $sign;
3854     my $unit = lc $t->{value}; ## TODO: case
3855     $t = $tt->get_next_token;
3856     if ($length_unit->{$unit}) {
3857     $prop_value{'margin-right'} = ['DIMENSION', $value, $unit];
3858     } else {
3859 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3860 wakaba 1.19 level => $self->{must_level},
3861 wakaba 1.38 uri => \$self->{href},
3862 wakaba 1.19 token => $t);
3863     return ($t, undef);
3864     }
3865     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
3866     my $value = $t->{number} * $sign;
3867     $t = $tt->get_next_token;
3868     $prop_value{'margin-right'} = ['PERCENTAGE', $value];
3869 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
3870 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
3871     my $value = $t->{number} * $sign;
3872     $t = $tt->get_next_token;
3873     $prop_value{'margin-right'} = ['DIMENSION', $value, 'px'];
3874     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
3875     my $prop_value = lc $t->{value}; ## TODO: case folding
3876     $t = $tt->get_next_token;
3877     if ($prop_value eq 'auto') {
3878     $prop_value{'margin-right'} = ['KEYWORD', $prop_value];
3879     } else {
3880 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3881 wakaba 1.19 level => $self->{must_level},
3882 wakaba 1.38 uri => \$self->{href},
3883 wakaba 1.19 token => $t);
3884     return ($t, undef);
3885     }
3886     } else {
3887 wakaba 1.24 if ($sign < 0) {
3888 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3889 wakaba 1.24 level => $self->{must_level},
3890 wakaba 1.38 uri => \$self->{href},
3891 wakaba 1.24 token => $t);
3892     return ($t, undef);
3893     }
3894 wakaba 1.19 return ($t, \%prop_value);
3895     }
3896     $prop_value{'margin-left'} = $prop_value{'margin-right'};
3897    
3898     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3899     $sign = 1;
3900     if ($t->{type} == MINUS_TOKEN) {
3901     $t = $tt->get_next_token;
3902     $sign = -1;
3903     }
3904    
3905     if ($t->{type} == DIMENSION_TOKEN) {
3906     my $value = $t->{number} * $sign;
3907     my $unit = lc $t->{value}; ## TODO: case
3908     $t = $tt->get_next_token;
3909     if ($length_unit->{$unit}) {
3910     $prop_value{'margin-bottom'} = ['DIMENSION', $value, $unit];
3911     } else {
3912 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3913 wakaba 1.19 level => $self->{must_level},
3914 wakaba 1.38 uri => \$self->{href},
3915 wakaba 1.19 token => $t);
3916     return ($t, undef);
3917     }
3918     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
3919     my $value = $t->{number} * $sign;
3920     $t = $tt->get_next_token;
3921     $prop_value{'margin-bottom'} = ['PERCENTAGE', $value];
3922 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
3923 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
3924     my $value = $t->{number} * $sign;
3925     $t = $tt->get_next_token;
3926     $prop_value{'margin-bottom'} = ['DIMENSION', $value, 'px'];
3927     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
3928     my $prop_value = lc $t->{value}; ## TODO: case folding
3929     $t = $tt->get_next_token;
3930     if ($prop_value eq 'auto') {
3931     $prop_value{'margin-bottom'} = ['KEYWORD', $prop_value];
3932     } else {
3933 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3934 wakaba 1.19 level => $self->{must_level},
3935 wakaba 1.38 uri => \$self->{href},
3936 wakaba 1.19 token => $t);
3937     return ($t, undef);
3938     }
3939     } else {
3940 wakaba 1.24 if ($sign < 0) {
3941 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3942 wakaba 1.24 level => $self->{must_level},
3943 wakaba 1.38 uri => \$self->{href},
3944 wakaba 1.24 token => $t);
3945     return ($t, undef);
3946     }
3947 wakaba 1.19 return ($t, \%prop_value);
3948     }
3949    
3950     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
3951     $sign = 1;
3952     if ($t->{type} == MINUS_TOKEN) {
3953     $t = $tt->get_next_token;
3954     $sign = -1;
3955     }
3956    
3957     if ($t->{type} == DIMENSION_TOKEN) {
3958     my $value = $t->{number} * $sign;
3959     my $unit = lc $t->{value}; ## TODO: case
3960     $t = $tt->get_next_token;
3961     if ($length_unit->{$unit}) {
3962     $prop_value{'margin-left'} = ['DIMENSION', $value, $unit];
3963     } else {
3964 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3965 wakaba 1.19 level => $self->{must_level},
3966 wakaba 1.38 uri => \$self->{href},
3967 wakaba 1.19 token => $t);
3968     return ($t, undef);
3969     }
3970     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
3971     my $value = $t->{number} * $sign;
3972     $t = $tt->get_next_token;
3973     $prop_value{'margin-left'} = ['PERCENTAGE', $value];
3974 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
3975 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
3976     my $value = $t->{number} * $sign;
3977     $t = $tt->get_next_token;
3978     $prop_value{'margin-left'} = ['DIMENSION', $value, 'px'];
3979     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
3980     my $prop_value = lc $t->{value}; ## TODO: case folding
3981     $t = $tt->get_next_token;
3982     if ($prop_value eq 'auto') {
3983     $prop_value{'margin-left'} = ['KEYWORD', $prop_value];
3984     } else {
3985 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3986 wakaba 1.19 level => $self->{must_level},
3987 wakaba 1.38 uri => \$self->{href},
3988 wakaba 1.19 token => $t);
3989     return ($t, undef);
3990     }
3991     } else {
3992 wakaba 1.24 if ($sign < 0) {
3993 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
3994 wakaba 1.24 level => $self->{must_level},
3995 wakaba 1.38 uri => \$self->{href},
3996 wakaba 1.24 token => $t);
3997     return ($t, undef);
3998     }
3999 wakaba 1.19 return ($t, \%prop_value);
4000     }
4001    
4002     return ($t, \%prop_value);
4003     },
4004     serialize => sub {
4005     my ($self, $prop_name, $value) = @_;
4006    
4007     local $Error::Depth = $Error::Depth + 1;
4008     my @v;
4009     push @v, $self->margin_top;
4010 wakaba 1.34 return '' unless length $v[-1];
4011 wakaba 1.19 push @v, $self->margin_right;
4012 wakaba 1.34 return '' unless length $v[-1];
4013 wakaba 1.19 push @v, $self->margin_bottom;
4014 wakaba 1.34 return '' unless length $v[-1];
4015 wakaba 1.19 push @v, $self->margin_left;
4016 wakaba 1.34 return '' unless length $v[-1];
4017 wakaba 1.19
4018     pop @v if $v[1] eq $v[3];
4019     pop @v if $v[0] eq $v[2];
4020     pop @v if $v[0] eq $v[1];
4021     return join ' ', @v;
4022     },
4023     };
4024     $Attr->{margin} = $Prop->{margin};
4025    
4026     $Prop->{padding} = {
4027     css => 'padding',
4028     dom => 'padding',
4029     parse => sub {
4030     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4031    
4032     my %prop_value;
4033    
4034     my $sign = 1;
4035     if ($t->{type} == MINUS_TOKEN) {
4036     $t = $tt->get_next_token;
4037     $sign = -1;
4038     }
4039    
4040     if ($t->{type} == DIMENSION_TOKEN) {
4041     my $value = $t->{number} * $sign;
4042     my $unit = lc $t->{value}; ## TODO: case
4043     $t = $tt->get_next_token;
4044     if ($length_unit->{$unit} and $value >= 0) {
4045     $prop_value{'padding-top'} = ['DIMENSION', $value, $unit];
4046     } else {
4047 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4048 wakaba 1.19 level => $self->{must_level},
4049 wakaba 1.38 uri => \$self->{href},
4050 wakaba 1.19 token => $t);
4051     return ($t, undef);
4052     }
4053     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4054     my $value = $t->{number} * $sign;
4055     $t = $tt->get_next_token;
4056     $prop_value{'padding-top'} = ['PERCENTAGE', $value];
4057     unless ($value >= 0) {
4058 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4059 wakaba 1.19 level => $self->{must_level},
4060 wakaba 1.38 uri => \$self->{href},
4061 wakaba 1.19 token => $t);
4062     return ($t, undef);
4063     }
4064 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4065 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4066     my $value = $t->{number} * $sign;
4067     $t = $tt->get_next_token;
4068     $prop_value{'padding-top'} = ['DIMENSION', $value, 'px'];
4069     unless ($value >= 0) {
4070 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4071 wakaba 1.19 level => $self->{must_level},
4072 wakaba 1.38 uri => \$self->{href},
4073 wakaba 1.19 token => $t);
4074     return ($t, undef);
4075     }
4076     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4077     my $prop_value = lc $t->{value}; ## TODO: case folding
4078     $t = $tt->get_next_token;
4079     if ($prop_value eq 'inherit') {
4080     $prop_value{'padding-top'} = ['INHERIT'];
4081     $prop_value{'padding-right'} = $prop_value{'padding-top'};
4082     $prop_value{'padding-bottom'} = $prop_value{'padding-top'};
4083     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4084     return ($t, \%prop_value);
4085     } else {
4086 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4087 wakaba 1.19 level => $self->{must_level},
4088 wakaba 1.38 uri => \$self->{href},
4089 wakaba 1.19 token => $t);
4090     return ($t, undef);
4091     }
4092     } else {
4093 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4094 wakaba 1.19 level => $self->{must_level},
4095 wakaba 1.38 uri => \$self->{href},
4096 wakaba 1.19 token => $t);
4097     return ($t, undef);
4098     }
4099     $prop_value{'padding-right'} = $prop_value{'padding-top'};
4100     $prop_value{'padding-bottom'} = $prop_value{'padding-top'};
4101     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4102    
4103     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4104     $sign = 1;
4105     if ($t->{type} == MINUS_TOKEN) {
4106     $t = $tt->get_next_token;
4107     $sign = -1;
4108     }
4109    
4110     if ($t->{type} == DIMENSION_TOKEN) {
4111     my $value = $t->{number} * $sign;
4112     my $unit = lc $t->{value}; ## TODO: case
4113     $t = $tt->get_next_token;
4114     if ($length_unit->{$unit} and $value >= 0) {
4115     $prop_value{'padding-right'} = ['DIMENSION', $value, $unit];
4116     } else {
4117 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4118 wakaba 1.19 level => $self->{must_level},
4119 wakaba 1.38 uri => \$self->{href},
4120 wakaba 1.19 token => $t);
4121     return ($t, undef);
4122     }
4123     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4124     my $value = $t->{number} * $sign;
4125     $t = $tt->get_next_token;
4126     $prop_value{'padding-right'} = ['PERCENTAGE', $value];
4127     unless ($value >= 0) {
4128 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4129 wakaba 1.19 level => $self->{must_level},
4130 wakaba 1.38 uri => \$self->{href},
4131 wakaba 1.19 token => $t);
4132     return ($t, undef);
4133     }
4134 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4135 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4136     my $value = $t->{number} * $sign;
4137     $t = $tt->get_next_token;
4138     $prop_value{'padding-right'} = ['DIMENSION', $value, 'px'];
4139     unless ($value >= 0) {
4140 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4141 wakaba 1.19 level => $self->{must_level},
4142 wakaba 1.38 uri => \$self->{href},
4143 wakaba 1.19 token => $t);
4144     return ($t, undef);
4145     }
4146     } else {
4147 wakaba 1.24 if ($sign < 0) {
4148 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4149 wakaba 1.24 level => $self->{must_level},
4150 wakaba 1.38 uri => \$self->{href},
4151 wakaba 1.24 token => $t);
4152     return ($t, undef);
4153     }
4154 wakaba 1.19 return ($t, \%prop_value);
4155     }
4156     $prop_value{'padding-left'} = $prop_value{'padding-right'};
4157    
4158     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4159     $sign = 1;
4160     if ($t->{type} == MINUS_TOKEN) {
4161     $t = $tt->get_next_token;
4162     $sign = -1;
4163     }
4164    
4165     if ($t->{type} == DIMENSION_TOKEN) {
4166     my $value = $t->{number} * $sign;
4167     my $unit = lc $t->{value}; ## TODO: case
4168     $t = $tt->get_next_token;
4169     if ($length_unit->{$unit} and $value >= 0) {
4170     $prop_value{'padding-bottom'} = ['DIMENSION', $value, $unit];
4171     } else {
4172 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4173 wakaba 1.19 level => $self->{must_level},
4174 wakaba 1.38 uri => \$self->{href},
4175 wakaba 1.19 token => $t);
4176     return ($t, undef);
4177     }
4178     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4179     my $value = $t->{number} * $sign;
4180     $t = $tt->get_next_token;
4181     $prop_value{'padding-bottom'} = ['PERCENTAGE', $value];
4182     unless ($value >= 0) {
4183 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4184 wakaba 1.19 level => $self->{must_level},
4185 wakaba 1.38 uri => \$self->{href},
4186 wakaba 1.19 token => $t);
4187     return ($t, undef);
4188     }
4189 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4190 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4191     my $value = $t->{number} * $sign;
4192     $t = $tt->get_next_token;
4193     $prop_value{'padding-bottom'} = ['DIMENSION', $value, 'px'];
4194     unless ($value >= 0) {
4195 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4196 wakaba 1.19 level => $self->{must_level},
4197 wakaba 1.38 uri => \$self->{href},
4198 wakaba 1.19 token => $t);
4199     return ($t, undef);
4200     }
4201     } else {
4202 wakaba 1.24 if ($sign < 0) {
4203 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4204 wakaba 1.24 level => $self->{must_level},
4205 wakaba 1.38 uri => \$self->{href},
4206 wakaba 1.24 token => $t);
4207     return ($t, undef);
4208     }
4209 wakaba 1.19 return ($t, \%prop_value);
4210     }
4211    
4212     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4213     $sign = 1;
4214     if ($t->{type} == MINUS_TOKEN) {
4215     $t = $tt->get_next_token;
4216     $sign = -1;
4217     }
4218    
4219     if ($t->{type} == DIMENSION_TOKEN) {
4220     my $value = $t->{number} * $sign;
4221     my $unit = lc $t->{value}; ## TODO: case
4222     $t = $tt->get_next_token;
4223     if ($length_unit->{$unit} and $value >= 0) {
4224     $prop_value{'padding-left'} = ['DIMENSION', $value, $unit];
4225     } else {
4226 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4227 wakaba 1.19 level => $self->{must_level},
4228 wakaba 1.38 uri => \$self->{href},
4229 wakaba 1.19 token => $t);
4230     return ($t, undef);
4231     }
4232     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4233     my $value = $t->{number} * $sign;
4234     $t = $tt->get_next_token;
4235     $prop_value{'padding-left'} = ['PERCENTAGE', $value];
4236     unless ($value >= 0) {
4237 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4238 wakaba 1.19 level => $self->{must_level},
4239 wakaba 1.38 uri => \$self->{href},
4240 wakaba 1.19 token => $t);
4241     return ($t, undef);
4242     }
4243 wakaba 1.20 } elsif ($t->{type} == NUMBER_TOKEN and
4244 wakaba 1.19 ($self->{unitless_px} or $t->{number} == 0)) {
4245     my $value = $t->{number} * $sign;
4246     $t = $tt->get_next_token;
4247     $prop_value{'padding-left'} = ['DIMENSION', $value, 'px'];
4248     unless ($value >= 0) {
4249 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4250 wakaba 1.19 level => $self->{must_level},
4251 wakaba 1.38 uri => \$self->{href},
4252 wakaba 1.19 token => $t);
4253     return ($t, undef);
4254     }
4255     } else {
4256 wakaba 1.24 if ($sign < 0) {
4257 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4258 wakaba 1.24 level => $self->{must_level},
4259 wakaba 1.38 uri => \$self->{href},
4260 wakaba 1.24 token => $t);
4261     return ($t, undef);
4262     }
4263 wakaba 1.19 return ($t, \%prop_value);
4264     }
4265    
4266     return ($t, \%prop_value);
4267     },
4268     serialize => sub {
4269     my ($self, $prop_name, $value) = @_;
4270    
4271     local $Error::Depth = $Error::Depth + 1;
4272     my @v;
4273     push @v, $self->padding_top;
4274 wakaba 1.34 return '' unless length $v[-1];
4275 wakaba 1.19 push @v, $self->padding_right;
4276 wakaba 1.34 return '' unless length $v[-1];
4277 wakaba 1.19 push @v, $self->padding_bottom;
4278 wakaba 1.34 return '' unless length $v[-1];
4279 wakaba 1.19 push @v, $self->padding_left;
4280 wakaba 1.34 return '' unless length $v[-1];
4281 wakaba 1.19
4282     pop @v if $v[1] eq $v[3];
4283     pop @v if $v[0] eq $v[2];
4284     pop @v if $v[0] eq $v[1];
4285     return join ' ', @v;
4286     },
4287     };
4288     $Attr->{padding} = $Prop->{padding};
4289    
4290 wakaba 1.24 $Prop->{'border-spacing'} = {
4291     css => 'border-spacing',
4292     dom => 'border_spacing',
4293     parse => sub {
4294     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4295    
4296     my %prop_value;
4297    
4298     my $sign = 1;
4299     if ($t->{type} == MINUS_TOKEN) {
4300     $t = $tt->get_next_token;
4301     $sign = -1;
4302     }
4303    
4304     if ($t->{type} == DIMENSION_TOKEN) {
4305     my $value = $t->{number} * $sign;
4306     my $unit = lc $t->{value}; ## TODO: case
4307     $t = $tt->get_next_token;
4308     if ($length_unit->{$unit} and $value >= 0) {
4309     $prop_value{'-manakai-border-spacing-x'} = ['DIMENSION', $value, $unit];
4310     } else {
4311 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4312 wakaba 1.24 level => $self->{must_level},
4313 wakaba 1.38 uri => \$self->{href},
4314 wakaba 1.24 token => $t);
4315     return ($t, undef);
4316     }
4317     } elsif ($t->{type} == NUMBER_TOKEN and
4318     ($self->{unitless_px} or $t->{number} == 0)) {
4319     my $value = $t->{number} * $sign;
4320     $t = $tt->get_next_token;
4321     $prop_value{'-manakai-border-spacing-x'} = ['DIMENSION', $value, 'px'];
4322     unless ($value >= 0) {
4323 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4324 wakaba 1.24 level => $self->{must_level},
4325 wakaba 1.38 uri => \$self->{href},
4326 wakaba 1.24 token => $t);
4327     return ($t, undef);
4328     }
4329     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4330     my $prop_value = lc $t->{value}; ## TODO: case folding
4331     $t = $tt->get_next_token;
4332     if ($prop_value eq 'inherit') {
4333     $prop_value{'-manakai-border-spacing-x'} = ['INHERIT'];
4334     $prop_value{'-manakai-border-spacing-y'}
4335     = $prop_value{'-manakai-border-spacing-x'};
4336     return ($t, \%prop_value);
4337     } else {
4338 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4339 wakaba 1.24 level => $self->{must_level},
4340 wakaba 1.38 uri => \$self->{href},
4341 wakaba 1.24 token => $t);
4342     return ($t, undef);
4343     }
4344     } else {
4345 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4346 wakaba 1.24 level => $self->{must_level},
4347 wakaba 1.38 uri => \$self->{href},
4348 wakaba 1.24 token => $t);
4349     return ($t, undef);
4350     }
4351     $prop_value{'-manakai-border-spacing-y'}
4352     = $prop_value{'-manakai-border-spacing-x'};
4353    
4354     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4355     $sign = 1;
4356     if ($t->{type} == MINUS_TOKEN) {
4357     $t = $tt->get_next_token;
4358     $sign = -1;
4359     }
4360    
4361     if ($t->{type} == DIMENSION_TOKEN) {
4362     my $value = $t->{number} * $sign;
4363     my $unit = lc $t->{value}; ## TODO: case
4364     $t = $tt->get_next_token;
4365     if ($length_unit->{$unit} and $value >= 0) {
4366     $prop_value{'-manakai-border-spacing-y'} = ['DIMENSION', $value, $unit];
4367     } else {
4368 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4369 wakaba 1.24 level => $self->{must_level},
4370 wakaba 1.38 uri => \$self->{href},
4371 wakaba 1.24 token => $t);
4372     return ($t, undef);
4373     }
4374     } elsif ($t->{type} == NUMBER_TOKEN and
4375     ($self->{unitless_px} or $t->{number} == 0)) {
4376     my $value = $t->{number} * $sign;
4377     $t = $tt->get_next_token;
4378     $prop_value{'-manakai-border-spacing-y'} = ['DIMENSION', $value, 'px'];
4379     unless ($value >= 0) {
4380 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4381 wakaba 1.24 level => $self->{must_level},
4382 wakaba 1.38 uri => \$self->{href},
4383 wakaba 1.24 token => $t);
4384     return ($t, undef);
4385     }
4386     } else {
4387     if ($sign < 0) {
4388 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4389 wakaba 1.24 level => $self->{must_level},
4390 wakaba 1.38 uri => \$self->{href},
4391 wakaba 1.24 token => $t);
4392     return ($t, undef);
4393     }
4394     return ($t, \%prop_value);
4395     }
4396    
4397     return ($t, \%prop_value);
4398     },
4399     serialize => sub {
4400     my ($self, $prop_name, $value) = @_;
4401    
4402     local $Error::Depth = $Error::Depth + 1;
4403     my @v;
4404     push @v, $self->_manakai_border_spacing_x;
4405 wakaba 1.34 return '' unless length $v[-1];
4406 wakaba 1.24 push @v, $self->_manakai_border_spacing_y;
4407 wakaba 1.34 return '' unless length $v[-1];
4408 wakaba 1.24
4409     pop @v if $v[0] eq $v[1];
4410     return join ' ', @v;
4411     },
4412 wakaba 1.25 serialize_multiple => $Prop->{'-manakai-border-spacing-x'}
4413     ->{serialize_multiple},
4414 wakaba 1.24 };
4415     $Attr->{border_spacing} = $Prop->{'border-spacing'};
4416    
4417 wakaba 1.27 ## NOTE: See <http://suika.fam.cx/gate/2005/sw/background-position> for
4418     ## browser compatibility problems.
4419     $Prop->{'background-position'} = {
4420     css => 'background-position',
4421     dom => 'background_position',
4422     parse => sub {
4423     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4424    
4425     my %prop_value;
4426    
4427     my $sign = 1;
4428     if ($t->{type} == MINUS_TOKEN) {
4429     $t = $tt->get_next_token;
4430     $sign = -1;
4431     }
4432    
4433     if ($t->{type} == DIMENSION_TOKEN) {
4434     my $value = $t->{number} * $sign;
4435     my $unit = lc $t->{value}; ## TODO: case
4436     $t = $tt->get_next_token;
4437     if ($length_unit->{$unit}) {
4438     $prop_value{'background-position-x'} = ['DIMENSION', $value, $unit];
4439     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4440     } else {
4441 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4442 wakaba 1.27 level => $self->{must_level},
4443 wakaba 1.38 uri => \$self->{href},
4444 wakaba 1.27 token => $t);
4445     return ($t, undef);
4446     }
4447     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4448     my $value = $t->{number} * $sign;
4449     $t = $tt->get_next_token;
4450     $prop_value{'background-position-x'} = ['PERCENTAGE', $value];
4451     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4452     } elsif ($t->{type} == NUMBER_TOKEN and
4453     ($self->{unitless_px} or $t->{number} == 0)) {
4454     my $value = $t->{number} * $sign;
4455     $t = $tt->get_next_token;
4456     $prop_value{'background-position-x'} = ['DIMENSION', $value, 'px'];
4457     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4458     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4459     my $prop_value = lc $t->{value}; ## TODO: case folding
4460     $t = $tt->get_next_token;
4461     if ({left => 1, center => 1, right => 1}->{$prop_value}) {
4462     $prop_value{'background-position-x'} = ['KEYWORD', $prop_value];
4463     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4464     } elsif ($prop_value eq 'top' or $prop_value eq 'bottom') {
4465     $prop_value{'background-position-y'} = ['KEYWORD', $prop_value];
4466    
4467     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4468     if ($t->{type} == IDENT_TOKEN) {
4469     my $prop_value = lc $t->{value}; ## TODO: case folding
4470     if ({left => 1, center => 1, right => 1}->{$prop_value}) {
4471     $prop_value{'background-position-x'} = ['KEYWORD', $prop_value];
4472     $t = $tt->get_next_token;
4473     return ($t, \%prop_value);
4474     }
4475     }
4476     $prop_value{'background-position-x'} = ['KEYWORD', 'center'];
4477     return ($t, \%prop_value);
4478     } elsif ($prop_value eq 'inherit') {
4479     $prop_value{'background-position-x'} = ['INHERIT'];
4480     $prop_value{'background-position-y'} = ['INHERIT'];
4481     return ($t, \%prop_value);
4482     } else {
4483 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4484 wakaba 1.27 level => $self->{must_level},
4485 wakaba 1.38 uri => \$self->{href},
4486 wakaba 1.27 token => $t);
4487     return ($t, undef);
4488     }
4489     } else {
4490 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4491 wakaba 1.27 level => $self->{must_level},
4492 wakaba 1.38 uri => \$self->{href},
4493 wakaba 1.27 token => $t);
4494     return ($t, undef);
4495     }
4496    
4497     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4498     $sign = 1;
4499     if ($t->{type} == MINUS_TOKEN) {
4500     $t = $tt->get_next_token;
4501     $sign = -1;
4502     }
4503    
4504     if ($t->{type} == DIMENSION_TOKEN) {
4505     my $value = $t->{number} * $sign;
4506     my $unit = lc $t->{value}; ## TODO: case
4507     $t = $tt->get_next_token;
4508     if ($length_unit->{$unit}) {
4509     $prop_value{'background-position-y'} = ['DIMENSION', $value, $unit];
4510     } else {
4511 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4512 wakaba 1.27 level => $self->{must_level},
4513 wakaba 1.38 uri => \$self->{href},
4514 wakaba 1.27 token => $t);
4515     return ($t, undef);
4516     }
4517     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4518     my $value = $t->{number} * $sign;
4519     $t = $tt->get_next_token;
4520     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
4521 wakaba 1.30 } elsif ($t->{type} == NUMBER_TOKEN and
4522     ($self->{unitless_px} or $t->{number} == 0)) {
4523 wakaba 1.27 my $value = $t->{number} * $sign;
4524     $t = $tt->get_next_token;
4525     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
4526     } elsif ($t->{type} == IDENT_TOKEN) {
4527     my $value = lc $t->{value}; ## TODO: case
4528     if ({top => 1, center => 1, bottom => 1}->{$value}) {
4529     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4530     $t = $tt->get_next_token;
4531     }
4532     } else {
4533     if ($sign < 0) {
4534 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4535 wakaba 1.27 level => $self->{must_level},
4536 wakaba 1.38 uri => \$self->{href},
4537 wakaba 1.27 token => $t);
4538     return ($t, undef);
4539     }
4540     return ($t, \%prop_value);
4541     }
4542    
4543     return ($t, \%prop_value);
4544     },
4545     serialize => sub {
4546     my ($self, $prop_name, $value) = @_;
4547    
4548     local $Error::Depth = $Error::Depth + 1;
4549     my $x = $self->background_position_x;
4550     my $y = $self->background_position_y;
4551 wakaba 1.34 return $x . ' ' . $y if length $x and length $y;
4552     return '';
4553 wakaba 1.27 },
4554 wakaba 1.30 serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
4555 wakaba 1.27 };
4556     $Attr->{background_position} = $Prop->{'background-position'};
4557    
4558 wakaba 1.30 $Prop->{background} = {
4559     css => 'background',
4560     dom => 'background',
4561     parse => sub {
4562     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4563     my %prop_value;
4564     B: for (1..5) {
4565     my $sign = 1;
4566     if ($t->{type} == MINUS_TOKEN) {
4567     $sign = -1;
4568     $t = $tt->get_next_token;
4569     }
4570    
4571     if ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4572     my $value = lc $t->{value}; ## TODO: case
4573     if ($Prop->{'background-repeat'}->{keyword}->{$value} and
4574     $self->{prop_value}->{'background-repeat'}->{$value} and
4575     not defined $prop_value{'background-repeat'}) {
4576     $prop_value{'background-repeat'} = ['KEYWORD', $value];
4577     $t = $tt->get_next_token;
4578     } elsif ($Prop->{'background-attachment'}->{keyword}->{$value} and
4579     $self->{prop_value}->{'background-attachment'}->{$value} and
4580     not defined $prop_value{'background-attachment'}) {
4581     $prop_value{'background-attachment'} = ['KEYWORD', $value];
4582     $t = $tt->get_next_token;
4583     } elsif ($value eq 'none' and
4584     not defined $prop_value{'background-image'}) {
4585     $prop_value{'background-image'} = ['KEYWORD', $value];
4586     $t = $tt->get_next_token;
4587     } elsif ({left => 1, center => 1, right => 1}->{$value} and
4588     not defined $prop_value{'background-position-x'}) {
4589     $prop_value{'background-position-x'} = ['KEYWORD', $value];
4590     $t = $tt->get_next_token;
4591     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4592     my $sign = 1;
4593     if ($t->{type} == MINUS_TOKEN) {
4594     $sign = -1;
4595     $t = $tt->get_next_token;
4596     }
4597     if ($sign > 0 and $t->{type} == IDENT_TOKEN) {
4598     my $value = lc $t->{value}; ## TODO: case
4599     if ({top => 1, bottom => 1, center => 1}->{$value}) {
4600     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4601     $t = $tt->get_next_token;
4602     } elsif ($prop_value{'background-position-x'}->[1] eq 'center' and
4603     $value eq 'left' or $value eq 'right') {
4604     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4605     $prop_value{'background-position-x'} = ['KEYWORD', $value];
4606     $t = $tt->get_next_token;
4607     } else {
4608     $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4609     }
4610     } elsif ($t->{type} == DIMENSION_TOKEN) {
4611     my $value = $t->{number} * $sign;
4612     my $unit = lc $t->{value}; ## TODO: case
4613     $t = $tt->get_next_token;
4614     if ($length_unit->{$unit}) {
4615     $prop_value{'background-position-y'}
4616     = ['DIMENSION', $value, $unit];
4617     } else {
4618 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4619 wakaba 1.30 level => $self->{must_level},
4620 wakaba 1.38 uri => \$self->{href},
4621 wakaba 1.30 token => $t);
4622     last B;
4623     }
4624     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4625     my $value = $t->{number} * $sign;
4626     $t = $tt->get_next_token;
4627     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
4628     } elsif ($t->{type} == NUMBER_TOKEN and
4629     ($self->{unitless_px} or $t->{number} == 0)) {
4630     my $value = $t->{number} * $sign;
4631     $t = $tt->get_next_token;
4632     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
4633     } elsif ($sign < 0) {
4634 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4635 wakaba 1.30 level => $self->{must_level},
4636 wakaba 1.38 uri => \$self->{href},
4637 wakaba 1.30 token => $t);
4638     last B;
4639     }
4640     } elsif (($value eq 'top' or $value eq 'bottom') and
4641     not defined $prop_value{'background-position-y'}) {
4642     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4643     $t = $tt->get_next_token;
4644     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4645     if ($t->{type} == IDENT_TOKEN and ## TODO: case
4646     {left => 1, center => 1, right => 1}->{lc $t->{value}}) {
4647     $prop_value{'background-position-x'} = ['KEYWORD', $value];
4648     $t = $tt->get_next_token;
4649     } else {
4650     $prop_value{'background-position-x'} = ['KEYWORD', 'center'];
4651     }
4652     } elsif ($value eq 'inherit' and not keys %prop_value) {
4653     $prop_value{'background-color'} =
4654     $prop_value{'background-image'} =
4655     $prop_value{'background-repeat'} =
4656     $prop_value{'background-attachment'} =
4657     $prop_value{'background-position-x'} =
4658     $prop_value{'background-position-y'} = ['INHERIT'];
4659     $t = $tt->get_next_token;
4660     return ($t, \%prop_value);
4661     } elsif (not defined $prop_value{'background-color'} or
4662     not keys %prop_value) {
4663     ($t, my $pv) = $parse_color->($self, 'background', $tt, $t,
4664     $onerror);
4665     if (defined $pv) {
4666     $prop_value{'background-color'} = $pv->{background};
4667     } else {
4668     ## NOTE: An error should already be raiased.
4669     return ($t, undef);
4670     }
4671     }
4672     } elsif (($t->{type} == DIMENSION_TOKEN or
4673     $t->{type} == PERCENTAGE_TOKEN or
4674     ($t->{type} == NUMBER_TOKEN and
4675     $t->{unitless_px} or $t->{number} == 0)) and
4676     not defined $prop_value{'background-position-x'}) {
4677     if ($t->{type} == DIMENSION_TOKEN) {
4678     my $value = $t->{number} * $sign;
4679     my $unit = lc $t->{value}; ## TODO: case
4680     $t = $tt->get_next_token;
4681     if ($length_unit->{$unit}) {
4682     $prop_value{'background-position-x'}
4683     = ['DIMENSION', $value, $unit];
4684     } else {
4685 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4686 wakaba 1.30 level => $self->{must_level},
4687 wakaba 1.38 uri => \$self->{href},
4688 wakaba 1.30 token => $t);
4689     last B;
4690     }
4691     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4692     my $value = $t->{number} * $sign;
4693     $t = $tt->get_next_token;
4694     $prop_value{'background-position-x'} = ['PERCENTAGE', $value];
4695     } elsif ($t->{type} == NUMBER_TOKEN and
4696     ($self->{unitless_px} or $t->{number} == 0)) {
4697     my $value = $t->{number} * $sign;
4698     $t = $tt->get_next_token;
4699     $prop_value{'background-position-x'} = ['DIMENSION', $value, 'px'];
4700     } else {
4701     ## NOTE: Should not be happened.
4702     last B;
4703     }
4704    
4705     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4706     if ($t->{type} == MINUS_TOKEN) {
4707     $sign = -1;
4708     $t = $tt->get_next_token;
4709     } else {
4710     $sign = 1;
4711     }
4712    
4713     if ($t->{type} == DIMENSION_TOKEN) {
4714     my $value = $t->{number} * $sign;
4715     my $unit = lc $t->{value}; ## TODO: case
4716     $t = $tt->get_next_token;
4717     if ($length_unit->{$unit}) {
4718     $prop_value{'background-position-y'}
4719     = ['DIMENSION', $value, $unit];
4720     } else {
4721 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4722 wakaba 1.30 level => $self->{must_level},
4723 wakaba 1.38 uri => \$self->{href},
4724 wakaba 1.30 token => $t);
4725     last B;
4726     }
4727     } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4728     my $value = $t->{number} * $sign;
4729     $t = $tt->get_next_token;
4730     $prop_value{'background-position-y'} = ['PERCENTAGE', $value];
4731     } elsif ($t->{type} == NUMBER_TOKEN and
4732     ($self->{unitless_px} or $t->{number} == 0)) {
4733     my $value = $t->{number} * $sign;
4734     $t = $tt->get_next_token;
4735     $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
4736     } elsif ($t->{type} == IDENT_TOKEN) {
4737     my $value = lc $t->{value}; ## TODO: case
4738     if ({top => 1, center => 1, bottom => 1}->{$value}) {
4739     $prop_value{'background-position-y'} = ['KEYWORD', $value];
4740     $t = $tt->get_next_token;
4741     } else {
4742     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4743     }
4744     } else {
4745     if ($sign > 0) {
4746     $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
4747     } else {
4748 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4749 wakaba 1.30 level => $self->{must_level},
4750 wakaba 1.38 uri => \$self->{href},
4751 wakaba 1.30 token => $t);
4752     }
4753     }
4754     } elsif ($t->{type} == URI_TOKEN and
4755     not defined $prop_value{'background-image'}) {
4756     $prop_value{'background-image'} = ['URI', $t->{value}];
4757     $t = $tt->get_next_token;
4758     } else {
4759     if (keys %prop_value and $sign > 0) {
4760     last B;
4761     } else {
4762 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4763 wakaba 1.30 level => $self->{must_level},
4764 wakaba 1.38 uri => \$self->{href},
4765 wakaba 1.30 token => $t);
4766     }
4767     }
4768    
4769     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4770     } # B
4771    
4772     $prop_value{$_} ||= $Prop->{$_}->{initial}
4773     for qw/background-image background-attachment background-repeat
4774     background-color background-position-x background-position-y/;
4775    
4776     return ($t, \%prop_value);
4777     },
4778     serialize => sub {
4779     my ($self, $prop_name, $value) = @_;
4780    
4781     local $Error::Depth = $Error::Depth + 1;
4782     my $color = $self->background_color;
4783 wakaba 1.34 return '' unless length $color;
4784 wakaba 1.30 my $image = $self->background_image;
4785 wakaba 1.34 return '' unless length $image;
4786 wakaba 1.30 my $repeat = $self->background_repeat;
4787 wakaba 1.34 return '' unless length $repeat;
4788 wakaba 1.30 my $attachment = $self->background_attachment;
4789 wakaba 1.34 return '' unless length $attachment;
4790 wakaba 1.30 my $position = $self->background_position;
4791 wakaba 1.34 return '' unless length $position;
4792 wakaba 1.30
4793     my @v;
4794     push @v, $color unless $color eq 'transparent';
4795     push @v, $image unless $image eq 'none';
4796     push @v, $repeat unless $repeat eq 'repeat';
4797     push @v, $attachment unless $attachment eq 'scroll';
4798     push @v, $position unless $position eq '0% 0%';
4799     if (@v) {
4800     return join ' ', @v;
4801     } else {
4802     return 'transparent none repeat scroll 0% 0%';
4803     }
4804     },
4805     serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
4806     };
4807     $Attr->{background} = $Prop->{background};
4808    
4809 wakaba 1.31 $Prop->{font} = {
4810     css => 'font',
4811     dom => 'font',
4812     parse => sub {
4813     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4814    
4815     my %prop_value;
4816    
4817     A: for (1..3) {
4818     if ($t->{type} == IDENT_TOKEN) {
4819     my $value = lc $t->{value}; ## TODO: case
4820     if ($value eq 'normal') {
4821     $t = $tt->get_next_token;
4822     } elsif ($Prop->{'font-style'}->{keyword}->{$value} and
4823     $self->{prop_value}->{'font-style'}->{$value} and
4824     not defined $prop_value{'font-style'}) {
4825     $prop_value{'font-style'} = ['KEYWORD', $value];
4826     $t = $tt->get_next_token;
4827     } elsif ($Prop->{'font-variant'}->{keyword}->{$value} and
4828     $self->{prop_value}->{'font-variant'}->{$value} and
4829     not defined $prop_value{'font-variant'}) {
4830     $prop_value{'font-variant'} = ['KEYWORD', $value];
4831     $t = $tt->get_next_token;
4832     } elsif ({normal => 1, bold => 1,
4833     bolder => 1, lighter => 1}->{$value} and
4834     not defined $prop_value{'font-weight'}) {
4835     $prop_value{'font-weight'} = ['KEYWORD', $value];
4836     $t = $tt->get_next_token;
4837     } elsif ($value eq 'inherit' and 0 == keys %prop_value) {
4838     $t = $tt->get_next_token;
4839     return ($t, {'font-style' => ['INHERIT'],
4840     'font-variant' => ['INHERIT'],
4841     'font-weight' => ['INHERIT'],
4842     'font-size' => ['INHERIT'],
4843     'line-height' => ['INHERIT'],
4844     'font-family' => ['INHERIT']});
4845     } elsif ({
4846     caption => 1, icon => 1, menu => 1,
4847     'message-box' => 1, 'small-caption' => 1, 'status-bar' => 1,
4848     }->{$value} and 0 == keys %prop_value) {
4849     $t = $tt->get_next_token;
4850     return ($t, $self->{get_system_font}->($self, $value, {
4851     'font-style' => $Prop->{'font-style'}->{initial},
4852     'font-variant' => $Prop->{'font-variant'}->{initial},
4853     'font-weight' => $Prop->{'font-weight'}->{initial},
4854     'font-size' => $Prop->{'font-size'}->{initial},
4855     'line-height' => $Prop->{'line-height'}->{initial},
4856     'font-family' => ['FONT', ['KEYWORD', '-manakai-'.$value]],
4857     }));
4858     } else {
4859     if (keys %prop_value) {
4860     last A;
4861     } else {
4862 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4863 wakaba 1.31 level => $self->{must_level},
4864 wakaba 1.38 uri => \$self->{href},
4865 wakaba 1.31 token => $t);
4866     return ($t, undef);
4867     }
4868     }
4869     } elsif ($t->{type} == NUMBER_TOKEN) {
4870     if ({100 => 1, 200 => 1, 300 => 1, 400 => 1, 500 => 1,
4871     600 => 1, 700 => 1, 800 => 1, 900 => 1}->{$t->{value}}) {
4872     $prop_value{'font-weight'} = ['NUMBER', $t->{value}];
4873     $t = $tt->get_next_token;
4874     } else {
4875     last A;
4876     }
4877     }
4878    
4879     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4880     } # A
4881    
4882     for (qw/font-style font-variant font-weight/) {
4883     $prop_value{$_} = $Prop->{$_}->{initial} unless defined $prop_value{$_};
4884     }
4885    
4886     ($t, my $pv) = $Prop->{'font-size'}->{parse}
4887     ->($self, 'font', $tt, $t, $onerror);
4888     return ($t, undef) unless defined $pv;
4889     if ($pv->{font}->[0] eq 'INHERIT') {
4890 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4891 wakaba 1.31 level => $self->{must_level},
4892 wakaba 1.38 uri => \$self->{href},
4893 wakaba 1.31 token => $t);
4894     return ($t, undef);
4895     }
4896     $prop_value{'font-size'} = $pv->{font};
4897    
4898     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4899     if ($t->{type} == DELIM_TOKEN and $t->{value} eq '/') {
4900     $t = $tt->get_next_token;
4901     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4902     ($t, my $pv) = $Prop->{'line-height'}->{parse}
4903     ->($self, 'font', $tt, $t, $onerror);
4904     return ($t, undef) unless defined $pv;
4905     if ($pv->{font}->[0] eq 'INHERIT') {
4906 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4907 wakaba 1.31 level => $self->{must_level},
4908 wakaba 1.38 uri => \$self->{href},
4909 wakaba 1.31 token => $t);
4910     return ($t, undef);
4911     }
4912     $prop_value{'line-height'} = $pv->{font};
4913     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4914     } else {
4915     $prop_value{'line-height'} = $Prop->{'line-height'}->{initial};
4916     }
4917    
4918     undef $pv;
4919     ($t, $pv) = $Prop->{'font-family'}->{parse}
4920     ->($self, 'font', $tt, $t, $onerror);
4921     return ($t, undef) unless defined $pv;
4922     $prop_value{'font-family'} = $pv->{font};
4923    
4924     return ($t, \%prop_value);
4925     },
4926     serialize => sub {
4927     my ($self, $prop_name, $value) = @_;
4928    
4929     local $Error::Depth = $Error::Depth + 1;
4930     my $style = $self->font_style;
4931     my $i = $self->get_property_priority ('font-style');
4932 wakaba 1.34 return '' unless length $style;
4933 wakaba 1.31 my $variant = $self->font_variant;
4934 wakaba 1.34 return '' unless length $variant;
4935     return '' if $i ne $self->get_property_priority ('font-variant');
4936 wakaba 1.31 my $weight = $self->font_weight;
4937 wakaba 1.34 return '' unless length $weight;
4938     return '' if $i ne $self->get_property_priority ('font-weight');
4939 wakaba 1.31 my $size = $self->font_size;
4940 wakaba 1.34 return '' unless length $size;
4941     return '' if $i ne $self->get_property_priority ('font-size');
4942 wakaba 1.31 my $height = $self->line_height;
4943 wakaba 1.34 return '' unless length $height;
4944     return '' if $i ne $self->get_property_priority ('line-height');
4945 wakaba 1.31 my $family = $self->font_family;
4946 wakaba 1.34 return '' unless length $family;
4947     return '' if $i ne $self->get_property_priority ('font-family');
4948 wakaba 1.31
4949     my @v;
4950     push @v, $style unless $style eq 'normal';
4951     push @v, $variant unless $variant eq 'normal';
4952     push @v, $weight unless $weight eq 'normal';
4953     push @v, $size.($height eq 'normal' ? '' : '/'.$height);
4954     push @v, $family;
4955 wakaba 1.34 push @v, '! '.$i if length $i;
4956 wakaba 1.31 return join ' ', @v;
4957     },
4958     };
4959     $Attr->{font} = $Prop->{font};
4960    
4961 wakaba 1.20 $Prop->{'border-width'} = {
4962     css => 'border-width',
4963     dom => 'border_width',
4964     parse => sub {
4965     my ($self, $prop_name, $tt, $t, $onerror) = @_;
4966    
4967     my %prop_value;
4968    
4969     my $sign = 1;
4970     if ($t->{type} == MINUS_TOKEN) {
4971     $t = $tt->get_next_token;
4972     $sign = -1;
4973     }
4974    
4975     if ($t->{type} == DIMENSION_TOKEN) {
4976     my $value = $t->{number} * $sign;
4977     my $unit = lc $t->{value}; ## TODO: case
4978     $t = $tt->get_next_token;
4979     if ($length_unit->{$unit} and $value >= 0) {
4980     $prop_value{'border-top-width'} = ['DIMENSION', $value, $unit];
4981     } else {
4982 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4983 wakaba 1.20 level => $self->{must_level},
4984 wakaba 1.38 uri => \$self->{href},
4985 wakaba 1.20 token => $t);
4986     return ($t, undef);
4987     }
4988     } elsif ($t->{type} == NUMBER_TOKEN and
4989     ($self->{unitless_px} or $t->{number} == 0)) {
4990     my $value = $t->{number} * $sign;
4991     $t = $tt->get_next_token;
4992     $prop_value{'border-top-width'} = ['DIMENSION', $value, 'px'];
4993     unless ($value >= 0) {
4994 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
4995 wakaba 1.20 level => $self->{must_level},
4996 wakaba 1.38 uri => \$self->{href},
4997 wakaba 1.20 token => $t);
4998     return ($t, undef);
4999     }
5000     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
5001     my $prop_value = lc $t->{value}; ## TODO: case folding
5002     $t = $tt->get_next_token;
5003     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5004     $prop_value{'border-top-width'} = ['KEYWORD', $prop_value];
5005     } elsif ($prop_value eq 'inherit') {
5006     $prop_value{'border-top-width'} = ['INHERIT'];
5007     $prop_value{'border-right-width'} = $prop_value{'border-top-width'};
5008     $prop_value{'border-bottom-width'} = $prop_value{'border-top-width'};
5009     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5010     return ($t, \%prop_value);
5011     } else {
5012 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5013 wakaba 1.20 level => $self->{must_level},
5014 wakaba 1.38 uri => \$self->{href},
5015 wakaba 1.20 token => $t);
5016     return ($t, undef);
5017     }
5018     } else {
5019 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5020 wakaba 1.20 level => $self->{must_level},
5021 wakaba 1.38 uri => \$self->{href},
5022 wakaba 1.20 token => $t);
5023     return ($t, undef);
5024     }
5025     $prop_value{'border-right-width'} = $prop_value{'border-top-width'};
5026     $prop_value{'border-bottom-width'} = $prop_value{'border-top-width'};
5027     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5028    
5029     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5030     $sign = 1;
5031     if ($t->{type} == MINUS_TOKEN) {
5032     $t = $tt->get_next_token;
5033     $sign = -1;
5034     }
5035    
5036     if ($t->{type} == DIMENSION_TOKEN) {
5037     my $value = $t->{number} * $sign;
5038     my $unit = lc $t->{value}; ## TODO: case
5039     $t = $tt->get_next_token;
5040     if ($length_unit->{$unit} and $value >= 0) {
5041     $prop_value{'border-right-width'} = ['DIMENSION', $value, $unit];
5042     } else {
5043 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5044 wakaba 1.20 level => $self->{must_level},
5045 wakaba 1.38 uri => \$self->{href},
5046 wakaba 1.20 token => $t);
5047     return ($t, undef);
5048     }
5049     } elsif ($t->{type} == NUMBER_TOKEN and
5050     ($self->{unitless_px} or $t->{number} == 0)) {
5051     my $value = $t->{number} * $sign;
5052     $t = $tt->get_next_token;
5053     $prop_value{'border-right-width'} = ['DIMENSION', $value, 'px'];
5054     unless ($value >= 0) {
5055 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5056 wakaba 1.20 level => $self->{must_level},
5057 wakaba 1.38 uri => \$self->{href},
5058 wakaba 1.20 token => $t);
5059     return ($t, undef);
5060     }
5061     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
5062     my $prop_value = lc $t->{value}; ## TODO: case
5063     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5064     $prop_value{'border-right-width'} = ['KEYWORD', $prop_value];
5065     $t = $tt->get_next_token;
5066     }
5067     } else {
5068 wakaba 1.24 if ($sign < 0) {
5069 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5070 wakaba 1.24 level => $self->{must_level},
5071 wakaba 1.38 uri => \$self->{href},
5072 wakaba 1.24 token => $t);
5073     return ($t, undef);
5074     }
5075 wakaba 1.20 return ($t, \%prop_value);
5076     }
5077     $prop_value{'border-left-width'} = $prop_value{'border-right-width'};
5078    
5079     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5080     $sign = 1;
5081     if ($t->{type} == MINUS_TOKEN) {
5082     $t = $tt->get_next_token;
5083     $sign = -1;
5084     }
5085    
5086     if ($t->{type} == DIMENSION_TOKEN) {
5087     my $value = $t->{number} * $sign;
5088     my $unit = lc $t->{value}; ## TODO: case
5089     $t = $tt->get_next_token;
5090     if ($length_unit->{$unit} and $value >= 0) {
5091     $prop_value{'border-bottom-width'} = ['DIMENSION', $value, $unit];
5092     } else {
5093 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5094 wakaba 1.20 level => $self->{must_level},
5095 wakaba 1.38 uri => \$self->{href},
5096 wakaba 1.20 token => $t);
5097     return ($t, undef);
5098     }
5099     } elsif ($t->{type} == NUMBER_TOKEN and
5100     ($self->{unitless_px} or $t->{number} == 0)) {
5101     my $value = $t->{number} * $sign;
5102     $t = $tt->get_next_token;
5103     $prop_value{'border-bottom-width'} = ['DIMENSION', $value, 'px'];
5104     unless ($value >= 0) {
5105 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5106 wakaba 1.20 level => $self->{must_level},
5107 wakaba 1.38 uri => \$self->{href},
5108 wakaba 1.20 token => $t);
5109     return ($t, undef);
5110     }
5111     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
5112     my $prop_value = lc $t->{value}; ## TODO: case
5113     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5114     $prop_value{'border-bottom-width'} = ['KEYWORD', $prop_value];
5115     $t = $tt->get_next_token;
5116     }
5117     } else {
5118 wakaba 1.24 if ($sign < 0) {
5119 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5120 wakaba 1.24 level => $self->{must_level},
5121 wakaba 1.38 uri => \$self->{href},
5122 wakaba 1.24 token => $t);
5123     return ($t, undef);
5124     }
5125 wakaba 1.20 return ($t, \%prop_value);
5126     }
5127    
5128     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5129     $sign = 1;
5130     if ($t->{type} == MINUS_TOKEN) {
5131     $t = $tt->get_next_token;
5132     $sign = -1;
5133     }
5134    
5135     if ($t->{type} == DIMENSION_TOKEN) {
5136     my $value = $t->{number} * $sign;
5137     my $unit = lc $t->{value}; ## TODO: case
5138     $t = $tt->get_next_token;
5139     if ($length_unit->{$unit} and $value >= 0) {
5140     $prop_value{'border-left-width'} = ['DIMENSION', $value, $unit];
5141     } else {
5142 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5143 wakaba 1.20 level => $self->{must_level},
5144 wakaba 1.38 uri => \$self->{href},
5145 wakaba 1.20 token => $t);
5146     return ($t, undef);
5147     }
5148     } elsif ($t->{type} == NUMBER_TOKEN and
5149     ($self->{unitless_px} or $t->{number} == 0)) {
5150     my $value = $t->{number} * $sign;
5151     $t = $tt->get_next_token;
5152     $prop_value{'border-left-width'} = ['DIMENSION', $value, 'px'];
5153     unless ($value >= 0) {
5154 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5155 wakaba 1.20 level => $self->{must_level},
5156 wakaba 1.38 uri => \$self->{href},
5157 wakaba 1.20 token => $t);
5158     return ($t, undef);
5159     }
5160     } elsif ($sign > 0 and $t->{type} == IDENT_TOKEN) {
5161     my $prop_value = lc $t->{value}; ## TODO: case
5162     if ({thin => 1, medium => 1, thick => 1}->{$prop_value}) {
5163     $prop_value{'border-left-width'} = ['KEYWORD', $prop_value];
5164     $t = $tt->get_next_token;
5165     }
5166     } else {
5167 wakaba 1.24 if ($sign < 0) {
5168 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5169 wakaba 1.24 level => $self->{must_level},
5170 wakaba 1.38 uri => \$self->{href},
5171 wakaba 1.24 token => $t);
5172     return ($t, undef);
5173     }
5174 wakaba 1.20 return ($t, \%prop_value);
5175     }
5176    
5177     return ($t, \%prop_value);
5178     },
5179     serialize => sub {
5180     my ($self, $prop_name, $value) = @_;
5181    
5182     local $Error::Depth = $Error::Depth + 1;
5183     my @v;
5184 wakaba 1.24 push @v, $self->border_top_width;
5185 wakaba 1.34 return '' unless length $v[-1];
5186 wakaba 1.24 push @v, $self->border_right_width;
5187 wakaba 1.34 return '' unless length $v[-1];
5188 wakaba 1.24 push @v, $self->border_bottom_width;
5189 wakaba 1.34 return '' unless length $v[-1];
5190 wakaba 1.24 push @v, $self->border_left_width;
5191 wakaba 1.34 return '' unless length $v[-1];
5192 wakaba 1.20
5193     pop @v if $v[1] eq $v[3];
5194     pop @v if $v[0] eq $v[2];
5195     pop @v if $v[0] eq $v[1];
5196     return join ' ', @v;
5197     },
5198 wakaba 1.29 serialize_multiple => $Prop->{'border-top-color'}->{serialize_multiple},
5199 wakaba 1.20 };
5200 wakaba 1.24 $Attr->{border_width} = $Prop->{'border-width'};
5201 wakaba 1.20
5202 wakaba 1.12 $Prop->{'list-style'} = {
5203     css => 'list-style',
5204     dom => 'list_style',
5205     parse => sub {
5206     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5207    
5208     my %prop_value;
5209     my $none = 0;
5210    
5211     F: for my $f (1..3) {
5212     if ($t->{type} == IDENT_TOKEN) {
5213     my $prop_value = lc $t->{value}; ## TODO: case folding
5214     $t = $tt->get_next_token;
5215    
5216     if ($prop_value eq 'none') {
5217     $none++;
5218     } elsif ($Prop->{'list-style-type'}->{keyword}->{$prop_value}) {
5219     if (exists $prop_value{'list-style-type'}) {
5220 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5221 wakaba 1.12 level => $self->{must_level},
5222 wakaba 1.38 uri => \$self->{href},
5223 wakaba 1.12 token => $t);
5224     return ($t, undef);
5225     } else {
5226     $prop_value{'list-style-type'} = ['KEYWORD', $prop_value];
5227     }
5228     } elsif ($Prop->{'list-style-position'}->{keyword}->{$prop_value}) {
5229     if (exists $prop_value{'list-style-position'}) {
5230 wakaba 1.39 $onerror->(type => "duplication:'list-style-position'",
5231 wakaba 1.12 level => $self->{must_level},
5232 wakaba 1.38 uri => \$self->{href},
5233 wakaba 1.12 token => $t);
5234     return ($t, undef);
5235     }
5236    
5237     $prop_value{'list-style-position'} = ['KEYWORD', $prop_value];
5238     } elsif ($f == 1 and $prop_value eq 'inherit') {
5239     $prop_value{'list-style-type'} = ["INHERIT"];
5240     $prop_value{'list-style-position'} = ["INHERIT"];
5241     $prop_value{'list-style-image'} = ["INHERIT"];
5242     last F;
5243     } else {
5244     if ($f == 1) {
5245 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5246 wakaba 1.12 level => $self->{must_level},
5247 wakaba 1.38 uri => \$self->{href},
5248 wakaba 1.12 token => $t);
5249     return ($t, undef);
5250     } else {
5251     last F;
5252     }
5253     }
5254     } elsif ($t->{type} == URI_TOKEN) {
5255     if (exists $prop_value{'list-style-image'}) {
5256 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5257 wakaba 1.38 uri => \$self->{href},
5258 wakaba 1.12 level => $self->{must_level},
5259     token => $t);
5260     return ($t, undef);
5261     }
5262    
5263     $prop_value{'list-style-image'}
5264 wakaba 1.13 = ['URI', $t->{value}, \($self->{base_uri})];
5265 wakaba 1.12 $t = $tt->get_next_token;
5266     } else {
5267     if ($f == 1) {
5268 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5269 wakaba 1.12 level => $self->{must_level},
5270 wakaba 1.38 uri => \$self->{href},
5271 wakaba 1.12 token => $t);
5272     return ($t, undef);
5273     } else {
5274     last F;
5275     }
5276     }
5277    
5278     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5279     } # F
5280     ## NOTE: No browser support |list-style: url(xxx|{EOF}.
5281    
5282     if ($none == 1) {
5283     if (exists $prop_value{'list-style-type'}) {
5284     if (exists $prop_value{'list-style-image'}) {
5285 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5286 wakaba 1.38 uri => \$self->{href},
5287 wakaba 1.12 level => $self->{must_level},
5288     token => $t);
5289     return ($t, undef);
5290     } else {
5291     $prop_value{'list-style-image'} = ['KEYWORD', 'none'];
5292     }
5293     } else {
5294     $prop_value{'list-style-type'} = ['KEYWORD', 'none'];
5295     $prop_value{'list-style-image'} = ['KEYWORD', 'none']
5296     unless exists $prop_value{'list-style-image'};
5297     }
5298     } elsif ($none == 2) {
5299     if (exists $prop_value{'list-style-type'}) {
5300 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5301 wakaba 1.38 uri => \$self->{href},
5302 wakaba 1.12 level => $self->{must_level},
5303     token => $t);
5304     return ($t, undef);
5305     }
5306     if (exists $prop_value{'list-style-image'}) {
5307 wakaba 1.39 $onerror->(type => "duplication:'list-style-image'",
5308 wakaba 1.38 uri => \$self->{href},
5309 wakaba 1.12 level => $self->{must_level},
5310     token => $t);
5311     return ($t, undef);
5312     }
5313    
5314     $prop_value{'list-style-type'} = ['KEYWORD', 'none'];
5315     $prop_value{'list-style-image'} = ['KEYWORD', 'none'];
5316     } elsif ($none == 3) {
5317 wakaba 1.39 $onerror->(type => "duplication:'list-style-type'",
5318 wakaba 1.38 uri => \$self->{href},
5319 wakaba 1.12 level => $self->{must_level},
5320     token => $t);
5321     return ($t, undef);
5322     }
5323    
5324     for (qw/list-style-type list-style-position list-style-image/) {
5325     $prop_value{$_} = $Prop->{$_}->{initial} unless exists $prop_value{$_};
5326     }
5327    
5328     return ($t, \%prop_value);
5329     },
5330     serialize => sub {
5331     my ($self, $prop_name, $value) = @_;
5332    
5333     local $Error::Depth = $Error::Depth + 1;
5334     return $self->list_style_type . ' ' . $self->list_style_position .
5335     ' ' . $self->list_style_image;
5336     },
5337     };
5338     $Attr->{list_style} = $Prop->{'list-style'};
5339    
5340 wakaba 1.16 ## NOTE: Future version of the implementation will change the way to
5341     ## store the parsed value to support CSS 3 properties.
5342     $Prop->{'text-decoration'} = {
5343     css => 'text-decoration',
5344     dom => 'text_decoration',
5345     key => 'text_decoration',
5346     parse => sub {
5347     my ($self, $prop_name, $tt, $t, $onerror) = @_;
5348    
5349     my $value = ['DECORATION']; # , underline, overline, line-through, blink
5350    
5351     if ($t->{type} == IDENT_TOKEN) {
5352     my $v = lc $t->{value}; ## TODO: case
5353     $t = $tt->get_next_token;
5354     if ($v eq 'inherit') {
5355     return ($t, {$prop_name => ['INHERIT']});
5356     } elsif ($v eq 'none') {
5357     return ($t, {$prop_name => $value});
5358     } elsif ($v eq 'underline' and
5359     $self->{prop_value}->{$prop_name}->{$v}) {
5360     $value->[1] = 1;
5361     } elsif ($v eq 'overline' and
5362     $self->{prop_value}->{$prop_name}->{$v}) {
5363     $value->[2] = 1;
5364     } elsif ($v eq 'line-through' and
5365     $self->{prop_value}->{$prop_name}->{$v}) {
5366     $value->[3] = 1;
5367     } elsif ($v eq 'blink' and
5368     $self->{prop_value}->{$prop_name}->{$v}) {
5369     $value->[4] = 1;
5370     } else {
5371 wakaba 1.39 $onerror->(type => "syntax error:'$prop_name'",
5372 wakaba 1.16 level => $self->{must_level},
5373 wakaba 1.38 uri => \$self->{href},
5374 wakaba 1.16 token => $t);
5375     return ($t, undef);
5376     }
5377     }
5378    
5379     F: {
5380     $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5381     last F unless $t->{type} == IDENT_TOKEN;
5382    
5383     my $v = lc $t->{value}; ## TODO: case
5384     $t = $tt->get_next_token;
5385     if ($v eq 'underline' and
5386     $self->{prop_value}->{$prop_name}->{$v}) {
5387     $value->[1] = 1;
5388     } elsif ($v eq 'overline' and
5389     $self->{prop_value}->{$prop_name}->{$v}) {
5390     $value->[1] = 2;
5391     } elsif ($v eq 'line-through' and
5392     $self->{prop_value}->{$prop_name}->{$v}) {
5393     $value->[1] = 3;
5394     } elsif ($v eq 'blink' and
5395     $self->{prop_value}->{$prop_name}->{$v}) {
5396     $value->[1] = 4;
5397     } else {
5398     last F;
5399     }
5400    
5401     redo F;
5402     } # F
5403    
5404     return ($t, {$prop_name => $value});
5405     },
5406     serialize => $default_serializer,
5407     initial => ["KEYWORD", "none"],
5408     #inherited => 0,
5409     compute => $compute_as_specified,
5410     };
5411     $Attr->{text_decoration} = $Prop->{'text-decoration'};
5412     $Key->{text_decoration} = $Prop->{'text-decoration'};
5413    
5414 wakaba 1.1 1;
5415 wakaba 1.41 ## $Date: 2008/01/22 12:47:26 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24