| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { | 162 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { |
| 163 gfx::Point location = GetLocationInCurrentRoot(); | 163 gfx::Point location = GetLocationInCurrentRoot(); |
| 164 ui::MouseWheelEvent wheelev(gfx::Vector2d(delta_x, delta_y), location, | 164 ui::MouseWheelEvent wheelev(gfx::Vector2d(delta_x, delta_y), location, |
| 165 location, ui::EventTimeForNow(), flags_, 0); | 165 location, ui::EventTimeForNow(), flags_, 0); |
| 166 Dispatch(&wheelev); | 166 Dispatch(&wheelev); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void EventGenerator::SendMouseEnter() { | 169 void EventGenerator::SendMouseEnter() { |
| 170 gfx::Point enter_location(current_location_); | 170 gfx::Point enter_location(current_location_); |
| 171 delegate()->ConvertPointToTarget(current_target_, &enter_location); | 171 delegate()->ConvertPointToTarget(current_target_, &enter_location); |
| 172 ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, enter_location, enter_location, | 172 ui::MouseEvent mouseev( |
| 173 ui::EventTimeForNow(), flags_, 0); | 173 ui::ET_MOUSE_ENTERED, enter_location, enter_location, |
| 174 ui::EventTimeForNow(), flags_, 0, |
| 175 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 176 ui::PointerEvent::kMousePointerId)); |
| 174 Dispatch(&mouseev); | 177 Dispatch(&mouseev); |
| 175 } | 178 } |
| 176 | 179 |
| 177 void EventGenerator::SendMouseExit() { | 180 void EventGenerator::SendMouseExit() { |
| 178 gfx::Point exit_location(current_location_); | 181 gfx::Point exit_location(current_location_); |
| 179 delegate()->ConvertPointToTarget(current_target_, &exit_location); | 182 delegate()->ConvertPointToTarget(current_target_, &exit_location); |
| 180 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, | 183 ui::MouseEvent mouseev( |
| 181 ui::EventTimeForNow(), flags_, 0); | 184 ui::ET_MOUSE_EXITED, exit_location, exit_location, ui::EventTimeForNow(), |
| 185 flags_, 0, |
| 186 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 187 ui::PointerEvent::kMousePointerId)); |
| 182 Dispatch(&mouseev); | 188 Dispatch(&mouseev); |
| 183 } | 189 } |
| 184 | 190 |
| 185 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, | 191 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, |
| 186 const gfx::Point& point_for_native) { | 192 const gfx::Point& point_for_native) { |
| 187 #if defined(USE_X11) | 193 #if defined(USE_X11) |
| 188 ui::ScopedXI2Event xevent; | 194 ui::ScopedXI2Event xevent; |
| 189 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); | 195 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); |
| 190 static_cast<XEvent*>(xevent)->xmotion.time = | 196 static_cast<XEvent*>(xevent)->xmotion.time = |
| 191 (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; | 197 (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| 192 ui::MouseEvent mouseev(xevent); | 198 ui::MouseEvent mouseev(xevent); |
| 193 #elif defined(USE_OZONE) | 199 #elif defined(USE_OZONE) |
| 194 // Ozone uses the location in native event as a system location. | 200 // Ozone uses the location in native event as a system location. |
| 195 // Create a fake event with the point in host, which will be passed | 201 // Create a fake event with the point in host, which will be passed |
| 196 // to the non native event, then update the native event with the native | 202 // to the non native event, then update the native event with the native |
| 197 // (root) one. | 203 // (root) one. |
| 198 std::unique_ptr<ui::MouseEvent> native_event( | 204 std::unique_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( |
| 199 new ui::MouseEvent(ui::ET_MOUSE_MOVED, point_in_host, point_in_host, | 205 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, ui::EventTimeForNow(), |
| 200 ui::EventTimeForNow(), flags_, 0)); | 206 flags_, 0, |
| 207 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 208 ui::PointerEvent::kMousePointerId))); |
| 201 ui::MouseEvent mouseev(native_event.get()); | 209 ui::MouseEvent mouseev(native_event.get()); |
| 202 native_event->set_location(point_for_native); | 210 native_event->set_location(point_for_native); |
| 203 #else | 211 #else |
| 204 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, | 212 ui::MouseEvent mouseev( |
| 205 ui::EventTimeForNow(), flags_, 0); | 213 ui::ET_MOUSE_MOVED, point_in_host, point_for_native, |
| 214 ui::EventTimeForNow(), flags_, 0, |
| 215 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 216 ui::PointerEvent::kMousePointerId)); |
| 206 LOG(FATAL) | 217 LOG(FATAL) |
| 207 << "Generating a native motion event is not supported on this platform"; | 218 << "Generating a native motion event is not supported on this platform"; |
| 208 #endif | 219 #endif |
| 209 Dispatch(&mouseev); | 220 Dispatch(&mouseev); |
| 210 | 221 |
| 211 current_location_ = point_in_host; | 222 current_location_ = point_in_host; |
| 212 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); | 223 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); |
| 213 } | 224 } |
| 214 | 225 |
| 215 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { | 226 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { |
| 216 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 227 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
| 217 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 228 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
| 218 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, | 229 ui::MouseEvent mouseev( |
| 219 ui::EventTimeForNow(), flags_, 0); | 230 event_type, point_in_host, point_in_host, ui::EventTimeForNow(), flags_, |
| 231 0, |
| 232 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 233 ui::PointerEvent::kMousePointerId)); |
| 220 Dispatch(&mouseev); | 234 Dispatch(&mouseev); |
| 221 | 235 |
| 222 current_location_ = point_in_host; | 236 current_location_ = point_in_host; |
| 223 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); | 237 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); |
| 224 } | 238 } |
| 225 | 239 |
| 226 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, | 240 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, |
| 227 int count) { | 241 int count) { |
| 228 DCHECK_GT(count, 0); | 242 DCHECK_GT(count, 0); |
| 229 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? | 243 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? |
| 230 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; | 244 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; |
| 231 | 245 |
| 232 gfx::Vector2dF diff(point_in_screen - current_location_); | 246 gfx::Vector2dF diff(point_in_screen - current_location_); |
| 233 for (float i = 1; i <= count; i++) { | 247 for (float i = 1; i <= count; i++) { |
| 234 gfx::Vector2dF step(diff); | 248 gfx::Vector2dF step(diff); |
| 235 step.Scale(i / count); | 249 step.Scale(i / count); |
| 236 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); | 250 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
| 237 if (!grab_) | 251 if (!grab_) |
| 238 UpdateCurrentDispatcher(move_point); | 252 UpdateCurrentDispatcher(move_point); |
| 239 delegate()->ConvertPointToTarget(current_target_, &move_point); | 253 delegate()->ConvertPointToTarget(current_target_, &move_point); |
| 240 ui::MouseEvent mouseev(event_type, move_point, move_point, | 254 ui::MouseEvent mouseev( |
| 241 ui::EventTimeForNow(), flags_, 0); | 255 event_type, move_point, move_point, ui::EventTimeForNow(), flags_, 0, |
| 256 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 257 ui::PointerEvent::kMousePointerId)); |
| 242 Dispatch(&mouseev); | 258 Dispatch(&mouseev); |
| 243 } | 259 } |
| 244 current_location_ = point_in_screen; | 260 current_location_ = point_in_screen; |
| 245 } | 261 } |
| 246 | 262 |
| 247 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, | 263 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, |
| 248 const gfx::Point& point_in_parent) { | 264 const gfx::Point& point_in_parent) { |
| 249 gfx::Point point(point_in_parent); | 265 gfx::Point point(point_in_parent); |
| 250 delegate()->ConvertPointFromTarget(window, &point); | 266 delegate()->ConvertPointFromTarget(window, &point); |
| 251 MoveMouseTo(point); | 267 MoveMouseTo(point); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 673 |
| 658 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 674 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
| 659 current_target_ = delegate()->GetTargetAt(point); | 675 current_target_ = delegate()->GetTargetAt(point); |
| 660 } | 676 } |
| 661 | 677 |
| 662 void EventGenerator::PressButton(int flag) { | 678 void EventGenerator::PressButton(int flag) { |
| 663 if (!(flags_ & flag)) { | 679 if (!(flags_ & flag)) { |
| 664 flags_ |= flag; | 680 flags_ |= flag; |
| 665 grab_ = (flags_ & kAllButtonMask) != 0; | 681 grab_ = (flags_ & kAllButtonMask) != 0; |
| 666 gfx::Point location = GetLocationInCurrentRoot(); | 682 gfx::Point location = GetLocationInCurrentRoot(); |
| 667 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, | 683 ui::MouseEvent mouseev( |
| 668 ui::EventTimeForNow(), flags_, flag); | 684 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), flags_, |
| 685 flag, |
| 686 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 687 ui::PointerEvent::kMousePointerId)); |
| 669 Dispatch(&mouseev); | 688 Dispatch(&mouseev); |
| 670 } | 689 } |
| 671 } | 690 } |
| 672 | 691 |
| 673 void EventGenerator::ReleaseButton(int flag) { | 692 void EventGenerator::ReleaseButton(int flag) { |
| 674 if (flags_ & flag) { | 693 if (flags_ & flag) { |
| 675 gfx::Point location = GetLocationInCurrentRoot(); | 694 gfx::Point location = GetLocationInCurrentRoot(); |
| 676 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, location, | 695 ui::MouseEvent mouseev( |
| 677 ui::EventTimeForNow(), flags_, flag); | 696 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
| 697 flags_, flag, |
| 698 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 699 ui::PointerEvent::kMousePointerId)); |
| 678 Dispatch(&mouseev); | 700 Dispatch(&mouseev); |
| 679 flags_ ^= flag; | 701 flags_ ^= flag; |
| 680 } | 702 } |
| 681 grab_ = (flags_ & kAllButtonMask) != 0; | 703 grab_ = (flags_ & kAllButtonMask) != 0; |
| 682 } | 704 } |
| 683 | 705 |
| 684 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { | 706 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { |
| 685 gfx::Point p(current_location_); | 707 gfx::Point p(current_location_); |
| 686 delegate()->ConvertPointToTarget(current_target_, &p); | 708 delegate()->ConvertPointToTarget(current_target_, &p); |
| 687 return p; | 709 return p; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 return default_delegate; | 786 return default_delegate; |
| 765 } | 787 } |
| 766 | 788 |
| 767 EventGeneratorDelegate* EventGenerator::delegate() { | 789 EventGeneratorDelegate* EventGenerator::delegate() { |
| 768 return const_cast<EventGeneratorDelegate*>( | 790 return const_cast<EventGeneratorDelegate*>( |
| 769 const_cast<const EventGenerator*>(this)->delegate()); | 791 const_cast<const EventGenerator*>(this)->delegate()); |
| 770 } | 792 } |
| 771 | 793 |
| 772 } // namespace test | 794 } // namespace test |
| 773 } // namespace ui | 795 } // namespace ui |
| OLD | NEW |