Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: ash/accelerators/accelerator_dispatcher.cc

Issue 9958152: Consolidate win/x dispatchers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync, addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/accelerators/accelerator_dispatcher.h" 5 #include "ash/accelerators/accelerator_dispatcher.h"
6 6
7 #if defined(USE_X11)
8 #include <X11/Xlib.h>
9
10 // Xlib defines RootWindow
11 #ifdef RootWindow
12 #undef RootWindow
13 #endif
14 #endif // defined(USE_X11)
15
16 #include "ash/accelerators/accelerator_controller.h"
17 #include "ash/shell.h"
18 #include "ui/aura/env.h"
19 #include "ui/aura/event.h"
20 #include "ui/aura/root_window.h"
21 #include "ui/base/accelerators/accelerator.h"
22 #include "ui/base/events.h"
23
7 namespace ash { 24 namespace ash {
25 namespace {
26
27 const int kModifierMask = (ui::EF_SHIFT_DOWN |
28 ui::EF_CONTROL_DOWN |
29 ui::EF_ALT_DOWN);
30 #if defined(OS_WIN)
31 bool IsKeyEvent(const MSG& msg) {
32 return
33 msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN ||
34 msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP;
35 }
36 bool IsKeyRelease(const MSG& msg) {
37 return msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP;
38 }
39 #elif defined(USE_X11)
40 bool IsKeyEvent(const XEvent* xev) {
41 return xev->type == KeyPress || xev->type == KeyRelease;
42 }
43 bool IsKeyRelease(const XEvent* xev) {
44 return xev->type == KeyRelease;
45 }
46 #endif
47
48 } // namespace
8 49
9 AcceleratorDispatcher::AcceleratorDispatcher( 50 AcceleratorDispatcher::AcceleratorDispatcher(
10 MessageLoop::Dispatcher* nested_dispatcher, aura::Window* associated_window) 51 MessageLoop::Dispatcher* nested_dispatcher, aura::Window* associated_window)
11 : nested_dispatcher_(nested_dispatcher), 52 : nested_dispatcher_(nested_dispatcher),
12 associated_window_(associated_window) { 53 associated_window_(associated_window) {
13 DCHECK(nested_dispatcher_); 54 DCHECK(nested_dispatcher_);
14 associated_window_->AddObserver(this); 55 associated_window_->AddObserver(this);
15 } 56 }
16 57
17 AcceleratorDispatcher::~AcceleratorDispatcher() { 58 AcceleratorDispatcher::~AcceleratorDispatcher() {
18 if (associated_window_) 59 if (associated_window_)
19 associated_window_->RemoveObserver(this); 60 associated_window_->RemoveObserver(this);
20 } 61 }
21 62
22 void AcceleratorDispatcher::OnWindowDestroying(aura::Window* window) { 63 void AcceleratorDispatcher::OnWindowDestroying(aura::Window* window) {
23 if (associated_window_ == window) 64 if (associated_window_ == window)
24 associated_window_ = NULL; 65 associated_window_ = NULL;
25 } 66 }
26 67
68 bool AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) {
69 if (!associated_window_)
70 return false;
71 if (!ui::IsNoopEvent(event) && !associated_window_->CanReceiveEvents())
72 return aura::Env::GetInstance()->GetDispatcher()->Dispatch(event);
73
74 if (IsKeyEvent(event)) {
75 ash::AcceleratorController* accelerator_controller =
76 ash::Shell::GetInstance()->accelerator_controller();
77 if (accelerator_controller) {
78 ui::Accelerator accelerator(ui::KeyboardCodeFromNative(event),
79 ui::EventFlagsFromNative(event) & kModifierMask);
80 if (IsKeyRelease(event))
81 accelerator.set_type(ui::ET_KEY_RELEASED);
82 if (accelerator_controller->Process(accelerator))
83 return true;
84 accelerator.set_type(aura::TranslatedKeyEvent(event, false).type());
85 if (accelerator_controller->Process(accelerator))
86 return true;
87 }
88 }
89
90 return nested_dispatcher_->Dispatch(event);
91 }
92
27 } // namespace ash 93 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_dispatcher.h ('k') | ash/accelerators/accelerator_dispatcher_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698