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/events/test/event_generator.h" | 5 #include "ui/events/test/event_generator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 }; | 56 }; |
57 | 57 |
58 class TestTouchEvent : public ui::TouchEvent { | 58 class TestTouchEvent : public ui::TouchEvent { |
59 public: | 59 public: |
60 TestTouchEvent(ui::EventType type, | 60 TestTouchEvent(ui::EventType type, |
61 const gfx::Point& root_location, | 61 const gfx::Point& root_location, |
62 int touch_id, | 62 int touch_id, |
63 int flags, | 63 int flags, |
64 base::TimeDelta timestamp) | 64 base::TimeDelta timestamp) |
65 : TouchEvent(type, root_location, flags, touch_id, timestamp, | 65 : TouchEvent(type, |
66 1.0f, 1.0f, 0.0f, 0.0f) { | 66 root_location, |
67 } | 67 flags, |
| 68 touch_id, |
| 69 timestamp, |
| 70 0.0f, |
| 71 PointerEventDetails(EventPointerType::POINTER_TYPE_TOUCH, |
| 72 1.0f, |
| 73 1.0f, |
| 74 0.0f, |
| 75 0.0f, |
| 76 0.0f)) {} |
68 | 77 |
69 private: | 78 private: |
70 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); | 79 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); |
71 }; | 80 }; |
72 | 81 |
73 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 82 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
74 | 83 |
75 } // namespace | 84 } // namespace |
76 | 85 |
77 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; | 86 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 void EventGenerator::PressRightButton() { | 161 void EventGenerator::PressRightButton() { |
153 PressButton(ui::EF_RIGHT_MOUSE_BUTTON); | 162 PressButton(ui::EF_RIGHT_MOUSE_BUTTON); |
154 } | 163 } |
155 | 164 |
156 void EventGenerator::ReleaseRightButton() { | 165 void EventGenerator::ReleaseRightButton() { |
157 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON); | 166 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON); |
158 } | 167 } |
159 | 168 |
160 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { | 169 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { |
161 gfx::Point location = GetLocationInCurrentRoot(); | 170 gfx::Point location = GetLocationInCurrentRoot(); |
162 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, | 171 ui::MouseEvent mouseev( |
163 ui::EventTimeForNow(), flags_, 0); | 172 ui::ET_MOUSEWHEEL, location, location, ui::EventTimeForNow(), flags_, 0, |
| 173 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
164 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); | 174 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); |
165 Dispatch(&wheelev); | 175 Dispatch(&wheelev); |
166 } | 176 } |
167 | 177 |
168 void EventGenerator::SendMouseExit() { | 178 void EventGenerator::SendMouseExit() { |
169 gfx::Point exit_location(current_location_); | 179 gfx::Point exit_location(current_location_); |
170 delegate()->ConvertPointToTarget(current_target_, &exit_location); | 180 delegate()->ConvertPointToTarget(current_target_, &exit_location); |
171 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, | 181 ui::MouseEvent mouseev( |
172 ui::EventTimeForNow(), flags_, 0); | 182 ui::ET_MOUSE_EXITED, exit_location, exit_location, ui::EventTimeForNow(), |
| 183 flags_, 0, |
| 184 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
173 Dispatch(&mouseev); | 185 Dispatch(&mouseev); |
174 } | 186 } |
175 | 187 |
176 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, | 188 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, |
177 const gfx::Point& point_for_native) { | 189 const gfx::Point& point_for_native) { |
178 #if defined(USE_X11) | 190 #if defined(USE_X11) |
179 ui::ScopedXI2Event xevent; | 191 ui::ScopedXI2Event xevent; |
180 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); | 192 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); |
181 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds(); | 193 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds(); |
182 ui::MouseEvent mouseev(xevent); | 194 ui::MouseEvent mouseev(xevent); |
183 #elif defined(USE_OZONE) | 195 #elif defined(USE_OZONE) |
184 // Ozone uses the location in native event as a system location. | 196 // Ozone uses the location in native event as a system location. |
185 // Create a fake event with the point in host, which will be passed | 197 // Create a fake event with the point in host, which will be passed |
186 // to the non native event, then update the native event with the native | 198 // to the non native event, then update the native event with the native |
187 // (root) one. | 199 // (root) one. |
188 scoped_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( | 200 scoped_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( |
189 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); | 201 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0, |
| 202 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
190 ui::MouseEvent mouseev(native_event.get()); | 203 ui::MouseEvent mouseev(native_event.get()); |
191 native_event->set_location(point_for_native); | 204 native_event->set_location(point_for_native); |
192 #else | 205 #else |
193 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, | 206 ui::MouseEvent mouseev( |
194 Now(), flags_, 0); | 207 ui::ET_MOUSE_MOVED, point_in_host, point_for_native, Now(), flags_, 0, |
| 208 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
195 LOG(FATAL) | 209 LOG(FATAL) |
196 << "Generating a native motion event is not supported on this platform"; | 210 << "Generating a native motion event is not supported on this platform"; |
197 #endif | 211 #endif |
198 Dispatch(&mouseev); | 212 Dispatch(&mouseev); |
199 | 213 |
200 current_location_ = point_in_host; | 214 current_location_ = point_in_host; |
201 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); | 215 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); |
202 } | 216 } |
203 | 217 |
204 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { | 218 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { |
205 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 219 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
206 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 220 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
207 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, | 221 ui::MouseEvent mouseev( |
208 ui::EventTimeForNow(), flags_, 0); | 222 event_type, point_in_host, point_in_host, ui::EventTimeForNow(), flags_, |
| 223 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
209 Dispatch(&mouseev); | 224 Dispatch(&mouseev); |
210 | 225 |
211 current_location_ = point_in_host; | 226 current_location_ = point_in_host; |
212 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); | 227 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); |
213 } | 228 } |
214 | 229 |
215 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, | 230 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, |
216 int count) { | 231 int count) { |
217 DCHECK_GT(count, 0); | 232 DCHECK_GT(count, 0); |
218 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 233 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
219 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 234 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
220 | 235 |
221 gfx::Vector2dF diff(point_in_screen - current_location_); | 236 gfx::Vector2dF diff(point_in_screen - current_location_); |
222 for (float i = 1; i <= count; i++) { | 237 for (float i = 1; i <= count; i++) { |
223 gfx::Vector2dF step(diff); | 238 gfx::Vector2dF step(diff); |
224 step.Scale(i / count); | 239 step.Scale(i / count); |
225 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); | 240 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
226 if (!grab_) | 241 if (!grab_) |
227 UpdateCurrentDispatcher(move_point); | 242 UpdateCurrentDispatcher(move_point); |
228 delegate()->ConvertPointToTarget(current_target_, &move_point); | 243 delegate()->ConvertPointToTarget(current_target_, &move_point); |
229 ui::MouseEvent mouseev(event_type, move_point, move_point, | 244 ui::MouseEvent mouseev( |
230 ui::EventTimeForNow(), flags_, 0); | 245 event_type, move_point, move_point, ui::EventTimeForNow(), flags_, 0, |
| 246 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
231 Dispatch(&mouseev); | 247 Dispatch(&mouseev); |
232 } | 248 } |
233 current_location_ = point_in_screen; | 249 current_location_ = point_in_screen; |
234 } | 250 } |
235 | 251 |
236 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, | 252 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, |
237 const gfx::Point& point_in_parent) { | 253 const gfx::Point& point_in_parent) { |
238 gfx::Point point(point_in_parent); | 254 gfx::Point point(point_in_parent); |
239 delegate()->ConvertPointFromTarget(window, &point); | 255 delegate()->ConvertPointFromTarget(window, &point); |
240 MoveMouseTo(point); | 256 MoveMouseTo(point); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 614 |
599 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 615 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
600 current_target_ = delegate()->GetTargetAt(point); | 616 current_target_ = delegate()->GetTargetAt(point); |
601 } | 617 } |
602 | 618 |
603 void EventGenerator::PressButton(int flag) { | 619 void EventGenerator::PressButton(int flag) { |
604 if (!(flags_ & flag)) { | 620 if (!(flags_ & flag)) { |
605 flags_ |= flag; | 621 flags_ |= flag; |
606 grab_ = (flags_ & kAllButtonMask) != 0; | 622 grab_ = (flags_ & kAllButtonMask) != 0; |
607 gfx::Point location = GetLocationInCurrentRoot(); | 623 gfx::Point location = GetLocationInCurrentRoot(); |
608 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, | 624 ui::MouseEvent mouseev( |
609 ui::EventTimeForNow(), flags_, flag); | 625 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), flags_, |
| 626 flag, |
| 627 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
610 Dispatch(&mouseev); | 628 Dispatch(&mouseev); |
611 } | 629 } |
612 } | 630 } |
613 | 631 |
614 void EventGenerator::ReleaseButton(int flag) { | 632 void EventGenerator::ReleaseButton(int flag) { |
615 if (flags_ & flag) { | 633 if (flags_ & flag) { |
616 gfx::Point location = GetLocationInCurrentRoot(); | 634 gfx::Point location = GetLocationInCurrentRoot(); |
617 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, location, | 635 ui::MouseEvent mouseev( |
618 ui::EventTimeForNow(), flags_, flag); | 636 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
| 637 flags_, flag, |
| 638 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
619 Dispatch(&mouseev); | 639 Dispatch(&mouseev); |
620 flags_ ^= flag; | 640 flags_ ^= flag; |
621 } | 641 } |
622 grab_ = (flags_ & kAllButtonMask) != 0; | 642 grab_ = (flags_ & kAllButtonMask) != 0; |
623 } | 643 } |
624 | 644 |
625 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { | 645 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { |
626 gfx::Point p(current_location_); | 646 gfx::Point p(current_location_); |
627 delegate()->ConvertPointToTarget(current_target_, &p); | 647 delegate()->ConvertPointToTarget(current_target_, &p); |
628 return p; | 648 return p; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 return default_delegate; | 706 return default_delegate; |
687 } | 707 } |
688 | 708 |
689 EventGeneratorDelegate* EventGenerator::delegate() { | 709 EventGeneratorDelegate* EventGenerator::delegate() { |
690 return const_cast<EventGeneratorDelegate*>( | 710 return const_cast<EventGeneratorDelegate*>( |
691 const_cast<const EventGenerator*>(this)->delegate()); | 711 const_cast<const EventGenerator*>(this)->delegate()); |
692 } | 712 } |
693 | 713 |
694 } // namespace test | 714 } // namespace test |
695 } // namespace ui | 715 } // namespace ui |
OLD | NEW |