changeset 1758:ed0b2be9c06d

merge
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 24 Oct 2010 15:00:36 -0300
parents 7874398eb633 (current diff) c75d0b8f71fc (diff)
children d247a3e0d41a cbca357af616
files
diffstat 6 files changed, 95 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dw/style.cc	Thu Oct 21 21:03:47 2010 +0200
+++ b/dw/style.cc	Sun Oct 24 15:00:36 2010 -0300
@@ -49,6 +49,8 @@
    margin.setVal (0);
    borderWidth.setVal (0);
    padding.setVal (0);
+   borderCollapse = BORDER_MODEL_SEPARATE;
+   collapseStyleSet = false;
    setBorderColor (NULL);
    setBorderStyle (BORDER_NONE);
    hBorderSpacing = 0;
@@ -123,6 +125,8 @@
        margin.equals (&otherAttrs->margin) &&
        borderWidth.equals (&otherAttrs->borderWidth) &&
        padding.equals (&otherAttrs->padding) &&
+       borderCollapse == otherAttrs->borderCollapse &&
+       collapseStyleSet == otherAttrs->collapseStyleSet &&
        borderColor.top == otherAttrs->borderColor.top &&
        borderColor.right == otherAttrs->borderColor.right &&
        borderColor.bottom == otherAttrs->borderColor.bottom &&
@@ -158,6 +162,8 @@
       margin.hashValue () +
       borderWidth.hashValue () +
       padding.hashValue () +
+      borderCollapse +
+      collapseStyleSet +
       (intptr_t) borderColor.top +
       (intptr_t) borderColor.right +
       (intptr_t) borderColor.bottom  +
@@ -246,6 +252,8 @@
    margin = attrs->margin;
    borderWidth = attrs->borderWidth;
    padding = attrs->padding;
+   borderCollapse = attrs->borderCollapse;
+   collapseStyleSet = attrs->collapseStyleSet;
    borderColor = attrs->borderColor;
    borderStyle = attrs->borderStyle;
    display = attrs->display;
--- a/dw/style.hh	Thu Oct 21 21:03:47 2010 +0200
+++ b/dw/style.hh	Sun Oct 24 15:00:36 2010 -0300
@@ -193,7 +193,7 @@
 namespace style {
 
 enum Cursor {
-   CURSOR_COSSHAIR,
+   CURSOR_CROSSHAIR,
    CURSOR_DEFAULT,
    CURSOR_POINTER,
    CURSOR_MOVE,
@@ -210,6 +210,11 @@
    CURSOR_HELP
 };
 
+enum BorderCollapse {
+   BORDER_MODEL_SEPARATE,
+   BORDER_MODEL_COLLAPSE
+};
+
 enum BorderStyle {
    BORDER_NONE,
    BORDER_HIDDEN,
@@ -435,6 +440,8 @@
    Length width, height, lineHeight;
 
    Box margin, borderWidth, padding;
+   BorderCollapse borderCollapse;
+   bool collapseStyleSet;
    struct { Color *top, *right, *bottom, *left; } borderColor;
    struct { BorderStyle top, right, bottom, left; } borderStyle;
 
--- a/src/cssparser.cc	Thu Oct 21 21:03:47 2010 +0200
+++ b/src/cssparser.cc	Sun Oct 24 15:00:36 2010 -0300
@@ -47,6 +47,10 @@
    const char *const *enum_symbols;
 } CssPropertyInfo;
 
+static const char *const Css_border_collapse_enum_vals[] = {
+   "separate", "collapse", NULL
+};
+
 static const char *const Css_border_style_enum_vals[] = {
    "none", "hidden", "dotted", "dashed", "solid", "double", "groove",
    "ridge", "inset", "outset", NULL
@@ -137,7 +141,8 @@
     Css_border_style_enum_vals},
    {"border-bottom-width", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
     Css_border_width_enum_vals},
-   {"border-collapse", {CSS_TYPE_UNUSED}, NULL},
+   {"border-collapse", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
+    Css_border_collapse_enum_vals},
    {"border-left-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
    {"border-left-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
     Css_border_style_enum_vals},
--- a/src/html_common.hh	Thu Oct 21 21:03:47 2010 +0200
+++ b/src/html_common.hh	Sun Oct 24 15:00:36 2010 -0300
@@ -97,6 +97,7 @@
    DilloHtmlParseMode parse_mode;
    DilloHtmlTableMode table_mode;
    bool cell_text_align_set;
+
    DilloHtmlListMode list_type;
    int list_number;
 
--- a/src/styleengine.cc	Thu Oct 21 21:03:47 2010 +0200
+++ b/src/styleengine.cc	Sun Oct 24 15:00:36 2010 -0300
@@ -434,6 +434,9 @@
                //attrs->backgroundColor = Color::create(layout, 0xdcd1ba);
                attrs->backgroundColor = Color::create(layout, 0xe0e0a3);
             break;
+         case CSS_PROPERTY_BORDER_COLLAPSE:
+            attrs->borderCollapse = (BorderCollapse) p->value.intVal;
+            break;
          case CSS_PROPERTY_BORDER_TOP_COLOR:
             attrs->borderColor.top =
               Color::create (layout, p->value.intVal);
--- a/src/table.cc	Thu Oct 21 21:03:47 2010 +0200
+++ b/src/table.cc	Sun Oct 24 15:00:36 2010 -0300
@@ -108,7 +108,7 @@
       html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_WIDTH,
                                         CSS_TYPE_LENGTH_PERCENTAGE, cssLength);
       html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_WIDTH,
-                                        CSS_TYPE_LENGTH_PERCENTAGE,  cssLength);
+                                        CSS_TYPE_LENGTH_PERCENTAGE, cssLength);
       html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_WIDTH,
                                         CSS_TYPE_LENGTH_PERCENTAGE, cssLength);
       html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_WIDTH,
