From 57da2b3af19406f5736a2b3941c8d0223b098553 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 6 Sep 2011 18:11:10 +0000 Subject: Expose contextual content request API to front ends, via browser window layer. svn path=/trunk/netsurf/; revision=12755 --- desktop/browser.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ desktop/browser.h | 13 +++++++++++++ 2 files changed, 67 insertions(+) diff --git a/desktop/browser.c b/desktop/browser.c index af9528f76..b18bde482 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -469,6 +469,60 @@ void browser_window_set_scroll(struct browser_window *bw, int x, int y) } } +/** + * Internal helper for browser_window_get_contextual_content + */ +static void browser_window__get_contextual_content(struct browser_window *bw, + int x, int y, struct contextual_content *data) +{ + 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 */ + browser_window__get_contextual_content(bwc, + (x - bwc->x), (y - bwc->y), data); + return; + } + + /* Coordinate not contained by any frame */ + return; + } + + if (bw->current_content == NULL) + /* No content; nothing to set */ + return; + + /* Pass request to content */ + content_get_contextual_content(bw->current_content, x, y, data); + data->main = bw->current_content; +} + +/* exported interface, documented in browser.h */ +void browser_window_get_contextual_content(struct browser_window *bw, + int x, int y, struct contextual_content *data) +{ + data->link_url = NULL; + data->object = NULL; + data->main = NULL; + + browser_window__get_contextual_content(bw, x, y, data); +} + + /** * Create and open a new root browser window with the given page. * diff --git a/desktop/browser.h b/desktop/browser.h index 3d289767a..cb3b22bb0 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -229,6 +229,19 @@ void browser_window_reformat(struct browser_window *bw, bool background, int width, int height); void browser_window_set_scale(struct browser_window *bw, float scale, bool all); +/** + * Get access to any content, link URLs and objects (images) currently + * at the given (x, y) coordinates. + * + * \param bw browser window to look inside + * \param x x-coordinate of point of interest + * \param y y-coordinate of point of interest + * \param data pointer to contextual_content struct. Its fields are updated + * with pointers to any relevent content, or set to NULL if none. + */ +void browser_window_get_contextual_content(struct browser_window *bw, + int x, int y, struct contextual_content *data); + void browser_window_refresh_url_bar(struct browser_window *bw, const char *url, const char *frag); -- cgit v1.2.3