changeset 543:74c07ade1edc

convert table code to new style handling
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 10 Nov 2008 19:56:36 +0100
parents 09d926b89bfb
children 197fa5e98f9f
files src/css.cc src/css.hh src/html.cc src/html_common.hh src/styleengine.cc src/table.cc
diffstat 6 files changed, 162 insertions(+), 140 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/css.cc	Mon Nov 10 19:56:36 2008 +0100
@@ -164,6 +164,16 @@
    props = new CssPropertyList ();
    props->set (CssProperty::CSS_PROPERTY_FONT_FAMILY, "DejaVu Sans Mono");
    s->addRule (new CssSelector(a_Html_tag_index("pre"), NULL, NULL), props);
+
+   // <table>
+   props = new CssPropertyList ();
+   props->set (CssProperty::CSS_PROPERTY_BORDER_STYLE, BORDER_OUTSET);
+   s->addRule (new CssSelector(a_Html_tag_index("table"), NULL, NULL), props);
+
+   // <td>
+   props = new CssPropertyList ();
+   props->set (CssProperty::CSS_PROPERTY_BORDER_STYLE, BORDER_INSET);
+   s->addRule (new CssSelector(a_Html_tag_index("td"), NULL, NULL), props);
    
    return s;
 }
--- a/src/css.hh	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/css.hh	Mon Nov 10 19:56:36 2008 +0100
@@ -21,6 +21,7 @@
          CSS_PROPERTY_BORDER_BOTTOM_STYLE,
          CSS_PROPERTY_BORDER_BOTTOM_WIDTH,
          CSS_PROPERTY_BORDER_COLLAPSE,
+         CSS_PROPERTY_BORDER_COLOR,
          CSS_PROPERTY_BORDER_LEFT_COLOR,
          CSS_PROPERTY_BORDER_LEFT_STYLE,
          CSS_PROPERTY_BORDER_LEFT_WIDTH,
@@ -28,9 +29,11 @@
          CSS_PROPERTY_BORDER_RIGHT_STYLE,
          CSS_PROPERTY_BORDER_RIGHT_WIDTH,
          CSS_PROPERTY_BORDER_SPACING,
+         CSS_PROPERTY_BORDER_STYLE,
          CSS_PROPERTY_BORDER_TOP_COLOR,
          CSS_PROPERTY_BORDER_TOP_STYLE,
          CSS_PROPERTY_BORDER_TOP_WIDTH,
+         CSS_PROPERTY_BORDER_WIDTH,
          CSS_PROPERTY_BOTTOM,
          CSS_PROPERTY_CAPTION_SIDE,
          CSS_PROPERTY_CLEAR,
@@ -72,6 +75,7 @@
          CSS_PROPERTY_OUTLINE_STYLE,
          CSS_PROPERTY_OUTLINE_WIDTH,
          CSS_PROPERTY_OVERFLOW,
+         CSS_PROPERTY_PADDING,
          CSS_PROPERTY_PADDING_BOTTOM,
          CSS_PROPERTY_PADDING_LEFT,
          CSS_PROPERTY_PADDING_RIGHT,
@@ -118,8 +122,15 @@
 };
 
 class CssPropertyList : public lout::misc::SimpleVector <CssProperty> {
+      int refCount;
+
    public:
-      CssPropertyList() : lout::misc::SimpleVector <CssProperty> (1) {};
+      CssPropertyList() : lout::misc::SimpleVector <CssProperty> (1) {
+         refCount = 0;
+      };
+      CssPropertyList(const CssPropertyList &p) : lout::misc::SimpleVector <CssProperty> (p) {
+         refCount = 0;
+      };
 
       static CssPropertyList *parse (const char *buf);
       void set (CssProperty::Name name, CssProperty::Value value);
@@ -134,6 +145,9 @@
          set (name, v);
       };
       void apply (CssPropertyList *props);
