mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-02 01:04:33 +03:00
simplify the browser window operations by removing scroll API
The browser window scrollingAPI was duplicated in window operation table, this simplifies it to a single set_scroll API.
This commit is contained in:
parent
796bb0f652
commit
87066f9f8d
@ -586,36 +586,33 @@ static void browser_window_set_selection(struct browser_window *bw,
|
||||
top->selection.read_only = read_only;
|
||||
}
|
||||
|
||||
/* exported interface, documented in browser.h */
|
||||
void browser_window_scroll_visible(struct browser_window *bw,
|
||||
const struct rect *rect)
|
||||
{
|
||||
assert(bw != NULL);
|
||||
|
||||
if (bw->window != NULL) {
|
||||
/* Front end window */
|
||||
guit->window->scroll_visible(bw->window,
|
||||
rect->x0, rect->y0, rect->x1, rect->y1);
|
||||
} else {
|
||||
/* Core managed browser window */
|
||||
if (bw->scroll_x != NULL)
|
||||
scrollbar_set(bw->scroll_x, rect->x0, false);
|
||||
if (bw->scroll_y != NULL)
|
||||
scrollbar_set(bw->scroll_y, rect->y0, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* exported interface, documented in browser.h */
|
||||
void browser_window_set_scroll(struct browser_window *bw, int x, int y)
|
||||
/**
|
||||
* Set the scroll position of a browser window.
|
||||
*
|
||||
* scrolls the viewport to ensure the specified rectangle of the
|
||||
* content is shown.
|
||||
*
|
||||
* \param gw gui_window to scroll
|
||||
* \param rect The rectangle to ensure is shown.
|
||||
* \return NSERROR_OK on success or apropriate error code.
|
||||
*/
|
||||
static nserror
|
||||
browser_window_set_scroll(struct browser_window *bw,
|
||||
const struct rect *rect)
|
||||
{
|
||||
if (bw->window != NULL) {
|
||||
guit->window->set_scroll(bw->window, x, y);
|
||||
} else {
|
||||
if (bw->scroll_x != NULL)
|
||||
scrollbar_set(bw->scroll_x, x, false);
|
||||
if (bw->scroll_y != NULL)
|
||||
scrollbar_set(bw->scroll_y, y, false);
|
||||
return guit->window->set_scroll(bw->window, rect);
|
||||
}
|
||||
|
||||
if (bw->scroll_x != NULL) {
|
||||
scrollbar_set(bw->scroll_x, rect->x0, false);
|
||||
}
|
||||
if (bw->scroll_y != NULL) {
|
||||
scrollbar_set(bw->scroll_y, rect->y0, false);
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1610,25 +1607,28 @@ browser_window_callback(hlcache_handle *c,
|
||||
break;
|
||||
|
||||
case CONTENT_MSG_SCROLL:
|
||||
/* Content wants to be scrolled */
|
||||
if (bw->current_content != c)
|
||||
break;
|
||||
{
|
||||
struct rect rect = {
|
||||
.x0 = event->data.scroll.x0,
|
||||
.y0 = event->data.scroll.y0,
|
||||
};
|
||||
|
||||
if (event->data.scroll.area) {
|
||||
struct rect rect = {
|
||||
.x0 = event->data.scroll.x0,
|
||||
.y0 = event->data.scroll.y0,
|
||||
.x1 = event->data.scroll.x1,
|
||||
.y1 = event->data.scroll.y1
|
||||
};
|
||||
browser_window_scroll_visible(bw, &rect);
|
||||
} else {
|
||||
browser_window_set_scroll(bw,
|
||||
event->data.scroll.x0,
|
||||
event->data.scroll.y0);
|
||||
/* Content wants to be scrolled */
|
||||
if (bw->current_content != c) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (event->data.scroll.area) {
|
||||
rect.x1 = event->data.scroll.x1;
|
||||
rect.y1 = event->data.scroll.y1;
|
||||
} else {
|
||||
rect.x1 = event->data.scroll.x0;
|
||||
rect.y1 = event->data.scroll.y0;
|
||||
}
|
||||
browser_window_set_scroll(bw, &rect);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CONTENT_MSG_DRAGSAVE:
|
||||
{
|
||||
@ -2324,13 +2324,48 @@ void browser_window_set_dimensions(struct browser_window *bw,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* scroll to a fragment if present
|
||||
*
|
||||
* \param bw browser window
|
||||
* \return true if the scroll was sucessful
|
||||
*/
|
||||
static bool frag_scroll(struct browser_window *bw)
|
||||
{
|
||||
struct rect rect;
|
||||
|
||||
if (bw->frag_id == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!html_get_id_offset(bw->current_content,
|
||||
bw->frag_id,
|
||||
&rect.x0,
|
||||
&rect.y0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rect.x1 = rect.x0;
|
||||
rect.y1 = rect.y0;
|
||||
if (browser_window_set_scroll(bw, &rect) == NSERROR_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Exported interface, documented in browser.h */
|
||||
void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
{
|
||||
int x, y;
|
||||
static const struct rect zrect = {
|
||||
.x0 = 0,
|
||||
.y0 = 0,
|
||||
.x1 = 0,
|
||||
.y1 = 0
|
||||
};
|
||||
|
||||
if (bw->current_content == NULL)
|
||||
if (bw->current_content == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (bw->browser_window_type) {
|
||||
|
||||
@ -2343,13 +2378,9 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
if (bw->frag_id &&
|
||||
html_get_id_offset(bw->current_content,
|
||||
bw->frag_id, &x, &y)) {
|
||||
browser_window_set_scroll(bw, x, y);
|
||||
} else {
|
||||
if (!frag_scroll(bw)) {
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, 0, 0);
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2364,15 +2395,13 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top)
|
||||
browser_window_set_scroll(bw, 0, 0);
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
if (bw->frag_id && html_get_id_offset(bw->current_content,
|
||||
bw->frag_id, &x, &y)) {
|
||||
browser_window_set_scroll(bw, x, y);
|
||||
}
|
||||
frag_scroll(bw);
|
||||
|
||||
html_redraw_a_box(bw->parent->current_content, bw->box);
|
||||
break;
|
||||
@ -2382,15 +2411,13 @@ void browser_window_update(struct browser_window *bw, bool scroll_to_top)
|
||||
struct rect rect;
|
||||
browser_window_update_extent(bw);
|
||||
|
||||
if (scroll_to_top)
|
||||
browser_window_set_scroll(bw, 0, 0);
|
||||
if (scroll_to_top) {
|
||||
browser_window_set_scroll(bw, &zrect);
|
||||
}
|
||||
|
||||
/* if frag_id exists, then try to scroll to it */
|
||||
/** @todo don't do this if the user has scrolled */
|
||||
if (bw->frag_id && html_get_id_offset(bw->current_content,
|
||||
bw->frag_id, &x, &y)) {
|
||||
browser_window_set_scroll(bw, x, y);
|
||||
}
|
||||
frag_scroll(bw);
|
||||
|
||||
rect.x0 = scrollbar_get_offset(bw->scroll_x);
|
||||
rect.y0 = scrollbar_get_offset(bw->scroll_y);
|
||||
@ -3078,17 +3105,19 @@ void browser_window_mouse_track(struct browser_window *bw,
|
||||
browser_window_resize_frame(bw, bw->x + x, bw->y + y);
|
||||
} else if (bw->drag.type == DRAGGING_PAGE_SCROLL) {
|
||||
/* mouse movement since drag started */
|
||||
int scrollx = bw->drag.start_x - x;
|
||||
int scrolly = bw->drag.start_y - y;
|
||||
struct rect rect;
|
||||
|
||||
rect.x0 = bw->drag.start_x - x;
|
||||
rect.y0 = bw->drag.start_y - y;
|
||||
|
||||
/* new scroll offsets */
|
||||
scrollx += bw->drag.start_scroll_x;
|
||||
scrolly += bw->drag.start_scroll_y;
|
||||
rect.x0 += bw->drag.start_scroll_x;
|
||||
rect.y0 += bw->drag.start_scroll_y;
|
||||
|
||||
bw->drag.start_scroll_x = scrollx;
|
||||
bw->drag.start_scroll_y = scrolly;
|
||||
bw->drag.start_scroll_x = rect.x1 = rect.x0;
|
||||
bw->drag.start_scroll_y = rect.y1 = rect.y0;
|
||||
|
||||
browser_window_set_scroll(bw, scrollx, scrolly);
|
||||
browser_window_set_scroll(bw, &rect);
|
||||
} else {
|
||||
assert(c != NULL);
|
||||
content_mouse_track(c, bw, mouse, x, y);
|
||||
|
@ -82,12 +82,6 @@ static void gui_default_window_set_icon(struct gui_window *g,
|
||||
{
|
||||
}
|
||||
|
||||
static void gui_default_window_scroll_visible(struct gui_window *g,
|
||||
int x0, int y0,
|
||||
int x1, int y1)
|
||||
{
|
||||
guit->window->set_scroll(g, x0, y0);
|
||||
}
|
||||
|
||||
static void gui_default_window_new_content(struct gui_window *g)
|
||||
{
|
||||
@ -212,9 +206,6 @@ static nserror verify_window_register(struct gui_window_table *gwt)
|
||||
if (gwt->save_link == NULL) {
|
||||
gwt->save_link = gui_default_window_save_link;
|
||||
}
|
||||
if (gwt->scroll_visible == NULL) {
|
||||
gwt->scroll_visible = gui_default_window_scroll_visible;
|
||||
}
|
||||
if (gwt->new_content == NULL) {
|
||||
gwt->new_content = gui_default_window_new_content;
|
||||
}
|
||||
|
@ -572,26 +572,6 @@ void browser_window_get_position(struct browser_window *bw, bool root,
|
||||
*/
|
||||
void browser_window_set_position(struct browser_window *bw, int x, int y);
|
||||
|
||||
/**
|
||||
* Scroll the browser window to display the passed area
|
||||
*
|
||||
* \param bw browser window to scroll
|
||||
* \param rect area to display
|
||||
*/
|
||||
void browser_window_scroll_visible(struct browser_window *bw,
|
||||
const struct rect *rect);
|
||||
|
||||
/**
|
||||
* Set scroll offsets for a browser window.
|
||||
*
|
||||
* \param bw The browser window
|
||||
* \param x The x scroll offset to set
|
||||
* \param y The y scroll offset to set
|
||||
*
|
||||
* \todo Do we really need this and browser_window_scroll_visible?
|
||||
* Ditto for gui_window_* variants.
|
||||
*/
|
||||
void browser_window_set_scroll(struct browser_window *bw, int x, int y);
|
||||
|
||||
/**
|
||||
* Set drag type for a browser window, and inform front end
|
||||
|
@ -136,11 +136,20 @@ struct gui_window_table {
|
||||
/**
|
||||
* Set the scroll position of a browser window.
|
||||
*
|
||||
* \param g gui_window to scroll
|
||||
* \param sx point to place at top-left of window
|
||||
* \param sy point to place at top-left of window
|
||||
* scrolls the viewport to ensure the specified rectangle of
|
||||
* the content is shown.
|
||||
* If the rectangle is of zero size i.e. x0 == x1 and y0 == y1
|
||||
* the contents will be scrolled so the specified point in the
|
||||
* content is at the top of the viewport.
|
||||
* If the size of the rectangle is non zero the frontend may
|
||||
* add padding or center the defined area or it may simply
|
||||
* align as in the zero size rectangle
|
||||
*
|
||||
* \param gw gui_window to scroll
|
||||
* \param rect The rectangle to ensure is shown.
|
||||
* \return NSERROR_OK on success or apropriate error code.
|
||||
*/
|
||||
void (*set_scroll)(struct gui_window *g, int sx, int sy);
|
||||
nserror (*set_scroll)(struct gui_window *gw, const struct rect *rect);
|
||||
|
||||
|
||||
/**
|
||||
@ -267,20 +276,6 @@ struct gui_window_table {
|
||||
*/
|
||||
nserror (*save_link)(struct gui_window *g, struct nsurl *url, const char *title);
|
||||
|
||||
/**
|
||||
* Scrolls the specified area of a browser window into view.
|
||||
*
|
||||
* @todo investigate if this can be merged with set_scroll
|
||||
* which is what the default implementation used by most
|
||||
* toolkits uses.
|
||||
*
|
||||
* \param g gui_window to scroll
|
||||
* \param x0 left point to ensure visible
|
||||
* \param y0 bottom point to ensure visible
|
||||
* \param x1 right point to ensure visible
|
||||
* \param y1 top point to ensure visible
|
||||
*/
|
||||
void (*scroll_visible)(struct gui_window *g, int x0, int y0, int x1, int y1);
|
||||
|
||||
/**
|
||||
* Starts drag scrolling of a browser window
|
||||
|
Loading…
Reference in New Issue
Block a user