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 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 // need/want that. | 1633 // need/want that. |
1634 is_drag_mode_ = false; | 1634 is_drag_mode_ = false; |
1635 | 1635 |
1636 // Make the rest of eventSender think a drag is in progress. | 1636 // Make the rest of eventSender think a drag is in progress. |
1637 pressed_button_ = WebMouseEvent::ButtonLeft; | 1637 pressed_button_ = WebMouseEvent::ButtonLeft; |
1638 } | 1638 } |
1639 | 1639 |
1640 void EventSender::AddTouchPoint(gin::Arguments* args) { | 1640 void EventSender::AddTouchPoint(gin::Arguments* args) { |
1641 double x; | 1641 double x; |
1642 double y; | 1642 double y; |
1643 args->GetNext(&x); | 1643 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1644 args->GetNext(&y); | 1644 args->ThrowError(); |
| 1645 return; |
| 1646 } |
1645 | 1647 |
1646 WebTouchPoint touch_point; | 1648 WebTouchPoint touch_point; |
1647 touch_point.state = WebTouchPoint::StatePressed; | 1649 touch_point.state = WebTouchPoint::StatePressed; |
1648 touch_point.position = WebFloatPoint(static_cast<float>(x), | 1650 touch_point.position = WebFloatPoint(static_cast<float>(x), |
1649 static_cast<float>(y)); | 1651 static_cast<float>(y)); |
1650 touch_point.screenPosition = touch_point.position; | 1652 touch_point.screenPosition = touch_point.position; |
1651 | 1653 |
1652 if (!args->PeekNext().IsEmpty()) { | 1654 if (!args->PeekNext().IsEmpty()) { |
1653 double radius_x; | 1655 double radius_x; |
1654 if (!args->GetNext(&radius_x)) { | 1656 if (!args->GetNext(&radius_x)) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 InitMouseWheelEvent(args, true, &event); | 1756 InitMouseWheelEvent(args, true, &event); |
1755 view_->handleInputEvent(event); | 1757 view_->handleInputEvent(event); |
1756 } | 1758 } |
1757 | 1759 |
1758 void EventSender::MouseMoveTo(gin::Arguments* args) { | 1760 void EventSender::MouseMoveTo(gin::Arguments* args) { |
1759 if (force_layout_on_events_) | 1761 if (force_layout_on_events_) |
1760 view_->layout(); | 1762 view_->layout(); |
1761 | 1763 |
1762 double x; | 1764 double x; |
1763 double y; | 1765 double y; |
1764 args->GetNext(&x); | 1766 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1765 args->GetNext(&y); | 1767 args->ThrowError(); |
| 1768 return; |
| 1769 } |
1766 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); | 1770 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
1767 | 1771 |
1768 int modifiers = 0; | 1772 int modifiers = 0; |
1769 if (!args->PeekNext().IsEmpty()) | 1773 if (!args->PeekNext().IsEmpty()) |
1770 modifiers = GetKeyModifiersFromV8(args->PeekNext()); | 1774 modifiers = GetKeyModifiersFromV8(args->PeekNext()); |
1771 | 1775 |
1772 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 1776 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && |
1773 !replaying_saved_events_) { | 1777 !replaying_saved_events_) { |
1774 SavedEvent saved_event; | 1778 SavedEvent saved_event; |
1775 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | 1779 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 --i; | 1921 --i; |
1918 } else | 1922 } else |
1919 touch_point->state = WebTouchPoint::StateStationary; | 1923 touch_point->state = WebTouchPoint::StateStationary; |
1920 } | 1924 } |
1921 } | 1925 } |
1922 | 1926 |
1923 void EventSender::GestureEvent(WebInputEvent::Type type, | 1927 void EventSender::GestureEvent(WebInputEvent::Type type, |
1924 gin::Arguments* args) { | 1928 gin::Arguments* args) { |
1925 double x; | 1929 double x; |
1926 double y; | 1930 double y; |
1927 args->GetNext(&x); | 1931 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1928 args->GetNext(&y); | 1932 args->ThrowError(); |
1929 WebPoint point(x, y); | 1933 return; |
| 1934 } |
1930 | 1935 |
1931 WebGestureEvent event; | 1936 WebGestureEvent event; |
1932 event.type = type; | 1937 event.type = type; |
1933 | 1938 |
1934 switch (type) { | 1939 switch (type) { |
1935 case WebInputEvent::GestureScrollUpdate: | 1940 case WebInputEvent::GestureScrollUpdate: |
1936 case WebInputEvent::GestureScrollUpdateWithoutPropagation: | 1941 case WebInputEvent::GestureScrollUpdateWithoutPropagation: |
1937 event.data.scrollUpdate.deltaX = static_cast<float>(x); | 1942 event.data.scrollUpdate.deltaX = static_cast<float>(x); |
1938 event.data.scrollUpdate.deltaY = static_cast<float>(y); | 1943 event.data.scrollUpdate.deltaY = static_cast<float>(y); |
1939 event.x = current_gesture_location_.x; | 1944 event.x = current_gesture_location_.x; |
1940 event.y = current_gesture_location_.y; | 1945 event.y = current_gesture_location_.y; |
1941 current_gesture_location_.x = | 1946 current_gesture_location_.x = |
1942 current_gesture_location_.x + event.data.scrollUpdate.deltaX; | 1947 current_gesture_location_.x + event.data.scrollUpdate.deltaX; |
1943 current_gesture_location_.y = | 1948 current_gesture_location_.y = |
1944 current_gesture_location_.y + event.data.scrollUpdate.deltaY; | 1949 current_gesture_location_.y + event.data.scrollUpdate.deltaY; |
1945 break; | 1950 break; |
1946 case WebInputEvent::GestureScrollBegin: | 1951 case WebInputEvent::GestureScrollBegin: |
1947 current_gesture_location_ = WebPoint(point.x, point.y); | 1952 current_gesture_location_ = WebPoint(x, y); |
1948 event.x = current_gesture_location_.x; | 1953 event.x = current_gesture_location_.x; |
1949 event.y = current_gesture_location_.y; | 1954 event.y = current_gesture_location_.y; |
1950 break; | 1955 break; |
1951 case WebInputEvent::GestureScrollEnd: | 1956 case WebInputEvent::GestureScrollEnd: |
1952 case WebInputEvent::GestureFlingStart: | 1957 case WebInputEvent::GestureFlingStart: |
1953 event.x = current_gesture_location_.x; | 1958 event.x = current_gesture_location_.x; |
1954 event.y = current_gesture_location_.y; | 1959 event.y = current_gesture_location_.y; |
1955 break; | 1960 break; |
1956 case WebInputEvent::GestureTap: | 1961 case WebInputEvent::GestureTap: |
1957 { | 1962 { |
(...skipping 14 matching lines...) Expand all Loading... |
1972 } | 1977 } |
1973 if (!args->PeekNext().IsEmpty()) { | 1978 if (!args->PeekNext().IsEmpty()) { |
1974 if (!args->GetNext(&height)) { | 1979 if (!args->GetNext(&height)) { |
1975 args->ThrowError(); | 1980 args->ThrowError(); |
1976 return; | 1981 return; |
1977 } | 1982 } |
1978 } | 1983 } |
1979 event.data.tap.tapCount = tap_count; | 1984 event.data.tap.tapCount = tap_count; |
1980 event.data.tap.width = width; | 1985 event.data.tap.width = width; |
1981 event.data.tap.height = height; | 1986 event.data.tap.height = height; |
1982 event.x = point.x; | 1987 event.x = x; |
1983 event.y = point.y; | 1988 event.y = y; |
1984 break; | 1989 break; |
1985 } | 1990 } |
1986 case WebInputEvent::GestureTapUnconfirmed: | 1991 case WebInputEvent::GestureTapUnconfirmed: |
1987 if (!args->PeekNext().IsEmpty()) { | 1992 if (!args->PeekNext().IsEmpty()) { |
1988 float tap_count; | 1993 float tap_count; |
1989 if (!args->GetNext(&tap_count)) { | 1994 if (!args->GetNext(&tap_count)) { |
1990 args->ThrowError(); | 1995 args->ThrowError(); |
1991 return; | 1996 return; |
1992 } | 1997 } |
1993 event.data.tap.tapCount = tap_count; | 1998 event.data.tap.tapCount = tap_count; |
1994 } else { | 1999 } else { |
1995 event.data.tap.tapCount = 1; | 2000 event.data.tap.tapCount = 1; |
1996 } | 2001 } |
1997 event.x = point.x; | 2002 event.x = x; |
1998 event.y = point.y; | 2003 event.y = y; |
1999 break; | 2004 break; |
2000 case WebInputEvent::GestureTapDown: | 2005 case WebInputEvent::GestureTapDown: |
2001 { | 2006 { |
2002 float width = 30; | 2007 float width = 30; |
2003 float height = 30; | 2008 float height = 30; |
2004 if (!args->PeekNext().IsEmpty()) { | 2009 if (!args->PeekNext().IsEmpty()) { |
2005 if (!args->GetNext(&width)) { | 2010 if (!args->GetNext(&width)) { |
2006 args->ThrowError(); | 2011 args->ThrowError(); |
2007 return; | 2012 return; |
2008 } | 2013 } |
2009 } | 2014 } |
2010 if (!args->PeekNext().IsEmpty()) { | 2015 if (!args->PeekNext().IsEmpty()) { |
2011 if (!args->GetNext(&height)) { | 2016 if (!args->GetNext(&height)) { |
2012 args->ThrowError(); | 2017 args->ThrowError(); |
2013 return; | 2018 return; |
2014 } | 2019 } |
2015 } | 2020 } |
2016 event.x = point.x; | 2021 event.x = x; |
2017 event.y = point.y; | 2022 event.y = y; |
2018 event.data.tapDown.width = width; | 2023 event.data.tapDown.width = width; |
2019 event.data.tapDown.height = height; | 2024 event.data.tapDown.height = height; |
2020 break; | 2025 break; |
2021 } | 2026 } |
2022 case WebInputEvent::GestureShowPress: | 2027 case WebInputEvent::GestureShowPress: |
2023 { | 2028 { |
2024 float width = 30; | 2029 float width = 30; |
2025 float height = 30; | 2030 float height = 30; |
2026 if (!args->PeekNext().IsEmpty()) { | 2031 if (!args->PeekNext().IsEmpty()) { |
2027 if (!args->GetNext(&width)) { | 2032 if (!args->GetNext(&width)) { |
2028 args->ThrowError(); | 2033 args->ThrowError(); |
2029 return; | 2034 return; |
2030 } | 2035 } |
2031 if (!args->PeekNext().IsEmpty()) { | 2036 if (!args->PeekNext().IsEmpty()) { |
2032 if (!args->GetNext(&height)) { | 2037 if (!args->GetNext(&height)) { |
2033 args->ThrowError(); | 2038 args->ThrowError(); |
2034 return; | 2039 return; |
2035 } | 2040 } |
2036 } | 2041 } |
2037 } | 2042 } |
2038 event.x = point.x; | 2043 event.x = x; |
2039 event.y = point.y; | 2044 event.y = y; |
2040 event.data.showPress.width = width; | 2045 event.data.showPress.width = width; |
2041 event.data.showPress.height = height; | 2046 event.data.showPress.height = height; |
2042 break; | 2047 break; |
2043 } | 2048 } |
2044 case WebInputEvent::GestureTapCancel: | 2049 case WebInputEvent::GestureTapCancel: |
2045 event.x = point.x; | 2050 event.x = x; |
2046 event.y = point.y; | 2051 event.y = y; |
2047 break; | 2052 break; |
2048 case WebInputEvent::GestureLongPress: | 2053 case WebInputEvent::GestureLongPress: |
2049 event.x = point.x; | 2054 event.x = x; |
2050 event.y = point.y; | 2055 event.y = y; |
2051 if (!args->PeekNext().IsEmpty()) { | 2056 if (!args->PeekNext().IsEmpty()) { |
2052 float width; | 2057 float width; |
2053 if (!args->GetNext(&width)) { | 2058 if (!args->GetNext(&width)) { |
2054 args->ThrowError(); | 2059 args->ThrowError(); |
2055 return; | 2060 return; |
2056 } | 2061 } |
2057 event.data.longPress.width = width; | 2062 event.data.longPress.width = width; |
2058 if (!args->PeekNext().IsEmpty()) { | 2063 if (!args->PeekNext().IsEmpty()) { |
2059 float height; | 2064 float height; |
2060 if (!args->GetNext(&height)) { | 2065 if (!args->GetNext(&height)) { |
2061 args->ThrowError(); | 2066 args->ThrowError(); |
2062 return; | 2067 return; |
2063 } | 2068 } |
2064 event.data.longPress.height = height; | 2069 event.data.longPress.height = height; |
2065 } | 2070 } |
2066 } | 2071 } |
2067 break; | 2072 break; |
2068 case WebInputEvent::GestureLongTap: | 2073 case WebInputEvent::GestureLongTap: |
2069 event.x = point.x; | 2074 event.x = x; |
2070 event.y = point.y; | 2075 event.y = y; |
2071 if (!args->PeekNext().IsEmpty()) { | 2076 if (!args->PeekNext().IsEmpty()) { |
2072 float width; | 2077 float width; |
2073 if (!args->GetNext(&width)) { | 2078 if (!args->GetNext(&width)) { |
2074 args->ThrowError(); | 2079 args->ThrowError(); |
2075 return; | 2080 return; |
2076 } | 2081 } |
2077 event.data.longPress.width = width; | 2082 event.data.longPress.width = width; |
2078 if (!args->PeekNext().IsEmpty()) { | 2083 if (!args->PeekNext().IsEmpty()) { |
2079 float height; | 2084 float height; |
2080 if (!args->GetNext(&height)) { | 2085 if (!args->GetNext(&height)) { |
2081 args->ThrowError(); | 2086 args->ThrowError(); |
2082 return; | 2087 return; |
2083 } | 2088 } |
2084 event.data.longPress.height = height; | 2089 event.data.longPress.height = height; |
2085 } | 2090 } |
2086 } | 2091 } |
2087 break; | 2092 break; |
2088 case WebInputEvent::GestureTwoFingerTap: | 2093 case WebInputEvent::GestureTwoFingerTap: |
2089 event.x = point.x; | 2094 event.x = x; |
2090 event.y = point.y; | 2095 event.y = y; |
2091 if (!args->PeekNext().IsEmpty()) { | 2096 if (!args->PeekNext().IsEmpty()) { |
2092 float first_finger_width; | 2097 float first_finger_width; |
2093 if (!args->GetNext(&first_finger_width)) { | 2098 if (!args->GetNext(&first_finger_width)) { |
2094 args->ThrowError(); | 2099 args->ThrowError(); |
2095 return; | 2100 return; |
2096 } | 2101 } |
2097 event.data.twoFingerTap.firstFingerWidth = first_finger_width; | 2102 event.data.twoFingerTap.firstFingerWidth = first_finger_width; |
2098 if (!args->PeekNext().IsEmpty()) { | 2103 if (!args->PeekNext().IsEmpty()) { |
2099 float first_finger_height; | 2104 float first_finger_height; |
2100 if (!args->GetNext(&first_finger_height)) { | 2105 if (!args->GetNext(&first_finger_height)) { |
(...skipping 15 matching lines...) Expand all Loading... |
2116 if (force_layout_on_events_) | 2121 if (force_layout_on_events_) |
2117 view_->layout(); | 2122 view_->layout(); |
2118 | 2123 |
2119 bool result = view_->handleInputEvent(event); | 2124 bool result = view_->handleInputEvent(event); |
2120 | 2125 |
2121 // Long press might start a drag drop session. Complete it if so. | 2126 // Long press might start a drag drop session. Complete it if so. |
2122 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { | 2127 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { |
2123 WebMouseEvent mouse_event; | 2128 WebMouseEvent mouse_event; |
2124 InitMouseEvent(WebInputEvent::MouseDown, | 2129 InitMouseEvent(WebInputEvent::MouseDown, |
2125 pressed_button_, | 2130 pressed_button_, |
2126 point, | 2131 WebPoint(x, y), |
2127 GetCurrentEventTimeSec(), | 2132 GetCurrentEventTimeSec(), |
2128 click_count_, | 2133 click_count_, |
2129 0, | 2134 0, |
2130 &mouse_event); | 2135 &mouse_event); |
2131 | 2136 |
2132 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); | 2137 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); |
2133 } | 2138 } |
2134 args->Return(result); | 2139 args->Return(result); |
2135 } | 2140 } |
2136 | 2141 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 } | 2296 } |
2292 default: | 2297 default: |
2293 NOTREACHED(); | 2298 NOTREACHED(); |
2294 } | 2299 } |
2295 } | 2300 } |
2296 | 2301 |
2297 replaying_saved_events_ = false; | 2302 replaying_saved_events_ = false; |
2298 } | 2303 } |
2299 | 2304 |
2300 } // namespace content | 2305 } // namespace content |
OLD | NEW |