changeset 32419:7b9566b77501

Add page up/down for WebKit view.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Tue, 27 Dec 2011 22:00:00 +0000
parents 466efc330d3d
children 4039f92cc589
files pidgin/gtkconv.c pidgin/gtkwebview.c pidgin/gtkwebview.h
diffstat 3 files changed, 51 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv.c	Fri Dec 23 03:59:39 2011 +0000
+++ b/pidgin/gtkconv.c	Tue Dec 27 22:00:00 2011 +0000
@@ -2186,19 +2186,13 @@
 
 		case GDK_Page_Up:
 		case GDK_KP_Page_Up:
-/* TODO WEBKIT: Write this. */
-#if 0
-			gtk_imhtml_page_up(GTK_IMHTML(gtkconv->imhtml));
-#endif /* if 0 */
+			gtk_webview_page_up(GTK_WEBVIEW(gtkconv->webview));
 			return TRUE;
 			break;
 
 		case GDK_Page_Down:
 		case GDK_KP_Page_Down:
-/* TODO WEBKIT: Write this. */
-#if 0
-			gtk_imhtml_page_down(GTK_IMHTML(gtkconv->imhtml));
-#endif /* if 0 */
+			gtk_webview_page_down(GTK_WEBVIEW(gtkconv->webview));
 			return TRUE;
 			break;
 
--- a/pidgin/gtkwebview.c	Fri Dec 23 03:59:39 2011 +0000
+++ b/pidgin/gtkwebview.c	Tue Dec 27 22:00:00 2011 +0000
@@ -394,6 +394,41 @@
 	}
 }
 
+void gtk_webview_page_up(GtkWebView *webview)
+{
+	GtkAdjustment *vadj = webview->priv->vadj;
+	gdouble scroll_val;
+
+#if GTK_CHECK_VERSION(2,14,0)
+	scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
+	scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
+#else
+	scroll_val = gtk_adjustment_get_value(vadj) - vadj->page_size;
+	scroll_val = MAX(scroll_val, vadj->lower);
+#endif
+
+	gtk_adjustment_set_value(vadj, scroll_val);
+}
+
+void gtk_webview_page_down(GtkWebView *webview)
+{
+	GtkAdjustment *vadj = webview->priv->vadj;
+	gdouble scroll_val;
+	gdouble page_size;
+
+#if GTK_CHECK_VERSION(2,14,0)
+	page_size = gtk_adjustment_get_page_size(vadj);
+	scroll_val = gtk_adjustment_get_value(vadj) + page_size;
+	scroll_val = MIN(scroll_val, gtk_adjustment_get_upper(vadj) - page_size);
+#else
+	page_size = vadj->page_size;
+	scroll_val = gtk_adjustment_get_value(vadj) + page_size;
+	scroll_val = MIN(scroll_val, vadj->upper - page_size);
+#endif
+
+	gtk_adjustment_set_value(vadj, scroll_val);
+}
+
 GType
 gtk_webview_get_type(void)
 {
--- a/pidgin/gtkwebview.h	Fri Dec 23 03:59:39 2011 +0000
+++ b/pidgin/gtkwebview.h	Tue Dec 27 22:00:00 2011 +0000
@@ -143,5 +143,19 @@
  */
 void gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth);
 
+/**
+ * Scrolls a GtkWebView up by one page.
+ *
+ * @param webview The GtkWebView.
+ */
+void gtk_webview_page_up(GtkWebView *webview);
+
+/**
+ * Scrolls a GtkWebView down by one page.
+ *
+ * @param webview The GtkWebView.
+ */
+void gtk_webview_page_down(GtkWebView *webview);
+
 #endif /* _PIDGIN_WEBVIEW_H_ */