changeset 1017:181a53d66446

allow negative values for specific CSS properties only This needs to be done at parser level, so that alternative settings can overrule a faulty negative one. Testcase: <html> <head> <style type="text/css" > #foo {padding: -1px; background-color: green} .bar {padding: 10px} </style> </head> <body> <div id="foo" class="bar">should be green and have 10px padding</div> </body> </html>
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 23 Mar 2009 10:13:53 +0100
parents e8e70f16e010
children 1949cc16378f
files ChangeLog src/css.hh src/cssparser.cc
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 23 09:51:18 2009 +0100
+++ b/ChangeLog	Mon Mar 23 10:13:53 2009 +0100
@@ -75,6 +75,7 @@
  - Add support for negative numbers in CSS parser.
  - Fix allow_white_bg dillorc option.
  - Load <style></style> content only if applicable.
+ - Allow negative values for specific CSS properties only.
    Patches: Johannes Hofmann
 +- Updated the GPL copyright note in the source files.
    Patch: Detlef Riekenberg
--- a/src/css.hh	Mon Mar 23 09:51:18 2009 +0100
+++ b/src/css.hh	Mon Mar 23 10:13:53 2009 +0100
@@ -35,6 +35,7 @@
                                    only because Dw cannot handle percentages
                                    in this particular case (e.g.
                                    'margin-*-width'). */
+   CSS_TYPE_SIGNED_LENGTH,      /* As CSS_TYPE_LENGTH but may be negative. */
    CSS_TYPE_COLOR,              /* Represented as integer. */
    CSS_TYPE_FONT_WEIGHT,        /* this very special and only used by
                                    'font-weight' */
--- a/src/cssparser.cc	Mon Mar 23 09:51:18 2009 +0100
+++ b/src/cssparser.cc	Mon Mar 23 10:13:53 2009 +0100
@@ -148,10 +148,10 @@
    {"list-style-image", {CSS_TYPE_UNUSED}, NULL},
    {"list-style-position", {CSS_TYPE_UNUSED}, NULL},
    {"list-style-type", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED}, Css_list_style_type_enum_vals},
-   {"margin-bottom", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
-   {"margin-left", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
-   {"margin-right", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
-   {"margin-top", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"margin-bottom", {CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"margin-left", {CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"margin-right", {CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"margin-top", {CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED}, NULL},
    {"marker-offset", {CSS_TYPE_UNUSED}, NULL},
    {"marks", {CSS_TYPE_UNUSED}, NULL},
    {"max-height", {CSS_TYPE_UNUSED}, NULL},
@@ -622,6 +622,10 @@
 
          case CSS_TYPE_LENGTH_PERCENTAGE:
          case CSS_TYPE_LENGTH:
+            if  (tval[0] == '-')
+               return false;
+            // Fall Through
+         case CSS_TYPE_SIGNED_LENGTH:
             if (ttype == CSS_TK_DECINT ||
                 ttype == CSS_TK_FLOAT ||
                 (ttype == CSS_TK_SYMBOL && dStrcasecmp(tval, "auto") == 0))
@@ -709,6 +713,7 @@
 
    case CSS_TYPE_LENGTH_PERCENTAGE:
    case CSS_TYPE_LENGTH:
+   case CSS_TYPE_SIGNED_LENGTH:
       if (ttype == CSS_TK_DECINT || ttype == CSS_TK_FLOAT) {
          fval = atof(tval);
          lentype = CSS_LENGTH_TYPE_PX;  /* Actually, there must be a unit,