changeset 1472:6ed936726b50

support border-width: thin | medium | thick
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Fri, 18 Dec 2009 22:23:30 +0100
parents 7fc6e6dca086
children 87a7d28d4c7d
files src/css.hh src/cssparser.cc src/styleengine.cc src/styleengine.hh
diffstat 4 files changed, 45 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.hh	Thu Dec 17 21:38:38 2009 +0100
+++ b/src/css.hh	Fri Dec 18 22:23:30 2009 +0100
@@ -230,6 +230,12 @@
 } CssPropertyValue;
 
 typedef enum {
+   CSS_BORDER_WIDTH_THIN,
+   CSS_BORDER_WIDTH_MEDIUM,
+   CSS_BORDER_WIDTH_THICK,
+} CssBorderWidthExtensions;
+
+typedef enum {
    CSS_FONT_WEIGHT_BOLD,
    CSS_FONT_WEIGHT_BOLDER,
    CSS_FONT_WEIGHT_LIGHT,
--- a/src/cssparser.cc	Thu Dec 17 21:38:38 2009 +0100
+++ b/src/cssparser.cc	Fri Dec 18 22:23:30 2009 +0100
@@ -52,6 +52,10 @@
    "ridge", "inset", "outset", NULL
 };
 
+static const char *const Css_border_width_enum_vals[] = {
+   "thin", "medium", "thick", NULL
+};
+
 static const char *const Css_cursor_enum_vals[] = {
    "crosshair", "default", "pointer", "move", "e-resize", "ne-resize",
    "nw-resize", "n-resize", "se-resize", "sw-resize", "s-resize",
@@ -118,21 +122,25 @@
    {"border-bottom-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
    {"border-bottom-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
     Css_border_style_enum_vals},
-   {"border-bottom-width", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"border-bottom-width", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
+    Css_border_width_enum_vals},
    {"border-collapse", {CSS_TYPE_UNUSED}, NULL},
    {"border-left-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
    {"border-left-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
     Css_border_style_enum_vals},
-   {"border-left-width", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"border-left-width", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
+    Css_border_width_enum_vals},
    {"border-right-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
    {"border-right-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
     Css_border_style_enum_vals},
-   {"border-right-width", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"border-rigth-width", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
+    Css_border_width_enum_vals},
    {"border-spacing", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
    {"border-top-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
    {"border-top-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
     Css_border_style_enum_vals},
-   {"border-top-width", {CSS_TYPE_LENGTH, CSS_TYPE_UNUSED}, NULL},
+   {"border-top-width", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
+    Css_border_width_enum_vals},
    {"bottom", {CSS_TYPE_UNUSED}, NULL},
    {"caption-side", {CSS_TYPE_UNUSED}, NULL},
    {"clear", {CSS_TYPE_UNUSED}, NULL},
--- a/src/styleengine.cc	Thu Dec 17 21:38:38 2009 +0100
+++ b/src/styleengine.cc	Fri Dec 18 22:23:30 2009 +0100
@@ -386,20 +386,16 @@
             attrs->borderStyle.top = (BorderStyle) p->value.intVal;
             break;
          case CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
-            computeValue (&attrs->borderWidth.bottom, p->value.intVal,
-                          attrs->font);
+            computeBorderWidth (&attrs->borderWidth.bottom, p, attrs->font);
             break;
          case CSS_PROPERTY_BORDER_LEFT_WIDTH:
-            computeValue (&attrs->borderWidth.left, p->value.intVal,
-                          attrs->font);
+            computeBorderWidth (&attrs->borderWidth.left, p, attrs->font);
             break;
          case CSS_PROPERTY_BORDER_RIGHT_WIDTH:
-            computeValue (&attrs->borderWidth.right, p->value.intVal,
-                          attrs->font);
+            computeBorderWidth (&attrs->borderWidth.right, p, attrs->font);
             break;
          case CSS_PROPERTY_BORDER_TOP_WIDTH:
-            computeValue (&attrs->borderWidth.top, p->value.intVal,
-                          attrs->font);
+            computeBorderWidth (&attrs->borderWidth.top, p, attrs->font);
             break;
          case CSS_PROPERTY_BORDER_SPACING:
             computeValue (&attrs->hBorderSpacing, p->value.intVal,attrs->font);
@@ -552,6 +548,27 @@
    return false;
 }
 
+void StyleEngine::computeBorderWidth (int *dest, CssProperty *p,
+                                      dw::core::style::Font *font) {
+   if (p->type == CSS_TYPE_ENUM) {
+      switch (p->value.intVal) {
+         case CSS_BORDER_WIDTH_THIN:
+            *dest = 1;
+            break;
+         case CSS_BORDER_WIDTH_MEDIUM:
+            *dest = 2;
+            break;
+         case CSS_BORDER_WIDTH_THICK:
+            *dest = 3;
+            break;
+         default:
+            assert(false);
+      }
+   } else {
+      computeValue (dest, p->value.intVal, font);
+   }
+}
+
 /**
  * \brief Similar to StyleEngine::style(), but with backgroundColor set.
  * A normal style might have backgroundColor == NULL to indicate a transparent
--- a/src/styleengine.hh	Thu Dec 17 21:38:38 2009 +0100
+++ b/src/styleengine.hh	Fri Dec 18 22:23:30 2009 +0100
@@ -42,6 +42,8 @@
                          dw::core::style::Font *font, int percentageBase);
       bool computeLength (dw::core::style::Length *dest, CssLength value,
                           dw::core::style::Font *font);
+      void computeBorderWidth (int *dest, CssProperty *p,
+                               dw::core::style::Font *font);
 
    public:
       StyleEngine (dw::core::Layout *layout);