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

Contents of /messaging/manakai/lib/Message/DOM/CSSStyleDeclaration.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Sun Jan 13 06:37:44 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +3 -2 lines
++ manakai/lib/Message/DOM/ChangeLog	13 Jan 2008 06:35:37 -0000
2008-01-13  Wakaba  <wakaba@suika.fam.cx>

	* Window.pm: New Perl module.

	* Document.pm (default_view): Implemented.

	* Element.pm (current_style): Implemented.

1 wakaba 1.1 package Message::DOM::CSSStyleDeclaration;
2     use strict;
3 wakaba 1.8 our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1 push our @ISA, 'Message::IF::CSSStyleDeclaration';
5    
6     sub ____new ($) {
7     return bless \{}, $_[0];
8     } # ____new
9    
10 wakaba 1.3 sub AUTOLOAD {
11     my $method_name = our $AUTOLOAD;
12     $method_name =~ s/.*:://;
13     return if $method_name eq 'DESTROY';
14    
15     require Whatpm::CSS::Parser;
16     my $prop_def = $Whatpm::CSS::Parser::Attr->{$method_name};
17    
18     if ($prop_def) {
19     no strict 'refs';
20     *{ $method_name } = sub {
21     ## TODO: setter
22    
23     my $self = $_[0];
24     my $value = $$self->{$prop_def->{key}};
25     if ($value) {
26     return $prop_def->{serialize}->($self, $prop_def->{css}, $value->[0]);
27     } else {
28     return undef;
29     }
30     ## TODO: null? ""? ... if not set?
31 wakaba 1.8 ## ISSUE: If one of shorthand component properties is !important?
32 wakaba 1.3 };
33     goto &{ $AUTOLOAD };
34     } else {
35     require Carp;
36     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
37     }
38     } # AUTOLOAD
39    
40 wakaba 1.1 ## |CSSStyleDeclaration| attributes
41    
42 wakaba 1.2 sub css_text ($;$) {
43 wakaba 1.3 ## TODO: setter
44    
45     require Whatpm::CSS::Parser;
46     my $self = $_[0];
47     my $r = '';
48 wakaba 1.7 my %serialized;
49 wakaba 1.3 for (grep {$$self->{$_}} keys %$$self) {
50     my $prop_def = $Whatpm::CSS::Parser::Key->{$_};
51     next unless $prop_def;
52 wakaba 1.7
53     if ($prop_def->{serialize_multiple}) {
54     unless ($serialized{$prop_def->{serialize_multiple}}) {
55     $serialized{$prop_def->{serialize_multiple}} = 1;
56     my $v = $prop_def->{serialize_multiple}->($self);
57     for my $prop_name (sort {$a cmp $b} keys %$v) {
58     $r .= ' ' . $prop_name . ': ' . $v->{$prop_name} . ";\n"
59     }
60     }
61     } else {
62     my $value = $$self->{$_};
63     my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $value->[0]);
64     if (defined $s) {
65     $r .= ' ' . $prop_def->{css} . ': ' . $s;
66     $r .= ' !' . $value->[1] if defined $value->[1];
67     $r .= ";\n";
68     }
69 wakaba 1.3 }
70     }
71     ## TODO: shorthands
72     return $r;
73 wakaba 1.2 } # css_text
74    
75 wakaba 1.1 sub parent_rule ($) {
76     return ${$_[0]}->{parent_rule};
77     } # parent_rule
78    
79 wakaba 1.7 ## |CSSStyleDeclaration| methods
80    
81     sub get_property_priority ($$) {
82     my $prop_name = ''.$_[1];
83    
84     require Whatpm::CSS::Parser;
85     my $prop_def = $Whatpm::CSS::Parser::Prop->{$prop_name};
86     return '' unless defined $prop_def;
87    
88     my $v = ${$_[0]}->{$prop_def->{key}};
89    
90     return ((defined $v->[1] and $v->[1] eq 'important') ? 'important' : '');
91     } # get_property_priority
92    
93 wakaba 1.1 ## TODO: Implement other methods and attributes
94    
95 wakaba 1.4 package Message::DOM::CSSComputedStyleDeclaration;
96     push our @ISA, 'Message::IF::CSSStyleDeclaration';
97    
98     sub ____new ($$$) {
99     my $self = bless \{}, shift;
100     $$self->{cascade} = shift; # Whatpm::CSS::Cascade object.
101     $$self->{element} = shift; ## TODO: This link should be weaken?
102     return $self;
103     } # ____new
104    
105 wakaba 1.7 sub AUTOLOAD {
106     my $method_name = our $AUTOLOAD;
107     $method_name =~ s/.*:://;
108     return if $method_name eq 'DESTROY';
109    
110     require Whatpm::CSS::Parser;
111     my $prop_def = $Whatpm::CSS::Parser::Attr->{$method_name};
112    
113     if ($prop_def) {
114     no strict 'refs';
115     *{ $method_name } = sub {
116     ## TODO: setter
117    
118     my $self = $_[0];
119     my $value = $$self->{cascade}->get_computed_value
120     ($$self->{element}, $prop_def->{css});
121     if ($value) {
122     return $prop_def->{serialize}->($self, $prop_def->{css}, $value);
123     } else {
124     return undef;
125     }
126     ## TODO: null? ""? ... if not set?
127     };
128     goto &{ $AUTOLOAD };
129     } else {
130     require Carp;
131     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
132     }
133     } # AUTOLOAD
134    
135 wakaba 1.4 sub css_text ($;$) {
136     ## TODO: error if modified
137    
138     my $self = shift;
139     require Whatpm::CSS::Parser;
140    
141     ## TODO: ordering
142     ## TODO: any spec?
143     my $r = '';
144 wakaba 1.7 my %serialized;
145 wakaba 1.6 for my $prop_def (sort {$a->{css} cmp $b->{css}}
146 wakaba 1.7 grep {$_->{compute} or
147     $_->{compute_multiple} or
148     $_->{serialize_multiple}}
149 wakaba 1.6 values %$Whatpm::CSS::Parser::Prop) {
150 wakaba 1.7 if ($prop_def->{serialize_multiple}) {
151     unless ($serialized{$prop_def->{serialize_multiple}}) {
152     $serialized{$prop_def->{serialize_multiple}} = 1;
153     my $v = $prop_def->{serialize_multiple}->($self);
154     for my $prop_name (sort {$a cmp $b} keys %$v) {
155     $r .= ' ' . $prop_name . ': ' . $v->{$prop_name} . ";\n"
156     }
157     }
158 wakaba 1.5 } else {
159 wakaba 1.7 my $prop_value = $$self->{cascade}->get_computed_value
160     ($$self->{element}, $prop_def->{css});
161     my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $prop_value);
162     if (defined $s) {
163     $r .= ' ' . $prop_def->{css} . ': ' . $s;
164     $r .= ";\n";
165     } else {
166     ## NOTE: This should be an error of the implementation.
167     $r .= " /* $prop_def->{css}: ???; */\n";
168     }
169 wakaba 1.4 }
170     }
171 wakaba 1.6
172     ## ISSUE: Should we include CSS properties that are not supported?
173    
174 wakaba 1.4 return $r;
175     } # css_text
176    
177 wakaba 1.7 ## |CSSStyleDeclaration| methods
178    
179     sub get_property_priority ($$) {
180     return '';
181     } # get_property_priority
182    
183 wakaba 1.4 ## TODO: members
184    
185 wakaba 1.1 package Message::IF::CSSStyleDeclaration;
186    
187     1;
188 wakaba 1.8 ## $Date: 2008/01/06 04:32:56 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24