1 |
package Message::DOM::CSSStyleSheet; |
2 |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision: 1.2 $=~/\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 |
return $self; |
16 |
} # ____new |
17 |
|
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 |
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 |
|
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 |
## 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 |
$r .= $rule->css_text; |
99 |
} |
100 |
return $r; |
101 |
} # css_text |
102 |
|
103 |
sub owner_rule ($); |
104 |
|
105 |
## |CSSStyleSheet| methods |
106 |
|
107 |
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 |
|
120 |
## TODO: insert_rule |
121 |
|
122 |
package Message::IF::StyleSheet; |
123 |
package Message::IF::CSSStyleSheet; |
124 |
|
125 |
1; |
126 |
## $Date: 2007/12/22 06:57:46 $ |