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

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

Issue 301243012: Merge 269819 "views: Terminate the nested message-loop correctly..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1985/src/
Patch Set: Created 6 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 | Annotate | Revision Log
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_event_dispatcher_linux.h" 5 #include "ui/views/controls/menu/menu_event_dispatcher_linux.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
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/widget/widget.h" 13 #include "ui/views/widget/widget.h"
14 14
15 namespace views { 15 namespace views {
16 namespace internal { 16 namespace internal {
17 17
18 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) 18 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller)
19 : menu_controller_(controller) {} 19 : menu_controller_(controller) {}
20 20
21 MenuEventDispatcher::~MenuEventDispatcher() {} 21 MenuEventDispatcher::~MenuEventDispatcher() {}
22 22
23 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { 23 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) {
24 return true; 24 return true;
25 } 25 }
26 26
27 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { 27 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) {
28 bool should_quit = false;
29 bool should_perform_default = true;
28 bool should_process_event = true; 30 bool should_process_event = true;
29 31
30 // Check if the event should be handled. 32 // Check if the event should be handled.
31 scoped_ptr<ui::Event> ui_event(ui::EventFromNative(event)); 33 scoped_ptr<ui::Event> ui_event(ui::EventFromNative(event));
32 if (ui_event && menu_controller_->owner()) { 34 if (ui_event && menu_controller_->owner()) {
33 aura::Window* menu_window = menu_controller_->owner()->GetNativeWindow(); 35 aura::Window* menu_window = menu_controller_->owner()->GetNativeWindow();
34 aura::Window* target_window = static_cast<aura::Window*>( 36 aura::Window* target_window = static_cast<aura::Window*>(
35 static_cast<ui::EventTarget*>(menu_window->GetRootWindow())-> 37 static_cast<ui::EventTarget*>(menu_window->GetRootWindow())->
36 GetEventTargeter()->FindTargetForEvent(menu_window, 38 GetEventTargeter()->FindTargetForEvent(menu_window,
37 ui_event.get())); 39 ui_event.get()));
38 // TODO(flackr): The event shouldn't be handled if target_window is not 40 // TODO(flackr): The event shouldn't be handled if target_window is not
39 // menu_window, however the event targeter does not properly target the 41 // menu_window, however the event targeter does not properly target the
40 // open menu. For now, we allow targeters to prevent handling by the menu. 42 // open menu. For now, we allow targeters to prevent handling by the menu.
41 if (!target_window) 43 if (!target_window)
42 should_process_event = false; 44 should_process_event = false;
43 } 45 }
44 46
45 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || 47 if (menu_controller_->exit_type() == MenuController::EXIT_ALL ||
46 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) 48 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) {
47 return (ui::POST_DISPATCH_QUIT_LOOP | ui::POST_DISPATCH_PERFORM_DEFAULT); 49 should_quit = true;
48 50 } else if (should_process_event) {
49 if (should_process_event) {
50 switch (ui::EventTypeFromNative(event)) { 51 switch (ui::EventTypeFromNative(event)) {
51 case ui::ET_KEY_PRESSED: { 52 case ui::ET_KEY_PRESSED: {
52 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) 53 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) {
53 return ui::POST_DISPATCH_QUIT_LOOP; 54 should_quit = true;
55 should_perform_default = false;
56 break;
57 }
54 58
55 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. 59 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed.
56 int flags = ui::EventFlagsFromNative(event); 60 int flags = ui::EventFlagsFromNative(event);
57 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) { 61 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) {
58 char c = ui::GetCharacterFromKeyCode( 62 char c = ui::GetCharacterFromKeyCode(
59 ui::KeyboardCodeFromNative(event), flags); 63 ui::KeyboardCodeFromNative(event), flags);
60 if (menu_controller_->SelectByChar(c)) 64 if (menu_controller_->SelectByChar(c)) {
61 return ui::POST_DISPATCH_QUIT_LOOP; 65 should_quit = true;
66 should_perform_default = false;
67 break;
68 }
62 } 69 }
63 return ui::POST_DISPATCH_NONE; 70 should_quit = false;
71 should_perform_default = false;
72 break;
64 } 73 }
65 case ui::ET_KEY_RELEASED: 74 case ui::ET_KEY_RELEASED:
66 return ui::POST_DISPATCH_NONE; 75 should_quit = false;
76 should_perform_default = false;
77 break;
67 default: 78 default:
68 break; 79 break;
69 } 80 }
70 } 81 }
71 82
72 return ui::POST_DISPATCH_PERFORM_DEFAULT | 83 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE)
73 (menu_controller_->exit_type() == MenuController::EXIT_NONE 84 menu_controller_->TerminateNestedMessageLoop();
74 ? ui::POST_DISPATCH_NONE 85
75 : ui::POST_DISPATCH_QUIT_LOOP); 86 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT
87 : ui::POST_DISPATCH_NONE;
76 } 88 }
77 89
78 } // namespace internal 90 } // namespace internal
79 } // namespace views 91 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller_unittest.cc ('k') | ui/views/controls/menu/menu_message_pump_dispatcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698