1 |
wakaba |
1.1 |
package Message::DOM::CSSStyleSheet; |
2 |
|
|
use strict; |
3 |
wakaba |
1.5 |
our $VERSION=do{my @r=(q$Revision: 1.4 $=~/\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 |
|
|
sub disabled ($;$) { |
47 |
|
|
if (@_ > 1) { |
48 |
|
|
if ($_[1]) { |
49 |
|
|
${$_[0]}->{disabled} = 1; |
50 |
|
|
} else { |
51 |
|
|
delete ${$_[0]}->{disabled}; |
52 |
|
|
} |
53 |
|
|
} |
54 |
|
|
return ${$_[0]}->{disabled}; |
55 |
|
|
} # disabled |
56 |
|
|
|
57 |
|
|
sub href ($); |
58 |
|
|
|
59 |
wakaba |
1.2 |
sub media ($;$) { |
60 |
|
|
if (@_ > 1) { |
61 |
|
|
local $Error::Depth = $Error::Depth + 1; |
62 |
|
|
${+shift}->{media}->media_text (@_); |
63 |
|
|
} |
64 |
|
|
return ${$_[0]}->{media}; |
65 |
|
|
} # media |
66 |
wakaba |
1.1 |
|
67 |
|
|
sub owner_node ($); |
68 |
|
|
|
69 |
|
|
sub parent_style_sheet ($); |
70 |
|
|
|
71 |
|
|
sub title ($;$) { |
72 |
|
|
if (@_ > 1) { |
73 |
|
|
if (defined $_[1]) { |
74 |
|
|
${$_[0]}->{title} = ''.$_[1]; |
75 |
|
|
} else { |
76 |
|
|
delete ${$_[0]}->{title}; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
return ${$_[0]}->{title}; |
80 |
|
|
} # title |
81 |
|
|
|
82 |
|
|
sub type ($); |
83 |
|
|
|
84 |
|
|
## |CSSStyleSheet| attributes |
85 |
|
|
|
86 |
|
|
sub css_rules ($) { |
87 |
|
|
require Message::DOM::CSSRuleList; |
88 |
|
|
return bless \\($_[0]), 'Message::DOM::CSSRuleList'; |
89 |
|
|
} # css_rules |
90 |
|
|
|
91 |
wakaba |
1.3 |
## NOTE: This is a manakai extension. |
92 |
|
|
sub css_text ($;$) { |
93 |
|
|
## TODO: setter |
94 |
|
|
|
95 |
|
|
my $r = ''; |
96 |
|
|
local $Error::Depth = $Error::Depth + 1; |
97 |
|
|
for my $rule (@{$_[0]->css_rules}) { |
98 |
wakaba |
1.4 |
$r .= $rule->css_text . "\n"; ## TODO: \x0D\x0A? \x0A? |
99 |
wakaba |
1.3 |
} |
100 |
|
|
return $r; |
101 |
|
|
} # css_text |
102 |
|
|
|
103 |
wakaba |
1.1 |
sub owner_rule ($); |
104 |
|
|
|
105 |
|
|
## |CSSStyleSheet| methods |
106 |
|
|
|
107 |
wakaba |
1.2 |
sub delete_rule ($$) { |
108 |
|
|
if ($_[1] < 0 or $_[1] > @{${$_[0]}->{css_rules}}) { |
109 |
|
|
report Message::DOM::DOMException |
110 |
|
|
-object => $_[0], |
111 |
|
|
-type => 'INDEX_SIZE_ERR', |
112 |
|
|
-subtype => 'INDEX_OUT_OF_BOUND_ERR'; |
113 |
|
|
} else { |
114 |
|
|
my $rule = ${$_[0]}->{css_rules}->[$_[1]]; |
115 |
|
|
delete $rule->{parent_rule}; |
116 |
|
|
delete ${$_[0]}->{css_rules}->[$_[1]]; |
117 |
|
|
} |
118 |
|
|
} # delete_rule |
119 |
wakaba |
1.1 |
|
120 |
|
|
## TODO: insert_rule |
121 |
|
|
|
122 |
wakaba |
1.5 |
## TODO: Documentation |
123 |
|
|
sub manakai_is_default_namespace ($$) { |
124 |
|
|
my $uri = $_[1]; |
125 |
|
|
for my $rule (@{$_[0]->css_rules}) { |
126 |
|
|
next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE |
127 |
|
|
return 0 if $rule->type != 7; # NAMESPACE_RULE |
128 |
|
|
|
129 |
|
|
## TODO: Can we insert NAMESPACE_RULE after other kinds of rules |
130 |
|
|
## by insert_rule? |
131 |
|
|
|
132 |
|
|
if ($uri eq $rule->namespace_uri) { |
133 |
|
|
return 1 if $rule->prefix eq ''; |
134 |
|
|
} |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
return 0; |
138 |
|
|
} # manakai_is_default_namespace |
139 |
|
|
|
140 |
|
|
## TODO: Documentation |
141 |
|
|
sub manakai_lookup_namespace_prefix ($$) { |
142 |
|
|
my $uri = $_[1]; |
143 |
|
|
for my $rule (@{$_[0]->css_rules}) { |
144 |
|
|
next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE |
145 |
|
|
return undef if $rule->type != 7; # NAMESPACE_RULE |
146 |
|
|
|
147 |
|
|
## TODO: Can we insert NAMESPACE_RULE after other kinds of rules |
148 |
|
|
## by insert_rule? |
149 |
|
|
|
150 |
|
|
if ($uri eq $rule->namespace_uri) { |
151 |
|
|
my $prefix = $rule->prefix; |
152 |
|
|
return $prefix if $prefix ne ''; |
153 |
|
|
} |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
return undef; |
157 |
|
|
} # manakai_lookup_namespace_prefix |
158 |
|
|
|
159 |
wakaba |
1.1 |
package Message::IF::StyleSheet; |
160 |
|
|
package Message::IF::CSSStyleSheet; |
161 |
|
|
|
162 |
|
|
1; |
163 |
wakaba |
1.5 |
## $Date: 2007/12/23 11:20:08 $ |