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"
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
) {
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
{
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
;
57 void UpdateRootLayerStateForSynchronousInputHandler(
58 const gfx::ScrollOffset
& total_scroll_offset
,
59 const gfx::ScrollOffset
& max_scroll_offset
,
60 const gfx::SizeF
& scrollable_size
,
61 float page_scale_factor
,
62 float min_page_scale_factor
,
63 float max_page_scale_factor
) override
;
65 // SynchronousInputHandlerProxy implementation.
66 void SetOnlySynchronouslyAnimateRootFlings(
67 SynchronousInputHandler
* synchronous_input_handler
) override
;
68 void SynchronouslyAnimate(base::TimeTicks time
) override
;
69 void SynchronouslySetRootScrollOffset(
70 const gfx::ScrollOffset
& root_offset
) override
;
72 // blink::WebGestureCurveTarget implementation.
73 virtual bool scrollBy(const blink::WebFloatSize
& offset
,
74 const blink::WebFloatSize
& velocity
);
76 bool gesture_scroll_on_impl_thread_for_testing() const {
77 return gesture_scroll_on_impl_thread_
;
81 // Helper functions for handling more complicated input events.
82 EventDisposition
HandleMouseWheel(
83 const blink::WebMouseWheelEvent
& event
);
84 EventDisposition
HandleGestureScrollBegin(
85 const blink::WebGestureEvent
& event
);
86 EventDisposition
HandleGestureScrollUpdate(
87 const blink::WebGestureEvent
& event
);
88 EventDisposition
HandleGestureScrollEnd(
89 const blink::WebGestureEvent
& event
);
90 EventDisposition
HandleGestureFlingStart(
91 const blink::WebGestureEvent
& event
);
92 EventDisposition
HandleTouchStart(
93 const blink::WebTouchEvent
& event
);
95 // Returns true if the event should be suppressed due to to an active,
96 // boost-enabled fling, in which case further processing should cease.
97 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent
& event
);
99 // Schedule a time in the future after which a boost-enabled fling will
100 // terminate without further momentum from the user (see |Animate()|).
101 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent
& event
);
103 // Returns true if we scrolled by the increment.
104 bool TouchpadFlingScroll(const blink::WebFloatSize
& increment
);
106 // Returns true if we actually had an active fling to cancel, also notifying
107 // the client that the fling has ended. Note that if a boosted fling is active
108 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
109 // will be injected to resume scrolling.
110 bool CancelCurrentFling();
112 // Returns true if we actually had an active fling to cancel.
113 bool CancelCurrentFlingWithoutNotifyingClient();
115 // Request a frame of animation from the InputHandler or
116 // SynchronousInputHandler. They can provide that by calling Animate().
117 void RequestAnimation();
119 // Used to send overscroll messages to the browser.
120 void HandleOverscroll(
121 const gfx::Point
& causal_event_viewport_point
,
122 const cc::InputHandlerScrollResult
& scroll_result
);
124 scoped_ptr
<blink::WebGestureCurve
> fling_curve_
;
125 // Parameters for the active fling animation, stored in case we need to
126 // transfer it out later.
127 blink::WebActiveWheelFlingParameters fling_parameters_
;
129 InputHandlerProxyClient
* client_
;
130 cc::InputHandler
* input_handler_
;
132 // Time at which an active fling should expire due to a deferred cancellation
133 // event. A call to |Animate()| after this time will end the fling.
134 double deferred_fling_cancel_time_seconds_
;
136 // The last event that extended the lifetime of the boosted fling. If the
137 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
138 // fling terminates (via |CancelCurrentFling()|).
139 blink::WebGestureEvent last_fling_boost_event_
;
141 // When present, Animates are not requested to the InputHandler, but to this
142 // SynchronousInputHandler instead. And all Animate() calls are expected to
143 // happen via the SynchronouslyAnimate() call instead of coming directly from
145 SynchronousInputHandler
* synchronous_input_handler_
;
146 bool allow_root_animate_
;
149 bool expect_scroll_update_end_
;
151 bool gesture_scroll_on_impl_thread_
;
152 bool gesture_pinch_on_impl_thread_
;
153 // This is always false when there are no flings on the main thread, but
154 // conservative in the sense that we might not be actually flinging when it is
156 bool fling_may_be_active_on_main_thread_
;
157 // The axes on which the current fling is allowed to scroll. If a given fling
158 // has overscrolled on a particular axis, further fling scrolls on that axis
160 bool disallow_horizontal_fling_scroll_
;
161 bool disallow_vertical_fling_scroll_
;
163 // Whether an active fling has seen an |Animate()| call. This is useful for
164 // determining if the fling start time should be re-initialized.
165 bool has_fling_animation_started_
;
167 // Non-zero only within the scope of |scrollBy|.
168 gfx::Vector2dF current_fling_velocity_
;
170 // Used to animate rubber-band over-scroll effect on Mac.
171 scoped_ptr
<InputScrollElasticityController
> scroll_elasticity_controller_
;
173 bool smooth_scroll_enabled_
;
175 bool uma_latency_reporting_enabled_
;
177 base::TimeTicks last_fling_animate_time_
;
179 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy
);
182 } // namespace content
184 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_