[project @ 2005-04-16 08:22:57 by adrianl]

first cut at selecting inter-block spaces

svn path=/import/netsurf/; revision=1652
This commit is contained in:
Adrian Lees 2005-04-16 08:22:57 +00:00
parent f10db1f6f1
commit 2f3895f088
2 changed files with 43 additions and 22 deletions

View File

@ -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;
}

View File

@ -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;