31 #define MSG_CSS(A, ...) MSG(A, __VA_ARGS__) 32 #define DEBUG_TOKEN_LEVEL 0 33 #define DEBUG_PARSE_LEVEL 0 34 #define DEBUG_CREATE_LEVEL 0 36 #define DEBUG_LEVEL 10 39 #define CSS_NUM_INTERNAL_PROPERTIES 3 40 #define CSS_NUM_PARSED_PROPERTIES \ 41 (CSS_PROPERTY_LAST - CSS_NUM_INTERNAL_PROPERTIES) 51 "scroll",
"fixed", NULL
55 "repeat",
"repeat-x",
"repeat-y",
"no-repeat", NULL
59 "separate",
"collapse", NULL
67 "none",
"hidden",
"dotted",
"dashed",
"solid",
"double",
"groove",
68 "ridge",
"inset",
"outset", NULL
72 "thin",
"medium",
"thick", NULL
76 "crosshair",
"default",
"pointer",
"move",
"e-resize",
"ne-resize",
77 "nw-resize",
"n-resize",
"se-resize",
"sw-resize",
"s-resize",
78 "w-resize",
"text",
"wait",
"help", NULL
82 "block",
"inline",
"inline-block",
"list-item",
"none",
"table",
83 "table-row-group",
"table-header-group",
"table-footer-group",
"table-row",
88 "large",
"larger",
"medium",
"small",
"smaller",
"xx-large",
"xx-small",
89 "x-large",
"x-small", NULL
93 "normal",
"italic",
"oblique", NULL
97 "normal",
"small-caps", NULL
101 "bold",
"bolder",
"light",
"lighter",
"normal", NULL
109 "inside",
"outside", NULL
117 "disc",
"circle",
"square",
"decimal",
"decimal-leading-zero",
118 "lower-roman",
"upper-roman",
"lower-greek",
"lower-alpha",
119 "lower-latin",
"upper-alpha",
"upper-latin",
"hebrew",
"armenian",
120 "georgian",
"cjk-ideographic",
"hiragana",
"katakana",
"hiragana-iroha",
121 "katakana-iroha",
"none", NULL
125 "left",
"right",
"center",
"justify",
"string", NULL
129 "underline",
"overline",
"line-through",
"blink", NULL
133 "none",
"capitalize",
"uppercase",
"lowercase", NULL
137 "top",
"bottom",
"middle",
"baseline",
"sub",
"super",
"text-top",
142 "normal",
"pre",
"nowrap",
"pre-wrap",
"pre-line", NULL
430 #define CSS_SHORTHAND_NUM \ 431 (sizeof(Css_shorthand_info) / sizeof(Css_shorthand_info[0])) 439 const char *buf,
int buflen)
441 this->context = context;
442 this->origin = origin;
444 this->buflen = buflen;
446 this->spaceSeparated =
false;
447 this->withinBlock =
false;
448 this->baseUrl = baseUrl;
460 if (bufptr >= buflen)
487 for (
int n = 0; str[n]; n++) {
508 spaceSeparated =
false;
513 spaceSeparated =
true;
514 }
else if (skipString(c,
"/*")) {
517 }
while (c != EOF && ! skipString(c,
"*/"));
518 }
else if (skipString(c,
"<!--")) {
519 }
else if (skipString(c,
"-->")) {
527 if (i < maxStrLen - 1)
533 ttype = CSS_TK_DECINT;
535 if (i < maxStrLen - 1) {
540 }
while (isdigit(c));
550 ttype = CSS_TK_FLOAT;
551 if (i < maxStrLen - 1)
554 if (i < maxStrLen - 1)
558 }
while (isdigit(c));
566 if (ttype == CSS_TK_DECINT) {
574 if (ttype == CSS_TK_DECINT) {
586 if (isalpha(c) || c ==
'_' || c ==
'-') {
587 ttype = CSS_TK_SYMBOL;
592 while (isalnum(c) || c ==
'_' || c ==
'-') {
593 if (i < maxStrLen - 1) {
605 if (c ==
'"' || c ==
'\'') {
607 ttype = CSS_TK_STRING;
612 while (c != EOF && c != c1) {
621 while (j < 4 && isxdigit(d)) {
628 c = strtol(hexbuf, NULL, 16);
635 if (i < maxStrLen - 1) {
650 if (c ==
'#' && withinBlock) {
651 ttype = CSS_TK_COLOR;
656 while (isxdigit(c)) {
657 if (i < maxStrLen - 1) {
693 if (ttype == CSS_TK_SYMBOL) {
702 if (ttype == CSS_TK_SYMBOL) {
716 if (ttype == CSS_TK_SYMBOL &&
731 if (ttype == CSS_TK_DECINT || ttype == CSS_TK_FLOAT)
741 if ((ttype == CSS_TK_COLOR ||
742 ttype == CSS_TK_SYMBOL) &&
749 if (ttype == CSS_TK_STRING)
754 if (ttype == CSS_TK_SYMBOL ||
755 ttype == CSS_TK_STRING)
760 if (ttype == CSS_TK_DECINT) {
761 i = strtol(tval, NULL, 10);
762 if (i >= 100 && i <= 900)
768 if (ttype == CSS_TK_SYMBOL &&
787 if (ttype != CSS_TK_DECINT) {
788 MSG_CSS(
"expected integer not found in %s color\n",
"rgb");
792 *cc = strtol(tval, NULL, 10);
795 if (ttype == CSS_TK_CHAR && tval[0] ==
'%') {
796 if (*percentage == 0) {
797 MSG_CSS(
"'%s' unexpected in rgb color\n",
"%");
801 *cc = *cc * 255 / 100;
804 if (*percentage == 1) {
805 MSG_CSS(
"expected '%s' not found in rgb color\n",
"%");
825 if (ttype != CSS_TK_CHAR || tval[0] !=
'(') {
826 MSG_CSS(
"expected '%s' not found in rgb color\n",
"(");
831 if (!parseRgbColorComponent(&cc, &percentage))
835 if (ttype != CSS_TK_CHAR || tval[0] !=
',') {
836 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
841 if (!parseRgbColorComponent(&cc, &percentage))
845 if (ttype != CSS_TK_CHAR || tval[0] !=
',') {
846 MSG_CSS(
"expected '%s' not found in rgb color\n",
",");
851 if (!parseRgbColorComponent(&cc, &percentage))
855 if (ttype != CSS_TK_CHAR || tval[0] !=
')') {
856 MSG_CSS(
"expected '%s' not found in rgb color\n",
")");
868 bool found, ret =
false;
870 int i, ival, err = 1;
875 if (ttype == CSS_TK_SYMBOL) {
891 while (ttype == CSS_TK_SYMBOL) {
893 for (i = 0, found =
false;
908 if (ttype == CSS_TK_DECINT || ttype == CSS_TK_FLOAT) {
913 if (!spaceSeparated && ttype == CSS_TK_SYMBOL) {
947 }
else if (!spaceSeparated &&
950 ttype == CSS_TK_CHAR &&
977 if (ttype == CSS_TK_COLOR) {
980 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
984 }
else if (ttype == CSS_TK_SYMBOL) {
987 if (parseRgbColor(&val->
intVal))
990 MSG_CSS(
"Failed to parse %s color\n",
"rgb(r,g,b)");
994 MSG_CSS(
"color is not in \"%s\" format\n",
"#RRGGBB");
1003 if (ttype == CSS_TK_STRING) {
1013 while (ttype == CSS_TK_SYMBOL || ttype == CSS_TK_STRING ||
1014 (ttype == CSS_TK_CHAR && tval[0] ==
',')) {
1032 if (ttype == CSS_TK_DECINT) {
1033 ival = strtol(tval, NULL, 10);
1034 if (ival < 100 || ival > 900)
1047 if (ttype == CSS_TK_SYMBOL &&
1049 val->
strVal = parseUrl();
1065 h[0] = v[0] = h[1] = v[1] =
false;
1070 for (i = 0; i < 2; i++) {
1076 h[i] = ttype != CSS_TK_SYMBOL ||
1079 v[i] = ttype != CSS_TK_SYMBOL ||
1084 h[i] = v[i] =
false;
1088 if (ttype == CSS_TK_SYMBOL) {
1111 h[i] = v[i] =
false;
1124 if (!h[1] && !v[1]) {
1130 if ((h[0] && v[1]) || (v[0] && h[1])) {
1162 if (ttype == CSS_TK_CHAR && tval[0] ==
'!') {
1164 if (ttype == CSS_TK_SYMBOL &&
1204 int sh_index, i, j, n;
1205 int dir_set[4][4] = {
1212 if (ttype == CSS_TK_SYMBOL) {
1222 if (ttype == CSS_TK_CHAR && tval[0] ==
':') {
1224 if (tokenMatchesProperty (prop, &type) &&
1225 parseValue(prop, type, &val)) {
1226 weight = parseWeight();
1227 if (weight && importantProps)
1228 importantProps->
set(prop, type, val);
1230 props->
set(prop, type, val);
1243 if (ttype == CSS_TK_CHAR && tval[0] ==
':') {
1252 for (found =
false, i = 0;
1258 properties[i], &type)) {
1261 "will assign to '%s'\n",
1264 .properties[i]].symbol);
1266 .properties[i], type, &val)) {
1267 weight = parseWeight();
1268 if (weight && importantProps)
1271 properties[i], type, val);
1274 properties[i], type, val);
1284 properties[0], &type) &&
1286 .properties[0], type, &val)) {
1288 dir_types[n] = type;
1294 weight = parseWeight();
1296 for (i = 0; i < 4; i++)
1297 if (weight && importantProps)
1300 dir_types[dir_set[n - 1][i]],
1301 dir_vals[dir_set[n - 1][i]]);
1305 dir_types[dir_set[n - 1][i]],
1306 dir_vals[dir_set[n - 1][i]]);
1308 MSG_CSS(
"no values for shorthand property '%s'\n",
1315 for (found =
false, i = 0;
1319 properties[i], &type)) {
1322 .properties[i], type, &val)) {
1323 weight = parseWeight();
1324 for (j = 0; j < 4; j++)
1325 if (weight && importantProps)
1328 properties[j * 3 + i], type, val);
1331 properties[j * 3 + i], type, val);
1343 while (!(ttype == CSS_TK_END ||
1344 (ttype == CSS_TK_CHAR &&
1345 (tval[0] ==
';' || tval[0] ==
'}'))))
1348 if (ttype == CSS_TK_CHAR && tval[0] ==
';')
1356 if (ttype == CSS_TK_SYMBOL) {
1361 }
else if (ttype == CSS_TK_CHAR && tval[0] ==
'*') {
1366 }
else if (ttype == CSS_TK_CHAR &&
1377 if (ttype == CSS_TK_CHAR) {
1403 if (ttype == CSS_TK_SYMBOL) {
1415 selector->
id, selector->
klass,
1426 if (! parseSimpleSelector (selector->
top ())) {
1432 if (ttype == CSS_TK_CHAR &&
1433 (tval[0] ==
',' || tval[0] ==
'{')) {
1435 }
else if (ttype == CSS_TK_CHAR && tval[0] ==
'>') {
1438 }
else if (ttype == CSS_TK_CHAR && tval[0] ==
'+') {
1441 }
else if (ttype != CSS_TK_END && spaceSeparated) {
1450 while (ttype != CSS_TK_END &&
1451 (ttype != CSS_TK_CHAR ||
1452 (tval[0] !=
',' && tval[0] !=
'{')))
1467 selector = parseSelector();
1472 list->
set(list->
size() - 1, selector);
1479 if (ttype == CSS_TK_CHAR && tval[0] ==
',')
1492 importantProps->
ref();
1495 if (ttype != CSS_TK_END) {
1499 parseDeclaration(props, importantProps);
1500 while (!(ttype == CSS_TK_END ||
1501 (ttype == CSS_TK_CHAR && tval[0] ==
'}')));
1502 withinBlock =
false;
1505 for (
int i = 0; i < list->
size(); i++) {
1522 importantProps->
unref();
1526 if (ttype == CSS_TK_CHAR && tval[0] ==
'}')
1532 Dstr *urlStr = NULL;
1534 if (ttype != CSS_TK_SYMBOL ||
1540 if (ttype != CSS_TK_CHAR || tval[0] !=
'(')
1545 if (ttype == CSS_TK_STRING) {
1550 while (ttype != CSS_TK_END &&
1551 (ttype != CSS_TK_CHAR || tval[0] !=
')')) {
1557 if (ttype != CSS_TK_CHAR || tval[0] !=
')') {
1575 char *urlStr = NULL;
1576 bool importSyntaxIsOK =
false;
1577 bool mediaSyntaxIsOK =
true;
1578 bool mediaIsSelected =
true;
1582 if (ttype == CSS_TK_SYMBOL &&
1584 urlStr = parseUrl();
1585 else if (ttype == CSS_TK_STRING)
1591 if (ttype == CSS_TK_SYMBOL) {
1592 mediaSyntaxIsOK =
false;
1593 mediaIsSelected =
false;
1594 while (ttype == CSS_TK_SYMBOL) {
1597 mediaIsSelected =
true;
1599 if (ttype == CSS_TK_CHAR && tval[0] ==
',') {
1602 mediaSyntaxIsOK =
true;
1608 if (mediaSyntaxIsOK &&
1609 ttype == CSS_TK_CHAR &&
1611 importSyntaxIsOK =
true;
1617 if (importSyntaxIsOK && mediaIsSelected) {
1618 MSG(
"CssParser::parseImport(): @import %s\n", urlStr);
1620 this->baseUrl ? 1 : 0);
1630 bool mediaSyntaxIsOK =
false;
1631 bool mediaIsSelected =
false;
1636 while (ttype == CSS_TK_SYMBOL) {
1639 mediaIsSelected =
true;
1641 if (ttype == CSS_TK_CHAR && tval[0] ==
',') {
1644 mediaSyntaxIsOK =
true;
1650 if (!(mediaSyntaxIsOK &&
1651 ttype == CSS_TK_CHAR &&
1658 if (mediaIsSelected) {
1660 while (ttype != CSS_TK_END) {
1662 if (ttype == CSS_TK_CHAR && tval[0] ==
'}') {
1680 while (ttype != CSS_TK_END) {
1681 if (ttype == CSS_TK_CHAR) {
1682 if (tval[0] ==
'{') {
1684 }
else if (tval[0] ==
'}') {
1698 while (ttype != CSS_TK_END) {
1699 if (ttype == CSS_TK_CHAR) {
1700 if (tval[0] ==
';') {
1703 }
else if (tval[0] ==
'{') {
1717 CssParser parser (context, origin, baseUrl, buf, buflen);
1718 bool importsAreAllowed =
true;
1720 while (parser.
ttype != CSS_TK_END) {
1721 if (parser.
ttype == CSS_TK_CHAR &&
1722 parser.
tval[0] ==
'@') {
1724 if (parser.
ttype == CSS_TK_SYMBOL) {
1727 importsAreAllowed) {
1738 importsAreAllowed =
false;
1745 const char *buf,
int buflen,
1755 while (!(parser.
ttype == CSS_TK_END ||
1756 (parser.
ttype == CSS_TK_CHAR && parser.
tval[0] ==
'}')));