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

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

Issue 1138523006: Enable keyboard accelerators while a menu is open (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling oshima's comments Created 5 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" 5 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h"
6 6
7 #include <windowsx.h> 7 #include <windowsx.h>
8 8
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/keyboard_code_conversion.h" 10 #include "ui/events/keycodes/keyboard_code_conversion.h"
11 #include "ui/events/keycodes/keyboard_codes.h" 11 #include "ui/events/keycodes/keyboard_codes.h"
12 #include "ui/views/controls/menu/menu_controller.h" 12 #include "ui/views/controls/menu/menu_controller.h"
13 #include "ui/views/controls/menu/menu_item_view.h" 13 #include "ui/views/controls/menu/menu_item_view.h"
14 14
15 namespace views { 15 namespace views {
16 namespace internal { 16 namespace internal {
17 17
18 MenuMessagePumpDispatcher::MenuMessagePumpDispatcher(MenuController* controller) 18 MenuMessagePumpDispatcher::MenuMessagePumpDispatcher(MenuController* controller)
19 : menu_controller_(controller) {} 19 : menu_controller_(controller) {}
20 20
21 MenuMessagePumpDispatcher::~MenuMessagePumpDispatcher() {} 21 MenuMessagePumpDispatcher::~MenuMessagePumpDispatcher() {}
22 22
23 uint32_t MenuMessagePumpDispatcher::Dispatch(const MSG& msg) { 23 uint32_t MenuMessagePumpDispatcher::Dispatch(const MSG& msg) {
pkotwicz 2015/06/16 16:04:59 It would be nice if MenuEventFilter handled as man
afakhry 2015/06/16 23:56:39 That would be my preference too but we can't do th
pkotwicz 2015/06/17 14:26:24 I was unaware of the special handling for WM_CHAR.
afakhry 2015/06/17 18:48:00 If you want to see the negative effect I was talki
pkotwicz 2015/06/18 19:45:57 I tried it again. I get the same behavior that you
pkotwicz 2015/07/10 17:33:21 Have you addressed this comment?
afakhry 2015/07/10 23:49:46 Yes, I spent the whole day yesterday testing on Wi
pkotwicz 2015/07/13 23:29:17 Thank you for pointing me to the bug and for the e
afakhry 2015/07/14 20:50:43 I will try to investigate this later on Windows. I
pkotwicz 2015/07/15 00:37:14 The hacky solution does not work. The "é" key does
24 DCHECK(menu_controller_->IsBlockingRun()); 24 DCHECK(menu_controller_->IsBlockingRun());
25 25
26 bool should_quit = false; 26 bool should_quit = false;
27 bool should_perform_default = true; 27 bool should_perform_default = true;
28 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || 28 if (menu_controller_->exit_type() == MenuController::EXIT_ALL ||
29 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) { 29 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) {
30 should_quit = true; 30 should_quit = true;
31 } else { 31 } else {
32 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. 32 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here.
33 switch (msg.message) { 33 switch (msg.message) {
34 case WM_CONTEXTMENU: { 34 case WM_CONTEXTMENU: {
35 MenuItemView* item = menu_controller_->pending_state_.item; 35 MenuItemView* item = menu_controller_->pending_state_.item;
36 if (item && item->GetRootMenuItem() != item) { 36 if (item && item->GetRootMenuItem() != item) {
37 gfx::Point screen_loc(0, item->height()); 37 gfx::Point screen_loc(0, item->height());
38 View::ConvertPointToScreen(item, &screen_loc); 38 View::ConvertPointToScreen(item, &screen_loc);
39 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; 39 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE;
40 if (GET_X_LPARAM(msg.lParam) == -1 && GET_Y_LPARAM(msg.lParam) == -1) 40 if (GET_X_LPARAM(msg.lParam) == -1 && GET_Y_LPARAM(msg.lParam) == -1)
41 source_type = ui::MENU_SOURCE_KEYBOARD; 41 source_type = ui::MENU_SOURCE_KEYBOARD;
42 item->GetDelegate()->ShowContextMenu( 42 item->GetDelegate()->ShowContextMenu(
43 item, item->GetCommand(), screen_loc, source_type); 43 item, item->GetCommand(), screen_loc, source_type);
44 } 44 }
45 should_quit = false; 45 should_quit = false;
46 should_perform_default = false; 46 should_perform_default = false;
47 break; 47 break;
48 } 48 }
49 49
50 // NOTE: focus wasn't changed when the menu was shown. As such, don't
51 // dispatch key events otherwise the focused window will get the events.
52 case WM_KEYDOWN: { 50 case WM_KEYDOWN: {
53 bool result = 51 // We do nothing here as the key event will be processed by
54 menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(msg)); 52 // MenuEventFilter::OnKeyEvent() as a result of the following dispatch
55 TranslateMessage(&msg); 53 // call. The MenuEventFilter will stop the event propagation, so the
54 // focused window will not get the event.
55 //
56 // NOTE: We don't call TranslateMessage() here as we don't want to
57 // produce a WM_CHAR which will result in inserting a character in a
58 // Textfield while the menu is still open or has just exited.
59 // MenuEventFilter::OnKeyEvent() takes care of everything.
60 DispatchMessage(&msg);
56 should_perform_default = false; 61 should_perform_default = false;
57 should_quit = !result;
58 break; 62 break;
59 } 63 }
60 case WM_CHAR: { 64 case WM_CHAR: {
61 should_quit = menu_controller_->SelectByChar( 65 // We do nothing here. Selecting a menu item by Char is done at the
62 static_cast<base::char16>(msg.wParam)); 66 // MenuEventFilter::OnKeyEvent().
63 should_perform_default = false; 67 should_perform_default = false;
64 break; 68 break;
65 } 69 }
66 case WM_KEYUP: 70 case WM_KEYUP:
67 case WM_SYSKEYUP: 71 case WM_SYSKEYUP:
68 // We may have been shown on a system key, as such don't do anything 72 // We may have been shown on a system key, as such don't do anything
69 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and 73 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and
70 // close the menu. 74 // close the menu.
71 should_quit = false; 75 should_quit = false;
72 should_perform_default = false; 76 should_perform_default = false;
(...skipping 13 matching lines...) Expand all
86 } 90 }
87 91
88 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE) 92 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE)
89 menu_controller_->TerminateNestedMessageLoop(); 93 menu_controller_->TerminateNestedMessageLoop();
90 return should_perform_default ? POST_DISPATCH_PERFORM_DEFAULT 94 return should_perform_default ? POST_DISPATCH_PERFORM_DEFAULT
91 : POST_DISPATCH_NONE; 95 : POST_DISPATCH_NONE;
92 } 96 }
93 97
94 } // namespace internal 98 } // namespace internal
95 } // namespace views 99 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698