diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2015-06-17 17:20:03 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2015-06-17 17:21:46 +0200 |
commit | 799305b2fb8bfbdcda1a72bbc1df0ca3d32afc5a (patch) | |
tree | 68e11987ed0c2ce28f44051b839833b94af31cee | |
parent | 583eccca3fc839a00270a8ab05d85ac9632775cf (diff) | |
download | yelp-carlosgc/webkit2-port.tar.gz |
Fix scroll position when navigating back/fordwardcarlosgc/webkit2-port
Use the WebKit back-forward list instead of a custom one.
-rw-r--r-- | libyelp/yelp-view.c | 95 |
1 files changed, 22 insertions, 73 deletions
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c index b6e8e3fa..d09eeffa 100644 --- a/libyelp/yelp-view.c +++ b/libyelp/yelp-view.c @@ -91,6 +91,7 @@ static void view_print_action (GAction *action static void view_history_action (GAction *action, GVariant *parameter, YelpView *view); +static void view_history_changed (YelpView *view); static void view_navigation_action (GAction *action, GVariant *parameter, YelpView *view); @@ -158,25 +159,6 @@ action_entry_free (YelpActionEntry *entry) g_free (entry); } -typedef struct _YelpBackEntry YelpBackEntry; -struct _YelpBackEntry { - YelpUri *uri; - gchar *title; - gchar *desc; - gdouble hadj; - gdouble vadj; -}; -static void -back_entry_free (YelpBackEntry *back) -{ - if (back == NULL) - return; - g_object_unref (back->uri); - g_free (back->title); - g_free (back->desc); - g_free (back); -} - typedef struct _RequestAsyncData RequestAsyncData; struct _RequestAsyncData { WebKitURISchemeRequest *request; @@ -227,10 +209,6 @@ struct _YelpViewPrivate { gchar *page_desc; gchar *page_icon; - GList *back_list; - GList *back_cur; - gboolean back_load; - GSimpleAction *print_action; GSimpleAction *back_action; GSimpleAction *forward_action; @@ -371,6 +349,11 @@ yelp_view_constructed (GObject *object) G_OBJECT_CLASS (yelp_view_parent_class)->constructed (object); + g_signal_connect_swapped (webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (view)), + "changed", + G_CALLBACK (view_history_changed), + view); + priv->fonts_changed = g_signal_connect (settings, "fonts-changed", G_CALLBACK (settings_set_fonts), @@ -426,12 +409,6 @@ yelp_view_dispose (GObject *object) priv->link_actions = g_slist_delete_link (priv->link_actions, priv->link_actions); } - priv->back_cur = NULL; - while (priv->back_list) { - back_entry_free ((YelpBackEntry *) priv->back_list->data); - priv->back_list = g_list_delete_link (priv->back_list, priv->back_list); - } - G_OBJECT_CLASS (yelp_view_parent_class)->dispose (object); } @@ -1579,6 +1556,7 @@ view_policy_decision_requested (YelpView *view, gpointer user_data) { YelpViewPrivate *priv = GET_PRIV (view); + WebKitNavigationAction *action; WebKitURIRequest *request; gchar *fixed_uri; YelpUri *uri; @@ -1591,7 +1569,11 @@ view_policy_decision_requested (YelpView *view, return FALSE; } - request = webkit_navigation_policy_decision_get_request (WEBKIT_NAVIGATION_POLICY_DECISION (decision)); + action = webkit_navigation_policy_decision_get_navigation_action (WEBKIT_NAVIGATION_POLICY_DECISION (decision)); + if (webkit_navigation_action_get_navigation_type (action) == WEBKIT_NAVIGATION_TYPE_BACK_FORWARD) + return FALSE; + + request = webkit_navigation_action_get_request (action); fixed_uri = build_yelp_uri (webkit_uri_request_get_uri (request)); webkit_policy_decision_ignore (decision); @@ -1617,7 +1599,6 @@ view_load_status_changed (WebKitWebView *view, switch (load_event) { case WEBKIT_LOAD_COMMITTED: { gchar *real_id; - YelpBackEntry *back = NULL; GParamSpec *spec; real_id = yelp_document_get_page_id (priv->document, priv->page_id); @@ -1642,15 +1623,6 @@ view_load_status_changed (WebKitWebView *view, priv->page_desc = yelp_document_get_page_desc (priv->document, priv->page_id); priv->page_icon = yelp_document_get_page_icon (priv->document, priv->page_id); - if (priv->back_cur) - back = priv->back_cur->data; - if (back) { - g_free (back->title); - back->title = g_strdup (priv->page_title); - g_free (back->desc); - back->desc = g_strdup (priv->page_desc); - } - spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), "root-title"); g_signal_emit_by_name (view, "notify::root-title", spec); @@ -1734,27 +1706,20 @@ view_history_action (GAction *action, GVariant *parameter, YelpView *view) { - GList *newcur; - YelpViewPrivate *priv = GET_PRIV (view); - - if (priv->back_cur == NULL) - return; - if (g_str_equal (g_action_get_name (action), "yelp-view-go-back")) - newcur = priv->back_cur->next; + webkit_web_view_go_back (WEBKIT_WEB_VIEW (view)); else - newcur = priv->back_cur->prev; - - if (newcur == NULL) - return; - - priv->back_cur = newcur; + webkit_web_view_go_forward (WEBKIT_WEB_VIEW (view)); +} - if (priv->back_cur->data == NULL) - return; +static void +view_history_changed (YelpView *view) +{ + YelpViewPrivate *priv = GET_PRIV (view); + WebKitWebView *web_view = WEBKIT_WEB_VIEW (view); - priv->back_load = TRUE; - yelp_view_load_uri (view, ((YelpBackEntry *) priv->back_cur->data)->uri); + g_simple_action_set_enabled (priv->back_action, webkit_web_view_can_go_back (web_view)); + g_simple_action_set_enabled (priv->forward_action, webkit_web_view_can_go_forward (web_view)); } static void @@ -2129,7 +2094,6 @@ uri_resolved (YelpUri *uri, YelpViewPrivate *priv = GET_PRIV (view); YelpUriDocumentType doctype; YelpDocument *document; - YelpBackEntry *back; GError *error = NULL; gchar *struri; GParamSpec *spec; @@ -2178,21 +2142,6 @@ uri_resolved (YelpUri *uri, g_free (struri); } - if (!priv->back_load) { - back = g_new0 (YelpBackEntry, 1); - back->uri = g_object_ref (uri); - while (priv->back_list != priv->back_cur) { - back_entry_free ((YelpBackEntry *) priv->back_list->data); - priv->back_list = g_list_delete_link (priv->back_list, priv->back_list); - } - priv->back_list = g_list_prepend (priv->back_list, back); - priv->back_cur = priv->back_list; - } - priv->back_load = FALSE; - - g_simple_action_set_enabled (priv->back_action, (priv->back_cur->next && priv->back_cur->next->data)); - g_simple_action_set_enabled (priv->forward_action, (priv->back_cur->prev && priv->back_cur->prev->data)); - spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), "yelp-uri"); g_signal_emit_by_name (view, "notify::yelp-uri", spec); |