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"
21 class InputHandlerProxyClient;
23 // This class is a proxy between the content input event filtering and the
24 // compositor's input handling logic. InputHandlerProxy instances live entirely
25 // on the compositor thread. Each InputHandler instance handles input events
26 // intended for a specific WebWidget.
27 class CONTENT_EXPORT InputHandlerProxy
28 : public cc::InputHandlerClient,
29 public NON_EXPORTED_BASE(blink::WebGestureCurveTarget) {
31 InputHandlerProxy(cc::InputHandler* input_handler,
32 InputHandlerProxyClient* client);
33 virtual ~InputHandlerProxy();
35 enum EventDisposition {
40 EventDisposition HandleInputEventWithLatencyInfo(
41 const blink::WebInputEvent& event,
42 ui::LatencyInfo* latency_info);
43 EventDisposition HandleInputEvent(const blink::WebInputEvent& event);
45 // cc::InputHandlerClient implementation.
46 void WillShutdown() override;
47 void Animate(base::TimeTicks time) override;
48 void MainThreadHasStoppedFlinging() override;
50 // blink::WebGestureCurveTarget implementation.
51 virtual bool scrollBy(const blink::WebFloatSize& offset,
52 const blink::WebFloatSize& velocity);
54 bool gesture_scroll_on_impl_thread_for_testing() const {
55 return gesture_scroll_on_impl_thread_;
59 EventDisposition HandleGestureFling(const blink::WebGestureEvent& event);
61 // Returns true if the event should be suppressed due to to an active,
62 // boost-enabled fling, in which case further processing should cease.
63 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent& event);
65 // Schedule a time in the future after which a boost-enabled fling will
66 // terminate without further momentum from the user (see |Animate()|).
67 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent& event);
69 // Returns true if we scrolled by the increment.
70 bool TouchpadFlingScroll(const blink::WebFloatSize& increment);
72 // Returns true if we actually had an active fling to cancel, also notifying
73 // the client that the fling has ended. Note that if a boosted fling is active
74 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
75 // will be injected to resume scrolling.
76 bool CancelCurrentFling();
78 // Returns true if we actually had an active fling to cancel.
79 bool CancelCurrentFlingWithoutNotifyingClient();
81 // Used to send overscroll messages to the browser.
82 void HandleOverscroll(
83 const gfx::Point& causal_event_viewport_point,
84 const cc::InputHandlerScrollResult& scroll_result);
86 scoped_ptr<blink::WebGestureCurve> fling_curve_;
87 // Parameters for the active fling animation, stored in case we need to
88 // transfer it out later.
89 blink::WebActiveWheelFlingParameters fling_parameters_;
91 InputHandlerProxyClient* client_;
92 cc::InputHandler* input_handler_;
94 // Time at which an active fling should expire due to a deferred cancellation
95 // event. A call to |Animate()| after this time will end the fling.
96 double deferred_fling_cancel_time_seconds_;
98 // The last event that extended the lifetime of the boosted fling. If the
99 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
100 // fling terminates (via |CancelCurrentFling()|).
101 blink::WebGestureEvent last_fling_boost_event_;
104 bool expect_scroll_update_end_;
106 bool gesture_scroll_on_impl_thread_;
107 bool gesture_pinch_on_impl_thread_;
108 // This is always false when there are no flings on the main thread, but
109 // conservative in the sense that we might not be actually flinging when it is
111 bool fling_may_be_active_on_main_thread_;
112 // The axes on which the current fling is allowed to scroll. If a given fling
113 // has overscrolled on a particular axis, further fling scrolls on that axis
115 bool disallow_horizontal_fling_scroll_;
116 bool disallow_vertical_fling_scroll_;
118 // Whether an active fling has seen an |Animate()| call. This is useful for
119 // determining if the fling start time should be re-initialized.
120 bool has_fling_animation_started_;
122 // Non-zero only within the scope of |scrollBy|.
123 gfx::Vector2dF current_fling_velocity_;
125 bool smooth_scroll_enabled_;
127 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy);
130 } // namespace content
132 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_