From 6e3e168d08a6d9ae12d33f65ffcdae20306e9d06 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 31 Aug 2011 17:53:40 +0000 Subject: Avoid instance of using bw->current_content outside desktop/. svn path=/trunk/netsurf/; revision=12690 --- render/box.c | 74 +++++++++++++++++++++++++---------------------- render/box.h | 2 +- render/html.h | 2 -- render/html_interaction.c | 70 ++++++++++++++++++++++---------------------- 4 files changed, 75 insertions(+), 73 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index 17d73c5fd..b48b07e8f 100644 --- a/render/box.c +++ b/render/box.c @@ -784,7 +784,7 @@ bool box_nearest_text_box(struct box *box, int bx, int by, * the mouse pointer, or nearest in the given direction if the pointer is * not over a text box. * - * \param h html content's high level cache handle + * \param html an HTML content * \param x coordinate of mouse * \param y coordinate of mouse * \param dir direction to search (-1 = above-left, +1 = below-right) @@ -792,47 +792,51 @@ bool box_nearest_text_box(struct box *box, int bx, int by, * \param dy receives y ordinate of mouse relative to text box */ -struct box *box_pick_text_box(hlcache_handle *h, +struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy) { struct box *text_box = NULL; + struct box *box; + int nr_xd, nr_yd; + int bx, by; + int fx, fy; + int tx, ty; - if (h != NULL && content_get_type(h) == CONTENT_HTML) { - struct box *box = html_get_box_tree(h); - int nr_xd, nr_yd; - int bx = box->margin[LEFT]; - int by = box->margin[TOP]; - int fx = bx; - int fy = by; - int tx, ty; - - if (!box_nearest_text_box(box, bx, by, fx, fy, x, y, - dir, &text_box, &tx, &ty, &nr_xd, &nr_yd)) { - if (text_box && text_box->text && !text_box->object) { - int w = (text_box->padding[LEFT] + - text_box->width + - text_box->padding[RIGHT]); - int h = (text_box->padding[TOP] + - text_box->height + - text_box->padding[BOTTOM]); - int x1, y1; - - y1 = ty + h; - x1 = tx + w; - - /* ensure point lies within the text box */ - if (x < tx) x = tx; - if (y < ty) y = ty; - if (y > y1) y = y1; - if (x > x1) x = x1; - } - } + if (html == NULL) + return NULL; - /* return coordinates relative to box */ - *dx = x - tx; - *dy = y - ty; + box = html->layout; + bx = box->margin[LEFT]; + by = box->margin[TOP]; + fx = bx; + fy = by; + + if (!box_nearest_text_box(box, bx, by, fx, fy, x, y, + dir, &text_box, &tx, &ty, &nr_xd, &nr_yd)) { + if (text_box && text_box->text && !text_box->object) { + int w = (text_box->padding[LEFT] + + text_box->width + + text_box->padding[RIGHT]); + int h = (text_box->padding[TOP] + + text_box->height + + text_box->padding[BOTTOM]); + int x1, y1; + + y1 = ty + h; + x1 = tx + w; + + /* ensure point lies within the text box */ + if (x < tx) x = tx; + if (y < ty) y = ty; + if (y > y1) y = y1; + if (x > x1) x = x1; + } } + /* return coordinates relative to box */ + *dx = x - tx; + *dy = y - ty; + return text_box; } diff --git a/render/box.h b/render/box.h index 28dd007da..4b2e8d029 100644 --- a/render/box.h +++ b/render/box.h @@ -324,7 +324,7 @@ struct box *box_at_point(struct box *box, const int x, const int y, int *box_x, int *box_y, struct hlcache_handle **content); struct box *box_object_at_point(struct hlcache_handle *h, int x, int y); struct box *box_href_at_point(struct hlcache_handle *h, int x, int y); -struct box *box_pick_text_box(struct hlcache_handle *h, +struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy); struct box *box_find_by_id(struct box *box, const char *id); bool box_visible(struct box *box); diff --git a/render/html.h b/render/html.h index 482297e0d..88c8b9bfb 100644 --- a/render/html.h +++ b/render/html.h @@ -148,8 +148,6 @@ void html_redraw_a_box(struct hlcache_handle *h, struct box *box); void html_overflow_scroll_drag_end(struct scrollbar *scrollbar, browser_mouse_state mouse, int x, int y); -size_t html_selection_drag_end(struct hlcache_handle *h, - browser_mouse_state mouse, int x, int y, int dir); bool text_redraw(const char *utf8_text, size_t utf8_len, size_t offset, int space, diff --git a/render/html_interaction.c b/render/html_interaction.c index 98fb4c9cb..ceea4bf08 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -48,6 +48,39 @@ static gui_pointer_shape get_pointer_shape(struct browser_window *bw, struct box *box, bool imagemap); static void html_box_drag_start(struct box *box, int x, int y); + +/** + * End overflow scroll scrollbar drags + * + * \param h html content's high level cache entry + * \param mouse state of mouse buttons and modifier keys + * \param x coordinate of mouse + * \param y coordinate of mouse + */ +static size_t html_selection_drag_end(struct html_content *html, + browser_mouse_state mouse, int x, int y, int dir) +{ + int pixel_offset; + struct box *box; + int dx, dy; + size_t idx = 0; + + box = box_pick_text_box(html, x, y, dir, &dx, &dy); + if (box) { + plot_font_style_t fstyle; + + font_plot_style_from_css(box->style, &fstyle); + + nsfont.font_position_in_string(&fstyle, box->text, box->length, + dx, &idx, &pixel_offset); + + idx += box->byte_offset; + } + + return idx; +} + + /** * Handle mouse tracking (including drags) in an HTML content window. * @@ -62,7 +95,6 @@ void html_mouse_track(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y) { html_content *html = (html_content*) c; - hlcache_handle *h = bw->current_content; if (bw->drag_type == DRAGGING_SELECTION && !mouse) { int dir = -1; @@ -71,7 +103,7 @@ void html_mouse_track(struct content *c, struct browser_window *bw, if (selection_dragging_start(&html->sel)) dir = 1; - idx = html_selection_drag_end(h, mouse, x, y, dir); + idx = html_selection_drag_end(html, mouse, x, y, dir); if (idx != 0) selection_track(&html->sel, mouse, idx); @@ -88,7 +120,7 @@ void html_mouse_track(struct content *c, struct browser_window *bw, if (selection_dragging_start(&html->sel)) dir = 1; - box = box_pick_text_box(h, x, y, dir, &dx, &dy); + box = box_pick_text_box(html, x, y, dir, &dx, &dy); if (box) { int pixel_offset; @@ -869,38 +901,6 @@ void html_overflow_scroll_drag_end(struct scrollbar *scrollbar, } -/** - * End overflow scroll scrollbar drags - * - * \param h html content's high level cache entry - * \param mouse state of mouse buttons and modifier keys - * \param x coordinate of mouse - * \param y coordinate of mouse - */ -size_t html_selection_drag_end(hlcache_handle *h, browser_mouse_state mouse, - int x, int y, int dir) -{ - int pixel_offset; - struct box *box; - int dx, dy; - size_t idx = 0; - - box = box_pick_text_box(h, x, y, dir, &dx, &dy); - if (box) { - plot_font_style_t fstyle; - - font_plot_style_from_css(box->style, &fstyle); - - nsfont.font_position_in_string(&fstyle, box->text, box->length, - dx, &idx, &pixel_offset); - - idx += box->byte_offset; - } - - return idx; -} - - /** * Start drag scrolling the contents of a box * -- cgit v1.2.3