change browser_window_drop_file_at_point() to take unscaled coordinates

This commit is contained in:
Vincent Sanders 2019-08-04 14:23:48 +01:00
parent c88a55999a
commit 3be2b98cc2
3 changed files with 92 additions and 57 deletions

View File

@ -1925,11 +1925,11 @@ html_get_contextual_content(struct content *c, int x, int y,
} }
if (box->iframe) { if (box->iframe) {
browser_window_get_features( float scale = browser_window_get_scale(box->iframe);
box->iframe, browser_window_get_features(box->iframe,
(x - box_x) * browser_window_get_scale(box->iframe), (x - box_x) * scale,
(y - box_y) * browser_window_get_scale(box->iframe), (y - box_y) * scale,
data); data);
} }
if (box->object) if (box->object)
@ -2004,13 +2004,15 @@ html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
continue; continue;
/* Pass into iframe */ /* Pass into iframe */
if (box->iframe && if (box->iframe) {
browser_window_scroll_at_point( float scale = browser_window_get_scale(box->iframe);
box->iframe,
(x - box_x) * browser_window_get_scale(box->iframe), if (browser_window_scroll_at_point(box->iframe,
(y - box_y) * browser_window_get_scale(box->iframe), (x - box_x) * scale,
scrx, scry) == true) (y - box_y) * scale,
return true; scrx, scry) == true)
return true;
}
/* Pass into textarea widget */ /* Pass into textarea widget */
if (box->gadget && (box->gadget->type == GADGET_TEXTAREA || 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_x, &box_y)) != NULL) {
box = next; box = next;
if (box->style && css_computed_visibility(box->style) == if (box->style &&
CSS_VISIBILITY_HIDDEN) css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
continue; continue;
if (box->iframe) if (box->iframe) {
return browser_window_drop_file_at_point(box->iframe, float scale = browser_window_get_scale(box->iframe);
x - box_x, y - box_y, file); 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) x - box_x, y - box_y, file) == true)
return true; return true;

View File

@ -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 static bool
browser_window_scroll_at_point_internal(struct browser_window *bw, browser_window_scroll_at_point_internal(struct browser_window *bw,
int x, int y, 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 */ /* exported interface, documented in netsurf/browser_window.h */
nserror nserror
browser_window_get_name(struct browser_window *bw, const char **out_name) 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, int x, int y,
char *file) char *file)
{ {
assert(bw != NULL); return browser_window_drop_file_at_point_internal(bw,
x / bw->scale,
/* Handle (i)frame scroll offset (core-managed browser windows only) */ y / bw->scale,
x += scrollbar_get_offset(bw->scroll_x); file);
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;
} }

View File

@ -4365,7 +4365,7 @@ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message)
message->data.data_xfer.pos.y, &pos)) message->data.data_xfer.pos.y, &pos))
return false; 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) message->data.data_xfer.file_name) == false)
return false; return false;