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
;
15 bool WebTouchEventTraits::AllTouchPointsHaveState(
16 const WebTouchEvent
& event
,
17 blink::WebTouchPoint::State state
) {
18 if (!event
.touchesLength
)
20 for (size_t i
= 0; i
< event
.touchesLength
; ++i
) {
21 if (event
.touches
[i
].state
!= state
)
27 bool WebTouchEventTraits::IsTouchSequenceStart(const WebTouchEvent
& event
) {
28 DCHECK(event
.touchesLength
);
29 if (event
.type
!= WebInputEvent::TouchStart
)
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
)
38 if (!event
.touchesLength
)
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
)
48 void WebTouchEventTraits::ResetType(WebInputEvent::Type type
,
50 WebTouchEvent
* event
) {
51 DCHECK(WebInputEvent::isTouchEventType(type
));
53 event
->cancelable
= (type
!= WebInputEvent::TouchCancel
);
54 event
->timeStampSeconds
= timestamp_sec
;
57 void WebTouchEventTraits::ResetTypeAndTouchStates(WebInputEvent::Type type
,
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
;
67 case WebInputEvent::TouchMove
:
68 newState
= WebTouchPoint::StateMoved
;
70 case WebInputEvent::TouchEnd
:
71 newState
= WebTouchPoint::StateReleased
;
73 case WebInputEvent::TouchCancel
:
74 newState
= WebTouchPoint::StateCancelled
;
80 for (size_t i
= 0; i
< event
->touchesLength
; ++i
)
81 event
->touches
[i
].state
= newState
;
84 } // namespace content