Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / overscroll_controller.h
blob6ea77e60d461a0ba0c8eda42ea5f8d442b2447e0
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"
12 namespace ui {
13 class LatencyInfo;
16 namespace content {
18 class RenderWidgetHostViewAuraOverscrollTest;
19 class OverscrollControllerDelegate;
21 // Indicates the direction that the scroll is heading in relative to the screen,
22 // with the top being NORTH.
23 enum OverscrollMode {
24 OVERSCROLL_NONE,
25 OVERSCROLL_NORTH,
26 OVERSCROLL_SOUTH,
27 OVERSCROLL_WEST,
28 OVERSCROLL_EAST
31 // When a page is scrolled beyond the scrollable region, it will trigger an
32 // overscroll gesture. This controller receives the events that are dispatched
33 // to the renderer, and the ACKs of events, and updates the overscroll gesture
34 // status accordingly.
35 class OverscrollController {
36 public:
37 OverscrollController();
38 virtual ~OverscrollController();
40 // This must be called when dispatching any event from the
41 // RenderWidgetHostView so that the state of the overscroll gesture can be
42 // updated properly. Returns true if the event was handled, in which case
43 // further processing should cease.
44 bool WillHandleEvent(const blink::WebInputEvent& event);
46 // This must be called when the ACK for any event comes in. This updates the
47 // overscroll gesture status as appropriate.
48 void ReceivedEventACK(const blink::WebInputEvent& event, bool processed);
50 // This must be called when a gesture event is filtered out and not sent to
51 // the renderer.
52 void DiscardingGestureEvent(const blink::WebGestureEvent& event);
54 OverscrollMode overscroll_mode() const { return overscroll_mode_; }
56 void set_delegate(OverscrollControllerDelegate* delegate) {
57 delegate_ = delegate;
60 // Resets internal states.
61 void Reset();
63 // Cancels any in-progress overscroll (and calls OnOverscrollModeChange on the
64 // delegate if necessary), and resets internal states.
65 void Cancel();
67 private:
68 friend class RenderWidgetHostViewAuraOverscrollTest;
70 // Different scrolling states.
71 enum ScrollState {
72 STATE_UNKNOWN,
73 STATE_PENDING,
74 STATE_CONTENT_SCROLLING,
75 STATE_OVERSCROLLING,
78 // Returns true if the event indicates that the in-progress overscroll gesture
79 // can now be completed.
80 bool DispatchEventCompletesAction(
81 const blink::WebInputEvent& event) const;
83 // Returns true to indicate that dispatching the event should reset the
84 // overscroll gesture status.
85 bool DispatchEventResetsState(const blink::WebInputEvent& event) const;
87 // Processes an event to update the internal state for overscroll. Returns
88 // true if the state is updated, false otherwise.
89 bool ProcessEventForOverscroll(const blink::WebInputEvent& event);
91 // Processes horizontal overscroll. This can update both the overscroll mode
92 // and the over scroll amount (i.e. |overscroll_mode_|, |overscroll_delta_x_|
93 // and |overscroll_delta_y_|). Returns true if overscroll was handled by the
94 // delegate.
95 bool ProcessOverscroll(float delta_x,
96 float delta_y,
97 blink::WebInputEvent::Type event_type);
99 // Completes the desired action from the current gesture.
100 void CompleteAction();
102 // Sets the overscroll mode (and triggers callback in the delegate when
103 // appropriate).
104 void SetOverscrollMode(OverscrollMode new_mode);
106 // The current state of overscroll gesture.
107 OverscrollMode overscroll_mode_;
109 // Used to keep track of the scrolling state.
110 // If scrolling starts, and some scroll events are consumed at the beginning
111 // of the scroll (i.e. some content on the web-page was scrolled), then do not
112 // process any of the subsequent scroll events for generating overscroll
113 // gestures.
114 ScrollState scroll_state_;
116 // The amount of overscroll in progress. These values are invalid when
117 // |overscroll_mode_| is set to OVERSCROLL_NONE.
118 float overscroll_delta_x_;
119 float overscroll_delta_y_;
121 // The delegate that receives the overscroll updates. The delegate is not
122 // owned by this controller.
123 OverscrollControllerDelegate* delegate_;
125 DISALLOW_COPY_AND_ASSIGN(OverscrollController);
128 } // namespace content
130 #endif // CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_