Add ICU message format support
[chromium-blink-merge.git] / content / common / input / gesture_event_stream_validator.cc
blob6ea29de25ac8536fd054b45af307ee58dc5cdebe
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;
14 namespace content {
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) {
25 DCHECK(error_msg);
26 error_msg->clear();
27 if (!WebInputEvent::isGestureEventType(event.type)) {
28 error_msg->append(base::StringPrintf(
29 "Invalid gesture type: %s", WebInputEventTraits::GetName(event.type)));
31 switch (event.type) {
32 case WebInputEvent::GestureScrollBegin:
33 if (scrolling_)
34 error_msg->append("Scroll begin during scroll\n");
35 if (pinching_)
36 error_msg->append("Scroll begin during pinch\n");
37 scrolling_ = true;
38 break;
39 case WebInputEvent::GestureScrollUpdate:
40 if (!scrolling_)
41 error_msg->append("Scroll update outside of scroll\n");
42 break;
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");
49 if (!scrolling_)
50 error_msg->append("Fling start outside of scroll\n");
51 if (pinching_)
52 error_msg->append("Flinging while pinching\n");
53 scrolling_ = false;
54 break;
55 case WebInputEvent::GestureScrollEnd:
56 if (!scrolling_)
57 error_msg->append("Scroll end outside of scroll\n");
58 if (pinching_)
59 error_msg->append("Ending scroll while pinching\n");
60 scrolling_ = false;
61 break;
62 case WebInputEvent::GesturePinchBegin:
63 if (pinching_)
64 error_msg->append("Pinch begin during pinch\n");
65 pinching_ = true;
66 break;
67 case WebInputEvent::GesturePinchUpdate:
68 if (!pinching_)
69 error_msg->append("Pinch update outside of pinch\n");
70 break;
71 case WebInputEvent::GesturePinchEnd:
72 if (!pinching_)
73 error_msg->append("Pinch end outside of pinch\n");
74 pinching_ = false;
75 break;
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;
80 break;
81 case WebInputEvent::GestureTapUnconfirmed:
82 if (!waiting_for_tap_end_)
83 error_msg->append("Missing TapDown event before TapUnconfirmed\n");
84 break;
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;
89 break;
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;
94 break;
95 case WebInputEvent::GestureDoubleTap:
96 // DoubleTap gestures may be synthetically inserted, and do not require a
97 // preceding TapDown.
98 waiting_for_tap_end_ = false;
99 break;
100 default:
101 break;
103 return error_msg->empty();
106 } // namespace content