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, tlsa/list-values has been created
at 9783296c4ffd83dfdb18e1e293ad635f214d2fd0 (commit)
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9783296c4ffd83dfdb18e1e293ad635f214d2fd0
commit 9783296c4ffd83dfdb18e1e293ad635f214d2fd0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
layout: Add support for OL reversed attribute.
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 672084a..94cdf8f 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4517,6 +4517,98 @@ layout__get_ol_start(dom_node *ol_node, dom_long
*start_out)
/**
+ * 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.
@@ -4547,7 +4639,16 @@ layout__ordered_list_count(
next = 1;
if (tag_type == DOM_HTML_ELEMENT_TYPE_OL) {
- layout__get_ol_start(box->node, &next);
+ 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);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=32d9de461e4cb9c287dbafb0745ac64358a0b561
commit 32d9de461e4cb9c287dbafb0745ac64358a0b561
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
util: corestring: Add DOM "reversed" string.
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index b287cde..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);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=496b1eca087490346a29c6c062c53a21e679ddd5
commit 496b1eca087490346a29c6c062c53a21e679ddd5
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
layout: list handling: Scope reduce some variables in the recursive call.
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 6d7d70f..672084a 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4674,14 +4674,13 @@ static void
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(
@@ -4700,6 +4699,7 @@ layout_lists(const html_content *content, struct box *box)
marker->height) / 2;
} else if (marker->text) {
if (marker->width == UNKNOWN_WIDTH) {
+ plot_font_style_t fstyle;
font_plot_style_from_css(
&content->len_ctx,
marker->style,
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=d29f6d6c1e8433f718b6de3d31626cd6f06c352f
commit d29f6d6c1e8433f718b6de3d31626cd6f06c352f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: layout: Change list value step to variable.
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 8f84cf4..6d7d70f 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4528,6 +4528,7 @@ layout__ordered_list_count(
dom_html_element_type tag_type;
dom_exception exc;
dom_node *child;
+ int step = 1;
int next;
if (box->node == NULL) {
@@ -4578,7 +4579,7 @@ layout__ordered_list_count(
} else {
marker->list_value = next;
}
- next++;
+ next += step;
}
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=e18bb8fde15d860f198b9555ddac123273ea2e30
commit e18bb8fde15d860f198b9555ddac123273ea2e30
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: Add support for OL start attribute.
Note: Added new box member because rows was unsigned, and it was
naughty to use something meant for tables.
Note: Now numbers <= 0 can be generated, but LibCSS needs updated
to support that.
diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h
index a193d3c..1059556 100644
--- a/content/handlers/html/box.h
+++ b/content/handlers/html/box.h
@@ -405,6 +405,11 @@ struct box {
struct column *col;
/**
+ * List item value.
+ */
+ int list_value;
+
+ /**
* List marker box if this is a list-item, or NULL.
*/
struct box *list_marker;
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 b46b8a5..8f84cf4 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4481,6 +4481,42 @@ layout__get_li_value(dom_node *li_node, dom_long
*value_out)
/**
+ * 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;
+}
+
+
+/**
* Handle list item counting, if this is a list owner box.
*
* \param[in] box Box to do list item counting for.
@@ -4492,8 +4528,7 @@ layout__ordered_list_count(
dom_html_element_type tag_type;
dom_exception exc;
dom_node *child;
- unsigned count;
- unsigned next;
+ int next;
if (box->node == NULL) {
return;
@@ -4509,13 +4544,16 @@ layout__ordered_list_count(
return;
}
+ next = 1;
+ if (tag_type == DOM_HTML_ELEMENT_TYPE_OL) {
+ layout__get_ol_start(box->node, &next);
+ }
+
exc = dom_node_get_first_child(box->node, &child);
if (exc != DOM_NO_ERR) {
return;
}
- count = 1;
- next = 1;
while (child != NULL) {
dom_node *temp_node;
@@ -4533,14 +4571,14 @@ layout__ordered_list_count(
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)) {
- child_box->list_marker->rows = value;
- next = value + 1;
+ marker->list_value = value;
+ next = marker->list_value;
} else {
- child_box->list_marker->rows = next;
- next++;
+ marker->list_value = next;
}
- count++;
+ next++;
}
}
@@ -4552,8 +4590,6 @@ layout__ordered_list_count(
child = temp_node;
}
-
- box->rows = count;
}
/**
@@ -4585,7 +4621,7 @@ layout__set_numerical_marker_text(
return;
}
- css_res = css_computed_format_list_style(box->style, marker->rows,
+ 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) {
@@ -4599,7 +4635,7 @@ layout__set_numerical_marker_text(
return;
}
css_computed_format_list_style(box->style,
- marker->rows, marker->text,
+ marker->list_value, marker->text,
counter_len, &counter_len);
}
marker->length = counter_len;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=4c941254c8cfd1cf0e6f005d39ed0cc8f8ff077c
commit 4c941254c8cfd1cf0e6f005d39ed0cc8f8ff077c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
util: corestring: Add DOM "start" string.
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index d6be3c4..b287cde 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -309,6 +309,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);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=64680a8edbebcfbcb5f2f2ddcce9a998aeef19f3
commit 64680a8edbebcfbcb5f2f2ddcce9a998aeef19f3
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
layout: Add support for list item value attribute.
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index 2f222b9..b46b8a5 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4439,6 +4439,48 @@ layout__check_element_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;
+}
+
+
+/**
* Handle list item counting, if this is a list owner box.
*
* \param[in] box Box to do list item counting for.
@@ -4451,6 +4493,7 @@ layout__ordered_list_count(
dom_exception exc;
dom_node *child;
unsigned count;
+ unsigned next;
if (box->node == NULL) {
return;
@@ -4472,6 +4515,7 @@ layout__ordered_list_count(
}
count = 1;
+ next = 1;
while (child != NULL) {
dom_node *temp_node;
@@ -4488,7 +4532,14 @@ layout__ordered_list_count(
if (child_box != NULL &&
child_box->list_marker != NULL) {
- child_box->list_marker->rows = count;
+ dom_long value;
+ if (layout__get_li_value(child, &value)) {
+ child_box->list_marker->rows = value;
+ next = value + 1;
+ } else {
+ child_box->list_marker->rows = next;
+ next++;
+ }
count++;
}
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=41a0c21812ed1fb59bf75cbe26a8b8c5e19e71a0
commit 41a0c21812ed1fb59bf75cbe26a8b8c5e19e71a0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: Do list item counting at layout time.
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/layout.c b/content/handlers/html/layout.c
index 8303d7b..2f222b9 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4505,6 +4505,79 @@ layout__ordered_list_count(
box->rows = count;
}
+/**
+ * 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->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(content->bctx,
+ marker->text,
+ char,
+ counter_len);
+ if (marker->text == NULL) {
+ return;
+ }
+ css_computed_format_list_style(box->style,
+ marker->rows, 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.
@@ -4521,6 +4594,12 @@ layout_lists(const html_content *content, struct box
*box)
for (child = box->children; child; child = child->next) {
if (child->list_marker) {
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);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9434fe1ff08cb9e009efa9cd434177d91948d12e
commit 9434fe1ff08cb9e009efa9cd434177d91948d12e
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
layout: Pass content into list layout function.
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index ce3fe18..8303d7b 100644
--- a/content/handlers/html/layout.c
+++ b/content/handlers/html/layout.c
@@ -4510,9 +4510,7 @@ layout__ordered_list_count(
* 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;
@@ -4529,14 +4527,17 @@ layout_lists(struct box *box,
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,
+ font_plot_style_from_css(
+ &content->len_ctx,
+ marker->style,
+ &fstyle);
+ content->font_func->width(&fstyle,
marker->text,
marker->length,
&marker->width);
@@ -4544,7 +4545,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;
@@ -4555,7 +4557,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);
}
}
@@ -5533,7 +5535,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);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=839fb8570a4fb8a31a76605b4614e7384d60f039
commit 839fb8570a4fb8a31a76605b4614e7384d60f039
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
layout: Add counting for list items to layout.
diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h
index d0df735..a193d3c 100644
--- a/content/handlers/html/box.h
+++ b/content/handlers/html/box.h
@@ -404,7 +404,6 @@ struct box {
*/
struct column *col;
-
/**
* List marker box if this is a list-item, or NULL.
*/
diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c
index ddf1d16..ce3fe18 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,6 +4413,100 @@ 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;
+}
+
+
+/**
+ * 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;
+ unsigned count;
+
+ 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;
+ }
+
+ exc = dom_node_get_first_child(box->node, &child);
+ if (exc != DOM_NO_ERR) {
+ return;
+ }
+
+ count = 1;
+ 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) {
+ child_box->list_marker->rows = count;
+ count++;
+ }
+ }
+
+ exc = dom_node_get_next_sibling(child, &temp_node);
+ dom_node_unref(child);
+ if (exc != DOM_NO_ERR) {
+ return;
+ }
+
+ child = temp_node;
+ }
+
+ box->rows = count;
+}
+
+
+/**
* Layout list markers.
*/
static void
@@ -4423,6 +4518,8 @@ layout_lists(struct box *box,
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;
-----------------------------------------------------------------------
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]