| 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windowsx.h> | 8 #include <windowsx.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "ui/aura/client/screen_position_client.h" | 12 #include "ui/aura/client/screen_position_client.h" |
| 13 #include "ui/aura/env.h" | |
| 14 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 18 #include "ui/events/platform/platform_event_source.h" | 17 #include "ui/events/platform/platform_event_source.h" |
| 19 #include "ui/events/platform/scoped_event_dispatcher.h" | 18 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 20 #include "ui/views/controls/menu/menu_controller.h" | 19 #include "ui/views/controls/menu/menu_controller.h" |
| 21 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 22 #include "ui/wm/public/activation_change_observer.h" | 21 #include "ui/wm/public/activation_change_observer.h" |
| 23 #include "ui/wm/public/activation_client.h" | 22 #include "ui/wm/public/activation_client.h" |
| 24 #include "ui/wm/public/dispatcher_client.h" | 23 #include "ui/wm/public/dispatcher_client.h" |
| 25 #include "ui/wm/public/drag_drop_client.h" | 24 #include "ui/wm/public/drag_drop_client.h" |
| 26 | 25 |
| 27 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 28 #include "ui/base/win/internal_constants.h" | 27 #include "ui/base/win/internal_constants.h" |
| 29 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" | 28 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" |
| 30 #include "ui/views/win/hwnd_util.h" | 29 #include "ui/views/win/hwnd_util.h" |
| 31 #else | 30 #else |
| 32 #include "ui/views/controls/menu/menu_event_dispatcher.h" | 31 #include "ui/views/controls/menu/menu_key_event_handler.h" |
| 33 #endif | 32 #endif |
| 34 | 33 |
| 35 using aura::client::ScreenPositionClient; | 34 using aura::client::ScreenPositionClient; |
| 36 | 35 |
| 37 namespace views { | 36 namespace views { |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 aura::Window* GetOwnerRootWindow(views::Widget* owner) { | 40 aura::Window* GetOwnerRootWindow(views::Widget* owner) { |
| 42 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; | 41 return owner ? owner->GetNativeWindow()->GetRootWindow() : NULL; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); | 95 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 } // namespace | 98 } // namespace |
| 100 | 99 |
| 101 // static | 100 // static |
| 102 MenuMessageLoop* MenuMessageLoop::Create() { | 101 MenuMessageLoop* MenuMessageLoop::Create() { |
| 103 return new MenuMessageLoopAura; | 102 return new MenuMessageLoopAura; |
| 104 } | 103 } |
| 105 | 104 |
| 106 MenuMessageLoopAura::MenuMessageLoopAura() : owner_(NULL) { | 105 MenuMessageLoopAura::MenuMessageLoopAura() : owner_(nullptr) { |
| 107 } | 106 } |
| 108 | 107 |
| 109 MenuMessageLoopAura::~MenuMessageLoopAura() { | 108 MenuMessageLoopAura::~MenuMessageLoopAura() { |
| 110 } | 109 } |
| 111 | 110 |
| 112 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, | 111 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, |
| 113 gfx::NativeWindow window, | 112 gfx::NativeWindow window, |
| 114 const gfx::Point& screen_loc) { | 113 const gfx::Point& screen_loc) { |
| 115 aura::Window* root = window->GetRootWindow(); | 114 aura::Window* root = window->GetRootWindow(); |
| 116 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); | 115 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 message_loop_quit_ = run_loop.QuitClosure(); | 149 message_loop_quit_ = run_loop.QuitClosure(); |
| 151 run_loop.Run(); | 150 run_loop.Run(); |
| 152 } else { | 151 } else { |
| 153 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 152 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 154 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 153 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 155 base::RunLoop run_loop(&nested_dispatcher); | 154 base::RunLoop run_loop(&nested_dispatcher); |
| 156 message_loop_quit_ = run_loop.QuitClosure(); | 155 message_loop_quit_ = run_loop.QuitClosure(); |
| 157 run_loop.Run(); | 156 run_loop.Run(); |
| 158 } | 157 } |
| 159 #else | 158 #else |
| 160 internal::MenuEventDispatcher event_dispatcher(controller); | 159 scoped_ptr<ActivationChangeObserverImpl> observer; |
| 161 scoped_ptr<ui::ScopedEventDispatcher> dispatcher_override; | |
| 162 if (ui::PlatformEventSource::GetInstance()) { | |
| 163 dispatcher_override = | |
| 164 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( | |
| 165 &event_dispatcher); | |
| 166 } | |
| 167 if (root) { | 160 if (root) { |
| 168 scoped_ptr<ActivationChangeObserverImpl> observer; | |
| 169 if (!nested_menu) | 161 if (!nested_menu) |
| 170 observer.reset(new ActivationChangeObserverImpl(controller, root)); | 162 observer.reset(new ActivationChangeObserverImpl(controller, root)); |
| 171 aura::client::DispatcherRunLoop run_loop( | |
| 172 aura::client::GetDispatcherClient(root), NULL); | |
| 173 message_loop_quit_ = run_loop.QuitClosure(); | |
| 174 run_loop.Run(); | |
| 175 } else { | |
| 176 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
| 177 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
| 178 base::RunLoop run_loop; | |
| 179 message_loop_quit_ = run_loop.QuitClosure(); | |
| 180 run_loop.Run(); | |
| 181 } | 163 } |
| 182 #endif | 164 |
| 165 scoped_ptr<MenuKeyEventHandler> menu_event_filter; |
| 166 if (!nested_menu) { |
| 167 // If this is a nested menu, then the MenuKeyEventHandler would have been |
| 168 // created already in the top parent menu. So no need to recreate it here. |
| 169 menu_event_filter.reset(new MenuKeyEventHandler); |
| 170 } |
| 171 |
| 172 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 173 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 174 base::RunLoop run_loop; |
| 175 message_loop_quit_ = run_loop.QuitClosure(); |
| 176 |
| 177 run_loop.Run(); |
| 178 #endif // defined(OS_WIN) |
| 183 } | 179 } |
| 184 | 180 |
| 185 void MenuMessageLoopAura::QuitNow() { | 181 void MenuMessageLoopAura::QuitNow() { |
| 186 CHECK(!message_loop_quit_.is_null()); | 182 CHECK(!message_loop_quit_.is_null()); |
| 187 message_loop_quit_.Run(); | 183 message_loop_quit_.Run(); |
| 188 | 184 |
| 189 #if !defined(OS_WIN) | 185 #if !defined(OS_WIN) |
| 190 // Ask PlatformEventSource to stop dispatching events in this message loop | 186 // Ask PlatformEventSource to stop dispatching events in this message loop |
| 191 // iteration. We want our menu's loop to return before the next event. | 187 // iteration. We want our menu's loop to return before the next event. |
| 192 if (ui::PlatformEventSource::GetInstance()) | 188 if (ui::PlatformEventSource::GetInstance()) |
| 193 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); | 189 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); |
| 194 #endif | 190 #endif |
| 195 } | 191 } |
| 196 | 192 |
| 197 void MenuMessageLoopAura::ClearOwner() { | 193 void MenuMessageLoopAura::ClearOwner() { |
| 198 owner_ = NULL; | 194 owner_ = NULL; |
| 199 } | 195 } |
| 200 | 196 |
| 201 } // namespace views | 197 } // namespace views |
| OLD | NEW |