[epiphany-extensions] auto-scroller: fix the actual scrolling



commit 0e1467db2271b21b9545c527255de234a258355b
Author: Diego Escalante Urrelo <descalante igalia com>
Date:   Fri Jan 22 23:41:43 2010 -0500

    auto-scroller: fix the actual scrolling
    
    It was broken, with a similar problem than push-scroller.

 .../auto-scroller/ephy-auto-scroller-extension.c   |   12 ++++---
 extensions/auto-scroller/ephy-auto-scroller.c      |   32 +++++++++++++++-----
 extensions/auto-scroller/ephy-auto-scroller.h      |    4 +-
 3 files changed, 33 insertions(+), 15 deletions(-)
---
diff --git a/extensions/auto-scroller/ephy-auto-scroller-extension.c b/extensions/auto-scroller/ephy-auto-scroller-extension.c
index f6c54fa..3fffb70 100644
--- a/extensions/auto-scroller/ephy-auto-scroller-extension.c
+++ b/extensions/auto-scroller/ephy-auto-scroller-extension.c
@@ -62,7 +62,7 @@ dom_mouse_down_cb (EphyWebView *view,
 {
 	EphyAutoScroller *scroller;
 	guint context;
-	guint button, x, y;
+	guint button;
         WebKitHitTestResult *hit_test;
 
 	button = event->button;
@@ -70,7 +70,9 @@ dom_mouse_down_cb (EphyWebView *view,
 	g_object_get (hit_test, "context", &context, NULL);
 	g_object_unref (hit_test);
 
-	if (button != 2 || (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) ||
+	if (button != 2 ||
+	    event->type != GDK_BUTTON_PRESS ||
+	    (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) ||
 	    (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK))
 	{
 		return FALSE;
@@ -79,9 +81,9 @@ dom_mouse_down_cb (EphyWebView *view,
 	scroller = ensure_auto_scroller (window);
 	g_return_val_if_fail (scroller != NULL, FALSE);
 
-	x = (guint)event->x_root;
-	y = (guint)event->y_root;
-	ephy_auto_scroller_start (scroller, EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), x, y);
+	ephy_auto_scroller_start (scroller,
+				  EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view),
+				  event->x_root, event->y_root);
 
 	return TRUE;
 }
diff --git a/extensions/auto-scroller/ephy-auto-scroller.c b/extensions/auto-scroller/ephy-auto-scroller.c
index b18217d..2153dfc 100644
--- a/extensions/auto-scroller/ephy-auto-scroller.c
+++ b/extensions/auto-scroller/ephy-auto-scroller.c
@@ -190,16 +190,32 @@ ephy_auto_scroller_scroll_pixels (EphyEmbed *embed, int scroll_x, int scroll_y)
 {
 	GtkAdjustment *adj;
 	gdouble value;
+	gdouble new_value;
+	gdouble page_size;
+	gdouble upper;
+	gdouble lower;
+	GtkWidget *sw;
+
+	sw = gtk_widget_get_parent (GTK_WIDGET (ephy_embed_get_web_view (embed)));
+	g_return_if_fail (GTK_IS_SCROLLED_WINDOW (sw));
+
+	adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (sw));
+	upper = gtk_adjustment_get_upper (adj);
+	lower = gtk_adjustment_get_lower (adj);
+	value = gtk_adjustment_get_value (adj);
+	page_size = gtk_adjustment_get_page_size (adj);
 
-	g_return_if_fail (GTK_IS_SCROLLED_WINDOW (embed));
+	new_value = CLAMP (value + scroll_x, lower, upper - page_size);
+	gtk_adjustment_set_value (adj, new_value);
 
-	adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (embed));
+	adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw));
+	upper = gtk_adjustment_get_upper (adj);
+	lower = gtk_adjustment_get_lower (adj);
 	value = gtk_adjustment_get_value (adj);
-	gtk_adjustment_set_value (adj, value + scroll_x);
+	page_size = gtk_adjustment_get_page_size (adj);
 
-	adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (embed));
-	value = gtk_adjustment_get_value (adj);
-	gtk_adjustment_set_value (adj, value + scroll_y);
+	new_value = CLAMP (value + scroll_y, lower, upper - page_size);
+	gtk_adjustment_set_value (adj, new_value);
 }
 
 static int
@@ -284,8 +300,8 @@ ephy_auto_scroller_timeout_cb (EphyAutoScroller *scroller)
 void
 ephy_auto_scroller_start (EphyAutoScroller *scroller,
 			  EphyEmbed *embed,
-			  int x,
-			  int y)
+			  gdouble x,
+			  gdouble y)
 {
 	EphyAutoScrollerPrivate *priv = scroller->priv;
 	GtkWidget *widget, *child;
diff --git a/extensions/auto-scroller/ephy-auto-scroller.h b/extensions/auto-scroller/ephy-auto-scroller.h
index c132f26..da36aae 100644
--- a/extensions/auto-scroller/ephy-auto-scroller.h
+++ b/extensions/auto-scroller/ephy-auto-scroller.h
@@ -62,8 +62,8 @@ EphyAutoScroller       *ephy_auto_scroller_new		 (EphyWindow *window);
 
 void			ephy_auto_scroller_start	 (EphyAutoScroller *scroller,
 							  EphyEmbed *embed,
-							  int x,
-							  int y);
+							  gdouble x,
+							  gdouble y);
 
 void			ephy_auto_scroller_stop		 (EphyAutoScroller *scroller,
 							  guint32 timestamp);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]