]> spindle.queued.net Git - midori/commitdiff
Conditionalize restoring of the scrolling position
authorChristian Dywan <christian@twotoasts.de>
Wed, 7 Oct 2009 21:51:35 +0000 (23:51 +0200)
committerChristian Dywan <christian@twotoasts.de>
Thu, 8 Oct 2009 18:56:24 +0000 (20:56 +0200)
Ensure that we differentiate an unset value from a valid value
as well as having restored the position already so we don't
accidentally restore a wrong position.

Restoring after having loaded a page is still not ideal but there
doesn't seem to be a better way at this point.

midori/midori-view.c

index 1ca49dcd6cf6ceebe7860a15d3521326dd7795b3..5918293bd4f87b44ff21b1705d511b0d2e9bd176 100644 (file)
@@ -904,6 +904,31 @@ webkit_web_frame_load_done_cb (WebKitWebFrame* web_frame,
 }
 #endif
 
+static void
+midori_view_apply_scroll_position (MidoriView* view)
+{
+    if (view->scrollh > -2)
+    {
+        if (view->scrollh > 0)
+        {
+            GtkAdjustment* adjustment = katze_object_get_object (view, "hadjustment");
+            gtk_adjustment_set_value (adjustment, view->scrollh);
+            g_object_unref (adjustment);
+        }
+        view->scrollh = -3;
+    }
+    if (view->scrollv > -2)
+    {
+        if (view->scrollv > 0)
+        {
+            GtkAdjustment* adjustment = katze_object_get_object (view, "vadjustment");
+            gtk_adjustment_set_value (adjustment, view->scrollv);
+            g_object_unref (adjustment);
+        }
+        view->scrollv = -3;
+    }
+}
+
 static void
 webkit_web_view_load_finished_cb (WebKitWebView*  web_view,
                                   WebKitWebFrame* web_frame,
@@ -911,21 +936,14 @@ webkit_web_view_load_finished_cb (WebKitWebView*  web_view,
 {
     g_object_freeze_notify (G_OBJECT (view));
 
+    /* TODO: Find a better condition than a finished load.
+      Apparently WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT is too early. */
+    midori_view_apply_scroll_position (view);
+
     view->progress = 1.0;
     g_object_notify (G_OBJECT (view), "progress");
     midori_view_update_load_status (view, MIDORI_LOAD_FINISHED);
 
-    if (view->scrollh || view->scrollv)
-    {
-        GtkAdjustment* adjustment = katze_object_get_object (view, "hadjustment");
-        gtk_adjustment_set_value (adjustment, view->scrollh);
-        g_object_unref (adjustment);
-        adjustment = katze_object_get_object (view, "vadjustment");
-        gtk_adjustment_set_value (adjustment, view->scrollv);
-        g_object_unref (adjustment);
-        view->scrollh = view->scrollv = 0;
-    }
-
     if (1)
     {
         JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
@@ -2208,7 +2226,7 @@ midori_view_init (MidoriView* view)
     view->news_feeds = katze_array_new (KATZE_TYPE_ITEM);
 
     view->item = NULL;
-    view->scrollh = view->scrollv = 0;
+    view->scrollh = view->scrollv = -2;
     view->back_forward_set = FALSE;
 
     view->download_manager = NULL;
@@ -3474,9 +3492,9 @@ midori_view_item_meta_data_changed (KatzeItem*   item,
     else if (g_str_has_prefix (key, "scroll"))
     {
         gint value = katze_item_get_meta_integer (item, key);
-        if (!view->scrollh && key[6] == 'h')
+        if (view->scrollh == -2 && key[6] == 'h')
             view->scrollh = value > -1 ? value : 0;
-        else if (!view->scrollv && key[6] == 'v')
+        else if (view->scrollv == -2 && key[6] == 'v')
             view->scrollv = value > -1 ? value : 0;
         else
             return;