summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2021-02-09 19:04:52 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2021-02-09 20:36:52 +0000
commit839fb8570a4fb8a31a76605b4614e7384d60f039 (patch)
treefd43359404d2f1711d487accd160de2ff0962f57 /content
parentdcec1d0cd58343f64d4dd0b7d52e2c5d6193dfe8 (diff)
downloadnetsurf-839fb8570a4fb8a31a76605b4614e7384d60f039.tar.gz
netsurf-839fb8570a4fb8a31a76605b4614e7384d60f039.tar.bz2
layout: Add counting for list items to layout.
Diffstat (limited to 'content')
-rw-r--r--content/handlers/html/box.h1
-rw-r--r--content/handlers/html/layout.c97
2 files changed, 97 insertions, 1 deletions
diff --git a/content/handlers/html/box.h b/content/handlers/html/box.h
index d0df73568..a193d3c2a 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 ddf1d1632..ce3fe18ca 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;