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