| 44 |
require Whatpm::CSS::Parser; |
require Whatpm::CSS::Parser; |
| 45 |
my $self = $_[0]; |
my $self = $_[0]; |
| 46 |
my $r = ''; |
my $r = ''; |
| 47 |
|
my %serialized; |
| 48 |
for (grep {$$self->{$_}} keys %$$self) { |
for (grep {$$self->{$_}} keys %$$self) { |
| 49 |
my $prop_def = $Whatpm::CSS::Parser::Key->{$_}; |
my $prop_def = $Whatpm::CSS::Parser::Key->{$_}; |
| 50 |
next unless $prop_def; |
next unless $prop_def; |
| 51 |
my $value = $$self->{$_}; |
|
| 52 |
my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $value->[0]); |
if ($prop_def->{serialize_multiple}) { |
| 53 |
if (defined $s) { |
unless ($serialized{$prop_def->{serialize_multiple}}) { |
| 54 |
$r .= ' ' . $prop_def->{css} . ': ' . $s; |
$serialized{$prop_def->{serialize_multiple}} = 1; |
| 55 |
$r .= ' !' . $value->[1] if defined $value->[1]; |
my $v = $prop_def->{serialize_multiple}->($self); |
| 56 |
$r .= ";\n"; |
for my $prop_name (sort {$a cmp $b} keys %$v) { |
| 57 |
|
$r .= ' ' . $prop_name . ': ' . $v->{$prop_name} . ";\n" |
| 58 |
|
} |
| 59 |
|
} |
| 60 |
|
} else { |
| 61 |
|
my $value = $$self->{$_}; |
| 62 |
|
my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $value->[0]); |
| 63 |
|
if (defined $s) { |
| 64 |
|
$r .= ' ' . $prop_def->{css} . ': ' . $s; |
| 65 |
|
$r .= ' !' . $value->[1] if defined $value->[1]; |
| 66 |
|
$r .= ";\n"; |
| 67 |
|
} |
| 68 |
} |
} |
| 69 |
} |
} |
| 70 |
## TODO: shorthands |
## TODO: shorthands |
| 75 |
return ${$_[0]}->{parent_rule}; |
return ${$_[0]}->{parent_rule}; |
| 76 |
} # parent_rule |
} # parent_rule |
| 77 |
|
|
| 78 |
|
## |CSSStyleDeclaration| methods |
| 79 |
|
|
| 80 |
|
sub get_property_priority ($$) { |
| 81 |
|
my $prop_name = ''.$_[1]; |
| 82 |
|
|
| 83 |
|
require Whatpm::CSS::Parser; |
| 84 |
|
my $prop_def = $Whatpm::CSS::Parser::Prop->{$prop_name}; |
| 85 |
|
return '' unless defined $prop_def; |
| 86 |
|
|
| 87 |
|
my $v = ${$_[0]}->{$prop_def->{key}}; |
| 88 |
|
|
| 89 |
|
return ((defined $v->[1] and $v->[1] eq 'important') ? 'important' : ''); |
| 90 |
|
} # get_property_priority |
| 91 |
|
|
| 92 |
## TODO: Implement other methods and attributes |
## TODO: Implement other methods and attributes |
| 93 |
|
|
| 94 |
package Message::DOM::CSSComputedStyleDeclaration; |
package Message::DOM::CSSComputedStyleDeclaration; |
| 101 |
return $self; |
return $self; |
| 102 |
} # ____new |
} # ____new |
| 103 |
|
|
| 104 |
|
sub AUTOLOAD { |
| 105 |
|
my $method_name = our $AUTOLOAD; |
| 106 |
|
$method_name =~ s/.*:://; |
| 107 |
|
return if $method_name eq 'DESTROY'; |
| 108 |
|
|
| 109 |
|
require Whatpm::CSS::Parser; |
| 110 |
|
my $prop_def = $Whatpm::CSS::Parser::Attr->{$method_name}; |
| 111 |
|
|
| 112 |
|
if ($prop_def) { |
| 113 |
|
no strict 'refs'; |
| 114 |
|
*{ $method_name } = sub { |
| 115 |
|
## TODO: setter |
| 116 |
|
|
| 117 |
|
my $self = $_[0]; |
| 118 |
|
my $value = $$self->{cascade}->get_computed_value |
| 119 |
|
($$self->{element}, $prop_def->{css}); |
| 120 |
|
if ($value) { |
| 121 |
|
return $prop_def->{serialize}->($self, $prop_def->{css}, $value); |
| 122 |
|
} else { |
| 123 |
|
return undef; |
| 124 |
|
} |
| 125 |
|
## TODO: null? ""? ... if not set? |
| 126 |
|
}; |
| 127 |
|
goto &{ $AUTOLOAD }; |
| 128 |
|
} else { |
| 129 |
|
require Carp; |
| 130 |
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
| 131 |
|
} |
| 132 |
|
} # AUTOLOAD |
| 133 |
|
|
| 134 |
sub css_text ($;$) { |
sub css_text ($;$) { |
| 135 |
## TODO: error if modified |
## TODO: error if modified |
| 136 |
|
|
| 140 |
## TODO: ordering |
## TODO: ordering |
| 141 |
## TODO: any spec? |
## TODO: any spec? |
| 142 |
my $r = ''; |
my $r = ''; |
| 143 |
|
my %serialized; |
| 144 |
for my $prop_def (sort {$a->{css} cmp $b->{css}} |
for my $prop_def (sort {$a->{css} cmp $b->{css}} |
| 145 |
grep {$_->{compute} or $_->{compute_multiple}} |
grep {$_->{compute} or |
| 146 |
|
$_->{compute_multiple} or |
| 147 |
|
$_->{serialize_multiple}} |
| 148 |
values %$Whatpm::CSS::Parser::Prop) { |
values %$Whatpm::CSS::Parser::Prop) { |
| 149 |
my $prop_value = $$self->{cascade}->get_computed_value |
if ($prop_def->{serialize_multiple}) { |
| 150 |
($$self->{element}, $prop_def->{css}); |
unless ($serialized{$prop_def->{serialize_multiple}}) { |
| 151 |
my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $prop_value); |
$serialized{$prop_def->{serialize_multiple}} = 1; |
| 152 |
if (defined $s) { |
my $v = $prop_def->{serialize_multiple}->($self); |
| 153 |
$r .= ' ' . $prop_def->{css} . ': ' . $s; |
for my $prop_name (sort {$a cmp $b} keys %$v) { |
| 154 |
$r .= ";\n"; |
$r .= ' ' . $prop_name . ': ' . $v->{$prop_name} . ";\n" |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
} else { |
} else { |
| 158 |
## NOTE: This should be an error of the implementation. |
my $prop_value = $$self->{cascade}->get_computed_value |
| 159 |
$r .= " /* $prop_def->{css}: ???; */\n"; |
($$self->{element}, $prop_def->{css}); |
| 160 |
|
my $s = $prop_def->{serialize}->($self, $prop_def->{css}, $prop_value); |
| 161 |
|
if (defined $s) { |
| 162 |
|
$r .= ' ' . $prop_def->{css} . ': ' . $s; |
| 163 |
|
$r .= ";\n"; |
| 164 |
|
} else { |
| 165 |
|
## NOTE: This should be an error of the implementation. |
| 166 |
|
$r .= " /* $prop_def->{css}: ???; */\n"; |
| 167 |
|
} |
| 168 |
} |
} |
| 169 |
} |
} |
| 170 |
|
|
| 173 |
return $r; |
return $r; |
| 174 |
} # css_text |
} # css_text |
| 175 |
|
|
| 176 |
|
## |CSSStyleDeclaration| methods |
| 177 |
|
|
| 178 |
|
sub get_property_priority ($$) { |
| 179 |
|
return ''; |
| 180 |
|
} # get_property_priority |
| 181 |
|
|
| 182 |
## TODO: members |
## TODO: members |
| 183 |
|
|
| 184 |
package Message::IF::CSSStyleDeclaration; |
package Message::IF::CSSStyleDeclaration; |