Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / renderer / input / input_handler_proxy.h
blobfd99af6f0256a7bb0543337aa61ad46e5886baa8
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 "third_party/WebKit/public/platform/WebGestureCurve.h"
15 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
16 #include "third_party/WebKit/public/web/WebActiveWheelFlingParameters.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 namespace content {
21 class InputHandlerProxyClient;
22 class InputScrollElasticityController;
24 // This class is a proxy between the content input event filtering and the
25 // compositor's input handling logic. InputHandlerProxy instances live entirely
26 // on the compositor thread. Each InputHandler instance handles input events
27 // intended for a specific WebWidget.
28 class CONTENT_EXPORT InputHandlerProxy
29 : public cc::InputHandlerClient,
30 public NON_EXPORTED_BASE(blink::WebGestureCurveTarget) {
31 public:
32 InputHandlerProxy(cc::InputHandler* input_handler,
33 InputHandlerProxyClient* client);
34 virtual ~InputHandlerProxy();
36 InputScrollElasticityController* scroll_elasticity_controller() {
37 return scroll_elasticity_controller_.get();
40 enum EventDisposition {
41 DID_HANDLE,
42 DID_NOT_HANDLE,
43 DROP_EVENT
45 EventDisposition HandleInputEventWithLatencyInfo(
46 const blink::WebInputEvent& event,
47 ui::LatencyInfo* latency_info);
48 EventDisposition HandleInputEvent(const blink::WebInputEvent& event);
50 // cc::InputHandlerClient implementation.
51 void WillShutdown() override;
52 void Animate(base::TimeTicks time) override;
53 void MainThreadHasStoppedFlinging() override;
54 void ReconcileElasticOverscrollAndRootScroll() override;
56 // blink::WebGestureCurveTarget implementation.
57 virtual bool scrollBy(const blink::WebFloatSize& offset,
58 const blink::WebFloatSize& velocity);
60 bool gesture_scroll_on_impl_thread_for_testing() const {
61 return gesture_scroll_on_impl_thread_;
64 private:
65 // Helper functions for handling more complicated input events.
66 EventDisposition HandleMouseWheel(
67 const blink::WebMouseWheelEvent& event);
68 EventDisposition HandleGestureScrollBegin(
69 const blink::WebGestureEvent& event);
70 EventDisposition HandleGestureScrollUpdate(
71 const blink::WebGestureEvent& event);
72 EventDisposition HandleGestureScrollEnd(
73 const blink::WebGestureEvent& event);
74 EventDisposition HandleGestureFlingStart(
75 const blink::WebGestureEvent& event);
76 EventDisposition HandleTouchStart(
77 const blink::WebTouchEvent& event);
79 // Returns true if the event should be suppressed due to to an active,
80 // boost-enabled fling, in which case further processing should cease.
81 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent& event);
83 // Schedule a time in the future after which a boost-enabled fling will
84 // terminate without further momentum from the user (see |Animate()|).
85 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent& event);
87 // Returns true if we scrolled by the increment.
88 bool TouchpadFlingScroll(const blink::WebFloatSize& increment);
90 // Returns true if we actually had an active fling to cancel, also notifying
91 // the client that the fling has ended. Note that if a boosted fling is active
92 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
93 // will be injected to resume scrolling.
94 bool CancelCurrentFling();
96 // Returns true if we actually had an active fling to cancel.
97 bool CancelCurrentFlingWithoutNotifyingClient();
99 // Used to send overscroll messages to the browser.
100 void HandleOverscroll(
101 const gfx::Point& causal_event_viewport_point,
102 const cc::InputHandlerScrollResult& scroll_result);
104 scoped_ptr<blink::WebGestureCurve> fling_curve_;
105 // Parameters for the active fling animation, stored in case we need to
106 // transfer it out later.
107 blink::WebActiveWheelFlingParameters fling_parameters_;
109 InputHandlerProxyClient* client_;
110 cc::InputHandler* input_handler_;
112 // Time at which an active fling should expire due to a deferred cancellation
113 // event. A call to |Animate()| after this time will end the fling.
114 double deferred_fling_cancel_time_seconds_;
116 // The last event that extended the lifetime of the boosted fling. If the
117 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
118 // fling terminates (via |CancelCurrentFling()|).
119 blink::WebGestureEvent last_fling_boost_event_;
121 #ifndef NDEBUG
122 bool expect_scroll_update_end_;
123 #endif
124 bool gesture_scroll_on_impl_thread_;
125 bool gesture_pinch_on_impl_thread_;
126 // This is always false when there are no flings on the main thread, but
127 // conservative in the sense that we might not be actually flinging when it is
128 // true.
129 bool fling_may_be_active_on_main_thread_;
130 // The axes on which the current fling is allowed to scroll. If a given fling
131 // has overscrolled on a particular axis, further fling scrolls on that axis
132 // will be disabled.
133 bool disallow_horizontal_fling_scroll_;
134 bool disallow_vertical_fling_scroll_;
136 // Whether an active fling has seen an |Animate()| call. This is useful for
137 // determining if the fling start time should be re-initialized.
138 bool has_fling_animation_started_;
140 // Non-zero only within the scope of |scrollBy|.
141 gfx::Vector2dF current_fling_velocity_;
143 // Used to animate rubber-band over-scroll effect on Mac.
144 scoped_ptr<InputScrollElasticityController> scroll_elasticity_controller_;
146 bool smooth_scroll_enabled_;
148 bool uma_latency_reporting_enabled_;
150 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy);
153 } // namespace content
155 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_