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

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: sky's 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 DCHECK(menu_controller);
31
32 if (menu_controller->exit_type() == MenuController::EXIT_ALL ||
33 menu_controller->exit_type() == MenuController::EXIT_DESTROYED) {
34 // If the event has arrived after the menu's exit type had changed but
35 // before its message loop terminated, the event will continue its normal
36 // propagation for the following reason:
37 // If the user accepts a menu item in a nested menu, the menu item action is
38 // run after the base::RunLoop for the innermost menu has quit but before
39 // the base::RunLoop for the outermost menu has quit. If the menu item
40 // action starts a base::RunLoop, the outermost menu's base::RunLoop will
41 // not quit till the action's base::RunLoop ends. IDC_BOOKMARK_BAR_OPEN_ALL
42 // sometimes opens a modal dialog. The modal dialog starts a base::RunLoop
43 // and keeps the base::RunLoop running for the duration of its lifetime.
44 menu_controller->TerminateNestedMessageLoop();
45 return;
46 } else {
sky 2015/09/09 15:44:52 Style guide says no else after return.
afakhry 2015/09/09 20:21:33 Done.
47 if (event->type() == ui::ET_KEY_PRESSED) {
48 menu_controller->OnKeyDown(event->key_code());
49
50 // Below we'll handle the mnemonics only if neither Alt nor Ctrl is
sky 2015/09/09 15:44:52 This comment is documenting the code and doesn't t
afakhry 2015/09/09 20:21:33 The why here is not so clear to me. I think it was
51 // pressed.
52 const int flags = event->flags();
53 if (menu_controller->exit_type() == MenuController::EXIT_NONE &&
54 (flags & kKeyFlagsMask) == 0) {
55 char c = ui::DomCodeToUsLayoutCharacter(event->code(), flags);
56 menu_controller->SelectByChar(c);
57 }
58 }
59 }
60
61 ViewsDelegate::GetInstance()->HandleKeyEventOnMenu(event);
62
63 if (menu_controller->exit_type() != MenuController::EXIT_NONE)
64 menu_controller->TerminateNestedMessageLoop();
65
66 event->StopPropagation();
67 }
68
69 void MenuEventHandler::OnTouchEvent(ui::TouchEvent* event) {
70 if (event->type() == ui::ET_TOUCH_RELEASED ||
71 event->type() == ui::ET_TOUCH_CANCELLED) {
72 // Don't allow the event copy to clear the native touch id
73 // mapping, or we'll lose the mapping before the initial event
74 // has finished being dispatched.
75 event->set_should_remove_native_touch_id_mapping(false);
76 }
77 }
78
79 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698