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

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

Issue 279073002: views: Terminate the nested message-loop correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
« no previous file with comments | « ui/views/controls/menu/menu_event_dispatcher_linux.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
24 DCHECK(menu_controller_->IsBlockingRun()); 24 DCHECK(menu_controller_->IsBlockingRun());
25 25
26 bool should_quit = false;
27 bool should_perform_default = true;
26 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || 28 if (menu_controller_->exit_type() == MenuController::EXIT_ALL ||
27 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) 29 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) {
28 return (POST_DISPATCH_QUIT_LOOP | POST_DISPATCH_PERFORM_DEFAULT); 30 should_quit = true;
31 } else {
32 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here.
33 switch (msg.message) {
34 case WM_CONTEXTMENU: {
35 MenuItemView* item = menu_controller_->pending_state_.item;
36 if (item && item->GetRootMenuItem() != item) {
37 gfx::Point screen_loc(0, item->height());
38 View::ConvertPointToScreen(item, &screen_loc);
39 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE;
40 if (GET_X_LPARAM(msg.lParam) == -1 && GET_Y_LPARAM(msg.lParam) == -1)
41 source_type = ui::MENU_SOURCE_KEYBOARD;
42 item->GetDelegate()->ShowContextMenu(
43 item, item->GetCommand(), screen_loc, source_type);
44 }
45 should_quit = false;
46 should_perform_default = false;
47 break;
48 }
29 49
30 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. 50 // NOTE: focus wasn't changed when the menu was shown. As such, don't
31 switch (msg.message) { 51 // dispatch key events otherwise the focused window will get the events.
32 case WM_CONTEXTMENU: { 52 case WM_KEYDOWN: {
33 MenuItemView* item = menu_controller_->pending_state_.item; 53 bool result =
34 if (item && item->GetRootMenuItem() != item) { 54 menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(msg));
35 gfx::Point screen_loc(0, item->height()); 55 TranslateMessage(&msg);
36 View::ConvertPointToScreen(item, &screen_loc); 56 should_perform_default = false;
37 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; 57 should_quit = !result;
38 if (GET_X_LPARAM(msg.lParam) == -1 && GET_Y_LPARAM(msg.lParam) == -1) 58 break;
39 source_type = ui::MENU_SOURCE_KEYBOARD;
40 item->GetDelegate()->ShowContextMenu(
41 item, item->GetCommand(), screen_loc, source_type);
42 } 59 }
43 return POST_DISPATCH_NONE; 60 case WM_CHAR: {
61 should_quit = menu_controller_->SelectByChar(
62 static_cast<base::char16>(msg.wParam));
63 should_perform_default = false;
64 break;
65 }
66 case WM_KEYUP:
67 case WM_SYSKEYUP:
68 // 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
70 // close the menu.
71 should_quit = false;
72 should_perform_default = false;
73 break;
74
75 case WM_CANCELMODE:
76 case WM_SYSKEYDOWN:
77 // Exit immediately on system keys.
78 menu_controller_->Cancel(MenuController::EXIT_ALL);
79 should_quit = true;
80 should_perform_default = false;
81 break;
82
83 default:
84 break;
44 } 85 }
86 }
45 87
46 // NOTE: focus wasn't changed when the menu was shown. As such, don't 88 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE)
47 // dispatch key events otherwise the focused window will get the events. 89 menu_controller_->TerminateNestedMessageLoop();
48 case WM_KEYDOWN: { 90 return should_perform_default ? POST_DISPATCH_PERFORM_DEFAULT
49 bool result = 91 : POST_DISPATCH_NONE;
50 menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(msg));
51 TranslateMessage(&msg);
52 return result ? POST_DISPATCH_NONE : POST_DISPATCH_QUIT_LOOP;
53 }
54 case WM_CHAR: {
55 bool should_exit =
56 menu_controller_->SelectByChar(static_cast<base::char16>(msg.wParam));
57 return should_exit ? POST_DISPATCH_QUIT_LOOP : POST_DISPATCH_NONE;
58 }
59 case WM_KEYUP:
60 return POST_DISPATCH_NONE;
61
62 case WM_SYSKEYUP:
63 // We may have been shown on a system key, as such don't do anything
64 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and
65 // close the menu.
66 return POST_DISPATCH_NONE;
67
68 case WM_CANCELMODE:
69 case WM_SYSKEYDOWN:
70 // Exit immediately on system keys.
71 menu_controller_->Cancel(MenuController::EXIT_ALL);
72 return POST_DISPATCH_QUIT_LOOP;
73
74 default:
75 break;
76 }
77 return POST_DISPATCH_PERFORM_DEFAULT |
78 (menu_controller_->exit_type() == MenuController::EXIT_NONE
79 ? POST_DISPATCH_NONE
80 : POST_DISPATCH_QUIT_LOOP);
81 } 92 }
82 93
83 } // namespace internal 94 } // namespace internal
84 } // namespace views 95 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_event_dispatcher_linux.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698