1 |
package Message::DOM::CSSRule; |
2 |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
push our @ISA, 'Message::IF::CSSRule'; |
5 |
require Scalar::Util; |
6 |
|
7 |
## |CSSRule| constants |
8 |
|
9 |
sub STYLE_RULE () { 1 } |
10 |
sub CHARSET_RULE () { 2 } |
11 |
sub IMPORT_RULE () { 3 } |
12 |
sub MEDIA_RULE () { 4 } |
13 |
sub FONT_FACE_RULE () { 5 } |
14 |
sub PAGE_RULE () { 6 } |
15 |
sub NAMESPACE_RULE () { 7 } |
16 |
|
17 |
## |CSSRule| attributes |
18 |
|
19 |
sub css_text ($) { |
20 |
die "$0: ".(ref $_[0])."->css_text: Not implemented"; |
21 |
} # css_text |
22 |
|
23 |
sub parent_rule ($) { |
24 |
return ${$_[0]}->{parent_rule}; |
25 |
} # parent_rule |
26 |
|
27 |
sub parent_style_sheet ($) { |
28 |
if (${$_[0]}->{parent_style_sheet}) { |
29 |
return ${$_[0]}->{parent_style_sheet}; |
30 |
} elsif (${$_[0]}->{parent_rule}) { |
31 |
local $Error::Depth = $Error::Depth + 1; |
32 |
return ${$_[0]}->{parent_rule}->parent_style_sheet; |
33 |
} else { |
34 |
## NOTE: Not in the CSSOM ED: If the |CSSRule| object is not |
35 |
## yet associated to any CSS style sheet. Such object should not be |
36 |
## returned to applications - that is, the intention is that only |
37 |
## modules belonging to manakai may get |undef| from the |
38 |
## |parent_style_sheet| attribute during the construction of CSSOM. |
39 |
## Therefore, this is not counted as a manakai extension to CSSOM spec. |
40 |
return undef; |
41 |
} |
42 |
} # parent_style_sheet |
43 |
|
44 |
sub type ($) { |
45 |
die "$0: ".(ref $_[0])."->type: Not implemented"; |
46 |
} # type |
47 |
|
48 |
package Message::DOM::CSSStyleRule; |
49 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSStyleRule'; |
50 |
|
51 |
sub ____new ($$$) { |
52 |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
53 |
${$_[2]}->{parent_rule} = $self; |
54 |
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
55 |
return $self; |
56 |
} # ____new |
57 |
|
58 |
## |CSSRule| attributes |
59 |
|
60 |
sub css_text ($;$) { |
61 |
## TODO: setter |
62 |
|
63 |
## TODO: Browser compatibility |
64 |
local $Error::Depth = $Error::Depth + 1; |
65 |
return $_[0]->selector_text . " {\n" . $_[0]->style->css_text . "}\n"; |
66 |
} # css_text |
67 |
|
68 |
sub type ($) { Message::DOM::CSSRule::STYLE_RULE } |
69 |
|
70 |
## |CSSStyleRule| attributes |
71 |
|
72 |
sub selector_text ($;$) { |
73 |
## TODO: setter |
74 |
|
75 |
## TODO: Browser-compatible serializer |
76 |
## TODO: This code does not work for cases where default namespace |
77 |
## has no namespace prefix declared. |
78 |
my $self = $_[0]; |
79 |
require Whatpm::CSS::SelectorsSerializer; |
80 |
return Whatpm::CSS::SelectorsSerializer->serialize_selector_text |
81 |
($$self->{_selectors}, sub { |
82 |
## TODO: We should have some caching mechanism, otherwise |
83 |
## too many computation for complex selectors in long style sheet. |
84 |
return $self->parent_style_sheet->manakai_lookup_namespace_prefix |
85 |
($_[0]); |
86 |
}); |
87 |
} # selector_text |
88 |
|
89 |
sub style ($) { |
90 |
return ${$_[0]}->{style}; |
91 |
} # style |
92 |
|
93 |
package Message::DOM::CSSCharsetRule; |
94 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSCharsetRule'; |
95 |
|
96 |
sub ____new ($$) { |
97 |
return bless \{encoding => $_[1]}, $_[0]; |
98 |
} # ____new |
99 |
|
100 |
## |CSSRule| attributes |
101 |
|
102 |
sub css_text ($;$) { |
103 |
## TODO: setter |
104 |
|
105 |
## NOTE: It will be broken if |encoding| contains |"| or |\|, but this |
106 |
## is what browsers do. |
107 |
return '@charset "'.${$_[0]}->{encoding}.'";'; |
108 |
} # css_text |
109 |
|
110 |
sub type ($) { Message::DOM::CSSRule::CHARSET_RULE } |
111 |
|
112 |
## |CSSCharsetRule| attribute |
113 |
|
114 |
sub encoding ($) { |
115 |
return ${$_[0]}->{encoding}; |
116 |
} # encoding |
117 |
|
118 |
package Message::DOM::CSSImportRule; |
119 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSImportRule'; |
120 |
|
121 |
sub ____new ($$$$) { |
122 |
my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0]; |
123 |
${$_[3]}->{owner_rule} = $self; |
124 |
Scalar::Util::weaken (${$_[3]}->{owner_rule}); |
125 |
return $self; |
126 |
} # ____new |
127 |
|
128 |
## |CSSRule| attributes |
129 |
|
130 |
## TODO: |css_text| |
131 |
|
132 |
sub type ($) { Message::DOM::CSSRule::IMPORT_RULE } |
133 |
|
134 |
## |CSSImportRule| attributes |
135 |
|
136 |
sub href ($) { |
137 |
return ${$_[0]}->{href}; |
138 |
} # href |
139 |
|
140 |
sub media ($) { |
141 |
return ${$_[0]}->{media}; |
142 |
} # media |
143 |
|
144 |
sub style_sheet ($) { |
145 |
return ${$_[0]}->{style_sheet}; |
146 |
} # style_sheet |
147 |
|
148 |
package Message::DOM::CSSMediaRule; |
149 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule'; |
150 |
|
151 |
sub ____new ($$$) { |
152 |
my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0]; |
153 |
for (@{$_[2]}) { |
154 |
${$_}->{parent_rule} = $self; |
155 |
Scalar::Util::weaken (${$_}->{parent_rule}); |
156 |
} |
157 |
return $self; |
158 |
} # ____new |
159 |
|
160 |
## |CSSRule| attributes |
161 |
|
162 |
## TODO: |css_text| |
163 |
|
164 |
sub type ($) { Message::DOM::CSSRule::MEDIA_RULE } |
165 |
|
166 |
## |CSSMediaRule| attributes |
167 |
|
168 |
sub css_rules ($) { |
169 |
require Message::DOM::CSSRuleList; |
170 |
return bless \\($_[0]), 'Message::DOM::CSSRuleList'; |
171 |
} # css_rules |
172 |
|
173 |
sub media ($) { |
174 |
return ${$_[0]}->{media}; |
175 |
} # media |
176 |
|
177 |
package Message::DOM::CSSFontFaceRule; |
178 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSFontFaceRule'; |
179 |
|
180 |
sub ____new ($$) { |
181 |
my $self = bless \{style => $_[1]}, $_[0]; |
182 |
${$_[2]}->{parent_rule} = $self; |
183 |
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
184 |
return $self; |
185 |
} # ____new |
186 |
|
187 |
## |CSSRule| attributes |
188 |
|
189 |
## TODO: |css_text| |
190 |
|
191 |
sub type ($) { Message::DOM::CSSRule::FONT_FACE_RULE } |
192 |
|
193 |
## |CSSFontFaceRule| attribute |
194 |
|
195 |
sub style ($) { |
196 |
return ${$_[0]}->{style}; |
197 |
} # style |
198 |
|
199 |
package Message::DOM::CSSPageRule; |
200 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule'; |
201 |
|
202 |
sub ____new ($$$) { |
203 |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
204 |
${$_[2]}->{parent_rule} = $self; |
205 |
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
206 |
return $self; |
207 |
} # ____new |
208 |
|
209 |
## |CSSRule| attributes |
210 |
|
211 |
## TODO: |css_text| |
212 |
|
213 |
sub type ($) { Message::DOM::CSSRule::PAGE_RULE } |
214 |
|
215 |
## |CSSPageRule| attributes |
216 |
|
217 |
sub selector_text ($;$) { |
218 |
## TODO: setter |
219 |
|
220 |
## TODO: Browser-compatible serializer |
221 |
require Whatpm::CSS::SelectorsSerializer; |
222 |
return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors}); |
223 |
} # selector_text |
224 |
|
225 |
sub style ($) { |
226 |
return ${$_[0]}->{style}; |
227 |
} # style |
228 |
|
229 |
package Message::DOM::CSSNamespaceRule; |
230 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSNamespaceRule'; |
231 |
|
232 |
sub ____new ($$$) { |
233 |
return bless \{namespace_uri => $_[2], prefix => $_[1]}, $_[0]; |
234 |
} # ___new |
235 |
|
236 |
## |CSSRule| attributes |
237 |
|
238 |
sub css_text ($;$) { |
239 |
## TODO: Setter |
240 |
|
241 |
## NOTE: Sometimes ugly, but this is what Firefox does. |
242 |
my $prefix = ${$_[0]}->{prefix}; |
243 |
return '@namespace '.($prefix ne '' ? $prefix.' ' : ''). |
244 |
'url('.${$_[0]}->{namespace_uri}.');'; |
245 |
} # css_text |
246 |
|
247 |
sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE } |
248 |
|
249 |
## |CSSNamespaceRule| attributes |
250 |
|
251 |
sub namespace_uri ($) { |
252 |
return ${$_[0]}->{namespace_uri}; |
253 |
} # namespace_uri |
254 |
|
255 |
sub prefix ($) { |
256 |
return ${$_[0]}->{prefix}; |
257 |
} # prefix |
258 |
|
259 |
package Message::IF::CSSRule; |
260 |
package Message::IF::CSSStyleRule; |
261 |
package Message::IF::CSSCharsetRule; |
262 |
package Message::IF::CSSImportRule; |
263 |
package Message::IF::CSSMediaRule; |
264 |
package Message::IF::CSSFontFaceRule; |
265 |
package Message::IF::CSSPageRule; |
266 |
|
267 |
1; |
268 |
## $Date: 2007/12/23 15:45:49 $ |