OLD | NEW |
| (Empty) |
1 // Copyright 2014 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/nested_accelerator_delegate.h" | |
6 | |
7 #include "ash/accelerators/accelerator_controller.h" | |
8 #include "ash/shell.h" | |
9 #include "ui/aura/window_event_dispatcher.h" | |
10 #include "ui/base/accelerators/accelerator.h" | |
11 #include "ui/events/event.h" | |
12 #include "ui/events/event_constants.h" | |
13 #include "ui/events/event_utils.h" | |
14 #include "ui/views/controls/menu/menu_controller.h" | |
15 | |
16 namespace ash { | |
17 namespace { | |
18 | |
19 bool IsPossibleAcceleratorNotForMenu(const ui::KeyEvent& key_event) { | |
20 // For shortcuts generated by Ctrl or Alt plus a letter, number or | |
21 // the tab key, we want to exit the context menu first and then | |
22 // repost the event. That allows for the shortcut execution after | |
23 // the context menu has exited. | |
24 if (key_event.type() == ui::ET_KEY_PRESSED && | |
25 (key_event.flags() & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))) { | |
26 const ui::KeyboardCode key_code = key_event.key_code(); | |
27 if ((key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z) || | |
28 (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9) || | |
29 (key_code == ui::VKEY_TAB)) { | |
30 return true; | |
31 } | |
32 } | |
33 return false; | |
34 } | |
35 | |
36 } // namespace | |
37 | |
38 NestedAcceleratorDelegate::NestedAcceleratorDelegate() { | |
39 LOG(ERROR) << "NAD"; | |
40 } | |
41 | |
42 NestedAcceleratorDelegate::~NestedAcceleratorDelegate() { | |
43 LOG(ERROR) << "~NAD"; | |
44 } | |
45 | |
46 bool NestedAcceleratorDelegate::ShouldProcessEventNow( | |
47 const ui::KeyEvent& key_event) { | |
48 if (!IsPossibleAcceleratorNotForMenu(key_event)) | |
49 return true; | |
50 | |
51 if (views::MenuController* menu_controller = | |
52 views::MenuController::GetActiveInstance()) { | |
53 menu_controller->CancelAll(); | |
54 return false; | |
55 } | |
56 return true; | |
57 } | |
58 | |
59 bool NestedAcceleratorDelegate::ProcessEvent(const ui::KeyEvent& key_event) { | |
60 ash::AcceleratorController* accelerator_controller = | |
61 ash::Shell::GetInstance()->accelerator_controller(); | |
62 if (!accelerator_controller) | |
63 return false; | |
64 const int kModifierMask = | |
65 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); | |
66 ui::Accelerator accelerator(key_event.key_code(), | |
67 key_event.flags() & kModifierMask); | |
68 if (key_event.type() == ui::ET_KEY_RELEASED) | |
69 accelerator.set_type(ui::ET_KEY_RELEASED); | |
70 // Fill out context object so AcceleratorController will know what | |
71 // was the previous accelerator or if the current accelerator is repeated. | |
72 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext( | |
73 accelerator); | |
74 return accelerator_controller->Process(accelerator); | |
75 } | |
76 | |
77 } // namespace ash | |
OLD | NEW |