summaryrefslogtreecommitdiff
path: root/content/handlers/text/textplain.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/text/textplain.c')
-rw-r--r--content/handlers/text/textplain.c136
1 files changed, 85 insertions, 51 deletions
diff --git a/content/handlers/text/textplain.c b/content/handlers/text/textplain.c
index 534b91d93..d8f61be89 100644
--- a/content/handlers/text/textplain.c
+++ b/content/handlers/text/textplain.c
@@ -1452,6 +1452,68 @@ textplain_textsearch_find(struct content *c,
/**
+ * Given a range of byte offsets within a UTF8 textplain content,
+ * return a box that fully encloses the text
+ *
+ * \param[in] c content of type CONTENT_TEXTPLAIN
+ * \param[in] start byte offset of start of text range
+ * \param[in] end byte offset of end
+ * \param[out] r rectangle to be completed
+ */
+static void
+textplain_coords_from_range(struct content *c,
+ unsigned start,
+ unsigned end,
+ struct rect *r)
+{
+ textplain_content *text = (textplain_content *) c;
+ float line_height = textplain_line_height();
+ char *utf8_data;
+ struct textplain_line *line;
+ unsigned lineno = 0;
+ unsigned nlines;
+
+ assert(c != NULL);
+ assert(start <= end);
+ assert(end <= text->utf8_data_size);
+
+ utf8_data = text->utf8_data;
+ nlines = text->physical_line_count;
+ line = text->physical_line;
+
+ /* find start */
+ lineno = textplain_find_line(c, start);
+
+ r->y0 = (int)(MARGIN + lineno * line_height);
+
+ if (lineno + 1 <= nlines || line[lineno + 1].start >= end) {
+ /* \todo - it may actually be more efficient just to
+ * run forwards most of the time
+ */
+
+ /* find end */
+ lineno = textplain_find_line(c, end);
+
+ r->x0 = 0;
+ r->x1 = text->formatted_width;
+ } else {
+ /* single line */
+ const char *text = utf8_data + line[lineno].start;
+
+ r->x0 = textplain_coord_from_offset(text,
+ start - line[lineno].start,
+ line[lineno].length);
+
+ r->x1 = textplain_coord_from_offset(text,
+ end - line[lineno].start,
+ line[lineno].length);
+ }
+
+ r->y1 = (int)(MARGIN + (lineno + 1) * line_height);
+}
+
+
+/**
* get bounds of a free text search match
*/
static nserror
@@ -1488,6 +1550,28 @@ textplain_create_selection(struct content *c, struct selection **sel_out)
/**
+ * invalidate a region based on offsets into the text cauing a redraw
+ */
+static nserror
+textplain_textselection_redraw(struct content *c,
+ unsigned start_idx,
+ unsigned end_idx)
+{
+ struct rect r;
+
+ if (end_idx <= start_idx) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ textplain_coords_from_range(c, start_idx, end_idx, &r);
+
+ content__request_redraw(c, r.x0, r.y0, r.x1 - r.x0, r.y1 - r.y0);
+
+ return NSERROR_OK;
+}
+
+
+/**
* plain text content handler table
*/
static const content_handler textplain_content_handler = {
@@ -1508,6 +1592,7 @@ static const content_handler textplain_content_handler = {
.type = textplain_content_type,
.textsearch_find = textplain_textsearch_find,
.textsearch_bounds = textplain_textsearch_bounds,
+ .textselection_redraw = textplain_textselection_redraw,
.create_selection = textplain_create_selection,
.no_share = true,
};
@@ -1555,58 +1640,7 @@ size_t textplain_size(struct content *c)
}
-/* exported interface documented in html/textplain.h */
-void
-textplain_coords_from_range(struct content *c,
- unsigned start,
- unsigned end,
- struct rect *r)
-{
- textplain_content *text = (textplain_content *) c;
- float line_height = textplain_line_height();
- char *utf8_data;
- struct textplain_line *line;
- unsigned lineno = 0;
- unsigned nlines;
-
- assert(c != NULL);
- assert(start <= end);
- assert(end <= text->utf8_data_size);
-
- utf8_data = text->utf8_data;
- nlines = text->physical_line_count;
- line = text->physical_line;
- /* find start */
- lineno = textplain_find_line(c, start);
-
- r->y0 = (int)(MARGIN + lineno * line_height);
-
- if (lineno + 1 <= nlines || line[lineno + 1].start >= end) {
- /* \todo - it may actually be more efficient just to
- * run forwards most of the time
- */
-
- /* find end */
- lineno = textplain_find_line(c, end);
-
- r->x0 = 0;
- r->x1 = text->formatted_width;
- } else {
- /* single line */
- const char *text = utf8_data + line[lineno].start;
-
- r->x0 = textplain_coord_from_offset(text,
- start - line[lineno].start,
- line[lineno].length);
-
- r->x1 = textplain_coord_from_offset(text,
- end - line[lineno].start,
- line[lineno].length);
- }
-
- r->y1 = (int)(MARGIN + (lineno + 1) * line_height);
-}
/* exported interface documented in html/textplain.h */