Revert of Update V8 to version 3.27.17 (based on bleeding_edge revision r21586) ...
[chromium-blink-merge.git] / cc / input / input_handler.h
blob7f35ddabb1e660b8616f53a9181de10a41d9b472
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.
5 #ifndef CC_INPUT_INPUT_HANDLER_H_
6 #define CC_INPUT_INPUT_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/base/swap_promise_monitor.h"
12 #include "cc/input/scrollbar.h"
14 namespace gfx {
15 class Point;
16 class PointF;
17 class Vector2d;
18 class Vector2dF;
21 namespace ui { struct LatencyInfo; }
23 namespace cc {
25 class LayerScrollOffsetDelegate;
27 class CC_EXPORT InputHandlerClient {
28 public:
29 virtual ~InputHandlerClient() {}
31 virtual void WillShutdown() = 0;
32 virtual void Animate(base::TimeTicks time) = 0;
33 virtual void MainThreadHasStoppedFlinging() = 0;
35 // Called when scroll deltas reaching the root scrolling layer go unused.
36 // The accumulated overscroll is scoped by the most recent call to
37 // InputHandler::ScrollBegin.
38 virtual void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll,
39 const gfx::Vector2dF& latest_overscroll_delta) = 0;
41 protected:
42 InputHandlerClient() {}
44 private:
45 DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
48 // The InputHandler is a way for the embedders to interact with the impl thread
49 // side of the compositor implementation. There is one InputHandler per
50 // LayerTreeHost. To use the input handler, implement the InputHanderClient
51 // interface and bind it to the handler on the compositor thread.
52 class CC_EXPORT InputHandler {
53 public:
54 // Note these are used in a histogram. Do not reorder or delete existing
55 // entries.
56 enum ScrollStatus {
57 ScrollOnMainThread = 0,
58 ScrollStarted,
59 ScrollIgnored,
60 ScrollUnknown,
61 // This must be the last entry.
62 ScrollStatusCount
64 enum ScrollInputType { Gesture, Wheel, NonBubblingGesture };
66 // Binds a client to this handler to receive notifications. Only one client
67 // can be bound to an InputHandler. The client must live at least until the
68 // handler calls WillShutdown() on the client.
69 virtual void BindToClient(InputHandlerClient* client) = 0;
71 // Selects a layer to be scrolled at a given point in viewport (logical
72 // pixel) coordinates. Returns ScrollStarted if the layer at the coordinates
73 // can be scrolled, ScrollOnMainThread if the scroll event should instead be
74 // delegated to the main thread, or ScrollIgnored if there is nothing to be
75 // scrolled at the given coordinates.
76 virtual ScrollStatus ScrollBegin(const gfx::Point& viewport_point,
77 ScrollInputType type) = 0;
79 // Scroll the selected layer starting at the given position. If the scroll
80 // type given to ScrollBegin was a gesture, then the scroll point and delta
81 // should be in viewport (logical pixel) coordinates. Otherwise they are in
82 // scrolling layer's (logical pixel) space. If there is no room to move the
83 // layer in the requested direction, its first ancestor layer that can be
84 // scrolled will be moved instead. If no layer can be moved in the requested
85 // direction at all, then false is returned. If any layer is moved, then
86 // true is returned.
87 // If the scroll delta hits the root layer, and the layer can no longer move,
88 // the root overscroll accumulated within this ScrollBegin() scope is reported
89 // to the client.
90 // Should only be called if ScrollBegin() returned ScrollStarted.
91 virtual bool ScrollBy(const gfx::Point& viewport_point,
92 const gfx::Vector2dF& scroll_delta) = 0;
94 virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
95 ScrollDirection direction) = 0;
97 // Returns ScrollStarted if a layer was being actively being scrolled,
98 // ScrollIgnored if not.
99 virtual ScrollStatus FlingScrollBegin() = 0;
101 virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0;
103 // Stop scrolling the selected layer. Should only be called if ScrollBegin()
104 // returned ScrollStarted.
105 virtual void ScrollEnd() = 0;
107 virtual void SetRootLayerScrollOffsetDelegate(
108 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) = 0;
110 // Called when the value returned by
111 // LayerScrollOffsetDelegate.GetTotalScrollOffset has changed for reasons
112 // other than a SetTotalScrollOffset call.
113 // NOTE: This should only called after a valid delegate was set via a call to
114 // SetRootLayerScrollOffsetDelegate.
115 virtual void OnRootLayerDelegatedScrollOffsetChanged() = 0;
117 virtual void PinchGestureBegin() = 0;
118 virtual void PinchGestureUpdate(float magnify_delta,
119 const gfx::Point& anchor) = 0;
120 virtual void PinchGestureEnd() = 0;
122 virtual void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
123 bool anchor_point,
124 float page_scale,
125 base::TimeDelta duration) = 0;
127 // Request another callback to InputHandlerClient::Animate().
128 virtual void SetNeedsAnimate() = 0;
130 // Whether the layer under |viewport_point| is the currently scrolling layer.
131 virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
132 ScrollInputType type) = 0;
134 virtual bool HaveTouchEventHandlersAt(const gfx::Point& viewport_point) = 0;
136 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
137 // LatencyInfoSwapPromiseMonitor. During the life time of the
138 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
139 // is called on LayerTreeHostImpl, the original latency info will be turned
140 // into a LatencyInfoSwapPromise.
141 virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
142 ui::LatencyInfo* latency) = 0;
144 protected:
145 InputHandler() {}
146 virtual ~InputHandler() {}
148 private:
149 DISALLOW_COPY_AND_ASSIGN(InputHandler);
152 } // namespace cc
154 #endif // CC_INPUT_INPUT_HANDLER_H_