[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / input / web_touch_event_traits.cc
blob1a161060630be1f5996346ba43e66e22ff86a433
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
3 // found in the LICENSE file.
5 #include "content/common/input/web_touch_event_traits.h"
7 #include "base/logging.h"
9 using blink::WebInputEvent;
10 using blink::WebTouchEvent;
11 using blink::WebTouchPoint;
13 namespace content {
15 bool WebTouchEventTraits::AllTouchPointsHaveState(
16 const WebTouchEvent& event,
17 blink::WebTouchPoint::State state) {
18 if (!event.touchesLength)
19 return false;
20 for (size_t i = 0; i < event.touchesLength; ++i) {
21 if (event.touches[i].state != state)
22 return false;
24 return true;
27 bool WebTouchEventTraits::IsTouchSequenceStart(const WebTouchEvent& event) {
28 DCHECK(event.touchesLength);
29 if (event.type != WebInputEvent::TouchStart)
30 return false;
31 return AllTouchPointsHaveState(event, blink::WebTouchPoint::StatePressed);
34 bool WebTouchEventTraits::IsTouchSequenceEnd(const WebTouchEvent& event) {
35 if (event.type != WebInputEvent::TouchEnd &&
36 event.type != WebInputEvent::TouchCancel)
37 return false;
38 if (!event.touchesLength)
39 return true;
40 for (size_t i = 0; i < event.touchesLength; ++i) {
41 if (event.touches[i].state != blink::WebTouchPoint::StateReleased &&
42 event.touches[i].state != blink::WebTouchPoint::StateCancelled)
43 return false;
45 return true;
48 void WebTouchEventTraits::ResetType(WebInputEvent::Type type,
49 double timestamp_sec,
50 WebTouchEvent* event) {
51 DCHECK(WebInputEvent::isTouchEventType(type));
52 event->type = type;
53 event->cancelable = (type != WebInputEvent::TouchCancel);
54 event->timeStampSeconds = timestamp_sec;
57 void WebTouchEventTraits::ResetTypeAndTouchStates(WebInputEvent::Type type,
58 double timestamp_sec,
59 WebTouchEvent* event) {
60 ResetType(type, timestamp_sec, event);
62 WebTouchPoint::State newState = WebTouchPoint::StateUndefined;
63 switch (event->type) {
64 case WebInputEvent::TouchStart:
65 newState = WebTouchPoint::StatePressed;
66 break;
67 case WebInputEvent::TouchMove:
68 newState = WebTouchPoint::StateMoved;
69 break;
70 case WebInputEvent::TouchEnd:
71 newState = WebTouchPoint::StateReleased;
72 break;
73 case WebInputEvent::TouchCancel:
74 newState = WebTouchPoint::StateCancelled;
75 break;
76 default:
77 NOTREACHED();
78 break;
80 for (size_t i = 0; i < event->touchesLength; ++i)
81 event->touches[i].state = newState;
84 } // namespace content