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/gesture_event_stream_validator.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/common/input/web_input_event_traits.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
12 using blink::WebInputEvent
;
16 GestureEventStreamValidator::GestureEventStreamValidator()
17 : scrolling_(false), pinching_(false), waiting_for_tap_end_(false) {
20 GestureEventStreamValidator::~GestureEventStreamValidator() {
23 bool GestureEventStreamValidator::Validate(const blink::WebGestureEvent
& event
,
24 std::string
* error_msg
) {
27 if (!WebInputEvent::isGestureEventType(event
.type
)) {
28 error_msg
->append(base::StringPrintf(
29 "Invalid gesture type: %s", WebInputEventTraits::GetName(event
.type
)));
32 case WebInputEvent::GestureScrollBegin
:
34 error_msg
->append("Scroll begin during scroll\n");
36 error_msg
->append("Scroll begin during pinch\n");
39 case WebInputEvent::GestureScrollUpdate
:
41 error_msg
->append("Scroll update outside of scroll\n");
43 case WebInputEvent::GestureFlingStart
:
44 if (event
.sourceDevice
== blink::WebGestureDeviceTouchscreen
&&
45 !event
.data
.flingStart
.velocityX
&&
46 !event
.data
.flingStart
.velocityY
) {
47 error_msg
->append("Zero velocity touchscreen fling\n");
50 error_msg
->append("Fling start outside of scroll\n");
52 error_msg
->append("Flinging while pinching\n");
55 case WebInputEvent::GestureScrollEnd
:
57 error_msg
->append("Scroll end outside of scroll\n");
59 error_msg
->append("Ending scroll while pinching\n");
62 case WebInputEvent::GesturePinchBegin
:
64 error_msg
->append("Pinch begin during pinch\n");
67 case WebInputEvent::GesturePinchUpdate
:
69 error_msg
->append("Pinch update outside of pinch\n");
71 case WebInputEvent::GesturePinchEnd
:
73 error_msg
->append("Pinch end outside of pinch\n");
76 case WebInputEvent::GestureTapDown
:
77 if (waiting_for_tap_end_
)
78 error_msg
->append("Missing tap ending event before TapDown\n");
79 waiting_for_tap_end_
= true;
81 case WebInputEvent::GestureTapUnconfirmed
:
82 if (!waiting_for_tap_end_
)
83 error_msg
->append("Missing TapDown event before TapUnconfirmed\n");
85 case WebInputEvent::GestureTapCancel
:
86 if (!waiting_for_tap_end_
)
87 error_msg
->append("Missing TapDown event before TapCancel\n");
88 waiting_for_tap_end_
= false;
90 case WebInputEvent::GestureTap
:
91 if (!waiting_for_tap_end_
)
92 error_msg
->append("Missing TapDown event before Tap\n");
93 waiting_for_tap_end_
= false;
95 case WebInputEvent::GestureDoubleTap
:
96 // DoubleTap gestures may be synthetically inserted, and do not require a
98 waiting_for_tap_end_
= false;
103 return error_msg
->empty();
106 } // namespace content