Remember the scrolled positions of views

This commit is contained in:
Christian Dywan 2009-09-16 22:02:30 +02:00
parent c4808e1701
commit 9d1fdd7a05

View file

@ -92,6 +92,7 @@ struct _MidoriView
GtkWidget* tab_title; GtkWidget* tab_title;
GtkWidget* tab_close; GtkWidget* tab_close;
KatzeItem* item; KatzeItem* item;
gint scrollh, scrollv;
KatzeNet* net; KatzeNet* net;
}; };
@ -206,7 +207,6 @@ static void
midori_view_speed_dial_save (GtkWidget* web_view, midori_view_speed_dial_save (GtkWidget* web_view,
const gchar* message); const gchar* message);
static void static void
midori_view_class_init (MidoriViewClass* class) midori_view_class_init (MidoriViewClass* class)
{ {
@ -847,6 +847,17 @@ webkit_web_view_load_finished_cb (WebKitWebView* web_view,
g_object_notify (G_OBJECT (view), "progress"); g_object_notify (G_OBJECT (view), "progress");
midori_view_update_load_status (view, MIDORI_LOAD_FINISHED); 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) if (1)
{ {
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame); JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
@ -1668,6 +1679,48 @@ webkit_web_view_window_object_cleared_cb (GtkWidget* web_view,
g_signal_emit (view, signals[CONTEXT_READY], 0, js_context); g_signal_emit (view, signals[CONTEXT_READY], 0, js_context);
} }
static void
midori_view_hadjustment_notify_value_cb (GtkAdjustment* hadjustment,
GParamSpec* pspec,
MidoriView* view)
{
gint value = (gint)gtk_adjustment_get_value (hadjustment);
if (view->item)
katze_item_set_meta_integer (view->item, "scrollh", value);
}
static void
midori_view_notify_hadjustment_cb (MidoriView* view,
GParamSpec* pspec,
gpointer data)
{
GtkAdjustment* hadjustment = katze_object_get_object (view, "hadjustment");
g_signal_connect (hadjustment, "notify::value",
G_CALLBACK (midori_view_hadjustment_notify_value_cb), view);
g_object_unref (hadjustment);
}
static void
midori_view_vadjustment_notify_value_cb (GtkAdjustment* vadjustment,
GParamSpec* pspec,
MidoriView* view)
{
gint value = (gint)gtk_adjustment_get_value (vadjustment);
if (view->item)
katze_item_set_meta_integer (view->item, "scrollv", value);
}
static void
midori_view_notify_vadjustment_cb (MidoriView* view,
GParamSpec* pspec,
gpointer data)
{
GtkAdjustment* vadjustment = katze_object_get_object (view, "vadjustment");
g_signal_connect (vadjustment, "notify::value",
G_CALLBACK (midori_view_vadjustment_notify_value_cb), view);
g_object_unref (vadjustment);
}
static void static void
midori_view_init (MidoriView* view) midori_view_init (MidoriView* view)
{ {
@ -1685,13 +1738,18 @@ midori_view_init (MidoriView* view)
view->news_feeds = katze_array_new (KATZE_TYPE_ITEM); view->news_feeds = katze_array_new (KATZE_TYPE_ITEM);
view->item = NULL; view->item = NULL;
view->scrollh = view->scrollv = 0;
view->download_manager = NULL; view->download_manager = NULL;
view->news_aggregator = NULL; view->news_aggregator = NULL;
view->web_view = NULL; view->web_view = NULL;
/* Adjustments are not created automatically */ /* Adjustments are not created initially, but overwritten later */
g_object_set (view, "hadjustment", NULL, "vadjustment", NULL, NULL); g_object_set (view, "hadjustment", NULL, "vadjustment", NULL, NULL);
g_signal_connect (view, "notify::hadjustment",
G_CALLBACK (midori_view_notify_hadjustment_cb), view);
g_signal_connect (view, "notify::vadjustment",
G_CALLBACK (midori_view_notify_vadjustment_cb), view);
} }
static void static void
@ -2926,6 +2984,16 @@ midori_view_item_meta_data_changed (KatzeItem* item,
if (g_str_equal (key, "minimized")) if (g_str_equal (key, "minimized"))
g_object_set (view, "minimized", g_object_set (view, "minimized",
katze_item_get_meta_string (item, key) != NULL, NULL); katze_item_get_meta_string (item, key) != NULL, NULL);
else if (g_str_has_prefix (key, "scroll"))
{
gint value = katze_item_get_meta_integer (item, key);
if (!view->scrollh && key[6] == 'h')
view->scrollh = value > -1 ? value : 0;
else if (!view->scrollv && key[6] == 'v')
view->scrollv = value > -1 ? value : 0;
else
return;
}
} }
/** /**