Code

moving trunk for module inkscape
[inkscape.git] / src / dom / prop-css2.cpp
1 /**
2  * Phoebe DOM Implementation.
3  *
4  * This is a C++ approximation of the W3C DOM model, which follows
5  * fairly closely the specifications in the various .idl files, copies of
6  * which are provided for reference.  Most important is this one:
7  *
8  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9  *
10  * Authors:
11  *   Bob Jamison
12  *
13  * Copyright (C) 2005 Bob Jamison
14  *
15  *  This library is free software; you can redistribute it and/or
16  *  modify it under the terms of the GNU Lesser General Public
17  *  License as published by the Free Software Foundation; either
18  *  version 2.1 of the License, or (at your option) any later version.
19  *
20  *  This library is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  *  Lesser General Public License for more details.
24  *
25  *  You should have received a copy of the GNU Lesser General Public
26  *  License along with this library; if not, write to the Free Software
27  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28  */
29 #include <stdio.h>
30 #include <string.h>
32 typedef struct CssProp_def CssProp;
34 typedef bool (*parsefunc)(CssProp *prop, char *propName, char *propVal);
37 struct CssProp_def
38 {
39     parsefunc func;
40     char *name;
41     char *values;
42     char *defaultValue;
43     char *appliesTo;
44     bool inherited;
45     char *percentages;
46     char *mediaGroups;
47 };
50 bool parseDefault(CssProp *prop, char *propName, char *propVal)
51 {
52     printf("######## '%s:%s'\n", propName, propVal);
53     return true;
54 }
58 static CssProp cssProps[] =
59 {
61 {
62 parseDefault,
63 "azimuth",
64 "<angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards | inherit",
65 "center",
66 "",
67 true,
68 "",
69 "aural"
70 },
73 {
74 parseDefault,
75 "background-attachment",
76 "scroll | fixed | inherit",
77 "scroll",
78 "",
79 false,
80 "",
81 "visual"
82 },
85 {
86 parseDefault,
87 "background-color",
88 "<color> | transparent | inherit",
89 "transparent",
90 "",
91 false,
92 "",
93 "visual"
94 },
97 {
98 parseDefault,
99 "background-image",
100 "<uri> | none | inherit",
101 "none",
102 "",
103 false,
104 "",
105 "visual"
106 },
110 parseDefault,
111 "background-position",
112 "[ [ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit",
113 "0% 0%",
114 "",
115 false,
116 "refer to the size of the box itself",
117 "visual"
118 },
122 parseDefault,
123 "background-repeat",
124 "repeat | repeat-x | repeat-y | no-repeat | inherit",
125 "repeat",
126 "",
127 false,
128 "",
129 "visual"
130 },
134 parseDefault,
135 "background",
136 "['background-color' || 'background-image' || 'background-repeat' || 'background-attachment' || 'background-position'] | inherit",
137 "see individual properties",
138 "",
139 false,
140 "allowed on 'background-position",
141 "visual"
142 },
146 parseDefault,
147 "border-collapse",
148 "collapse | separate | inherit",
149 "separate",
150 "table' and 'inline-table' elements",
151 true,
152 "",
153 "visual"
154 },
158 parseDefault,
159 "border-color",
160 "[ <color> | transparent ]{1,4} | inherit",
161 "see individual properties",
162 "",
163 false,
164 "",
165 "visual"
166 },
170 parseDefault,
171 "border-spacing",
172 "<length> <length>? | inherit",
173 "0",
174 "table' and 'inline-table' elements",
175 true,
176 "",
177 "visual"
178 },
182 parseDefault,
183 "border-style",
184 "<border-style>{1,4} | inherit",
185 "see individual properties",
186 "",
187 false,
188 "",
189 "visual"
190 },
194 parseDefault,
195 "border-top' 'border-right' 'border-bottom' 'border-left",
196 "[ <border-width> || <border-style> || 'border-top-color' ] | inherit",
197 "see individual properties",
198 "",
199 false,
200 "",
201 "visual"
202 },
206 parseDefault,
207 "border-top-color' 'border-right-color' 'border-bottom-color' 'border-left-color",
208 "<color> | transparent | inherit",
209 "the value of the 'color' property",
210 "",
211 false,
212 "",
213 "visual"
214 },
218 parseDefault,
219 "border-top-style' 'border-right-style' 'border-bottom-style' 'border-left-style",
220 "<border-style> | inherit",
221 "none",
222 "",
223 false,
224 "",
225 "visual"
226 },
230 parseDefault,
231 "border-top-width' 'border-right-width' 'border-bottom-width' 'border-left-width",
232 "<border-width> | inherit",
233 "medium",
234 "",
235 false,
236 "",
237 "visual"
238 },
242 parseDefault,
243 "border-width",
244 "<border-width>{1,4} | inherit",
245 "see individual properties",
246 "",
247 false,
248 "",
249 "visual"
250 },
254 parseDefault,
255 "border",
256 "[ <border-width> || <border-style> || 'border-top-color' ] | inherit",
257 "see individual properties",
258 "",
259 false,
260 "",
261 "visual"
262 },
266 parseDefault,
267 "bottom",
268 "<length> | <percentage> | auto | inherit",
269 "auto",
270 "positioned elements",
271 false,
272 "refer to height of containing block",
273 "visual"
274 },
278 parseDefault,
279 "caption-side",
280 "top | bottom | inherit",
281 "top",
282 "table-caption' elements",
283 true,
284 "",
285 "visual"
286 },
290 parseDefault,
291 "clear",
292 "none | left | right | both | inherit",
293 "none",
294 "block-level elements",
295 false,
296 "",
297 "visual"
298 },
302 parseDefault,
303 "clip",
304 "<shape> | auto | inherit",
305 "auto",
306 "absolutely positioned elements",
307 false,
308 "",
309 "visual"
310 },
314 parseDefault,
315 "color",
316 "<color> | inherit",
317 "depends on user agent",
318 "",
319 true,
320 "",
321 "visual"
322 },
326 parseDefault,
327 "content",
328 "normal | [ <string> | <uri> | <counter> | attr(<identifier>) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit",
329 "normal",
330 ":before and :after pseudo-elements",
331 false,
332 "",
333 "all "
334 },
338 parseDefault,
339 "counter-increment",
340 "[ <identifier> <integer>? ]+ | none | inherit",
341 "none",
342 "",
343 false,
344 "",
345 "all "
346 },
350 parseDefault,
351 "counter-reset",
352 "[ <identifier> <integer>? ]+ | none | inherit",
353 "none",
354 "",
355 false,
356 "",
357 "all "
358 },
362 parseDefault,
363 "cue-after",
364 "<uri> | none | inherit",
365 "none",
366 "",
367 false,
368 "",
369 "aural"
370 },
374 parseDefault,
375 "cue-before",
376 "<uri> | none | inherit",
377 "none",
378 "",
379 false,
380 "",
381 "aural"
382 },
386 parseDefault,
387 "cue",
388 "[ 'cue-before' || 'cue-after' ] | inherit",
389 "see individual properties",
390 "",
391 false,
392 "",
393 "aural"
394 },
398 parseDefault,
399 "cursor",
400 "[ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | text | wait | help | progress ] ] | inherit",
401 "auto",
402 "",
403 true,
404 "",
405 "visual, interactive "
406 },
410 parseDefault,
411 "direction",
412 "ltr | rtl | inherit",
413 "ltr",
414 "all elements, but see prose",
415 true,
416 "",
417 "visual"
418 },
422 parseDefault,
423 "display",
424 "inline | block | list-item | run-in | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit",
425 "inline",
426 "",
427 false,
428 "",
429 "all "
430 },
434 parseDefault,
435 "elevation",
436 "<angle> | below | level | above | higher | lower | inherit",
437 "level",
438 "",
439 true,
440 "",
441 "aural"
442 },
446 parseDefault,
447 "empty-cells",
448 "show | hide | inherit",
449 "show",
450 "table-cell' elements",
451 true,
452 "",
453 "visual"
454 },
458 parseDefault,
459 "float",
460 "left | right | none | inherit",
461 "none",
462 "all, but see 9.7",
463 false,
464 "",
465 "visual"
466 },
470 parseDefault,
471 "font-family",
472 "[[ <family-name> | <generic-family> ] [, <family-name>| <generic-family>]* ] | inherit",
473 "depends on user agent",
474 "",
475 true,
476 "",
477 "visual"
478 },
482 parseDefault,
483 "font-size",
484 "<absolute-size> | <relative-size> | <length> | <percentage> | inherit",
485 "medium",
486 "",
487 true,
488 "refer to parent element's font size",
489 "visual"
490 },
494 parseDefault,
495 "font-style",
496 "normal | italic | oblique | inherit",
497 "normal",
498 "",
499 true,
500 "",
501 "visual"
502 },
506 parseDefault,
507 "font-variant",
508 "normal | small-caps | inherit",
509 "normal",
510 "",
511 true,
512 "",
513 "visual"
514 },
518 parseDefault,
519 "font-weight",
520 "normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit",
521 "normal",
522 "",
523 true,
524 "",
525 "visual"
526 },
530 parseDefault,
531 "font",
532 "[ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit",
533 "see individual properties",
534 "",
535 true,
536 "see individual properties",
537 "visual"
538 },
542 parseDefault,
543 "height",
544 "<length> | <percentage> | auto | inherit",
545 "auto",
546 "all elements but non-replaced inline elements, table columns, and column groups",
547 false,
548 "see prose",
549 "visual"
550 },
554 parseDefault,
555 "left",
556 "<length> | <percentage> | auto | inherit",
557 "auto",
558 "positioned elements",
559 false,
560 "refer to width of containing block",
561 "visual"
562 },
566 parseDefault,
567 "letter-spacing",
568 "normal | <length> | inherit",
569 "normal",
570 "",
571 true,
572 "",
573 "visual"
574 },
578 parseDefault,
579 "line-height",
580 "normal | <number> | <length> | <percentage> | inherit",
581 "normal",
582 "",
583 true,
584 "refer to the font size of the element itself",
585 "visual"
586 },
590 parseDefault,
591 "list-style-image",
592 "<uri> | none | inherit",
593 "none",
594 "elements with 'display: list-item",
595 true,
596 "",
597 "visual"
598 },
602 parseDefault,
603 "list-style-position",
604 "inside | outside | inherit",
605 "outside",
606 "elements with 'display: list-item",
607 true,
608 "",
609 "visual"
610 },
614 parseDefault,
615 "list-style-type",
616 "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | none | inherit",
617 "disc",
618 "elements with 'display: list-item",
619 true,
620 "",
621 "visual"
622 },
626 parseDefault,
627 "list-style",
628 "[ 'list-style-type' || 'list-style-position' || 'list-style-image' ] | inherit",
629 "see individual properties",
630 "elements with 'display: list-item",
631 true,
632 "",
633 "visual"
634 },
638 parseDefault,
639 "margin-right' 'margin-left",
640 "<margin-width> | inherit",
641 "0",
642 "all elements except elements with table display types other than table and inline-table",
643 false,
644 "refer to width of containing block",
645 "visual"
646 },
650 parseDefault,
651 "margin-top' 'margin-bottom",
652 "<margin-width> | inherit",
653 "0",
654 "all elements except elements with table display types other than table and inline-table",
655 false,
656 "refer to width of containing block",
657 "visual"
658 },
662 parseDefault,
663 "margin",
664 "<margin-width>{1,4} | inherit",
665 "see individual properties",
666 "all elements except elements with table display types other than table and inline-table",
667 false,
668 "refer to width of containing block",
669 "visual"
670 },
674 parseDefault,
675 "max-height",
676 "<length> | <percentage> | none | inherit",
677 "none",
678 "all elements except non-replaced inline elements and table elements",
679 false,
680 "see prose",
681 "visual"
682 },
686 parseDefault,
687 "max-width",
688 "<length> | <percentage> | none | inherit",
689 "none",
690 "all elements except non-replaced inline elements and table elements",
691 false,
692 "refer to width of containing block",
693 "visual"
694 },
698 parseDefault,
699 "min-height",
700 "<length> | <percentage> | inherit",
701 "0",
702 "all elements except non-replaced inline elements and table elements",
703 false,
704 "see prose",
705 "visual"
706 },
710 parseDefault,
711 "min-width",
712 "<length> | <percentage> | inherit",
713 "0",
714 "all elements except non-replaced inline elements and table elements",
715 false,
716 "refer to width of containing block",
717 "visual"
718 },
722 parseDefault,
723 "orphans",
724 "<integer> | inherit",
725 "2",
726 "block-level elements",
727 true,
728 "",
729 "visual, paged "
730 },
734 parseDefault,
735 "outline-color",
736 "<color> | invert | inherit",
737 "invert",
738 "",
739 false,
740 "",
741 "visual, interactive "
742 },
746 parseDefault,
747 "outline-style",
748 "<border-style> | inherit",
749 "none",
750 "",
751 false,
752 "",
753 "visual, interactive "
754 },
758 parseDefault,
759 "outline-width",
760 "<border-width> | inherit",
761 "medium",
762 "",
763 false,
764 "",
765 "visual, interactive "
766 },
770 parseDefault,
771 "outline",
772 "[ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit",
773 "see individual properties",
774 "",
775 false,
776 "",
777 "visual, interactive "
778 },
782 parseDefault,
783 "overflow",
784 "visible | hidden | scroll | auto | inherit",
785 "visible",
786 "block-level and replaced elements, table cells, inline blocks",
787 false,
788 "",
789 "visual"
790 },
794 parseDefault,
795 "padding-top' 'padding-right' 'padding-bottom' 'padding-left",
796 "<padding-width> | inherit",
797 "0",
798 "all elements except elements with table display types other than table, inline-table, and table-cell",
799 false,
800 "refer to width of containing block",
801 "visual"
802 },
806 parseDefault,
807 "padding",
808 "<padding-width>{1,4} | inherit",
809 "see individual properties",
810 "all elements except elements with table display types other than table, inline-table, and table-cell",
811 false,
812 "refer to width of containing block",
813 "visual"
814 },
818 parseDefault,
819 "page-break-after",
820 "auto | always | avoid | left | right | inherit",
821 "auto",
822 "block-level elements",
823 false,
824 "",
825 "visual, paged "
826 },
830 parseDefault,
831 "page-break-before",
832 "auto | always | avoid | left | right | inherit",
833 "auto",
834 "block-level elements",
835 false,
836 "",
837 "visual, paged "
838 },
842 parseDefault,
843 "page-break-inside",
844 "avoid | auto | inherit",
845 "auto",
846 "block-level elements",
847 true,
848 "",
849 "visual, paged "
850 },
854 parseDefault,
855 "pause-after",
856 "<time> | <percentage> | inherit",
857 "0",
858 "",
859 false,
860 "see prose",
861 "aural"
862 },
866 parseDefault,
867 "pause-before",
868 "<time> | <percentage> | inherit",
869 "0",
870 "",
871 false,
872 "see prose",
873 "aural"
874 },
878 parseDefault,
879 "pause",
880 "[ [<time> | <percentage>]{1,2} ] | inherit",
881 "see individual properties",
882 "",
883 false,
884 "see descriptions of 'pause-before' and 'pause-after",
885 "aural"
886 },
890 parseDefault,
891 "pitch-range",
892 "<number> | inherit",
893 "50",
894 "",
895 true,
896 "",
897 "aural"
898 },
902 parseDefault,
903 "pitch",
904 "<frequency> | x-low | low | medium | high | x-high | inherit",
905 "medium",
906 "",
907 true,
908 "",
909 "aural"
910 },
914 parseDefault,
915 "play-during",
916 "<uri> [ mix || repeat ]? | auto | none | inherit",
917 "auto",
918 "",
919 false,
920 "",
921 "aural"
922 },
926 parseDefault,
927 "position",
928 "static | relative | absolute | fixed | inherit",
929 "static",
930 "",
931 false,
932 "",
933 "visual"
934 },
938 parseDefault,
939 "quotes",
940 "[<string> <string>]+ | none | inherit",
941 "depends on user agent",
942 "",
943 true,
944 "",
945 "visual"
946 },
950 parseDefault,
951 "richness",
952 "<number> | inherit",
953 "50",
954 "",
955 true,
956 "",
957 "aural"
958 },
962 parseDefault,
963 "right",
964 "<length> | <percentage> | auto | inherit",
965 "auto",
966 "positioned elements",
967 false,
968 "refer to width of containing block",
969 "visual"
970 },
974 parseDefault,
975 "speak-header",
976 "once | always | inherit",
977 "once",
978 "elements that have table header information",
979 true,
980 "",
981 "aural"
982 },
986 parseDefault,
987 "speak-numeral",
988 "digits | continuous | inherit",
989 "continuous",
990 "",
991 true,
992 "",
993 "aural"
994 },
998 parseDefault,
999 "speak-punctuation",
1000 "code | none | inherit",
1001 "none",
1002 "",
1003 true,
1004 "",
1005 "aural"
1006 },
1010 parseDefault,
1011 "speak",
1012 "normal | none | spell-out | inherit",
1013 "normal",
1014 "",
1015 true,
1016 "",
1017 "aural"
1018 },
1022 parseDefault,
1023 "speech-rate",
1024 "<number> | x-slow | slow | medium | fast | x-fast | faster | slower | inherit",
1025 "medium",
1026 "",
1027 true,
1028 "",
1029 "aural"
1030 },
1034 parseDefault,
1035 "stress",
1036 "<number> | inherit",
1037 "50",
1038 "",
1039 true,
1040 "",
1041 "aural"
1042 },
1046 parseDefault,
1047 "table-layout",
1048 "auto | fixed | inherit",
1049 "auto",
1050 "table' and 'inline-table' elements",
1051 false,
1052 "",
1053 "visual"
1054 },
1058 parseDefault,
1059 "text-align",
1060 "left | right | center | justify | inherit",
1061 "left' if 'direction' is 'ltr'; 'right' if 'direction' is 'rtl",
1062 "block-level elements, table cells and inline blocks",
1063 true,
1064 "",
1065 "visual"
1066 },
1070 parseDefault,
1071 "text-decoration",
1072 "none | [ underline || overline || line-through || blink ] | inherit",
1073 "none",
1074 "",
1075 "no (see prose)",
1076 "",
1077 "visual"
1078 },
1082 parseDefault,
1083 "text-indent",
1084 "<length> | <percentage> | inherit",
1085 "0",
1086 "block-level elements, table cells and inline blocks",
1087 true,
1088 "refer to width of containing block",
1089 "visual"
1090 },
1094 parseDefault,
1095 "text-transform",
1096 "capitalize | uppercase | lowercase | none | inherit",
1097 "none",
1098 "",
1099 true,
1100 "",
1101 "visual"
1102 },
1106 parseDefault,
1107 "top",
1108 "<length> | <percentage> | auto | inherit",
1109 "auto",
1110 "positioned elements",
1111 false,
1112 "refer to height of containing block",
1113 "visual"
1114 },
1118 parseDefault,
1119 "unicode-bidi",
1120 "normal | embed | bidi-override | inherit",
1121 "normal",
1122 "all elements, but see prose",
1123 false,
1124 "",
1125 "visual"
1126 },
1130 parseDefault,
1131 "vertical-align",
1132 "baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> | <length> | inherit",
1133 "baseline",
1134 "inline-level and 'table-cell' elements",
1135 false,
1136 "refer to the 'line-height' of the element itself",
1137 "visual"
1138 },
1142 parseDefault,
1143 "visibility",
1144 "visible | hidden | collapse | inherit",
1145 "visible",
1146 "",
1147 true,
1148 "",
1149 "visual"
1150 },
1154 parseDefault,
1155 "voice-family",
1156 "[[<specific-voice> | <generic-voice> ],]* [<specific-voice> | <generic-voice> ] | inherit",
1157 "depends on user agent",
1158 "",
1159 true,
1160 "",
1161 "aural"
1162 },
1166 parseDefault,
1167 "volume",
1168 "<number> | <percentage> | silent | x-soft | soft | medium | loud | x-loud | inherit",
1169 "medium",
1170 "",
1171 true,
1172 "refer to inherited value",
1173 "aural"
1174 },
1178 parseDefault,
1179 "white-space",
1180 "normal | pre | nowrap | pre-wrap | pre-line | inherit",
1181 "normal",
1182 "",
1183 true,
1184 "",
1185 "visual"
1186 },
1190 parseDefault,
1191 "widows",
1192 "<integer> | inherit",
1193 "2",
1194 "block-level elements",
1195 true,
1196 "",
1197 "visual, paged"
1198 },
1202 parseDefault,
1203 "width",
1204 "<length> | <percentage> | auto | inherit",
1205 "auto",
1206 "all elements but non-replaced inline elements, table rows, and row groups",
1207 false,
1208 "refer to width of containing block",
1209 "visual"
1210 },
1214 parseDefault,
1215 "word-spacing",
1216 "normal | <length> | inherit",
1217 "normal",
1218 "",
1219 true,
1220 "",
1221 "visual"
1222 },
1226 parseDefault,
1227 "z-index",
1228 "auto | <integer> | inherit",
1229 "auto",
1230 "positioned elements",
1231 false,
1232 "",
1233 "visual"
1234 },
1237 NULL,
1238 NULL,
1239 NULL,
1240 NULL,
1241 NULL,
1242 false,
1243 NULL,
1244 NULL
1247 };
1251 bool parseProperty(char *name, char *value)
1253     for (CssProp *prop=cssProps; prop->name ; prop++)
1254         {
1255         if (strcmp(name, prop->name)==0)
1256             {
1257             parsefunc func = prop->func;
1258             if (func)
1259                 {
1260                 if (!(*func)(prop, name, value))
1261                     {
1262                     printf("...\n");
1263                     return false;
1264                     }
1265                 else
1266                     {
1267                     return true;
1268                     }
1269                 }
1270             else
1271                 {
1272                 printf("null parsing function specified\n");
1273                 return false;
1274                 }
1275             }
1276         }
1277     printf("Property '%s' not found\n",  name);
1278     return false;
1282 bool printTable()
1284     for (CssProp *prop=cssProps; prop->name ; prop++)
1285         {
1286         printf("#### Prop: %s ####\n", prop->name);
1287         printf("values      : %s\n", prop->values);
1288         printf("defaultValue: %s\n", prop->defaultValue);
1289         printf("appliesTo   : %s\n", prop->appliesTo);
1290         printf("inherited   : %s\n", ( prop->inherited ? "true" : "false" ));
1291         printf("percentages : %s\n", prop->percentages);
1292         printf("groups      : %s\n", prop->mediaGroups);
1293         printf("\n");
1294         }
1295     return true;
1299 int main(int argc, char **argv)
1301     //printTable();
1302     parseProperty("visibility", "hidden");
1303     return 0;