From e18bb8fde15d860f198b9555ddac123273ea2e30 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 10 Feb 2021 17:09:20 +0000 Subject: 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. --- content/handlers/html/box.h | 5 +++ content/handlers/html/box_manipulate.c | 1 + content/handlers/html/layout.c | 62 +++++++++++++++++++++++++++------- 3 files changed, 55 insertions(+), 13 deletions(-) (limited to 'content/handlers/html') diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h index a193d3c2a..1059556e6 100644 --- a/content/handlers/html/box.h +++ b/content/handlers/html/box.h @@ -404,6 +404,11 @@ 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_manipulate.c b/content/handlers/html/box_manipulate.c index d23091b7c..8073a7fd1 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 b46b8a592..8f84cf4b6 100644 --- a/content/handlers/html/layout.c +++ b/content/handlers/html/layout.c @@ -4480,6 +4480,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. * @@ -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; -- cgit v1.2.3