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" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
18 #include "ui/events/platform/platform_event_source.h" | 18 #include "ui/events/platform/platform_event_source.h" |
19 #include "ui/events/platform/scoped_event_dispatcher.h" | 19 #include "ui/events/platform/scoped_event_dispatcher.h" |
20 #include "ui/views/controls/menu/menu_controller.h" | 20 #include "ui/views/controls/menu/menu_controller.h" |
21 #include "ui/views/controls/menu/menu_event_filter.h" | |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
22 #include "ui/wm/public/activation_change_observer.h" | 23 #include "ui/wm/public/activation_change_observer.h" |
23 #include "ui/wm/public/activation_client.h" | 24 #include "ui/wm/public/activation_client.h" |
24 #include "ui/wm/public/dispatcher_client.h" | 25 #include "ui/wm/public/dispatcher_client.h" |
25 #include "ui/wm/public/drag_drop_client.h" | 26 #include "ui/wm/public/drag_drop_client.h" |
26 | 27 |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 #include "ui/base/win/internal_constants.h" | 29 #include "ui/base/win/internal_constants.h" |
29 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" | 30 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" |
30 #include "ui/views/win/hwnd_util.h" | 31 #include "ui/views/win/hwnd_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); | 97 DISALLOW_COPY_AND_ASSIGN(ActivationChangeObserverImpl); |
97 }; | 98 }; |
98 | 99 |
99 } // namespace | 100 } // namespace |
100 | 101 |
101 // static | 102 // static |
102 MenuMessageLoop* MenuMessageLoop::Create() { | 103 MenuMessageLoop* MenuMessageLoop::Create() { |
103 return new MenuMessageLoopAura; | 104 return new MenuMessageLoopAura; |
104 } | 105 } |
105 | 106 |
106 MenuMessageLoopAura::MenuMessageLoopAura() : owner_(NULL) { | 107 MenuMessageLoopAura::MenuMessageLoopAura() : owner_(nullptr) { |
107 } | 108 } |
108 | 109 |
109 MenuMessageLoopAura::~MenuMessageLoopAura() { | 110 MenuMessageLoopAura::~MenuMessageLoopAura() { |
110 } | 111 } |
111 | 112 |
112 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, | 113 void MenuMessageLoopAura::RepostEventToWindow(const ui::LocatedEvent& event, |
113 gfx::NativeWindow window, | 114 gfx::NativeWindow window, |
114 const gfx::Point& screen_loc) { | 115 const gfx::Point& screen_loc) { |
115 aura::Window* root = window->GetRootWindow(); | 116 aura::Window* root = window->GetRootWindow(); |
116 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); | 117 ScreenPositionClient* spc = aura::client::GetScreenPositionClient(root); |
(...skipping 16 matching lines...) Expand all Loading... | |
133 owner_ = owner; | 134 owner_ = owner; |
134 aura::Window* root = GetOwnerRootWindow(owner_); | 135 aura::Window* root = GetOwnerRootWindow(owner_); |
135 // It is possible for the same MenuMessageLoopAura to start a nested | 136 // 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 | 137 // 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 | 138 // quit-closure gets reset to the outer loop's quit-closure once the innermost |
138 // loop terminates. | 139 // loop terminates. |
139 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, | 140 base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_, |
140 base::Closure()); | 141 base::Closure()); |
141 | 142 |
142 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
143 internal::MenuMessagePumpDispatcher nested_dispatcher(controller); | 144 internal::MenuMessagePumpDispatcher nested_dispatcher(controller); |
sky
2015/09/03 17:23:21
Why is the filtering specific to non-windows platf
afakhry
2015/09/04 01:49:42
On Windows, we have the MenuMessagePumpDispatcher
sky
2015/09/09 15:44:52
I don't see how that handles the ash accelerators
afakhry
2015/09/09 20:21:32
Exactly, because the current code is very unclear.
| |
144 if (root) { | 145 if (root) { |
145 scoped_ptr<ActivationChangeObserverImpl> observer; | 146 scoped_ptr<ActivationChangeObserverImpl> observer; |
146 if (!nested_menu) | 147 if (!nested_menu) |
147 observer.reset(new ActivationChangeObserverImpl(controller, root)); | 148 observer.reset(new ActivationChangeObserverImpl(controller, root)); |
148 aura::client::DispatcherRunLoop run_loop( | 149 aura::client::DispatcherRunLoop run_loop( |
149 aura::client::GetDispatcherClient(root), &nested_dispatcher); | 150 aura::client::GetDispatcherClient(root), &nested_dispatcher); |
150 message_loop_quit_ = run_loop.QuitClosure(); | 151 message_loop_quit_ = run_loop.QuitClosure(); |
151 run_loop.Run(); | 152 run_loop.Run(); |
152 } else { | 153 } else { |
153 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 154 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
154 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | 155 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
155 base::RunLoop run_loop(&nested_dispatcher); | 156 base::RunLoop run_loop(&nested_dispatcher); |
156 message_loop_quit_ = run_loop.QuitClosure(); | 157 message_loop_quit_ = run_loop.QuitClosure(); |
157 run_loop.Run(); | 158 run_loop.Run(); |
158 } | 159 } |
159 #else | 160 #else |
160 internal::MenuEventDispatcher event_dispatcher(controller); | 161 scoped_ptr<ActivationChangeObserverImpl> observer; |
161 scoped_ptr<ui::ScopedEventDispatcher> dispatcher_override; | 162 MenuEventFilter::Delegate* filter_delegate = nullptr; |
162 if (ui::PlatformEventSource::GetInstance()) { | |
163 dispatcher_override = | |
164 ui::PlatformEventSource::GetInstance()->OverrideDispatcher( | |
165 &event_dispatcher); | |
166 } | |
167 if (root) { | 163 if (root) { |
168 scoped_ptr<ActivationChangeObserverImpl> observer; | |
169 if (!nested_menu) | 164 if (!nested_menu) |
170 observer.reset(new ActivationChangeObserverImpl(controller, root)); | 165 observer.reset(new ActivationChangeObserverImpl(controller, root)); |
171 aura::client::DispatcherRunLoop run_loop( | 166 filter_delegate = MenuEventFilter::GetMenuEventFilterDelegate(root); |
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 } | 167 } |
182 #endif | 168 |
169 MenuEventFilter menu_event_filter(controller, filter_delegate); | |
sky
2015/09/03 17:23:21
AFAICT the functionality you need is the ability t
afakhry
2015/09/04 01:49:42
I'm not sure I understand your suggestion. What's
sky
2015/09/04 14:38:54
I'm trying to understand why you are doing the cha
oshima
2015/09/04 18:27:01
My understanding of the role of ViewsDelegate is t
oshima
2015/09/04 18:32:10
Or just have ViewsDelegate::HandleKeyEventOnMenu
afakhry
2015/09/08 21:31:46
Done.
| |
170 aura::Env::GetInstanceDontCreate()->PrependPreTargetHandler( | |
171 &menu_event_filter); | |
172 | |
173 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
174 base::MessageLoop::ScopedNestableTaskAllower allow(loop); | |
175 base::RunLoop run_loop; | |
176 message_loop_quit_ = run_loop.QuitClosure(); | |
177 | |
178 run_loop.Run(); | |
179 | |
180 aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler( | |
181 &menu_event_filter); | |
182 #endif // defined(OS_WIN) | |
183 } | 183 } |
184 | 184 |
185 void MenuMessageLoopAura::QuitNow() { | 185 void MenuMessageLoopAura::QuitNow() { |
186 CHECK(!message_loop_quit_.is_null()); | 186 CHECK(!message_loop_quit_.is_null()); |
187 message_loop_quit_.Run(); | 187 message_loop_quit_.Run(); |
188 | 188 |
189 #if !defined(OS_WIN) | 189 #if !defined(OS_WIN) |
190 // Ask PlatformEventSource to stop dispatching events in this message loop | 190 // Ask PlatformEventSource to stop dispatching events in this message loop |
191 // iteration. We want our menu's loop to return before the next event. | 191 // iteration. We want our menu's loop to return before the next event. |
192 if (ui::PlatformEventSource::GetInstance()) | 192 if (ui::PlatformEventSource::GetInstance()) |
193 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); | 193 ui::PlatformEventSource::GetInstance()->StopCurrentEventStream(); |
194 #endif | 194 #endif |
195 } | 195 } |
196 | 196 |
197 void MenuMessageLoopAura::ClearOwner() { | 197 void MenuMessageLoopAura::ClearOwner() { |
198 owner_ = NULL; | 198 owner_ = NULL; |
199 } | 199 } |
200 | 200 |
201 } // namespace views | 201 } // namespace views |
OLD | NEW |