Index: ash/accelerators/accelerator_dispatcher.cc |
diff --git a/ash/accelerators/accelerator_dispatcher.cc b/ash/accelerators/accelerator_dispatcher.cc |
index 47dde9c4a6ceb726895d4032ad99ac558093e88f..e8c7fb2235adbaac2c96b36bb0d9e40ca1d00ceb 100644 |
--- a/ash/accelerators/accelerator_dispatcher.cc |
+++ b/ash/accelerators/accelerator_dispatcher.cc |
@@ -4,7 +4,48 @@ |
#include "ash/accelerators/accelerator_dispatcher.h" |
+#if defined(USE_X11) |
+#include <X11/Xlib.h> |
+ |
+// Xlib defines RootWindow |
+#ifdef RootWindow |
+#undef RootWindow |
+#endif |
+#endif // defined(USE_X11) |
+ |
+#include "ash/accelerators/accelerator_controller.h" |
+#include "ash/shell.h" |
+#include "ui/aura/env.h" |
+#include "ui/aura/event.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/base/accelerators/accelerator.h" |
+#include "ui/base/events.h" |
+ |
namespace ash { |
+namespace { |
+ |
+const int kModifierMask = (ui::EF_SHIFT_DOWN | |
+ ui::EF_CONTROL_DOWN | |
+ ui::EF_ALT_DOWN); |
+#if defined(OS_WIN) |
+bool IsKeyEvent(const MSG& msg) { |
+ return |
+ msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || |
+ msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP; |
+} |
+bool IsKeyRelease(const MSG& msg) { |
+ return msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP; |
+} |
+#elif defined(USE_X11) |
+bool IsKeyEvent(const XEvent* xev) { |
+ return xev->type == KeyPress || xev->type == KeyRelease; |
+} |
+bool IsKeyRelease(const XEvent* xev) { |
+ return xev->type == KeyRelease; |
+} |
+#endif |
+ |
+} // namespace |
AcceleratorDispatcher::AcceleratorDispatcher( |
MessageLoop::Dispatcher* nested_dispatcher, aura::Window* associated_window) |
@@ -24,4 +65,29 @@ void AcceleratorDispatcher::OnWindowDestroying(aura::Window* window) { |
associated_window_ = NULL; |
} |
+bool AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) { |
+ if (!associated_window_) |
+ return false; |
+ if (!ui::IsNoopEvent(event) && !associated_window_->CanReceiveEvents()) |
+ return aura::Env::GetInstance()->GetDispatcher()->Dispatch(event); |
+ |
+ if (IsKeyEvent(event)) { |
+ ash::AcceleratorController* accelerator_controller = |
+ ash::Shell::GetInstance()->accelerator_controller(); |
+ if (accelerator_controller) { |
+ ui::Accelerator accelerator(ui::KeyboardCodeFromNative(event), |
+ ui::EventFlagsFromNative(event) & kModifierMask); |
+ if (IsKeyRelease(event)) |
+ accelerator.set_type(ui::ET_KEY_RELEASED); |
+ if (accelerator_controller->Process(accelerator)) |
+ return true; |
+ accelerator.set_type(aura::TranslatedKeyEvent(event, false).type()); |
+ if (accelerator_controller->Process(accelerator)) |
+ return true; |
+ } |
+ } |
+ |
+ return nested_dispatcher_->Dispatch(event); |
+} |
+ |
} // namespace ash |