[epiphany] ephy-embed: show a message popup when entering fullscreen mode



commit 88198c2707d57b346bf6fcbb028dfd9aac4e0fae
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Mon Jun 11 13:10:26 2012 +0300

    ephy-embed: show a message popup when entering fullscreen mode
    
    The message is different depending on whether we are entering HTML5 fullscreen
    mode or application fullscreen, since the keys used to leave either mode are
    different.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671195

 embed/ephy-embed.c         |   89 ++++++++++++++++++++++++++++++++++++++++++++
 embed/ephy-embed.h         |    3 +
 src/ephy-window.c          |    2 +
 src/resources/epiphany.css |    7 +++
 4 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 3a8d531..46366b4 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -68,6 +68,8 @@ struct _EphyEmbedPrivate
   GSList *destroy_on_transition_list;
   GtkWidget *floating_bar;
   GtkWidget *progress;
+  GtkWidget *fullscreen_message_label;
+  char *fullscreen_string;
 
   GSList *messages;
   GSList *keys;
@@ -78,6 +80,8 @@ struct _EphyEmbedPrivate
   guint tab_message_id;
   guint pop_statusbar_later_source_id;
 
+  guint fullscreen_message_id;
+
   guint clear_progress_source_id;
 
   gulong status_handler_id;
@@ -280,6 +284,38 @@ ephy_embed_grab_focus (GtkWidget *widget)
     gtk_widget_grab_focus (child);
 }
 
+
+static gboolean
+fullscreen_message_label_hide (EphyEmbed *embed)
+{
+  if (embed->priv->fullscreen_message_id) {
+    gtk_widget_hide (embed->priv->fullscreen_message_label);
+    g_source_remove (embed->priv->fullscreen_message_id);
+    embed->priv->fullscreen_message_id = 0;
+  }
+
+  return FALSE;
+}
+
+void
+ephy_embed_entering_fullscreen (EphyEmbed *embed)
+{
+  gtk_widget_show (embed->priv->fullscreen_message_label);
+
+  if (embed->priv->fullscreen_message_id)
+    g_source_remove (embed->priv->fullscreen_message_id);
+
+  embed->priv->fullscreen_message_id = g_timeout_add_seconds (5,
+                                                              (GSourceFunc)fullscreen_message_label_hide,
+                                                              embed);
+}
+
+void
+ephy_embed_leaving_fullscreen (EphyEmbed *embed)
+{
+  fullscreen_message_label_hide (embed);
+}
+
 static void
 ephy_embed_dispose (GObject *object)
 {
@@ -325,6 +361,11 @@ ephy_embed_dispose (GObject *object)
     priv->progress_update_handler_id = 0;
   }
 
+  if (priv->fullscreen_message_id) {
+    g_source_remove (priv->fullscreen_message_id);
+    priv->fullscreen_message_id = 0;
+  }
+
   G_OBJECT_CLASS (ephy_embed_parent_class)->dispose (object);
 }
 
@@ -359,6 +400,8 @@ ephy_embed_finalize (GObject *object)
   g_slist_free (priv->keys);
   priv->keys = NULL;
 
+  g_free (embed->priv->fullscreen_string);
+
   G_OBJECT_CLASS (ephy_embed_parent_class)->finalize (object);
 }
 
@@ -497,6 +540,40 @@ download_requested_cb (WebKitWebView *web_view,
   return TRUE;
 }
 
