Fix box_at_point() for certain cases involving floats (solves unclickable links on Wikipedia). Fix text-selection code that assumed that text boxes would be returned last by box_at_point().
svn path=/trunk/netsurf/; revision=2606
This commit is contained in:
parent
581ad55c90
commit
dece339528
|
@ -830,6 +830,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||
int box_x = 0, box_y = 0;
|
||||
int gadget_box_x = 0, gadget_box_y = 0;
|
||||
int scroll_box_x = 0, scroll_box_y = 0;
|
||||
int text_box_x = 0, text_box_y = 0;
|
||||
struct box *gadget_box = 0;
|
||||
struct box *scroll_box = 0;
|
||||
struct box *text_box = 0;
|
||||
|
@ -907,10 +908,16 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||
scroll_box_y = box_y + box->scroll_y;
|
||||
}
|
||||
|
||||
if (box->text && !box->object)
|
||||
if (box->text && !box->object) {
|
||||
text_box = box;
|
||||
text_box_x = box_x;
|
||||
text_box_y = box_y;
|
||||
}
|
||||
}
|
||||
|
||||
/* use of box_x, box_y, or content below this point is probably a
|
||||
* mistake; they will refer to the last box returned by box_at_point */
|
||||
|
||||
if (scroll_box) {
|
||||
status = browser_window_scrollbar_click(bw, mouse, scroll_box,
|
||||
scroll_box_x, scroll_box_y,
|
||||
|
@ -984,7 +991,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||
nsfont_position_in_string(text_box->style,
|
||||
text_box->text,
|
||||
text_box->length,
|
||||
x - box_x,
|
||||
x - text_box_x,
|
||||
&idx,
|
||||
&pixel_offset);
|
||||
|
||||
|
@ -1021,7 +1028,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||
nsfont_position_in_string(text_box->style,
|
||||
text_box->text,
|
||||
text_box->length,
|
||||
x - box_x,
|
||||
x - text_box_x,
|
||||
&idx,
|
||||
&pixel_offset);
|
||||
|
||||
|
@ -1109,7 +1116,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||
nsfont_position_in_string(text_box->style,
|
||||
text_box->text,
|
||||
text_box->length,
|
||||
x - box_x,
|
||||
x - text_box_x,
|
||||
&idx,
|
||||
&pixel_offset);
|
||||
|
||||
|
@ -1667,8 +1674,6 @@ void browser_window_redraw_rect(struct browser_window *bw, int x, int y,
|
|||
if (c) {
|
||||
union content_msg_data data;
|
||||
|
||||
LOG(("REDRAW %d,%d,%d,%d", x, y, width, height));
|
||||
|
||||
data.redraw.x = x;
|
||||
data.redraw.y = y;
|
||||
data.redraw.width = width;
|
||||
|
@ -2040,8 +2045,10 @@ struct box *browser_window_pick_text_box(struct browser_window *bw,
|
|||
NULL) {
|
||||
box = next_box;
|
||||
|
||||
if (box->text && !box->object)
|
||||
if (box->text && !box->object) {
|
||||
text_box = box;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!text_box) {
|
||||
|
|
54
render/box.c
54
render/box.c
|
@ -18,6 +18,7 @@
|
|||
#include "netsurf/css/css.h"
|
||||
#include "netsurf/render/box.h"
|
||||
#include "netsurf/render/form.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/talloc.h"
|
||||
|
||||
|
||||
|
@ -303,19 +304,20 @@ struct box *box_at_point(struct box *box, int x, int y,
|
|||
/* consider floats first, since they will often overlap other boxes */
|
||||
for (child = box->float_children; child; child = child->next_float) {
|
||||
if (box_contains_point(child, x - bx, y - by)) {
|
||||
*box_x += child->x - child->scroll_x;
|
||||
*box_y += child->y - child->scroll_y;
|
||||
*box_x = bx + child->x - child->scroll_x;
|
||||
*box_y = by + child->y - child->scroll_y;
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
non_float_children:
|
||||
/* non-float children */
|
||||
for (child = box->children; child; child = child->next) {
|
||||
if (box_is_float(child))
|
||||
continue;
|
||||
if (box_contains_point(child, x - bx, y - by)) {
|
||||
*box_x += child->x - child->scroll_x;
|
||||
*box_y += child->y - child->scroll_y;
|
||||
*box_x = bx + child->x - child->scroll_x;
|
||||
*box_y = by + child->y - child->scroll_y;
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +325,28 @@ struct box *box_at_point(struct box *box, int x, int y,
|
|||
siblings:
|
||||
/* siblings and siblings of ancestors */
|
||||
while (box) {
|
||||
if (!box_is_float(box)) {
|
||||
if (box_is_float(box)) {
|
||||
bx -= box->x - box->scroll_x;
|
||||
by -= box->y - box->scroll_y;
|
||||
for (sibling = box->next_float; sibling;
|
||||
sibling = sibling->next_float) {
|
||||
if (box_contains_point(sibling,
|
||||
x - bx, y - by)) {
|
||||
*box_x = bx + sibling->x -
|
||||
sibling->scroll_x;
|
||||
*box_y = by + sibling->y -
|
||||
sibling->scroll_y;
|
||||
return sibling;
|
||||
}
|
||||
}
|
||||
/* ascend to float's parent */
|
||||
do {
|
||||
box = box->parent;
|
||||
} while (!box->float_children);
|
||||
/* process non-float children of float's parent */
|
||||
goto non_float_children;
|
||||
|
||||
} else {
|
||||
bx -= box->x - box->scroll_x;
|
||||
by -= box->y - box->scroll_y;
|
||||
for (sibling = box->next; sibling;
|
||||
|
@ -340,23 +363,6 @@ siblings:
|
|||
}
|
||||
}
|
||||
box = box->parent;
|
||||
} else {
|
||||
bx -= box->x - box->scroll_x;
|
||||
by -= box->y - box->scroll_y;
|
||||
for (sibling = box->next_float; sibling;
|
||||
sibling = sibling->next_float) {
|
||||
if (box_contains_point(sibling,
|
||||
x - bx, y - by)) {
|
||||
*box_x = bx + sibling->x -
|
||||
sibling->scroll_x;
|
||||
*box_y = by + sibling->y -
|
||||
sibling->scroll_y;
|
||||
return sibling;
|
||||
}
|
||||
}
|
||||
do {
|
||||
box = box->parent;
|
||||
} while (!box->float_children);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,9 +498,9 @@ void box_dump(struct box *box, unsigned int depth)
|
|||
default: fprintf(stderr, "Unknown box type ");
|
||||
}
|
||||
|
||||
fprintf(stderr, "ofst %d", box->byte_offset);
|
||||
if (box->text)
|
||||
fprintf(stderr, "'%.*s' ", (int) box->length, box->text);
|
||||
fprintf(stderr, "%u '%.*s' ", box->byte_offset,
|
||||
(int) box->length, box->text);
|
||||
if (box->space)
|
||||
fprintf(stderr, "space ");
|
||||
if (box->object)
|
||||
|
|
Loading…
Reference in New Issue