+
+      inline void ref () { refCount++; }
+      inline void unref () { if(--refCount == 0) delete this; }
 };
 
 /** \todo proper implementation */
--- a/src/html.cc	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/html.cc	Mon Nov 10 19:56:36 2008 +0100
@@ -331,19 +331,22 @@
  * sets the style in style_attrs. Returns true when set.
  */
 bool a_Html_tag_set_valign_attr(DilloHtml *html, const char *tag,
-                                int tagsize, StyleAttrs *style_attrs)
+                                int tagsize, CssPropertyList *props)
 {
    const char *attr;
+   VAlignType valign;
 
    if ((attr = a_Html_get_attr(html, tag, tagsize, "valign"))) {
       if (dStrcasecmp (attr, "top") == 0)
-         style_attrs->valign = VALIGN_TOP;
+         valign = VALIGN_TOP;
       else if (dStrcasecmp (attr, "bottom") == 0)
-         style_attrs->valign = VALIGN_BOTTOM;
+         valign = VALIGN_BOTTOM;
       else if (dStrcasecmp (attr, "baseline") == 0)
-         style_attrs->valign = VALIGN_BASELINE;
+         valign = VALIGN_BASELINE;
       else
-         style_attrs->valign = VALIGN_MIDDLE;
+         valign = VALIGN_MIDDLE;
+
+      props->set (CssProperty::CSS_PROPERTY_VERTICAL_ALIGN, valign);
       return true;
    } else
       return false;
@@ -470,7 +473,7 @@
 
    stack = new misc::SimpleVector <DilloHtmlState> (16);
    stack->increase();
-   stack->getRef(0)->table_cell_style = NULL;
+   stack->getRef(0)->table_cell_props = NULL;
    stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT;
    stack->getRef(0)->table_mode = DILLO_HTML_TABLE_MODE_NONE;
    stack->getRef(0)->cell_text_align_set = false;
@@ -514,8 +517,8 @@
    images = new misc::SimpleVector <DilloLinkImage*> (16);
    //a_Dw_image_map_list_init(&maps);
 
-   link_color = prefs.link_color;
-   visited_color = prefs.visited_color;
+   link_color = -1;
+   visited_color = -1;
 
    /* Initialize the main widget */
    initDw();
@@ -533,7 +536,7 @@
    /* Create the main widget */
    dw = stack->getRef(0)->textblock = new Textblock (prefs.limit_text_width);
 
-   stack->getRef(0)->table_cell_style = NULL;
+   stack->getRef(0)->table_cell_props = NULL;
 
    /* Handle it when the user clicks on a link */
    connectSignals(dw);
@@ -1254,9 +1257,8 @@
     * instead of copying all fields except for tag.  --Jcid */
    *html->stack->getRef(n_items) = *html->stack->getRef(n_items - 1);
    html->stack->getRef(n_items)->tag_idx = tag_idx;
-   /* proper memory management, may be unref'd later */
-   if (S_TOP(html)->table_cell_style)
-      (S_TOP(html)->table_cell_style)->ref ();
+   if (S_TOP(html)->table_cell_props)
+      S_TOP(html)->table_cell_props->ref ();
    html->dw = S_TOP(html)->textblock;
 }
 
