- add sources.
[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/time/time.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/input/scrollbar.h"
12
13 namespace gfx {
14 class Point;
15 class PointF;
16 class Vector2d;
17 class Vector2dF;
18 }
19
20 namespace ui { struct LatencyInfo; }
21
22 namespace cc {
23
24 class LayerScrollOffsetDelegate;
25
26 struct DidOverscrollParams {
27   gfx::Vector2dF accumulated_overscroll;
28   gfx::Vector2dF latest_overscroll_delta;
29   gfx::Vector2dF current_fling_velocity;
30 };
31
32 class CC_EXPORT InputHandlerClient {
33  public:
34   virtual ~InputHandlerClient() {}
35
36   virtual void WillShutdown() = 0;
37   virtual void Animate(base::TimeTicks time) = 0;
38   virtual void MainThreadHasStoppedFlinging() = 0;
39
40   // Called when scroll deltas reaching the root scrolling layer go unused.
41   // The accumulated overscroll is scoped by the most recent call to
42   // InputHandler::ScrollBegin.
43   virtual void DidOverscroll(const DidOverscrollParams& params) = 0;
44
45  protected:
46   InputHandlerClient() {}
47
48  private:
49   DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
50 };
51
52 // The InputHandler is a way for the embedders to interact with the impl thread
53 // side of the compositor implementation. There is one InputHandler per
54 // LayerTreeHost. To use the input handler, implement the InputHanderClient
55 // interface and bind it to the handler on the compositor thread.
56 class CC_EXPORT InputHandler {
57  public:
58   enum ScrollStatus { ScrollOnMainThread, ScrollStarted, ScrollIgnored };
59   enum ScrollInputType { Gesture, Wheel, NonBubblingGesture };
60
61   // Binds a client to this handler to receive notifications. Only one client
62   // can be bound to an InputHandler. The client must live at least until the
63   // handler calls WillShutdown() on the client.
64   virtual void BindToClient(InputHandlerClient* client) = 0;
65
66   // Selects a layer to be scrolled at a given point in viewport (logical
67   // pixel) coordinates. Returns ScrollStarted if the layer at the coordinates
68   // can be scrolled, ScrollOnMainThread if the scroll event should instead be
69   // delegated to the main thread, or ScrollIgnored if there is nothing to be
70   // scrolled at the given coordinates.
71   virtual ScrollStatus ScrollBegin(gfx::Point viewport_point,
72                                    ScrollInputType type) = 0;
73
74   // Scroll the selected layer starting at the given position. If the scroll
75   // type given to ScrollBegin was a gesture, then the scroll point and delta
76   // should be in viewport (logical pixel) coordinates. Otherwise they are in
77   // scrolling layer's (logical pixel) space. If there is no room to move the
78   // layer in the requested direction, its first ancestor layer that can be
79   // scrolled will be moved instead. If no layer can be moved in the requested
80   // direction at all, then false is returned. If any layer is moved, then
81   // true is returned.
82   // If the scroll delta hits the root layer, and the layer can no longer move,
83   // the root overscroll accumulated within this ScrollBegin() scope is reported
84   // to the client.
85   // Should only be called if ScrollBegin() returned ScrollStarted.
86   virtual bool ScrollBy(gfx::Point viewport_point,
87                         gfx::Vector2dF scroll_delta) = 0;
88
89   virtual bool ScrollVerticallyByPage(
90       gfx::Point viewport_point,
91       ScrollDirection direction) = 0;
92
93   // Returns ScrollStarted if a layer was being actively being scrolled,
94   // ScrollIgnored if not.
95   virtual ScrollStatus FlingScrollBegin() = 0;
96
97   virtual void NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) = 0;
98
99   virtual void MouseMoveAt(gfx::Point mouse_position) = 0;
100
101   // Stop scrolling the selected layer. Should only be called if ScrollBegin()
102   // returned ScrollStarted.
103   virtual void ScrollEnd() = 0;
104
105   virtual void SetRootLayerScrollOffsetDelegate(
106       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) = 0;
107
108   // Called when the value returned by
109   // LayerScrollOffsetDelegate.GetTotalScrollOffset has changed for reasons
110   // other than a SetTotalScrollOffset call.
111   // NOTE: This should only called after a valid delegate was set via a call to
112   // SetRootLayerScrollOffsetDelegate.
113   virtual void OnRootLayerDelegatedScrollOffsetChanged() = 0;
114
115   virtual void PinchGestureBegin() = 0;
116   virtual void PinchGestureUpdate(float magnify_delta, gfx::Point anchor) = 0;
117   virtual void PinchGestureEnd() = 0;
118
119   virtual void StartPageScaleAnimation(gfx::Vector2d target_offset,
120                                        bool anchor_point,
121                                        float page_scale,
122                                        base::TimeDelta duration) = 0;
123
124   // Request another callback to InputHandlerClient::Animate().
125   virtual void ScheduleAnimation() = 0;
126
127   virtual bool HaveTouchEventHandlersAt(gfx::Point viewport_point) = 0;
128
129   virtual void SetLatencyInfoForInputEvent(
130       const ui::LatencyInfo& latency_info) = 0;
131
132  protected:
133   InputHandler() {}
134   virtual ~InputHandler() {}
135
136  private:
137   DISALLOW_COPY_AND_ASSIGN(InputHandler);
138 };
139
140 }  // namespace cc
141
142 #endif  // CC_INPUT_INPUT_HANDLER_H_