/[suikacvs]/test/html-webhacc/WebHACC/Language/CSS.pm
Suika

Contents of /test/html-webhacc/WebHACC/Language/CSS.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun Jul 20 14:58:24 2008 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
++ ChangeLog	20 Jul 2008 14:58:20 -0000
2008-07-20  Wakaba  <wakaba@suika.fam.cx>

	* cc.cgi: Modularized.

	* WebHACC/: New directory.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24