@@ -1276,10 +1278,9 @@
 {
    bool hand_over_break;
 
-   //(html->styleEngine->style ())->unref ();
-   if (S_TOP(html)->table_cell_style)
-      (S_TOP(html)->table_cell_style)->unref ();
    html->styleEngine->endElement (S_TOP(html)->tag_idx);
+   if (S_TOP(html)->table_cell_props)
+      S_TOP(html)->table_cell_props->unref ();
    hand_over_break = S_TOP(html)->hand_over_break;
    html->stack->setSize (html->stack->size() - 1);
    Html_eventually_pop_dw(html, hand_over_break);
@@ -1686,8 +1687,7 @@
 {
    const char *attrbuf;
    Textblock *textblock;
-   StyleAttrs style_attrs;
-   Style *style;
+   CssPropertyList props;
    int32_t color;
 
    if (!(html->InFlags & IN_BODY))
@@ -1705,43 +1705,37 @@
 
    textblock = DW2TB(html->dw);
 
-   if (!prefs.force_my_colors) {
-      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
-         color = a_Html_color_parse(html, attrbuf, prefs.bg_color);
-         if (color == 0xffffff && !prefs.allow_white_bg)
-            color = prefs.bg_color;
-
-         style_attrs = *html->dw->getStyle ();
-         style_attrs.backgroundColor = Color::createShaded(HT2LT(html), color);
-         style = Style::create (HT2LT(html), &style_attrs);
-         html->dw->setStyle (style);
-         style->unref ();
-         S_TOP(html)->current_bg_color = color;
-      }
-
-      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "text"))) {
-         color = a_Html_color_parse(html, attrbuf, prefs.text_color);
-         HTML_SET_TOP_ATTR (html, color,
-                            Color::createSimple (HT2LT(html),color));
-      }
-
-      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "link")))
-         html->link_color = a_Html_color_parse(html,attrbuf,prefs.link_color);
-
-      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "vlink")))
-         html->visited_color = a_Html_color_parse(html, attrbuf,
-                                                  prefs.visited_color);
-
-      if (prefs.contrast_visited_color) {
-         /* get a color that has a "safe distance" from text, link and bg */
-         html->visited_color =
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
+      color = a_Html_color_parse(html, attrbuf, prefs.bg_color);
+      if (color == 0xffffff && !prefs.allow_white_bg)
+         color = prefs.bg_color;
+      S_TOP(html)->current_bg_color = color;
+      props.set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, color);
+   }
+
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "text"))) {
+      color = a_Html_color_parse(html, attrbuf, prefs.text_color);
+      props.set (CssProperty::CSS_PROPERTY_COLOR, color);
+   }
+
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "link")))
+      html->link_color = a_Html_color_parse(html, attrbuf, -1);
+
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "vlink")))
+      html->visited_color = a_Html_color_parse(html, attrbuf, -1);
+
+   if (prefs.contrast_visited_color) {
+      /* get a color that has a "safe distance" from text, link and bg */
+      html->visited_color =
             a_Color_vc(html->visited_color,
                        html->styleEngine->style ()->color->getColor(),
                        html->link_color,
                        S_TOP(html)->current_bg_color);
-      }
    }
 
+   html->styleEngine->setNonCssProperties (&props);
+   html->dw->setStyle (html->styleEngine->style ());
+
    S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_BODY;
 }
 
@@ -2460,11 +2454,16 @@
       if (a_Capi_get_flags(url) & CAPI_IsCached) {
          html->InVisitedLink = true;
          html->styleEngine->setPseudoClass ("visited");
+         if (html->visited_color != -1)
+            props.set (CssProperty::CSS_PROPERTY_COLOR, html->visited_color);
       } else {
          html->styleEngine->setPseudoClass ("link");
+         if (html->link_color != -1)
+            props.set (CssProperty::CSS_PROPERTY_COLOR, html->link_color);
       }
 
       props.set (CssProperty::PROPERTY_X_LINK, Html_set_new_link(html, &url));
+
       html->styleEngine->setNonCssProperties (&props);
    }
 
--- a/src/html_common.hh	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/html_common.hh	Mon Nov 10 19:56:36 2008 +0100
@@ -114,8 +114,7 @@
 };
 
 struct _DilloHtmlState {
-//   dw::core::style::Style *style, *table_cell_style;
-   dw::core::style::Style *table_cell_style;
+   CssPropertyList *table_cell_props;
    DilloHtmlParseMode parse_mode;
    DilloHtmlTableMode table_mode;
    bool cell_text_align_set;
@@ -273,7 +272,7 @@
                                const char *tag, int tagsize);
 bool a_Html_tag_set_valign_attr(DilloHtml *html,
                                 const char *tag, int tagsize,
-                                dw::core::style::StyleAttrs *style_attrs);
+                                CssPropertyList *props);
 void a_Html_set_top_font(DilloHtml *html, const char *name, int size,
                          int BI, int BImask);
 
