summaryrefslogtreecommitdiff
path: root/content/handlers/html
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/html')
-rw-r--r--content/handlers/html/html.c5
-rw-r--r--content/handlers/html/textselection.c47
-rw-r--r--content/handlers/html/textselection.h9
3 files changed, 57 insertions, 4 deletions
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 136c4eef2..2c471ae40 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -1056,7 +1056,7 @@ static void html_reformat(struct content *c, int width, int height)
if (c->height < layout->y + layout->descendant_y1)
c->height = layout->y + layout->descendant_y1;
- selection_reinit(&htmlc->sel, htmlc->layout);
+ selection_reinit(&htmlc->sel);
htmlc->reflowing = false;
htmlc->had_initial_layout = true;
@@ -1304,7 +1304,7 @@ html_open(struct content *c,
html->drag_owner.no_owner = true;
/* text selection */
- selection_init(&html->sel, html->layout);
+ selection_init(&html->sel);
html->selection_type = HTML_SELECTION_NONE;
html->selection_owner.none = true;
@@ -2337,6 +2337,7 @@ static const content_handler html_content_handler = {
.textsearch_bounds = html_textsearch_bounds,
.textselection_redraw = html_textselection_redraw,
.textselection_copy = html_textselection_copy,
+ .textselection_get_end = html_textselection_get_end,
.create_selection = html_create_selection,
.no_share = true,
};
diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c
index 67fd25be3..06e28e11f 100644
--- a/content/handlers/html/textselection.c
+++ b/content/handlers/html/textselection.c
@@ -264,14 +264,13 @@ coords_from_range(struct box *box,
nserror
html_create_selection(struct content *c, struct selection **sel_out)
{
- html_content *html = (html_content *)c;
struct selection *sel;
sel = selection_create(c, true);
if (sel == NULL) {
return NSERROR_NOMEM;
}
- selection_init(sel, html->layout);
+ selection_init(sel);
*sel_out = sel;
return NSERROR_OK;
@@ -528,3 +527,47 @@ html_textselection_copy(struct content *c,
}
return NSERROR_OK;
}
+
+
+/**
+ * Label each text box in the given box subtree with its position
+ * in a textual representation of the content.
+ *
+ * \param box The box at root of subtree
+ * \param idx current position within textual representation
+ * \return updated position
+ */
+static unsigned selection_label_subtree(struct box *box, unsigned idx)
+{
+ struct box *child = box->children;
+
+ box->byte_offset = idx;
+
+ if (box->text) {
+ idx += box->length + SPACE_LEN(box);
+ }
+
+ while (child) {
+ if (child->list_marker) {
+ idx = selection_label_subtree(child->list_marker, idx);
+ }
+
+ idx = selection_label_subtree(child, idx);
+ child = child->next;
+ }
+
+ return idx;
+}
+
+/* exported interface documented in html/textselection.h */
+nserror
+html_textselection_get_end(struct content *c, unsigned *end_idx)
+{
+ html_content *html = (html_content *)c;
+ unsigned root_idx;
+
+ root_idx = 0;
+
+ *end_idx = selection_label_subtree(html->layout, root_idx);
+ return NSERROR_OK;
+}
diff --git a/content/handlers/html/textselection.h b/content/handlers/html/textselection.h
index 4a866b0b2..95d7078c5 100644
--- a/content/handlers/html/textselection.h
+++ b/content/handlers/html/textselection.h
@@ -36,4 +36,13 @@ nserror html_textselection_redraw(struct content *c, unsigned start_idx, unsigne
nserror html_textselection_copy(struct content *c, unsigned start_idx, unsigned end_idx, struct selection_string *selstr);
+/**
+ * get maximum index of text section.
+ *
+ * \param[in] c The content to measure
+ * \param[out] end_idx pointer to value to recive result
+ * \return NSERROR_OK and \a end_idx updated else error code
+ */
+nserror html_textselection_get_end(struct content *c, unsigned *end_idx);
+
#endif