summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-04-26 20:48:54 +0100
committerVincent Sanders <vince@kyllikki.org>2017-04-26 20:48:54 +0100
commit87066f9f8dbad2416c53f70497aeb7c940ccb239 (patch)
tree4dac3a7c9eff12f4ec7d2cfd09882f72d7923e3c
parent796bb0f652a5557f6903d96c6b7652a1565e6885 (diff)
downloadnetsurf-87066f9f8dbad2416c53f70497aeb7c940ccb239.tar.gz
netsurf-87066f9f8dbad2416c53f70497aeb7c940ccb239.tar.bz2
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.
-rw-r--r--desktop/browser.c155
-rw-r--r--desktop/gui_factory.c9
-rw-r--r--include/netsurf/browser_window.h20
-rw-r--r--include/netsurf/window.h31
4 files changed, 105 insertions, 110 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 73a86c2e3..4b6a5bbd0 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -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);
+/**
+ * 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) {
- /* 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);
+ return guit->window->set_scroll(bw->window, rect);
}
-}
-/* exported interface, documented in browser.h */
-void browser_window_set_scroll(struct browser_window *bw, int x, int y)
-{
- 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);
+ 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:
+ {
+ struct rect rect = {
+ .x0 = event->data.scroll.x0,
+ .y0 = event->data.scroll.y0,
+ };
+
/* Content wants to be scrolled */
- if (bw->current_content != c)
+ if (bw->current_content != c) {
break;
+ }
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);
+ rect.x1 = event->data.scroll.x1;
+ rect.y1 = event->data.scroll.y1;
} else {
- browser_window_set_scroll(bw,
- event->data.scroll.x0,
- event->data.scroll.y0);
+ 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);
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 559823d61..ca9eff1da 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -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;
}
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index c56cf5571..567e314c5 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -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
diff --git a/include/netsurf/window.h b/include/netsurf/window.h
index b9a68639c..81fc0676b 100644
--- a/include/netsurf/window.h
+++ b/include/netsurf/window.h
@@ -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