changeset 1772:d3eb50e48d9d

Support @media rules.
author Jeremy Henty <onepoint@starurchin.org>
date Fri, 26 Nov 2010 11:07:10 +0000
parents 47ae467a64e0
children cbdb75544a74
files src/cssparser.cc src/cssparser.hh
diffstat 2 files changed, 56 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/cssparser.cc	Thu Nov 25 16:49:14 2010 +0100
+++ b/src/cssparser.cc	Fri Nov 26 11:07:10 2010 +0000
@@ -1439,6 +1439,48 @@
    }
 }
 
+void CssParser::parseMedia()
+{
+   bool mediaSyntaxIsOK = false;
+   bool mediaIsSelected = false;
+
+   /* parse a comma-separated list of media */
+   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;
+      }
+   }
+
+   /* check that the syntax is OK so far */
+   if (!(mediaSyntaxIsOK &&
+         ttype == CSS_TK_CHAR &&
+         tval[0] == '{')) {
+      ignoreStatement();
+      return;
+   }
+
+   /* parse/ignore the block as required */
+   if (mediaIsSelected) {
+      nextToken();
+      while (ttype != CSS_TK_END) {
+         parseRuleset();
+         if (ttype == CSS_TK_CHAR && tval[0] == '}') {
+            nextToken();
+            break;
+         }
+      }
+   }
+   else
+      ignoreBlock();
+}
+
 const char * CssParser::propertyNameString(CssPropertyName name)
 {
    return Css_property_info[name].symbol;
@@ -1492,12 +1534,19 @@
       if (parser.ttype == CSS_TK_CHAR &&
           parser.tval[0] == '@') {
          parser.nextToken();
-         if (parser.ttype == CSS_TK_SYMBOL &&
-             dStrcasecmp(parser.tval, "import") == 0 &&
-             html != NULL &&
-             importsAreAllowed) {
-            parser.nextToken();
-            parser.parseImport(html, url);
+         if (parser.ttype == CSS_TK_SYMBOL) {
+            if (dStrcasecmp(parser.tval, "import") == 0 &&
+                html != NULL &&
+                importsAreAllowed) {
+               parser.nextToken();
+               parser.parseImport(html, url);
+            }
+            else if (dStrcasecmp(parser.tval, "media") == 0) {
+               parser.nextToken();
+               parser.parseMedia();
+            }
+            else
+               parser.ignoreStatement();
          }
          else
             parser.ignoreStatement();
--- a/src/cssparser.hh	Thu Nov 25 16:49:14 2010 +0100
+++ b/src/cssparser.hh	Fri Nov 26 11:07:10 2010 +0000
@@ -40,6 +40,7 @@
       bool parseSimpleSelector(CssSimpleSelector *selector);
       char *parseUrl();
       void parseImport(DilloHtml *html, DilloUrl *url);
+      void parseMedia();
       CssSelector *parseSelector();
       void parseRuleset();
       void ignoreBlock();