[devhelp] WebView: store total_scroll_delta_y per view



commit 320aeb45d47d625e0561171fd034a88d5ee4dfcf
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Feb 10 09:38:47 2018 +0100

    WebView: store total_scroll_delta_y per view
    
    With the static variable, the same variable was used for all
    DhWebView's.

 src/dh-web-view.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/src/dh-web-view.c b/src/dh-web-view.c
index f122780..24d7c54 100644
--- a/src/dh-web-view.c
+++ b/src/dh-web-view.c
@@ -21,6 +21,7 @@
 
 struct _DhWebViewPrivate {
         gchar *search_text;
+        gdouble total_scroll_delta_y;
 };
 
 static const gdouble zoom_levels[] = {
@@ -86,7 +87,6 @@ dh_web_view_scroll_event (GtkWidget      *widget,
                           GdkEventScroll *scroll_event)
 {
         DhWebView *view = DH_WEB_VIEW (widget);
-        static gdouble total_delta_y = 0.f; /* FIXME: store in view->priv->total_scroll_delta_y */
         gdouble delta_y;
 
         if ((scroll_event->state & GDK_CONTROL_MASK) == 0)
@@ -107,17 +107,17 @@ dh_web_view_scroll_event (GtkWidget      *widget,
 
                 case GDK_SCROLL_SMOOTH:
                         gdk_event_get_scroll_deltas ((GdkEvent *)scroll_event, NULL, &delta_y);
-                        total_delta_y += delta_y;
+                        view->priv->total_scroll_delta_y += delta_y;
 
                         /* Avoiding direct float comparison.
                          * -1 and 1 are the thresholds for bumping the zoom level,
                          * which can be adjusted for taste.
                          */
-                        if ((gint)total_delta_y <= -1) {
-                                total_delta_y = 0.f;
+                        if ((gint)view->priv->total_scroll_delta_y <= -1) {
+                                view->priv->total_scroll_delta_y = 0.f;
                                 bump_zoom_level (view, 1);
-                        } else if ((gint)total_delta_y >= 1) {
-                                total_delta_y = 0.f;
+                        } else if ((gint)view->priv->total_scroll_delta_y >= 1) {
+                                view->priv->total_scroll_delta_y = 0.f;
                                 bump_zoom_level (view, -1);
                         }
                         return GDK_EVENT_STOP;
@@ -175,6 +175,7 @@ static void
 dh_web_view_init (DhWebView *view)
 {
         view->priv = dh_web_view_get_instance_private (view);
+        view->priv->total_scroll_delta_y = 0.f;
 }
 
 DhWebView *


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