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 "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 event.windowsKeyCode != ui::VKEY_B && | 342 event.windowsKeyCode != ui::VKEY_B && |
343 event.windowsKeyCode != ui::VKEY_I; | 343 event.windowsKeyCode != ui::VKEY_I; |
344 #else | 344 #else |
345 return !!(event.modifiers & WebInputEvent::AltKey); | 345 return !!(event.modifiers & WebInputEvent::AltKey); |
346 #endif | 346 #endif |
347 } | 347 } |
348 | 348 |
349 const char* kSourceDeviceStringTouchpad = "touchpad"; | 349 const char* kSourceDeviceStringTouchpad = "touchpad"; |
350 const char* kSourceDeviceStringTouchscreen = "touchscreen"; | 350 const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
351 | 351 |
352 const char* kPointerTypeStringUnknown = ""; | |
353 const char* kPointerTypeStringMouse = "mouse"; | |
354 const char* kPointerTypeStringPen = "pen"; | |
355 const char* kPointerTypeStringTouch = "touch"; | |
356 | |
352 } // namespace | 357 } // namespace |
353 | 358 |
354 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { | 359 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
355 public: | 360 public: |
356 static gin::WrapperInfo kWrapperInfo; | 361 static gin::WrapperInfo kWrapperInfo; |
357 | 362 |
358 static void Install(base::WeakPtr<EventSender> sender, | 363 static void Install(base::WeakPtr<EventSender> sender, |
359 blink::WebFrame* frame); | 364 blink::WebFrame* frame); |
360 | 365 |
361 private: | 366 private: |
362 explicit EventSenderBindings(base::WeakPtr<EventSender> sender); | 367 explicit EventSenderBindings(base::WeakPtr<EventSender> sender); |
363 ~EventSenderBindings() override; | 368 ~EventSenderBindings() override; |
364 | 369 |
365 // gin::Wrappable: | 370 // gin::Wrappable: |
366 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 371 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
367 v8::Isolate* isolate) override; | 372 v8::Isolate* isolate) override; |
368 | 373 |
369 // Bound methods: | 374 // Bound methods: |
370 void EnableDOMUIEventLogging(); | 375 void EnableDOMUIEventLogging(); |
371 void FireKeyboardEventsToElement(); | 376 void FireKeyboardEventsToElement(); |
372 void ClearKillRing(); | 377 void ClearKillRing(); |
373 std::vector<std::string> ContextClick(); | 378 std::vector<std::string> ContextClick(); |
374 void TextZoomIn(); | 379 void TextZoomIn(); |
375 void TextZoomOut(); | 380 void TextZoomOut(); |
376 void ZoomPageIn(); | 381 void ZoomPageIn(); |
377 void ZoomPageOut(); | 382 void ZoomPageOut(); |
378 void SetPageZoomFactor(double factor); | 383 void SetPageZoomFactor(double factor); |
379 void ClearTouchPoints(); | 384 void ClearTouchPoints(); |
380 void ReleaseTouchPoint(unsigned index); | 385 void ReleaseTouchPoint(unsigned index); |
381 void UpdateTouchPoint(unsigned index, double x, double y); | 386 void UpdateTouchPoint(unsigned index, |
387 double x, | |
388 double y, | |
389 gin::Arguments* args); | |
382 void CancelTouchPoint(unsigned index); | 390 void CancelTouchPoint(unsigned index); |
383 void SetTouchModifier(const std::string& key_name, bool set_mask); | 391 void SetTouchModifier(const std::string& key_name, bool set_mask); |
384 void SetTouchCancelable(bool cancelable); | 392 void SetTouchCancelable(bool cancelable); |
385 void DumpFilenameBeingDragged(); | 393 void DumpFilenameBeingDragged(); |
386 void GestureFlingCancel(); | 394 void GestureFlingCancel(); |
387 void GestureFlingStart(float x, | 395 void GestureFlingStart(float x, |
388 float y, | 396 float y, |
389 float velocity_x, | 397 float velocity_x, |
390 float velocity_y, | 398 float velocity_y, |
391 gin::Arguments* args); | 399 gin::Arguments* args); |
392 void GestureScrollFirstPoint(int x, int y); | 400 void GestureScrollFirstPoint(int x, int y); |
393 void TouchStart(); | 401 void TouchStart(); |
394 void TouchMove(); | 402 void TouchMove(); |
395 void TouchMoveCausingScrollIfUncanceled(); | 403 void TouchMoveCausingScrollIfUncanceled(); |
396 void TouchCancel(); | 404 void TouchCancel(); |
397 void TouchEnd(); | 405 void TouchEnd(); |
398 void LeapForward(int milliseconds); | 406 void LeapForward(int milliseconds); |
399 void BeginDragWithFiles(const std::vector<std::string>& files); | 407 void BeginDragWithFiles(const std::vector<std::string>& files); |
400 void AddTouchPoint(gin::Arguments* args); | 408 void AddTouchPoint(double x, double y, gin::Arguments* args); |
401 void MouseDragBegin(); | 409 void MouseDragBegin(); |
402 void MouseDragEnd(); | 410 void MouseDragEnd(); |
403 void GestureScrollBegin(gin::Arguments* args); | 411 void GestureScrollBegin(gin::Arguments* args); |
404 void GestureScrollEnd(gin::Arguments* args); | 412 void GestureScrollEnd(gin::Arguments* args); |
405 void GestureScrollUpdate(gin::Arguments* args); | 413 void GestureScrollUpdate(gin::Arguments* args); |
406 void GesturePinchBegin(gin::Arguments* args); | 414 void GesturePinchBegin(gin::Arguments* args); |
407 void GesturePinchEnd(gin::Arguments* args); | 415 void GesturePinchEnd(gin::Arguments* args); |
408 void GesturePinchUpdate(gin::Arguments* args); | 416 void GesturePinchUpdate(gin::Arguments* args); |
409 void GestureTap(gin::Arguments* args); | 417 void GestureTap(gin::Arguments* args); |
410 void GestureTapDown(gin::Arguments* args); | 418 void GestureTapDown(gin::Arguments* args); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 void EventSenderBindings::ClearTouchPoints() { | 653 void EventSenderBindings::ClearTouchPoints() { |
646 if (sender_) | 654 if (sender_) |
647 sender_->ClearTouchPoints(); | 655 sender_->ClearTouchPoints(); |
648 } | 656 } |
649 | 657 |
650 void EventSenderBindings::ReleaseTouchPoint(unsigned index) { | 658 void EventSenderBindings::ReleaseTouchPoint(unsigned index) { |
651 if (sender_) | 659 if (sender_) |
652 sender_->ReleaseTouchPoint(index); | 660 sender_->ReleaseTouchPoint(index); |
653 } | 661 } |
654 | 662 |
655 void EventSenderBindings::UpdateTouchPoint(unsigned index, double x, double y) { | 663 void EventSenderBindings::UpdateTouchPoint(unsigned index, |
664 double x, | |
665 double y, | |
666 gin::Arguments* args) { | |
656 if (sender_) { | 667 if (sender_) { |
657 sender_->UpdateTouchPoint(index, static_cast<float>(x), | 668 sender_->UpdateTouchPoint(index, static_cast<float>(x), |
658 static_cast<float>(y)); | 669 static_cast<float>(y), args); |
659 } | 670 } |
660 } | 671 } |
661 | 672 |
662 void EventSenderBindings::CancelTouchPoint(unsigned index) { | 673 void EventSenderBindings::CancelTouchPoint(unsigned index) { |
663 if (sender_) | 674 if (sender_) |
664 sender_->CancelTouchPoint(index); | 675 sender_->CancelTouchPoint(index); |
665 } | 676 } |
666 | 677 |
667 void EventSenderBindings::SetTouchModifier(const std::string& key_name, | 678 void EventSenderBindings::SetTouchModifier(const std::string& key_name, |
668 bool set_mask) { | 679 bool set_mask) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 if (sender_) | 739 if (sender_) |
729 sender_->LeapForward(milliseconds); | 740 sender_->LeapForward(milliseconds); |
730 } | 741 } |
731 | 742 |
732 void EventSenderBindings::BeginDragWithFiles( | 743 void EventSenderBindings::BeginDragWithFiles( |
733 const std::vector<std::string>& files) { | 744 const std::vector<std::string>& files) { |
734 if (sender_) | 745 if (sender_) |
735 sender_->BeginDragWithFiles(files); | 746 sender_->BeginDragWithFiles(files); |
736 } | 747 } |
737 | 748 |
738 void EventSenderBindings::AddTouchPoint(gin::Arguments* args) { | 749 void EventSenderBindings::AddTouchPoint(double x, |
750 double y, | |
751 gin::Arguments* args) { | |
739 if (sender_) | 752 if (sender_) |
740 sender_->AddTouchPoint(args); | 753 sender_->AddTouchPoint(static_cast<float>(x), static_cast<float>(y), args); |
741 } | 754 } |
742 | 755 |
743 void EventSenderBindings::MouseDragBegin() { | 756 void EventSenderBindings::MouseDragBegin() { |
744 if (sender_) | 757 if (sender_) |
745 sender_->MouseDragBegin(); | 758 sender_->MouseDragBegin(); |
746 } | 759 } |
747 | 760 |
748 void EventSenderBindings::MouseDragEnd() { | 761 void EventSenderBindings::MouseDragEnd() { |
749 if (sender_) | 762 if (sender_) |
750 sender_->MouseDragEnd(); | 763 sender_->MouseDragEnd(); |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1550 void EventSender::ReleaseTouchPoint(unsigned index) { | 1563 void EventSender::ReleaseTouchPoint(unsigned index) { |
1551 if (index >= touch_points_.size()) { | 1564 if (index >= touch_points_.size()) { |
1552 ThrowTouchPointError(); | 1565 ThrowTouchPointError(); |
1553 return; | 1566 return; |
1554 } | 1567 } |
1555 | 1568 |
1556 WebTouchPoint* touch_point = &touch_points_[index]; | 1569 WebTouchPoint* touch_point = &touch_points_[index]; |
1557 touch_point->state = WebTouchPoint::StateReleased; | 1570 touch_point->state = WebTouchPoint::StateReleased; |
1558 } | 1571 } |
1559 | 1572 |
1560 void EventSender::UpdateTouchPoint(unsigned index, float x, float y) { | 1573 void EventSender::UpdateTouchPoint(unsigned index, |
1574 float x, | |
1575 float y, | |
1576 gin::Arguments* args) { | |
1561 if (index >= touch_points_.size()) { | 1577 if (index >= touch_points_.size()) { |
1562 ThrowTouchPointError(); | 1578 ThrowTouchPointError(); |
1563 return; | 1579 return; |
1564 } | 1580 } |
1565 | 1581 |
1566 WebTouchPoint* touch_point = &touch_points_[index]; | 1582 WebTouchPoint* touch_point = &touch_points_[index]; |
1567 touch_point->state = WebTouchPoint::StateMoved; | 1583 touch_point->state = WebTouchPoint::StateMoved; |
1568 touch_point->position = WebFloatPoint(x, y); | 1584 touch_point->position = WebFloatPoint(x, y); |
1569 touch_point->screenPosition = touch_point->position; | 1585 touch_point->screenPosition = touch_point->position; |
1586 | |
1587 InitPointerProperties(args, touch_point, &touch_point->radiusX, | |
1588 &touch_point->radiusY); | |
1570 } | 1589 } |
1571 | 1590 |
1572 void EventSender::CancelTouchPoint(unsigned index) { | 1591 void EventSender::CancelTouchPoint(unsigned index) { |
1573 if (index >= touch_points_.size()) { | 1592 if (index >= touch_points_.size()) { |
1574 ThrowTouchPointError(); | 1593 ThrowTouchPointError(); |
1575 return; | 1594 return; |
1576 } | 1595 } |
1577 | 1596 |
1578 WebTouchPoint* touch_point = &touch_points_[index]; | 1597 WebTouchPoint* touch_point = &touch_points_[index]; |
1579 touch_point->state = WebTouchPoint::StateCancelled; | 1598 touch_point->state = WebTouchPoint::StateCancelled; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1721 current_drag_effects_allowed_, | 1740 current_drag_effects_allowed_, |
1722 0); | 1741 0); |
1723 // |is_drag_mode_| saves events and then replays them later. We don't | 1742 // |is_drag_mode_| saves events and then replays them later. We don't |
1724 // need/want that. | 1743 // need/want that. |
1725 is_drag_mode_ = false; | 1744 is_drag_mode_ = false; |
1726 | 1745 |
1727 // Make the rest of eventSender think a drag is in progress. | 1746 // Make the rest of eventSender think a drag is in progress. |
1728 pressed_button_ = WebMouseEvent::ButtonLeft; | 1747 pressed_button_ = WebMouseEvent::ButtonLeft; |
1729 } | 1748 } |
1730 | 1749 |
1731 void EventSender::AddTouchPoint(gin::Arguments* args) { | 1750 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { |
1732 double x; | |
1733 double y; | |
1734 if (!args->GetNext(&x) || !args->GetNext(&y)) { | |
1735 args->ThrowError(); | |
1736 return; | |
1737 } | |
1738 | |
1739 WebTouchPoint touch_point; | 1751 WebTouchPoint touch_point; |
1740 touch_point.state = WebTouchPoint::StatePressed; | 1752 touch_point.state = WebTouchPoint::StatePressed; |
1741 touch_point.position = WebFloatPoint(static_cast<float>(x), | 1753 touch_point.position = WebFloatPoint(x, y); |
1742 static_cast<float>(y)); | |
1743 touch_point.screenPosition = touch_point.position; | 1754 touch_point.screenPosition = touch_point.position; |
1744 | 1755 |
1745 if (!args->PeekNext().IsEmpty()) { | |
1746 double radius_x; | |
1747 if (!args->GetNext(&radius_x)) { | |
1748 args->ThrowError(); | |
1749 return; | |
1750 } | |
1751 | |
1752 double radius_y = radius_x; | |
1753 if (!args->PeekNext().IsEmpty()) { | |
1754 if (!args->GetNext(&radius_y)) { | |
1755 args->ThrowError(); | |
1756 return; | |
1757 } | |
1758 } | |
1759 | |
1760 touch_point.radiusX = static_cast<float>(radius_x); | |
1761 touch_point.radiusY = static_cast<float>(radius_y); | |
1762 } | |
1763 | |
1764 int lowest_id = 0; | 1756 int lowest_id = 0; |
1765 for (size_t i = 0; i < touch_points_.size(); i++) { | 1757 for (size_t i = 0; i < touch_points_.size(); i++) { |
1766 if (touch_points_[i].id == lowest_id) | 1758 if (touch_points_[i].id == lowest_id) |
mustaq
2015/07/29 17:11:34
This is not your code, but seems brittle: could ge
USE eero AT chromium.org
2015/07/29 17:39:37
Done.
| |
1767 lowest_id++; | 1759 lowest_id++; |
1768 } | 1760 } |
1769 touch_point.id = lowest_id; | 1761 touch_point.id = lowest_id; |
1762 | |
1763 InitPointerProperties(args, &touch_point, &touch_point.radiusX, | |
1764 &touch_point.radiusY); | |
1765 | |
1770 touch_points_.push_back(touch_point); | 1766 touch_points_.push_back(touch_point); |
1771 } | 1767 } |
1772 | 1768 |
1773 void EventSender::MouseDragBegin() { | 1769 void EventSender::MouseDragBegin() { |
1774 WebMouseWheelEvent event; | 1770 WebMouseWheelEvent event; |
1775 InitMouseEvent(WebInputEvent::MouseWheel, | 1771 InitMouseEvent(WebInputEvent::MouseWheel, |
1776 WebMouseEvent::ButtonNone, | 1772 WebMouseEvent::ButtonNone, |
1777 last_mouse_pos_, | 1773 last_mouse_pos_, |
1778 GetCurrentEventTimeSec(), | 1774 GetCurrentEventTimeSec(), |
1779 click_count_, | 1775 click_count_, |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2374 event->canScroll = can_scroll; | 2370 event->canScroll = can_scroll; |
2375 if (continuous) { | 2371 if (continuous) { |
2376 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2372 event->wheelTicksX /= kScrollbarPixelsPerTick; |
2377 event->wheelTicksY /= kScrollbarPixelsPerTick; | 2373 event->wheelTicksY /= kScrollbarPixelsPerTick; |
2378 } else { | 2374 } else { |
2379 event->deltaX *= kScrollbarPixelsPerTick; | 2375 event->deltaX *= kScrollbarPixelsPerTick; |
2380 event->deltaY *= kScrollbarPixelsPerTick; | 2376 event->deltaY *= kScrollbarPixelsPerTick; |
2381 } | 2377 } |
2382 } | 2378 } |
2383 | 2379 |
2380 void EventSender::InitPointerProperties(gin::Arguments* args, | |
2381 blink::WebPointerProperties* e, | |
2382 float* radius_x_pointer, | |
mustaq
2015/07/29 17:11:34
Setting the fields radiusX & radiusY here appears
USE eero AT chromium.org
2015/07/29 17:39:37
Done.
| |
2383 float* radius_y_pointer) { | |
2384 if (!args->PeekNext().IsEmpty()) { | |
2385 double radius_x; | |
2386 if (!args->GetNext(&radius_x)) { | |
2387 args->ThrowError(); | |
2388 return; | |
2389 } | |
2390 | |
2391 double radius_y = radius_x; | |
2392 if (!args->PeekNext().IsEmpty()) { | |
2393 if (!args->GetNext(&radius_y)) { | |
2394 args->ThrowError(); | |
2395 return; | |
2396 } | |
2397 } | |
2398 | |
2399 *radius_x_pointer = static_cast<float>(radius_x); | |
2400 *radius_y_pointer = static_cast<float>(radius_y); | |
2401 } | |
2402 | |
2403 if (!args->PeekNext().IsEmpty()) { | |
2404 double force; | |
2405 if (!args->GetNext(&force)) { | |
2406 args->ThrowError(); | |
2407 return; | |
2408 } | |
2409 e->force = static_cast<float>(force); | |
2410 } | |
2411 | |
2412 if (!args->PeekNext().IsEmpty()) { | |
2413 int tiltX, tiltY; | |
2414 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { | |
2415 args->ThrowError(); | |
2416 return; | |
2417 } | |
2418 e->tiltX = tiltX; | |
2419 e->tiltY = tiltY; | |
2420 } | |
2421 | |
2422 if (!args->PeekNext().IsEmpty()) { | |
2423 std::string pointer_type_string; | |
2424 if (!args->GetNext(&pointer_type_string)) { | |
2425 args->ThrowError(); | |
2426 return; | |
2427 } | |
2428 if (pointer_type_string == kPointerTypeStringUnknown) { | |
2429 e->pointerType = WebMouseEvent::PointerTypeUnknown; | |
2430 } else if (pointer_type_string == kPointerTypeStringMouse) { | |
2431 e->pointerType = WebMouseEvent::PointerTypeMouse; | |
2432 } else if (pointer_type_string == kPointerTypeStringPen) { | |
2433 e->pointerType = WebMouseEvent::PointerTypePen; | |
2434 } else if (pointer_type_string == kPointerTypeStringTouch) { | |
2435 e->pointerType = WebMouseEvent::PointerTypeTouch; | |
2436 } else { | |
2437 args->ThrowError(); | |
2438 return; | |
2439 } | |
2440 } | |
2441 } | |
2442 | |
2384 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2443 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, |
2385 blink::WebDragOperation drag_effect) { | 2444 blink::WebDragOperation drag_effect) { |
2386 WebPoint client_point(e.x, e.y); | 2445 WebPoint client_point(e.x, e.y); |
2387 WebPoint screen_point(e.globalX, e.globalY); | 2446 WebPoint screen_point(e.globalX, e.globalY); |
2388 current_drag_effect_ = drag_effect; | 2447 current_drag_effect_ = drag_effect; |
2389 if (current_drag_effect_) { | 2448 if (current_drag_effect_) { |
2390 // Specifically pass any keyboard modifiers to the drop method. This allows | 2449 // Specifically pass any keyboard modifiers to the drop method. This allows |
2391 // tests to control the drop type (i.e. copy or move). | 2450 // tests to control the drop type (i.e. copy or move). |
2392 view_->dragTargetDrop(client_point, screen_point, e.modifiers); | 2451 view_->dragTargetDrop(client_point, screen_point, e.modifiers); |
2393 } else { | 2452 } else { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2481 | 2540 |
2482 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2541 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
2483 if (WebPagePopup* popup = view_->pagePopup()) { | 2542 if (WebPagePopup* popup = view_->pagePopup()) { |
2484 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2543 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2485 return popup->handleInputEvent(event); | 2544 return popup->handleInputEvent(event); |
2486 } | 2545 } |
2487 return view_->handleInputEvent(event); | 2546 return view_->handleInputEvent(event); |
2488 } | 2547 } |
2489 | 2548 |
2490 } // namespace test_runner | 2549 } // namespace test_runner |
OLD | NEW |