changeset 1761:f5b91fafcbd4

Moved the table border model flag from style to DilloHtmlState (i.e. stack)
author Jorge Arellano Cid <jcid@dillo.org>
date Mon, 15 Nov 2010 17:07:15 -0300
parents cbca357af616
children 433a380f83a1
files dw/style.cc dw/style.hh src/html.cc src/html_common.hh src/table.cc
diffstat 5 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dw/style.cc	Sat Nov 13 13:15:55 2010 -0300
+++ b/dw/style.cc	Mon Nov 15 17:07:15 2010 -0300
@@ -51,7 +51,6 @@
    borderWidth.setVal (0);
    padding.setVal (0);
    borderCollapse = BORDER_MODEL_SEPARATE;
-   collapseStyleSet = false;
    setBorderColor (NULL);
    setBorderStyle (BORDER_NONE);
    hBorderSpacing = 0;
@@ -127,7 +126,6 @@
        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 &&
@@ -164,7 +162,6 @@
       borderWidth.hashValue () +
       padding.hashValue () +
       borderCollapse +
-      collapseStyleSet +
       (intptr_t) borderColor.top +
       (intptr_t) borderColor.right +
       (intptr_t) borderColor.bottom  +
@@ -254,7 +251,6 @@
    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	Sat Nov 13 13:15:55 2010 -0300
+++ b/dw/style.hh	Mon Nov 15 17:07:15 2010 -0300
@@ -447,7 +447,6 @@
 
    Box margin, borderWidth, padding;
    BorderCollapse borderCollapse;
-   bool collapseStyleSet;
    struct { Color *top, *right, *bottom, *left; } borderColor;
    struct { BorderStyle top, right, bottom, left; } borderStyle;
 
--- a/src/html.cc	Sat Nov 13 13:15:55 2010 -0300
+++ b/src/html.cc	Mon Nov 15 17:07:15 2010 -0300
@@ -428,6 +428,7 @@
    stack->increase();
    stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT;
    stack->getRef(0)->table_mode = DILLO_HTML_TABLE_MODE_NONE;
+   stack->getRef(0)->table_border_mode = DILLO_HTML_TABLE_BORDER_SEPARATE;
    stack->getRef(0)->cell_text_align_set = false;
    stack->getRef(0)->list_type = HTML_LIST_NONE;
    stack->getRef(0)->list_number = 0;
--- a/src/html_common.hh	Sat Nov 13 13:15:55 2010 -0300
+++ b/src/html_common.hh	Mon Nov 15 17:07:15 2010 -0300
@@ -64,6 +64,11 @@
 } DilloHtmlTableMode;
 
 typedef enum {
+   DILLO_HTML_TABLE_BORDER_SEPARATE,
+   DILLO_HTML_TABLE_BORDER_COLLAPSE
+} DilloHtmlTableBorderMode;
+
+typedef enum {
    HTML_LIST_NONE,
    HTML_LIST_UNORDERED,
    HTML_LIST_ORDERED
@@ -96,6 +101,7 @@
 struct _DilloHtmlState {
    DilloHtmlParseMode parse_mode;
    DilloHtmlTableMode table_mode;
+   DilloHtmlTableBorderMode table_border_mode;
    bool cell_text_align_set;
 
    DilloHtmlListMode list_type;
--- a/src/table.cc	Sat Nov 13 13:15:55 2010 -0300
+++ b/src/table.cc	Mon Nov 15 17:07:15 2010 -0300
@@ -139,6 +139,7 @@
    HT2TB(html)->addWidget (table, html->styleEngine->style ());
 
    S_TOP(html)->table_mode = DILLO_HTML_TABLE_MODE_TOP;
+   S_TOP(html)->table_border_mode = DILLO_HTML_TABLE_BORDER_SEPARATE;
    S_TOP(html)->cell_text_align_set = FALSE;
    S_TOP(html)->table = table;
 }
@@ -216,6 +217,34 @@
  * Utilities
  */
 
+/*
+ * The table border model is stored in the table's stack item
+ */ 
+static int Html_table_get_border_model(DilloHtml *html)
+{
+   static int i_TABLE = -1;
+   if (i_TABLE == -1)
+      i_TABLE = a_Html_tag_index("table");
+
+   int s_idx = html->stack->size();
+   while (--s_idx > 0 && html->stack->getRef(s_idx)->tag_idx != i_TABLE)
+      ;
+   return html->stack->getRef(s_idx)->table_border_mode;
+}
+
+/*
+ * Set current table's border model
+ */
+static void Html_table_set_border_model(DilloHtml *html,
+                                        DilloHtmlTableBorderMode mode)
+{
+   int s_idx = html->stack->size(), i_TABLE = a_Html_tag_index("table");
+
+   while (--s_idx > 0 && html->stack->getRef(s_idx)->tag_idx != i_TABLE) ;
+   if (s_idx > 0)
+      html->stack->getRef(s_idx)->table_border_mode = mode;
+}
+
 /* WORKAROUND: collapsing border model requires moving rendering code from
  *             the cell to the table, and making table-code aware of each
  *             cell style.
@@ -243,11 +272,10 @@
    collapseStyle = Style::create(HT2LT(html), &collapseCellAttrs);
    col_tb->setStyle (collapseStyle);
 
-   if (!tableStyle->collapseStyleSet) {
+   if (Html_table_get_border_model(html) != DILLO_HTML_TABLE_BORDER_COLLAPSE) {
+      Html_table_set_border_model(html, DILLO_HTML_TABLE_BORDER_COLLAPSE);
       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;