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 --- content/handlers/html/html.c | 44 ++++++++++-------- desktop/browser_window.c | 103 +++++++++++++++++++++++++++---------------- frontends/riscos/window.c | 2 +- 3 files changed, 92 insertions(+), 57 deletions(-) diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c index 1bbb4c699..7280ff66a 100644 --- a/content/handlers/html/html.c +++ b/content/handlers/html/html.c @@ -1925,11 +1925,11 @@ html_get_contextual_content(struct content *c, int x, int y, } if (box->iframe) { - browser_window_get_features( - box->iframe, - (x - box_x) * browser_window_get_scale(box->iframe), - (y - box_y) * browser_window_get_scale(box->iframe), - data); + float scale = browser_window_get_scale(box->iframe); + browser_window_get_features(box->iframe, + (x - box_x) * scale, + (y - box_y) * scale, + data); } if (box->object) @@ -2004,13 +2004,15 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry) continue; /* Pass into iframe */ - if (box->iframe && - browser_window_scroll_at_point( - box->iframe, - (x - box_x) * browser_window_get_scale(box->iframe), - (y - box_y) * browser_window_get_scale(box->iframe), - scrx, scry) == true) - return true; + if (box->iframe) { + float scale = browser_window_get_scale(box->iframe); + + if (browser_window_scroll_at_point(box->iframe, + (x - box_x) * scale, + (y - box_y) * scale, + scrx, scry) == true) + return true; + } /* Pass into textarea widget */ if (box->gadget && (box->gadget->type == GADGET_TEXTAREA || @@ -2146,15 +2148,21 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) &box_x, &box_y)) != NULL) { box = next; - if (box->style && css_computed_visibility(box->style) == - CSS_VISIBILITY_HIDDEN) + if (box->style && + css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) continue; - if (box->iframe) - return browser_window_drop_file_at_point(box->iframe, - x - box_x, y - box_y, file); + if (box->iframe) { + float scale = browser_window_get_scale(box->iframe); + return browser_window_drop_file_at_point( + box->iframe, + (x - box_x) * scale, + (y - box_y) * scale, + file); + } - if (box->object && content_drop_file_at_point(box->object, + if (box->object && + content_drop_file_at_point(box->object, x - box_x, y - box_y, file) == true) return true; 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); } diff --git a/frontends/riscos/window.c b/frontends/riscos/window.c index 5a46529ae..ab46f284f 100644 --- a/frontends/riscos/window.c +++ b/frontends/riscos/window.c @@ -4365,7 +4365,7 @@ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message) message->data.data_xfer.pos.y, &pos)) return false; - if (browser_window_drop_file_at_point(g->bw, pos.x/g->scale, pos.y/g->scale, + if (browser_window_drop_file_at_point(g->bw, pos.x, pos.y, message->data.data_xfer.file_name) == false) return false; -- cgit v1.2.3