/[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 - (hide 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 wakaba 1.1 package Message::DOM::CSSRule;
2     use strict;
3 wakaba 1.8 our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\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 wakaba 1.8 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 wakaba 1.2 ${$_[3]}->{owner_rule} = $self;
125     Scalar::Util::weaken (${$_[3]}->{owner_rule});
126 wakaba 1.1 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 wakaba 1.8 my $self = bless \{media => \$_[1], css_rules => $_[2]}, $_[0];
154     require Message::DOM::MediaList;
155     bless $$self->{media}, 'Message::DOM::MediaList';
156 wakaba 1.1 for (@{$_[2]}) {
157 wakaba 1.2 ${$_}->{parent_rule} = $self;
158     Scalar::Util::weaken (${$_}->{parent_rule});
159 wakaba 1.1 }
160     return $self;
161     } # ____new
162    
163     ## |CSSRule| attributes
164    
165 wakaba 1.8 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 wakaba 1.1
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 wakaba 1.2 ${$_[2]}->{parent_rule} = $self;
195     Scalar::Util::weaken (${$_[2]}->{parent_rule});
196     return $self;
197 wakaba 1.1 } # ____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 wakaba 1.3 my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0];
216 wakaba 1.2 ${$_[2]}->{parent_rule} = $self;
217     Scalar::Util::weaken (${$_[2]}->{parent_rule});
218 wakaba 1.1 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 wakaba 1.3 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 wakaba 1.1
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 wakaba 1.5 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 wakaba 1.1
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 wakaba 1.8 ## $Date: 2008/01/14 05:53:44 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24