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/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"
20 class InputHandlerProxyClient
;
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
) {
30 InputHandlerProxy(cc::InputHandler
* input_handler
,
31 InputHandlerProxyClient
* client
);
32 virtual ~InputHandlerProxy();
34 enum EventDisposition
{
39 EventDisposition
HandleInputEventWithLatencyInfo(
40 const blink::WebInputEvent
& event
,
41 ui::LatencyInfo
* latency_info
);
42 EventDisposition
HandleInputEvent(const blink::WebInputEvent
& event
);
44 // cc::InputHandlerClient implementation.
45 virtual void WillShutdown() override
;
46 virtual void Animate(base::TimeTicks time
) override
;
47 virtual void MainThreadHasStoppedFlinging() override
;
48 virtual void DidOverscroll(
49 const gfx::PointF
& causal_event_viewport_point
,
50 const gfx::Vector2dF
& accumulated_overscroll
,
51 const gfx::Vector2dF
& latest_overscroll_delta
) override
;
53 // blink::WebGestureCurveTarget implementation.
54 virtual bool scrollBy(const blink::WebFloatSize
& offset
,
55 const blink::WebFloatSize
& velocity
);
57 bool gesture_scroll_on_impl_thread_for_testing() const {
58 return gesture_scroll_on_impl_thread_
;
62 EventDisposition
HandleGestureFling(const blink::WebGestureEvent
& event
);
64 // Returns true if the event should be suppressed due to to an active,
65 // boost-enabled fling, in which case further processing should cease.
66 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent
& event
);
68 // Schedule a time in the future after which a boost-enabled fling will
69 // terminate without further momentum from the user (see |Animate()|).
70 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent
& event
);
72 // Returns true if we scrolled by the increment.
73 bool TouchpadFlingScroll(const blink::WebFloatSize
& increment
);
75 // Returns true if we actually had an active fling to cancel, also notifying
76 // the client that the fling has ended. Note that if a boosted fling is active
77 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
78 // will be injected to resume scrolling.
79 bool CancelCurrentFling();
81 // Returns true if we actually had an active fling to cancel.
82 bool CancelCurrentFlingWithoutNotifyingClient();
84 scoped_ptr
<blink::WebGestureCurve
> fling_curve_
;
85 // Parameters for the active fling animation, stored in case we need to
86 // transfer it out later.
87 blink::WebActiveWheelFlingParameters fling_parameters_
;
89 InputHandlerProxyClient
* client_
;
90 cc::InputHandler
* input_handler_
;
92 // Time at which an active fling should expire due to a deferred cancellation
93 // event. A call to |Animate()| after this time will end the fling.
94 double deferred_fling_cancel_time_seconds_
;
96 // The last event that extended the lifetime of the boosted fling. If the
97 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
98 // fling terminates (via |CancelCurrentFling()|).
99 blink::WebGestureEvent last_fling_boost_event_
;
102 bool expect_scroll_update_end_
;
104 bool gesture_scroll_on_impl_thread_
;
105 bool gesture_pinch_on_impl_thread_
;
106 // This is always false when there are no flings on the main thread, but
107 // conservative in the sense that we might not be actually flinging when it is
109 bool fling_may_be_active_on_main_thread_
;
110 // The axes on which the current fling is allowed to scroll. If a given fling
111 // has overscrolled on a particular axis, further fling scrolls on that axis
113 bool disallow_horizontal_fling_scroll_
;
114 bool disallow_vertical_fling_scroll_
;
116 // Whether an active fling has seen an |Animate()| call. This is useful for
117 // determining if the fling start time should be re-initialized.
118 bool has_fling_animation_started_
;
120 // Non-zero only within the scope of |scrollBy|.
121 gfx::Vector2dF current_fling_velocity_
;
123 bool smooth_scroll_enabled_
;
125 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy
);
128 } // namespace content
130 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_