/[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.7 - (show annotations) (download)
Mon Jan 14 05:53:45 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +4 -2 lines
++ manakai/lib/Message/DOM/ChangeLog	14 Jan 2008 05:53:34 -0000
	* CSSRule.pm (css_text): Trailing newline character is removed
	to avoid double empty lines in CSSStyleSheet->css_text.
	(selector_text): Namespace support is fixed.

	* CSSStyleSheet.pm (___new): Now it accepts |_nsmap| option.

2008-01-14  Wakaba  <wakaba@suika.fam.cx>

1 package Message::DOM::CSSStyleSheet;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.6 $=~/\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 sub owner_rule ($);
115
116 ## |CSSStyleSheet| methods
117
118 sub delete_rule ($$) {
119 if ($_[1] < 0 or $_[1] > @{${$_[0]}->{css_rules}}) {
120 report Message::DOM::DOMException
121 -object => $_[0],
122 -type => 'INDEX_SIZE_ERR',
123 -subtype => 'INDEX_OUT_OF_BOUND_ERR';
124 } else {
125 my $rule = ${$_[0]}->{css_rules}->[$_[1]];
126 delete $rule->{parent_rule};
127 delete ${$_[0]}->{css_rules}->[$_[1]];
128 }
129 } # delete_rule
130
131 ## TODO: insert_rule
132
133 ## TODO: Documentation
134 sub manakai_is_default_namespace ($$) {
135 my $uri = $_[1];
136 for my $rule (@{$_[0]->css_rules}) {
137 next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE
138 return 0 if $rule->type != 7; # NAMESPACE_RULE
139
140 ## TODO: Can we insert NAMESPACE_RULE after other kinds of rules
141 ## by insert_rule?
142
143 if ($uri eq $rule->namespace_uri) {
144 return 1 if $rule->prefix eq '';
145 }
146 }
147
148 return 0;
149 } # manakai_is_default_namespace
150
151 ## TODO: Documentation
152 sub manakai_lookup_namespace_prefix ($$) {
153 my $uri = $_[1];
154 for my $rule (@{$_[0]->css_rules}) {
155 next if $rule->type == 2 or $rule->type == 3; # CHARSET_RULE or IMPORT_RULE
156 return undef if $rule->type != 7; # NAMESPACE_RULE
157
158 ## TODO: Can we insert NAMESPACE_RULE after other kinds of rules
159 ## by insert_rule?
160
161 if ($uri eq $rule->namespace_uri) {
162 my $prefix = $rule->prefix;
163 return $prefix if $prefix ne '';
164 }
165 }
166
167 return undef;
168 } # manakai_lookup_namespace_prefix
169
170 package Message::IF::StyleSheet;
171 package Message::IF::CSSStyleSheet;
172
173 1;
174 ## $Date: 2008/01/01 09:09:16 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24