diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-09 19:50:06 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-09 19:50:06 +0000 |
commit | 046460d54e5397286cba1b3ce9462b4129b2aaab (patch) | |
tree | 79b0e31f0a28b01ae9b1dfd12dad5be6fa3368b4 /ash/accelerators | |
parent | c90ec6552b57ec596c35a4c44082ad518857a393 (diff) | |
download | chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.zip chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.tar.gz chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.tar.bz2 |
Consolidate win/x dispatchers
BUG=116282
TEST=no functional change. All tests should pass.
Review URL: http://codereview.chromium.org/9958152
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/accelerators')
-rw-r--r-- | ash/accelerators/accelerator_dispatcher.cc | 66 | ||||
-rw-r--r-- | ash/accelerators/accelerator_dispatcher.h | 8 | ||||
-rw-r--r-- | ash/accelerators/accelerator_dispatcher_linux.cc | 58 | ||||
-rw-r--r-- | ash/accelerators/accelerator_dispatcher_win.cc | 51 | ||||
-rw-r--r-- | ash/accelerators/nested_dispatcher_controller_unittest.cc | 19 |
5 files changed, 74 insertions, 128 deletions
diff --git a/ash/accelerators/accelerator_dispatcher.cc b/ash/accelerators/accelerator_dispatcher.cc index 47dde9c..e8c7fb2 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 diff --git a/ash/accelerators/accelerator_dispatcher.h b/ash/accelerators/accelerator_dispatcher.h index 1d5d75c..fcc69f0 100644 --- a/ash/accelerators/accelerator_dispatcher.h +++ b/ash/accelerators/accelerator_dispatcher.h @@ -26,12 +26,8 @@ class ASH_EXPORT AcceleratorDispatcher : public MessageLoop::Dispatcher, aura::Window* associated_window); virtual ~AcceleratorDispatcher(); -#if defined(USE_X11) - virtual base::MessagePumpDispatcher::DispatchStatus Dispatch( - XEvent* xev) OVERRIDE; -#elif defined(OS_WIN) - bool AcceleratorDispatcher::Dispatch(const MSG& msg) OVERRIDE; -#endif + // MessageLoop::Dispatcher overrides: + virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; // aura::WindowObserver overrides: virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; diff --git a/ash/accelerators/accelerator_dispatcher_linux.cc b/ash/accelerators/accelerator_dispatcher_linux.cc deleted file mode 100644 index 3167f75..0000000 --- a/ash/accelerators/accelerator_dispatcher_linux.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/accelerators/accelerator_dispatcher.h" - -#include <X11/Xlib.h> - -// Xlib defines RootWindow -#ifdef RootWindow -#undef RootWindow -#endif - -#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); -} // namespace - -base::MessagePumpDispatcher::DispatchStatus AcceleratorDispatcher::Dispatch( - XEvent* xev) { - // TODO(oshima): Consolidate win and linux. http://crbug.com/116282 - if (!associated_window_) - return EVENT_QUIT; - if (!ui::IsNoopEvent(xev) && !associated_window_->CanReceiveEvents()) - return aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev); - - if (xev->type == KeyPress || xev->type == KeyRelease) { - ash::AcceleratorController* accelerator_controller = - ash::Shell::GetInstance()->accelerator_controller(); - if (accelerator_controller) { - ui::Accelerator accelerator(ui::KeyboardCodeFromNative(xev), - ui::EventFlagsFromNative(xev) & kModifierMask); - if (xev->type == KeyRelease) - accelerator.set_type(ui::ET_KEY_RELEASED); - if (accelerator_controller->Process(accelerator)) - return EVENT_PROCESSED; - - accelerator.set_type(aura::TranslatedKeyEvent(xev, false).type()); - if (accelerator_controller->Process(accelerator)) - return EVENT_PROCESSED; - } - } - return nested_dispatcher_->Dispatch(xev); -} - -} // namespace ash diff --git a/ash/accelerators/accelerator_dispatcher_win.cc b/ash/accelerators/accelerator_dispatcher_win.cc deleted file mode 100644 index f5d2c10..0000000 --- a/ash/accelerators/accelerator_dispatcher_win.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/accelerators/accelerator_dispatcher.h" - -#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); -} // namespace - -bool AcceleratorDispatcher::Dispatch(const MSG& msg) { - // TODO(oshima): Consolidate win and linux. http://crbug.com/116282 - if (!associated_window_) - return false; - if (!ui::IsNoopEvent(msg) && !associated_window_->CanReceiveEvents()) - return aura::Env::GetInstance()->GetDispatcher()->Dispatch(msg); - - if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || - msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP) { - ash::AcceleratorController* accelerator_controller = - ash::Shell::GetInstance()->accelerator_controller(); - if (accelerator_controller) { - ui::Accelerator accelerator(ui::KeyboardCodeFromNative(msg), - ui::EventFlagsFromNative(msg) & kModifierMask); - if (msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP) - accelerator.set_type(ui::ET_KEY_RELEASED); - if (accelerator_controller->Process(accelerator)) - return true; - accelerator.set_type(aura::TranslatedKeyEvent(msg, false).type()); - if (accelerator_controller->Process(accelerator)) - return true; - } - } - - return nested_dispatcher_->Dispatch(msg); -} - -} // namespace ash diff --git a/ash/accelerators/nested_dispatcher_controller_unittest.cc b/ash/accelerators/nested_dispatcher_controller_unittest.cc index 905b353..18c24e0 100644 --- a/ash/accelerators/nested_dispatcher_controller_unittest.cc +++ b/ash/accelerators/nested_dispatcher_controller_unittest.cc @@ -15,6 +15,7 @@ #include "ui/aura/test/test_windows.h" #include "ui/aura/window.h" #include "ui/base/accelerators/accelerator.h" +#include "ui/base/events.h" #if defined(USE_X11) #include <X11/Xlib.h> @@ -33,21 +34,13 @@ class MockDispatcher : public MessageLoop::Dispatcher { int num_key_events_dispatched() { return num_key_events_dispatched_; } -#if defined(OS_WIN) - virtual bool Dispatch(const MSG& msg) OVERRIDE { - if (msg.message == WM_KEYUP) +#if defined(OS_WIN) || defined(USE_X11) + virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { + if (ui::EventTypeFromNative(event) == ui::ET_KEY_RELEASED) num_key_events_dispatched_++; - return !ui::IsNoopEvent(msg); + return !ui::IsNoopEvent(event); } -#elif defined(USE_X11) - virtual base::MessagePumpDispatcher::DispatchStatus Dispatch( - XEvent* xev) OVERRIDE { - if (xev->type == KeyRelease) - num_key_events_dispatched_++; - return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT : - MessagePumpDispatcher::EVENT_IGNORED; - } -#endif +#endif // defined(OS_WIN) || defined(USE_X11) private: int num_key_events_dispatched_; |