From 3be2b98cc2d5c4e7c97a6caba86d1869893f25eb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Aug 2019 14:23:48 +0100 Subject: change browser_window_drop_file_at_point() to take unscaled coordinates --- desktop/browser_window.c | 103 ++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 38 deletions(-) (limited to 'desktop') diff --git a/desktop/browser_window.c b/desktop/browser_window.c index 9d8a5e3d8..f3b173f22 100644 --- a/desktop/browser_window.c +++ b/desktop/browser_window.c @@ -1819,6 +1819,13 @@ browser_window_mouse_track_internal(struct browser_window *bw, } +/** + * perform a scroll operation at a given coordinate + * + * \param bw The browsing context receiving the event + * \param x The scaled x co-ordinate of the event + * \param y The scaled y co-ordinate of the event + */ static bool browser_window_scroll_at_point_internal(struct browser_window *bw, int x, int y, @@ -1876,6 +1883,60 @@ browser_window_scroll_at_point_internal(struct browser_window *bw, } +/** + * allows a dragged file to be dropped into a browser window at a position + * + * \param bw The browsing context receiving the event + * \param x The scaled x co-ordinate of the event + * \param y The scaled y co-ordinate of the event + * \param file filename to be put in the widget + */ +static bool +browser_window_drop_file_at_point_internal(struct browser_window *bw, + int x, int y, + char *file) +{ + assert(bw != NULL); + + /* Handle (i)frame scroll offset (core-managed browser windows only) */ + x += scrollbar_get_offset(bw->scroll_x); + y += scrollbar_get_offset(bw->scroll_y); + + 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_drop_file_at_point_internal(bwc, + (x - bwc->x), + (y - bwc->y), + file); + } + } + + /* Pass file drop on to any content */ + if (bw->current_content != NULL) { + return content_drop_file_at_point(bw->current_content, + x, y, file); + } + + return false; +} + + /* exported interface, documented in netsurf/browser_window.h */ nserror browser_window_get_name(struct browser_window *bw, const char **out_name) @@ -2366,44 +2427,10 @@ browser_window_drop_file_at_point(struct browser_window *bw, int x, int y, char *file) { - assert(bw != NULL); - - /* Handle (i)frame scroll offset (core-managed browser windows only) */ - x += scrollbar_get_offset(bw->scroll_x); - y += scrollbar_get_offset(bw->scroll_y); - - 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_drop_file_at_point(bwc, - (x - bwc->x), - (y - bwc->y), - file); - } - } - - /* Pass file drop on to any content */ - if (bw->current_content != NULL) { - return content_drop_file_at_point(bw->current_content, - x, y, file); - } - - return false; + return browser_window_drop_file_at_point_internal(bw, + x / bw->scale, + y / bw->scale, + file); } -- cgit v1.2.3