summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Lees <adrian@aemulor.com>2005-04-15 05:52:11 +0000
committerAdrian Lees <adrian@aemulor.com>2005-04-15 05:52:11 +0000
commit043db9ece0fd2d2ea8ac02e7fa2fbc2ed371415e (patch)
treeba8e63174b632973391ecdbf9da838e0aa4e613d
parent25e9cbf55bce63c27a66313503e58d113a84edb3 (diff)
downloadnetsurf-043db9ece0fd2d2ea8ac02e7fa2fbc2ed371415e.tar.gz
netsurf-043db9ece0fd2d2ea8ac02e7fa2fbc2ed371415e.tar.bz2
[project @ 2005-04-15 05:52:11 by adrianl]
Text selection svn path=/import/netsurf/; revision=1636
-rw-r--r--render/box.h2
-rw-r--r--render/html_redraw.c105
2 files changed, 92 insertions, 15 deletions
diff --git a/render/box.h b/render/box.h
index fe67e8fb3..bcdf79005 100644
--- a/render/box.h
+++ b/render/box.h
@@ -141,6 +141,8 @@ struct box {
int min_width;
int max_width; /**< Width that would be taken with no line breaks. */
+ unsigned byte_offset; /**< byte offset within a textual representation of this content */
+
char *text; /**< Text, or 0 if none. Unterminated. */
size_t length; /**< Length of text. */
diff --git a/render/html_redraw.c b/render/html_redraw.c
index d38c677cb..491631194 100644
--- a/render/html_redraw.c
+++ b/render/html_redraw.c
@@ -16,6 +16,7 @@
#include "netsurf/content/content.h"
#include "netsurf/css/css.h"
#include "netsurf/desktop/plotters.h"
+#include "netsurf/desktop/selection.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
#include "netsurf/render/form.h"
@@ -119,16 +120,33 @@ bool html_redraw_box(struct box *box,
int colour;
int x_scrolled, y_scrolled;
- x = (x_parent + box->x) * scale;
- y = (y_parent + box->y) * scale;
- width = box->width * scale;
- height = box->height * scale;
- padding_left = box->padding[LEFT] * scale;
- padding_top = box->padding[TOP] * scale;
- padding_width = (box->padding[LEFT] + box->width +
- box->padding[RIGHT]) * scale;
- padding_height = (box->padding[TOP] + box->height +
- box->padding[BOTTOM]) * scale;
+ /* avoid trivial FP maths */
+ if (scale == 1.0) {
+ x = (x_parent + box->x);
+ y = (y_parent + box->y);
+ width = box->width;
+ height = box->height;
+ padding_left = box->padding[LEFT];
+ padding_top = box->padding[TOP];
+ padding_width = padding_left + box->width + box->padding[RIGHT];
+ padding_height = padding_top + box->height + box->padding[BOTTOM];
+ }
+ else {
+ x = (x_parent + box->x) * scale;
+ y = (y_parent + box->y) * scale;
+ width = box->width * scale;
+ height = box->height * scale;
+ /* left and top padding values are normally zero, so avoid trivial FP maths */
+ padding_left = box->padding[LEFT] ? (box->padding[LEFT] * scale) : 0;
+ padding_top = box->padding[TOP] ? (box->padding[TOP] * scale) : 0;
+ padding_width = (box->padding[LEFT] + box->width +
+ box->padding[RIGHT]) * scale;
+ padding_height = (box->padding[TOP] + box->height +
+ box->padding[BOTTOM]) * scale;
+ }
+
+//LOG(("%d %d %d %d", padding_top, padding_left, padding_width, padding_height));
+//padding_top and padding_left are often 0
/* calculate clip rectangle for this box */
if (box->style && box->style->overflow != CSS_OVERFLOW_VISIBLE) {
@@ -296,6 +314,10 @@ bool html_redraw_box(struct box *box,
return false;
} else if (box->text) {
+
+ unsigned start_idx;
+ unsigned end_idx;
+
/* antialias colour for under/overline */
colour = html_redraw_aa(current_background_color,
/*print_text_black ? 0 :*/ box->style->color);
@@ -330,12 +352,65 @@ bool html_redraw_box(struct box *box,
return false;
}
- if (!plot.text(x, y + (int) (box->height * 0.75 * scale),
- box->style, box->text, box->length,
- current_background_color,
- /*print_text_black ? 0 :*/ box->style->color))
- return false;
+ /* is this box part of the current selection? */
+ if (box->text && !box->object && current_redraw_browser &&
+ selection_defined(current_redraw_browser->sel) &&
+ selection_highlighted(current_redraw_browser->sel, box,
+ &start_idx, &end_idx)) {
+
+ int startx, endx;
+
+ if (!nsfont_width(box->style, box->text, start_idx, &startx))
+ startx = 0;
+
+ if (!nsfont_width(box->style, box->text + start_idx,
+ end_idx - start_idx, &endx))
+ endx = 0;
+ endx += startx;
+
+ if (scale != 1.0) {
+ startx *= scale;
+ endx *= scale;
+ }
+
+ if (start_idx > 0) {
+
+ if (!plot.text(x, y + (int) (box->height * 0.75 * scale),
+ box->style, box->text, start_idx,
+ current_background_color,
+ /*print_text_black ? 0 :*/ box->style->color))
+ return false;
+
+ }
+
+ if (!plot.fill(x + startx, y, x + endx, y + box->height * scale,
+ current_background_color ^ 0xffffff))
+ return false;
+
+ if (!plot.text(x + startx, y + (int) (box->height * 0.75 * scale),
+ box->style, box->text + start_idx, end_idx - start_idx,
+ current_background_color ^ 0xffffff,
+ current_background_color))
+ return false;
+
+ if (end_idx < box->length) {
+
+ if (!plot.text(x + endx, y + (int) (box->height * 0.75 * scale),
+ box->style, box->text + end_idx, box->length - end_idx,
+ current_background_color,
+ /*print_text_black ? 0 :*/ box->style->color))
+ return false;
+
+ }
+ }
+ else {
+ if (!plot.text(x, y + (int) (box->height * 0.75 * scale),
+ box->style, box->text, box->length,
+ current_background_color,
+ /*print_text_black ? 0 :*/ box->style->color))
+ return false;
+ }
} else {
for (c = box->children; c != 0; c = c->next)
if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT)