From dece339528e289dc008d9129f757d717974f975e Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 24 May 2006 22:55:37 +0000 Subject: 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 --- render/box.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'render/box.c') diff --git a/render/box.c b/render/box.c index 65c15fba3..22ccdd8e3 100644 --- a/render/box.c +++ b/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,13 +325,11 @@ 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; sibling; - sibling = sibling->next) { - if (box_is_float(sibling)) - continue; + for (sibling = box->next_float; sibling; + sibling = sibling->next_float) { if (box_contains_point(sibling, x - bx, y - by)) { *box_x = bx + sibling->x - @@ -339,12 +339,20 @@ siblings: return sibling; } } - box = box->parent; + /* 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_float; sibling; - sibling = sibling->next_float) { + for (sibling = box->next; sibling; + sibling = sibling->next) { + if (box_is_float(sibling)) + continue; if (box_contains_point(sibling, x - bx, y - by)) { *box_x = bx + sibling->x - @@ -354,9 +362,7 @@ siblings: return sibling; } } - do { - box = box->parent; - } while (!box->float_children); + box = box->parent; } } @@ -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) -- cgit v1.2.3