--- a/src/styleengine.cc	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/styleengine.cc	Mon Nov 10 19:56:36 2008 +0100
@@ -65,9 +65,11 @@
 
 /**
  * \brief set properties that were definded using (mostly deprecated) HTML
- * attributes (e.g. bgColor).
+ *    attributes (e.g. bgColor).
  */
 void StyleEngine::setNonCssProperties (CssPropertyList *props) {
+   if (stack->getRef (stack->size () - 1)->style)
+      stack->getRef (stack->size () - 1)->style->unref ();
    style0 (props); // evaluate now, so caller can free props
 }
 
@@ -93,6 +95,9 @@
    stack->setSize (stack->size () - 1);
 }
 
+/**
+ * \brief Make changes to StyleAttrs attrs according to CssPropertyList props.
+ */
 void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
    FontAttrs fontAttrs = *attrs->font;
 
@@ -109,9 +114,18 @@
             attrs->borderColor.bottom =
               Color::createSimple (layout, p->value.intVal);
             break; 
+         case CssProperty::CSS_PROPERTY_BORDER_COLOR:
+            attrs->setBorderColor (Color::createSimple (layout, p->value.intVal));
+            break; 
          case CssProperty::CSS_PROPERTY_BORDER_BOTTOM_STYLE:
             attrs->borderStyle.bottom = (BorderStyle) p->value.intVal;
             break;
+         case CssProperty::CSS_PROPERTY_BORDER_STYLE:
+            attrs->setBorderStyle ((BorderStyle) p->value.intVal);
+            break;
+         case CssProperty::CSS_PROPERTY_BORDER_WIDTH:
+            attrs->borderWidth.setVal (p->value.intVal);
+            break;
          case CssProperty::CSS_PROPERTY_COLOR:
             attrs->color = Color::createSimple (layout, p->value.intVal);
             break; 
@@ -147,12 +161,21 @@
          case CssProperty::CSS_PROPERTY_LIST_STYLE_TYPE:
             attrs->listStyleType = (ListStyleType) p->value.intVal;
             break;
+         case CssProperty::CSS_PROPERTY_PADDING:
+            attrs->padding.setVal (p->value.intVal);
+            break;
          case CssProperty::CSS_PROPERTY_TEXT_ALIGN:
             attrs->textAlign = (TextAlignType) p->value.intVal;
             break;
          case CssProperty::CSS_PROPERTY_TEXT_DECORATION:
             attrs->textDecoration |= p->value.intVal;
             break;
+         case CssProperty::CSS_PROPERTY_VERTICAL_ALIGN:
+            attrs->valign = (VAlignType) p->value.intVal;
+            break;
+         case CssProperty::CSS_PROPERTY_WIDTH:
+            attrs->width = p->value.intVal;
+            break;
          case CssProperty::PROPERTY_X_LINK:
             attrs->x_link = p->value.intVal;
             break;
@@ -180,6 +203,8 @@
 
    // get previous style from the stack
    StyleAttrs attrs = *stack->getRef (stack->size () - 2)->style;
+   // reset values that are not inherited according to CSS
+   attrs.resetValues ();
 
    cssContext->apply (&props, this, tagStyleProps, nonCssProperties);
 
--- a/src/table.cc	Mon Nov 10 19:35:07 2008 +0100
+++ b/src/table.cc	Mon Nov 10 19:56:36 2008 +0100
@@ -18,6 +18,7 @@
 
 #include "prefs.h"
 #include "msg.h"
+#include "css.hh"
 
 /* Undefine if you want to unroll tables. For instance for PDAs */
 #define USE_TABLES
