| OLD | NEW |
| 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 "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 8 | 9 |
| 10 using blink::WebInputEvent; |
| 11 |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 11 using blink::WebInputEvent; | 14 GestureEventStreamValidator::GestureEventStreamValidator() |
| 15 : scrolling_(false), pinching_(false), waiting_for_tap_end_(false) { |
| 16 } |
| 12 | 17 |
| 13 GestureEventStreamValidator::GestureEventStreamValidator() | 18 GestureEventStreamValidator::~GestureEventStreamValidator() { |
| 14 : scrolling_(false), pinching_(false), waiting_for_tap_end_(false) {} | 19 } |
| 15 | |
| 16 GestureEventStreamValidator::~GestureEventStreamValidator() {} | |
| 17 | 20 |
| 18 bool GestureEventStreamValidator::Validate(const blink::WebGestureEvent& event, | 21 bool GestureEventStreamValidator::Validate(const blink::WebGestureEvent& event, |
| 19 const char** error_message) { | 22 std::string* error_msg) { |
| 20 *error_message = NULL; | 23 DCHECK(error_msg); |
| 24 error_msg->clear(); |
| 21 switch (event.type) { | 25 switch (event.type) { |
| 22 case WebInputEvent::GestureScrollBegin: | 26 case WebInputEvent::GestureScrollBegin: |
| 23 if (scrolling_ || pinching_) | 27 if (scrolling_ || pinching_) |
| 24 *error_message = "Scroll begin during scroll"; | 28 error_msg->append("Scroll begin during scroll\n"); |
| 25 scrolling_ = true; | 29 scrolling_ = true; |
| 26 break; | 30 break; |
| 27 case WebInputEvent::GestureScrollUpdate: | 31 case WebInputEvent::GestureScrollUpdate: |
| 28 case WebInputEvent::GestureScrollUpdateWithoutPropagation: | 32 case WebInputEvent::GestureScrollUpdateWithoutPropagation: |
| 29 if (!scrolling_) | 33 if (!scrolling_) |
| 30 *error_message = "Scroll update outside of scroll"; | 34 error_msg->append("Scroll update outside of scroll\n"); |
| 31 break; | 35 break; |
| 32 case WebInputEvent::GestureScrollEnd: | 36 case WebInputEvent::GestureScrollEnd: |
| 33 case WebInputEvent::GestureFlingStart: | 37 case WebInputEvent::GestureFlingStart: |
| 34 if (!scrolling_) | 38 if (!scrolling_) |
| 35 *error_message = "Scroll end outside of scroll"; | 39 error_msg->append("Scroll end outside of scroll\n"); |
| 36 if (pinching_) | 40 if (pinching_) |
| 37 *error_message = "Ending scroll while pinching"; | 41 error_msg->append("Ending scroll while pinching\n"); |
| 38 scrolling_ = false; | 42 scrolling_ = false; |
| 39 break; | 43 break; |
| 40 case WebInputEvent::GesturePinchBegin: | 44 case WebInputEvent::GesturePinchBegin: |
| 41 if (!scrolling_) | 45 if (!scrolling_) |
| 42 *error_message = "Pinch begin outside of scroll"; | 46 error_msg->append("Pinch begin outside of scroll\n"); |
| 43 if (pinching_) | 47 if (pinching_) |
| 44 *error_message = "Pinch begin during pinch"; | 48 error_msg->append("Pinch begin during pinch\n"); |
| 45 pinching_ = true; | 49 pinching_ = true; |
| 46 break; | 50 break; |
| 47 case WebInputEvent::GesturePinchUpdate: | 51 case WebInputEvent::GesturePinchUpdate: |
| 48 if (!pinching_ || !scrolling_) | 52 if (!pinching_ || !scrolling_) |
| 49 *error_message = "Pinch update outside of pinch"; | 53 error_msg->append("Pinch update outside of pinch\n"); |
| 50 break; | 54 break; |
| 51 case WebInputEvent::GesturePinchEnd: | 55 case WebInputEvent::GesturePinchEnd: |
| 52 if (!pinching_ || !scrolling_) | 56 if (!pinching_ || !scrolling_) |
| 53 *error_message = "Pinch end outside of pinch"; | 57 error_msg->append("Pinch end outside of pinch\n"); |
| 54 pinching_ = false; | 58 pinching_ = false; |
| 55 break; | 59 break; |
| 56 case WebInputEvent::GestureTapDown: | 60 case WebInputEvent::GestureTapDown: |
| 57 if (waiting_for_tap_end_) | 61 if (waiting_for_tap_end_) |
| 58 *error_message = "Missing tap end event"; | 62 error_msg->append("Missing tap end event\n"); |
| 59 waiting_for_tap_end_ = true; | 63 waiting_for_tap_end_ = true; |
| 60 break; | 64 break; |
| 61 case WebInputEvent::GestureTap: | 65 case WebInputEvent::GestureTap: |
| 62 case WebInputEvent::GestureTapCancel: | 66 case WebInputEvent::GestureTapCancel: |
| 63 case WebInputEvent::GestureDoubleTap: | 67 case WebInputEvent::GestureDoubleTap: |
| 64 if (!waiting_for_tap_end_) | 68 if (!waiting_for_tap_end_) |
| 65 *error_message = "Missing GestureTapDown event"; | 69 error_msg->append("Missing GestureTapDown event\n"); |
| 66 waiting_for_tap_end_ = false; | 70 waiting_for_tap_end_ = false; |
| 67 break; | 71 break; |
| 68 default: | 72 default: |
| 69 break; | 73 break; |
| 70 } | 74 } |
| 71 if (*error_message == NULL) | 75 return error_msg->empty(); |
| 72 return true; | |
| 73 return false; | |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace content | 78 } // namespace content |
| OLD | NEW |