changeset 529:a88b4a31cb7a

make ol work
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Fri, 31 Oct 2008 23:40:38 +0100
parents ec2fae048155
children b0e3156bfeec
files src/css.cc src/html.cc src/html_common.hh src/styleengine.cc src/table.cc
diffstat 5 files changed, 91 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Fri Oct 31 16:39:54 2008 +0100
+++ b/src/css.cc	Fri Oct 31 23:40:38 2008 +0100
@@ -84,14 +84,19 @@
 void CssContext::apply (CssPropertyList *props, Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCss) {
 
-   sheet[CSS_PRIMARY_USER_AGENT]->apply (props, docTree);
+   for (int o = CSS_PRIMARY_USER_AGENT; o <= CSS_PRIMARY_USER; o++)
+      if (sheet[o])
+         sheet[o]->apply (props, docTree);
+
    if (nonCss)
         nonCss->apply (props);
-   for (int o = CSS_PRIMARY_USER; o <= CSS_PRIMARY_USER_IMPORTANT; o++)
+
+   for (int o = CSS_PRIMARY_AUTHOR; o <= CSS_PRIMARY_USER_IMPORTANT; o++)
       if (sheet[o])
          sheet[o]->apply (props, docTree);
+
    if (tagStyle)
-        nonCss->apply (props);
+        tagStyle->apply (props);
 }
 
 CssStyleSheet * CssContext::buildUserAgentStyle () {
@@ -139,6 +144,12 @@
    props->set (CssProperty::CSS_PROPERTY_FONT_SIZE, v);
    s->addRule (new CssSelector(a_Html_tag_index("h3"), NULL, NULL), props);
 
+   // <ol>
+   props = new CssPropertyList ();
+   v.listStyleType = dw::core::style::LIST_STYLE_TYPE_DECIMAL;
+   props->set (CssProperty::CSS_PROPERTY_LIST_STYLE_TYPE, v);
+   s->addRule (new CssSelector(a_Html_tag_index("ol"), NULL, NULL), props);
+
    // <pre>
    props = new CssPropertyList ();
    v.name = "DejaVu Sans Mono";
@@ -153,25 +164,27 @@
    CssPropertyList *props;
    CssProperty::Value v;
 
-   // <a>
-   props = new CssPropertyList ();
-   v.color = prefs.link_color;
-   props->set (CssProperty::CSS_PROPERTY_COLOR, v);
-   s->addRule (new CssSelector(a_Html_tag_index("a"), NULL, NULL), props);
+   if (! important) {
+      // <a>
+      props = new CssPropertyList ();
+      v.color = prefs.link_color;
+      props->set (CssProperty::CSS_PROPERTY_COLOR, v);
+      s->addRule (new CssSelector(a_Html_tag_index("a"), NULL, NULL), props);
 
-   // <body>
-   props = new CssPropertyList ();
-   v.name = prefs.vw_fontname;
-   props->set (CssProperty::CSS_PROPERTY_FONT_FAMILY, v);
-   v.color = prefs.text_color;
-   props->set (CssProperty::CSS_PROPERTY_COLOR, v);
-   s->addRule (new CssSelector(a_Html_tag_index("body"), NULL, NULL), props);
+      // <body>
+      props = new CssPropertyList ();
+      v.name = prefs.vw_fontname;
+      props->set (CssProperty::CSS_PROPERTY_FONT_FAMILY, v);
+      v.color = prefs.text_color;
+      props->set (CssProperty::CSS_PROPERTY_COLOR, v);
+      s->addRule (new CssSelector(a_Html_tag_index("body"), NULL, NULL), props);
 
-   // <pre>
-   props = new CssPropertyList ();
-   v.name = prefs.fw_fontname;
-   props->set (CssProperty::CSS_PROPERTY_FONT_FAMILY, v);
-   s->addRule (new CssSelector(a_Html_tag_index("pre"), NULL, NULL), props);
+      // <pre>
+      props = new CssPropertyList ();
+      v.name = prefs.fw_fontname;
+      props->set (CssProperty::CSS_PROPERTY_FONT_FAMILY, v);
+      s->addRule (new CssSelector(a_Html_tag_index("pre"), NULL, NULL), props);
+   }
 
    return s;
 }
