| 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_message_loop_aura.h" | 5 #include "ui/views/controls/menu/menu_message_loop_aura.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/platform/platform_event_source.h" | 15 #include "ui/events/platform/platform_event_source.h" |
| 16 #include "ui/events/platform/scoped_event_dispatcher.h" | 16 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 17 #include "ui/views/controls/menu/menu_controller.h" | 17 #include "ui/views/controls/menu/menu_controller.h" |
| 18 #include "ui/views/controls/menu/menu_key_event_handler.h" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 19 #include "ui/wm/public/activation_change_observer.h" | 20 #include "ui/wm/public/activation_change_observer.h" |
| 20 #include "ui/wm/public/activation_client.h" | 21 #include "ui/wm/public/activation_client.h" |
| 21 #include "ui/wm/public/dispatcher_client.h" | 22 #include "ui/wm/public/dispatcher_client.h" |
| 22 #include "ui/wm/public/drag_drop_client.h" | 23 #include "ui/wm/public/drag_drop_client.h" |
| 23 | 24 |
| 24 #if defined(OS_WIN) | |
| 25 #include "ui/base/win/internal_constants.h" | |
| 26 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" | |
| 27 #include "ui/views/win/hwnd_util.h" | |
| 28 #else | |
| 29 #include "ui/views/controls/menu/menu_key_event_handler.h" | |
| 30 #endif | |
| 31 | 25 |
| 32 using aura::client::ScreenPositionClient; | 26 using aura::client::ScreenPositionClient; |
| 33 | 27 |
| 34 namespace views { | 28 namespace views { |
| 35 | 29 |
| 36 namespace { | 30 namespace { |
| 37 | 31 |
| 38 aura::Window* GetOwnerRootWindow(views::Widget* owner) { | 32 aura::Window* GetOwnerRootWindow(views::Widget* owner) { |
| 39 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; | 33 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; |
| 40 } | 34 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // |owner_| may be NULL. | 126 // |owner_| may be NULL. |
| 133 owner_ = owner; | 127 owner_ = owner; |
| 134 aura::Window* root = GetOwnerRootWindow(owner_); | 128 aura::Window* root = GetOwnerRootWindow(owner_); |
| 135 // It is possible for the same MenuMessageLoopAura to start a nested | 129 // It is possible for the same MenuMessageLoopAura to start a nested |
| 136 // message-loop while it is already running a nested loop. So make sure the | 130 // message-loop while it is already running a nested loop. So make sure the |
| 137 // quit-closure gets reset to the outer loop's quit-closure once the innermost | 131 // quit-closure gets reset to the outer loop's quit-closure once the innermost |
| 138 // loop terminates. | 132 // loop terminates. |
| 139 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, | 133 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, |
| 140 base::Closure()); | 134 base::Closure()); |
| 141 | 135 |
| 142 #if defined(OS_WIN) | |
| 143 internal::MenuMessagePumpDispatcher nested_dispatcher(controller); | |
| 144 if (root) { | |
| 145 scoped_ptr<ActivationChangeObserverImpl> observer; | |
| 146 if (!nested_menu) | |
| 147 observer.reset(new ActivationChangeObserverImpl(controller, root)); | |
| 148 aura::client::DispatcherRunLoop run_loop( | |
| 149 aura::client::GetDispatcherClient(root), &nested_dispatcher); | |
| 150 message_loop_quit_ = run_loop.QuitClosure(); | |
| 151 run_loop.Run(); | |
| 152 } else { | |
| 153 base::MessageLoop* loop = base::MessageLoop::current(); | |
| 154 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 155 base::RunLoop run_loop(&nested_dispatcher); | |
| 156 message_loop_quit_ = run_loop.QuitClosure(); | |
| 157 run_loop.Run(); | |
| 158 } | |
| 159 #else | |
| 160 scoped_ptr<ActivationChangeObserverImpl> observer; | 136 scoped_ptr<ActivationChangeObserverImpl> observer; |
| 161 if (root) { | 137 if (root) { |
| 162 if (!nested_menu) | 138 if (!nested_menu) |
| 163 observer.reset(new ActivationChangeObserverImpl(controller, root)); | 139 observer.reset(new ActivationChangeObserverImpl(controller, root)); |
| 164 } | 140 } |
| 165 | 141 |
| 166 scoped_ptr<MenuKeyEventHandler> menu_event_filter; | 142 scoped_ptr<MenuKeyEventHandler> menu_event_filter; |
| 167 if (!nested_menu) { | 143 if (!nested_menu) { |
| 168 // If this is a nested menu, then the MenuKeyEventHandler would have been | 144 // If this is a nested menu, then the MenuKeyEventHandler would have been |
| 169 // created already in the top parent menu. So no need to recreate it here. | 145 // created already in the top parent menu. So no need to recreate it here. |
| 170 menu_event_filter.reset(new MenuKeyEventHandler); | 146 menu_event_filter.reset(new MenuKeyEventHandler); |
| 171 } | 147 } |
| 172 | 148 |
| 173 base::MessageLoop* loop = base::MessageLoop::current(); | 149 base::MessageLoop* loop = base::MessageLoop::current(); |
| 174 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 150 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 175 base::RunLoop run_loop; | 151 base::RunLoop run_loop; |
| 176 message_loop_quit_ = run_loop.QuitClosure(); | 152 message_loop_quit_ = run_loop.QuitClosure(); |
| 177 | 153 |
| 178 run_loop.Run(); | 154 run_loop.Run(); |
| 179 #endif // defined(OS_WIN) | |
| 180 } | 155 } |
| 181 | 156 |
| 182 void MenuMessageLoopAura::QuitNow() { | 157 void MenuMessageLoopAura::QuitNow() { |
| 183 CHECK(!message_loop_quit_.is_null()); | 158 CHECK(!message_loop_quit_.is_null()); |
| 184 message_loop_quit_.Run(); | 159 message_loop_quit_.Run(); |
| 185 | 160 |
| 186 #if !defined(OS_WIN) | 161 #if !defined(OS_WIN) |
| 187 // Ask PlatformEventSource to stop dispatching events in this message loop | 162 // Ask PlatformEventSource to stop dispatching events in this message loop |
| 188 // iteration. We want our menu's loop to return before the next event. | 163 // iteration. We want our menu's loop to return before the next event. |
| 189 if (ui::PlatformEventSource::GetInstance()) | 164 if (ui::PlatformEventSource::GetInstance()) |
| 190 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); | 165 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); |
| 191 #endif | 166 #endif |
| 192 } | 167 } |
| 193 | 168 |
| 194 void MenuMessageLoopAura::ClearOwner() { | 169 void MenuMessageLoopAura::ClearOwner() { |
| 195 owner_ = NULL; | 170 owner_ = NULL; |
| 196 } | 171 } |
| 197 | 172 |
| 198 } // namespace views | 173 } // namespace views |
| OLD | NEW |