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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
9 #include "ui/aura/test/aura_test_utils.h" | 9 #include "ui/aura/test/aura_test_utils.h" |
10 #include "ui/aura/test/ui_controls_factory_aura.h" | 10 #include "ui/aura/test/ui_controls_factory_aura.h" |
11 #include "ui/aura/window_tree_host.h" | 11 #include "ui/aura/window_tree_host.h" |
12 #include "ui/base/test/ui_controls_aura.h" | 12 #include "ui/base/test/ui_controls_aura.h" |
13 #include "ui/events/test/events_test_utils.h" | |
13 | 14 |
14 namespace aura { | 15 namespace aura { |
15 namespace test { | 16 namespace test { |
16 namespace { | 17 namespace { |
17 | 18 |
18 class UIControlsOzone : public ui_controls::UIControlsAura { | 19 class UIControlsOzone : public ui_controls::UIControlsAura { |
19 public: | 20 public: |
20 UIControlsOzone(WindowTreeHost* host) : host_(host) {} | 21 UIControlsOzone(WindowTreeHost* host) : host_(host) {} |
21 | 22 |
22 virtual bool SendKeyPress(gfx::NativeWindow window, | 23 virtual bool SendKeyPress(gfx::NativeWindow window, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 virtual bool SendMouseClick(ui_controls::MouseButton type) override { | 159 virtual bool SendMouseClick(ui_controls::MouseButton type) override { |
159 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 160 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
160 } | 161 } |
161 virtual void RunClosureAfterAllPendingUIEvents( | 162 virtual void RunClosureAfterAllPendingUIEvents( |
162 const base::Closure& closure) override { | 163 const base::Closure& closure) override { |
163 if (!closure.is_null()) | 164 if (!closure.is_null()) |
164 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 165 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
165 } | 166 } |
166 | 167 |
167 private: | 168 private: |
169 void SendEventToProcessor(ui::Event* event) { | |
sky
2014/11/07 15:50:14
Is there a reason this needs to be a pointer? I br
sadrul
2014/11/07 17:03:15
This is mostly so the consumers can do SetHandled(
| |
170 ui::EventSourceTestApi event_source_test(host_->GetEventSource()); | |
171 ui::EventDispatchDetails details = | |
172 event_source_test.SendEventToProcessor(event); | |
173 if (details.dispatcher_destroyed) | |
174 return; | |
175 } | |
176 | |
168 void PostKeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) { | 177 void PostKeyEvent(ui::EventType type, ui::KeyboardCode key_code, int flags) { |
169 base::MessageLoop::current()->PostTask( | 178 base::MessageLoop::current()->PostTask( |
170 FROM_HERE, | 179 FROM_HERE, |
171 base::Bind(&UIControlsOzone::PostKeyEventTask, | 180 base::Bind(&UIControlsOzone::PostKeyEventTask, |
172 base::Unretained(this), | 181 base::Unretained(this), |
173 type, | 182 type, |
174 key_code, | 183 key_code, |
175 flags)); | 184 flags)); |
176 } | 185 } |
177 | 186 |
178 void PostKeyEventTask(ui::EventType type, | 187 void PostKeyEventTask(ui::EventType type, |
179 ui::KeyboardCode key_code, | 188 ui::KeyboardCode key_code, |
180 int flags) { | 189 int flags) { |
181 // Do not rewrite injected events. See crbug.com/136465. | 190 // Do not rewrite injected events. See crbug.com/136465. |
182 flags |= ui::EF_FINAL; | 191 flags |= ui::EF_FINAL; |
183 | 192 |
184 ui::KeyEvent key_event(type, key_code, flags); | 193 ui::KeyEvent key_event(type, key_code, flags); |
185 host_->PostNativeEvent(&key_event); | 194 SendEventToProcessor(&key_event); |
186 } | 195 } |
187 | 196 |
188 void PostMouseEvent(ui::EventType type, | 197 void PostMouseEvent(ui::EventType type, |
189 const gfx::PointF& location, | 198 const gfx::PointF& location, |
190 int flags, | 199 int flags, |
191 int changed_button_flags) { | 200 int changed_button_flags) { |
192 base::MessageLoop::current()->PostTask( | 201 base::MessageLoop::current()->PostTask( |
193 FROM_HERE, | 202 FROM_HERE, |
194 base::Bind(&UIControlsOzone::PostMouseEventTask, | 203 base::Bind(&UIControlsOzone::PostMouseEventTask, |
195 base::Unretained(this), | 204 base::Unretained(this), |
196 type, | 205 type, |
197 location, | 206 location, |
198 flags, | 207 flags, |
199 changed_button_flags)); | 208 changed_button_flags)); |
200 } | 209 } |
201 | 210 |
202 void PostMouseEventTask(ui::EventType type, | 211 void PostMouseEventTask(ui::EventType type, |
203 const gfx::PointF& location, | 212 const gfx::PointF& location, |
204 int flags, | 213 int flags, |
205 int changed_button_flags) { | 214 int changed_button_flags) { |
206 ui::MouseEvent mouse_event( | 215 ui::MouseEvent mouse_event( |
207 type, location, location, flags, changed_button_flags); | 216 type, location, location, flags, changed_button_flags); |
208 | 217 |
209 // This hack is necessary to set the repeat count for clicks. | 218 // This hack is necessary to set the repeat count for clicks. |
210 ui::MouseEvent mouse_event2(&mouse_event); | 219 ui::MouseEvent mouse_event2(&mouse_event); |
211 | 220 |
212 host_->PostNativeEvent(&mouse_event2); | 221 SendEventToProcessor(&mouse_event2); |
213 } | 222 } |
214 | 223 |
215 WindowTreeHost* host_; | 224 WindowTreeHost* host_; |
216 | 225 |
217 // Mask of the mouse buttons currently down. | 226 // Mask of the mouse buttons currently down. |
218 unsigned button_down_mask_ = 0; | 227 unsigned button_down_mask_ = 0; |
219 | 228 |
220 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); | 229 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); |
221 }; | 230 }; |
222 | 231 |
223 } // namespace | 232 } // namespace |
224 | 233 |
225 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { | 234 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
226 return new UIControlsOzone(host); | 235 return new UIControlsOzone(host); |
227 } | 236 } |
228 | 237 |
229 } // namespace test | 238 } // namespace test |
230 } // namespace aura | 239 } // namespace aura |
OLD | NEW |