--- a/src/html.cc	Fri Oct 31 16:39:54 2008 +0100
+++ b/src/html.cc	Fri Oct 31 23:40:38 2008 +0100
@@ -288,25 +288,26 @@
  * sets the style at the top of the stack.
  */
 void a_Html_tag_set_align_attr(DilloHtml *html,
+                               CssPropertyList *props,        
                                const char *tag, int tagsize)
 {
-   const char *align, *charattr;
+   const char *align;
 
    if ((align = a_Html_get_attr(html, tag, tagsize, "align"))) {
-      Style *old_style = html->styleEngine->style ();
-      StyleAttrs style_attrs = *old_style;
+      CssProperty::Value v;
 
       if (dStrcasecmp (align, "left") == 0)
-         style_attrs.textAlign = TEXT_ALIGN_LEFT;
+         v.textAlignType = TEXT_ALIGN_LEFT;
       else if (dStrcasecmp (align, "right") == 0)
-         style_attrs.textAlign = TEXT_ALIGN_RIGHT;
+         v.textAlignType = TEXT_ALIGN_RIGHT;
       else if (dStrcasecmp (align, "center") == 0)
-         style_attrs.textAlign = TEXT_ALIGN_CENTER;
+         v.textAlignType = TEXT_ALIGN_CENTER;
       else if (dStrcasecmp (align, "justify") == 0)
-         style_attrs.textAlign = TEXT_ALIGN_JUSTIFY;
+         v.textAlignType = TEXT_ALIGN_JUSTIFY;
+#if 0
       else if (dStrcasecmp (align, "char") == 0) {
          /* TODO: Actually not supported for <p> etc. */
-         style_attrs.textAlign = TEXT_ALIGN_STRING;
+         v.textAlign = TEXT_ALIGN_STRING;
          if ((charattr = a_Html_get_attr(html, tag, tagsize, "char"))) {
             if (charattr[0] == 0)
                /* TODO: ALIGN=" ", and even ALIGN="&32;" will reult in
@@ -320,8 +321,8 @@
             /* TODO: Examine LANG attr of <html>. */
             style_attrs.textAlignChar = '.';
       }
-//      html->styleEngine->style () = Style::create (HT2LT(html), &style_attrs);
-//      old_style->unref ();
+#endif
+      props->set (CssProperty::CSS_PROPERTY_TEXT_ALIGN, v);
    }
 }
 
@@ -1763,13 +1764,16 @@
  */
 static void Html_tag_open_p(DilloHtml *html, const char *tag, int tagsize)
 {
+   CssPropertyList props;
+
    if ((html->InFlags & IN_LI) && !html->WordAfterLI) {
       /* ignore first parbreak after an empty <LI> */
       html->WordAfterLI = true;
    } else {
       DW2TB(html->dw)->addParbreak (9, html->styleEngine->style ());
    }
-   a_Html_tag_set_align_attr (html, tag, tagsize);
+   a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+   html->styleEngine->setNonCssProperties (&props);
 }
 
 /*
@@ -1858,13 +1862,12 @@
  */
 static void Html_tag_open_h(DilloHtml *html, const char *tag, int tagsize)
 {
+   CssPropertyList props;
+
    DW2TB(html->dw)->addParbreak (9, html->styleEngine->style ());
 
-   /* TODO: combining these two would be slightly faster */
-   a_Html_set_top_font(html, prefs.vw_fontname,
-                       Html_level_to_fontsize(FontSizesNum - (tag[2] - '0')),
-                       1, 3);
-   a_Html_tag_set_align_attr (html, tag, tagsize);
+   a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+   html->styleEngine->setNonCssProperties (&props);
 
    /* First finalize unclosed H tags (we test if already named anyway) */
    a_Menu_pagemarks_set_text(html->bw, html->Stash->str);
@@ -2592,11 +2595,8 @@
  */
 static void Html_tag_open_dir(DilloHtml *html, const char *tag, int tagsize)
 {
-   ListStyleType list_style_type = LIST_STYLE_TYPE_DISC;
-
    DW2TB(html->dw)->addParbreak (9, html->styleEngine->style ());
-   Html_add_indented(html, 40, 0, 9);
-   HTML_SET_TOP_ATTR(html, listStyleType, list_style_type);
+
    S_TOP(html)->list_type = HTML_LIST_UNORDERED;
    S_TOP(html)->list_number = 0;
    S_TOP(html)->ref_list_item = NULL;
@@ -2619,28 +2619,30 @@
 static void Html_tag_open_ol(DilloHtml *html, const char *tag, int tagsize)
 {
    const char *attrbuf;
-   ListStyleType list_style_type;
    int n = 1;
 
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "type"))) {
+      CssPropertyList props;
+      CssProperty::Value v;
+
+      if (*attrbuf == '1')
+         v.listStyleType = LIST_STYLE_TYPE_DECIMAL;
+      else if (*attrbuf == 'a')
+         v.listStyleType = LIST_STYLE_TYPE_LOWER_ALPHA;
+      else if (*attrbuf == 'A')
+         v.listStyleType = LIST_STYLE_TYPE_UPPER_ALPHA;
+      else if (*attrbuf == 'i')
+         v.listStyleType = LIST_STYLE_TYPE_LOWER_ROMAN;
+      else if (*attrbuf == 'I')
+         v.listStyleType = LIST_STYLE_TYPE_UPPER_ROMAN;
+
+      props.set (CssProperty::CSS_PROPERTY_LIST_STYLE_TYPE, v);
+      html->styleEngine->setNonCssProperties (&props);
+   }
+
    DW2TB(html->dw)->addParbreak (9, html->styleEngine->style ());
    Html_add_indented(html, 40, 0, 9);
 
-   list_style_type = LIST_STYLE_TYPE_DECIMAL;
-
-   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "type"))) {
-      if (*attrbuf == '1')
-         list_style_type = LIST_STYLE_TYPE_DECIMAL;
-      else if (*attrbuf == 'a')
-         list_style_type = LIST_STYLE_TYPE_LOWER_ALPHA;
-      else if (*attrbuf == 'A')
-         list_style_type = LIST_STYLE_TYPE_UPPER_ALPHA;
-      else if (*attrbuf == 'i')
-         list_style_type = LIST_STYLE_TYPE_LOWER_ROMAN;
-      else if (*attrbuf == 'I')
-         list_style_type = LIST_STYLE_TYPE_UPPER_ROMAN;
-   }
-
-   HTML_SET_TOP_ATTR(html, listStyleType, list_style_type);
    S_TOP(html)->list_type = HTML_LIST_ORDERED;
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "start")) &&
@@ -3043,8 +3045,11 @@
  */
 static void Html_tag_open_div(DilloHtml *html, const char *tag, int tagsize)
 {
+   CssPropertyList props;
+
    DW2TB(html->dw)->addParbreak (0, html->styleEngine->style ());
-   a_Html_tag_set_align_attr (html, tag, tagsize);
+   a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+   html->styleEngine->setNonCssProperties (&props);
 }
 
 /*
@@ -3443,10 +3448,6 @@
       /* Push the tag into the stack */
       Html_push_tag(html, ni);
 
