[epiphany/wip/mcatanzaro/fedora-needs-upstreamed: 31/32] title-box: Don't flash the location entry between page loads



commit 2f52664e9ae8c2e4ec527764c9b42c8036192bc2
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Feb 6 16:51:10 2015 -0600

    title-box: Don't flash the location entry between page loads
    
    This fixes the distracting flicker when the title box switches from
    title mode to location entry mode when loading a page.
    
    Upstream status: Should probably be upstreamed as-is. But beware
    potential regressions
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741808

 src/ephy-title-box.c |   49 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/src/ephy-title-box.c b/src/ephy-title-box.c
index 2cc853a..da43c5e 100644
--- a/src/ephy-title-box.c
+++ b/src/ephy-title-box.c
@@ -71,6 +71,7 @@ typedef struct
   guint switch_to_entry_timeout_id;
 
   gulong title_sig_id;
+  gulong load_changed_sig_id;
 } EphyTitleBoxPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (EphyTitleBox, ephy_title_box, GTK_TYPE_STACK)
@@ -453,6 +454,25 @@ ephy_title_box_init (EphyTitleBox *title_box)
   LOG ("EphyTitleBox initialising %p", title_box);
 }
 
+/* The title box state is tricky to get right without visual glitches. We want
+ * to show title mode with a new title as soon as the the title becomes
+ * available, especially if the location entry is currently displayed. We want
+ * to show the location entry instead if the page has no title (e.g. because
+ * it's a text file). But the title is emptied at the start of each load, and
+ * then set sometime after the load has been committed. If we were previously
+ * displaying title mode, we don't want to flash the location entry during
+ * that brief period; we instead want to leave title mode stale until the
+ * new title is available. But if the page has no title, we don't want to get
+ * stuck on title mode, so we also connect to load-changed and switch to the
+ * location entry when the load has finished if no title is set. We also do not
+ * want to get stuck on the location entry when loading from the page cache,
+ * when the title is set before the load is committed. The user should not be
+ * switched from the location entry to title mode if the location entry is
+ * focused when the title change. When in title mode, the title should stay in
+ * sync with the URL at all times. If you try to change something, expect to
+ * break one of the above, so be careful.
+ */
+
 static void
 ephy_title_box_title_changed_cb (GObject    *gobject,
                                  GParamSpec *pspec,
@@ -467,13 +487,23 @@ ephy_title_box_title_changed_cb (GObject    *gobject,
 
   title = webkit_web_view_get_title (web_view);
 
-  if (gtk_widget_is_focus (priv->entry) ||
-      !title || *title == '\0') {
-    ephy_title_box_set_mode (title_box, EPHY_TITLE_BOX_MODE_LOCATION_ENTRY);
-    return;
-  }
+  if (!gtk_widget_is_focus (priv->entry) && title && *title != '\0')
+    ephy_title_box_set_mode (title_box, EPHY_TITLE_BOX_MODE_TITLE);
+}
+
+static void
+web_view_load_changed_cb (WebKitWebView *web_view,
+                          WebKitLoadEvent load_event,
+                          gpointer user_data)
+{
+  EphyTitleBox        *title_box = EPHY_TITLE_BOX (user_data);
+  EphyTitleBoxPrivate *priv = ephy_title_box_get_instance_private (title_box);
+  const char          *title = gtk_label_get_text (priv->title);
 
-  ephy_title_box_set_mode (title_box, EPHY_TITLE_BOX_MODE_TITLE);
+  LOG ("load-changed web_view %p title-box %p\n", web_view, title_box);
+
+  if (load_event == WEBKIT_LOAD_FINISHED && (!title || *title == '\0'))
+    ephy_title_box_set_mode (title_box, EPHY_TITLE_BOX_MODE_LOCATION_ENTRY);
 }
 
 /**
@@ -531,6 +561,9 @@ ephy_title_box_set_web_view (EphyTitleBox  *title_box,
     if (priv->title_sig_id > 0)
       g_signal_handler_disconnect (priv->web_view, priv->title_sig_id);
 
+    if (priv->load_changed_sig_id > 0)
+      g_signal_handler_disconnect (priv->web_view, priv->load_changed_sig_id);
+
     g_clear_object (&priv->title_binding);
 
     g_object_remove_weak_pointer (G_OBJECT (priv->web_view), (gpointer *)&priv->web_view);
@@ -555,6 +588,10 @@ ephy_title_box_set_web_view (EphyTitleBox  *title_box,
   priv->title_sig_id = g_signal_connect (priv->web_view, "notify::title",
                                          G_CALLBACK (ephy_title_box_title_changed_cb),
                                          title_box);
+  priv->load_changed_sig_id = g_signal_connect (priv->web_view, "load-changed",
+                                                G_CALLBACK (web_view_load_changed_cb),
+                                                title_box);
+
   g_signal_connect (priv->entry, "key-press-event",
                     G_CALLBACK (ephy_title_box_entry_key_press_cb), title_box);
   g_signal_connect (priv->web_view, "focus-in-event",


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