changeset 1784:c76b679df50e

CssParser::parseImport(): implement media-conditional @import rules.
author Jeremy Henty <onepoint@starurchin.org>
date Sat, 18 Dec 2010 17:18:13 +0000
parents e9fcbca26b9d
children ef68139142bb
files src/cssparser.cc
diffstat 1 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/cssparser.cc	Sat Dec 18 17:18:13 2010 +0000
+++ b/src/cssparser.cc	Sat Dec 18 17:18:13 2010 +0000
@@ -1423,6 +1423,9 @@
 void CssParser::parseImport(DilloHtml *html, DilloUrl *baseUrl)
 {
    char *urlStr = NULL;
+   bool importSyntaxIsOK = false;
+   bool mediaSyntaxIsOK = true;
+   bool mediaIsSelected = true;
 
    nextToken();
 
@@ -1432,14 +1435,42 @@
    else if (ttype == CSS_TK_STRING)
       urlStr = dStrdup (tval);
 
-   ignoreStatement();
+   nextToken();
+
+   /* parse a comma-separated list of media */
+   if (ttype == CSS_TK_SYMBOL) {
+      mediaSyntaxIsOK = false;
+      mediaIsSelected = false;
+      while (ttype == CSS_TK_SYMBOL) {
+         if (dStrcasecmp(tval, "all") == 0 ||
+             dStrcasecmp(tval, "screen") == 0)
+            mediaIsSelected = true;
+         nextToken();
+         if (ttype == CSS_TK_CHAR && tval[0] == ',') {
+            nextToken();
+         } else {
+            mediaSyntaxIsOK = true;
+            break;
+         }
+      }
+   }
+
+   if (mediaSyntaxIsOK &&
+       ttype == CSS_TK_CHAR &&
+       tval[0] == ';') {
+      importSyntaxIsOK = true;
+      nextToken();
+   } else
+      ignoreStatement();
 
    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);
+      if (importSyntaxIsOK && mediaIsSelected) {
+         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);
    }
 }