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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 } | 1930 } |
1931 | 1931 |
1932 bool EventSender::IsFlinging() const { | 1932 bool EventSender::IsFlinging() const { |
1933 return view()->isFlinging(); | 1933 return view()->isFlinging(); |
1934 } | 1934 } |
1935 | 1935 |
1936 void EventSender::GestureScrollFirstPoint(int x, int y) { | 1936 void EventSender::GestureScrollFirstPoint(int x, int y) { |
1937 current_gesture_location_ = WebPoint(x, y); | 1937 current_gesture_location_ = WebPoint(x, y); |
1938 } | 1938 } |
1939 | 1939 |
1940 bool EventSender::GetMovedBeyondSlopRegionArg(gin::Arguments* args) { | |
1941 std::string arg; | |
1942 if (args->PeekNext().IsEmpty()) | |
1943 return false; | |
1944 | |
1945 if(args->PeekNext()->IsString() && args->GetNext(&arg)) { | |
1946 if (arg == "movedBeyondSlopRegion") | |
1947 return true; | |
1948 } | |
1949 | |
1950 args->ThrowError(); | |
1951 return false; | |
1952 } | |
1953 | |
1954 void EventSender::TouchStart(gin::Arguments* args) { | 1940 void EventSender::TouchStart(gin::Arguments* args) { |
1955 SendCurrentTouchEvent(WebInputEvent::TouchStart, | 1941 SendCurrentTouchEvent(WebInputEvent::TouchStart, args); |
1956 GetMovedBeyondSlopRegionArg(args)); | |
1957 } | 1942 } |
1958 | 1943 |
1959 void EventSender::TouchMove(gin::Arguments* args) { | 1944 void EventSender::TouchMove(gin::Arguments* args) { |
1960 SendCurrentTouchEvent(WebInputEvent::TouchMove, | 1945 SendCurrentTouchEvent(WebInputEvent::TouchMove, args); |
1961 GetMovedBeyondSlopRegionArg(args)); | |
1962 } | 1946 } |
1963 | 1947 |
1964 void EventSender::TouchCancel(gin::Arguments* args) { | 1948 void EventSender::TouchCancel(gin::Arguments* args) { |
1965 SendCurrentTouchEvent(WebInputEvent::TouchCancel, | 1949 SendCurrentTouchEvent(WebInputEvent::TouchCancel, args); |
1966 GetMovedBeyondSlopRegionArg(args)); | |
1967 } | 1950 } |
1968 | 1951 |
1969 void EventSender::TouchEnd(gin::Arguments* args) { | 1952 void EventSender::TouchEnd(gin::Arguments* args) { |
1970 SendCurrentTouchEvent(WebInputEvent::TouchEnd, | 1953 SendCurrentTouchEvent(WebInputEvent::TouchEnd, args); |
1971 GetMovedBeyondSlopRegionArg(args)); | |
1972 } | 1954 } |
1973 | 1955 |
1974 void EventSender::NotifyStartOfTouchScroll() { | 1956 void EventSender::NotifyStartOfTouchScroll() { |
1975 WebTouchEvent event; | 1957 WebTouchEvent event; |
1976 event.type = WebInputEvent::TouchScrollStarted; | 1958 event.type = WebInputEvent::TouchScrollStarted; |
1977 HandleInputEventOnViewOrPopup(event); | 1959 HandleInputEventOnViewOrPopup(event); |
1978 } | 1960 } |
1979 | 1961 |
1980 void EventSender::LeapForward(int milliseconds) { | 1962 void EventSender::LeapForward(int milliseconds) { |
1981 if (is_drag_mode_ && | 1963 if (is_drag_mode_ && |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2209 | 2191 |
2210 double EventSender::GetCurrentEventTimeSec() { | 2192 double EventSender::GetCurrentEventTimeSec() { |
2211 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + | 2193 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + |
2212 time_offset_ms_ / 1000.0; | 2194 time_offset_ms_ / 1000.0; |
2213 } | 2195 } |
2214 | 2196 |
2215 void EventSender::DoLeapForward(int milliseconds) { | 2197 void EventSender::DoLeapForward(int milliseconds) { |
2216 time_offset_ms_ += milliseconds; | 2198 time_offset_ms_ += milliseconds; |
2217 } | 2199 } |
2218 | 2200 |
| 2201 void EventSender::GetOptionalTouchArgs(gin::Arguments* args, |
| 2202 bool& moved_beyond_slop_region, |
| 2203 uint32_t& unique_touch_event_id) { |
| 2204 moved_beyond_slop_region = false; |
| 2205 if(!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) { |
| 2206 std::string arg; |
| 2207 if (args->GetNext(&arg) && arg == "movedBeyondSlopRegion") |
| 2208 moved_beyond_slop_region = true; |
| 2209 else |
| 2210 args->ThrowError(); |
| 2211 } |
| 2212 |
| 2213 unique_touch_event_id = GetUniqueTouchEventId(args); |
| 2214 return; |
| 2215 } |
| 2216 |
| 2217 uint32_t EventSender::GetUniqueTouchEventId(gin::Arguments* args) { |
| 2218 uint32_t unique_touch_event_id; |
| 2219 if(!args->PeekNext().IsEmpty() && args->GetNext(&unique_touch_event_id)) |
| 2220 return unique_touch_event_id; |
| 2221 |
| 2222 return 0; |
| 2223 } |
| 2224 |
2219 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type, | 2225 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type, |
2220 bool movedBeyondSlopRegion) { | 2226 gin::Arguments* args) { |
| 2227 bool moved_beyond_slop_region; |
| 2228 uint32_t unique_touch_event_id; |
| 2229 GetOptionalTouchArgs(args, moved_beyond_slop_region, unique_touch_event_id); |
| 2230 |
2221 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap), | 2231 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap), |
2222 touch_points_.size()); | 2232 touch_points_.size()); |
2223 if (force_layout_on_events_) | 2233 if (force_layout_on_events_) |
2224 view()->updateAllLifecyclePhases(); | 2234 view()->updateAllLifecyclePhases(); |
2225 | 2235 |
2226 WebTouchEvent touch_event; | 2236 WebTouchEvent touch_event; |
2227 touch_event.type = type; | 2237 touch_event.type = type; |
2228 touch_event.modifiers = touch_modifiers_; | 2238 touch_event.modifiers = touch_modifiers_; |
2229 touch_event.dispatchType = touch_cancelable_ | 2239 touch_event.dispatchType = touch_cancelable_ |
2230 ? WebInputEvent::Blocking | 2240 ? WebInputEvent::Blocking |
2231 : WebInputEvent::EventNonBlocking; | 2241 : WebInputEvent::EventNonBlocking; |
2232 touch_event.timeStampSeconds = GetCurrentEventTimeSec(); | 2242 touch_event.timeStampSeconds = GetCurrentEventTimeSec(); |
2233 touch_event.movedBeyondSlopRegion = movedBeyondSlopRegion; | 2243 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region; |
| 2244 touch_event.uniqueTouchEventId = unique_touch_event_id; |
2234 touch_event.touchesLength = touch_points_.size(); | 2245 touch_event.touchesLength = touch_points_.size(); |
2235 for (size_t i = 0; i < touch_points_.size(); ++i) | 2246 for (size_t i = 0; i < touch_points_.size(); ++i) |
2236 touch_event.touches[i] = touch_points_[i]; | 2247 touch_event.touches[i] = touch_points_[i]; |
2237 HandleInputEventOnViewOrPopup(touch_event); | 2248 HandleInputEventOnViewOrPopup(touch_event); |
2238 | 2249 |
2239 for (size_t i = 0; i < touch_points_.size(); ++i) { | 2250 for (size_t i = 0; i < touch_points_.size(); ++i) { |
2240 WebTouchPoint* touch_point = &touch_points_[i]; | 2251 WebTouchPoint* touch_point = &touch_points_[i]; |
2241 if (touch_point->state == WebTouchPoint::StateReleased | 2252 if (touch_point->state == WebTouchPoint::StateReleased |
2242 || touch_point->state == WebTouchPoint::StateCancelled) { | 2253 || touch_point->state == WebTouchPoint::StateCancelled) { |
2243 touch_points_.erase(touch_points_.begin() + i); | 2254 touch_points_.erase(touch_points_.begin() + i); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 event.y = y; | 2432 event.y = y; |
2422 event.data.showPress.width = width; | 2433 event.data.showPress.width = width; |
2423 event.data.showPress.height = height; | 2434 event.data.showPress.height = height; |
2424 break; | 2435 break; |
2425 } | 2436 } |
2426 case WebInputEvent::GestureTapCancel: | 2437 case WebInputEvent::GestureTapCancel: |
2427 event.x = x; | 2438 event.x = x; |
2428 event.y = y; | 2439 event.y = y; |
2429 break; | 2440 break; |
2430 case WebInputEvent::GestureLongPress: | 2441 case WebInputEvent::GestureLongPress: |
2431 event.x = x; | |
2432 event.y = y; | |
2433 if (!args->PeekNext().IsEmpty()) { | |
2434 float width; | |
2435 if (!args->GetNext(&width)) { | |
2436 args->ThrowError(); | |
2437 return; | |
2438 } | |
2439 event.data.longPress.width = width; | |
2440 if (!args->PeekNext().IsEmpty()) { | |
2441 float height; | |
2442 if (!args->GetNext(&height)) { | |
2443 args->ThrowError(); | |
2444 return; | |
2445 } | |
2446 event.data.longPress.height = height; | |
2447 } | |
2448 } | |
2449 break; | |
2450 case WebInputEvent::GestureLongTap: | 2442 case WebInputEvent::GestureLongTap: |
2451 event.x = x; | 2443 event.x = x; |
2452 event.y = y; | 2444 event.y = y; |
2453 if (!args->PeekNext().IsEmpty()) { | 2445 if (!args->PeekNext().IsEmpty()) { |
2454 float width; | 2446 float width; |
2455 if (!args->GetNext(&width)) { | 2447 if (!args->GetNext(&width)) { |
2456 args->ThrowError(); | 2448 args->ThrowError(); |
2457 return; | 2449 return; |
2458 } | 2450 } |
2459 event.data.longPress.width = width; | 2451 event.data.longPress.width = width; |
(...skipping 24 matching lines...) Expand all Loading... |
2484 return; | 2476 return; |
2485 } | 2477 } |
2486 event.data.twoFingerTap.firstFingerHeight = first_finger_height; | 2478 event.data.twoFingerTap.firstFingerHeight = first_finger_height; |
2487 } | 2479 } |
2488 } | 2480 } |
2489 break; | 2481 break; |
2490 default: | 2482 default: |
2491 NOTREACHED(); | 2483 NOTREACHED(); |
2492 } | 2484 } |
2493 | 2485 |
| 2486 event.uniqueTouchEventId = GetUniqueTouchEventId(args); |
| 2487 |
2494 event.globalX = event.x; | 2488 event.globalX = event.x; |
2495 event.globalY = event.y; | 2489 event.globalY = event.y; |
2496 event.timeStampSeconds = GetCurrentEventTimeSec(); | 2490 event.timeStampSeconds = GetCurrentEventTimeSec(); |
2497 | 2491 |
2498 if (force_layout_on_events_) | 2492 if (force_layout_on_events_) |
2499 view()->updateAllLifecyclePhases(); | 2493 view()->updateAllLifecyclePhases(); |
2500 | 2494 |
2501 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); | 2495 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
2502 | 2496 |
2503 // Long press might start a drag drop session. Complete it if so. | 2497 // Long press might start a drag drop session. Complete it if so. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2820 | 2814 |
2821 const blink::WebView* EventSender::view() const { | 2815 const blink::WebView* EventSender::view() const { |
2822 return web_test_proxy_base_->web_view(); | 2816 return web_test_proxy_base_->web_view(); |
2823 } | 2817 } |
2824 | 2818 |
2825 blink::WebView* EventSender::view() { | 2819 blink::WebView* EventSender::view() { |
2826 return web_test_proxy_base_->web_view(); | 2820 return web_test_proxy_base_->web_view(); |
2827 } | 2821 } |
2828 | 2822 |
2829 } // namespace test_runner | 2823 } // namespace test_runner |
OLD | NEW |