| 2 |
use strict; |
use strict; |
| 3 |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 |
push our @ISA, 'Message::IF::CSSRule'; |
push our @ISA, 'Message::IF::CSSRule'; |
| 5 |
|
require Scalar::Util; |
| 6 |
|
|
| 7 |
## |CSSRule| constants |
## |CSSRule| constants |
| 8 |
|
|
| 14 |
sub PAGE_RULE () { 6 } |
sub PAGE_RULE () { 6 } |
| 15 |
sub NAMESPACE_RULE () { 7 } |
sub NAMESPACE_RULE () { 7 } |
| 16 |
|
|
|
sub AUTOLOAD { |
|
|
my $method_name = our $AUTOLOAD; |
|
|
$method_name =~ s/.*:://; |
|
|
return if $method_name eq 'DESTROY'; |
|
|
|
|
|
if ({ |
|
|
## Read-only attributes (trivial accessors) |
|
|
parent_rule => 1, |
|
|
parent_style_sheet => 1, |
|
|
}->{$method_name}) { |
|
|
no strict 'refs'; |
|
|
eval qq{ |
|
|
sub $method_name (\$) { |
|
|
return \${\$_[0]}->{$method_name}; |
|
|
} |
|
|
}; |
|
|
goto &{ $AUTOLOAD }; |
|
|
} else { |
|
|
require Carp; |
|
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
|
|
} |
|
|
} # AUTOLOAD |
|
|
|
|
| 17 |
## |CSSRule| attributes |
## |CSSRule| attributes |
| 18 |
|
|
| 19 |
sub css_text ($) { |
sub css_text ($) { |
| 20 |
die "$0: ".(ref $self)."->css_text: Not implemented"; |
die "$0: ".(ref $_[0])."->css_text: Not implemented"; |
| 21 |
} # css_text |
} # css_text |
| 22 |
|
|
| 23 |
sub parent_rule ($); |
sub parent_rule ($) { |
| 24 |
|
return ${$_[0]}->{parent_rule}; |
| 25 |
sub parent_style_sheet ($); |
} # parent_rule |
| 26 |
|
|
| 27 |
|
sub parent_style_sheet ($) { |
| 28 |
|
if (${$_[0]}->{parent_style_sheet}) { |
| 29 |
|
return ${$_[0]}->{parent_style_sheet}; |
| 30 |
|
} elsif (${$_[0]}->{parent_rule}) { |
| 31 |
|
local $Error::Depth = $Error::Depth + 1; |
| 32 |
|
return ${$_[0]}->{parent_rule}->parent_style_sheet; |
| 33 |
|
} else { |
| 34 |
|
## NOTE: Not in the CSSOM ED: If the |CSSRule| object is not |
| 35 |
|
## yet associated to any CSS style sheet. Such object should not be |
| 36 |
|
## returned to applications - that is, the intention is that only |
| 37 |
|
## modules belonging to manakai may get |undef| from the |
| 38 |
|
## |parent_style_sheet| attribute during the construction of CSSOM. |
| 39 |
|
## Therefore, this is not counted as a manakai extension to CSSOM spec. |
| 40 |
|
return undef; |
| 41 |
|
} |
| 42 |
|
} # parent_style_sheet |
| 43 |
|
|
| 44 |
sub type ($) { |
sub type ($) { |
| 45 |
die "$0: ".(ref $self)."->type: Not implemented"; |
die "$0: ".(ref $_[0])."->type: Not implemented"; |
| 46 |
} # type |
} # type |
| 47 |
|
|
| 48 |
package Message::DOM::CSSStyleRule; |
package Message::DOM::CSSStyleRule; |
| 49 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSStyleRule'; |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSStyleRule'; |
| 50 |
|
|
| 51 |
sub ____new ($$$) { |
sub ____new ($$$) { |
| 52 |
my $self = bless \{_selector => $_[1], style => $_[2]}, $_[0]; |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
| 53 |
## TODO: style -> owner |
${$_[2]}->{parent_rule} = $self; |
| 54 |
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
| 55 |
return $self; |
return $self; |
| 56 |
} # ____new |
} # ____new |
| 57 |
|
|
| 58 |
## |CSSRule| attributes |
## |CSSRule| attributes |
| 59 |
|
|
| 60 |
## TODO: |css_text| |
sub css_text ($;$) { |
| 61 |
|
## TODO: setter |
| 62 |
|
|
| 63 |
|
## NOTE: Where and how white space characters are inserted are |
| 64 |
|
## intentionally changed from those in browsers so that properties are |
| 65 |
|
## more prettily printed. |
| 66 |
|
## See <http://suika.fam.cx/gate/2005/sw/cssText> for what browsers do. |
| 67 |
|
local $Error::Depth = $Error::Depth + 1; |
| 68 |
|
return $_[0]->selector_text . " {\n" . $_[0]->style->css_text . '}'; |
| 69 |
|
} # css_text |
| 70 |
|
|
| 71 |
sub type ($) { Message::DOM::CSSRule::STYLE_RULE } |
sub type ($) { Message::DOM::CSSRule::STYLE_RULE } |
| 72 |
|
|
| 73 |
## |CSSStyleRule| attributes |
## |CSSStyleRule| attributes |
| 74 |
|
|
| 75 |
## TODO: |selector_text| |
sub selector_text ($;$) { |
| 76 |
|
## TODO: setter |
| 77 |
|
|
| 78 |
|
## TODO: Browser-compatible serializer |
| 79 |
|
## TODO: This code does not work for cases where default namespace |
| 80 |
|
## has no namespace prefix declared. |
| 81 |
|
my $self = $_[0]; |
| 82 |
|
require Whatpm::CSS::SelectorsSerializer; |
| 83 |
|
return Whatpm::CSS::SelectorsSerializer->serialize_selector_text |
| 84 |
|
($$self->{_selectors}, ${$self->parent_style_sheet}->{_nsmap}); |
| 85 |
|
} # selector_text |
| 86 |
|
|
| 87 |
sub style ($) { |
sub style ($) { |
| 88 |
return ${$_[0]}->{style}; |
return ${$_[0]}->{style}; |
| 97 |
|
|
| 98 |
## |CSSRule| attributes |
## |CSSRule| attributes |
| 99 |
|
|
| 100 |
## TODO: |css_text| |
sub css_text ($;$) { |
| 101 |
|
## TODO: setter |
| 102 |
|
|
| 103 |
|
## NOTE: It will be broken if |encoding| contains |"| or |\|, but this |
| 104 |
|
## is what browsers do. |
| 105 |
|
return '@charset "'.${$_[0]}->{encoding}.'";'; |
| 106 |
|
} # css_text |
| 107 |
|
|
| 108 |
sub type ($) { Message::DOM::CSSRule::CHARSET_RULE } |
sub type ($) { Message::DOM::CSSRule::CHARSET_RULE } |
| 109 |
|
|
| 118 |
|
|
| 119 |
sub ____new ($$$$) { |
sub ____new ($$$$) { |
| 120 |
my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0]; |
my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0]; |
| 121 |
## TODO: $_[3] owner_style_sheet |
${$_[3]}->{owner_rule} = $self; |
| 122 |
|
Scalar::Util::weaken (${$_[3]}->{owner_rule}); |
| 123 |
return $self; |
return $self; |
| 124 |
} # ____new |
} # ____new |
| 125 |
|
|
| 149 |
sub ____new ($$$) { |
sub ____new ($$$) { |
| 150 |
my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0]; |
my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0]; |
| 151 |
for (@{$_[2]}) { |
for (@{$_[2]}) { |
| 152 |
## TODO: owner_rule |
${$_}->{parent_rule} = $self; |
| 153 |
|
Scalar::Util::weaken (${$_}->{parent_rule}); |
| 154 |
} |
} |
| 155 |
return $self; |
return $self; |
| 156 |
} # ____new |
} # ____new |
| 177 |
|
|
| 178 |
sub ____new ($$) { |
sub ____new ($$) { |
| 179 |
my $self = bless \{style => $_[1]}, $_[0]; |
my $self = bless \{style => $_[1]}, $_[0]; |
| 180 |
|
${$_[2]}->{parent_rule} = $self; |
| 181 |
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
| 182 |
|
return $self; |
| 183 |
} # ____new |
} # ____new |
| 184 |
|
|
| 185 |
## |CSSRule| attributes |
## |CSSRule| attributes |
| 198 |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule'; |
push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule'; |
| 199 |
|
|
| 200 |
sub ____new ($$$) { |
sub ____new ($$$) { |
| 201 |
my $self = bless \{_selector => $_[1], style => $_[2]}, $_[0]; |
my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0]; |
| 202 |
## TODO: style -> owner |
${$_[2]}->{parent_rule} = $self; |
| 203 |
|
Scalar::Util::weaken (${$_[2]}->{parent_rule}); |
| 204 |
return $self; |
return $self; |
| 205 |
} # ____new |
} # ____new |
| 206 |
|
|
| 212 |
|
|
| 213 |
## |CSSPageRule| attributes |
## |CSSPageRule| attributes |
| 214 |
|
|
| 215 |
## TODO: |selector_text| |
sub selector_text ($;$) { |
| 216 |
|
## TODO: setter |
| 217 |
|
|
| 218 |
|
## TODO: Browser-compatible serializer |
| 219 |
|
require Whatpm::CSS::SelectorsSerializer; |
| 220 |
|
return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors}); |
| 221 |
|
} # selector_text |
| 222 |
|
|
| 223 |
sub style ($) { |
sub style ($) { |
| 224 |
return ${$_[0]}->{style}; |
return ${$_[0]}->{style}; |
| 233 |
|
|
| 234 |
## |CSSRule| attributes |
## |CSSRule| attributes |
| 235 |
|
|
| 236 |
## TODO: |css_text| |
sub css_text ($;$) { |
| 237 |
|
## TODO: Setter |
| 238 |
|
|
| 239 |
|
## NOTE: Sometimes ugly, but this is what Firefox does. |
| 240 |
|
my $prefix = ${$_[0]}->{prefix}; |
| 241 |
|
return '@namespace '.($prefix ne '' ? $prefix.' ' : ''). |
| 242 |
|
'url('.${$_[0]}->{namespace_uri}.');'; |
| 243 |
|
} # css_text |
| 244 |
|
|
| 245 |
sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE } |
sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE } |
| 246 |
|
|