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