changeset 1768:81876ff46376

imported patch ignore-unknown-at-rules-1
author Jeremy Henty <onepoint@starurchin.org>
date Sun, 21 Nov 2010 21:11:37 +0000
parents 1bccd1243740
children c43a79252d10
files src/cssparser.cc src/cssparser.hh
diffstat 2 files changed, 56 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/cssparser.cc	Sun Nov 21 21:11:37 2010 +0000
+++ b/src/cssparser.cc	Sun Nov 21 21:11:37 2010 +0000
@@ -1443,25 +1443,70 @@
 {
    return Css_property_info[name].symbol;
 }
+ 
+void CssParser::ignoreBlock()
+{
+   int depth = 0;
+
+   while (ttype != CSS_TK_END) {
+      if (ttype == CSS_TK_CHAR) {
+         if (tval[0] =='{')
+            depth++;
+         else if (tval[0] =='}') {
+            depth--;
+            if (depth == 0) {
+               nextToken();
+               return;
+            }
+         }
+      }
+      nextToken();
+   }
+}
+
+void CssParser::ignoreStatement()
+{
+   while (ttype != CSS_TK_END) {
+      if (ttype == CSS_TK_CHAR) {
+         if (tval[0] == ';') {
+            nextToken();
+            return;
+         }
+         else if (tval[0] =='{') {
+            ignoreBlock();
+            return;
+         }
+      }
+      nextToken();
+   }
+}
 
 void CssParser::parse(DilloHtml *html, DilloUrl *url, CssContext * context,
                       const char *buf,
                       int buflen, CssOrigin origin)
 {
    CssParser parser (context, origin, buf, buflen);
+   bool importsAreAllowed = true;
 
-   while (parser.ttype == CSS_TK_CHAR && parser.tval[0] == '@') {
-      parser.nextToken();
-      if (html != NULL &&
-          parser.ttype == CSS_TK_SYMBOL &&
-          dStrcasecmp(parser.tval, "import") == 0) {
+   while (parser.ttype != CSS_TK_END) {
+      if (parser.ttype == CSS_TK_CHAR &&
+          parser.tval[0] == '@') {
          parser.nextToken();
-         parser.parseImport(html, url);
+         if (parser.ttype == CSS_TK_SYMBOL &&
+             dStrcasecmp(parser.tval, "import") == 0 &&
+             html != NULL &&
+             importsAreAllowed) {
+            parser.nextToken();
+            parser.parseImport(html, url);
+         }
+         else
+            parser.ignoreStatement();
+      }
+      else {
+         importsAreAllowed = false;
+         parser.parseRuleset();
       }
    }
-
-   while (parser.ttype != CSS_TK_END)
-      parser.parseRuleset();
 }
 
 CssPropertyList *CssParser::parseDeclarationBlock(const char *buf, int buflen)
--- a/src/cssparser.hh	Sun Nov 21 21:11:37 2010 +0000
+++ b/src/cssparser.hh	Sun Nov 21 21:11:37 2010 +0000
@@ -42,6 +42,8 @@
       void parseImport(DilloHtml *html, DilloUrl *url);
       CssSelector *parseSelector();
       void parseRuleset();
+      void ignoreBlock();
+      void ignoreStatement();
 
    public:
       static CssPropertyList *parseDeclarationBlock(const char *buf,