Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/browser/renderer_host/overscroll_controller.h

Issue 2815823003: Notify OverscrollController of gesture events in plugins. (Closed)
Patch Set: Add test to verify OverscrollController sees consumed scrolls. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "content/common/content_export.h"
10 #include "third_party/WebKit/public/platform/WebGestureEvent.h" 11 #include "third_party/WebKit/public/platform/WebGestureEvent.h"
11 #include "third_party/WebKit/public/platform/WebInputEvent.h" 12 #include "third_party/WebKit/public/platform/WebInputEvent.h"
12 13
13 namespace content { 14 namespace content {
14 15
15 class RenderWidgetHostViewAuraOverscrollTest; 16 class RenderWidgetHostViewAuraOverscrollTest;
16 class OverscrollControllerDelegate; 17 class OverscrollControllerDelegate;
17 18
18 // Indicates the direction that the scroll is heading in relative to the screen, 19 // Indicates the direction that the scroll is heading in relative to the screen,
19 // with the top being NORTH. 20 // with the top being NORTH.
(...skipping 11 matching lines...) Expand all
31 TOUCHPAD, 32 TOUCHPAD,
32 TOUCHSCREEN, 33 TOUCHSCREEN,
33 }; 34 };
34 35
35 // When a page is scrolled beyond the scrollable region, it will trigger an 36 // When a page is scrolled beyond the scrollable region, it will trigger an
36 // overscroll gesture. This controller receives the events that are dispatched 37 // overscroll gesture. This controller receives the events that are dispatched
37 // to the renderer, and the ACKs of events, and updates the overscroll gesture 38 // to the renderer, and the ACKs of events, and updates the overscroll gesture
38 // status accordingly. 39 // status accordingly.
39 class OverscrollController { 40 class OverscrollController {
40 public: 41 public:
41 OverscrollController(); 42 // Exported for testing.
42 virtual ~OverscrollController(); 43 // TODO(mcnee): Tests needing this are BrowserPlugin specific
44 // (crbug.com/533069).
45 CONTENT_EXPORT OverscrollController();
46 CONTENT_EXPORT virtual ~OverscrollController();
43 47
44 // This must be called when dispatching any event from the 48 // This must be called when dispatching any event from the
45 // RenderWidgetHostView so that the state of the overscroll gesture can be 49 // RenderWidgetHostView so that the state of the overscroll gesture can be
46 // updated properly. Returns true if the event was handled, in which case 50 // updated properly. Returns true if the event was handled, in which case
47 // further processing should cease. 51 // further processing should cease.
48 bool WillHandleEvent(const blink::WebInputEvent& event); 52 bool WillHandleEvent(const blink::WebInputEvent& event);
49 53
50 // This must be called when the ACK for any event comes in. This updates the 54 // This must be called when the ACK for any event comes in. This updates the
51 // overscroll gesture status as appropriate. 55 // overscroll gesture status as appropriate.
52 void ReceivedEventACK(const blink::WebInputEvent& event, bool processed); 56 // Virtual and exported for testing.
57 // TODO(mcnee): Tests needing this are BrowserPlugin specific
58 // (crbug.com/533069).
59 CONTENT_EXPORT virtual void ReceivedEventACK(
60 const blink::WebInputEvent& event,
61 bool processed);
53 62
54 // This must be called when a gesture event is filtered out and not sent to 63 // This must be called when a gesture event is filtered out and not sent to
55 // the renderer. 64 // the renderer.
56 void DiscardingGestureEvent(const blink::WebGestureEvent& event); 65 void DiscardingGestureEvent(const blink::WebGestureEvent& event);
57 66
58 OverscrollMode overscroll_mode() const { return overscroll_mode_; } 67 OverscrollMode overscroll_mode() const { return overscroll_mode_; }
59 68
60 void set_delegate(OverscrollControllerDelegate* delegate) { 69 void set_delegate(OverscrollControllerDelegate* delegate) {
61 delegate_ = delegate; 70 delegate_ = delegate;
62 } 71 }
63 72
64 // Resets internal states. 73 // Resets internal states.
65 void Reset(); 74 void Reset();
66 75
67 // Cancels any in-progress overscroll (and calls OnOverscrollModeChange on the 76 // Cancels any in-progress overscroll (and calls OnOverscrollModeChange on the
68 // delegate if necessary), and resets internal states. 77 // delegate if necessary), and resets internal states.
69 void Cancel(); 78 void Cancel();
70 79
71 private: 80 protected:
72 friend class RenderWidgetHostViewAuraOverscrollTest;
73
74 // Different scrolling states. 81 // Different scrolling states.
82 // Protected for testing.
83 // TODO(mcnee): Tests needing this are BrowserPlugin specific
84 // (crbug.com/533069).
75 enum ScrollState { 85 enum ScrollState {
76 STATE_UNKNOWN, 86 STATE_UNKNOWN,
77 STATE_PENDING, 87 STATE_PENDING,
78 STATE_CONTENT_SCROLLING, 88 STATE_CONTENT_SCROLLING,
79 STATE_OVERSCROLLING, 89 STATE_OVERSCROLLING,
80 }; 90 };
81 91
92 // Used to keep track of the scrolling state.
93 // If scrolling starts, and some scroll events are consumed at the beginning
94 // of the scroll (i.e. some content on the web-page was scrolled), then do not
95 // process any of the subsequent scroll events for generating overscroll
96 // gestures.
97 // Protected for testing.
98 // TODO(mcnee): Tests needing this are BrowserPlugin specific
99 // (crbug.com/533069).
100 ScrollState scroll_state_;
101
102 private:
103 friend class RenderWidgetHostViewAuraOverscrollTest;
104
82 // Returns true if the event indicates that the in-progress overscroll gesture 105 // Returns true if the event indicates that the in-progress overscroll gesture
83 // can now be completed. 106 // can now be completed.
84 bool DispatchEventCompletesAction( 107 bool DispatchEventCompletesAction(
85 const blink::WebInputEvent& event) const; 108 const blink::WebInputEvent& event) const;
86 109
87 // Returns true to indicate that dispatching the event should reset the 110 // Returns true to indicate that dispatching the event should reset the
88 // overscroll gesture status. 111 // overscroll gesture status.
89 bool DispatchEventResetsState(const blink::WebInputEvent& event) const; 112 bool DispatchEventResetsState(const blink::WebInputEvent& event) const;
90 113
91 // Processes an event to update the internal state for overscroll. Returns 114 // Processes an event to update the internal state for overscroll. Returns
(...skipping 14 matching lines...) Expand all
106 // equal to OVERSCROLL_NONE), |source| will be set to the device that 129 // equal to OVERSCROLL_NONE), |source| will be set to the device that
107 // triggered the overscroll gesture. 130 // triggered the overscroll gesture.
108 void SetOverscrollMode(OverscrollMode new_mode, OverscrollSource source); 131 void SetOverscrollMode(OverscrollMode new_mode, OverscrollSource source);
109 132
110 // Whether this event should be processed or not handled by the controller. 133 // Whether this event should be processed or not handled by the controller.
111 bool ShouldProcessEvent(const blink::WebInputEvent& event); 134 bool ShouldProcessEvent(const blink::WebInputEvent& event);
112 135
113 // The current state of overscroll gesture. 136 // The current state of overscroll gesture.
114 OverscrollMode overscroll_mode_; 137 OverscrollMode overscroll_mode_;
115 138
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
120 // gestures.
121 ScrollState scroll_state_;
122
123 // The amount of overscroll in progress. These values are invalid when 139 // The amount of overscroll in progress. These values are invalid when
124 // |overscroll_mode_| is set to OVERSCROLL_NONE. 140 // |overscroll_mode_| is set to OVERSCROLL_NONE.
125 float overscroll_delta_x_; 141 float overscroll_delta_x_;
126 float overscroll_delta_y_; 142 float overscroll_delta_y_;
127 143
128 // The delegate that receives the overscroll updates. The delegate is not 144 // The delegate that receives the overscroll updates. The delegate is not
129 // owned by this controller. 145 // owned by this controller.
130 OverscrollControllerDelegate* delegate_; 146 OverscrollControllerDelegate* delegate_;
131 147
132 DISALLOW_COPY_AND_ASSIGN(OverscrollController); 148 DISALLOW_COPY_AND_ASSIGN(OverscrollController);
133 }; 149 };
134 150
135 } // namespace content 151 } // namespace content
136 152
137 #endif // CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_ 153 #endif // CONTENT_BROWSER_RENDERER_HOST_OVERSCROLL_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698