From 64c405c541eef1f17d848b1538a7175134d4c14c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 29 Nov 2011 14:20:25 +0000 Subject: New function for sending a scroll request into a core browser window at a given coordinate. Currently handles frames only. TODO: iframes and css overflow scrollable boxes. Front ends should call this to pass scroll wheel actions to the core. svn path=/trunk/netsurf/; revision=13197 --- desktop/browser.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ desktop/browser.h | 15 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/desktop/browser.c b/desktop/browser.c index 760849f6a..124821ff2 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -526,6 +526,52 @@ void browser_window_get_contextual_content(struct browser_window *bw, browser_window__get_contextual_content(bw, x, y, data); } +/* exported interface, documented in browser.h */ +bool browser_window_scroll_at_point(struct browser_window *bw, + int x, int y, int scrx, int scry) +{ + bool handled_scroll = false; + assert(bw != NULL); + + if (bw->children) { + /* Browser window has children, so pass request on to + * appropriate child */ + struct browser_window *bwc; + int cur_child; + int children = bw->rows * bw->cols; + + /* Loop through all children of bw */ + for (cur_child = 0; cur_child < children; cur_child++) { + /* Set current child */ + bwc = &bw->children[cur_child]; + + /* Skip this frame if (x, y) coord lies outside */ + if (x < bwc->x || bwc->x + bwc->width < x || + y < bwc->y || bwc->y + bwc->height < y) + continue; + + /* Pass request into this child */ + return browser_window_scroll_at_point(bwc, + (x - bwc->x), (y - bwc->y), + scrx, scry); + } + } + + /* TODO: + * Pass scroll to content to try scrolling something at this point */ + + /* Try to scroll this window, if scroll not already handled */ + if (handled_scroll == false) { + if (bw->scroll_y && scrollbar_scroll(bw->scroll_y, scry)) + handled_scroll = true; + + if (bw->scroll_x && scrollbar_scroll(bw->scroll_x, scrx)) + handled_scroll = true; + } + + return handled_scroll; +} + /** * Create and open a new root browser window with the given page. diff --git a/desktop/browser.h b/desktop/browser.h index d5c7079af..f2298b59f 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -249,6 +249,21 @@ void browser_window_set_scale(struct browser_window *bw, float scale, bool all); void browser_window_get_contextual_content(struct browser_window *bw, int x, int y, struct contextual_content *data); +/** + * Send a scroll request to a browser window at a particular point. The + * 'deepest' scrollable object which can be scrolled in the requested + * direction at the given point will consume the scroll. + * + * \param bw browser window to look inside + * \param x x-coordinate of point of interest + * \param y y-coordinate of point of interest + * \param scrx number of px try to scroll something in x direction + * \param scry number of px try to scroll something in y direction + * \return true iff scroll request has been consumed + */ +bool browser_window_scroll_at_point(struct browser_window *bw, + int x, int y, int scrx, int scry); + void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, lwc_string *frag); -- cgit v1.2.3