Home | History | Annotate | Download | only in input
      1 // Copyright 2013 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_ACTION_FILTER_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_ACTION_FILTER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "content/common/content_export.h"
     10 #include "content/common/input/touch_action.h"
     11 
     12 namespace blink {
     13 class WebGestureEvent;
     14 }
     15 
     16 namespace content {
     17 
     18 // The TouchActionFilter is responsible for filtering scroll and pinch gesture
     19 // events according to the CSS touch-action values the renderer has sent for
     20 // each touch point.
     21 // For details see the touch-action design doc at http://goo.gl/KcKbxQ.
     22 class CONTENT_EXPORT TouchActionFilter {
     23 public:
     24   TouchActionFilter();
     25 
     26   // Returns true if the supplied gesture event should be dropped based on
     27   // the current touch-action state.
     28   bool FilterGestureEvent(blink::WebGestureEvent* gesture_event);
     29 
     30   // Called when a set-touch-action message is received from the renderer
     31   // for a touch start event that is currently in flight.
     32   void OnSetTouchAction(content::TouchAction touch_action);
     33 
     34   // Must be called at least once between when the last gesture events for the
     35   // previous touch sequence have passed through the touch action filter and the
     36   // time the touch start for the next touch sequence has reached the
     37   // renderer. It may be called multiple times during this interval.
     38   void ResetTouchAction();
     39 
     40   TouchAction allowed_touch_action() const { return allowed_touch_action_; }
     41 
     42   // Return the intersection of two TouchAction values.
     43   static TouchAction Intersect(TouchAction ta1, TouchAction ta2);
     44 
     45 private:
     46   bool ShouldSuppressScroll(const blink::WebGestureEvent& gesture_event);
     47   bool FilterScrollEndingGesture();
     48 
     49   // Whether GestureScroll events should be discarded due to touch-action.
     50   bool drop_scroll_gesture_events_;
     51 
     52   // Whether GesturePinch events should be discarded due to touch-action.
     53   bool drop_pinch_gesture_events_;
     54 
     55   // Whether a tap ending event in this sequence should be discarded because a
     56   // previous GestureTapUnconfirmed event was turned into a GestureTap.
     57   bool drop_current_tap_ending_event_;
     58 
     59   // True iff the touch action of the last TapUnconfirmed or Tap event was
     60   // TOUCH_ACTION_AUTO. The double tap event depends on the touch action of the
     61   // previous tap or tap unconfirmed. Only valid between a TapUnconfirmed or Tap
     62   // and the next DoubleTap.
     63   bool allow_current_double_tap_event_;
     64 
     65   // What touch actions are currently permitted.
     66   TouchAction allowed_touch_action_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(TouchActionFilter);
     69 };
     70 
     71 }
     72 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_ACTION_FILTER_H_
     73