OLD | NEW |
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" |
| 8 #include "ui/aura/window.h" |
7 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
8 #include "ui/events/keycodes/keyboard_code_conversion.h" | 10 #include "ui/events/keycodes/keyboard_code_conversion.h" |
9 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
10 #include "ui/views/controls/menu/menu_controller.h" | 12 #include "ui/views/controls/menu/menu_controller.h" |
| 13 #include "ui/views/widget/widget.h" |
11 | 14 |
12 namespace views { | 15 namespace views { |
13 namespace internal { | 16 namespace internal { |
14 | 17 |
15 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) | 18 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) |
16 : menu_controller_(controller) {} | 19 : menu_controller_(controller) {} |
17 | 20 |
18 MenuEventDispatcher::~MenuEventDispatcher() {} | 21 MenuEventDispatcher::~MenuEventDispatcher() {} |
19 | 22 |
20 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { | 23 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { |
21 return true; | 24 return true; |
22 } | 25 } |
23 | 26 |
24 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { | 27 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { |
25 bool should_quit = false; | 28 bool should_quit = false; |
26 bool should_perform_default = true; | 29 bool should_perform_default = true; |
| 30 |
| 31 // Check if the event should be handled. |
| 32 scoped_ptr<ui::Event> ui_event(ui::EventFromNative(event)); |
| 33 if (ui_event && menu_controller_->owner()) { |
| 34 aura::Window* menu_window = menu_controller_->owner()->GetNativeWindow(); |
| 35 aura::Window* target_window = static_cast<aura::Window*>( |
| 36 static_cast<ui::EventTarget*>(menu_window->GetRootWindow())-> |
| 37 GetEventTargeter()->FindTargetForEvent(menu_window, |
| 38 ui_event.get())); |
| 39 // TODO(flackr): The event shouldn't be handled if target_window is not |
| 40 // menu_window, however the event targeter does not properly target the |
| 41 // open menu. For now, we allow targeters to prevent handling by the menu. |
| 42 if (!target_window) |
| 43 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 44 } |
| 45 |
27 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || | 46 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || |
28 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) { | 47 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) { |
29 should_quit = true; | 48 should_quit = true; |
30 } else { | 49 } else { |
31 switch (ui::EventTypeFromNative(event)) { | 50 switch (ui::EventTypeFromNative(event)) { |
32 case ui::ET_KEY_PRESSED: { | 51 case ui::ET_KEY_PRESSED: { |
33 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) { | 52 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) { |
34 should_quit = true; | 53 should_quit = true; |
35 should_perform_default = false; | 54 should_perform_default = false; |
36 break; | 55 break; |
(...skipping 25 matching lines...) Expand all Loading... |
62 | 81 |
63 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE) | 82 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE) |
64 menu_controller_->TerminateNestedMessageLoop(); | 83 menu_controller_->TerminateNestedMessageLoop(); |
65 | 84 |
66 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT | 85 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT |
67 : ui::POST_DISPATCH_NONE; | 86 : ui::POST_DISPATCH_NONE; |
68 } | 87 } |
69 | 88 |
70 } // namespace internal | 89 } // namespace internal |
71 } // namespace views | 90 } // namespace views |
OLD | NEW |