Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / overscroll_controller.h
bloba6287efd3bd75571c49dba54c50076783e2d8488
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 struct 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,
29 OVERSCROLL_COUNT
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 {
37 public:
38 OverscrollController();
39 virtual ~OverscrollController();
41 // This must be called when dispatching any event from the
42 // RenderWidgetHostView so that the state of the overscroll gesture can be
43 // updated properly. Returns true if the event was handled, in which case
44 // further processing should cease.
45 bool WillHandleEvent(const blink::WebInputEvent& event);
47 // This must be called when the ACK for any event comes in. This updates the
48 // overscroll gesture status as appropriate.
49 void ReceivedEventACK(const blink::WebInputEvent& event, bool processed);
51 // This must be called when a gesture event is filtered out and not sent to
52 // the renderer.
53 void DiscardingGestureEvent(const blink::WebGestureEvent& event);
55 OverscrollMode overscroll_mode() const { return overscroll_mode_; }
57 void set_delegate(OverscrollControllerDelegate* delegate) {
58 delegate_ = delegate;
61 // Resets internal states.
62 void Reset();
64 // Cancels any in-progress overscroll (and calls OnOverscrollModeChange on the
65 // delegate if necessary), and resets internal states.
66 void Cancel();
68 private:
69 friend class RenderWidgetHostViewAuraOverscrollTest;
71 // Different scrolling states.
72 enum ScrollState {
73 STATE_UNKNOWN,
74 STATE_PENDING,
75 STATE_CONTENT_SCROLLING,
76 STATE_OVERSCROLLING,
79 // Returns true if the event indicates that the in-progress overscroll gesture
80 // can now be completed.
81 bool DispatchEventCompletesAction(
82 const blink::WebInputEvent& event) const;
84 // Returns true to indicate that dispatching the event should reset the
85 // overscroll gesture status.
86 bool DispatchEventResetsState(const blink::WebInputEvent& event) const;
88 // Processes an event to update the internal state for overscroll. Returns
89 // true if the state is updated, false otherwise.
90 bool ProcessEventForOverscroll(const blink::WebInputEvent& event);
92 // Processes horizontal overscroll. This can update both the overscroll mode
93 // and the over scroll amount (i.e. |overscroll_mode_|, |overscroll_delta_x_|
94 // and |overscroll_delta_y_|). Returns true if overscroll was handled by the
95 // delegate.
96 bool ProcessOverscroll(float delta_x,
97 float delta_y,
98 blink::WebInputEvent::Type event_type);
100 // Completes the desired action from the current gesture.
101 void CompleteAction();
103 // Sets the overscroll mode (and triggers callback in the delegate when
104 // appropriate).
105 void SetOverscrollMode(OverscrollMode new_mode);
107 // The current state of overscroll gesture.
108 OverscrollMode overscroll_mode_;
110 // Used to keep track of the scrolling state.
111 // If scrolling starts, and some scroll events are consumed at the beginning
112 // of the scroll (i.e. some content on the web-page was scrolled), then do not
113 // process any of the subsequent scroll events for generating overscroll
114 // gestures.
115 ScrollState scroll_state_;
117 // The amount of overscroll in progress. These values are invalid when
118 // |overscroll_mode_| is set to OVERSCROLL_NONE.
119 float overscroll_delta_x_;
120 float overscroll_delta_y_;
122 // The delegate that receives the overscroll updates. The delegate is not
123 // owned by this controller.
124 OverscrollControllerDelegate* delegate_;
126 DISALLOW_COPY_AND_ASSIGN(OverscrollController);
129 } // namespace content
131 #endif // CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_