Skip to content

Commit 0aa7016

Browse files
[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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@221833 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent dc75aeb commit 0aa7016

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

Tools/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2017-09-10 Michael Catanzaro <[email protected]>
2+
3+
[GTK] Improve Ctrl+W and Ctrl+Q shortcuts in MiniBrowser
4+
https://bugs.webkit.org/show_bug.cgi?id=176619
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
There are two different problems here. First, Ctrl+W is closing the entire window. That made
9+
sense when I implemented the shortcut a couple years ago, but now MiniBrowser supports tabs
10+
and it should really close only one single tab. Fix that.
11+
12+
Next, the keyboard shortcuts are not using webkit_web_view_try_close() and so are bypassing
13+
onbeforeunload handlers, which are respected when closing with the mouse. Fix that too.
14+
15+
* MiniBrowser/gtk/BrowserWindow.c:
16+
(browserWindowTryCloseCurrentWebView):
17+
(browserWindowTryClose):
18+
(browser_window_init):
19+
120
2017-09-07 Myles C. Maxfield <[email protected]>
221

322
Add "if" statements to WSL

Tools/MiniBrowser/gtk/BrowserWindow.c

+25-18
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,29 @@ static void browserWindowUpdateNavigationActions(BrowserWindow *window, WebKitBa
254254
g_list_free(list);
255255
}
256256

257+
static void browserWindowTryCloseCurrentWebView(BrowserWindow *window)
258+
{
259+
int currentPage = gtk_notebook_get_current_page(GTK_NOTEBOOK(window->notebook));
260+
BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), currentPage);
261+
webkit_web_view_try_close(browser_tab_get_web_view(tab));
262+
}
263+
264+
static void browserWindowTryClose(BrowserWindow *window)
265+
{
266+
GSList *webViews = NULL;
267+
int n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook));
268+
int i;
269+
270+
for (i = 0; i < n; ++i) {
271+
BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), i);
272+
webViews = g_slist_prepend(webViews, browser_tab_get_web_view(tab));
273+
}
274+
275+
GSList *link;
276+
for (link = webViews; link; link = link->next)
277+
webkit_web_view_try_close(link->data);
278+
}
279+
257280
static void backForwardlistChanged(WebKitBackForwardList *backForwardlist, WebKitBackForwardListItem *itemAdded, GList *itemsRemoved, BrowserWindow *window)
258281
{
259282
browserWindowUpdateNavigationActions(window, backForwardlist);
@@ -933,9 +956,9 @@ static void browser_window_init(BrowserWindow *window)
933956

934957
/* Quit */
935958
gtk_accel_group_connect(window->accelGroup, GDK_KEY_Q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
936-
g_cclosure_new_swap(G_CALLBACK(gtk_widget_destroy), window, NULL));
959+
g_cclosure_new_swap(G_CALLBACK(browserWindowTryClose), window, NULL));
937960
gtk_accel_group_connect(window->accelGroup, GDK_KEY_W, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
938-
g_cclosure_new_swap(G_CALLBACK(gtk_widget_destroy), window, NULL));
961+
g_cclosure_new_swap(G_CALLBACK(browserWindowTryCloseCurrentWebView), window, NULL));
939962

940963
/* Print */
941964
gtk_accel_group_connect(window->accelGroup, GDK_KEY_P, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
@@ -1045,22 +1068,6 @@ static void browserWindowSaveSession(BrowserWindow *window)
10451068
g_bytes_unref(bytes);
10461069
}
10471070

1048-
static void browserWindowTryClose(BrowserWindow *window)
1049-
{
1050-
GSList *webViews = NULL;
1051-
int n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook));
1052-
int i;
1053-
1054-
for (i = 0; i < n; ++i) {
1055-
BrowserTab *tab = (BrowserTab *)gtk_notebook_get_nth_page(GTK_NOTEBOOK(window->notebook), i);
1056-
webViews = g_slist_prepend(webViews, browser_tab_get_web_view(tab));
1057-
}
1058-
1059-
GSList *link;
1060-
for (link = webViews; link; link = link->next)
1061-
webkit_web_view_try_close(link->data);
1062-
}
1063-
10641071
static gboolean browserWindowDeleteEvent(GtkWidget *widget, GdkEventAny* event)
10651072
{
10661073
BrowserWindow *window = BROWSER_WINDOW(widget);

0 commit comments

Comments
 (0)