[GTK][WK2] MiniBrowser fullscreen signals support
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2013 14:11:18 +0000 (14:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2013 14:11:18 +0000 (14:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108005

Patch by Manuel Rego Casasnovas <rego@igalia.com> on 2013-02-01
Reviewed by Carlos Garcia Campos.

Shows a label for 2 seconds using overlay (if GTK >= 3.2.0) and hides
the toolbar when entering fullscreen. When leaving fullscreen the
label is hidden (if it's not hidden yet) and the toolbar is shown again.

* MiniBrowser/gtk/BrowserWindow.c:
(_BrowserWindow):
(fullScreenMessageTimeoutCallback):
(webViewEnterFullScreen):
(webViewLeaveFullScreen):
(browserWindowFinalize):
(browserWindowConstructed):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141585 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/MiniBrowser/gtk/BrowserWindow.c

index 67eb6dd..5460f6f 100644 (file)
@@ -1,3 +1,22 @@
+2013-02-01  Manuel Rego Casasnovas  <rego@igalia.com>
+
+        [GTK][WK2] MiniBrowser fullscreen signals support
+        https://bugs.webkit.org/show_bug.cgi?id=108005
+
+        Reviewed by Carlos Garcia Campos.
+
+        Shows a label for 2 seconds using overlay (if GTK >= 3.2.0) and hides
+        the toolbar when entering fullscreen. When leaving fullscreen the
+        label is hidden (if it's not hidden yet) and the toolbar is shown again.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (_BrowserWindow):
+        (fullScreenMessageTimeoutCallback):
+        (webViewEnterFullScreen):
+        (webViewLeaveFullScreen):
+        (browserWindowFinalize):
+        (browserWindowConstructed):
+
 2013-02-01  Alexis Menard  <alexis@webkit.org>
 
         Enable unprefixed CSS transitions by default.
index 86b0446..a5b0cd3 100644 (file)
@@ -52,6 +52,10 @@ struct _BrowserWindow {
     WebKitWebView *webView;
     GtkWidget *downloadsBar;
     GdkPixbuf *favicon;
+#if GTK_CHECK_VERSION(3, 2, 0)
+    GtkWidget *fullScreenMessageLabel;
+    guint fullScreenMessageLabelId;
+#endif
 };
 
 struct _BrowserWindowClass {
@@ -261,6 +265,50 @@ static void webViewReadyToShow(WebKitWebView *webView, BrowserWindow *window)
     gtk_widget_show(GTK_WIDGET(window));
 }
 
+#if GTK_CHECK_VERSION(3, 2, 0)
+static gboolean fullScreenMessageTimeoutCallback(BrowserWindow *window)
+{
+    gtk_widget_hide(window->fullScreenMessageLabel);
+    window->fullScreenMessageLabelId = 0;
+    return FALSE;
+}
+#endif
+
+static gboolean webViewEnterFullScreen(WebKitWebView *webView, BrowserWindow *window)
+{
+#if GTK_CHECK_VERSION(3, 2, 0)
+    const gchar *titleOrURI = webkit_web_view_get_title(window->webView);
+    if (!titleOrURI)
+        titleOrURI = webkit_web_view_get_uri(window->webView);
+    gchar *message = g_strdup_printf("%s is now full screen. Press ESC or f to exit.", titleOrURI);
+    gtk_label_set_text(GTK_LABEL(window->fullScreenMessageLabel), message);
+    g_free(message);
+
+    gtk_widget_show(window->fullScreenMessageLabel);
+
+    window->fullScreenMessageLabelId = g_timeout_add_seconds(2, (GSourceFunc)fullScreenMessageTimeoutCallback, window);
+#endif
+
+    gtk_widget_hide(window->toolbar);
+
+    return FALSE;
+}
+
+static gboolean webViewLeaveFullScreen(WebKitWebView *webView, BrowserWindow *window)
+{
+#if GTK_CHECK_VERSION(3, 2, 0)
+    if (window->fullScreenMessageLabelId) {
+        g_source_remove(window->fullScreenMessageLabelId);
+        window->fullScreenMessageLabelId = 0;
+    }
+    gtk_widget_hide(window->fullScreenMessageLabel);
+#endif
+
+    gtk_widget_show(window->toolbar);
+
+    return FALSE;
+}
+
 static GtkWidget *webViewCreate(WebKitWebView *webView, BrowserWindow *window)
 {
     WebKitWebView *newWebView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(webkit_web_view_get_context(webView)));
@@ -396,6 +444,11 @@ static void browserWindowFinalize(GObject *gObject)
         window->favicon = NULL;
     }
 
+#if GTK_CHECK_VERSION(3, 2, 0)
+    if (window->fullScreenMessageLabelId)
+        g_source_remove(window->fullScreenMessageLabelId);
+#endif
+
     G_OBJECT_CLASS(browser_window_parent_class)->finalize(gObject);
 
     if (g_atomic_int_dec_and_test(&windowCount))
@@ -513,6 +566,8 @@ static void browserWindowConstructed(GObject *gObject)
     g_signal_connect(window->webView, "mouse-target-changed", G_CALLBACK(webViewMouseTargetChanged), window);
     g_signal_connect(window->webView, "notify::zoom-level", G_CALLBACK(webViewZoomLevelChanged), window);
     g_signal_connect(window->webView, "notify::favicon", G_CALLBACK(faviconChanged), window);
+    g_signal_connect(window->webView, "enter-fullscreen", G_CALLBACK(webViewEnterFullScreen), window);
+    g_signal_connect(window->webView, "leave-fullscreen", G_CALLBACK(webViewLeaveFullScreen), window);
 
     g_signal_connect(webkit_web_view_get_context(window->webView), "download-started", G_CALLBACK(downloadStarted), window);
 
@@ -534,6 +589,12 @@ static void browserWindowConstructed(GObject *gObject)
     gtk_overlay_add_overlay(GTK_OVERLAY(overlay), window->statusLabel);
 
     gtk_container_add(GTK_CONTAINER(overlay), GTK_WIDGET(window->webView));
+
+    window->fullScreenMessageLabel = gtk_label_new(NULL);
+    gtk_widget_set_halign(window->fullScreenMessageLabel, GTK_ALIGN_CENTER);
+    gtk_widget_set_valign(window->fullScreenMessageLabel, GTK_ALIGN_CENTER);
+    gtk_widget_set_no_show_all(window->fullScreenMessageLabel, TRUE);
+    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), window->fullScreenMessageLabel);
 #else
     gtk_box_pack_start(GTK_BOX(window->mainBox), GTK_WIDGET(window->webView), TRUE, TRUE, 0);
 #endif