| 1 |
package Message::DOM::CSSStyleDeclaration; |
| 2 |
use strict; |
| 3 |
our $VERSION=do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 |
push our @ISA, 'Message::IF::CSSStyleDeclaration'; |
| 5 |
|
| 6 |
sub ____new ($) { |
| 7 |
return bless \{}, $_[0]; |
| 8 |
} # ____new |
| 9 |
|
| 10 |
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 |
## |CSSStyleDeclaration| attributes |
| 40 |
|
| 41 |
sub css_text ($;$) { |
| 42 |
## 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 |
} # css_text |
| 61 |
|
| 62 |
sub parent_rule ($) { |
| 63 |
return ${$_[0]}->{parent_rule}; |
| 64 |
} # parent_rule |
| 65 |
|
| 66 |
## TODO: Implement other methods and attributes |
| 67 |
|
| 68 |
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 (sort {$a->{css} cmp $b->{css}} |
| 88 |
grep {$_->{compute} or $_->{compute_multiple}} |
| 89 |
values %$Whatpm::CSS::Parser::Prop) { |
| 90 |
my $prop_value = $$self->{cascade}->get_computed_value |
| 91 |
($$self->{element}, $prop_def->{css}); |
| 92 |
my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $prop_value); |
| 93 |
if (defined $s) { |
| 94 |
$r .= ' ' . $prop_def->{css} . ': ' . $s; |
| 95 |
$r .= ";\n"; |
| 96 |
} else { |
| 97 |
## NOTE: This should be an error of the implementation. |
| 98 |
$r .= " /* $prop_def->{css}: ???; */\n"; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
## ISSUE: Should we include CSS properties that are not supported? |
| 103 |
|
| 104 |
return $r; |
| 105 |
} # css_text |
| 106 |
|
| 107 |
## TODO: members |
| 108 |
|
| 109 |
package Message::IF::CSSStyleDeclaration; |
| 110 |
|
| 111 |
1; |
| 112 |
## $Date: 2008/01/01 09:09:16 $ |