Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / renderer / input / input_handler_proxy.h
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.
4
5 #ifndef CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_
6 #define CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_
7
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"
17
18 namespace content {
19
20 class InputHandlerProxyClient;
21
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();
33
34   enum EventDisposition {
35     DID_HANDLE,
36     DID_NOT_HANDLE,
37     DROP_EVENT
38   };
39   EventDisposition HandleInputEventWithLatencyInfo(
40       const blink::WebInputEvent& event,
41       ui::LatencyInfo* latency_info);
42   EventDisposition HandleInputEvent(const blink::WebInputEvent& event);
43
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(const gfx::Vector2dF& accumulated_overscroll,
49                              const gfx::Vector2dF& latest_overscroll_delta)
50       OVERRIDE;
51
52   // blink::WebGestureCurveTarget implementation.
53   virtual bool scrollBy(const blink::WebFloatSize& offset,
54                         const blink::WebFloatSize& velocity);
55
56   bool gesture_scroll_on_impl_thread_for_testing() const {
57     return gesture_scroll_on_impl_thread_;
58   }
59
60  private:
61   EventDisposition HandleGestureFling(const blink::WebGestureEvent& event);
62
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);
66
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 FlingBoostExtend(const blink::WebGestureEvent& event);
70
71   // Cancel the current fling and insert a GestureScrollBegin if necessary.
72   void FlingBoostCancelAndResumeScrollingIfNecessary();
73
74   // Returns true if we scrolled by the increment.
75   bool TouchpadFlingScroll(const blink::WebFloatSize& increment);
76
77   // Returns true if we actually had an active fling to cancel.
78   bool CancelCurrentFling(bool send_fling_stopped_notification);
79
80   scoped_ptr<blink::WebGestureCurve> fling_curve_;
81   // Parameters for the active fling animation, stored in case we need to
82   // transfer it out later.
83   blink::WebActiveWheelFlingParameters fling_parameters_;
84
85   InputHandlerProxyClient* client_;
86   cc::InputHandler* input_handler_;
87
88   // Time at which an active fling should expire due to a deferred cancellation
89   // event. A call to |Animate()| after this time will end the fling.
90   double deferred_fling_cancel_time_seconds_;
91
92   // The last event that extended the lifetime of the boosted fling. If the
93   // event was a scroll gesture, a GestureScrollBegin will be inserted if the
94   // fling terminates (via |FlingBoostCancelAndResumeScrollingIfNecessary()|).
95   blink::WebGestureEvent last_fling_boost_event_;
96
97 #ifndef NDEBUG
98   bool expect_scroll_update_end_;
99 #endif
100   bool gesture_scroll_on_impl_thread_;
101   bool gesture_pinch_on_impl_thread_;
102   // This is always false when there are no flings on the main thread, but
103   // conservative in the sense that we might not be actually flinging when it is
104   // true.
105   bool fling_may_be_active_on_main_thread_;
106   // The axes on which the current fling is allowed to scroll.  If a given fling
107   // has overscrolled on a particular axis, further fling scrolls on that axis
108   // will be disabled.
109   bool disallow_horizontal_fling_scroll_;
110   bool disallow_vertical_fling_scroll_;
111
112   // Whether an active fling has seen an |Animate()| call. This is useful for
113   // determining if the fling start time should be re-initialized.
114   bool has_fling_animation_started_;
115
116   // Non-zero only within the scope of |scrollBy|.
117   gfx::Vector2dF current_fling_velocity_;
118
119   DISALLOW_COPY_AND_ASSIGN(InputHandlerProxy);
120 };
121
122 }  // namespace content
123
124 #endif  // CONTENT_RENDERER_INPUT_INPUT_HANDLER_PROXY_H_