Expose contextual content request API to front ends, via browser window layer.

svn path=/trunk/netsurf/; revision=12755
This commit is contained in:
Michael Drake 2011-09-06 18:11:10 +00:00
parent 6167cc8508
commit 57da2b3af1
2 changed files with 67 additions and 0 deletions

View File

@ -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.
*

View File

@ -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);