Skip to content
Permalink
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):


Canonical link: https://commits.webkit.org/193182@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221833 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Michael Catanzaro committed Sep 10, 2017
1 parent 86e4f28 commit 756b06d2cb1871fa5630720ace5c1fb0d2170e9b
Showing with 44 additions and 18 deletions.
  1. +19 −0 Tools/ChangeLog
  2. +25 −18 Tools/MiniBrowser/gtk/BrowserWindow.c
@@ -1,3 +1,22 @@
2017-09-10 Michael Catanzaro <mcatanzaro@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 <mmaxfield@apple.com>

Add "if" statements to WSL
@@ -254,6 +254,29 @@ static void browserWindowUpdateNavigationActions(BrowserWindow *window, WebKitBa
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 @@ static void browser_window_init(BrowserWindow *window)

/* 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 @@ static void browserWindowSaveSession(BrowserWindow *window)
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);

0 comments on commit 756b06d

Please sign in to comment.