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 #include "content/browser/renderer_host/input/touch_action_filter.h" 6 7 #include "third_party/WebKit/public/web/WebInputEvent.h" 8 9 using blink::WebInputEvent; 10 using blink::WebGestureEvent; 11 12 namespace content { 13 14 TouchActionFilter::TouchActionFilter() : 15 drop_scroll_gesture_events_(false), 16 allowed_touch_action_(TOUCH_ACTION_AUTO) { 17 } 18 19 bool TouchActionFilter::FilterGestureEvent( 20 const WebGestureEvent& gesture_event) { 21 // Filter for allowable touch actions first (eg. before the TouchEventQueue 22 // can decide to send a touch cancel event). 23 // TODO(rbyers): Add touch-action control over for pinch. crbug.com/247566. 24 switch(gesture_event.type) { 25 case WebInputEvent::GestureScrollBegin: 26 if (allowed_touch_action_ == TOUCH_ACTION_NONE) 27 drop_scroll_gesture_events_ = true; 28 // FALL THROUGH 29 case WebInputEvent::GestureScrollUpdate: 30 if (drop_scroll_gesture_events_) 31 return true; 32 break; 33 34 case WebInputEvent::GestureScrollEnd: 35 case WebInputEvent::GestureFlingStart: 36 allowed_touch_action_ = content::TOUCH_ACTION_AUTO; 37 if (drop_scroll_gesture_events_) { 38 drop_scroll_gesture_events_ = false; 39 return true; 40 } 41 break; 42 43 default: 44 // Gesture events unrelated to touch actions (panning/zooming) are left 45 // alone. 46 break; 47 } 48 49 return false; 50 } 51 52 void TouchActionFilter::OnSetTouchAction( 53 content::TouchAction touch_action) { 54 // For multiple fingers, we take the intersection of the touch actions for 55 // all fingers that have gone down during this action. 56 // TODO(rbyers): What exact multi-finger semantic do we want? This is left 57 // as implementation-defined in the pointer events specification. 58 // crbug.com/247566. 59 if (touch_action == content::TOUCH_ACTION_NONE) 60 allowed_touch_action_ = content::TOUCH_ACTION_NONE; 61 } 62 63 } 64