@@ -216,6 +216,69 @@
  * Utilities
  */
 
+/* WORKAROUND: collapsing border model requires moving rendering code from
+ *             the cell to the table, and making table-code aware of each
+ *             cell style.
+ * This workaround mimics collapsing model within separate model. This is not
+ * a complete emulation but should be enough for most cases.
+ */
+static void Html_set_collapsing_border_model(DilloHtml *html, Widget *col_tb)
+{
+   dw::core::style::Style *collapseStyle, *tableStyle;
+   dw::core::style::StyleAttrs collapseCellAttrs, collapseTableAttrs;
+   int borderWidth, marginWidth;
+
+   tableStyle = ((dw::Table*)S_TOP(html)->table)->getStyle ();
+   borderWidth = html->styleEngine->style ()->borderWidth.top;
+   marginWidth = tableStyle->margin.top;
+
+   collapseCellAttrs = *(html->styleEngine->style ());
+   collapseCellAttrs.margin.setVal (0);
+   collapseCellAttrs.borderWidth.left = 0;
+   collapseCellAttrs.borderWidth.top = 0;
+   collapseCellAttrs.borderWidth.right = borderWidth;
+   collapseCellAttrs.borderWidth.bottom = borderWidth;
+   collapseCellAttrs.hBorderSpacing = 0;
+   collapseCellAttrs.vBorderSpacing = 0;
+   collapseStyle = Style::create(HT2LT(html), &collapseCellAttrs);
+   col_tb->setStyle (collapseStyle);
+
+   if (!tableStyle->collapseStyleSet) {
+      collapseTableAttrs = *tableStyle;
+      collapseTableAttrs.collapseStyleSet = true;
+      collapseTableAttrs.margin.setVal (marginWidth);
+      _MSG("COLLAPSING table margin set to %d\n", marginWidth);
+      collapseTableAttrs.borderWidth.left = borderWidth;
+      collapseTableAttrs.borderWidth.top = borderWidth;
+      collapseTableAttrs.borderWidth.right = 0;
+      collapseTableAttrs.borderWidth.bottom = 0;
+      collapseTableAttrs.hBorderSpacing = 0;
+      collapseTableAttrs.vBorderSpacing = 0;
+      collapseTableAttrs.borderColor = collapseCellAttrs.borderColor;
+      collapseTableAttrs.borderStyle = collapseCellAttrs.borderStyle;
+      /* CSS2 17.6.2: table does not have padding (in collapsing mode) */
+      collapseTableAttrs.padding.setVal (0);
+      collapseStyle = Style::create(HT2LT(html), &collapseTableAttrs);
+      ((dw::Table*)S_TOP(html)->table)->setStyle (collapseStyle);
+   }
+}
+
+/*
+ * Adjust style for separate border model.
+ * (Dw uses this model internally).
+ */
+static void Html_set_separate_border_model(DilloHtml *html, Widget *col_tb)
+{
+   dw::core::style::Style *separateStyle;
+   dw::core::style::StyleAttrs separateCellAttrs;
+
+   separateCellAttrs = *(html->styleEngine->style ());
+   /* CSS2 17.5: Internal table elements do not have margins */
+   separateCellAttrs.margin.setVal (0);
+   separateStyle = Style::create(HT2LT(html), &separateCellAttrs);
+   col_tb->setStyle (separateStyle);
+}
+
 /*
  * used by <TD> and <TH>
  */
@@ -290,7 +353,11 @@
       else
          col_tb = new Textblock (prefs.limit_text_width);
 
-      col_tb->setStyle (html->styleEngine->style ());
+      if (html->styleEngine->style()->borderCollapse == BORDER_MODEL_COLLAPSE){
+         Html_set_collapsing_border_model(html, col_tb);
+      } else {
+         Html_set_separate_border_model(html, col_tb);
+      }
 
       ((dw::Table*)S_TOP(html)->table)->addCell (col_tb, colspan, rowspan);
       S_TOP(html)->textblock = html->dw = col_tb;