summaryrefslogtreecommitdiffstats
path: root/ash/accelerators/accelerator_dispatcher.cc
diff options
context:
space:
mode:
authorsschmitz@chromium.org <sschmitz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 01:16:55 +0000
committersschmitz@chromium.org <sschmitz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 01:16:55 +0000
commit530020443649534f6fd19563c6326cf44f0b3be5 (patch)
tree5980621a8dfa6e58c05168cd4733d4a0a03dca4f /ash/accelerators/accelerator_dispatcher.cc
parenta540e60eaaa7866abf0901b873ec6814d9cc81a9 (diff)
downloadchromium_src-530020443649534f6fd19563c6326cf44f0b3be5.zip
chromium_src-530020443649534f6fd19563c6326cf44f0b3be5.tar.gz
chromium_src-530020443649534f6fd19563c6326cf44f0b3be5.tar.bz2
Fixes the problem that many shortcuts change the current tab without closing the current context menu. In addition shortcuts execute within the current message loop (created for the context menu). This could conceivably cause nested message loops which is undesirable.
Fix: Shortcuts generated by Ctrl/Alt plus either a letter, number of the tab key, will now close the currently open context menu and its message loop *before* they are processed. BUG=168910 TEST=manual 1. Bring up any context menu 2. Press Ctrl t (or 1-9, tab) for tab navigation 3. Observe that the context menu is closed first. Review URL: https://chromiumcodereview.appspot.com/11881034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/accelerators/accelerator_dispatcher.cc')
-rw-r--r--ash/accelerators/accelerator_dispatcher.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/ash/accelerators/accelerator_dispatcher.cc b/ash/accelerators/accelerator_dispatcher.cc
index 41a292f..f8456d5 100644
--- a/ash/accelerators/accelerator_dispatcher.cc
+++ b/ash/accelerators/accelerator_dispatcher.cc
@@ -22,6 +22,7 @@
#include "ui/base/events/event.h"
#include "ui/base/events/event_constants.h"
#include "ui/base/events/event_utils.h"
+#include "ui/views/controls/menu/menu_controller.h"
namespace ash {
namespace {
@@ -41,6 +42,23 @@ bool IsKeyEvent(const XEvent* xev) {
}
#endif
+bool IsPossibleAcceleratorNotForMenu(const ui::KeyEvent& key_event) {
+ // For shortcuts generated by Ctrl or Alt plus a letter, number or
+ // the tab key, we want to exit the context menu first and then
+ // repost the event. That allows for the shortcut execution after
+ // the context menu has exited.
+ if (key_event.type() == ui::ET_KEY_PRESSED &&
+ key_event.flags() & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) {
+ const ui::KeyboardCode key_code = key_event.key_code();
+ if ((key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z) ||
+ (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9) ||
+ (key_code == ui::VKEY_TAB)) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
AcceleratorDispatcher::AcceleratorDispatcher(
@@ -77,6 +95,20 @@ bool AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) {
event_rewriter->OnKeyEvent(&key_event);
if (key_event.stopped_propagation())
return true;
+
+ if (IsPossibleAcceleratorNotForMenu(key_event)) {
+ if (views::MenuController* menu_controller =
+ views::MenuController::GetActiveInstance()) {
+ menu_controller->CancelAll();
+#if defined(USE_X11)
+ XPutBackEvent(event->xany.display, event);
+#else
+ NOTIMPLEMENTED() << " Repost NativeEvent here.";
+#endif
+ return false;
+ }
+ }
+
ash::AcceleratorController* accelerator_controller =
ash::Shell::GetInstance()->accelerator_controller();
if (accelerator_controller) {