diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 19:37:55 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 19:37:55 +0000 |
commit | bc9e271112139a38fb81c38f00809a8a6d496542 (patch) | |
tree | 0eb67d503958b2cd91107fc4435189b3df656841 /chrome/browser/gtk | |
parent | b475c0507c663dfbd8d711f11f8394a3c6910f75 (diff) | |
download | chromium_src-bc9e271112139a38fb81c38f00809a8a6d496542.zip chromium_src-bc9e271112139a38fb81c38f00809a8a6d496542.tar.gz chromium_src-bc9e271112139a38fb81c38f00809a8a6d496542.tar.bz2 |
GTK: Handle some accelerators after the focused widget has had a chance to handle the keypress.
Also, don't try to give the browser commands that are disabled.
----
(this description may need to be re-written)
BUG=11526
Review URL: http://codereview.chromium.org/113050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 27 |
2 files changed, 16 insertions, 15 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index fbedb38..3a02d7f 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -112,9 +112,7 @@ void BrowserToolbarGtk::Init(Profile* profile, IDR_BACK_D, l10n_util::GetStringUTF8(IDS_TOOLTIP_BACK))); AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); - // TODO(estade): I ran into some problems with backspace in the find bar when - // I enabled this accelerator. Figure it out and re-enable the shortcut. - // AddAcceleratorToButton(back_, GDK_BackSpace, 0); + AddAcceleratorToButton(back_, GDK_BackSpace, 0); forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, IDR_FORWARD_H, IDR_FORWARD_D, l10n_util::GetStringUTF8(IDS_TOOLTIP_FORWARD))); diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index be98e95..b7a56e5 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -197,24 +197,26 @@ gboolean HandleCustomAccelerator(guint keyval, GdkModifierType modifier, return FALSE; } -// Usually accelerators are checked before propagating the key event, but if the -// focus is on the render area we want to reverse the order of things to allow -// webkit to handle key events like ctrl-l. +// Let the focused widget have first crack at the key event so we don't +// override their accelerators. gboolean OnKeyPress(GtkWindow* window, GdkEventKey* event, Browser* browser) { + // If a widget besides the native view is focused, we have to try to handle + // the custom accelerators before letting it handle them. TabContents* current_tab_contents = browser->tabstrip_model()->GetSelectedTabContents(); - // If there is no current tab contents or its view is gone (if the renderview - // crashed) or it is not focused then let the default GtkWindow key handler - // run. + // The current tab might not have a render view if it crashed. if (!current_tab_contents || !current_tab_contents->GetContentNativeView() || !gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) { - return HandleCustomAccelerator(event->keyval, - static_cast<GdkModifierType>(event->state), browser); + gboolean handled = HandleCustomAccelerator(event->keyval, + GdkModifierType(event->state), browser); + if (handled) + return TRUE; } - // If the content area is focused, let it handle the key event. - gboolean result = gtk_window_propagate_key_event(window, event); - DCHECK(result); + if (!gtk_window_propagate_key_event(window, event)) { + static_cast<BrowserWindowGtk*>(browser->window())->HandleAccelerator( + event->keyval, GdkModifierType(event->state)); + } return TRUE; } @@ -760,5 +762,6 @@ gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, } void BrowserWindowGtk::ExecuteBrowserCommand(int id) { - browser_->ExecuteCommand(id); + if (browser_->command_updater()->IsCommandEnabled(id)) + browser_->ExecuteCommand(id); } |