/[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.4 - (hide annotations) (download)
Tue Jan 1 07:06:04 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +35 -2 lines
++ manakai/lib/Message/DOM/ChangeLog	1 Jan 2008 07:05:57 -0000
2008-01-01  Wakaba  <wakaba@suika.fam.cx>

	* CSSStyleDeclaration.pm (CSSComputedStyleDeclaration): New class.

1 wakaba 1.1 package Message::DOM::CSSStyleDeclaration;
2     use strict;
3 wakaba 1.4 our $VERSION=do{my @r=(q$Revision: 1.3 $=~/\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     };
32     goto &{ $AUTOLOAD };
33     } else {
34     require Carp;
35     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
36     }
37     } # AUTOLOAD
38    
39 wakaba 1.1 ## |CSSStyleDeclaration| attributes
40    
41 wakaba 1.2 sub css_text ($;$) {
42 wakaba 1.3 ## TODO: setter
43    
44     require Whatpm::CSS::Parser;
45     my $self = $_[0];
46     my $r = '';
47     for (grep {$$self->{$_}} keys %$$self) {
48     my $prop_def = $Whatpm::CSS::Parser::Key->{$_};
49     next unless $prop_def;
50     my $value = $$self->{$_};
51     my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $value->[0]);
52     if (defined $s) {
53     $r .= ' ' . $prop_def->{css} . ': ' . $s;
54     $r .= ' !' . $value->[1] if defined $value->[1];
55     $r .= ";\n";
56     }
57     }
58     ## TODO: shorthands
59     return $r;
60 wakaba 1.2 } # css_text
61    
62 wakaba 1.1 sub parent_rule ($) {
63     return ${$_[0]}->{parent_rule};
64     } # parent_rule
65    
66     ## TODO: Implement other methods and attributes
67    
68 wakaba 1.4 package Message::DOM::CSSComputedStyleDeclaration;
69     push our @ISA, 'Message::IF::CSSStyleDeclaration';
70    
71     sub ____new ($$$) {
72     my $self = bless \{}, shift;
73     $$self->{cascade} = shift; # Whatpm::CSS::Cascade object.
74     $$self->{element} = shift; ## TODO: This link should be weaken?
75     return $self;
76     } # ____new
77    
78     sub css_text ($;$) {
79     ## TODO: error if modified
80    
81     my $self = shift;
82     require Whatpm::CSS::Parser;
83    
84     ## TODO: ordering
85     ## TODO: any spec?
86     my $r = '';
87     for my $prop_def (grep {$_->{compute}} values %$Whatpm::CSS::Parser::Prop) {
88     my $prop_value = $$self->{cascade}->get_computed_value
89     ($$self->{element}, $prop_def->{css});
90     my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $prop_value);
91     if (defined $s) {
92     $r .= ' ' . $prop_def->{css} . ': ' . $s;
93     $r .= ";\n";
94     }
95     }
96     return $r;
97     } # css_text
98    
99     ## TODO: members
100    
101 wakaba 1.1 package Message::IF::CSSStyleDeclaration;
102    
103     1;
104 wakaba 1.4 ## $Date: 2007/12/31 03:02:29 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24