@@ -43,10 +44,9 @@
 {
 #ifdef USE_TABLES
    dw::core::Widget *table;
-   dw::core::style::StyleAttrs style_attrs;
-   dw::core::style::Style *cell_style, *old_style;
+   CssPropertyList props, *table_cell_props;
    const char *attrbuf;
-   int32_t border = 0, cellspacing = 1, cellpadding = 2, bgcolor;
+   int32_t border = -1, cellspacing = -1, cellpadding = -1, bgcolor = -1;
 #endif
 
    DW2TB(html->dw)->addParbreak (0, html->styleEngine->style ());
@@ -59,68 +59,65 @@
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "cellpadding")))
       cellpadding = strtol (attrbuf, NULL, 10);
 
-   /* The style for the table */
-   style_attrs = *html->styleEngine->style ();
+   if (border != -1)
+      props.set (CssProperty::CSS_PROPERTY_BORDER_WIDTH, border);
+   if (cellspacing != -1)
+      props.set (CssProperty::CSS_PROPERTY_BORDER_SPACING, cellspacing);
+
+   props.set (CssProperty::CSS_PROPERTY_BORDER_STYLE, BORDER_OUTSET);
 
    /* When dillo was started with the --debug-rendering option, there
     * is always a border around the table. */
-   if (dillo_dbg_rendering)
-      style_attrs.borderWidth.setVal (MIN (border, 1));
-   else
-      style_attrs.borderWidth.setVal (border);
-
-   style_attrs.setBorderColor (
-      Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color));
-   style_attrs.setBorderStyle (BORDER_OUTSET);
-   style_attrs.hBorderSpacing = cellspacing;
-   style_attrs.vBorderSpacing = cellspacing;
+   if (dillo_dbg_rendering && border < 1)
+      props.set (CssProperty::CSS_PROPERTY_BORDER_WIDTH, 1);
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "width")))
-      style_attrs.width = a_Html_parse_length (html, attrbuf);
+      props.set (CssProperty::CSS_PROPERTY_WIDTH,
+         a_Html_parse_length (html, attrbuf));
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "align"))) {
       if (dStrcasecmp (attrbuf, "left") == 0)
-         style_attrs.textAlign = dw::core::style::TEXT_ALIGN_LEFT;
+         props.set (CssProperty::CSS_PROPERTY_TEXT_ALIGN, TEXT_ALIGN_LEFT);
       else if (dStrcasecmp (attrbuf, "right") == 0)
-         style_attrs.textAlign = dw::core::style::TEXT_ALIGN_RIGHT;
+         props.set (CssProperty::CSS_PROPERTY_TEXT_ALIGN, TEXT_ALIGN_RIGHT);
       else if (dStrcasecmp (attrbuf, "center") == 0)
-         style_attrs.textAlign = dw::core::style::TEXT_ALIGN_CENTER;
+         props.set (CssProperty::CSS_PROPERTY_TEXT_ALIGN, TEXT_ALIGN_CENTER);
    }
 
-   if (!prefs.force_my_colors &&
-       (attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
+   /** \todo figure out how to implement shaded colors with CSS */
+   props.set (CssProperty::CSS_PROPERTY_BORDER_COLOR, 0x000000);
+
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
       bgcolor = a_Html_color_parse(html, attrbuf, -1);
       if (bgcolor != -1) {
          if (bgcolor == 0xffffff && !prefs.allow_white_bg)
             bgcolor = prefs.bg_color;
          S_TOP(html)->current_bg_color = bgcolor;
-         style_attrs.backgroundColor =
-            Color::createShaded (HT2LT(html), bgcolor);
+         props.set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, bgcolor);
       }
    }
 
+   html->styleEngine->setNonCssProperties (&props);
+
    /* The style for the cells */