-      /* Call the open function for this tag */
-      Tags[ni].open (html, tag, tagsize);
-      if (html->stop_parser)
-         break;
 
       /* Now parse attributes that can appear on any tag */
       if (tagsize >= 8 &&        /* length of "<t id=i>" */
@@ -3499,6 +3500,11 @@
       if (style)
          free (style);
 
+      /* Call the open function for this tag */
+      Tags[ni].open (html, tag, tagsize);
+      if (html->stop_parser)
+         break;
+
       /* let the parser know this was an open tag */
       html->PrevWasOpenTag = true;
 
--- a/src/html_common.hh	Fri Oct 31 16:39:54 2008 +0100
+++ b/src/html_common.hh	Fri Oct 31 23:40:38 2008 +0100
@@ -269,7 +269,7 @@
                            const char *subtag, int32_t default_color);
 dw::core::style::Length a_Html_parse_length (DilloHtml *html,
                                              const char *attr);
-void a_Html_tag_set_align_attr(DilloHtml *html,
+void a_Html_tag_set_align_attr(DilloHtml *html, CssPropertyList *props,
                                const char *tag, int tagsize);
 bool a_Html_tag_set_valign_attr(DilloHtml *html,
                                 const char *tag, int tagsize,
--- a/src/styleengine.cc	Fri Oct 31 16:39:54 2008 +0100
+++ b/src/styleengine.cc	Fri Oct 31 23:40:38 2008 +0100
@@ -112,6 +112,9 @@
          case CssProperty::CSS_PROPERTY_FONT_WEIGHT:
             fontAttrs.weight = p->value.weight;
             break;
+         case CssProperty::CSS_PROPERTY_LIST_STYLE_TYPE:
+            attrs->listStyleType = p->value.listStyleType;
+            break;
          case CssProperty::CSS_PROPERTY_TEXT_DECORATION:
             attrs->textDecoration |= p->value.textDecoration;
             break;
--- a/src/table.cc	Fri Oct 31 16:39:54 2008 +0100
+++ b/src/table.cc	Fri Oct 31 23:40:38 2008 +0100
@@ -138,6 +138,7 @@
    dw::core::style::Style *style, *old_style;
    int32_t bgcolor = -1;
    bool new_style = false;
+   CssPropertyList props;
 
 #ifdef USE_TABLES
    switch (S_TOP(html)->table_mode) {
@@ -171,7 +172,8 @@
 
       if (a_Html_get_attr (html, tag, tagsize, "align")) {
          S_TOP(html)->cell_text_align_set = TRUE;
-         a_Html_tag_set_align_attr (html, tag, tagsize);
+         a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+         html->styleEngine->setNonCssProperties (&props);
       }
 
       style_attrs = *S_TOP(html)->table_cell_style;
@@ -236,6 +238,7 @@
    dw::core::style::Style *style, *old_style;
    int32_t bgcolor;
    bool_t new_style;
+   CssPropertyList props;
 
    switch (S_TOP(html)->table_mode) {
    case DILLO_HTML_TABLE_MODE_NONE:
@@ -271,7 +274,8 @@
 //      html->styleEngine->style () =
 //         Style::create (HT2LT(html), &style_attrs);
 //      old_style->unref ();
-      a_Html_tag_set_align_attr (html, tag, tagsize);
+      a_Html_tag_set_align_attr (html, &props, tag, tagsize);
+      html->styleEngine->setNonCssProperties (&props);
 
       /* cell style */
       style_attrs = *S_TOP(html)->table_cell_style;