don't scroll past the end of the page.
authorBrendan Taylor <whateley@gmail.com>
Sat, 20 Jun 2009 18:09:37 +0000 (12:09 -0600)
committerBrendan Taylor <whateley@gmail.com>
Sat, 20 Jun 2009 18:09:37 +0000 (12:09 -0600)
uzbl.c

diff --git a/uzbl.c b/uzbl.c
index b9e5d68..e6e9551 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -445,12 +445,24 @@ download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) {
 /* scroll a bar in a given direction */
 static void
 scroll (GtkAdjustment* bar, GArray *argv) {
-    gdouble amount;
     gchar *end;
+    gdouble max_value;
 
-    amount = g_ascii_strtod(g_array_index(argv, gchar*, 0), &end);
-    if (*end == '%') amount = gtk_adjustment_get_page_size(bar) * amount * 0.01;
-    gtk_adjustment_set_value (bar, gtk_adjustment_get_value(bar)+amount);
+    gdouble page_size = gtk_adjustment_get_page_size(bar);
+    gdouble value = gtk_adjustment_get_value(bar);
+    gdouble amount = g_ascii_strtod(g_array_index(argv, gchar*, 0), &end);
+
+    if (*end == '%')
+        value += page_size * amount * 0.01;
+    else
+        value += amount;
+
+    max_value = gtk_adjustment_get_upper(bar) - page_size;
+
+    if (value > max_value)
+        value = max_value; /* don't scroll past the end of the page */
+
+    gtk_adjustment_set_value (bar, value);
 }
 
 static void