Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/9783296c4ffd83dfdb18e1e293ad635f214d2fd0
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/9783296c4ffd83dfdb18e1e293ad635f214d2fd0
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/9783296c4ffd83dfdb18e1e293ad635f214d2fd0

The branch, master has been updated
       via  9783296c4ffd83dfdb18e1e293ad635f214d2fd0 (commit)
       via  32d9de461e4cb9c287dbafb0745ac64358a0b561 (commit)
       via  496b1eca087490346a29c6c062c53a21e679ddd5 (commit)
       via  d29f6d6c1e8433f718b6de3d31626cd6f06c352f (commit)
       via  e18bb8fde15d860f198b9555ddac123273ea2e30 (commit)
       via  4c941254c8cfd1cf0e6f005d39ed0cc8f8ff077c (commit)
       via  64680a8edbebcfbcb5f2f2ddcce9a998aeef19f3 (commit)
       via  41a0c21812ed1fb59bf75cbe26a8b8c5e19e71a0 (commit)
       via  9434fe1ff08cb9e009efa9cd434177d91948d12e (commit)
       via  839fb8570a4fb8a31a76605b4614e7384d60f039 (commit)
      from  dcec1d0cd58343f64d4dd0b7d52e2c5d6193dfe8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 content/handlers/html/box.h            |    4 +
 content/handlers/html/box_construct.c  |  101 +-------
 content/handlers/html/box_manipulate.c |    1 +
 content/handlers/html/layout.c         |  393 ++++++++++++++++++++++++++++++--
 utils/corestringlist.h                 |    2 +
 5 files changed, 390 insertions(+), 111 deletions(-)

diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h
index d0df735..1059556 100644
--- a/content/handlers/html/box.h
+++ b/content/handlers/html/box.h
@@ -404,6 +404,10 @@ struct box {
         */
        struct column *col;
 
+       /**
+        * List item value.
+        */
+       int list_value;
 
        /**
         * List marker box if this is a list-item, or NULL.
diff --git a/content/handlers/html/box_construct.c 
b/content/handlers/html/box_construct.c
index a133578..7bfc35e 100644
--- a/content/handlers/html/box_construct.c
+++ b/content/handlers/html/box_construct.c
@@ -350,61 +350,6 @@ box_construct_generate(dom_node *n,
 
 
 /**
- * compute the index for a list marker
- *
- * calculates a one based index of a list item
- */
-static unsigned int compute_list_marker_index(struct box *last)
-{
-       /* Drill down into last child of parent
-        * to find the list marker (if any)
-        *
-        * Floated list boxes end up as:
-        *
-        * parent
-        *   BOX_INLINE_CONTAINER
-        *     BOX_FLOAT_{LEFT,RIGHT}
-        *       BOX_BLOCK <-- list box
-        *        ...
-        */
-       while ((last != NULL) && (last->list_marker == NULL)) {
-               struct box *last_inner = last;
-
-               while (last_inner != NULL) {
-                       if (last_inner->list_marker != NULL) {
-                               break;
-                       }
-                       if (last_inner->type == BOX_INLINE_CONTAINER ||
-                           last_inner->type == BOX_FLOAT_LEFT ||
-                           last_inner->type == BOX_FLOAT_RIGHT) {
-                               last_inner = last_inner->last;
-                       } else {
-                               last_inner = NULL;
-                       }
-               }
-               if (last_inner != NULL) {
-                       last = last_inner;
-               } else {
-                       last = last->prev;
-               }
-       }
-
-       if ((last == NULL) || (last->list_marker == NULL)) {
-               return 1;
-       }
-
-       return last->list_marker->rows + 1;
-}
-
-/**
- * initial length of a list marker buffer
- *
- * enough for 9,999,999,999,999,999,999 in decimal
- * or five characters for 4byte utf8
- */
-#define LIST_MARKER_SIZE 20
-
-/**
  * Construct a list marker box
  *
  * \param box      Box to attach marker to
@@ -422,8 +367,6 @@ box_construct_marker(struct box *box,
        lwc_string *image_uri;
        struct box *marker;
        enum css_list_style_type_e list_style_type;
-       size_t counter_len;
-       css_error css_res;
 
        marker = box_create(NULL, box->style, false, NULL, NULL, title,
                        NULL, ctx->bctx);
@@ -454,51 +397,13 @@ box_construct_marker(struct box *box,
                marker->length = 3;
                break;
 
+       default:
+               /* Numerical list counters get handled in layout. */
+               /* Fall through. */
        case CSS_LIST_STYLE_TYPE_NONE:
                marker->text = NULL;
                marker->length = 0;
                break;
-
-       default:
-               marker->rows = compute_list_marker_index(parent->last);
-
-               marker->text = talloc_array(ctx->bctx, char, LIST_MARKER_SIZE);
-               if (marker->text == NULL) {
-                       return false;
-               }
-
-               css_res = css_computed_format_list_style(box->style,
-                                              marker->rows,
-                                              marker->text,
-                                              LIST_MARKER_SIZE,
-                                              &counter_len);
-               if (css_res == CSS_OK) {
-                       if (counter_len > LIST_MARKER_SIZE) {
-                               /*
-                                * use computed size as marker did not fit
-                                *  in default allocation 
-                                */
-                               marker->text = talloc_realloc(ctx->bctx,
-                                                             marker->text,
-                                                             char,
-                                                             counter_len);
-                               if (marker->text == NULL) {
-                                       return false;
-                               }
-                               css_computed_format_list_style(box->style,
-                                                              marker->rows,
-                                                              marker->text,
-                                                              counter_len,
-                                                              &counter_len);
-                       }
-                       marker->length = counter_len;
-               } else {
-                       /* failed to format marker so use none type */
-                       marker->text = NULL;
-                       marker->length = 0;
-               }
-               break;
-
        }
 
        if (css_computed_list_style_image(box->style, &image_uri) == 
CSS_LIST_STYLE_IMAGE_URI &&
diff --git a/content/handlers/html/box_manipulate.c 
b/content/handlers/html/box_manipulate.c
index d23091b..8073a7f 100644
--- a/content/handlers/html/box_manipulate.c
+++ b/content/handlers/html/box_manipulate.c
@@ -143,6 +143,7 @@ box_create(css_select_results *styles,
        box->float_container = NULL;
        box->next_float = NULL;
        box->cached_place_below_level = 0;
+       box->list_value = 1;
        box->list_marker = NULL;
        box->col = NULL;
        box->gadget = NULL;
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index ddf1d16..94cdf8f 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -47,6 +47,7 @@
 #include "utils/talloc.h"
 #include "utils/utils.h"
 #include "utils/nsoption.h"
+#include "utils/corestrings.h"
 #include "utils/nsurl.h"
 #include "netsurf/inttypes.h"
 #include "netsurf/content.h"
@@ -4412,34 +4413,399 @@ layout_block_context(struct box *block,
 
 
 /**
+ * Check a node's tag type.
+ *
+ * Assumes node is an HTML element.
+ *
+ * \param[in]  node  Node to ckeck tag type of.
+ * \param[in]  type  Tag type to test for.
+ * \return true if if node has given type, false otherwise.
+ */
+static inline bool
+layout__check_element_type(
+               const dom_node *node,
+               dom_html_element_type type)
+{
+       dom_html_element_type node_type;
+       dom_exception exc;
+
+       exc = dom_html_element_get_tag_type(node, &node_type);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       return node_type == type;
+}
+
+
+/**
+ * Helper to get attribute value from a LI node.
+ *
+ * \param[in]  li_node    DOM node for the LI element;
+ * \param[out] value_out  Returns the value on success.
+ * \return true if node has value, otherwise false.
+ */
+static bool
+layout__get_li_value(dom_node *li_node, dom_long *value_out)
+{
+       dom_exception exc;
+       dom_long value;
+       bool has_value;
+
+       /** \todo
+        * dom_html_li_element_get_value() is rubbish and we can't tell
+        * a lack of value attribute or invalid value from a perfectly
+        * valid '-1'.
+        *
+        * This helps for the common case of no value.  However we should
+        * fix libdom to have some kind of sane interface to get numerical
+        * attributes.
+        */
+       exc = dom_element_has_attribute(li_node,
+                       corestring_dom_value,
+                       &has_value);
+       if (exc != DOM_NO_ERR || has_value == false) {
+               return false;
+       }
+
+       exc = dom_html_li_element_get_value(
+                       (dom_html_li_element *)li_node,
+                       &value);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       *value_out = value;
+       return true;
+}
+
+
+/**
+ * Helper to get start attribute value from a OL node.
+ *
+ * \param[in]  ol_node    DOM node for the OL element;
+ * \param[out] start_out  Returns the value on success.
+ * \return true if node has value, otherwise false.
+ */
+static bool
+layout__get_ol_start(dom_node *ol_node, dom_long *start_out)
+{
+       dom_exception exc;
+       dom_long start;
+       bool has_start;
+
+       /** \todo
+        * see layout__get_li_value().
+        */
+       exc = dom_element_has_attribute(ol_node,
+                       corestring_dom_start,
+                       &has_start);
+       if (exc != DOM_NO_ERR || has_start == false) {
+               return false;
+       }
+
+       exc = dom_html_olist_element_get_start(
+                       (dom_html_olist_element *)ol_node,
+                       &start);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       *start_out = start;
+       return true;
+}
+
+
+/**
+ * Helper to get reversed attribute value from a OL node.
+ *
+ * \param[in]  ol_node    DOM node for the OL element;
+ * \return true if node has reversed, otherwise false.
+ */
+static bool
+layout__get_ol_reversed(dom_node *ol_node)
+{
+       dom_exception exc;
+       bool has_reversed;
+
+       exc = dom_element_has_attribute(ol_node,
+                       corestring_dom_reversed,
+                       &has_reversed);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       return has_reversed;
+}
+
+
+/**
+ * Get the number of list items for a list owner.
+ *
+ * \param[in]  list_owner  DOM node to count list items for.
+ * \param[in]  count_out   Returns list item count on success.
+ * \return true on success, otherwise false.
+ */
+static bool
+layout__get_list_item_count(
+               dom_node *list_owner, int *count_out)
+{
+       dom_html_element_type tag_type;
+       dom_exception exc;
+       dom_node *child;
+       int count;
+
+       if (list_owner == NULL) {
+               return false;
+       }
+
+       exc = dom_html_element_get_tag_type(list_owner, &tag_type);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       if (tag_type != DOM_HTML_ELEMENT_TYPE_OL &&
+           tag_type != DOM_HTML_ELEMENT_TYPE_UL) {
+               return false;
+       }
+
+       exc = dom_node_get_first_child(list_owner, &child);
+       if (exc != DOM_NO_ERR) {
+               return false;
+       }
+
+       count = 0;
+       while (child != NULL) {
+               dom_node *temp_node;
+
+               if (layout__check_element_type(child,
+                               DOM_HTML_ELEMENT_TYPE_LI)) {
+                       struct box *child_box;
+                       if (dom_node_get_user_data(child,
+                                       corestring_dom___ns_key_box_node_data,
+                                       &child_box) != DOM_NO_ERR) {
+                               dom_node_unref(child);
+                               return false;
+                       }
+
+                       if (child_box != NULL &&
+                           child_box->list_marker != NULL) {
+                               count++;
+                       }
+               }
+
+               exc = dom_node_get_next_sibling(child, &temp_node);
+               dom_node_unref(child);
+               if (exc != DOM_NO_ERR) {
+                       return false;
+               }
+
+               child = temp_node;
+       }
+
+       *count_out = count;
+       return true;
+}
+
+
+/**
+ * Handle list item counting, if this is a list owner box.
+ *
+ * \param[in]  box  Box to do list item counting for.
+ */
+static void
+layout__ordered_list_count(
+               struct box *box)
+{
+       dom_html_element_type tag_type;
+       dom_exception exc;
+       dom_node *child;
+       int step = 1;
+       int next;
+
+       if (box->node == NULL) {
+               return;
+       }
+
+       exc = dom_html_element_get_tag_type(box->node, &tag_type);
+       if (exc != DOM_NO_ERR) {
+               return;
+       }
+
+       if (tag_type != DOM_HTML_ELEMENT_TYPE_OL &&
+           tag_type != DOM_HTML_ELEMENT_TYPE_UL) {
+               return;
+       }
+
+       next = 1;
+       if (tag_type == DOM_HTML_ELEMENT_TYPE_OL) {
+               bool have_start = layout__get_ol_start(box->node, &next);
+               bool have_reversed = layout__get_ol_reversed(box->node);
+
+               if (have_reversed) {
+                       step = -1;
+               }
+
+               if (!have_start && have_reversed) {
+                       layout__get_list_item_count(box->node, &next);
+               }
+       }
+
+       exc = dom_node_get_first_child(box->node, &child);
+       if (exc != DOM_NO_ERR) {
+               return;
+       }
+
+       while (child != NULL) {
+               dom_node *temp_node;
+
+               if (layout__check_element_type(child,
+                               DOM_HTML_ELEMENT_TYPE_LI)) {
+                       struct box *child_box;
+
+                       if (dom_node_get_user_data(child,
+                                       corestring_dom___ns_key_box_node_data,
+                                       &child_box) != DOM_NO_ERR) {
+                               dom_node_unref(child);
+                               return;
+                       }
+
+                       if (child_box != NULL &&
+                           child_box->list_marker != NULL) {
+                               dom_long value;
+                               struct box *marker = child_box->list_marker;
+                               if (layout__get_li_value(child, &value)) {
+                                       marker->list_value = value;
+                                       next = marker->list_value;
+                               } else {
+                                       marker->list_value = next;
+                               }
+                               next += step;
+                       }
+               }
+
+               exc = dom_node_get_next_sibling(child, &temp_node);
+               dom_node_unref(child);
+               if (exc != DOM_NO_ERR) {
+                       return;
+               }
+
+               child = temp_node;
+       }
+}
+
+/**
+ * Set up the marker text for a numerical list item.
+ *
+ * \param[in]  content  The HTML content.
+ * \param[in]  box      The list item's main box.
+ */
+static void
+layout__set_numerical_marker_text(
+               const html_content *content,
+               struct box *box)
+{
+       struct box *marker = box->list_marker;
+       size_t counter_len;
+       css_error css_res;
+       enum {
+               /**
+                * initial length of a list marker buffer
+                *
+                * enough for 9,999,999,999,999,999,999 in decimal
+                * or five characters for 4-byte UTF-8.
+                */
+               LIST_MARKER_SIZE = 20,
+       };
+
+       marker->text = talloc_array(content->bctx, char, LIST_MARKER_SIZE);
+       if (marker->text == NULL) {
+               return;
+       }
+
+       css_res = css_computed_format_list_style(box->style, marker->list_value,
+                       marker->text, LIST_MARKER_SIZE, &counter_len);
+       if (css_res == CSS_OK) {
+               if (counter_len > LIST_MARKER_SIZE) {
+                       /* Use computed size as marker did not fit in
+                        * default allocation. */
+                       marker->text = talloc_realloc(content->bctx,
+                                       marker->text,
+                                       char,
+                                       counter_len);
+                       if (marker->text == NULL) {
+                               return;
+                       }
+                       css_computed_format_list_style(box->style,
+                                       marker->list_value, marker->text,
+                                       counter_len, &counter_len);
+               }
+               marker->length = counter_len;
+       }
+}
+
+/**
+ * Find out if box's style represents a numerical list style type.
+ *
+ * \param[in]  b  Box with style to test.
+ * \return true if box has numerical list style type, false otherwise.
+ */
+static bool
+layout__list_item_is_numerical(
+               const struct box *b)
+{
+       enum css_list_style_type_e t = css_computed_list_style_type(b->style);
+
+       switch (t) {
+       case CSS_LIST_STYLE_TYPE_DISC:   /* Fall through. */
+       case CSS_LIST_STYLE_TYPE_CIRCLE: /* Fall through. */
+       case CSS_LIST_STYLE_TYPE_SQUARE: /* Fall through. */
+       case CSS_LIST_STYLE_TYPE_NONE:
+               return false;
+
+       default:
+               return true;
+       }
+}
+
+/**
  * Layout list markers.
  */
 static void
-layout_lists(struct box *box,
-            const struct gui_layout_table *font_func,
-            const nscss_len_ctx *len_ctx)
+layout_lists(const html_content *content, struct box *box)
 {
        struct box *child;
-       struct box *marker;
-       plot_font_style_t fstyle;
+
+       layout__ordered_list_count(box);
 
        for (child = box->children; child; child = child->next) {
                if (child->list_marker) {
-                       marker = child->list_marker;
+                       struct box *marker = child->list_marker;
+
+                       if (layout__list_item_is_numerical(child)) {
+                               if (marker->text == NULL) {
+                                       layout__set_numerical_marker_text(
+                                                       content, child);
+                               }
+                       }
                        if (marker->object) {
                                marker->width =
                                        content_get_width(marker->object);
                                marker->x = -marker->width;
                                marker->height =
                                        content_get_height(marker->object);
-                               marker->y = (line_height(len_ctx,
+                               marker->y = (line_height(
+                                               &content->len_ctx,
                                                marker->style) -
                                                marker->height) / 2;
                        } else if (marker->text) {
                                if (marker->width == UNKNOWN_WIDTH) {
-                                       font_plot_style_from_css(len_ctx,
-                                                       marker->style, &fstyle);
-                                       font_func->width(&fstyle,
+                                       plot_font_style_t fstyle;
+                                       font_plot_style_from_css(
+                                                       &content->len_ctx,
+                                                       marker->style,
+                                                       &fstyle);
+                                       content->font_func->width(&fstyle,
                                                        marker->text,
                                                        marker->length,
                                                        &marker->width);
@@ -4447,7 +4813,8 @@ layout_lists(struct box *box,
                                }
                                marker->x = -marker->width;
                                marker->y = 0;
-                               marker->height = line_height(len_ctx,
+                               marker->height = line_height(
+                                               &content->len_ctx,
                                                marker->style);
                        } else {
                                marker->x = 0;
@@ -4458,7 +4825,7 @@ layout_lists(struct box *box,
                        /* Gap between marker and content */
                        marker->x -= 4;
                }
-               layout_lists(child, font_func, len_ctx);
+               layout_lists(content, child);
        }
 }
 
@@ -5436,7 +5803,7 @@ bool layout_document(html_content *content, int width, 
int height)
                                         doc->children->margin[BOTTOM]);
        }
 
-       layout_lists(doc, font_func, &content->len_ctx);
+       layout_lists(content, doc);
        layout_position_absolute(doc, doc, 0, 0, content);
        layout_position_relative(&content->len_ctx, doc, doc, 0, 0);
 
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index d6be3c4..b253b3b 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -295,6 +295,7 @@ CORESTRING_DOM_STRING(rect);
 CORESTRING_DOM_STRING(rel);
 CORESTRING_DOM_STRING(reset);
 CORESTRING_DOM_STRING(resize);
+CORESTRING_DOM_STRING(reversed);
 CORESTRING_DOM_STRING(rows);
 CORESTRING_DOM_STRING(rowspan);
 CORESTRING_DOM_STRING(scroll);
@@ -309,6 +310,7 @@ CORESTRING_DOM_STRING(size);
 CORESTRING_DOM_STRING(sizes);
 CORESTRING_DOM_STRING(src);
 CORESTRING_DOM_STRING(stalled);
+CORESTRING_DOM_STRING(start);
 CORESTRING_DOM_STRING(storage);
 CORESTRING_DOM_STRING(style);
 CORESTRING_DOM_STRING(submit);


-- 
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to