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 "content/shell/renderer/test_runner/event_sender.h" | 5 #include "content/shell/renderer/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/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/public/common/page_zoom.h" | 10 #include "content/public/common/page_zoom.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 void TouchCancel(); | 389 void TouchCancel(); |
390 void TouchEnd(); | 390 void TouchEnd(); |
391 void LeapForward(int milliseconds); | 391 void LeapForward(int milliseconds); |
392 void BeginDragWithFiles(const std::vector<std::string>& files); | 392 void BeginDragWithFiles(const std::vector<std::string>& files); |
393 void AddTouchPoint(gin::Arguments* args); | 393 void AddTouchPoint(gin::Arguments* args); |
394 void MouseDragBegin(); | 394 void MouseDragBegin(); |
395 void MouseDragEnd(); | 395 void MouseDragEnd(); |
396 void GestureScrollBegin(gin::Arguments* args); | 396 void GestureScrollBegin(gin::Arguments* args); |
397 void GestureScrollEnd(gin::Arguments* args); | 397 void GestureScrollEnd(gin::Arguments* args); |
398 void GestureScrollUpdate(gin::Arguments* args); | 398 void GestureScrollUpdate(gin::Arguments* args); |
| 399 void GesturePinchBegin(gin::Arguments* args); |
| 400 void GesturePinchEnd(gin::Arguments* args); |
| 401 void GesturePinchUpdate(gin::Arguments* args); |
399 void GestureTap(gin::Arguments* args); | 402 void GestureTap(gin::Arguments* args); |
400 void GestureTapDown(gin::Arguments* args); | 403 void GestureTapDown(gin::Arguments* args); |
401 void GestureShowPress(gin::Arguments* args); | 404 void GestureShowPress(gin::Arguments* args); |
402 void GestureTapCancel(gin::Arguments* args); | 405 void GestureTapCancel(gin::Arguments* args); |
403 void GestureLongPress(gin::Arguments* args); | 406 void GestureLongPress(gin::Arguments* args); |
404 void GestureLongTap(gin::Arguments* args); | 407 void GestureLongTap(gin::Arguments* args); |
405 void GestureTwoFingerTap(gin::Arguments* args); | 408 void GestureTwoFingerTap(gin::Arguments* args); |
406 void ContinuousMouseScrollBy(gin::Arguments* args); | 409 void ContinuousMouseScrollBy(gin::Arguments* args); |
407 void MouseMoveTo(gin::Arguments* args); | 410 void MouseMoveTo(gin::Arguments* args); |
408 void TrackpadScrollBegin(); | 411 void TrackpadScrollBegin(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 .SetMethod("touchEnd", &EventSenderBindings::TouchEnd) | 522 .SetMethod("touchEnd", &EventSenderBindings::TouchEnd) |
520 .SetMethod("leapForward", &EventSenderBindings::LeapForward) | 523 .SetMethod("leapForward", &EventSenderBindings::LeapForward) |
521 .SetMethod("beginDragWithFiles", &EventSenderBindings::BeginDragWithFiles) | 524 .SetMethod("beginDragWithFiles", &EventSenderBindings::BeginDragWithFiles) |
522 .SetMethod("addTouchPoint", &EventSenderBindings::AddTouchPoint) | 525 .SetMethod("addTouchPoint", &EventSenderBindings::AddTouchPoint) |
523 .SetMethod("mouseDragBegin", &EventSenderBindings::MouseDragBegin) | 526 .SetMethod("mouseDragBegin", &EventSenderBindings::MouseDragBegin) |
524 .SetMethod("mouseDragEnd", &EventSenderBindings::MouseDragEnd) | 527 .SetMethod("mouseDragEnd", &EventSenderBindings::MouseDragEnd) |
525 .SetMethod("gestureScrollBegin", &EventSenderBindings::GestureScrollBegin) | 528 .SetMethod("gestureScrollBegin", &EventSenderBindings::GestureScrollBegin) |
526 .SetMethod("gestureScrollEnd", &EventSenderBindings::GestureScrollEnd) | 529 .SetMethod("gestureScrollEnd", &EventSenderBindings::GestureScrollEnd) |
527 .SetMethod("gestureScrollUpdate", | 530 .SetMethod("gestureScrollUpdate", |
528 &EventSenderBindings::GestureScrollUpdate) | 531 &EventSenderBindings::GestureScrollUpdate) |
| 532 .SetMethod("gesturePinchBegin", &EventSenderBindings::GesturePinchBegin) |
| 533 .SetMethod("gesturePinchEnd", &EventSenderBindings::GesturePinchEnd) |
| 534 .SetMethod("gesturePinchUpdate", &EventSenderBindings::GesturePinchUpdate) |
529 .SetMethod("gestureTap", &EventSenderBindings::GestureTap) | 535 .SetMethod("gestureTap", &EventSenderBindings::GestureTap) |
530 .SetMethod("gestureTapDown", &EventSenderBindings::GestureTapDown) | 536 .SetMethod("gestureTapDown", &EventSenderBindings::GestureTapDown) |
531 .SetMethod("gestureShowPress", &EventSenderBindings::GestureShowPress) | 537 .SetMethod("gestureShowPress", &EventSenderBindings::GestureShowPress) |
532 .SetMethod("gestureTapCancel", &EventSenderBindings::GestureTapCancel) | 538 .SetMethod("gestureTapCancel", &EventSenderBindings::GestureTapCancel) |
533 .SetMethod("gestureLongPress", &EventSenderBindings::GestureLongPress) | 539 .SetMethod("gestureLongPress", &EventSenderBindings::GestureLongPress) |
534 .SetMethod("gestureLongTap", &EventSenderBindings::GestureLongTap) | 540 .SetMethod("gestureLongTap", &EventSenderBindings::GestureLongTap) |
535 .SetMethod("gestureTwoFingerTap", | 541 .SetMethod("gestureTwoFingerTap", |
536 &EventSenderBindings::GestureTwoFingerTap) | 542 &EventSenderBindings::GestureTwoFingerTap) |
537 .SetMethod("continuousMouseScrollBy", | 543 .SetMethod("continuousMouseScrollBy", |
538 &EventSenderBindings::ContinuousMouseScrollBy) | 544 &EventSenderBindings::ContinuousMouseScrollBy) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 void EventSenderBindings::GestureScrollEnd(gin::Arguments* args) { | 784 void EventSenderBindings::GestureScrollEnd(gin::Arguments* args) { |
779 if (sender_) | 785 if (sender_) |
780 sender_->GestureScrollEnd(args); | 786 sender_->GestureScrollEnd(args); |
781 } | 787 } |
782 | 788 |
783 void EventSenderBindings::GestureScrollUpdate(gin::Arguments* args) { | 789 void EventSenderBindings::GestureScrollUpdate(gin::Arguments* args) { |
784 if (sender_) | 790 if (sender_) |
785 sender_->GestureScrollUpdate(args); | 791 sender_->GestureScrollUpdate(args); |
786 } | 792 } |
787 | 793 |
| 794 void EventSenderBindings::GesturePinchBegin(gin::Arguments* args) { |
| 795 if (sender_) |
| 796 sender_->GesturePinchBegin(args); |
| 797 } |
| 798 |
| 799 void EventSenderBindings::GesturePinchEnd(gin::Arguments* args) { |
| 800 if (sender_) |
| 801 sender_->GesturePinchEnd(args); |
| 802 } |
| 803 |
| 804 void EventSenderBindings::GesturePinchUpdate(gin::Arguments* args) { |
| 805 if (sender_) |
| 806 sender_->GesturePinchUpdate(args); |
| 807 } |
| 808 |
788 void EventSenderBindings::GestureTap(gin::Arguments* args) { | 809 void EventSenderBindings::GestureTap(gin::Arguments* args) { |
789 if (sender_) | 810 if (sender_) |
790 sender_->GestureTap(args); | 811 sender_->GestureTap(args); |
791 } | 812 } |
792 | 813 |
793 void EventSenderBindings::GestureTapDown(gin::Arguments* args) { | 814 void EventSenderBindings::GestureTapDown(gin::Arguments* args) { |
794 if (sender_) | 815 if (sender_) |
795 sender_->GestureTapDown(args); | 816 sender_->GestureTapDown(args); |
796 } | 817 } |
797 | 818 |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1742 } | 1763 } |
1743 | 1764 |
1744 void EventSender::GestureScrollEnd(gin::Arguments* args) { | 1765 void EventSender::GestureScrollEnd(gin::Arguments* args) { |
1745 GestureEvent(WebInputEvent::GestureScrollEnd, args); | 1766 GestureEvent(WebInputEvent::GestureScrollEnd, args); |
1746 } | 1767 } |
1747 | 1768 |
1748 void EventSender::GestureScrollUpdate(gin::Arguments* args) { | 1769 void EventSender::GestureScrollUpdate(gin::Arguments* args) { |
1749 GestureEvent(WebInputEvent::GestureScrollUpdate, args); | 1770 GestureEvent(WebInputEvent::GestureScrollUpdate, args); |
1750 } | 1771 } |
1751 | 1772 |
| 1773 void EventSender::GesturePinchBegin(gin::Arguments* args) { |
| 1774 GestureEvent(WebInputEvent::GesturePinchBegin, args); |
| 1775 } |
| 1776 |
| 1777 void EventSender::GesturePinchEnd(gin::Arguments* args) { |
| 1778 GestureEvent(WebInputEvent::GesturePinchEnd, args); |
| 1779 } |
| 1780 |
| 1781 void EventSender::GesturePinchUpdate(gin::Arguments* args) { |
| 1782 GestureEvent(WebInputEvent::GesturePinchUpdate, args); |
| 1783 } |
| 1784 |
1752 void EventSender::GestureTap(gin::Arguments* args) { | 1785 void EventSender::GestureTap(gin::Arguments* args) { |
1753 GestureEvent(WebInputEvent::GestureTap, args); | 1786 GestureEvent(WebInputEvent::GestureTap, args); |
1754 } | 1787 } |
1755 | 1788 |
1756 void EventSender::GestureTapDown(gin::Arguments* args) { | 1789 void EventSender::GestureTapDown(gin::Arguments* args) { |
1757 GestureEvent(WebInputEvent::GestureTapDown, args); | 1790 GestureEvent(WebInputEvent::GestureTapDown, args); |
1758 } | 1791 } |
1759 | 1792 |
1760 void EventSender::GestureShowPress(gin::Arguments* args) { | 1793 void EventSender::GestureShowPress(gin::Arguments* args) { |
1761 GestureEvent(WebInputEvent::GestureShowPress, args); | 1794 GestureEvent(WebInputEvent::GestureShowPress, args); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 if (touch_point->state == WebTouchPoint::StateReleased) { | 1978 if (touch_point->state == WebTouchPoint::StateReleased) { |
1946 touch_points_.erase(touch_points_.begin() + i); | 1979 touch_points_.erase(touch_points_.begin() + i); |
1947 --i; | 1980 --i; |
1948 } else | 1981 } else |
1949 touch_point->state = WebTouchPoint::StateStationary; | 1982 touch_point->state = WebTouchPoint::StateStationary; |
1950 } | 1983 } |
1951 } | 1984 } |
1952 | 1985 |
1953 void EventSender::GestureEvent(WebInputEvent::Type type, | 1986 void EventSender::GestureEvent(WebInputEvent::Type type, |
1954 gin::Arguments* args) { | 1987 gin::Arguments* args) { |
| 1988 WebGestureEvent event; |
| 1989 event.type = type; |
| 1990 |
| 1991 // If the first argument is a string, it is to specify the device, otherwise |
| 1992 // the device is assumed to be a touchscreen (since most tests were written |
| 1993 // assuming this). |
| 1994 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 1995 if (args->PeekNext()->IsString()) { |
| 1996 std::string device_string; |
| 1997 if (!args->GetNext(&device_string)) { |
| 1998 args->ThrowError(); |
| 1999 return; |
| 2000 } |
| 2001 if (device_string == "touchpad") { |
| 2002 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 2003 } else if (device_string == "touchscreen") { |
| 2004 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 2005 } else { |
| 2006 args->ThrowError(); |
| 2007 return; |
| 2008 } |
| 2009 } |
| 2010 |
1955 double x; | 2011 double x; |
1956 double y; | 2012 double y; |
1957 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2013 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1958 args->ThrowError(); | 2014 args->ThrowError(); |
1959 return; | 2015 return; |
1960 } | 2016 } |
1961 | 2017 |
1962 WebGestureEvent event; | |
1963 event.type = type; | |
1964 | |
1965 switch (type) { | 2018 switch (type) { |
1966 case WebInputEvent::GestureScrollUpdate: | 2019 case WebInputEvent::GestureScrollUpdate: |
1967 { | 2020 { |
1968 bool preventPropagation = false; | 2021 bool preventPropagation = false; |
1969 if (!args->PeekNext().IsEmpty()) { | 2022 if (!args->PeekNext().IsEmpty()) { |
1970 if (!args->GetNext(&preventPropagation)) { | 2023 if (!args->GetNext(&preventPropagation)) { |
1971 args->ThrowError(); | 2024 args->ThrowError(); |
1972 return; | 2025 return; |
1973 } | 2026 } |
1974 } | 2027 } |
(...skipping 12 matching lines...) Expand all Loading... |
1987 case WebInputEvent::GestureScrollBegin: | 2040 case WebInputEvent::GestureScrollBegin: |
1988 current_gesture_location_ = WebPoint(x, y); | 2041 current_gesture_location_ = WebPoint(x, y); |
1989 event.x = current_gesture_location_.x; | 2042 event.x = current_gesture_location_.x; |
1990 event.y = current_gesture_location_.y; | 2043 event.y = current_gesture_location_.y; |
1991 break; | 2044 break; |
1992 case WebInputEvent::GestureScrollEnd: | 2045 case WebInputEvent::GestureScrollEnd: |
1993 case WebInputEvent::GestureFlingStart: | 2046 case WebInputEvent::GestureFlingStart: |
1994 event.x = current_gesture_location_.x; | 2047 event.x = current_gesture_location_.x; |
1995 event.y = current_gesture_location_.y; | 2048 event.y = current_gesture_location_.y; |
1996 break; | 2049 break; |
| 2050 case WebInputEvent::GesturePinchBegin: |
| 2051 case WebInputEvent::GesturePinchEnd: |
| 2052 current_gesture_location_ = WebPoint(x, y); |
| 2053 event.x = current_gesture_location_.x; |
| 2054 event.y = current_gesture_location_.y; |
| 2055 break; |
| 2056 case WebInputEvent::GesturePinchUpdate: |
| 2057 { |
| 2058 float scale = 1; |
| 2059 if (!args->PeekNext().IsEmpty()) { |
| 2060 if (!args->GetNext(&scale)) { |
| 2061 args->ThrowError(); |
| 2062 return; |
| 2063 } |
| 2064 } |
| 2065 event.data.pinchUpdate.scale = scale; |
| 2066 current_gesture_location_ = WebPoint(x, y); |
| 2067 event.x = current_gesture_location_.x; |
| 2068 event.y = current_gesture_location_.y; |
| 2069 break; |
| 2070 } |
1997 case WebInputEvent::GestureTap: | 2071 case WebInputEvent::GestureTap: |
1998 { | 2072 { |
1999 float tap_count = 1; | 2073 float tap_count = 1; |
2000 float width = 30; | 2074 float width = 30; |
2001 float height = 30; | 2075 float height = 30; |
2002 if (!args->PeekNext().IsEmpty()) { | 2076 if (!args->PeekNext().IsEmpty()) { |
2003 if (!args->GetNext(&tap_count)) { | 2077 if (!args->GetNext(&tap_count)) { |
2004 args->ThrowError(); | 2078 args->ThrowError(); |
2005 return; | 2079 return; |
2006 } | 2080 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 | 2420 |
2347 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2421 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
2348 if (WebPagePopup* popup = view_->pagePopup()) { | 2422 if (WebPagePopup* popup = view_->pagePopup()) { |
2349 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2423 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2350 return popup->handleInputEvent(event); | 2424 return popup->handleInputEvent(event); |
2351 } | 2425 } |
2352 return view_->handleInputEvent(event); | 2426 return view_->handleInputEvent(event); |
2353 } | 2427 } |
2354 | 2428 |
2355 } // namespace content | 2429 } // namespace content |
OLD | NEW |