-   cell_style = Style::create (HT2LT(html), &style_attrs);
-   style_attrs = *html->styleEngine->style ();
-   /* When dillo was started with the --debug-rendering option, there
-    * is always a border around the cells. */
-   if (dillo_dbg_rendering)
-      style_attrs.borderWidth.setVal (1);
-   else
-      style_attrs.borderWidth.setVal (border ? 1 : 0);
-   style_attrs.padding.setVal(cellpadding);
-   style_attrs.setBorderColor (cell_style->borderColor.top);
-   style_attrs.setBorderStyle (BORDER_INSET);
+   table_cell_props = new CssPropertyList ();
+   table_cell_props->ref ();
+   if (border != -1)
+      table_cell_props->set (CssProperty::CSS_PROPERTY_BORDER_WIDTH, border);
+   if (dillo_dbg_rendering && border < 1)
+      table_cell_props->set (CssProperty::CSS_PROPERTY_BORDER_WIDTH, 1);
+   table_cell_props->set (CssProperty::CSS_PROPERTY_PADDING, cellpadding);
+   /** \todo figure out how to implement shaded colors with CSS */
+   table_cell_props->set (CssProperty::CSS_PROPERTY_BORDER_COLOR, 0x000000);
+   table_cell_props->set (CssProperty::CSS_PROPERTY_BORDER_STYLE, BORDER_INSET);
 
-   old_style = S_TOP(html)->table_cell_style;
-   S_TOP(html)->table_cell_style =
-      Style::create (HT2LT(html), &style_attrs);
-   if (old_style)
-      old_style->unref ();
+   if (S_TOP(html)->table_cell_props)
+      S_TOP(html)->table_cell_props->unref ();
+
+   S_TOP(html)->table_cell_props = table_cell_props;
 
    table = new dw::Table(prefs.limit_text_width);
-   DW2TB(html->dw)->addWidget (table, cell_style);
-   cell_style->unref ();
+   DW2TB(html->dw)->addWidget (table, html->styleEngine->style ());
 
    S_TOP(html)->table_mode = DILLO_HTML_TABLE_MODE_TOP;
    S_TOP(html)->cell_text_align_set = FALSE;
