/[suikacvs]/markup/html/whatpm/Whatpm/CSS/Parser.pm
Suika

Diff of /markup/html/whatpm/Whatpm/CSS/Parser.pm

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

revision 1.47 by wakaba, Sat Jan 26 09:30:47 2008 UTC revision 1.48 by wakaba, Sat Jan 26 11:18:40 2008 UTC
# Line 1010  $Prop->{'background-color'} = { Line 1010  $Prop->{'background-color'} = {
1010    serialize_multiple => sub {    serialize_multiple => sub {
1011      my $self = shift;      my $self = shift;
1012    
     ## TODO: !important handling is incorrect.  
   
1013      my $r = {};      my $r = {};
1014      my $has_all;      my $has_all;
1015            
     local $Error::Depth = $Error::Depth + 1;  
1016      my $x = $self->background_position_x;      my $x = $self->background_position_x;
1017      my $y = $self->background_position_y;      my $y = $self->background_position_y;
1018      my $xi = $self->get_property_priority ('background-position-x');      my $xi = $self->get_property_priority ('background-position-x');
# Line 1023  $Prop->{'background-color'} = { Line 1020  $Prop->{'background-color'} = {
1020      if (length $x) {      if (length $x) {
1021        if (length $y) {        if (length $y) {
1022          if ($xi eq $yi) {          if ($xi eq $yi) {
1023            $r->{'background-position'} = [$x . ' ' . $y, $xi];            if ($x eq 'inherit') {
1024            $has_all = 1;              if ($y eq 'inherit') {
1025                  $r->{'background-position'} = ['inherit', $xi];
1026                  $has_all = 1;
1027                } else {
1028                  $r->{'background-position-x'} = [$x, $xi];
1029                  $r->{'background-position-y'} = [$y, $yi];
1030                }
1031              } elsif ($y eq 'inherit') {
1032                $r->{'background-position-x'} = [$x, $xi];
1033                $r->{'background-position-y'} = [$y, $yi];
1034              } else {
1035                $r->{'background-position'} = [$x . ' ' . $y, $xi];
1036                $has_all = 1;
1037              }
1038          } else {          } else {
1039            $r->{'background-position-x'} = [$x, $xi];            $r->{'background-position-x'} = [$x, $xi];
1040            $r->{'background-position-y'} = [$y, $yi];            $r->{'background-position-y'} = [$y, $yi];
# Line 1045  $Prop->{'background-color'} = { Line 1055  $Prop->{'background-color'} = {
1055        my $value = $self->$prop_name;        my $value = $self->$prop_name;
1056        if (length $value) {        if (length $value) {
1057          my $i = $self->get_property_priority ('background-'.$prop);          my $i = $self->get_property_priority ('background-'.$prop);
1058            undef $has_all unless $xi eq $i;
1059          $r->{'background-'.$prop} = [$value, $i];          $r->{'background-'.$prop} = [$value, $i];
1060        } else {        } else {
1061          undef $has_all;          undef $has_all;
# Line 1064  $Prop->{'background-color'} = { Line 1075  $Prop->{'background-color'} = {
1075        push @v, $r->{'background-position'}        push @v, $r->{'background-position'}
1076            unless $r->{'background-position'}->[0] eq '0% 0%';            unless $r->{'background-position'}->[0] eq '0% 0%';
1077        if (@v) {        if (@v) {
1078          return {background => [(join ' ', map {$_->[0]} @v), '']};          my $inherit = 0;
1079            for (@v) {
1080              $inherit++ if $_->[0] eq 'inherit';
1081            }
1082            if ($inherit == 5) {
1083              return {background => ['inherit', $xi]};
1084            } elsif ($inherit) {
1085              return $r;
1086            } else {
1087              return {background => [(join ' ', map {$_->[0]} @v), $xi]};
1088            }
1089        } else {        } else {
1090          return {background => ['transparent none repeat scroll 0% 0%', '']};          return {background => ['transparent none repeat scroll 0% 0%', $xi]};
1091        }        }
1092      } else {      } else {
1093        return $r;        return $r;
# Line 4789  $Prop->{'background-position'} = { Line 4810  $Prop->{'background-position'} = {
4810    
4811      return ($t, \%prop_value);      return ($t, \%prop_value);
4812    },    },
4813    serialize => sub {    serialize_shorthand => sub {
4814      my ($self, $prop_name, $value) = @_;      my $self = shift;
4815        
4816      local $Error::Depth = $Error::Depth + 1;      my $r = {};
4817    
4818      my $x = $self->background_position_x;      my $x = $self->background_position_x;
4819      my $y = $self->background_position_y;      my $y = $self->background_position_y;
4820      return $x . ' ' . $y if length $x and length $y;      my $xi = $self->get_property_priority ('background-position-x');
4821      return '';      my $yi = $self->get_property_priority ('background-position-y');
4822        if (length $x) {
4823          if (length $y) {
4824            if ($xi eq $yi) {
4825              if ($x eq 'inherit') {
4826                if ($y eq 'inherit') {
4827                  $r->{'background-position'} = ['inherit', $xi];
4828                } else {
4829                  $r->{'background-position-x'} = [$x, $xi];
4830                  $r->{'background-position-y'} = [$y, $yi];
4831                }
4832              } elsif ($y eq 'inherit') {
4833                $r->{'background-position-x'} = [$x, $xi];
4834                $r->{'background-position-y'} = [$y, $yi];
4835              } else {
4836                $r->{'background-position'} = [$x . ' ' . $y, $xi];
4837              }
4838            } else {
4839              $r->{'background-position-x'} = [$x, $xi];
4840              $r->{'background-position-y'} = [$y, $yi];
4841            }
4842          } else {
4843            $r->{'background-position-x'} = [$x, $xi];
4844          }
4845        } else {
4846          if (length $y) {
4847            $r->{'background-position-y'} = [$y, $yi];
4848          } else {
4849            #
4850          }
4851        }
4852    
4853        return $r;
4854    },    },
4855    serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},    serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
4856  };  };
# Line 4809  $Prop->{background} = { Line 4863  $Prop->{background} = {
4863      my ($self, $prop_name, $tt, $t, $onerror) = @_;      my ($self, $prop_name, $tt, $t, $onerror) = @_;
4864      my %prop_value;      my %prop_value;
4865      B: for (1..5) {      B: for (1..5) {
4866          my $has_sign;
4867        my $sign = 1;        my $sign = 1;
4868        if ($t->{type} == MINUS_TOKEN) {        if ($t->{type} == MINUS_TOKEN) {
4869          $sign = -1;          $sign = -1;
4870            $has_sign = 1;
4871            $t = $tt->get_next_token;
4872          } elsif ($t->{type} == PLUS_TOKEN) {
4873            $has_sign = 1;
4874          $t = $tt->get_next_token;          $t = $tt->get_next_token;
4875        }        }
4876    
4877        if ($sign > 0 and $t->{type} == IDENT_TOKEN) {        if (not $has_sign and $t->{type} == IDENT_TOKEN) {
4878          my $value = lc $t->{value}; ## TODO: case          my $value = lc $t->{value}; ## TODO: case
4879          if ($Prop->{'background-repeat'}->{keyword}->{$value} and          if ($Prop->{'background-repeat'}->{keyword}->{$value} and
4880              $self->{prop_value}->{'background-repeat'}->{$value} and              $self->{prop_value}->{'background-repeat'}->{$value} and
# Line 4837  $Prop->{background} = { Line 4896  $Prop->{background} = {
4896            $t = $tt->get_next_token;            $t = $tt->get_next_token;
4897            $t = $tt->get_next_token while $t->{type} == S_TOKEN;            $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4898            my $sign = 1;            my $sign = 1;
4899              my $has_sign;
4900            if ($t->{type} == MINUS_TOKEN) {            if ($t->{type} == MINUS_TOKEN) {
4901              $sign = -1;              $sign = -1;
4902                $has_sign = 1;
4903                $t = $tt->get_next_token;
4904              } elsif ($t->{type} == PLUS_TOKEN) {
4905                $has_sign = 1;
4906              $t = $tt->get_next_token;              $t = $tt->get_next_token;
4907            }            }
4908            if ($sign > 0 and $t->{type} == IDENT_TOKEN) {            if (not $has_sign and $t->{type} == IDENT_TOKEN) {
4909              my $value = lc $t->{value}; ## TODO: case              my $value = lc $t->{value}; ## TODO: case
4910              if ({top => 1, bottom => 1, center => 1}->{$value}) {              if ({top => 1, bottom => 1, center => 1}->{$value}) {
4911                $prop_value{'background-position-y'} = ['KEYWORD', $value];                $prop_value{'background-position-y'} = ['KEYWORD', $value];
# Line 4866  $Prop->{background} = { Line 4930  $Prop->{background} = {
4930                           level => $self->{must_level},                           level => $self->{must_level},
4931                           uri => \$self->{href},                           uri => \$self->{href},
4932                           token => $t);                           token => $t);
4933                last B;                return ($t, undef);
4934              }              }
4935            } elsif ($t->{type} == PERCENTAGE_TOKEN) {            } elsif ($t->{type} == PERCENTAGE_TOKEN) {
4936              my $value = $t->{number} * $sign;              my $value = $t->{number} * $sign;
# Line 4877  $Prop->{background} = { Line 4941  $Prop->{background} = {
4941              my $value = $t->{number} * $sign;              my $value = $t->{number} * $sign;
4942              $t = $tt->get_next_token;              $t = $tt->get_next_token;
4943              $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];              $prop_value{'background-position-y'} = ['DIMENSION', $value, 'px'];
4944            } elsif ($sign < 0) {            } elsif ($has_sign) {
4945              $onerror->(type => "syntax error:'$prop_name'",              $onerror->(type => "syntax error:'$prop_name'",
4946                         level => $self->{must_level},                         level => $self->{must_level},
4947                         uri => \$self->{href},                         uri => \$self->{href},
4948                         token => $t);                         token => $t);
4949              last B;              return ($t, undef);
4950              } else {
4951                $prop_value{'background-position-y'} = ['KEYWORD', 'center'];
4952            }            }
4953          } elsif (($value eq 'top' or $value eq 'bottom') and          } elsif (($value eq 'top' or $value eq 'bottom') and
4954                   not defined $prop_value{'background-position-y'}) {                   not defined $prop_value{'background-position-y'}) {
# Line 4890  $Prop->{background} = { Line 4956  $Prop->{background} = {
4956            $t = $tt->get_next_token;            $t = $tt->get_next_token;
4957            $t = $tt->get_next_token while $t->{type} == S_TOKEN;            $t = $tt->get_next_token while $t->{type} == S_TOKEN;
4958            if ($t->{type} == IDENT_TOKEN and ## TODO: case            if ($t->{type} == IDENT_TOKEN and ## TODO: case
4959                {left => 1, center => 1, right => 1}->{lc $t->{value}}) {                {
4960                    left => 1, center => 1, right => 1,
4961                  }->{my $value = lc $t->{value}}) {
4962              $prop_value{'background-position-x'} = ['KEYWORD', $value];              $prop_value{'background-position-x'} = ['KEYWORD', $value];
4963              $t = $tt->get_next_token;              $t = $tt->get_next_token;
4964            } else {            } else {
# Line 4919  $Prop->{background} = { Line 4987  $Prop->{background} = {
4987        } elsif (($t->{type} == DIMENSION_TOKEN or        } elsif (($t->{type} == DIMENSION_TOKEN or
4988                  $t->{type} == PERCENTAGE_TOKEN or                  $t->{type} == PERCENTAGE_TOKEN or
4989                  ($t->{type} == NUMBER_TOKEN and                  ($t->{type} == NUMBER_TOKEN and
4990                   $t->{unitless_px} or $t->{number} == 0)) and                   ($t->{unitless_px} or $t->{number} == 0))) and
4991                 not defined $prop_value{'background-position-x'}) {                 not defined $prop_value{'background-position-x'}) {
4992          if ($t->{type} == DIMENSION_TOKEN) {          if ($t->{type} == DIMENSION_TOKEN) {
4993            my $value = $t->{number} * $sign;            my $value = $t->{number} * $sign;
# Line 4933  $Prop->{background} = { Line 5001  $Prop->{background} = {
5001                         level => $self->{must_level},                         level => $self->{must_level},
5002                         uri => \$self->{href},                         uri => \$self->{href},
5003                         token => $t);                         token => $t);
5004              last B;              return ($t, undef);
5005            }            }
5006          } elsif ($t->{type} == PERCENTAGE_TOKEN) {          } elsif ($t->{type} == PERCENTAGE_TOKEN) {
5007            my $value = $t->{number} * $sign;            my $value = $t->{number} * $sign;
# Line 4952  $Prop->{background} = { Line 5020  $Prop->{background} = {
5020          $t = $tt->get_next_token while $t->{type} == S_TOKEN;          $t = $tt->get_next_token while $t->{type} == S_TOKEN;
5021          if ($t->{type} == MINUS_TOKEN) {          if ($t->{type} == MINUS_TOKEN) {
5022            $sign = -1;            $sign = -1;
5023              $has_sign = 1;
5024              $t = $tt->get_next_token;
5025            } elsif ($t->{type} == PLUS_TOKEN) {
5026              $has_sign = 1;
5027            $t = $tt->get_next_token;            $t = $tt->get_next_token;
5028          } else {          } else {
5029              undef $has_sign;
5030            $sign = 1;            $sign = 1;
5031          }          }
5032    
# Line 4969  $Prop->{background} = { Line 5042  $Prop->{background} = {
5042                         level => $self->{must_level},                         level => $self->{must_level},
5043                         uri => \$self->{href},                         uri => \$self->{href},
5044                         token => $t);                         token => $t);
5045              last B;              return ($t, undef);
5046            }            }
5047          } elsif ($t->{type} == PERCENTAGE_TOKEN) {          } elsif ($t->{type} == PERCENTAGE_TOKEN) {
5048            my $value = $t->{number} * $sign;            my $value = $t->{number} * $sign;
# Line 4989  $Prop->{background} = { Line 5062  $Prop->{background} = {
5062              $prop_value{'background-position-y'} = ['PERCENTAGE', 50];              $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
5063            }            }
5064          } else {          } else {
5065            if ($sign > 0) {            $prop_value{'background-position-y'} = ['PERCENTAGE', 50];
5066              $prop_value{'background-position-y'} = ['PERCENTAGE', 50];            if ($has_sign) {
           } else {  
5067              $onerror->(type => "syntax error:'$prop_name'",              $onerror->(type => "syntax error:'$prop_name'",
5068                         level => $self->{must_level},                         level => $self->{must_level},
5069                         uri => \$self->{href},                         uri => \$self->{href},
5070                         token => $t);                         token => $t);
5071                return ($t, undef);
5072            }            }
5073          }          }
5074        } elsif ($t->{type} == URI_TOKEN and        } elsif (not $has_sign and
5075                   $t->{type} == URI_TOKEN and
5076                 not defined $prop_value{'background-image'}) {                 not defined $prop_value{'background-image'}) {
5077          $prop_value{'background-image'} = ['URI', $t->{value}];          $prop_value{'background-image'}
5078                = ['URI', $t->{value}, \($self->{base_uri})];
5079          $t = $tt->get_next_token;          $t = $tt->get_next_token;
5080        } else {        } else {
5081          if (keys %prop_value and $sign > 0) {          if (keys %prop_value and not $has_sign) {
5082            last B;            last B;
5083          } else {          } else {
5084            $onerror->(type => "syntax error:'$prop_name'",            $onerror->(type => "syntax error:'$prop_name'",
5085                       level => $self->{must_level},                       level => $self->{must_level},
5086                       uri => \$self->{href},                       uri => \$self->{href},
5087                       token => $t);                       token => $t);
5088              return ($t, undef);
5089          }          }
5090        }        }
5091    
# Line 5022  $Prop->{background} = { Line 5098  $Prop->{background} = {
5098    
5099      return ($t, \%prop_value);      return ($t, \%prop_value);
5100    },    },
   serialize => sub {  
     my ($self, $prop_name, $value) = @_;  
       
     local $Error::Depth = $Error::Depth + 1;  
     my $color = $self->background_color;  
     return '' unless length $color;  
     my $image = $self->background_image;  
     return '' unless length $image;  
     my $repeat = $self->background_repeat;  
     return '' unless length $repeat;  
     my $attachment = $self->background_attachment;  
     return '' unless length $attachment;  
     my $position = $self->background_position;  
     return '' unless length $position;  
   
     my @v;  
     push @v, $color unless $color eq 'transparent';  
     push @v, $image unless $image eq 'none';  
     push @v, $repeat unless $repeat eq 'repeat';  
     push @v, $attachment unless $attachment eq 'scroll';  
     push @v, $position unless $position eq '0% 0%';  
     if (@v) {  
       return join ' ', @v;  
     } else {  
       return 'transparent none repeat scroll 0% 0%';  
     }  
   },  
5101    serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},    serialize_multiple => $Prop->{'background-color'}->{serialize_multiple},
5102  };  };
5103  $Attr->{background} = $Prop->{background};  $Attr->{background} = $Prop->{background};

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24