summaryrefslogtreecommitdiff
path: root/content/handlers/text
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2020-05-23 20:38:41 +0100
committerVincent Sanders <vince@kyllikki.org>2020-05-23 23:00:08 +0100
commite65e41e2d6efccba983cd63aadfb10b5b4a935b2 (patch)
tree3833ea9b7bb989fd5c96d5d230b66b6d29a59794 /content/handlers/text
parent36b9262e1481fc24d302b58f03006e733b2e6d16 (diff)
downloadnetsurf-e65e41e2d6efccba983cd63aadfb10b5b4a935b2.tar.gz
netsurf-e65e41e2d6efccba983cd63aadfb10b5b4a935b2.tar.bz2
move content handler specific selection copying into handlers
Diffstat (limited to 'content/handlers/text')
-rw-r--r--content/handlers/text/textplain.c79
-rw-r--r--content/handlers/text/textplain.h14
2 files changed, 55 insertions, 38 deletions
diff --git a/content/handlers/text/textplain.c b/content/handlers/text/textplain.c
index d8f61be89..275efda83 100644
--- a/content/handlers/text/textplain.c
+++ b/content/handlers/text/textplain.c
@@ -1514,6 +1514,43 @@ textplain_coords_from_range(struct content *c,
/**
+ * Return a pointer to the raw UTF-8 data, as opposed to the reformatted
+ * text to fit the window width. Thus only hard newlines are preserved
+ * in the saved/copied text of a selection.
+ *
+ * \param[in] c content of type CONTENT_TEXTPLAIN
+ * \param[in] start starting byte offset within UTF-8 text
+ * \param[in] end ending byte offset
+ * \param[out] plen receives validated length
+ * \return pointer to text, or NULL if no text
+ */
+static char *
+textplain_get_raw_data(struct content *c,
+ unsigned start,
+ unsigned end,
+ size_t *plen)
+{
+ textplain_content *text = (textplain_content *) c;
+ size_t utf8_size;
+
+ assert(c != NULL);
+
+ utf8_size = text->utf8_data_size;
+
+ /* any text at all? */
+ if (!utf8_size) return NULL;
+
+ /* clamp to valid offset range */
+ if (start >= utf8_size) start = utf8_size;
+ if (end >= utf8_size) end = utf8_size;
+
+ *plen = end - start;
+
+ return text->utf8_data + start;
+}
+
+
+/**
* get bounds of a free text search match
*/
static nserror
@@ -1570,6 +1607,23 @@ textplain_textselection_redraw(struct content *c,
return NSERROR_OK;
}
+static nserror
+textplain_textselection_copy(struct content *c,
+ unsigned start_idx,
+ unsigned end_idx,
+ struct selection_string *selstr)
+{
+ const char *text;
+ size_t length;
+ bool res;
+
+ text = textplain_get_raw_data(c, start_idx, end_idx, &length);
+ res = selection_string_append(text, length, false, NULL, selstr);
+ if (res == false) {
+ return NSERROR_NOMEM;
+ }
+ return NSERROR_OK;
+}
/**
* plain text content handler table
@@ -1593,6 +1647,7 @@ static const content_handler textplain_content_handler = {
.textsearch_find = textplain_textsearch_find,
.textsearch_bounds = textplain_textsearch_bounds,
.textselection_redraw = textplain_textselection_redraw,
+ .textselection_copy = textplain_textselection_copy,
.create_selection = textplain_create_selection,
.no_share = true,
};
@@ -1643,28 +1698,4 @@ size_t textplain_size(struct content *c)
-/* exported interface documented in html/textplain.h */
-char *
-textplain_get_raw_data(struct content *c,
- unsigned start,
- unsigned end,
- size_t *plen)
-{
- textplain_content *text = (textplain_content *) c;
- size_t utf8_size;
- assert(c != NULL);
-
- utf8_size = text->utf8_data_size;
-
- /* any text at all? */
- if (!utf8_size) return NULL;
-
- /* clamp to valid offset range */
- if (start >= utf8_size) start = utf8_size;
- if (end >= utf8_size) end = utf8_size;
-
- *plen = end - start;
-
- return text->utf8_data + start;
-}
diff --git a/content/handlers/text/textplain.h b/content/handlers/text/textplain.h
index 206c5831e..b94ee33d3 100644
--- a/content/handlers/text/textplain.h
+++ b/content/handlers/text/textplain.h
@@ -46,18 +46,4 @@ nserror textplain_init(void);
size_t textplain_size(struct content *c);
-/**
- * Return a pointer to the raw UTF-8 data, as opposed to the reformatted
- * text to fit the window width. Thus only hard newlines are preserved
- * in the saved/copied text of a selection.
- *
- * \param[in] c content of type CONTENT_TEXTPLAIN
- * \param[in] start starting byte offset within UTF-8 text
- * \param[in] end ending byte offset
- * \param[out] plen receives validated length
- * \return pointer to text, or NULL if no text
- */
-char *textplain_get_raw_data(struct content *c, unsigned start, unsigned end, size_t *plen);
-
-
#endif