diff options
Diffstat (limited to 'src/cssparser.cc')
-rw-r--r-- | src/cssparser.cc | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc index 1864bd49..69fb6d0b 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1198,17 +1198,91 @@ void CssParser::parseRuleset() nextToken(); } +char * CssParser::parseUrl() { + Dstr *urlStr = NULL; + + if (ttype != CSS_TK_SYMBOL || + dStrcasecmp(tval, "url") != 0) + return NULL; + + nextToken(); + + if (ttype != CSS_TK_CHAR || tval[0] != '(') + return NULL; + + nextToken(); + + if (ttype == CSS_TK_STRING) { + urlStr = dStr_new(tval); + nextToken(); + } else { + urlStr = dStr_new(""); + while (ttype != CSS_TK_END && + (ttype != CSS_TK_CHAR || tval[0] != ')')) { + dStr_append(urlStr, tval); + nextToken(); + } + } + + if (ttype != CSS_TK_CHAR || tval[0] != ')') { + dStr_free(urlStr, 1); + urlStr = NULL; + } + + if (urlStr) { + char *url = urlStr->str; + dStr_free(urlStr, 0); + return url; + } else { + return NULL; + } +} + +void CssParser::parseImport(DilloHtml *html, DilloUrl *baseUrl) { + char *urlStr = NULL; + + if (html != NULL && + ttype == CSS_TK_SYMBOL && + dStrcasecmp(tval, "import") == 0) { + nextToken(); + + if (ttype == CSS_TK_SYMBOL && + dStrcasecmp(tval, "url") == 0) + urlStr = parseUrl(); + else if (ttype == CSS_TK_STRING) + urlStr = dStrdup (tval); + + /* Skip all tokens until the expected end. */ + while (!(ttype == CSS_TK_END || + (ttype == CSS_TK_CHAR && (tval[0] == ';')))) + nextToken(); + + if (urlStr) { + MSG("CssParser::parseImport(): @import %s\n", urlStr); + DilloUrl *url = a_Html_url_new (html, urlStr, a_Url_str(baseUrl), baseUrl ? 1 : 0); + a_Html_load_stylesheet(html, url); + a_Url_free(url); + dFree (urlStr); + } + } +} + const char * CssParser::propertyNameString(CssPropertyName name) { return Css_property_info[name].symbol; } -void CssParser::parse(CssContext * context, +void CssParser::parse(DilloHtml *html, DilloUrl *url, CssContext * context, const char *buf, int buflen, CssOrigin origin) { CssParser parser (context, origin, buf, buflen); + while (parser.ttype == CSS_TK_CHAR && parser.tval[0] == '@') { + parser.nextToken(); + parser.parseImport(html, url); + } + while (parser.ttype != CSS_TK_END) parser.parseRuleset(); } |