mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Avoid instance of using bw->current_content outside desktop/.
svn path=/trunk/netsurf/; revision=12690
This commit is contained in:
parent
5af7a9c03c
commit
6e3e168d08
68
render/box.c
68
render/box.c
@ -784,7 +784,7 @@ bool box_nearest_text_box(struct box *box, int bx, int by,
|
||||
* the mouse pointer, or nearest in the given direction if the pointer is
|
||||
* not over a text box.
|
||||
*
|
||||
* \param h html content's high level cache handle
|
||||
* \param html an HTML content
|
||||
* \param x coordinate of mouse
|
||||
* \param y coordinate of mouse
|
||||
* \param dir direction to search (-1 = above-left, +1 = below-right)
|
||||
@ -792,47 +792,51 @@ bool box_nearest_text_box(struct box *box, int bx, int by,
|
||||
* \param dy receives y ordinate of mouse relative to text box
|
||||
*/
|
||||
|
||||
struct box *box_pick_text_box(hlcache_handle *h,
|
||||
struct box *box_pick_text_box(struct html_content *html,
|
||||
int x, int y, int dir, int *dx, int *dy)
|
||||
{
|
||||
struct box *text_box = NULL;
|
||||
struct box *box;
|
||||
int nr_xd, nr_yd;
|
||||
int bx, by;
|
||||
int fx, fy;
|
||||
int tx, ty;
|
||||
|
||||
if (h != NULL && content_get_type(h) == CONTENT_HTML) {
|
||||
struct box *box = html_get_box_tree(h);
|
||||
int nr_xd, nr_yd;
|
||||
int bx = box->margin[LEFT];
|
||||
int by = box->margin[TOP];
|
||||
int fx = bx;
|
||||
int fy = by;
|
||||
int tx, ty;
|
||||
if (html == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!box_nearest_text_box(box, bx, by, fx, fy, x, y,
|
||||
dir, &text_box, &tx, &ty, &nr_xd, &nr_yd)) {
|
||||
if (text_box && text_box->text && !text_box->object) {
|
||||
int w = (text_box->padding[LEFT] +
|
||||
text_box->width +
|
||||
text_box->padding[RIGHT]);
|
||||
int h = (text_box->padding[TOP] +
|
||||
text_box->height +
|
||||
text_box->padding[BOTTOM]);
|
||||
int x1, y1;
|
||||
box = html->layout;
|
||||
bx = box->margin[LEFT];
|
||||
by = box->margin[TOP];
|
||||
fx = bx;
|
||||
fy = by;
|
||||
|
||||
y1 = ty + h;
|
||||
x1 = tx + w;
|
||||
if (!box_nearest_text_box(box, bx, by, fx, fy, x, y,
|
||||
dir, &text_box, &tx, &ty, &nr_xd, &nr_yd)) {
|
||||
if (text_box && text_box->text && !text_box->object) {
|
||||
int w = (text_box->padding[LEFT] +
|
||||
text_box->width +
|
||||
text_box->padding[RIGHT]);
|
||||
int h = (text_box->padding[TOP] +
|
||||
text_box->height +
|
||||
text_box->padding[BOTTOM]);
|
||||
int x1, y1;
|
||||
|
||||
/* ensure point lies within the text box */
|
||||
if (x < tx) x = tx;
|
||||
if (y < ty) y = ty;
|
||||
if (y > y1) y = y1;
|
||||
if (x > x1) x = x1;
|
||||
}
|
||||
y1 = ty + h;
|
||||
x1 = tx + w;
|
||||
|
||||
/* ensure point lies within the text box */
|
||||
if (x < tx) x = tx;
|
||||
if (y < ty) y = ty;
|
||||
if (y > y1) y = y1;
|
||||
if (x > x1) x = x1;
|
||||
}
|
||||
|
||||
/* return coordinates relative to box */
|
||||
*dx = x - tx;
|
||||
*dy = y - ty;
|
||||
}
|
||||
|
||||
/* return coordinates relative to box */
|
||||
*dx = x - tx;
|
||||
*dy = y - ty;
|
||||
|
||||
return text_box;
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ struct box *box_at_point(struct box *box, const int x, const int y,
|
||||
int *box_x, int *box_y, struct hlcache_handle **content);
|
||||
struct box *box_object_at_point(struct hlcache_handle *h, int x, int y);
|
||||
struct box *box_href_at_point(struct hlcache_handle *h, int x, int y);
|
||||
struct box *box_pick_text_box(struct hlcache_handle *h,
|
||||
struct box *box_pick_text_box(struct html_content *html,
|
||||
int x, int y, int dir, int *dx, int *dy);
|
||||
struct box *box_find_by_id(struct box *box, const char *id);
|
||||
bool box_visible(struct box *box);
|
||||
|
@ -148,8 +148,6 @@ void html_redraw_a_box(struct hlcache_handle *h, struct box *box);
|
||||
|
||||
void html_overflow_scroll_drag_end(struct scrollbar *scrollbar,
|
||||
browser_mouse_state mouse, int x, int y);
|
||||
size_t html_selection_drag_end(struct hlcache_handle *h,
|
||||
browser_mouse_state mouse, int x, int y, int dir);
|
||||
|
||||
bool text_redraw(const char *utf8_text, size_t utf8_len,
|
||||
size_t offset, int space,
|
||||
|
@ -48,6 +48,39 @@ static gui_pointer_shape get_pointer_shape(struct browser_window *bw,
|
||||
struct box *box, bool imagemap);
|
||||
static void html_box_drag_start(struct box *box, int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* End overflow scroll scrollbar drags
|
||||
*
|
||||
* \param h html content's high level cache entry
|
||||
* \param mouse state of mouse buttons and modifier keys
|
||||
* \param x coordinate of mouse
|
||||
* \param y coordinate of mouse
|
||||
*/
|
||||
static size_t html_selection_drag_end(struct html_content *html,
|
||||
browser_mouse_state mouse, int x, int y, int dir)
|
||||
{
|
||||
int pixel_offset;
|
||||
struct box *box;
|
||||
int dx, dy;
|
||||
size_t idx = 0;
|
||||
|
||||
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
|
||||
if (box) {
|
||||
plot_font_style_t fstyle;
|
||||
|
||||
font_plot_style_from_css(box->style, &fstyle);
|
||||
|
||||
nsfont.font_position_in_string(&fstyle, box->text, box->length,
|
||||
dx, &idx, &pixel_offset);
|
||||
|
||||
idx += box->byte_offset;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle mouse tracking (including drags) in an HTML content window.
|
||||
*
|
||||
@ -62,7 +95,6 @@ void html_mouse_track(struct content *c, struct browser_window *bw,
|
||||
browser_mouse_state mouse, int x, int y)
|
||||
{
|
||||
html_content *html = (html_content*) c;
|
||||
hlcache_handle *h = bw->current_content;
|
||||
|
||||
if (bw->drag_type == DRAGGING_SELECTION && !mouse) {
|
||||
int dir = -1;
|
||||
@ -71,7 +103,7 @@ void html_mouse_track(struct content *c, struct browser_window *bw,
|
||||
if (selection_dragging_start(&html->sel))
|
||||
dir = 1;
|
||||
|
||||
idx = html_selection_drag_end(h, mouse, x, y, dir);
|
||||
idx = html_selection_drag_end(html, mouse, x, y, dir);
|
||||
|
||||
if (idx != 0)
|
||||
selection_track(&html->sel, mouse, idx);
|
||||
@ -88,7 +120,7 @@ void html_mouse_track(struct content *c, struct browser_window *bw,
|
||||
if (selection_dragging_start(&html->sel))
|
||||
dir = 1;
|
||||
|
||||
box = box_pick_text_box(h, x, y, dir, &dx, &dy);
|
||||
box = box_pick_text_box(html, x, y, dir, &dx, &dy);
|
||||
|
||||
if (box) {
|
||||
int pixel_offset;
|
||||
@ -869,38 +901,6 @@ void html_overflow_scroll_drag_end(struct scrollbar *scrollbar,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End overflow scroll scrollbar drags
|
||||
*
|
||||
* \param h html content's high level cache entry
|
||||
* \param mouse state of mouse buttons and modifier keys
|
||||
* \param x coordinate of mouse
|
||||
* \param y coordinate of mouse
|
||||
*/
|
||||
size_t html_selection_drag_end(hlcache_handle *h, browser_mouse_state mouse,
|
||||
int x, int y, int dir)
|
||||
{
|
||||
int pixel_offset;
|
||||
struct box *box;
|
||||
int dx, dy;
|
||||
size_t idx = 0;
|
||||
|
||||
box = box_pick_text_box(h, x, y, dir, &dx, &dy);
|
||||
if (box) {
|
||||
plot_font_style_t fstyle;
|
||||
|
||||
font_plot_style_from_css(box->style, &fstyle);
|
||||
|
||||
nsfont.font_position_in_string(&fstyle, box->text, box->length,
|
||||
dx, &idx, &pixel_offset);
|
||||
|
||||
idx += box->byte_offset;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start drag scrolling the contents of a box
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user