OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/accelerators/accelerator_dispatcher.h" | |
6 | |
7 #include <X11/Xlib.h> | |
8 | |
9 // Xlib defines RootWindow | |
10 #ifdef RootWindow | |
11 #undef RootWindow | |
12 #endif | |
13 | |
14 #include "ash/accelerators/accelerator_controller.h" | |
15 #include "ash/shell.h" | |
16 #include "ui/aura/env.h" | |
17 #include "ui/aura/event.h" | |
18 #include "ui/aura/root_window.h" | |
19 #include "ui/base/accelerators/accelerator.h" | |
20 #include "ui/base/events.h" | |
21 | |
22 namespace ash { | |
23 | |
24 namespace { | |
25 | |
26 const int kModifierMask = (ui::EF_SHIFT_DOWN | | |
27 ui::EF_CONTROL_DOWN | | |
28 ui::EF_ALT_DOWN); | |
29 } // namespace | |
30 | |
31 base::MessagePumpDispatcher::DispatchStatus AcceleratorDispatcher::Dispatch( | |
32 XEvent* xev) { | |
33 // TODO(oshima): Consolidate win and linux. http://crbug.com/116282 | |
34 if (!associated_window_) | |
35 return EVENT_QUIT; | |
36 if (!ui::IsNoopEvent(xev) && !associated_window_->CanReceiveEvents()) | |
37 return aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev); | |
38 | |
39 if (xev->type == KeyPress || xev->type == KeyRelease) { | |
40 ash::AcceleratorController* accelerator_controller = | |
41 ash::Shell::GetInstance()->accelerator_controller(); | |
42 if (accelerator_controller) { | |
43 ui::Accelerator accelerator(ui::KeyboardCodeFromNative(xev), | |
44 ui::EventFlagsFromNative(xev) & kModifierMask); | |
45 if (xev->type == KeyRelease) | |
46 accelerator.set_type(ui::ET_KEY_RELEASED); | |
47 if (accelerator_controller->Process(accelerator)) | |
48 return EVENT_PROCESSED; | |
49 | |
50 accelerator.set_type(aura::TranslatedKeyEvent(xev, false).type()); | |
51 if (accelerator_controller->Process(accelerator)) | |
52 return EVENT_PROCESSED; | |
53 } | |
54 } | |
55 return nested_dispatcher_->Dispatch(xev); | |
56 } | |
57 | |
58 } // namespace ash | |
OLD | NEW |