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_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_ 6 #define CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_ 7 8 #include "base/basictypes.h" 9 #include "base/containers/hash_tables.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "cc/input/input_handler.h" 12 #include "content/common/content_export.h" 13 #include "third_party/WebKit/public/platform/WebGestureCurve.h" 14 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" 15 #include "third_party/WebKit/public/web/WebActiveWheelFlingParameters.h" 16 #include "third_party/WebKit/public/web/WebInputEvent.h" 17 18 namespace content { 19 20 class InputHandlerProxyClient; 21 22 // This class is a proxy between the content input event filtering and the 23 // compositor's input handling logic. InputHandlerProxy instances live entirely 24 // on the compositor thread. Each InputHandler instance handles input events 25 // intended for a specific WebWidget. 26 class CONTENT_EXPORT InputHandlerProxy 27 : public cc::InputHandlerClient, 28 public NON_EXPORTED_BASE(blink::WebGestureCurveTarget) { 29 public: 30 explicit InputHandlerProxy(cc::InputHandler* input_handler); 31 virtual ~InputHandlerProxy(); 32 33 void SetClient(InputHandlerProxyClient* client); 34 35 enum EventDisposition { 36 DID_HANDLE, 37 DID_NOT_HANDLE, 38 DROP_EVENT 39 }; 40 EventDisposition HandleInputEventWithLatencyInfo( 41 const blink::WebInputEvent& event, 42 ui::LatencyInfo* latency_info); 43 EventDisposition HandleInputEvent(const blink::WebInputEvent& event); 44 45 // cc::InputHandlerClient implementation. 46 virtual void WillShutdown() OVERRIDE; 47 virtual void Animate(base::TimeTicks time) OVERRIDE; 48 virtual void MainThreadHasStoppedFlinging() OVERRIDE; 49 virtual void DidOverscroll(const cc::DidOverscrollParams& params) OVERRIDE; 50 51 // blink::WebGestureCurveTarget implementation. 52 virtual void scrollBy(const blink::WebFloatSize& offset); 53 virtual void notifyCurrentFlingVelocity(const blink::WebFloatSize& velocity); 54 55 bool gesture_scroll_on_impl_thread_for_testing() const { 56 return gesture_scroll_on_impl_thread_; 57 } 58 59 private: 60 EventDisposition HandleGestureFling(const blink::WebGestureEvent& event); 61 62 // Returns true if we scrolled by the increment. 63 bool TouchpadFlingScroll(const blink::WebFloatSize& increment); 64 65 // Returns true if we actually had an active fling to cancel. 66 bool CancelCurrentFling(); 67 68 scoped_ptr<blink::WebGestureCurve> fling_curve_; 69 // Parameters for the active fling animation, stored in case we need to 70 // transfer it out later. 71 blink::WebActiveWheelFlingParameters fling_parameters_; 72 73 InputHandlerProxyClient* client_; 74 cc::InputHandler* input_handler_; 75 76 #ifndef NDEBUG 77 bool expect_scroll_update_end_; 78 bool expect_pinch_update_end_; 79 #endif 80 bool gesture_scroll_on_impl_thread_; 81 bool gesture_pinch_on_impl_thread_; 82 // This is always false when there are no flings on the main thread, but 83 // conservative in the sense that we might not be actually flinging when it is 84 // true. 85 bool fling_may_be_active_on_main_thread_; 86 // The axes on which the current fling has overshot the bounds of the content. 87 bool fling_overscrolled_horizontally_; 88 bool fling_overscrolled_vertically_; 89 90 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy); 91 }; 92 93 } // namespace content 94 95 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_ 96