| 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/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 } | |
| 40 | |
| 41 NestedAcceleratorDelegate::~NestedAcceleratorDelegate() { | |
| 42 } | |
| 43 | |
| 44 bool NestedAcceleratorDelegate::ShouldProcessEventNow( | |
| 45 const ui::KeyEvent& key_event) { | |
| 46 if (!IsPossibleAcceleratorNotForMenu(key_event)) | |
| 47 return true; | |
| 48 | |
| 49 if (views::MenuController* menu_controller = | |
| 50 views::MenuController::GetActiveInstance()) { | |
| 51 menu_controller->CancelAll(); | |
| 52 return false; | |
| 53 } | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 bool NestedAcceleratorDelegate::ProcessEvent(const ui::KeyEvent& key_event) { | |
| 58 ash::AcceleratorController* accelerator_controller = | |
| 59 ash::Shell::GetInstance()->accelerator_controller(); | |
| 60 if (!accelerator_controller) | |
| 61 return false; | |
| 62 const int kModifierMask = | |
| 63 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); | |
| 64 ui::Accelerator accelerator(key_event.key_code(), | |
| 65 key_event.flags() & kModifierMask); | |
| 66 if (key_event.type() == ui::ET_KEY_RELEASED) | |
| 67 accelerator.set_type(ui::ET_KEY_RELEASED); | |
| 68 // Fill out context object so AcceleratorController will know what | |
| 69 // was the previous accelerator or if the current accelerator is repeated. | |
| 70 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext( | |
| 71 accelerator); | |
| 72 return accelerator_controller->Process(accelerator); | |
| 73 } | |
| 74 | |
| 75 } // namespace ash | |
| OLD | NEW |