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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Sun Feb 10 04:10:36 2008 UTC (16 years, 9 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +14 -2 lines
Error occurred while calculating annotation data.
++ manakai/lib/Message/DOM/ChangeLog	10 Feb 2008 04:10:31 -0000
2008-02-10  Wakaba  <wakaba@suika.fam.cx>

	* CSSStyleSheet.pm (manakai_input_encoding): New.

1 package Message::DOM::CSSStyleSheet;
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::CSSStyleSheet';
5 require Message::DOM::DOMException;
6 require Scalar::Util;
7
8 sub ____new ($;%) {
9 my $class = shift;
10 my $self = bless \{@_}, $class;
11 for (@{$$self->{css_rules}}) {
12 ${$_}->{parent_style_sheet} = $self;
13 Scalar::Util::weaken (${$_}->{parent_style_sheet});
14 }
15 # $self->{_parser} : Whatpm::CSS::Parser
16 # $self->{_nsmap} : $nsmap (see Whatpm::CSS::Parser)
17 return $self;
18 } # ____new
19
20 sub AUTOLOAD {
21 my $method_name = our $AUTOLOAD;
22 $method_name =~ s/.*:://;
23 return if $method_name eq 'DESTROY';
24
25 if ({
26 ## Read-only attributes (trivial accessors)
27 href => 1,
28 owner_node => 1,
29 owner_rule => 1,
30 parent_style_sheet => 1,
31 type => 1,
32 }->{$method_name}) {
33 no strict 'refs';
34 eval qq{
35 sub $method_name (\$) {
36 return \${\$_[0]}->{$method_name};
37 }
38 };
39 goto &{ $AUTOLOAD };
40 } else {
41 require Carp;
42 Carp::croak (qq<Can't locate method "$AUTOLOAD">);
43 }
44 } # AUTOLOAD
45
46 ## |StyleSheet| attributes
47
48 ## TODO: documentation
49 sub manakai_base_uri ($) {
50 if (defined ${$_[0]}->{manakai_base_uri}) {
51 return ${$_[0]}->{manakai_base_uri};
52 } else {
53 return ${$_[0]}->{href}; ## NOTE: Might be |undef|.
54 }
55 } # manakai_base_uri
56
57 sub disabled ($;$) {
58 if (@_ > 1) {
59 if ($_[1]) {
60 ${$_[0]}->{disabled} = 1;
61 } else {
62 delete ${$_[0]}->{disabled};
63 }
64 }
65 return ${$_[0]}->{disabled};
66 } # disabled
67
68 sub href ($);
69
70 sub media ($;$) {
71 if (@_ > 1) {
72 local $Error::Depth = $Error::Depth + 1;
73 ${+shift}->{media}->media_text (@_);
74 }
75 return ${$_[0]}->{media};
76 } # media
77
78 sub owner_node ($);
79
80 sub parent_style_sheet ($);
81
82 sub title ($;$) {
83 if (@_ > 1) {
84 if (defined $_[1]) {
85 ${$_[0]}->{title} = ''.$_[1];
86 } else {
87 delete ${$_[0]}->{title};
88 }
89 }
90 return ${$_[0]}->{title};
91 } # title
92
93 sub type ($);
94
95 ## |CSSStyleSheet| attributes
96
97 sub css_rules ($) {
98 require Message::DOM::CSSRuleList;
99 return bless \\($_[0]), 'Message::DOM::CSSRuleList';
100 } # css_rules
101
102 ## NOTE: This is a manakai extension.
103 sub css_text ($;$) {
104 ## TODO: setter
105
106 my $r = '';
107 local $Error::Depth = $Error::Depth + 1;
108 for my $rule (@{$_[0]->css_rules}) {
109 $r .= $rule->css_text . "\n"; ## TODO: \x0D\x0A? \x0A?
110 }
111 return $r;
112 } # css_text
113
114 ## TODO: documentation
115 sub manakai_input_encoding ($;$) {
116 if (@_ > 1) {
117 if (defined $_[1]) {
118 ${$_[0]}->{input_encoding} = ''.$_[1];
119 } else {
120 delete ${$_[0]}->{input_encoding};
121 }
122 }
123 return ${$_[0]}->{input_encoding};
124 } # manakai_input_encoding
125
126 sub owner_rule ($);
127
128 ## |CSSStyleSheet| methods
129
130 sub delete_rule ($$) {
131 if ($_[1] < 0 or $_[1] > @{${$_[0]}->{css_rules}}) {
132 report Message::DOM::DOMException
133 -object => $_[0],
134 -type => 'INDEX_SIZE_ERR',
135 -subtype => 'INDEX_OUT_OF_BOUND_ERR';
136 } else {
137 my $rule = ${$_[0]}->{css_rules}->[$_[1]];
138 delete $rule->{parent_rule};
139 delete ${$_[0]}->{css_rules}->[$_[1]];
140 }
141 } # delete_rule
142
143 ## TODO: insert_rule
144
145 ## TODO: Documentation
146 sub manakai_is_default_namespace ($$) {
147 my $uri = $_[1];
148 for my $rule (@{$_[0]->css_rules}) {
149 next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE
150 return 0 if $rule->type != 7; # NAMESPACE_RULE
151
152 ## TODO: Can we insert NAMESPACE_RULE after other kinds of rules
153 ## by insert_rule?
154
155 if ($uri eq $rule->namespace_uri) {
156 return 1 if $rule->prefix eq '';
157 }
158 }
159
160 return 0;
161 } # manakai_is_default_namespace
162
163 ## TODO: Documentation
164 sub manakai_lookup_namespace_prefix ($$) {
165 my $uri = $_[1];
166 for my $rule (@{$_[0]->css_rules}) {
167 next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE
168 return undef if $rule->type != 7; # NAMESPACE_RULE
169
170 ## TODO: Can we insert NAMESPACE_RULE after other kinds of rules
171 ## by insert_rule?
172
173 if ($uri eq $rule->namespace_uri) {
174 my $prefix = $rule->prefix;
175 return $prefix if $prefix ne '';
176 }
177 }
178
179 return undef;
180 } # manakai_lookup_namespace_prefix
181
182 package Message::IF::StyleSheet;
183 package Message::IF::CSSStyleSheet;
184
185 1;
186 ## $Date: 2008/01/14 05:53:45 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24