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