Title: [221833] trunk/Tools
Revision
221833
Author
mcatanz...@igalia.com
Date
2017-09-10 02:54:31 -0700 (Sun, 10 Sep 2017)

Log Message

[GTK] Improve Ctrl+W and Ctrl+Q shortcuts in MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=176619

Reviewed by Carlos Garcia Campos.

There are two different problems here. First, Ctrl+W is closing the entire window. That made
sense when I implemented the shortcut a couple years ago, but now MiniBrowser supports tabs
and it should really close only one single tab. Fix that.

Next, the keyboard shortcuts are not using webkit_web_view_try_close() and so are bypassing
onbeforeunload handlers, which are respected when closing with the mouse. Fix that too.

* MiniBrowser/gtk/BrowserWindow.c:
(browserWindowTryCloseCurrentWebView):
(browserWindowTryClose):
(browser_window_init):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (221832 => 221833)


--- trunk/Tools/ChangeLog	2017-09-10 00:21:55 UTC (rev 221832)
+++ trunk/Tools/ChangeLog	2017-09-10 09:54:31 UTC (rev 221833)
@@ -1,3 +1,22 @@
+2017-09-10  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        [GTK] Improve Ctrl+W and Ctrl+Q shortcuts in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=176619
+
+        Reviewed by Carlos Garcia Campos.
+
+        There are two different problems here. First, Ctrl+W is closing the entire window. That made
+        sense when I implemented the shortcut a couple years ago, but now MiniBrowser supports tabs
+        and it should really close only one single tab. Fix that.
+
+        Next, the keyboard shortcuts are not using webkit_web_view_try_close() and so are bypassing
+        onbeforeunload handlers, which are respected when closing with the mouse. Fix that too.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (browserWindowTryCloseCurrentWebView):
+        (browserWindowTryClose):
+        (browser_window_init):
+
 2017-09-07  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Add "if" statements to WSL

Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (221832 => 221833)


--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2017-09-10 00:21:55 UTC (rev 221832)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2017-09-10 09:54:31 UTC (rev 221833)
@@ -254,6 +254,29 @@
     g_list_free(list);
 }
 
+static void browserWindowTryCloseCurrentWebView(BrowserWindow *window)
+{
+    int currentPage = gtk_notebook_get_current_page(GTK_NOTEBOOK(window->notebook));
+    BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), currentPage);
+    webkit_web_view_try_close(browser_tab_get_web_view(tab));
+}
+
+static void browserWindowTryClose(BrowserWindow *window)
+{
+    GSList *webViews = NULL;
+    int n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook));
+    int i;
+
+    for (i = 0; i < n; ++i) {
+        BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), i);
+        webViews = g_slist_prepend(webViews, browser_tab_get_web_view(tab));
+    }
+
+    GSList *link;
+    for (link = webViews; link; link = link->next)
+        webkit_web_view_try_close(link->data);
+}
+
 static void backForwardlistChanged(WebKitBackForwardList *backForwardlist, WebKitBackForwardListItem *itemAdded, GList *itemsRemoved, BrowserWindow *window)
 {
     browserWindowUpdateNavigationActions(window, backForwardlist);
@@ -933,9 +956,9 @@
 
     /* Quit */
     gtk_accel_group_connect(window->accelGroup, GDK_KEY_Q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
-        g_cclosure_new_swap(G_CALLBACK(gtk_widget_destroy), window, NULL));
+        g_cclosure_new_swap(G_CALLBACK(browserWindowTryClose), window, NULL));
     gtk_accel_group_connect(window->accelGroup, GDK_KEY_W, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
-        g_cclosure_new_swap(G_CALLBACK(gtk_widget_destroy), window, NULL));
+        g_cclosure_new_swap(G_CALLBACK(browserWindowTryCloseCurrentWebView), window, NULL));
 
     /* Print */
     gtk_accel_group_connect(window->accelGroup, GDK_KEY_P, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
@@ -1045,22 +1068,6 @@
     g_bytes_unref(bytes);
 }
 
-static void browserWindowTryClose(BrowserWindow *window)
-{
-    GSList *webViews = NULL;
-    int n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook));
-    int i;
-
-    for (i = 0; i < n; ++i) {
-        BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), i);
-        webViews = g_slist_prepend(webViews, browser_tab_get_web_view(tab));
-    }
-
-    GSList *link;
-    for (link = webViews; link; link = link->next)
-        webkit_web_view_try_close(link->data);
-}
-
 static gboolean browserWindowDeleteEvent(GtkWidget *widget, GdkEventAny* event)
 {
     BrowserWindow *window = BROWSER_WINDOW(widget);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to