summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Lees <adrian@aemulor.com>2005-04-16 08:22:57 +0000
committerAdrian Lees <adrian@aemulor.com>2005-04-16 08:22:57 +0000
commit2f3895f0882e696598665cefcc0468de4cec0bff (patch)
tree457b620f3b45f504a8611c9b40430f393b78e21b
parentf10db1f6f17d6889b1c5043f36b89fe434ed9d0c (diff)
downloadnetsurf-2f3895f0882e696598665cefcc0468de4cec0bff.tar.gz
netsurf-2f3895f0882e696598665cefcc0468de4cec0bff.tar.bz2
[project @ 2005-04-16 08:22:57 by adrianl]
first cut at selecting inter-block spaces svn path=/import/netsurf/; revision=1652
-rw-r--r--desktop/selection.c42
-rw-r--r--render/html_redraw.c23
2 files changed, 43 insertions, 22 deletions
diff --git a/desktop/selection.c b/desktop/selection.c
index 291831723..afec4180a 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -656,26 +656,32 @@ void selection_set_end(struct selection *s, struct box *box, int idx)
bool selection_highlighted(struct selection *s, struct box *box,
unsigned *start_idx, unsigned *end_idx)
{
- if (selection_defined(s) && box->length > 0 &&
- box->byte_offset < s->end_idx &&
- box->byte_offset + box->length > s->start_idx) {
- unsigned offset = 0;
- unsigned len;
+ assert(selection_defined(s)); /* caller should have checked for efficiency */
+ assert(s && box);
- if (box->byte_offset < s->start_idx)
- offset = s->start_idx - box->byte_offset;
+ if (box->length > 0) {
+ unsigned box_len = box->length + (box->space ? 1 : 0);
- len = box->length - offset;
-
- if (box->byte_offset + box->length > s->end_idx)
- len = s->end_idx - (box->byte_offset + offset);
-
- assert(offset < box->length);
- assert(offset + len <= box->length);
-
- *start_idx = offset;
- *end_idx = offset + len;
- return true;
+ if (box->byte_offset < s->end_idx &&
+ box->byte_offset + box_len > s->start_idx) {
+ unsigned offset = 0;
+ unsigned len;
+
+ if (box->byte_offset < s->start_idx)
+ offset = s->start_idx - box->byte_offset;
+
+ len = box_len - offset;
+
+ if (box->byte_offset + box_len > s->end_idx)
+ len = s->end_idx - (box->byte_offset + offset);
+
+ assert(offset <= box_len);
+ assert(offset + len <= box->length + 1);
+
+ *start_idx = offset;
+ *end_idx = offset + len;
+ return true;
+ }
}
return false;
}
diff --git a/render/html_redraw.c b/render/html_redraw.c
index 491631194..c2eef9d3e 100644
--- a/render/html_redraw.c
+++ b/render/html_redraw.c
@@ -359,16 +359,31 @@ bool html_redraw_box(struct box *box,
selection_highlighted(current_redraw_browser->sel, box,
&start_idx, &end_idx)) {
+ unsigned endtxt_idx = end_idx;
int startx, endx;
+ if (end_idx > box->length) {
+ /* adjust for trailing space, not present in box->text */
+ assert(end_idx == box->length + 1);
+ endtxt_idx = box->length;
+ }
+
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))
+ endtxt_idx - start_idx, &endx))
endx = 0;
endx += startx;
+ /* is there a trailing space that should be highlighted as well? */
+ if (end_idx > box->length) {
+ int spc_width;
+ /* \todo is there a more elegant/efficient solution? */
+ if (nsfont_width(box->style, " ", 1, &spc_width))
+ endx += spc_width;
+ }
+
if (scale != 1.0) {
startx *= scale;
endx *= scale;
@@ -389,15 +404,15 @@ bool html_redraw_box(struct box *box,
return false;
if (!plot.text(x + startx, y + (int) (box->height * 0.75 * scale),
- box->style, box->text + start_idx, end_idx - start_idx,
+ box->style, box->text + start_idx, endtxt_idx - start_idx,
current_background_color ^ 0xffffff,
current_background_color))
return false;
- if (end_idx < box->length) {
+ if (endtxt_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,
+ box->style, box->text + endtxt_idx, box->length - endtxt_idx,
current_background_color,
/*print_text_black ? 0 :*/ box->style->color))
return false;