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

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

Issue 809773006: MacViews: Intercept events for Menus (after AppKit has interpreted keystrokes) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20141205-MacViews-AcceleratedWidget-PLUS-AddingLayers-fromcl-PLUS-bringup
Patch Set: rollback card unmask Created 6 years 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_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"
11 #include "ui/events/keycodes/keyboard_codes.h"
12 #include "ui/views/controls/menu/menu_controller.h" 10 #include "ui/views/controls/menu/menu_controller.h"
13 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
14 12
15 namespace views { 13 namespace views {
16 namespace internal { 14 namespace internal {
17 15
18 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) 16 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller)
19 : menu_controller_(controller) {} 17 : menu_controller_(controller) {}
20 18
21 MenuEventDispatcher::~MenuEventDispatcher() {} 19 MenuEventDispatcher::~MenuEventDispatcher() {}
22 20
23 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { 21 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) {
24 return true; 22 return true;
25 } 23 }
26 24
27 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { 25 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) {
28 bool should_quit = false;
29 bool should_perform_default = true;
30 bool should_process_event = true;
31
32 // Check if the event should be handled. 26 // Check if the event should be handled.
33 scoped_ptr<ui::Event> ui_event(ui::EventFromNative(event)); 27 scoped_ptr<ui::Event> ui_event(ui::EventFromNative(event));
28 aura::Window* target_window = nullptr;
34 if (ui_event && menu_controller_->owner()) { 29 if (ui_event && menu_controller_->owner()) {
35 aura::Window* menu_window = menu_controller_->owner()->GetNativeWindow(); 30 aura::Window* menu_window = menu_controller_->owner()->GetNativeWindow();
36 aura::Window* target_window = static_cast<aura::Window*>( 31 target_window = static_cast<aura::Window*>(
37 static_cast<ui::EventTarget*>(menu_window->GetRootWindow())-> 32 static_cast<ui::EventTarget*>(menu_window->GetRootWindow())
38 GetEventTargeter()->FindTargetForEvent(menu_window, 33 ->GetEventTargeter()
39 ui_event.get())); 34 ->FindTargetForEvent(menu_window, ui_event.get()));
40 // TODO(flackr): The event shouldn't be handled if target_window is not
41 // menu_window, however the event targeter does not properly target the
42 // open menu. For now, we allow targeters to prevent handling by the menu.
43 if (!target_window)
44 should_process_event = false;
45 } 35 }
46 36
47 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || 37 // TODO(flackr): The event shouldn't be handled if target_window is not
48 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) { 38 // menu_window, however the event targeter does not properly target the
49 should_quit = true; 39 // open menu. For now, we allow targeters to prevent handling by the menu.
50 } else if (ui_event && should_process_event) { 40 if (!target_window) {
51 switch (ui_event->type()) { 41 if (menu_controller_->exit_type() != MenuController::EXIT_NONE)
52 case ui::ET_KEY_PRESSED: { 42 menu_controller_->TerminateNestedMessageLoop();
53 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event.get()); 43 return ui::POST_DISPATCH_PERFORM_DEFAULT;
54 if (!menu_controller_->OnKeyDown(key_event->key_code())) {
55 should_quit = true;
56 should_perform_default = false;
57 break;
58 }
59
60 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed.
61 int flags = key_event->flags();
62 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) {
63 char c = ui::GetCharacterFromKeyCode(key_event->key_code(), flags);
64 if (menu_controller_->SelectByChar(c)) {
65 should_quit = true;
66 should_perform_default = false;
67 break;
68 }
69 }
70 should_quit = false;
71 should_perform_default = false;
72 break;
73 }
74 case ui::ET_KEY_RELEASED:
75 should_quit = false;
76 should_perform_default = false;
77 break;
78 default:
79 break;
80 }
81 } 44 }
82 45
83 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE) 46 DCHECK(ui_event);
84 menu_controller_->TerminateNestedMessageLoop(); 47 return menu_controller_->OnWillDispatchEvent(*ui_event.get());
85
86 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT
87 : ui::POST_DISPATCH_NONE;
88 } 48 }
89 49
90 } // namespace internal 50 } // namespace internal
91 } // namespace views 51 } // namespace views
OLDNEW
« ui/views/cocoa/bridged_content_view.mm ('K') | « ui/views/controls/menu/menu_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698