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

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

Issue 298703007: Refactor and move ash independent nested accelerator code to ui/wm/core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: skip test if platform does not support PES Created 6 years, 7 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
(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/accelerator_dispatcher.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 bool AcceleratorDispatcher::MenuClosedForPossibleAccelerator(
39 const ui::KeyEvent& key_event) {
40 if (!IsPossibleAcceleratorNotForMenu(key_event))
41 return false;
42
43 if (views::MenuController* menu_controller =
44 views::MenuController::GetActiveInstance()) {
45 menu_controller->CancelAll();
46 return true;
47 }
48 return false;
49 }
50
51 bool AcceleratorDispatcher::AcceleratorProcessedForKeyEvent(
52 const ui::KeyEvent& key_event) {
53 ash::AcceleratorController* accelerator_controller =
54 ash::Shell::GetInstance()->accelerator_controller();
55 if (!accelerator_controller)
56 return false;
57 const int kModifierMask =
58 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN);
59 ui::Accelerator accelerator(key_event.key_code(),
60 key_event.flags() & kModifierMask);
61 if (key_event.type() == ui::ET_KEY_RELEASED)
62 accelerator.set_type(ui::ET_KEY_RELEASED);
63 // Fill out context object so AcceleratorController will know what
64 // was the previous accelerator or if the current accelerator is repeated.
65 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext(
66 accelerator);
67 return accelerator_controller->Process(accelerator);
68 }
69
70 } // 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