From fa8f109da91310589c459bb94ae9c4616574b634 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 7 Oct 2009 23:51:35 +0200 Subject: [PATCH] Conditionalize restoring of the scrolling position 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 | 46 ++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/midori/midori-view.c b/midori/midori-view.c index 1ca49dcd..5918293b 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -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;