Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / renderer / input / input_handler_proxy.h
blobb61067c60a3d46789faadc4c6ab03b025d429b40
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.
5 #ifndef CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_
6 #define CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/input/input_handler.h"
13 #include "content/common/content_export.h"
14 #include "content/renderer/input/synchronous_input_handler_proxy.h"
15 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
16 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
17 #include "third_party/WebKit/public/web/WebActiveWheelFlingParameters.h"
18 #include "third_party/WebKit/public/web/WebInputEvent.h"
20 namespace content {
22 class InputHandlerProxyClient;
23 class InputScrollElasticityController;
25 // This class is a proxy between the content input event filtering and the
26 // compositor's input handling logic. InputHandlerProxy instances live entirely
27 // on the compositor thread. Each InputHandler instance handles input events
28 // intended for a specific WebWidget.
29 class CONTENT_EXPORT InputHandlerProxy
30 : public cc::InputHandlerClient,
31 public SynchronousInputHandlerProxy,
32 public NON_EXPORTED_BASE(blink::WebGestureCurveTarget) {
33 public:
34 InputHandlerProxy(cc::InputHandler* input_handler,
35 InputHandlerProxyClient* client);
36 virtual ~InputHandlerProxy();
38 InputScrollElasticityController* scroll_elasticity_controller() {
39 return scroll_elasticity_controller_.get();
42 enum EventDisposition {
43 DID_HANDLE,
44 DID_NOT_HANDLE,
45 DROP_EVENT
47 EventDisposition HandleInputEventWithLatencyInfo(
48 const blink::WebInputEvent& event,
49 ui::LatencyInfo* latency_info);
50 EventDisposition HandleInputEvent(const blink::WebInputEvent& event);
52 // cc::InputHandlerClient implementation.
53 void WillShutdown() override;
54 void Animate(base::TimeTicks time) override;
55 void MainThreadHasStoppedFlinging() override;
56 void ReconcileElasticOverscrollAndRootScroll() override;
58 // SynchronousInputHandlerProxy implementation.
59 void SetOnlySynchronouslyAnimateRootFlings(
60 SynchronousInputHandler* synchronous_input_handler) override;
61 void SynchronouslyAnimate(base::TimeTicks time) override;
63 // blink::WebGestureCurveTarget implementation.
64 virtual bool scrollBy(const blink::WebFloatSize& offset,
65 const blink::WebFloatSize& velocity);
67 bool gesture_scroll_on_impl_thread_for_testing() const {
68 return gesture_scroll_on_impl_thread_;
71 private:
72 // Helper functions for handling more complicated input events.
73 EventDisposition HandleMouseWheel(
74 const blink::WebMouseWheelEvent& event);
75 EventDisposition HandleGestureScrollBegin(
76 const blink::WebGestureEvent& event);
77 EventDisposition HandleGestureScrollUpdate(
78 const blink::WebGestureEvent& event);
79 EventDisposition HandleGestureScrollEnd(
80 const blink::WebGestureEvent& event);
81 EventDisposition HandleGestureFlingStart(
82 const blink::WebGestureEvent& event);
83 EventDisposition HandleTouchStart(
84 const blink::WebTouchEvent& event);
86 // Returns true if the event should be suppressed due to to an active,
87 // boost-enabled fling, in which case further processing should cease.
88 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent& event);
90 // Schedule a time in the future after which a boost-enabled fling will
91 // terminate without further momentum from the user (see |Animate()|).
92 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent& event);
94 // Returns true if we scrolled by the increment.
95 bool TouchpadFlingScroll(const blink::WebFloatSize& increment);
97 // Returns true if we actually had an active fling to cancel, also notifying
98 // the client that the fling has ended. Note that if a boosted fling is active
99 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
100 // will be injected to resume scrolling.
101 bool CancelCurrentFling();
103 // Returns true if we actually had an active fling to cancel.
104 bool CancelCurrentFlingWithoutNotifyingClient();
106 // Request a frame of animation from the InputHandler or
107 // SynchronousInputHandler. They can provide that by calling Animate().
108 void RequestAnimation();
110 // Used to send overscroll messages to the browser.
111 void HandleOverscroll(
112 const gfx::Point& causal_event_viewport_point,
113 const cc::InputHandlerScrollResult& scroll_result);
115 scoped_ptr<blink::WebGestureCurve> fling_curve_;
116 // Parameters for the active fling animation, stored in case we need to
117 // transfer it out later.
118 blink::WebActiveWheelFlingParameters fling_parameters_;
120 InputHandlerProxyClient* client_;
121 cc::InputHandler* input_handler_;
123 // Time at which an active fling should expire due to a deferred cancellation
124 // event. A call to |Animate()| after this time will end the fling.
125 double deferred_fling_cancel_time_seconds_;
127 // The last event that extended the lifetime of the boosted fling. If the
128 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
129 // fling terminates (via |CancelCurrentFling()|).
130 blink::WebGestureEvent last_fling_boost_event_;
132 // When present, Animates are not requested to the InputHandler, but to this
133 // SynchronousInputHandler instead. And all Animate() calls are expected to
134 // happen via the SynchronouslyAnimate() call instead of coming directly from
135 // the InputHandler.
136 SynchronousInputHandler* synchronous_input_handler_;
137 bool allow_root_animate_;
139 #ifndef NDEBUG
140 bool expect_scroll_update_end_;
141 #endif
142 bool gesture_scroll_on_impl_thread_;
143 bool gesture_pinch_on_impl_thread_;
144 // This is always false when there are no flings on the main thread, but
145 // conservative in the sense that we might not be actually flinging when it is
146 // true.
147 bool fling_may_be_active_on_main_thread_;
148 // The axes on which the current fling is allowed to scroll. If a given fling
149 // has overscrolled on a particular axis, further fling scrolls on that axis
150 // will be disabled.
151 bool disallow_horizontal_fling_scroll_;
152 bool disallow_vertical_fling_scroll_;
154 // Whether an active fling has seen an |Animate()| call. This is useful for
155 // determining if the fling start time should be re-initialized.
156 bool has_fling_animation_started_;
158 // Non-zero only within the scope of |scrollBy|.
159 gfx::Vector2dF current_fling_velocity_;
161 // Used to animate rubber-band over-scroll effect on Mac.
162 scoped_ptr<InputScrollElasticityController> scroll_elasticity_controller_;
164 bool smooth_scroll_enabled_;
166 bool uma_latency_reporting_enabled_;
168 base::TimeTicks last_fling_animate_time_;
170 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy);
173 } // namespace content
175 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_