/[suikacvs]/messaging/manakai/lib/Message/DOM/CSSRule.pm
Suika

Diff of /messaging/manakai/lib/Message/DOM/CSSRule.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sat Dec 22 06:57:46 2007 UTC revision 1.9 by wakaba, Mon Feb 11 00:32:53 2008 UTC
# Line 17  sub NAMESPACE_RULE () { 7 } Line 17  sub NAMESPACE_RULE () { 7 }
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 ($) {
# Line 42  sub parent_style_sheet ($) { Line 42  sub parent_style_sheet ($) {
42  } # parent_style_sheet  } # 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    ${$_[2]}->{parent_rule} = $self;    ${$_[2]}->{parent_rule} = $self;
54    Scalar::Util::weaken (${$_[2]}->{parent_rule});    Scalar::Util::weaken (${$_[2]}->{parent_rule});
55    return $self;    return $self;
# Line 57  sub ____new ($$$) { Line 57  sub ____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};
# Line 78  sub ____new ($$) { Line 97  sub ____new ($$) {
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    
# Line 91  sub encoding ($) { Line 116  sub encoding ($) {
116  package Message::DOM::CSSImportRule;  package Message::DOM::CSSImportRule;
117  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSImportRule';  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSImportRule';
118    
119  sub ____new ($$$$) {  sub ____new ($$$$$) {
120    my $self = bless \{href => $_[1], media => $_[2], style_sheet => $_[3]}, $_[0];    my $self = bless \{href => $_[1],
121    ${$_[3]}->{owner_rule} = $self;                       base_uri => $_[2], ## Ref to base URI
122    Scalar::Util::weaken (${$_[3]}->{owner_rule});                       media => \$_[3],
123                         style_sheet => $_[4]}, $_[0];
124      require Message::DOM::MediaList;
125      bless $$self->{media}, 'Message::DOM::MediaList';
126      ${$_[4]}->{owner_rule} = $self;
127      Scalar::Util::weaken (${$_[4]}->{owner_rule});
128    return $self;    return $self;
129  } # ____new  } # ____new
130    
131  ## |CSSRule| attributes  ## |CSSRule| attributes
132    
133  ## TODO: |css_text|  sub css_text ($;$) {
134      ## TODO: setter
135    
136      my $self = shift;
137      my $r = '@import url(' . $self->href . ')';
138      my $media = ''.$self->media;
139      if ($media) {
140        $r .= ' ' . $media;
141      }
142      $r .= ';';
143      return $r;
144    } # css_text
145    
146  sub type ($) { Message::DOM::CSSRule::IMPORT_RULE }  sub type ($) { Message::DOM::CSSRule::IMPORT_RULE }
147    
# Line 122  package Message::DOM::CSSMediaRule; Line 163  package Message::DOM::CSSMediaRule;
163  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule';  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSMediaRule';
164    
165  sub ____new ($$$) {  sub ____new ($$$) {
166    my $self = bless \{media => $_[1], css_rules => $_[2]}, $_[0];    my $self = bless \{media => \$_[1], css_rules => $_[2]}, $_[0];
167      require Message::DOM::MediaList;
168      bless $$self->{media}, 'Message::DOM::MediaList';
169    for (@{$_[2]}) {    for (@{$_[2]}) {
170      ${$_}->{parent_rule} = $self;      ${$_}->{parent_rule} = $self;
171      Scalar::Util::weaken (${$_}->{parent_rule});      Scalar::Util::weaken (${$_}->{parent_rule});
# Line 132  sub ____new ($$$) { Line 175  sub ____new ($$$) {
175    
176  ## |CSSRule| attributes  ## |CSSRule| attributes
177    
178  ## TODO: |css_text|  sub css_text ($;$) {
179      ## TODO: setter
180      my $v = '@media ' . $_[0]->media . " {\n";
181      for (@{${$_[0]}->{css_rules}}) {
182        $v .= $_->css_text . "\n";
183        ## BUG: Browsers do indent.
184      }
185      $v .= "}";
186      return $v;
187    } # css_text
188    
189  sub type ($) { Message::DOM::CSSRule::MEDIA_RULE }  sub type ($) { Message::DOM::CSSRule::MEDIA_RULE }
190    
# Line 173  package Message::DOM::CSSPageRule; Line 225  package Message::DOM::CSSPageRule;
225  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule';  push our @ISA, 'Message::DOM::CSSRule', 'Message::IF::CSSPageRule';
226    
227  sub ____new ($$$) {  sub ____new ($$$) {
228    my $self = bless \{_selector => $_[1], style => $_[2]}, $_[0];    my $self = bless \{_selectors => $_[1], style => $_[2]}, $_[0];
229    ${$_[2]}->{parent_rule} = $self;    ${$_[2]}->{parent_rule} = $self;
230    Scalar::Util::weaken (${$_[2]}->{parent_rule});    Scalar::Util::weaken (${$_[2]}->{parent_rule});
231    return $self;    return $self;
# Line 187  sub type ($) { Message::DOM::CSSRule::PA Line 239  sub type ($) { Message::DOM::CSSRule::PA
239    
240  ## |CSSPageRule| attributes  ## |CSSPageRule| attributes
241    
242  ## TODO: |selector_text|  sub selector_text ($;$) {
243      ## TODO: setter
244    
245      ## TODO: Browser-compatible serializer
246      require Whatpm::CSS::SelectorsSerializer;
247      return Whatpm::CSS::SelectorsSerializer->serialize_test (${$_[0]}->{_selectors});
248    } # selector_text
249    
250  sub style ($) {  sub style ($) {
251    return ${$_[0]}->{style};    return ${$_[0]}->{style};
# Line 202  sub ____new ($$$) { Line 260  sub ____new ($$$) {
260    
261  ## |CSSRule| attributes  ## |CSSRule| attributes
262    
263  ## TODO: |css_text|  sub css_text ($;$) {
264      ## TODO: Setter
265    
266      ## NOTE: Sometimes ugly, but this is what Firefox does.
267      my $prefix = ${$_[0]}->{prefix};
268      return '@namespace '.($prefix ne '' ? $prefix.' ' : '').
269          'url('.${$_[0]}->{namespace_uri}.');';
270    } # css_text
271    
272  sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE }  sub type ($) { Message::DOM::CSSRule::NAMESPACE_RULE }
273    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.9

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24