Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / input / input_handler.h
1 // Copyright 2011 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 CC_INPUT_INPUT_HANDLER_H_
6 #define CC_INPUT_INPUT_HANDLER_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/base/swap_promise_monitor.h"
13 #include "cc/input/scrollbar.h"
14
15 namespace gfx {
16 class Point;
17 class PointF;
18 class Vector2d;
19 class Vector2dF;
20 }
21
22 namespace ui { struct LatencyInfo; }
23
24 namespace cc {
25
26 class LayerScrollOffsetDelegate;
27
28 struct CC_EXPORT InputHandlerScrollResult {
29   InputHandlerScrollResult();
30   // Did any layer scroll as a result this ScrollBy call?
31   bool did_scroll;
32   // Was any of the scroll delta argument to this ScrollBy call not used?
33   bool did_overscroll_root;
34   // The total overscroll that has been accumulated by all ScrollBy calls that
35   // have had overscroll since the last ScrollBegin call. This resets upon a
36   // ScrollBy with no overscroll.
37   gfx::Vector2dF accumulated_root_overscroll;
38   // The amount of the scroll delta argument to this ScrollBy call that was not
39   // used for scrolling.
40   gfx::Vector2dF unused_scroll_delta;
41 };
42
43 class CC_EXPORT InputHandlerClient {
44  public:
45   virtual ~InputHandlerClient() {}
46
47   virtual void WillShutdown() = 0;
48   virtual void Animate(base::TimeTicks time) = 0;
49   virtual void MainThreadHasStoppedFlinging() = 0;
50
51  protected:
52   InputHandlerClient() {}
53
54  private:
55   DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
56 };
57
58 // The InputHandler is a way for the embedders to interact with the impl thread
59 // side of the compositor implementation. There is one InputHandler per
60 // LayerTreeHost. To use the input handler, implement the InputHanderClient
61 // interface and bind it to the handler on the compositor thread.
62 class CC_EXPORT InputHandler {
63  public:
64   // Note these are used in a histogram. Do not reorder or delete existing
65   // entries.
66   enum ScrollStatus {
67     ScrollOnMainThread = 0,
68     ScrollStarted,
69     ScrollIgnored,
70     ScrollUnknown,
71     // This must be the last entry.
72     ScrollStatusCount
73   };
74   enum ScrollInputType { Gesture, Wheel, NonBubblingGesture };
75
76   // Binds a client to this handler to receive notifications. Only one client
77   // can be bound to an InputHandler. The client must live at least until the
78   // handler calls WillShutdown() on the client.
79   virtual void BindToClient(InputHandlerClient* client) = 0;
80
81   // Selects a layer to be scrolled at a given point in viewport (logical
82   // pixel) coordinates. Returns ScrollStarted if the layer at the coordinates
83   // can be scrolled, ScrollOnMainThread if the scroll event should instead be
84   // delegated to the main thread, or ScrollIgnored if there is nothing to be
85   // scrolled at the given coordinates.
86   virtual ScrollStatus ScrollBegin(const gfx::Point& viewport_point,
87                                    ScrollInputType type) = 0;
88
89   virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point,
90                                       const gfx::Vector2dF& scroll_delta) = 0;
91
92   // Scroll the selected layer starting at the given position. If the scroll
93   // type given to ScrollBegin was a gesture, then the scroll point and delta
94   // should be in viewport (logical pixel) coordinates. Otherwise they are in
95   // scrolling layer's (logical pixel) space. If there is no room to move the
96   // layer in the requested direction, its first ancestor layer that can be
97   // scrolled will be moved instead. The return value's |did_scroll| field is
98   // set to false if no layer can be moved in the requested direction at all,
99   // and set to true if any layer is moved.
100   // If the scroll delta hits the root layer, and the layer can no longer move,
101   // the root overscroll accumulated within this ScrollBegin() scope is reported
102   // in the return value's |accumulated_overscroll| field.
103   // Should only be called if ScrollBegin() returned ScrollStarted.
104   virtual InputHandlerScrollResult ScrollBy(
105       const gfx::Point& viewport_point,
106       const gfx::Vector2dF& scroll_delta) = 0;
107
108   virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
109                                       ScrollDirection direction) = 0;
110
111   // Returns ScrollStarted if a layer was being actively being scrolled,
112   // ScrollIgnored if not.
113   virtual ScrollStatus FlingScrollBegin() = 0;
114
115   virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0;
116
117   // Stop scrolling the selected layer. Should only be called if ScrollBegin()
118   // returned ScrollStarted.
119   virtual void ScrollEnd() = 0;
120
121   virtual void SetRootLayerScrollOffsetDelegate(
122       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) = 0;
123
124   // Called when the value returned by
125   // LayerScrollOffsetDelegate.GetTotalScrollOffset has changed for reasons
126   // other than a SetTotalScrollOffset call.
127   // NOTE: This should only called after a valid delegate was set via a call to
128   // SetRootLayerScrollOffsetDelegate.
129   virtual void OnRootLayerDelegatedScrollOffsetChanged() = 0;
130
131   virtual void PinchGestureBegin() = 0;
132   virtual void PinchGestureUpdate(float magnify_delta,
133                                   const gfx::Point& anchor) = 0;
134   virtual void PinchGestureEnd() = 0;
135
136   // Request another callback to InputHandlerClient::Animate().
137   virtual void SetNeedsAnimate() = 0;
138
139   // Whether the layer under |viewport_point| is the currently scrolling layer.
140   virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
141                                            ScrollInputType type) = 0;
142
143   virtual bool HaveTouchEventHandlersAt(const gfx::Point& viewport_point) = 0;
144
145   // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
146   // LatencyInfoSwapPromiseMonitor. During the life time of the
147   // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
148   // is called on LayerTreeHostImpl, the original latency info will be turned
149   // into a LatencyInfoSwapPromise.
150   virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
151       ui::LatencyInfo* latency) = 0;
152
153  protected:
154   InputHandler() {}
155   virtual ~InputHandler() {}
156
157  private:
158   DISALLOW_COPY_AND_ASSIGN(InputHandler);
159 };
160
161 }  // namespace cc
162
163 #endif  // CC_INPUT_INPUT_HANDLER_H_