| 1 |
wakaba |
1.1 |
package WebHACC::Language::CSS; |
| 2 |
|
|
use strict; |
| 3 |
wakaba |
1.3 |
require WebHACC::Language::Base; |
| 4 |
wakaba |
1.1 |
push our @ISA, 'WebHACC::Language::Base'; |
| 5 |
|
|
|
| 6 |
|
|
sub new ($) { |
| 7 |
|
|
my $self = bless {}, shift; |
| 8 |
|
|
return $self; |
| 9 |
|
|
} # new |
| 10 |
|
|
|
| 11 |
|
|
sub generate_syntax_error_section ($) { |
| 12 |
|
|
my $self = shift; |
| 13 |
wakaba |
1.4 |
|
| 14 |
wakaba |
1.1 |
my $out = $self->output; |
| 15 |
wakaba |
1.4 |
|
| 16 |
wakaba |
1.6 |
$self->result->layer_uncertain ('charset'); |
| 17 |
|
|
|
| 18 |
wakaba |
1.4 |
$out->start_section (role => 'parse-errors'); |
| 19 |
|
|
$out->start_error_list (role => 'parse-errors'); |
| 20 |
wakaba |
1.6 |
$self->result->layer_applicable ('syntax'); |
| 21 |
wakaba |
1.1 |
|
| 22 |
|
|
my $input = $self->input; |
| 23 |
|
|
my $result = $self->result; |
| 24 |
|
|
|
| 25 |
|
|
my $p = $self->get_css_parser (); |
| 26 |
|
|
$p->init; |
| 27 |
|
|
$p->{onerror} = sub { |
| 28 |
|
|
my (%opt) = @_; |
| 29 |
wakaba |
1.2 |
if (not defined $opt{value} and defined $opt{token}) { |
| 30 |
|
|
$opt{value} = Whatpm::CSS::Tokenizer->serialize_token ($opt{token}); |
| 31 |
wakaba |
1.1 |
} |
| 32 |
wakaba |
1.2 |
$result->add_error (%opt, layer => 'syntax'); |
| 33 |
wakaba |
1.1 |
}; |
| 34 |
wakaba |
1.8 |
$p->{href} = $input->url; |
| 35 |
wakaba |
1.1 |
$p->{base_uri} = $input->{base_uri}; |
| 36 |
|
|
|
| 37 |
|
|
# if ($parse_mode eq 'q') { |
| 38 |
|
|
# $p->{unitless_px} = 1; |
| 39 |
|
|
# $p->{hashless_color} = 1; |
| 40 |
|
|
# } |
| 41 |
|
|
|
| 42 |
|
|
## TODO: Make $input->{s} a ref. |
| 43 |
|
|
|
| 44 |
|
|
my $s = \$input->{s}; |
| 45 |
|
|
my $charset; |
| 46 |
|
|
unless ($input->{is_char_string}) { |
| 47 |
wakaba |
1.7 |
$self->result->layer_uncertain ('encode'); |
| 48 |
wakaba |
1.1 |
require Encode; |
| 49 |
|
|
if (defined $input->{charset}) {## TODO: IANA->Perl |
| 50 |
|
|
$charset = $input->{charset}; |
| 51 |
|
|
$s = \(Encode::decode ($input->{charset}, $$s)); |
| 52 |
|
|
} else { |
| 53 |
|
|
## TODO: charset detection |
| 54 |
|
|
$s = \(Encode::decode ($charset = 'utf-8', $$s)); |
| 55 |
|
|
} |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
$self->{structure} = $p->parse_char_string ($$s); |
| 59 |
|
|
$self->{structure}->manakai_input_encoding ($charset) if defined $charset; |
| 60 |
|
|
|
| 61 |
wakaba |
1.4 |
$out->end_error_list (role => 'parse-errors'); |
| 62 |
wakaba |
1.1 |
$out->end_section; |
| 63 |
|
|
} # generate_syntax_error_section |
| 64 |
|
|
|
| 65 |
|
|
sub source_charset ($) { |
| 66 |
|
|
return shift->{structure}->manakai_input_encoding; |
| 67 |
|
|
} # source_charset |
| 68 |
|
|
|
| 69 |
|
|
sub generate_structure_dump_section ($) { |
| 70 |
|
|
my $self = shift; |
| 71 |
|
|
|
| 72 |
wakaba |
1.3 |
my $out = $self->output; |
| 73 |
wakaba |
1.4 |
|
| 74 |
wakaba |
1.5 |
$out->start_section (role => 'reformatted'); |
| 75 |
wakaba |
1.1 |
|
| 76 |
|
|
$out->start_code_block; |
| 77 |
wakaba |
1.3 |
$out->text ($self->{structure}->css_text); |
| 78 |
wakaba |
1.1 |
$out->end_code_block; |
| 79 |
|
|
|
| 80 |
|
|
$out->end_section; |
| 81 |
|
|
} # generate_structure_dump_section |
| 82 |
|
|
|
| 83 |
|
|
sub generate_structure_error_section ($) { |
| 84 |
wakaba |
1.9 |
## NOTE: The content of this method is commented out, since a CSSOM |
| 85 |
|
|
## tree would contain no error that affect conformance, AFAICT. |
| 86 |
|
|
## The plan is that we could someday implement "semantic" checking for CSSOM |
| 87 |
|
|
## trees, like "this color and this background color is too resemble such that |
| 88 |
|
|
## a user might not be able to read the text". Such errors do not affect |
| 89 |
|
|
## conformance, in any way. |
| 90 |
|
|
# my $self = shift; |
| 91 |
|
|
# |
| 92 |
|
|
# my $out = $self->output; |
| 93 |
|
|
# |
| 94 |
|
|
# $out->start_section (role => 'structure-errors'); |
| 95 |
|
|
# $out->start_error_list (role => 'structure-errors'); |
| 96 |
|
|
# $self->result->layer_applicable ('structure'); |
| 97 |
|
|
# |
| 98 |
|
|
# $self->result->add_error (level => 'u', |
| 99 |
|
|
# layer => 'structure', |
| 100 |
|
|
# input => $self->input, |
| 101 |
|
|
# type => 'CSSOM validation not supported'); |
| 102 |
|
|
# |
| 103 |
|
|
# $out->end_error_list (role => 'structure-errors'); |
| 104 |
|
|
# $out->end_section; |
| 105 |
wakaba |
1.1 |
} # generate_structure_error_section |
| 106 |
|
|
|
| 107 |
|
|
sub get_css_parser () { |
| 108 |
|
|
our $CSSParser; |
| 109 |
|
|
return $CSSParser if $CSSParser; |
| 110 |
|
|
|
| 111 |
|
|
require Whatpm::CSS::Parser; |
| 112 |
|
|
my $p = Whatpm::CSS::Parser->new; |
| 113 |
|
|
|
| 114 |
|
|
$p->{prop}->{$_} = 1 for qw/ |
| 115 |
|
|
alignment-baseline |
| 116 |
|
|
background background-attachment background-color background-image |
| 117 |
|
|
background-position background-position-x background-position-y |
| 118 |
|
|
background-repeat border border-bottom border-bottom-color |
| 119 |
|
|
border-bottom-style border-bottom-width border-collapse border-color |
| 120 |
|
|
border-left border-left-color |
| 121 |
|
|
border-left-style border-left-width border-right border-right-color |
| 122 |
|
|
border-right-style border-right-width |
| 123 |
|
|
border-spacing -manakai-border-spacing-x -manakai-border-spacing-y |
| 124 |
|
|
border-style border-top border-top-color border-top-style border-top-width |
| 125 |
|
|
border-width bottom |
| 126 |
|
|
caption-side clear clip color content counter-increment counter-reset |
| 127 |
|
|
cursor direction display dominant-baseline empty-cells float font |
| 128 |
|
|
font-family font-size font-size-adjust font-stretch |
| 129 |
|
|
font-style font-variant font-weight height left |
| 130 |
|
|
letter-spacing line-height |
| 131 |
|
|
list-style list-style-image list-style-position list-style-type |
| 132 |
|
|
margin margin-bottom margin-left margin-right margin-top marker-offset |
| 133 |
|
|
marks max-height max-width min-height min-width opacity -moz-opacity |
| 134 |
|
|
orphans outline outline-color outline-style outline-width overflow |
| 135 |
|
|
overflow-x overflow-y |
| 136 |
|
|
padding padding-bottom padding-left padding-right padding-top |
| 137 |
|
|
page page-break-after page-break-before page-break-inside |
| 138 |
|
|
position quotes right size table-layout |
| 139 |
|
|
text-align text-anchor text-decoration text-indent text-transform |
| 140 |
|
|
top unicode-bidi vertical-align visibility white-space width widows |
| 141 |
|
|
word-spacing writing-mode z-index |
| 142 |
|
|
/; |
| 143 |
|
|
$p->{prop_value}->{display}->{$_} = 1 for qw/ |
| 144 |
|
|
block clip inline inline-block inline-table list-item none |
| 145 |
|
|
table table-caption table-cell table-column table-column-group |
| 146 |
|
|
table-header-group table-footer-group table-row table-row-group |
| 147 |
|
|
compact marker |
| 148 |
|
|
/; |
| 149 |
|
|
$p->{prop_value}->{position}->{$_} = 1 for qw/ |
| 150 |
|
|
absolute fixed relative static |
| 151 |
|
|
/; |
| 152 |
wakaba |
1.10 |
for (qw/-moz-max-content -moz-min-content -moz-fit-content -moz-available/) { |
| 153 |
|
|
$p->{prop_value}->{width}->{$_} = 1; |
| 154 |
|
|
$p->{prop_value}->{'min-width'}->{$_} = 1; |
| 155 |
|
|
$p->{prop_value}->{'max-width'}->{$_} = 1; |
| 156 |
|
|
} |
| 157 |
wakaba |
1.1 |
$p->{prop_value}->{float}->{$_} = 1 for qw/ |
| 158 |
|
|
left right none |
| 159 |
|
|
/; |
| 160 |
|
|
$p->{prop_value}->{clear}->{$_} = 1 for qw/ |
| 161 |
|
|
left right none both |
| 162 |
|
|
/; |
| 163 |
|
|
$p->{prop_value}->{direction}->{ltr} = 1; |
| 164 |
|
|
$p->{prop_value}->{direction}->{rtl} = 1; |
| 165 |
|
|
$p->{prop_value}->{marks}->{crop} = 1; |
| 166 |
|
|
$p->{prop_value}->{marks}->{cross} = 1; |
| 167 |
|
|
$p->{prop_value}->{'unicode-bidi'}->{$_} = 1 for qw/ |
| 168 |
|
|
normal bidi-override embed |
| 169 |
|
|
/; |
| 170 |
|
|
for my $prop_name (qw/overflow overflow-x overflow-y/) { |
| 171 |
|
|
$p->{prop_value}->{$prop_name}->{$_} = 1 for qw/ |
| 172 |
|
|
visible hidden scroll auto -webkit-marquee -moz-hidden-unscrollable |
| 173 |
|
|
/; |
| 174 |
|
|
} |
| 175 |
|
|
$p->{prop_value}->{visibility}->{$_} = 1 for qw/ |
| 176 |
|
|
visible hidden collapse |
| 177 |
|
|
/; |
| 178 |
|
|
$p->{prop_value}->{'list-style-type'}->{$_} = 1 for qw/ |
| 179 |
|
|
disc circle square decimal decimal-leading-zero |
| 180 |
|
|
lower-roman upper-roman lower-greek lower-latin |
| 181 |
|
|
upper-latin armenian georgian lower-alpha upper-alpha none |
| 182 |
|
|
hebrew cjk-ideographic hiragana katakana hiragana-iroha |
| 183 |
|
|
katakana-iroha |
| 184 |
|
|
/; |
| 185 |
|
|
$p->{prop_value}->{'list-style-position'}->{outside} = 1; |
| 186 |
|
|
$p->{prop_value}->{'list-style-position'}->{inside} = 1; |
| 187 |
|
|
$p->{prop_value}->{'page-break-before'}->{$_} = 1 for qw/ |
| 188 |
|
|
auto always avoid left right |
| 189 |
|
|
/; |
| 190 |
|
|
$p->{prop_value}->{'page-break-after'}->{$_} = 1 for qw/ |
| 191 |
|
|
auto always avoid left right |
| 192 |
|
|
/; |
| 193 |
|
|
$p->{prop_value}->{'page-break-inside'}->{auto} = 1; |
| 194 |
|
|
$p->{prop_value}->{'page-break-inside'}->{avoid} = 1; |
| 195 |
|
|
$p->{prop_value}->{'background-repeat'}->{$_} = 1 for qw/ |
| 196 |
|
|
repeat repeat-x repeat-y no-repeat |
| 197 |
|
|
/; |
| 198 |
|
|
$p->{prop_value}->{'background-attachment'}->{scroll} = 1; |
| 199 |
|
|
$p->{prop_value}->{'background-attachment'}->{fixed} = 1; |
| 200 |
|
|
$p->{prop_value}->{'font-size'}->{$_} = 1 for qw/ |
| 201 |
|
|
xx-small x-small small medium large x-large xx-large |
| 202 |
|
|
-manakai-xxx-large -webkit-xxx-large |
| 203 |
|
|
larger smaller |
| 204 |
|
|
/; |
| 205 |
|
|
$p->{prop_value}->{'font-style'}->{normal} = 1; |
| 206 |
|
|
$p->{prop_value}->{'font-style'}->{italic} = 1; |
| 207 |
|
|
$p->{prop_value}->{'font-style'}->{oblique} = 1; |
| 208 |
|
|
$p->{prop_value}->{'font-variant'}->{normal} = 1; |
| 209 |
|
|
$p->{prop_value}->{'font-variant'}->{'small-caps'} = 1; |
| 210 |
|
|
$p->{prop_value}->{'font-stretch'}->{$_} = 1 for |
| 211 |
|
|
qw/normal wider narrower ultra-condensed extra-condensed |
| 212 |
|
|
condensed semi-condensed semi-expanded expanded |
| 213 |
|
|
extra-expanded ultra-expanded/; |
| 214 |
|
|
$p->{prop_value}->{'text-align'}->{$_} = 1 for qw/ |
| 215 |
|
|
left right center justify begin end |
| 216 |
|
|
/; |
| 217 |
|
|
$p->{prop_value}->{'text-transform'}->{$_} = 1 for qw/ |
| 218 |
|
|
capitalize uppercase lowercase none |
| 219 |
|
|
/; |
| 220 |
|
|
$p->{prop_value}->{'white-space'}->{$_} = 1 for qw/ |
| 221 |
|
|
normal pre nowrap pre-line pre-wrap -moz-pre-wrap |
| 222 |
|
|
/; |
| 223 |
|
|
$p->{prop_value}->{'writing-mode'}->{$_} = 1 for qw/ |
| 224 |
|
|
lr rl tb lr-tb rl-tb tb-rl |
| 225 |
|
|
/; |
| 226 |
|
|
$p->{prop_value}->{'text-anchor'}->{$_} = 1 for qw/ |
| 227 |
|
|
start middle end |
| 228 |
|
|
/; |
| 229 |
|
|
$p->{prop_value}->{'dominant-baseline'}->{$_} = 1 for qw/ |
| 230 |
|
|
auto use-script no-change reset-size ideographic alphabetic |
| 231 |
|
|
hanging mathematical central middle text-after-edge text-before-edge |
| 232 |
|
|
/; |
| 233 |
|
|
$p->{prop_value}->{'alignment-baseline'}->{$_} = 1 for qw/ |
| 234 |
|
|
auto baseline before-edge text-before-edge middle central |
| 235 |
|
|
after-edge text-after-edge ideographic alphabetic hanging |
| 236 |
|
|
mathematical |
| 237 |
|
|
/; |
| 238 |
|
|
$p->{prop_value}->{'text-decoration'}->{$_} = 1 for qw/ |
| 239 |
|
|
none blink underline overline line-through |
| 240 |
|
|
/; |
| 241 |
|
|
$p->{prop_value}->{'caption-side'}->{$_} = 1 for qw/ |
| 242 |
|
|
top bottom left right |
| 243 |
|
|
/; |
| 244 |
|
|
$p->{prop_value}->{'table-layout'}->{auto} = 1; |
| 245 |
|
|
$p->{prop_value}->{'table-layout'}->{fixed} = 1; |
| 246 |
|
|
$p->{prop_value}->{'border-collapse'}->{collapse} = 1; |
| 247 |
|
|
$p->{prop_value}->{'border-collapse'}->{separate} = 1; |
| 248 |
|
|
$p->{prop_value}->{'empty-cells'}->{show} = 1; |
| 249 |
|
|
$p->{prop_value}->{'empty-cells'}->{hide} = 1; |
| 250 |
|
|
$p->{prop_value}->{cursor}->{$_} = 1 for qw/ |
| 251 |
|
|
auto crosshair default pointer move e-resize ne-resize nw-resize n-resize |
| 252 |
|
|
se-resize sw-resize s-resize w-resize text wait help progress |
| 253 |
|
|
/; |
| 254 |
|
|
for my $prop (qw/border-top-style border-left-style |
| 255 |
|
|
border-bottom-style border-right-style outline-style/) { |
| 256 |
|
|
$p->{prop_value}->{$prop}->{$_} = 1 for qw/ |
| 257 |
|
|
none hidden dotted dashed solid double groove ridge inset outset |
| 258 |
|
|
/; |
| 259 |
|
|
} |
| 260 |
|
|
for my $prop (qw/color background-color |
| 261 |
|
|
border-bottom-color border-left-color border-right-color |
| 262 |
|
|
border-top-color border-color/) { |
| 263 |
|
|
$p->{prop_value}->{$prop}->{transparent} = 1; |
| 264 |
|
|
$p->{prop_value}->{$prop}->{flavor} = 1; |
| 265 |
|
|
$p->{prop_value}->{$prop}->{'-manakai-default'} = 1; |
| 266 |
|
|
} |
| 267 |
|
|
$p->{prop_value}->{'outline-color'}->{invert} = 1; |
| 268 |
|
|
$p->{prop_value}->{'outline-color'}->{'-manakai-invert-or-currentcolor'} = 1; |
| 269 |
|
|
$p->{pseudo_class}->{$_} = 1 for qw/ |
| 270 |
|
|
active checked disabled empty enabled first-child first-of-type |
| 271 |
|
|
focus hover indeterminate last-child last-of-type link only-child |
| 272 |
|
|
only-of-type root target visited |
| 273 |
|
|
lang nth-child nth-last-child nth-of-type nth-last-of-type not |
| 274 |
|
|
-manakai-contains -manakai-current |
| 275 |
|
|
/; |
| 276 |
|
|
$p->{pseudo_element}->{$_} = 1 for qw/ |
| 277 |
|
|
after before first-letter first-line |
| 278 |
|
|
/; |
| 279 |
|
|
|
| 280 |
|
|
return $CSSParser = $p; |
| 281 |
|
|
} # get_css_parser |
| 282 |
|
|
|
| 283 |
|
|
1; |