/[suikacvs]/messaging/manakai/lib/Message/DOM/CSSRule.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/CSSRule.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Fri Feb 8 15:08:04 2008 UTC (16 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +19 -5 lines
++ manakai/lib/Message/DOM/ChangeLog	8 Feb 2008 15:08:01 -0000
2008-02-08  Wakaba  <wakaba@suika.fam.cx>

	* CSSRule.pm (@media, @import ____new): Bless media object
	with the appropriate class.
	(@media css_text): Getter implemented.

	* MediaList.pm (media_text): Getter implemented.

1 package Message::DOM::CSSRule;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\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 ## 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 local $Error::Depth = $Error::Depth + 1;
68 return $_[0]->selector_text . " {\n" . $_[0]->style->css_text . '}';
69 } # css_text
70
71 sub type ($) { Message::DOM::CSSRule::STYLE_RULE }
72
73 ## |CSSStyleRule| attributes
74
75 sub selector_text ($;$) {
76 ## TODO: setter
77
78 ## TODO: Browser-compatible serializer
79 ## TODO: This code does not work for cases where default namespace
80 ## has no namespace prefix declared.
81 my $self = $_[0];
82 require Whatpm::CSS::SelectorsSerializer;
83 return Whatpm::CSS::SelectorsSerializer->serialize_selector_text
84 ($$self->{_selectors}, ${$self->parent_style_sheet}->{_nsmap});
85 } # selector_text
86
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 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
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],
121 style_sheet => $_[3]}, $_[0];
122 require Message::DOM::MediaList;
123 bless $$self->{media}, 'Message::DOM::MediaList';
124 ${$_[3]}->{owner_rule} = $self;
125 Scalar::Util::weaken (${$_[3]}->{owner_rule});
126 return $self;
127 } # ____new
128
129 ## |CSSRule| attributes
130
131 ## TODO: |css_text|
132
133 sub type ($) { Message::DOM::CSSRule::IMPORT_RULE }
134
135 ## |CSSImportRule| attributes
136
137 sub href ($) {
138 return ${$_[0]}->{href};
139 } # href
140
141 sub media ($) {
142 return ${$_[0]}->{media};
143 } # media
144
145 sub style_sheet ($) {
146 return ${$_[0]}->{style_sheet};
147 } # style_sheet
148
149 package Message::DOM::CSSMediaRule;
150 push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule';
151
152 sub ____new ($$$) {
153 my $self = bless \{media => \$_[1], css_rules => $_[2]}, $_[0];
154 require Message::DOM::MediaList;
155 bless $$self->{media}, 'Message::DOM::MediaList';
156 for (@{$_[2]}) {
157 ${$_}->{parent_rule} = $self;
158 Scalar::Util::weaken (${$_}->{parent_rule});
159 }
160 return $self;
161 } # ____new
162
163 ## |CSSRule| attributes
164
165 sub css_text ($;$) {
166 ## TODO: setter
167 my $v = '@media ' . $_[0]->media . " {\n";
168 for (@{${$_[0]}->{css_rules}}) {
169 $v .= $_->css_text . "\n";
170 ## BUG: Browsers do indent.
171 }
172 $v .= "}";
173 return $v;
174 } # css_text
175
176 sub type ($) { Message::DOM::CSSRule::MEDIA_RULE }
177
178 ## |CSSMediaRule| attributes
179
180 sub css_rules ($) {
181 require Message::DOM::CSSRuleList;
182 return bless \\($_[0]), 'Message::DOM::CSSRuleList';
183 } # css_rules
184
185 sub media ($) {
186 return ${$_[0]}->{media};
187 } # media
188
189 package Message::DOM::CSSFontFaceRule;
190 push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSFontFaceRule';
191
192 sub ____new ($$) {
193 my $self = bless \{style => $_[1]}, $_[0];
194 ${$_[2]}->{parent_rule} = $self;
195 Scalar::Util::weaken (${$_[2]}->{parent_rule});
196 return $self;
197 } # ____new
198
199 ## |CSSRule| attributes
200
201 ## TODO: |css_text|
202
203 sub type ($) { Message::DOM::CSSRule::FONT_FACE_RULE }
204
205 ## |CSSFontFaceRule| attribute
206
207 sub style ($) {
208 return ${$_[0]}->{style};
209 } # style
210
211 package Message::DOM::CSSPageRule;
212 push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule';
213
214 sub ____new ($$$) {
215 my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0];
216 ${$_[2]}->{parent_rule} = $self;
217 Scalar::Util::weaken (${$_[2]}->{parent_rule});
218 return $self;
219 } # ____new
220
221 ## |CSSRule| attributes
222
223 ## TODO: |css_text|
224
225 sub type ($) { Message::DOM::CSSRule::PAGE_RULE }
226
227 ## |CSSPageRule| attributes
228
229 sub selector_text ($;$) {
230 ## TODO: setter
231
232 ## TODO: Browser-compatible serializer
233 require Whatpm::CSS::SelectorsSerializer;
234 return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors});
235 } # selector_text
236
237 sub style ($) {
238 return ${$_[0]}->{style};
239 } # style
240
241 package Message::DOM::CSSNamespaceRule;
242 push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSNamespaceRule';
243
244 sub ____new ($$$) {
245 return bless \{namespace_uri => $_[2], prefix => $_[1]}, $_[0];
246 } # ___new
247
248 ## |CSSRule| attributes
249
250 sub css_text ($;$) {
251 ## TODO: Setter
252
253 ## NOTE: Sometimes ugly, but this is what Firefox does.
254 my $prefix = ${$_[0]}->{prefix};
255 return '@namespace '.($prefix ne '' ? $prefix.' ' : '').
256 'url('.${$_[0]}->{namespace_uri}.');';
257 } # css_text
258
259 sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE }
260
261 ## |CSSNamespaceRule| attributes
262
263 sub namespace_uri ($) {
264 return ${$_[0]}->{namespace_uri};
265 } # namespace_uri
266
267 sub prefix ($) {
268 return ${$_[0]}->{prefix};
269 } # prefix
270
271 package Message::IF::CSSRule;
272 package Message::IF::CSSStyleRule;
273 package Message::IF::CSSCharsetRule;
274 package Message::IF::CSSImportRule;
275 package Message::IF::CSSMediaRule;
276 package Message::IF::CSSFontFaceRule;
277 package Message::IF::CSSPageRule;
278
279 1;
280 ## $Date: 2008/01/14 05:53:44 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24