Skip to content

Commit

Permalink
Merge r221833 - [GTK] Improve Ctrl+W and Ctrl+Q shortcuts in MiniBrowser
Browse files Browse the repository at this point in the history
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):
  • Loading branch information
mcatanzaro authored and carlosgcampos committed Oct 16, 2017
1 parent 7259da3 commit 089002b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Tools/ChangeLog
@@ -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-09 Michael Catanzaro <mcatanzaro@igalia.com>

[GTK] Unreviewed, fix typo forwad -> forward
Expand Down
43 changes: 25 additions & 18 deletions Tools/MiniBrowser/gtk/BrowserWindow.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 089002b

Please sign in to comment.