+static void
+ephy_embed_set_fullscreen_message (EphyEmbed *embed,
+                                   gboolean is_html5_fullscreen)
+{
+  char *message;
+
+  if (G_UNLIKELY (embed->priv->fullscreen_string == NULL))
+    embed->priv->fullscreen_string = g_strdup (_("Press %s to exit fullscreen"));
+
+  /* Translators: 'ESC' and 'F11' are keyboard keys. */
+  message = g_strdup_printf (embed->priv->fullscreen_string, is_html5_fullscreen ? _("ESC") : _("F11"));
+  gtk_label_set_text (GTK_LABEL (embed->priv->fullscreen_message_label),
+                      message);
+  g_free (message);
+}
+
+static gboolean
+entering_fullscreen_cb (WebKitWebView *web_view,
+                        GObject *element,
+                        EphyEmbed *embed)
+{
+  ephy_embed_set_fullscreen_message (embed, TRUE);
+  return FALSE;
+}
+
+static gboolean
+leaving_fullscreen_cb (WebKitWebView *web_view,
+                       GObject *element,
+                       EphyEmbed *embed)
+{
+  ephy_embed_set_fullscreen_message (embed, FALSE);
+  return FALSE;
+}
+
 static gboolean
 pop_statusbar_later_cb (gpointer data)
 {
@@ -621,11 +698,21 @@ ephy_embed_constructed (GObject *object)
   overlay = gtk_overlay_new ();
   gtk_style_context_add_class (gtk_widget_get_style_context (overlay),
                                GTK_STYLE_CLASS_OSD);
+
   gtk_widget_add_events (overlay, 
                          GDK_ENTER_NOTIFY_MASK |
                          GDK_LEAVE_NOTIFY_MASK);
   gtk_container_add (GTK_CONTAINER (overlay), scrolled_window);
 
+  /* Floating message popup for fullscreen mode. */
+  priv->fullscreen_message_label = gtk_label_new (NULL);
+  gtk_widget_set_name (priv->fullscreen_message_label, "fullscreen-popup");
+  gtk_widget_set_halign (priv->fullscreen_message_label, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (priv->fullscreen_message_label, GTK_ALIGN_CENTER);
+  gtk_widget_set_no_show_all (priv->fullscreen_message_label, TRUE);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), priv->fullscreen_message_label);
+  ephy_embed_set_fullscreen_message (embed, FALSE);
+
   /* statusbar is hidden by default */
   priv->floating_bar = nautilus_floating_bar_new (NULL, FALSE);
   gtk_widget_set_halign (priv->floating_bar, GTK_ALIGN_START);
@@ -663,6 +750,8 @@ ephy_embed_constructed (GObject *object)
                     "signal::notify::load-status", G_CALLBACK (load_status_changed_cb), embed,
                     "signal::resource-request-starting", G_CALLBACK (resource_request_starting_cb), embed,
                     "signal::download-requested", G_CALLBACK (download_requested_cb), embed,
+                    "signal::entering-fullscreen", G_CALLBACK (entering_fullscreen_cb), embed,
+                    "signal::leaving-fullscreen", G_CALLBACK (leaving_fullscreen_cb), embed,
                     NULL);
 
   priv->status_handler_id = g_signal_connect (web_view, "notify::status-message",
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 9e6b373..91fc06e 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -59,6 +59,9 @@ void         ephy_embed_remove_top_widget        (EphyEmbed  *embed,
                                                   GtkWidget  *widget);
 void         ephy_embed_auto_download_url        (EphyEmbed  *embed,
                                                   const char *url);
+void         ephy_embed_entering_fullscreen      (EphyEmbed *embed);
+void         ephy_embed_leaving_fullscreen       (EphyEmbed *embed);
+
 G_END_DECLS
 
 #endif
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 3a19b63..3bbdab6 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -818,6 +818,7 @@ ephy_window_fullscreen (EphyWindow *window)
 	sync_tab_security (ephy_embed_get_web_view (embed), NULL, window);
 
 	sync_chromes_visibility (window);
+	ephy_embed_entering_fullscreen (embed);
 }
 
 static void
@@ -827,6 +828,7 @@ ephy_window_unfullscreen (EphyWindow *window)
 	window->priv->chrome = window->priv->pre_fullscreen_chrome;
 
 	sync_chromes_visibility (window);
+	ephy_embed_leaving_fullscreen (window->priv->active_embed);
 }
 
 static gboolean 
diff --git a/src/resources/epiphany.css b/src/resources/epiphany.css
index 546eeb9..113856f 100644
--- a/src/resources/epiphany.css
+++ b/src/resources/epiphany.css
@@ -18,3 +18,10 @@
     padding-left: 0;
     padding-right: 0;
 }
+
+#fullscreen-popup {
+    background-color: alpha (black, 0.7);
+    color: white;
+    padding: 12px;
+    border-radius: 10px;
+}



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