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

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

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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 #include "content/browser/renderer_host/overscroll_controller.h" 5 #include "content/browser/renderer_host/overscroll_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 9 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
10 #include "content/public/browser/overscroll_configuration.h" 10 #include "content/public/browser/overscroll_configuration.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 12
13 using WebKit::WebInputEvent; 13 using blink::WebInputEvent;
14 14
15 namespace { 15 namespace {
16 16
17 bool IsScrollEndEffectEnabled() { 17 bool IsScrollEndEffectEnabled() {
18 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 18 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
19 switches::kScrollEndEffect) == "1"; 19 switches::kScrollEndEffect) == "1";
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace content { 24 namespace content {
25 25
26 OverscrollController::OverscrollController() 26 OverscrollController::OverscrollController()
27 : overscroll_mode_(OVERSCROLL_NONE), 27 : overscroll_mode_(OVERSCROLL_NONE),
28 scroll_state_(STATE_UNKNOWN), 28 scroll_state_(STATE_UNKNOWN),
29 overscroll_delta_x_(0.f), 29 overscroll_delta_x_(0.f),
30 overscroll_delta_y_(0.f), 30 overscroll_delta_y_(0.f),
31 delegate_(NULL) { 31 delegate_(NULL) {
32 } 32 }
33 33
34 OverscrollController::~OverscrollController() { 34 OverscrollController::~OverscrollController() {
35 } 35 }
36 36
37 OverscrollController::Disposition OverscrollController::DispatchEvent( 37 OverscrollController::Disposition OverscrollController::DispatchEvent(
38 const WebKit::WebInputEvent& event, 38 const blink::WebInputEvent& event,
39 const ui::LatencyInfo& latency_info) { 39 const ui::LatencyInfo& latency_info) {
40 if (scroll_state_ != STATE_UNKNOWN) { 40 if (scroll_state_ != STATE_UNKNOWN) {
41 switch (event.type) { 41 switch (event.type) {
42 case WebKit::WebInputEvent::GestureScrollEnd: 42 case blink::WebInputEvent::GestureScrollEnd:
43 case WebKit::WebInputEvent::GestureFlingStart: 43 case blink::WebInputEvent::GestureFlingStart:
44 scroll_state_ = STATE_UNKNOWN; 44 scroll_state_ = STATE_UNKNOWN;
45 break; 45 break;
46 46
47 case WebKit::WebInputEvent::MouseWheel: { 47 case blink::WebInputEvent::MouseWheel: {
48 const WebKit::WebMouseWheelEvent& wheel = 48 const blink::WebMouseWheelEvent& wheel =
49 static_cast<const WebKit::WebMouseWheelEvent&>(event); 49 static_cast<const blink::WebMouseWheelEvent&>(event);
50 if (!wheel.hasPreciseScrollingDeltas || 50 if (!wheel.hasPreciseScrollingDeltas ||
51 wheel.phase == WebKit::WebMouseWheelEvent::PhaseEnded || 51 wheel.phase == blink::WebMouseWheelEvent::PhaseEnded ||
52 wheel.phase == WebKit::WebMouseWheelEvent::PhaseCancelled) { 52 wheel.phase == blink::WebMouseWheelEvent::PhaseCancelled) {
53 scroll_state_ = STATE_UNKNOWN; 53 scroll_state_ = STATE_UNKNOWN;
54 } 54 }
55 break; 55 break;
56 } 56 }
57 57
58 default: 58 default:
59 if (WebKit::WebInputEvent::isMouseEventType(event.type) || 59 if (blink::WebInputEvent::isMouseEventType(event.type) ||
60 WebKit::WebInputEvent::isKeyboardEventType(event.type)) { 60 blink::WebInputEvent::isKeyboardEventType(event.type)) {
61 scroll_state_ = STATE_UNKNOWN; 61 scroll_state_ = STATE_UNKNOWN;
62 } 62 }
63 break; 63 break;
64 } 64 }
65 } 65 }
66 66
67 if (DispatchEventCompletesAction(event)) { 67 if (DispatchEventCompletesAction(event)) {
68 CompleteAction(); 68 CompleteAction();
69 69
70 // If the overscroll was caused by touch-scrolling, then the gesture event 70 // If the overscroll was caused by touch-scrolling, then the gesture event
71 // that completes the action needs to be sent to the renderer, because the 71 // that completes the action needs to be sent to the renderer, because the
72 // touch-scrolls maintain state in the renderer side (in the compositor, for 72 // touch-scrolls maintain state in the renderer side (in the compositor, for
73 // example), and the event that completes this action needs to be sent to 73 // example), and the event that completes this action needs to be sent to
74 // the renderer so that those states can be updated/reset appropriately. 74 // the renderer so that those states can be updated/reset appropriately.
75 if (WebKit::WebInputEvent::isGestureEventType(event.type)) { 75 if (blink::WebInputEvent::isGestureEventType(event.type)) {
76 // A gesture-event isn't sent to the GestureEventFilter when overscroll is 76 // A gesture-event isn't sent to the GestureEventFilter when overscroll is
77 // in progress. So dispatch the event through the RenderWidgetHost so that 77 // in progress. So dispatch the event through the RenderWidgetHost so that
78 // it can reach the GestureEventFilter. 78 // it can reach the GestureEventFilter.
79 return SHOULD_FORWARD_TO_GESTURE_FILTER; 79 return SHOULD_FORWARD_TO_GESTURE_FILTER;
80 } 80 }
81 81
82 return SHOULD_FORWARD_TO_RENDERER; 82 return SHOULD_FORWARD_TO_RENDERER;
83 } 83 }
84 84
85 if (overscroll_mode_ != OVERSCROLL_NONE && DispatchEventResetsState(event)) { 85 if (overscroll_mode_ != OVERSCROLL_NONE && DispatchEventResetsState(event)) {
86 SetOverscrollMode(OVERSCROLL_NONE); 86 SetOverscrollMode(OVERSCROLL_NONE);
87 if (WebKit::WebInputEvent::isGestureEventType(event.type)) { 87 if (blink::WebInputEvent::isGestureEventType(event.type)) {
88 // A gesture-event isn't sent to the GestureEventFilter when overscroll is 88 // A gesture-event isn't sent to the GestureEventFilter when overscroll is
89 // in progress. So dispatch the event through the RenderWidgetHost so that 89 // in progress. So dispatch the event through the RenderWidgetHost so that
90 // it can reach the GestureEventFilter. 90 // it can reach the GestureEventFilter.
91 return SHOULD_FORWARD_TO_GESTURE_FILTER; 91 return SHOULD_FORWARD_TO_GESTURE_FILTER;
92 } 92 }
93 93
94 // Let the event be dispatched to the renderer. 94 // Let the event be dispatched to the renderer.
95 return SHOULD_FORWARD_TO_RENDERER; 95 return SHOULD_FORWARD_TO_RENDERER;
96 } 96 }
97 97
98 if (overscroll_mode_ != OVERSCROLL_NONE) { 98 if (overscroll_mode_ != OVERSCROLL_NONE) {
99 // Consume the event only if it updates the overscroll state. 99 // Consume the event only if it updates the overscroll state.
100 if (ProcessEventForOverscroll(event)) 100 if (ProcessEventForOverscroll(event))
101 return CONSUMED; 101 return CONSUMED;
102 } 102 }
103 103
104 return SHOULD_FORWARD_TO_RENDERER; 104 return SHOULD_FORWARD_TO_RENDERER;
105 } 105 }
106 106
107 void OverscrollController::ReceivedEventACK(const WebKit::WebInputEvent& event, 107 void OverscrollController::ReceivedEventACK(const blink::WebInputEvent& event,
108 bool processed) { 108 bool processed) {
109 if (processed) { 109 if (processed) {
110 // If a scroll event is consumed by the page, i.e. some content on the page 110 // If a scroll event is consumed by the page, i.e. some content on the page
111 // has been scrolled, then there is not going to be an overscroll gesture, 111 // has been scrolled, then there is not going to be an overscroll gesture,
112 // until the current scroll ends, and a new scroll gesture starts. 112 // until the current scroll ends, and a new scroll gesture starts.
113 if (scroll_state_ == STATE_UNKNOWN && 113 if (scroll_state_ == STATE_UNKNOWN &&
114 (event.type == WebKit::WebInputEvent::MouseWheel || 114 (event.type == blink::WebInputEvent::MouseWheel ||
115 event.type == WebKit::WebInputEvent::GestureScrollUpdate)) { 115 event.type == blink::WebInputEvent::GestureScrollUpdate)) {
116 scroll_state_ = STATE_CONTENT_SCROLLING; 116 scroll_state_ = STATE_CONTENT_SCROLLING;
117 } 117 }
118 return; 118 return;
119 } 119 }
120 ProcessEventForOverscroll(event); 120 ProcessEventForOverscroll(event);
121 } 121 }
122 122
123 void OverscrollController::DiscardingGestureEvent( 123 void OverscrollController::DiscardingGestureEvent(
124 const WebKit::WebGestureEvent& gesture) { 124 const blink::WebGestureEvent& gesture) {
125 if (scroll_state_ != STATE_UNKNOWN && 125 if (scroll_state_ != STATE_UNKNOWN &&
126 (gesture.type == WebKit::WebInputEvent::GestureScrollEnd || 126 (gesture.type == blink::WebInputEvent::GestureScrollEnd ||
127 gesture.type == WebKit::WebInputEvent::GestureFlingStart)) { 127 gesture.type == blink::WebInputEvent::GestureFlingStart)) {
128 scroll_state_ = STATE_UNKNOWN; 128 scroll_state_ = STATE_UNKNOWN;
129 } 129 }
130 } 130 }
131 131
132 void OverscrollController::Reset() { 132 void OverscrollController::Reset() {
133 overscroll_mode_ = OVERSCROLL_NONE; 133 overscroll_mode_ = OVERSCROLL_NONE;
134 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; 134 overscroll_delta_x_ = overscroll_delta_y_ = 0.f;
135 scroll_state_ = STATE_UNKNOWN; 135 scroll_state_ = STATE_UNKNOWN;
136 } 136 }
137 137
138 void OverscrollController::Cancel() { 138 void OverscrollController::Cancel() {
139 SetOverscrollMode(OVERSCROLL_NONE); 139 SetOverscrollMode(OVERSCROLL_NONE);
140 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; 140 overscroll_delta_x_ = overscroll_delta_y_ = 0.f;
141 scroll_state_ = STATE_UNKNOWN; 141 scroll_state_ = STATE_UNKNOWN;
142 } 142 }
143 143
144 bool OverscrollController::DispatchEventCompletesAction ( 144 bool OverscrollController::DispatchEventCompletesAction (
145 const WebKit::WebInputEvent& event) const { 145 const blink::WebInputEvent& event) const {
146 if (overscroll_mode_ == OVERSCROLL_NONE) 146 if (overscroll_mode_ == OVERSCROLL_NONE)
147 return false; 147 return false;
148 148
149 // Complete the overscroll gesture if there was a mouse move or a scroll-end 149 // Complete the overscroll gesture if there was a mouse move or a scroll-end
150 // after the threshold. 150 // after the threshold.
151 if (event.type != WebKit::WebInputEvent::MouseMove && 151 if (event.type != blink::WebInputEvent::MouseMove &&
152 event.type != WebKit::WebInputEvent::GestureScrollEnd && 152 event.type != blink::WebInputEvent::GestureScrollEnd &&
153 event.type != WebKit::WebInputEvent::GestureFlingStart) 153 event.type != blink::WebInputEvent::GestureFlingStart)
154 return false; 154 return false;
155 155
156 if (!delegate_) 156 if (!delegate_)
157 return false; 157 return false;
158 158
159 gfx::Rect bounds = delegate_->GetVisibleBounds(); 159 gfx::Rect bounds = delegate_->GetVisibleBounds();
160 if (bounds.IsEmpty()) 160 if (bounds.IsEmpty())
161 return false; 161 return false;
162 162
163 if (event.type == WebKit::WebInputEvent::GestureFlingStart) { 163 if (event.type == blink::WebInputEvent::GestureFlingStart) {
164 // Check to see if the fling is in the same direction of the overscroll. 164 // Check to see if the fling is in the same direction of the overscroll.
165 const WebKit::WebGestureEvent gesture = 165 const blink::WebGestureEvent gesture =
166 static_cast<const WebKit::WebGestureEvent&>(event); 166 static_cast<const blink::WebGestureEvent&>(event);
167 switch (overscroll_mode_) { 167 switch (overscroll_mode_) {
168 case OVERSCROLL_EAST: 168 case OVERSCROLL_EAST:
169 if (gesture.data.flingStart.velocityX < 0) 169 if (gesture.data.flingStart.velocityX < 0)
170 return false; 170 return false;
171 break; 171 break;
172 case OVERSCROLL_WEST: 172 case OVERSCROLL_WEST:
173 if (gesture.data.flingStart.velocityX > 0) 173 if (gesture.data.flingStart.velocityX > 0)
174 return false; 174 return false;
175 break; 175 break;
176 case OVERSCROLL_NORTH: 176 case OVERSCROLL_NORTH:
(...skipping 17 matching lines...) Expand all
194 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE); 194 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE);
195 } else { 195 } else {
196 ratio = fabs(overscroll_delta_y_) / bounds.height(); 196 ratio = fabs(overscroll_delta_y_) / bounds.height();
197 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE); 197 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE);
198 } 198 }
199 199
200 return ratio >= threshold; 200 return ratio >= threshold;
201 } 201 }
202 202
203 bool OverscrollController::DispatchEventResetsState( 203 bool OverscrollController::DispatchEventResetsState(
204 const WebKit::WebInputEvent& event) const { 204 const blink::WebInputEvent& event) const {
205 switch (event.type) { 205 switch (event.type) {
206 case WebKit::WebInputEvent::MouseWheel: { 206 case blink::WebInputEvent::MouseWheel: {
207 // Only wheel events with precise deltas (i.e. from trackpad) contribute 207 // Only wheel events with precise deltas (i.e. from trackpad) contribute
208 // to the overscroll gesture. 208 // to the overscroll gesture.
209 const WebKit::WebMouseWheelEvent& wheel = 209 const blink::WebMouseWheelEvent& wheel =
210 static_cast<const WebKit::WebMouseWheelEvent&>(event); 210 static_cast<const blink::WebMouseWheelEvent&>(event);
211 return !wheel.hasPreciseScrollingDeltas; 211 return !wheel.hasPreciseScrollingDeltas;
212 } 212 }
213 213
214 case WebKit::WebInputEvent::GestureScrollUpdate: 214 case blink::WebInputEvent::GestureScrollUpdate:
215 case WebKit::WebInputEvent::GestureFlingCancel: 215 case blink::WebInputEvent::GestureFlingCancel:
216 return false; 216 return false;
217 217
218 default: 218 default:
219 // Touch events can arrive during an overscroll gesture initiated by 219 // Touch events can arrive during an overscroll gesture initiated by
220 // touch-scrolling. These events should not reset the overscroll state. 220 // touch-scrolling. These events should not reset the overscroll state.
221 return !WebKit::WebInputEvent::isTouchEventType(event.type); 221 return !blink::WebInputEvent::isTouchEventType(event.type);
222 } 222 }
223 } 223 }
224 224
225 bool OverscrollController::ProcessEventForOverscroll( 225 bool OverscrollController::ProcessEventForOverscroll(
226 const WebKit::WebInputEvent& event) { 226 const blink::WebInputEvent& event) {
227 bool event_processed = false; 227 bool event_processed = false;
228 switch (event.type) { 228 switch (event.type) {
229 case WebKit::WebInputEvent::MouseWheel: { 229 case blink::WebInputEvent::MouseWheel: {
230 const WebKit::WebMouseWheelEvent& wheel = 230 const blink::WebMouseWheelEvent& wheel =
231 static_cast<const WebKit::WebMouseWheelEvent&>(event); 231 static_cast<const blink::WebMouseWheelEvent&>(event);
232 if (!wheel.hasPreciseScrollingDeltas) 232 if (!wheel.hasPreciseScrollingDeltas)
233 break; 233 break;
234 234
235 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, 235 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX,
236 wheel.deltaY * wheel.accelerationRatioY, 236 wheel.deltaY * wheel.accelerationRatioY,
237 wheel.type); 237 wheel.type);
238 event_processed = true; 238 event_processed = true;
239 break; 239 break;
240 } 240 }
241 case WebKit::WebInputEvent::GestureScrollUpdate: { 241 case blink::WebInputEvent::GestureScrollUpdate: {
242 const WebKit::WebGestureEvent& gesture = 242 const blink::WebGestureEvent& gesture =
243 static_cast<const WebKit::WebGestureEvent&>(event); 243 static_cast<const blink::WebGestureEvent&>(event);
244 ProcessOverscroll(gesture.data.scrollUpdate.deltaX, 244 ProcessOverscroll(gesture.data.scrollUpdate.deltaX,
245 gesture.data.scrollUpdate.deltaY, 245 gesture.data.scrollUpdate.deltaY,
246 gesture.type); 246 gesture.type);
247 event_processed = true; 247 event_processed = true;
248 break; 248 break;
249 } 249 }
250 case WebKit::WebInputEvent::GestureFlingStart: { 250 case blink::WebInputEvent::GestureFlingStart: {
251 const float kFlingVelocityThreshold = 1100.f; 251 const float kFlingVelocityThreshold = 1100.f;
252 const WebKit::WebGestureEvent& gesture = 252 const blink::WebGestureEvent& gesture =
253 static_cast<const WebKit::WebGestureEvent&>(event); 253 static_cast<const blink::WebGestureEvent&>(event);
254 float velocity_x = gesture.data.flingStart.velocityX; 254 float velocity_x = gesture.data.flingStart.velocityX;
255 float velocity_y = gesture.data.flingStart.velocityY; 255 float velocity_y = gesture.data.flingStart.velocityY;
256 if (fabs(velocity_x) > kFlingVelocityThreshold) { 256 if (fabs(velocity_x) > kFlingVelocityThreshold) {
257 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || 257 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) ||
258 (overscroll_mode_ == OVERSCROLL_EAST && velocity_x > 0)) { 258 (overscroll_mode_ == OVERSCROLL_EAST && velocity_x > 0)) {
259 CompleteAction(); 259 CompleteAction();
260 event_processed = true; 260 event_processed = true;
261 break; 261 break;
262 } 262 }
263 } else if (fabs(velocity_y) > kFlingVelocityThreshold) { 263 } else if (fabs(velocity_y) > kFlingVelocityThreshold) {
264 if ((overscroll_mode_ == OVERSCROLL_NORTH && velocity_y < 0) || 264 if ((overscroll_mode_ == OVERSCROLL_NORTH && velocity_y < 0) ||
265 (overscroll_mode_ == OVERSCROLL_SOUTH && velocity_y > 0)) { 265 (overscroll_mode_ == OVERSCROLL_SOUTH && velocity_y > 0)) {
266 CompleteAction(); 266 CompleteAction();
267 event_processed = true; 267 event_processed = true;
268 break; 268 break;
269 } 269 }
270 } 270 }
271 271
272 // Reset overscroll state if fling didn't complete the overscroll gesture. 272 // Reset overscroll state if fling didn't complete the overscroll gesture.
273 SetOverscrollMode(OVERSCROLL_NONE); 273 SetOverscrollMode(OVERSCROLL_NONE);
274 break; 274 break;
275 } 275 }
276 276
277 default: 277 default:
278 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) || 278 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) ||
279 WebKit::WebInputEvent::isTouchEventType(event.type)) 279 blink::WebInputEvent::isTouchEventType(event.type))
280 << "Received unexpected event: " << event.type; 280 << "Received unexpected event: " << event.type;
281 } 281 }
282 return event_processed; 282 return event_processed;
283 } 283 }
284 284
285 void OverscrollController::ProcessOverscroll(float delta_x, 285 void OverscrollController::ProcessOverscroll(float delta_x,
286 float delta_y, 286 float delta_y,
287 WebKit::WebInputEvent::Type type) { 287 blink::WebInputEvent::Type type) {
288 if (scroll_state_ != STATE_CONTENT_SCROLLING) 288 if (scroll_state_ != STATE_CONTENT_SCROLLING)
289 overscroll_delta_x_ += delta_x; 289 overscroll_delta_x_ += delta_x;
290 overscroll_delta_y_ += delta_y; 290 overscroll_delta_y_ += delta_y;
291 291
292 float horiz_threshold = GetOverscrollConfig( 292 float horiz_threshold = GetOverscrollConfig(
293 WebInputEvent::isGestureEventType(type) ? 293 WebInputEvent::isGestureEventType(type) ?
294 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN : 294 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN :
295 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD); 295 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD);
296 float vert_threshold = GetOverscrollConfig( 296 float vert_threshold = GetOverscrollConfig(
297 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); 297 OVERSCROLL_CONFIG_VERT_THRESHOLD_START);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 overscroll_mode_ = mode; 369 overscroll_mode_ = mode;
370 if (overscroll_mode_ == OVERSCROLL_NONE) 370 if (overscroll_mode_ == OVERSCROLL_NONE)
371 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; 371 overscroll_delta_x_ = overscroll_delta_y_ = 0.f;
372 else 372 else
373 scroll_state_ = STATE_OVERSCROLLING; 373 scroll_state_ = STATE_OVERSCROLLING;
374 if (delegate_) 374 if (delegate_)
375 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); 375 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_);
376 } 376 }
377 377
378 } // namespace content 378 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698