cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / renderer / input / input_handler_proxy.h
blob35075513dfc90b6c95e15ed2187ffd6bf2156dbb
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"
18 namespace content {
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) {
29 public:
30 InputHandlerProxy(cc::InputHandler* input_handler,
31 InputHandlerProxyClient* client);
32 virtual ~InputHandlerProxy();
34 enum EventDisposition {
35 DID_HANDLE,
36 DID_NOT_HANDLE,
37 DROP_EVENT
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 void WillShutdown() override;
46 void Animate(base::TimeTicks time) override;
47 void MainThreadHasStoppedFlinging() override;
48 void DidOverscroll(const gfx::PointF& causal_event_viewport_point,
49 const gfx::Vector2dF& accumulated_overscroll,
50 const gfx::Vector2dF& latest_overscroll_delta) override;
52 // blink::WebGestureCurveTarget implementation.
53 virtual bool scrollBy(const blink::WebFloatSize& offset,
54 const blink::WebFloatSize& velocity);
56 bool gesture_scroll_on_impl_thread_for_testing() const {
57 return gesture_scroll_on_impl_thread_;
60 private:
61 EventDisposition HandleGestureFling(const blink::WebGestureEvent& event);
63 // Returns true if the event should be suppressed due to to an active,
64 // boost-enabled fling, in which case further processing should cease.
65 bool FilterInputEventForFlingBoosting(const blink::WebInputEvent& event);
67 // Schedule a time in the future after which a boost-enabled fling will
68 // terminate without further momentum from the user (see |Animate()|).
69 void ExtendBoostedFlingTimeout(const blink::WebGestureEvent& event);
71 // Returns true if we scrolled by the increment.
72 bool TouchpadFlingScroll(const blink::WebFloatSize& increment);
74 // Returns true if we actually had an active fling to cancel, also notifying
75 // the client that the fling has ended. Note that if a boosted fling is active
76 // and suppressing an active scroll sequence, a synthetic GestureScrollBegin
77 // will be injected to resume scrolling.
78 bool CancelCurrentFling();
80 // Returns true if we actually had an active fling to cancel.
81 bool CancelCurrentFlingWithoutNotifyingClient();
83 scoped_ptr<blink::WebGestureCurve> fling_curve_;
84 // Parameters for the active fling animation, stored in case we need to
85 // transfer it out later.
86 blink::WebActiveWheelFlingParameters fling_parameters_;
88 InputHandlerProxyClient* client_;
89 cc::InputHandler* input_handler_;
91 // Time at which an active fling should expire due to a deferred cancellation
92 // event. A call to |Animate()| after this time will end the fling.
93 double deferred_fling_cancel_time_seconds_;
95 // The last event that extended the lifetime of the boosted fling. If the
96 // event was a scroll gesture, a GestureScrollBegin will be inserted if the
97 // fling terminates (via |CancelCurrentFling()|).
98 blink::WebGestureEvent last_fling_boost_event_;
100 #ifndef NDEBUG
101 bool expect_scroll_update_end_;
102 #endif
103 bool gesture_scroll_on_impl_thread_;
104 bool gesture_pinch_on_impl_thread_;
105 // This is always false when there are no flings on the main thread, but
106 // conservative in the sense that we might not be actually flinging when it is
107 // true.
108 bool fling_may_be_active_on_main_thread_;
109 // The axes on which the current fling is allowed to scroll. If a given fling
110 // has overscrolled on a particular axis, further fling scrolls on that axis
111 // will be disabled.
112 bool disallow_horizontal_fling_scroll_;
113 bool disallow_vertical_fling_scroll_;
115 // Whether an active fling has seen an |Animate()| call. This is useful for
116 // determining if the fling start time should be re-initialized.
117 bool has_fling_animation_started_;
119 // Non-zero only within the scope of |scrollBy|.
120 gfx::Vector2dF current_fling_velocity_;
122 bool smooth_scroll_enabled_;
124 DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy);
127 } // namespace content
129 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_