1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
18 class MockRenderWidgetHost
;
19 class OverscrollControllerDelegate
;
21 // Indicates the direction that the scroll is heading in relative to the screen,
22 // with the top being NORTH.
32 // When a page is scrolled beyond the scrollable region, it will trigger an
33 // overscroll gesture. This controller receives the events that are dispatched
34 // to the renderer, and the ACKs of events, and updates the overscroll gesture
35 // status accordingly.
36 class OverscrollController
{
38 OverscrollController();
39 virtual ~OverscrollController();
41 // The result of |DispatchEvent()|, indicating either how the event was
42 // handled, or how it should be handled by the caller.
45 SHOULD_FORWARD_TO_RENDERER
,
46 SHOULD_FORWARD_TO_GESTURE_QUEUE
48 // This must be called when dispatching any event from the
49 // RenderWidgetHostView so that the state of the overscroll gesture can be
51 Disposition
DispatchEvent(const blink::WebInputEvent
& event
,
52 const ui::LatencyInfo
& latency_info
);
54 // This must be called when the ACK for any event comes in. This updates the
55 // overscroll gesture status as appropriate.
56 void ReceivedEventACK(const blink::WebInputEvent
& event
, bool processed
);
58 // This must be called when a gesture event is filtered out and not sent to
60 void DiscardingGestureEvent(const blink::WebGestureEvent
& event
);
62 OverscrollMode
overscroll_mode() const { return overscroll_mode_
; }
64 void set_delegate(OverscrollControllerDelegate
* delegate
) {
68 // Resets internal states.
71 // Cancels any in-progress overscroll (and calls OnOverscrollModeChange on the
72 // delegate if necessary), and resets internal states.
76 friend class MockRenderWidgetHost
;
78 // Different scrolling states.
82 STATE_CONTENT_SCROLLING
,
86 // Returns true if the event indicates that the in-progress overscroll gesture
87 // can now be completed.
88 bool DispatchEventCompletesAction(
89 const blink::WebInputEvent
& event
) const;
91 // Returns true to indicate that dispatching the event should reset the
92 // overscroll gesture status.
93 bool DispatchEventResetsState(const blink::WebInputEvent
& event
) const;
95 // Processes an event to update the internal state for overscroll. Returns
96 // true if the state is updated, false otherwise.
97 bool ProcessEventForOverscroll(const blink::WebInputEvent
& event
);
99 // Processes horizontal overscroll. This can update both the overscroll mode
100 // and the over scroll amount (i.e. |overscroll_mode_|, |overscroll_delta_x_|
101 // and |overscroll_delta_y_|).
102 void ProcessOverscroll(float delta_x
,
104 blink::WebInputEvent::Type event_type
);
106 // Completes the desired action from the current gesture.
107 void CompleteAction();
109 // Sets the overscroll mode (and triggers callback in the delegate when
111 void SetOverscrollMode(OverscrollMode new_mode
);
113 // The current state of overscroll gesture.
114 OverscrollMode overscroll_mode_
;
116 // Used to keep track of the scrolling state.
117 // If scrolling starts, and some scroll events are consumed at the beginning
118 // of the scroll (i.e. some content on the web-page was scrolled), then do not
119 // process any of the subsequent scroll events for generating overscroll
121 ScrollState scroll_state_
;
123 // The amount of overscroll in progress. These values are invalid when
124 // |overscroll_mode_| is set to OVERSCROLL_NONE.
125 float overscroll_delta_x_
;
126 float overscroll_delta_y_
;
128 // The delegate that receives the overscroll updates. The delegate is not
129 // owned by this controller.
130 OverscrollControllerDelegate
* delegate_
;
132 DISALLOW_COPY_AND_ASSIGN(OverscrollController
);
135 } // namespace content
137 #endif // CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_