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

Side by Side Diff: ui/views/controls/menu/menu_event_handler.cc

Issue 1138523006: Enable keyboard accelerators while a menu is open (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "ui/views/controls/menu/menu_event_handler.h"
6
7 #include "ui/aura/env.h"
8 #include "ui/events/keycodes/keyboard_code_conversion.h"
9 #include "ui/views/controls/menu/menu_controller.h"
10 #include "ui/views/views_delegate.h"
11
12 namespace views {
13
14 namespace {
15
16 const int kKeyFlagsMask = ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN;
17
18 } // namespace
19
20 MenuEventHandler::MenuEventHandler() {
21 aura::Env::GetInstanceDontCreate()->PrependPreTargetHandler(this);
22 }
23
24 MenuEventHandler::~MenuEventHandler() {
25 aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler(this);
26 }
27
28 void MenuEventHandler::OnKeyEvent(ui::KeyEvent* event) {
29 MenuController* menu_controller = MenuController::GetActiveInstance();
30 if (!menu_controller)
sky 2015/09/09 00:01:59 Can this really happen? DCHECK?
afakhry 2015/09/09 02:31:34 DCHECK()ed
31 return;
32
33 if (menu_controller->exit_type() == MenuController::EXIT_ALL ||
34 menu_controller->exit_type() == MenuController::EXIT_DESTROYED) {
35 // If the event has arrived after the menu's exit type had changed but
36 // before its message loop terminated, the event will continue its normal
37 // propagation for the following reason:
38 // If the user accepts a menu item in a nested menu, the menu item action is
39 // run after the base::RunLoop for the innermost menu has quit but before
40 // the base::RunLoop for the outermost menu has quit. If the menu item
41 // action starts a base::RunLoop, the outermost menu's base::RunLoop will
42 // not quit till the action's base::RunLoop ends. IDC_BOOKMARK_BAR_OPEN_ALL
43 // sometimes opens a modal dialog. The modal dialog starts a base::RunLoop
44 // and keeps the base::RunLoop running for the duration of its lifetime.
45 menu_controller->TerminateNestedMessageLoop();
46 return;
47 } else {
48 if (event->type() == ui::ET_KEY_PRESSED) {
49 menu_controller->OnKeyDown(event->key_code());
50
51 // Below we'll handle the mnemonics only if neither Alt nor Ctrl is
52 // pressed.
53 const int flags = event->flags();
54 if (menu_controller->exit_type() == MenuController::EXIT_NONE &&
55 (flags & kKeyFlagsMask) == 0) {
oshima 2015/09/08 23:51:59 You can look into this in a follow up CL, but I th
56 char c = ui::DomCodeToUsLayoutCharacter(event->code(), flags);
57 menu_controller->SelectByChar(c);
58 }
59 }
60 }
61
62 ViewsDelegate::GetInstance()->HandleKeyEventOnMenu(event);
63
64 if (menu_controller->exit_type() != MenuController::EXIT_NONE)
65 menu_controller->TerminateNestedMessageLoop();
66
67 event->StopPropagation();
68 }
69
70 void MenuEventHandler::OnTouchEvent(ui::TouchEvent* event) {
71 if (event->type() == ui::ET_TOUCH_RELEASED ||
72 event->type() == ui::ET_TOUCH_CANCELLED) {
73 // Don't allow the event copy to clear the native touch id
74 // mapping, or we'll lose the mapping before the initial event
75 // has finished being dispatched.
76 event->set_should_remove_native_touch_id_mapping(false);
77 }
78 }
79
80 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698