| 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 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); | 96 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 MenuMessageLoop* MenuMessageLoop::Create() { | 102 MenuMessageLoop* MenuMessageLoop::Create() { |
| 103 return new MenuMessageLoopAura; | 103 return new MenuMessageLoopAura; |
| 104 } | 104 } |
| 105 | 105 |
| 106 MenuMessageLoopAura::MenuMessageLoopAura() : owner_(NULL) { | 106 MenuMessageLoopAura::MenuMessageLoopAura() |
| 107 : owner_(NULL), |
| 108 menu_event_filter_(new MenuEventFilter) { |
| 107 } | 109 } |
| 108 | 110 |
| 109 MenuMessageLoopAura::~MenuMessageLoopAura() { | 111 MenuMessageLoopAura::~MenuMessageLoopAura() { |
| 110 } | 112 } |
| 111 | 113 |
| 112 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, | 114 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, |
| 113 gfx::NativeWindow window, | 115 gfx::NativeWindow window, |
| 114 const gfx::Point& screen_loc) { | 116 const gfx::Point& screen_loc) { |
| 115 aura::Window* root = window->GetRootWindow(); | 117 aura::Window* root = window->GetRootWindow(); |
| 116 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); | 118 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 // |owner_| may be NULL. | 134 // |owner_| may be NULL. |
| 133 owner_ = owner; | 135 owner_ = owner; |
| 134 aura::Window* root = GetOwnerRootWindow(owner_); | 136 aura::Window* root = GetOwnerRootWindow(owner_); |
| 135 // It is possible for the same MenuMessageLoopAura to start a nested | 137 // 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 | 138 // 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 | 139 // quit-closure gets reset to the outer loop's quit-closure once the innermost |
| 138 // loop terminates. | 140 // loop terminates. |
| 139 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, | 141 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, |
| 140 base::Closure()); | 142 base::Closure()); |
| 141 | 143 |
| 142 #if defined(OS_WIN) | 144 scoped_ptr<ActivationChangeObserverImpl> observer; |
| 143 internal::MenuMessagePumpDispatcher nested_dispatcher(controller); | |
| 144 if (root) { | 145 if (root) { |
| 145 scoped_ptr<ActivationChangeObserverImpl> observer; | |
| 146 if (!nested_menu) | 146 if (!nested_menu) |
| 147 observer.reset(new ActivationChangeObserverImpl(controller, root)); | 147 observer.reset(new ActivationChangeObserverImpl(controller, root)); |
| 148 aura::client::DispatcherRunLoop run_loop( | 148 MenuEventFilter::Delegate* filter_delegate = |
| 149 aura::client::GetDispatcherClient(root), &nested_dispatcher); | 149 MenuEventFilter::GetMenuEventFilterDelegate(root); |
| 150 message_loop_quit_ = run_loop.QuitClosure(); | 150 if (filter_delegate) |
| 151 run_loop.Run(); | 151 menu_event_filter_->SetDelegate(filter_delegate); |
| 152 } else { | |
| 153 base::MessageLoopForUI* loop = base::MessageLoopForUI::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 } | 152 } |
| 153 |
| 154 CHECK(menu_event_filter_.get()); |
| 155 aura::Env::GetInstanceDontCreate()->PrependPreTargetHandler( |
| 156 menu_event_filter_.get()); |
| 157 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 158 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 159 |
| 160 #if defined(OS_WIN) |
| 161 // On Windows we need the following nested dispatcher to handle some |
| 162 // Windows-specific events like WM_CONTEXTMENU and others that can't be |
| 163 // captured by the MenuEventFilter. |
| 164 internal::MenuMessagePumpDispatcher nested_dispatcher(controller); |
| 165 base::RunLoop run_loop(&nested_dispatcher); |
| 159 #else | 166 #else |
| 160 internal::MenuEventDispatcher event_dispatcher(controller); | 167 base::RunLoop run_loop; |
| 161 scoped_ptr<ui::ScopedEventDispatcher> dispatcher_override; | 168 #endif // defined(OS_WIN) |
| 162 if (ui::PlatformEventSource::GetInstance()) { | 169 message_loop_quit_ = run_loop.QuitClosure(); |
| 163 dispatcher_override = | 170 run_loop.Run(); |
| 164 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( | |
| 165 &event_dispatcher); | |
| 166 } | |
| 167 if (root) { | |
| 168 scoped_ptr<ActivationChangeObserverImpl> observer; | |
| 169 if (!nested_menu) | |
| 170 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 } | |
| 182 #endif | |
| 183 } | 171 } |
| 184 | 172 |
| 185 void MenuMessageLoopAura::QuitNow() { | 173 void MenuMessageLoopAura::QuitNow() { |
| 186 CHECK(!message_loop_quit_.is_null()); | 174 CHECK(!message_loop_quit_.is_null()); |
| 187 message_loop_quit_.Run(); | 175 message_loop_quit_.Run(); |
| 188 | 176 |
| 177 aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler( |
| 178 menu_event_filter_.get()); |
| 179 menu_event_filter_->ClearDelegate(); |
| 180 |
| 189 #if !defined(OS_WIN) | 181 #if !defined(OS_WIN) |
| 190 // Ask PlatformEventSource to stop dispatching events in this message loop | 182 // Ask PlatformEventSource to stop dispatching events in this message loop |
| 191 // iteration. We want our menu's loop to return before the next event. | 183 // iteration. We want our menu's loop to return before the next event. |
| 192 if (ui::PlatformEventSource::GetInstance()) | 184 if (ui::PlatformEventSource::GetInstance()) |
| 193 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); | 185 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); |
| 194 #endif | 186 #endif |
| 195 } | 187 } |
| 196 | 188 |
| 197 void MenuMessageLoopAura::ClearOwner() { | 189 void MenuMessageLoopAura::ClearOwner() { |
| 198 owner_ = NULL; | 190 owner_ = NULL; |
| 199 } | 191 } |
| 200 | 192 |
| 201 } // namespace views | 193 } // namespace views |
| OLD | NEW |