Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: content/common/input/gesture_event_stream_validator.cc

Issue 537733003: [Android] Enable input event stream validation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review and fix tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/common/input/gesture_event_stream_validator.h" 5 #include "content/common/input/gesture_event_stream_validator.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h" 8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9 9
10 using blink::WebInputEvent; 10 using blink::WebInputEvent;
11 11
12 namespace content { 12 namespace content {
13 13
14 GestureEventStreamValidator::GestureEventStreamValidator() 14 GestureEventStreamValidator::GestureEventStreamValidator()
15 : scrolling_(false), pinching_(false), waiting_for_tap_end_(false) { 15 : scrolling_(false), pinching_(false), waiting_for_tap_end_(false) {
16 } 16 }
17 17
18 GestureEventStreamValidator::~GestureEventStreamValidator() { 18 GestureEventStreamValidator::~GestureEventStreamValidator() {
19 } 19 }
20 20
21 bool GestureEventStreamValidator::Validate(const blink::WebGestureEvent& event, 21 bool GestureEventStreamValidator::Validate(const blink::WebGestureEvent& event,
22 std::string* error_msg) { 22 std::string* error_msg) {
23 DCHECK(error_msg); 23 DCHECK(error_msg);
24 error_msg->clear(); 24 error_msg->clear();
25 switch (event.type) { 25 switch (event.type) {
26 case WebInputEvent::GestureScrollBegin: 26 case WebInputEvent::GestureScrollBegin:
27 if (scrolling_ || pinching_) 27 if (scrolling_)
28 error_msg->append("Scroll begin during scroll\n"); 28 error_msg->append("Scroll begin during scroll\n");
29 if (pinching_)
30 error_msg->append("Scroll begin during pinch\n");
29 scrolling_ = true; 31 scrolling_ = true;
30 break; 32 break;
31 case WebInputEvent::GestureScrollUpdate: 33 case WebInputEvent::GestureScrollUpdate:
32 case WebInputEvent::GestureScrollUpdateWithoutPropagation: 34 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
33 if (!scrolling_) 35 if (!scrolling_)
34 error_msg->append("Scroll update outside of scroll\n"); 36 error_msg->append("Scroll update outside of scroll\n");
35 break; 37 break;
36 case WebInputEvent::GestureScrollEnd: 38 case WebInputEvent::GestureScrollEnd:
37 case WebInputEvent::GestureFlingStart: 39 case WebInputEvent::GestureFlingStart:
38 if (!scrolling_) 40 if (!scrolling_)
39 error_msg->append("Scroll end outside of scroll\n"); 41 error_msg->append("Scroll end outside of scroll\n");
40 if (pinching_) 42 if (pinching_)
41 error_msg->append("Ending scroll while pinching\n"); 43 error_msg->append("Ending scroll while pinching\n");
42 scrolling_ = false; 44 scrolling_ = false;
43 break; 45 break;
44 case WebInputEvent::GesturePinchBegin: 46 case WebInputEvent::GesturePinchBegin:
45 if (!scrolling_)
46 error_msg->append("Pinch begin outside of scroll\n");
47 if (pinching_) 47 if (pinching_)
48 error_msg->append("Pinch begin during pinch\n"); 48 error_msg->append("Pinch begin during pinch\n");
49 pinching_ = true; 49 pinching_ = true;
50 break; 50 break;
51 case WebInputEvent::GesturePinchUpdate: 51 case WebInputEvent::GesturePinchUpdate:
52 if (!pinching_ || !scrolling_) 52 if (!pinching_)
53 error_msg->append("Pinch update outside of pinch\n"); 53 error_msg->append("Pinch update outside of pinch\n");
54 break; 54 break;
55 case WebInputEvent::GesturePinchEnd: 55 case WebInputEvent::GesturePinchEnd:
56 if (!pinching_ || !scrolling_) 56 if (!pinching_)
57 error_msg->append("Pinch end outside of pinch\n"); 57 error_msg->append("Pinch end outside of pinch\n");
58 pinching_ = false; 58 pinching_ = false;
59 break; 59 break;
60 case WebInputEvent::GestureTapDown: 60 case WebInputEvent::GestureTapDown:
61 if (waiting_for_tap_end_) 61 if (waiting_for_tap_end_)
62 error_msg->append("Missing tap end event\n"); 62 error_msg->append("Missing tap end event\n");
63 waiting_for_tap_end_ = true; 63 waiting_for_tap_end_ = true;
64 break; 64 break;
65 case WebInputEvent::GestureTap: 65 case WebInputEvent::GestureTap:
66 case WebInputEvent::GestureTapCancel: 66 case WebInputEvent::GestureTapCancel:
67 case WebInputEvent::GestureDoubleTap:
68 if (!waiting_for_tap_end_) 67 if (!waiting_for_tap_end_)
69 error_msg->append("Missing GestureTapDown event\n"); 68 error_msg->append("Missing GestureTapDown event\n");
70 waiting_for_tap_end_ = false; 69 waiting_for_tap_end_ = false;
71 break; 70 break;
71 case WebInputEvent::GestureDoubleTap:
72 waiting_for_tap_end_ = false;
73 break;
72 default: 74 default:
73 break; 75 break;
74 } 76 }
75 return error_msg->empty(); 77 return error_msg->empty();
76 } 78 }
77 79
78 } // namespace content 80 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/gesture_event_stream_validator.h ('k') | content/common/input/gesture_event_stream_validator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698