@@ -134,11 +131,9 @@
 void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize)
 {
    const char *attrbuf;
-   dw::core::style::StyleAttrs style_attrs;
-   dw::core::style::Style *style, *old_style;
    int32_t bgcolor = -1;
    bool new_style = false;
-   CssPropertyList props;
+   CssPropertyList props, *table_cell_props;
 
 #ifdef USE_TABLES
    switch (S_TOP(html)->table_mode) {
@@ -149,26 +144,20 @@
    case DILLO_HTML_TABLE_MODE_TOP:
    case DILLO_HTML_TABLE_MODE_TR:
    case DILLO_HTML_TABLE_MODE_TD:
-      style = NULL;
 
-      if (!prefs.force_my_colors &&
-          (attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
+      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
          bgcolor = a_Html_color_parse(html, attrbuf, -1);
          if (bgcolor != -1) {
             if (bgcolor == 0xffffff && !prefs.allow_white_bg)
                bgcolor = prefs.bg_color;
-
-            style_attrs = *html->styleEngine->style ();
-            style_attrs.backgroundColor =
-               Color::createShaded (HT2LT(html), bgcolor);
-            style = Style::create (HT2LT(html), &style_attrs);
+            props.set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, bgcolor);
             S_TOP(html)->current_bg_color = bgcolor;
          }
       }
 
-      ((dw::Table*)S_TOP(html)->table)->addRow (style);
-      if (style)
-         style->unref ();
+      html->styleEngine->setNonCssProperties (&props);
+
+      ((dw::Table*)S_TOP(html)->table)->addRow (html->styleEngine->style ());
 
       if (a_Html_get_attr (html, tag, tagsize, "align")) {
          S_TOP(html)->cell_text_align_set = TRUE;
@@ -176,18 +165,19 @@
          html->styleEngine->setNonCssProperties (&props);
       }
 
-      style_attrs = *S_TOP(html)->table_cell_style;
+      table_cell_props = new CssPropertyList (*S_TOP(html)->table_cell_props);
       if (bgcolor != -1) {
-         style_attrs.backgroundColor =Color::createShaded(HT2LT(html),bgcolor);
+         props.set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, bgcolor);
          new_style = true;
       }
-      if (a_Html_tag_set_valign_attr (html, tag, tagsize, &style_attrs))
+      if (a_Html_tag_set_valign_attr (html, tag, tagsize, table_cell_props))
          new_style = true;
       if (new_style) {
-         old_style = S_TOP(html)->table_cell_style;
-         S_TOP(html)->table_cell_style =
-            Style::create (HT2LT(html), &style_attrs);
-         old_style->unref ();
+         S_TOP(html)->table_cell_props->unref ();
+         S_TOP(html)->table_cell_props = table_cell_props;
+         S_TOP(html)->table_cell_props->ref ();
+      } else {
+         delete table_cell_props;
       }
       break;
    default:
@@ -235,10 +225,8 @@
    int colspan = 1, rowspan = 1;
    const char *attrbuf;
    int32_t bgcolor;
-   StyleAttrs style_attrs;
-   Style *style;
    bool_t new_style;
-   CssPropertyList props;
+   CssPropertyList props (*S_TOP(html)->table_cell_props);
 
    switch (S_TOP(html)->table_mode) {
    case DILLO_HTML_TABLE_MODE_NONE:
@@ -270,38 +258,29 @@
       else
          props.set (CssProperty::CSS_PROPERTY_WHITE_SPACE, WHITE_SPACE_NORMAL);
 
-//      html->styleEngine->style () =
-//         Style::create (HT2LT(html), &style_attrs);
-//      old_style->unref ();
       a_Html_tag_set_align_attr (html, &props, tag, tagsize);
-      html->styleEngine->setNonCssProperties (&props);
-
-      /* cell style */
-      style_attrs = *S_TOP(html)->table_cell_style;
-      new_style = FALSE;
 
       if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "width"))) {
-         style_attrs.width = a_Html_parse_length (html, attrbuf);
-         new_style = TRUE;
+         props.set (CssProperty::CSS_PROPERTY_WIDTH,
+            a_Html_parse_length (html, attrbuf));
       }
 
-      if (a_Html_tag_set_valign_attr (html, tag, tagsize, &style_attrs))
+      if (a_Html_tag_set_valign_attr (html, tag, tagsize, &props))
          new_style = TRUE;
 
-      if (!prefs.force_my_colors &&
-          (attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
+      if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
          bgcolor = a_Html_color_parse(html, attrbuf, -1);
          if (bgcolor != -1) {
             if (bgcolor == 0xffffff && !prefs.allow_white_bg)
                bgcolor = prefs.bg_color;
 
-            new_style = TRUE;
-            style_attrs.backgroundColor =
-               Color::createShaded (HT2LT(html), bgcolor);
+            props.set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, bgcolor);
             S_TOP(html)->current_bg_color = bgcolor;
          }
       }
 
+      html->styleEngine->setNonCssProperties (&props);
+
       if (html->styleEngine->style ()->textAlign
           == TEXT_ALIGN_STRING)
          col_tb = new dw::TableCell (((dw::Table*)S_TOP(html)->table)->getCellRef (),
@@ -309,18 +288,14 @@
       else
          col_tb = new Textblock (prefs.limit_text_width);
 
-      if (new_style) {
-         style = dw::core::style::Style::create (HT2LT(html), &style_attrs);
-         col_tb->setStyle (style);
-         style->unref ();
-      } else
-         col_tb->setStyle (S_TOP(html)->table_cell_style);
+      col_tb->setStyle (html->styleEngine->style ());
 
       ((dw::Table*)S_TOP(html)->table)->addCell (col_tb, colspan, rowspan);
       S_TOP(html)->textblock = html->dw = col_tb;
 
       /* Handle it when the user clicks on a link */
       html->connectSignals(col_tb);
+
       break;
 
    default: