1 |
wakaba |
1.1 |
package Message::DOM::CSSRule; |
2 |
|
|
use strict; |
3 |
wakaba |
1.7 |
our $VERSION=do{my @r=(q$Revision: 1.6 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.1 |
push our @ISA, 'Message::IF::CSSRule'; |
5 |
wakaba |
1.2 |
require Scalar::Util; |
6 |
wakaba |
1.1 |
|
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 |
wakaba |
1.3 |
die "$0: ".(ref $_[0])."->css_text: Not implemented"; |
21 |
wakaba |
1.1 |
} # css_text |
22 |
|
|
|
23 |
wakaba |
1.2 |
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 |
wakaba |
1.1 |
|
44 |
|
|
sub type ($) { |
45 |
wakaba |
1.3 |
die "$0: ".(ref $_[0])."->type: Not implemented"; |
46 |
wakaba |
1.1 |
} # type |
47 |
|
|
|
48 |
|
|
package Message::DOM::CSSStyleRule; |
49 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSStyleRule'; |
50 |
|
|
|
51 |
|
|
sub ____new ($$$) { |
52 |
wakaba |
1.3 |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
53 |
wakaba |
1.2 |
${$_[2]}->{parent_rule} = $self; |
54 |
|
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
55 |
wakaba |
1.1 |
return $self; |
56 |
|
|
} # ____new |
57 |
|
|
|
58 |
|
|
## |CSSRule| attributes |
59 |
|
|
|
60 |
wakaba |
1.3 |
sub css_text ($;$) { |
61 |
|
|
## TODO: setter |
62 |
|
|
|
63 |
wakaba |
1.7 |
## NOTE: Where and how white space characters are inserted are |
64 |
|
|
## intentionally changed from those in browsers so that properties are |
65 |
|
|
## more prettily printed. |
66 |
|
|
## See <http://suika.fam.cx/gate/2005/sw/cssText> for what browsers do. |
67 |
wakaba |
1.3 |
local $Error::Depth = $Error::Depth + 1; |
68 |
wakaba |
1.7 |
return $_[0]->selector_text . " {\n" . $_[0]->style->css_text . '}'; |
69 |
wakaba |
1.3 |
} # css_text |
70 |
wakaba |
1.1 |
|
71 |
|
|
sub type ($) { Message::DOM::CSSRule::STYLE_RULE } |
72 |
|
|
|
73 |
|
|
## |CSSStyleRule| attributes |
74 |
|
|
|
75 |
wakaba |
1.3 |
sub selector_text ($;$) { |
76 |
|
|
## TODO: setter |
77 |
|
|
|
78 |
|
|
## TODO: Browser-compatible serializer |
79 |
wakaba |
1.5 |
## TODO: This code does not work for cases where default namespace |
80 |
|
|
## has no namespace prefix declared. |
81 |
|
|
my $self = $_[0]; |
82 |
wakaba |
1.3 |
require Whatpm::CSS::SelectorsSerializer; |
83 |
wakaba |
1.6 |
return Whatpm::CSS::SelectorsSerializer->serialize_selector_text |
84 |
wakaba |
1.7 |
($$self->{_selectors}, ${$self->parent_style_sheet}->{_nsmap}); |
85 |
wakaba |
1.3 |
} # selector_text |
86 |
wakaba |
1.1 |
|
87 |
|
|
sub style ($) { |
88 |
|
|
return ${$_[0]}->{style}; |
89 |
|
|
} # style |
90 |
|
|
|
91 |
|
|
package Message::DOM::CSSCharsetRule; |
92 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSCharsetRule'; |
93 |
|
|
|
94 |
|
|
sub ____new ($$) { |
95 |
|
|
return bless \{encoding => $_[1]}, $_[0]; |
96 |
|
|
} # ____new |
97 |
|
|
|
98 |
|
|
## |CSSRule| attributes |
99 |
|
|
|
100 |
wakaba |
1.4 |
sub css_text ($;$) { |
101 |
|
|
## TODO: setter |
102 |
|
|
|
103 |
|
|
## NOTE: It will be broken if |encoding| contains |"| or |\|, but this |
104 |
|
|
## is what browsers do. |
105 |
|
|
return '@charset "'.${$_[0]}->{encoding}.'";'; |
106 |
|
|
} # css_text |
107 |
wakaba |
1.1 |
|
108 |
|
|
sub type ($) { Message::DOM::CSSRule::CHARSET_RULE } |
109 |
|
|
|
110 |
|
|
## |CSSCharsetRule| attribute |
111 |
|
|
|
112 |
|
|
sub encoding ($) { |
113 |
|
|
return ${$_[0]}->{encoding}; |
114 |
|
|
} # encoding |
115 |
|
|
|
116 |
|
|
package Message::DOM::CSSImportRule; |
117 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSImportRule'; |
118 |
|
|
|
119 |
|
|
sub ____new ($$$$) { |
120 |
|
|
my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0]; |
121 |
wakaba |
1.2 |
${$_[3]}->{owner_rule} = $self; |
122 |
|
|
Scalar::Util::weaken (${$_[3]}->{owner_rule}); |
123 |
wakaba |
1.1 |
return $self; |
124 |
|
|
} # ____new |
125 |
|
|
|
126 |
|
|
## |CSSRule| attributes |
127 |
|
|
|
128 |
|
|
## TODO: |css_text| |
129 |
|
|
|
130 |
|
|
sub type ($) { Message::DOM::CSSRule::IMPORT_RULE } |
131 |
|
|
|
132 |
|
|
## |CSSImportRule| attributes |
133 |
|
|
|
134 |
|
|
sub href ($) { |
135 |
|
|
return ${$_[0]}->{href}; |
136 |
|
|
} # href |
137 |
|
|
|
138 |
|
|
sub media ($) { |
139 |
|
|
return ${$_[0]}->{media}; |
140 |
|
|
} # media |
141 |
|
|
|
142 |
|
|
sub style_sheet ($) { |
143 |
|
|
return ${$_[0]}->{style_sheet}; |
144 |
|
|
} # style_sheet |
145 |
|
|
|
146 |
|
|
package Message::DOM::CSSMediaRule; |
147 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule'; |
148 |
|
|
|
149 |
|
|
sub ____new ($$$) { |
150 |
|
|
my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0]; |
151 |
|
|
for (@{$_[2]}) { |
152 |
wakaba |
1.2 |
${$_}->{parent_rule} = $self; |
153 |
|
|
Scalar::Util::weaken (${$_}->{parent_rule}); |
154 |
wakaba |
1.1 |
} |
155 |
|
|
return $self; |
156 |
|
|
} # ____new |
157 |
|
|
|
158 |
|
|
## |CSSRule| attributes |
159 |
|
|
|
160 |
|
|
## TODO: |css_text| |
161 |
|
|
|
162 |
|
|
sub type ($) { Message::DOM::CSSRule::MEDIA_RULE } |
163 |
|
|
|
164 |
|
|
## |CSSMediaRule| attributes |
165 |
|
|
|
166 |
|
|
sub css_rules ($) { |
167 |
|
|
require Message::DOM::CSSRuleList; |
168 |
|
|
return bless \\($_[0]), 'Message::DOM::CSSRuleList'; |
169 |
|
|
} # css_rules |
170 |
|
|
|
171 |
|
|
sub media ($) { |
172 |
|
|
return ${$_[0]}->{media}; |
173 |
|
|
} # media |
174 |
|
|
|
175 |
|
|
package Message::DOM::CSSFontFaceRule; |
176 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSFontFaceRule'; |
177 |
|
|
|
178 |
|
|
sub ____new ($$) { |
179 |
|
|
my $self = bless \{style => $_[1]}, $_[0]; |
180 |
wakaba |
1.2 |
${$_[2]}->{parent_rule} = $self; |
181 |
|
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
182 |
|
|
return $self; |
183 |
wakaba |
1.1 |
} # ____new |
184 |
|
|
|
185 |
|
|
## |CSSRule| attributes |
186 |
|
|
|
187 |
|
|
## TODO: |css_text| |
188 |
|
|
|
189 |
|
|
sub type ($) { Message::DOM::CSSRule::FONT_FACE_RULE } |
190 |
|
|
|
191 |
|
|
## |CSSFontFaceRule| attribute |
192 |
|
|
|
193 |
|
|
sub style ($) { |
194 |
|
|
return ${$_[0]}->{style}; |
195 |
|
|
} # style |
196 |
|
|
|
197 |
|
|
package Message::DOM::CSSPageRule; |
198 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule'; |
199 |
|
|
|
200 |
|
|
sub ____new ($$$) { |
201 |
wakaba |
1.3 |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
202 |
wakaba |
1.2 |
${$_[2]}->{parent_rule} = $self; |
203 |
|
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
204 |
wakaba |
1.1 |
return $self; |
205 |
|
|
} # ____new |
206 |
|
|
|
207 |
|
|
## |CSSRule| attributes |
208 |
|
|
|
209 |
|
|
## TODO: |css_text| |
210 |
|
|
|
211 |
|
|
sub type ($) { Message::DOM::CSSRule::PAGE_RULE } |
212 |
|
|
|
213 |
|
|
## |CSSPageRule| attributes |
214 |
|
|
|
215 |
wakaba |
1.3 |
sub selector_text ($;$) { |
216 |
|
|
## TODO: setter |
217 |
|
|
|
218 |
|
|
## TODO: Browser-compatible serializer |
219 |
|
|
require Whatpm::CSS::SelectorsSerializer; |
220 |
|
|
return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors}); |
221 |
|
|
} # selector_text |
222 |
wakaba |
1.1 |
|
223 |
|
|
sub style ($) { |
224 |
|
|
return ${$_[0]}->{style}; |
225 |
|
|
} # style |
226 |
|
|
|
227 |
|
|
package Message::DOM::CSSNamespaceRule; |
228 |
|
|
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSNamespaceRule'; |
229 |
|
|
|
230 |
|
|
sub ____new ($$$) { |
231 |
|
|
return bless \{namespace_uri => $_[2], prefix => $_[1]}, $_[0]; |
232 |
|
|
} # ___new |
233 |
|
|
|
234 |
|
|
## |CSSRule| attributes |
235 |
|
|
|
236 |
wakaba |
1.5 |
sub css_text ($;$) { |
237 |
|
|
## TODO: Setter |
238 |
|
|
|
239 |
|
|
## NOTE: Sometimes ugly, but this is what Firefox does. |
240 |
|
|
my $prefix = ${$_[0]}->{prefix}; |
241 |
|
|
return '@namespace '.($prefix ne '' ? $prefix.' ' : ''). |
242 |
|
|
'url('.${$_[0]}->{namespace_uri}.');'; |
243 |
|
|
} # css_text |
244 |
wakaba |
1.1 |
|
245 |
|
|
sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE } |
246 |
|
|
|
247 |
|
|
## |CSSNamespaceRule| attributes |
248 |
|
|
|
249 |
|
|
sub namespace_uri ($) { |
250 |
|
|
return ${$_[0]}->{namespace_uri}; |
251 |
|
|
} # namespace_uri |
252 |
|
|
|
253 |
|
|
sub prefix ($) { |
254 |
|
|
return ${$_[0]}->{prefix}; |
255 |
|
|
} # prefix |
256 |
|
|
|
257 |
|
|
package Message::IF::CSSRule; |
258 |
|
|
package Message::IF::CSSStyleRule; |
259 |
|
|
package Message::IF::CSSCharsetRule; |
260 |
|
|
package Message::IF::CSSImportRule; |
261 |
|
|
package Message::IF::CSSMediaRule; |
262 |
|
|
package Message::IF::CSSFontFaceRule; |
263 |
|
|
package Message::IF::CSSPageRule; |
264 |
|
|
|
265 |
|
|
1; |
266 |
wakaba |
1.7 |
## $Date: 2008/01/14 03:55:23 $ |