summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 21:00:06 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 21:00:06 +0100
commitc078c3f50932f9fc0bcb20ed8ddaaf648f6acda2 (patch)
tree3f4b34f8e1fbc101f84ff4ce03096d2d89b61dcf
parent818f4018d2a2e8a16e2c65c97ecd56c2f583f2c1 (diff)
downloadnetsurf-c078c3f50932f9fc0bcb20ed8ddaaf648f6acda2.tar.gz
netsurf-c078c3f50932f9fc0bcb20ed8ddaaf648f6acda2.tar.bz2
gtk/corewindow.c: Correctly handle scroll_visible
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--frontends/gtk/corewindow.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c
index 4f05648ba..9dc388c4f 100644
--- a/frontends/gtk/corewindow.c
+++ b/frontends/gtk/corewindow.c
@@ -608,26 +608,52 @@ static void
nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
{
struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw;
- int y = 0, height = 0, y0, y1;
- gdouble page;
+ int x0, y0, x1, y1;
+ gdouble vpage, hpage;
GtkAdjustment *vadj;
+ GtkAdjustment *hadj;
vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
+ hadj = gtk_scrolled_window_get_hadjustment(nsgtk_cw->scrolled);
- assert(vadj);
+ assert(vadj != NULL);
+ assert(hadj != NULL);
- g_object_get(vadj, "page-size", &page, NULL);
+ g_object_get(vadj, "page-size", &vpage, NULL);
+ g_object_get(hadj, "page-size", &hpage, NULL);
y0 = (int)(gtk_adjustment_get_value(vadj));
- y1 = y0 + page;
-
- if ((y >= y0) && (y + height <= y1))
- return;
- if (y + height > y1)
- y0 = y0 + (y + height - y1);
- if (y < y0)
- y0 = y;
+ y1 = y0 + vpage;
+ x0 = (int)(gtk_adjustment_get_value(hadj));
+ x1 = x0 + hpage;
+
+ if (r->y1 > y1) {
+ /* The bottom of the rectangle is off the bottom of the
+ * window, so scroll down to fit it
+ */
+ y0 = r->y1 - vpage;
+ }
+ if (r->y0 < y0) {
+ /* The top of the rectangle is off the top of the window,
+ * so scroll up to fit it
+ */
+ y0 = r->y0;
+ }
+ if (r->x1 > x1) {
+ /* The right of the rectangle is off the right of the window
+ * so scroll right to fit it
+ */
+ x0 = r->x1 - hpage;
+ }
+ if (r->x0 < x0) {
+ /* The left of the rectangle is off the left of the window
+ * so scroll left to fit it
+ */
+ x0 = r->x0;
+ }
+
gtk_adjustment_set_value(vadj, y0);
+ gtk_adjustment_set_value(hadj, x0);
}