diff options
author | Vincent Sanders <vince@kyllikki.org> | 2020-05-23 22:00:00 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2020-05-23 23:00:08 +0100 |
commit | a8c540ea597fb17426c5458fa464f9c505c3bda8 (patch) | |
tree | ff85eff8288d5c1584d82ef6719b3c87ce7e5f48 /content/handlers/html/textselection.c | |
parent | cfe57002febe0f58dfc87f0173ad42126f1362f4 (diff) | |
download | netsurf-a8c540ea597fb17426c5458fa464f9c505c3bda8.tar.gz netsurf-a8c540ea597fb17426c5458fa464f9c505c3bda8.tar.bz2 |
move content specific selection end to content handlers
Diffstat (limited to 'content/handlers/html/textselection.c')
-rw-r--r-- | content/handlers/html/textselection.c | 47 |
1 files changed, 45 insertions, 2 deletions
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; +} |