summaryrefslogtreecommitdiff
path: root/src/cssparser.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-06-23 21:20:13 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-06-23 21:20:13 +0200
commit6adce2371510f37725f26eb3279cd65c9bfd5b26 (patch)
treedd374762b8d206f6dca504e6020e226f30da42bd /src/cssparser.cc
parent9c4e99c6776437e0d4f7d98296c772c04532b392 (diff)
add support for css colors of the form rgb(255, 255, 255)
Diffstat (limited to 'src/cssparser.cc')
-rw-r--r--src/cssparser.cc89
1 files changed, 83 insertions, 6 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc
index 073faa3e..9bc10215 100644
--- a/src/cssparser.cc
+++ b/src/cssparser.cc
@@ -643,7 +643,8 @@ bool CssParser::tokenMatchesProperty(CssPropertyName prop, CssValueType * type)
case CSS_TYPE_COLOR:
if ((ttype == CSS_TK_COLOR ||
ttype == CSS_TK_SYMBOL) &&
- a_Color_parse(tval, -1, &err) != -1)
+ (dStrcasecmp(tval, "rgb") == 0 ||
+ a_Color_parse(tval, -1, &err) != -1))
return true;
break;
@@ -679,6 +680,74 @@ bool CssParser::tokenMatchesProperty(CssPropertyName prop, CssValueType * type)
return false;
}
+bool CssParser::parseRgbColorComponent(int32_t *cc) {
+ if (ttype != CSS_TK_DECINT) {
+ MSG_CSS("expected integer not found in %s color\n", "rgb");
+ return false;
+ }
+
+ *cc = strtol(tval, NULL, 10);
+
+ nextToken();
+ if (ttype == CSS_TK_CHAR && tval[0] == '%') {
+ *cc = *cc * 255 / 100;
+ nextToken();
+ }
+
+ if (*cc > 255)
+ *cc = 255;
+ if (*cc < 0)
+ *cc = 0;
+
+ return true;
+}
+
+bool CssParser::parseRgbColor(int32_t *c) {
+ int32_t cc;
+
+ *c = 0;
+
+ if (ttype != CSS_TK_CHAR || tval[0] != '(') {
+ MSG_CSS("expected '%s' not found in rgb color\n", "(");
+ return false;
+ }
+
+ nextToken();
+ if (!parseRgbColorComponent(&cc))
+ return false;
+
+ *c |= cc;
+
+ if (ttype != CSS_TK_CHAR || tval[0] != ',') {
+ MSG_CSS("expected '%s' not found in rgb color\n", ",");
+ return false;
+ }
+
+ nextToken();
+ if (!parseRgbColorComponent(&cc))
+ return false;
+
+ *c |= cc << 8;
+
+ if (ttype != CSS_TK_CHAR || tval[0] != ',') {
+ MSG_CSS("expected '%s' not found in rgb color\n", ",");
+ return false;
+ }
+
+ nextToken();
+ if (!parseRgbColorComponent(&cc))
+ return false;
+
+ *c |= cc << 16;
+
+ if (ttype != CSS_TK_CHAR || tval[0] != ')') {
+ MSG_CSS("expected '%s' not found in rgb color\n", ")");
+ return false;
+ }
+
+ return true;
+}
+
bool CssParser::parseValue(CssPropertyName prop,
CssValueType type,
CssPropertyValue * val)
@@ -785,11 +854,19 @@ bool CssParser::parseValue(CssPropertyName prop,
ret = true;
nextToken();
} else if (ttype == CSS_TK_SYMBOL) {
- val->intVal = a_Color_parse(tval, -1, &err);
- if (err)
- MSG_CSS("color is not in \"%s\" format\n", "#RRGGBB");
- else
- ret = true;
+ if (dStrcasecmp(tval, "rgb") == 0) {
+ nextToken();
+ if (parseRgbColor(&val->intVal))
+ ret = true;
+ else
+ MSG_CSS("Failed to parse %s color\n", "rgb(r,g,b)");
+ } else {
+ val->intVal = a_Color_parse(tval, -1, &err);
+ if (err)
+ MSG_CSS("color is not in \"%s\" format\n", "#RRGGBB");
+ else
+ ret = true;
+ }
nextToken();
}
break;