/[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.4 - (hide annotations) (download)
Sun Dec 23 11:20:08 2007 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +9 -3 lines
++ manakai/lib/Message/DOM/ChangeLog	23 Dec 2007 11:19:58 -0000
	* CSSRule.pm (@charset.css_text): Implemented.

2007-12-23  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package Message::DOM::CSSRule;
2     use strict;
3 wakaba 1.4 our $VERSION=do{my @r=(q$Revision: 1.3 $=~/\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     ## 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 wakaba 1.1
68     sub type ($) { Message::DOM::CSSRule::STYLE_RULE }
69    
70     ## |CSSStyleRule| attributes
71    
72 wakaba 1.3 sub selector_text ($;$) {
73     ## TODO: setter
74    
75     ## TODO: Browser-compatible serializer
76     require Whatpm::CSS::SelectorsSerializer;
77     return Whatpm::CSS::SelectorsSerializer->serialize_test
78     (${$_[0]}->{_selectors});
79     } # selector_text
80 wakaba 1.1
81     sub style ($) {
82     return ${$_[0]}->{style};
83     } # style
84    
85     package Message::DOM::CSSCharsetRule;
86     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSCharsetRule';
87    
88     sub ____new ($$) {
89     return bless \{encoding => $_[1]}, $_[0];
90     } # ____new
91    
92     ## |CSSRule| attributes
93    
94 wakaba 1.4 sub css_text ($;$) {
95     ## TODO: setter
96    
97     ## NOTE: It will be broken if |encoding| contains |"| or |\|, but this
98     ## is what browsers do.
99     return '@charset "'.${$_[0]}->{encoding}.'";';
100     } # css_text
101 wakaba 1.1
102     sub type ($) { Message::DOM::CSSRule::CHARSET_RULE }
103    
104     ## |CSSCharsetRule| attribute
105    
106     sub encoding ($) {
107     return ${$_[0]}->{encoding};
108     } # encoding
109    
110     package Message::DOM::CSSImportRule;
111     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSImportRule';
112    
113     sub ____new ($$$$) {
114     my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0];
115 wakaba 1.2 ${$_[3]}->{owner_rule} = $self;
116     Scalar::Util::weaken (${$_[3]}->{owner_rule});
117 wakaba 1.1 return $self;
118     } # ____new
119    
120     ## |CSSRule| attributes
121    
122     ## TODO: |css_text|
123    
124     sub type ($) { Message::DOM::CSSRule::IMPORT_RULE }
125    
126     ## |CSSImportRule| attributes
127    
128     sub href ($) {
129     return ${$_[0]}->{href};
130     } # href
131    
132     sub media ($) {
133     return ${$_[0]}->{media};
134     } # media
135    
136     sub style_sheet ($) {
137     return ${$_[0]}->{style_sheet};
138     } # style_sheet
139    
140     package Message::DOM::CSSMediaRule;
141     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule';
142    
143     sub ____new ($$$) {
144     my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0];
145     for (@{$_[2]}) {
146 wakaba 1.2 ${$_}->{parent_rule} = $self;
147     Scalar::Util::weaken (${$_}->{parent_rule});
148 wakaba 1.1 }
149     return $self;
150     } # ____new
151    
152     ## |CSSRule| attributes
153    
154     ## TODO: |css_text|
155    
156     sub type ($) { Message::DOM::CSSRule::MEDIA_RULE }
157    
158     ## |CSSMediaRule| attributes
159    
160     sub css_rules ($) {
161     require Message::DOM::CSSRuleList;
162     return bless \\($_[0]), 'Message::DOM::CSSRuleList';
163     } # css_rules
164    
165     sub media ($) {
166     return ${$_[0]}->{media};
167     } # media
168    
169     package Message::DOM::CSSFontFaceRule;
170     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSFontFaceRule';
171    
172     sub ____new ($$) {
173     my $self = bless \{style => $_[1]}, $_[0];
174 wakaba 1.2 ${$_[2]}->{parent_rule} = $self;
175     Scalar::Util::weaken (${$_[2]}->{parent_rule});
176     return $self;
177 wakaba 1.1 } # ____new
178    
179     ## |CSSRule| attributes
180    
181     ## TODO: |css_text|
182    
183     sub type ($) { Message::DOM::CSSRule::FONT_FACE_RULE }
184    
185     ## |CSSFontFaceRule| attribute
186    
187     sub style ($) {
188     return ${$_[0]}->{style};
189     } # style
190    
191     package Message::DOM::CSSPageRule;
192     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule';
193    
194     sub ____new ($$$) {
195 wakaba 1.3 my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0];
196 wakaba 1.2 ${$_[2]}->{parent_rule} = $self;
197     Scalar::Util::weaken (${$_[2]}->{parent_rule});
198 wakaba 1.1 return $self;
199     } # ____new
200    
201     ## |CSSRule| attributes
202    
203     ## TODO: |css_text|
204    
205     sub type ($) { Message::DOM::CSSRule::PAGE_RULE }
206    
207     ## |CSSPageRule| attributes
208    
209 wakaba 1.3 sub selector_text ($;$) {
210     ## TODO: setter
211    
212     ## TODO: Browser-compatible serializer
213     require Whatpm::CSS::SelectorsSerializer;
214     return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors});
215     } # selector_text
216 wakaba 1.1
217     sub style ($) {
218     return ${$_[0]}->{style};
219     } # style
220    
221     package Message::DOM::CSSNamespaceRule;
222     push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSNamespaceRule';
223    
224     sub ____new ($$$) {
225     return bless \{namespace_uri => $_[2], prefix => $_[1]}, $_[0];
226     } # ___new
227    
228     ## |CSSRule| attributes
229    
230     ## TODO: |css_text|
231    
232     sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE }
233    
234     ## |CSSNamespaceRule| attributes
235    
236     sub namespace_uri ($) {
237     return ${$_[0]}->{namespace_uri};
238     } # namespace_uri
239    
240     sub prefix ($) {
241     return ${$_[0]}->{prefix};
242     } # prefix
243    
244     package Message::IF::CSSRule;
245     package Message::IF::CSSStyleRule;
246     package Message::IF::CSSCharsetRule;
247     package Message::IF::CSSImportRule;
248     package Message::IF::CSSMediaRule;
249     package Message::IF::CSSFontFaceRule;
250     package Message::IF::CSSPageRule;
251    
252     1;
253 wakaba 1.4 ## $Date: 2007/12/23 08:18:59 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24