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