Make box_at_point() only return boxes if the point is physically contained within them, and not if the point is mearly in the descendant area. (Fixes sites like BBC F1 page where whole page became an iPlayer link.)

svn path=/trunk/netsurf/; revision=7335
This commit is contained in:
Michael Drake 2009-04-27 10:20:44 +00:00
parent 9f7a794b1f
commit 044a953400
2 changed files with 81 additions and 50 deletions

View File

@ -34,7 +34,7 @@
#include "utils/log.h" #include "utils/log.h"
#include "utils/talloc.h" #include "utils/talloc.h"
static bool box_contains_point(struct box *box, int x, int y); static bool box_contains_point(struct box *box, int x, int y, bool *physically);
#define box_is_float(box) (box->type == BOX_FLOAT_LEFT || \ #define box_is_float(box) (box->type == BOX_FLOAT_LEFT || \
box->type == BOX_FLOAT_RIGHT) box->type == BOX_FLOAT_RIGHT)
@ -302,12 +302,13 @@ void box_bounds(struct box *box, struct rect *r)
* \endcode * \endcode
*/ */
struct box *box_at_point(struct box *box, int x, int y, struct box *box_at_point(struct box *box, const int x, const int y,
int *box_x, int *box_y, int *box_x, int *box_y,
struct content **content) struct content **content)
{ {
int bx = *box_x, by = *box_y; int bx = *box_x, by = *box_y;
struct box *child, *sibling; struct box *child, *sibling;
bool physically;
assert(box); assert(box);
@ -324,10 +325,15 @@ struct box *box_at_point(struct box *box, int x, int y,
/* consider floats second, since they will often overlap other boxes */ /* consider floats second, since they will often overlap other boxes */
for (child = box->float_children; child; child = child->next_float) { for (child = box->float_children; child; child = child->next_float) {
if (box_contains_point(child, x - bx, y - by)) { if (box_contains_point(child, x - bx, y - by, &physically)) {
*box_x = bx + child->x - child->scroll_x; *box_x = bx + child->x - child->scroll_x;
*box_y = by + child->y - child->scroll_y; *box_y = by + child->y - child->scroll_y;
if (physically)
return child; return child;
else
return box_at_point(child, x, y, box_x, box_y,
content);
} }
} }
@ -336,20 +342,24 @@ non_float_children:
for (child = box->children; child; child = child->next) { for (child = box->children; child; child = child->next) {
if (box_is_float(child)) if (box_is_float(child))
continue; continue;
if (box_contains_point(child, x - bx, y - by)) { if (box_contains_point(child, x - bx, y - by, &physically)) {
*box_x = bx + child->x - child->scroll_x; *box_x = bx + child->x - child->scroll_x;
*box_y = by + child->y - child->scroll_y; *box_y = by + child->y - child->scroll_y;
if (physically)
return child; return child;
else
return box_at_point(child, x, y, box_x, box_y,
content);
} }
} }
/* marker boxes */ /* marker boxes */
if (box->list_marker) { if (box->list_marker) {
if (box_contains_point(box->list_marker, x - bx, y - by)) { if (box_contains_point(box->list_marker, x - bx, y - by,
*box_x = bx + box->list_marker->x - &physically)) {
box->list_marker->scroll_x; *box_x = bx + box->list_marker->x;
*box_y = by + box->list_marker->y - *box_y = by + box->list_marker->y;
box->list_marker->scroll_y;
return box->list_marker; return box->list_marker;
} }
} }
@ -363,12 +373,19 @@ siblings:
for (sibling = box->next_float; sibling; for (sibling = box->next_float; sibling;
sibling = sibling->next_float) { sibling = sibling->next_float) {
if (box_contains_point(sibling, if (box_contains_point(sibling,
x - bx, y - by)) { x - bx, y - by, &physically)) {
*box_x = bx + sibling->x - *box_x = bx + sibling->x -
sibling->scroll_x; sibling->scroll_x;
*box_y = by + sibling->y - *box_y = by + sibling->y -
sibling->scroll_y; sibling->scroll_y;
if (physically)
return sibling; return sibling;
else
return box_at_point(sibling,
x, y,
box_x, box_y,
content);
} }
} }
/* ascend to float's parent */ /* ascend to float's parent */
@ -385,13 +402,20 @@ siblings:
sibling = sibling->next) { sibling = sibling->next) {
if (box_is_float(sibling)) if (box_is_float(sibling))
continue; continue;
if (box_contains_point(sibling, if (box_contains_point(sibling, x - bx, y - by,
x - bx, y - by)) { &physically)) {
*box_x = bx + sibling->x - *box_x = bx + sibling->x -
sibling->scroll_x; sibling->scroll_x;
*box_y = by + sibling->y - *box_y = by + sibling->y -
sibling->scroll_y; sibling->scroll_y;
if (physically)
return sibling; return sibling;
else
return box_at_point(sibling,
x, y,
box_x, box_y,
content);
} }
} }
box = box->parent; box = box->parent;
@ -408,22 +432,27 @@ siblings:
* \param box box to consider * \param box box to consider
* \param x coordinate relative to box parent * \param x coordinate relative to box parent
* \param y coordinate relative to box parent * \param y coordinate relative to box parent
* \param physically if function returning true, physically is set true if
* point is within the box's physical dimensions and false
* if the point is not within the box's physical dimensions
* but is in the area defined by the box's descendants.
* if function returning false, physically is undefined.
* \return true if the point is within the box or a descendant box * \return true if the point is within the box or a descendant box
* *
* This is a helper function for box_at_point(). * This is a helper function for box_at_point().
*/ */
bool box_contains_point(struct box *box, int x, int y) bool box_contains_point(struct box *box, int x, int y, bool *physically)
{ {
if ((box->style && box->style->overflow != CSS_OVERFLOW_VISIBLE) ||
box->inline_end) {
if (box->x <= x + box->border[LEFT] && if (box->x <= x + box->border[LEFT] &&
x < box->x + box->padding[LEFT] + box->width + x < box->x + box->padding[LEFT] + box->width +
box->border[RIGHT] + box->padding[RIGHT] && box->border[RIGHT] + box->padding[RIGHT] &&
box->y <= y + box->border[TOP] && box->y <= y + box->border[TOP] &&
y < box->y + box->padding[TOP] + box->height + y < box->y + box->padding[TOP] + box->height +
box->border[BOTTOM] + box->padding[BOTTOM]) box->border[BOTTOM] + box->padding[BOTTOM]) {
*physically = true;
return true; return true;
}
if (box->list_marker && box->list_marker->x <= x + if (box->list_marker && box->list_marker->x <= x +
box->list_marker->border[LEFT] && box->list_marker->border[LEFT] &&
x < box->list_marker->x + x < box->list_marker->x +
@ -438,15 +467,18 @@ bool box_contains_point(struct box *box, int x, int y)
box->list_marker->height + box->list_marker->height +
box->list_marker->border[BOTTOM] + box->list_marker->border[BOTTOM] +
box->list_marker->padding[BOTTOM]) { box->list_marker->padding[BOTTOM]) {
*physically = true;
return true; return true;
} }
} else { if (box->style && box->style->overflow == CSS_OVERFLOW_VISIBLE) {
if (box->x + box->descendant_x0 <= x && if (box->x + box->descendant_x0 <= x &&
x < box->x + box->descendant_x1 && x < box->x + box->descendant_x1 &&
box->y + box->descendant_y0 <= y && box->y + box->descendant_y0 <= y &&
y < box->y + box->descendant_y1) y < box->y + box->descendant_y1) {
*physically = false;
return true; return true;
} }
}
return false; return false;
} }

View File

@ -293,9 +293,8 @@ void box_free_box(struct box *box);
void box_free_object_params(struct object_params *op); void box_free_object_params(struct object_params *op);
void box_bounds(struct box *box, struct rect *r); void box_bounds(struct box *box, struct rect *r);
void box_coords(struct box *box, int *x, int *y); void box_coords(struct box *box, int *x, int *y);
struct box *box_at_point(struct box *box, int x, int y, struct box *box_at_point(struct box *box, const int x, const int y,
int *box_x, int *box_y, int *box_x, int *box_y, struct content **content);
struct content **content);
struct box *box_object_at_point(struct content *c, int x, int y); struct box *box_object_at_point(struct content *c, int x, int y);
struct box *box_href_at_point(struct content *c, int x, int y); struct box *box_href_at_point(struct content *c, int x, int y);
struct box *box_find_by_id(struct box *box, const char *id); struct box *box_find_by_id(struct box *box, const char *id);