Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/common/input/input_event_utils.h" | |
| 10 #include "content/public/browser/overscroll_configuration.h" | 11 #include "content/public/browser/overscroll_configuration.h" |
| 11 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 12 | 13 |
| 13 using blink::WebInputEvent; | 14 using blink::WebInputEvent; |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 bool IsScrollEndEffectEnabled() { | 18 bool IsScrollEndEffectEnabled() { |
| 18 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 19 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 19 switches::kScrollEndEffect) == "1"; | 20 switches::kScrollEndEffect) == "1"; |
| 20 } | 21 } |
| 21 | 22 |
| 23 bool IsGestureEventFromTouchscreen(const blink::WebInputEvent& event) { | |
|
tdresser
2016/02/18 14:35:21
Maybe DCHECK that this is a gesture event?
dtapuska
2016/02/18 21:03:44
Done.
| |
| 24 const blink::WebGestureEvent& gesture = | |
| 25 static_cast<const blink::WebGestureEvent&>(event); | |
| 26 return gesture.sourceDevice == blink::WebGestureDeviceTouchscreen; | |
| 27 } | |
| 28 | |
| 22 } // namespace | 29 } // namespace |
| 23 | 30 |
| 24 namespace content { | 31 namespace content { |
| 25 | 32 |
| 26 OverscrollController::OverscrollController() | 33 OverscrollController::OverscrollController() |
| 27 : overscroll_mode_(OVERSCROLL_NONE), | 34 : overscroll_mode_(OVERSCROLL_NONE), |
| 28 scroll_state_(STATE_UNKNOWN), | 35 scroll_state_(STATE_UNKNOWN), |
| 29 overscroll_delta_x_(0.f), | 36 overscroll_delta_x_(0.f), |
| 30 overscroll_delta_y_(0.f), | 37 overscroll_delta_y_(0.f), |
| 31 delegate_(NULL) { | 38 delegate_(NULL), |
| 32 } | 39 use_gesutre_wheel_scrolling_(UseGestureBasedWheelScrolling()) {} |
|
tdresser
2016/02/18 14:35:21
use_gesutre -> use_gesture
dtapuska
2016/02/18 21:03:44
Done.
| |
| 33 | 40 |
| 34 OverscrollController::~OverscrollController() { | 41 OverscrollController::~OverscrollController() { |
| 35 } | 42 } |
| 36 | 43 |
| 37 bool OverscrollController::WillHandleEvent(const blink::WebInputEvent& event) { | 44 bool OverscrollController::WillHandleEvent(const blink::WebInputEvent& event) { |
| 38 bool reset_scroll_state = false; | 45 bool reset_scroll_state = false; |
| 39 if (scroll_state_ != STATE_UNKNOWN || | 46 if (scroll_state_ != STATE_UNKNOWN || |
| 40 overscroll_delta_x_ || overscroll_delta_y_) { | 47 overscroll_delta_x_ || overscroll_delta_y_) { |
| 41 switch (event.type) { | 48 switch (event.type) { |
| 42 case blink::WebInputEvent::GestureScrollEnd: | 49 case blink::WebInputEvent::GestureScrollEnd: |
| 50 // Gesture scroll end is sent based on a timeout avoid | |
|
tdresser
2016/02/18 14:35:21
timeout avoid -> timeout to avoid
dtapuska
2016/02/18 21:03:44
Done.
| |
| 51 // resetting on events from the touchpad. | |
| 52 reset_scroll_state = IsGestureEventFromTouchscreen(event); | |
| 53 break; | |
| 54 | |
| 43 case blink::WebInputEvent::GestureFlingStart: | 55 case blink::WebInputEvent::GestureFlingStart: |
| 44 reset_scroll_state = true; | 56 reset_scroll_state = true; |
| 45 break; | 57 break; |
| 46 | 58 |
| 47 case blink::WebInputEvent::MouseWheel: { | 59 case blink::WebInputEvent::MouseWheel: { |
| 48 const blink::WebMouseWheelEvent& wheel = | 60 if (!use_gesutre_wheel_scrolling_) { |
|
tdresser
2016/02/18 14:35:21
This might be clearer if you invert the condition.
dtapuska
2016/02/18 21:03:44
Done.
| |
| 49 static_cast<const blink::WebMouseWheelEvent&>(event); | 61 const blink::WebMouseWheelEvent& wheel = |
| 50 if (!wheel.hasPreciseScrollingDeltas || | 62 static_cast<const blink::WebMouseWheelEvent&>(event); |
| 51 wheel.phase == blink::WebMouseWheelEvent::PhaseEnded || | 63 if (!wheel.hasPreciseScrollingDeltas || |
| 52 wheel.phase == blink::WebMouseWheelEvent::PhaseCancelled) { | 64 wheel.phase == blink::WebMouseWheelEvent::PhaseEnded || |
| 53 reset_scroll_state = true; | 65 wheel.phase == blink::WebMouseWheelEvent::PhaseCancelled) { |
| 66 reset_scroll_state = true; | |
| 67 } | |
| 54 } | 68 } |
| 55 break; | 69 break; |
| 56 } | 70 } |
| 57 | 71 |
| 58 default: | 72 default: |
| 59 if (blink::WebInputEvent::isMouseEventType(event.type) || | 73 if (blink::WebInputEvent::isMouseEventType(event.type) || |
| 60 blink::WebInputEvent::isKeyboardEventType(event.type)) { | 74 blink::WebInputEvent::isKeyboardEventType(event.type)) { |
| 61 reset_scroll_state = true; | 75 reset_scroll_state = true; |
| 62 } | 76 } |
| 63 break; | 77 break; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 88 } else if (reset_scroll_state) { | 102 } else if (reset_scroll_state) { |
| 89 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 103 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
| 90 } | 104 } |
| 91 | 105 |
| 92 | 106 |
| 93 return false; | 107 return false; |
| 94 } | 108 } |
| 95 | 109 |
| 96 void OverscrollController::ReceivedEventACK(const blink::WebInputEvent& event, | 110 void OverscrollController::ReceivedEventACK(const blink::WebInputEvent& event, |
| 97 bool processed) { | 111 bool processed) { |
| 112 if (use_gesutre_wheel_scrolling_ && | |
| 113 event.type == blink::WebInputEvent::MouseWheel) | |
| 114 return; | |
| 115 | |
| 98 if (processed) { | 116 if (processed) { |
| 99 // If a scroll event is consumed by the page, i.e. some content on the page | 117 // If a scroll event is consumed by the page, i.e. some content on the page |
| 100 // has been scrolled, then there is not going to be an overscroll gesture, | 118 // has been scrolled, then there is not going to be an overscroll gesture, |
| 101 // until the current scroll ends, and a new scroll gesture starts. | 119 // until the current scroll ends, and a new scroll gesture starts. |
| 102 if (scroll_state_ == STATE_UNKNOWN && | 120 if (scroll_state_ == STATE_UNKNOWN && |
| 103 (event.type == blink::WebInputEvent::MouseWheel || | 121 (event.type == blink::WebInputEvent::MouseWheel || |
| 104 event.type == blink::WebInputEvent::GestureScrollUpdate)) { | 122 event.type == blink::WebInputEvent::GestureScrollUpdate)) { |
| 105 scroll_state_ = STATE_CONTENT_SCROLLING; | 123 scroll_state_ = STATE_CONTENT_SCROLLING; |
| 106 } | 124 } |
| 107 return; | 125 return; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 135 if (overscroll_mode_ == OVERSCROLL_NONE) | 153 if (overscroll_mode_ == OVERSCROLL_NONE) |
| 136 return false; | 154 return false; |
| 137 | 155 |
| 138 // Complete the overscroll gesture if there was a mouse move or a scroll-end | 156 // Complete the overscroll gesture if there was a mouse move or a scroll-end |
| 139 // after the threshold. | 157 // after the threshold. |
| 140 if (event.type != blink::WebInputEvent::MouseMove && | 158 if (event.type != blink::WebInputEvent::MouseMove && |
| 141 event.type != blink::WebInputEvent::GestureScrollEnd && | 159 event.type != blink::WebInputEvent::GestureScrollEnd && |
| 142 event.type != blink::WebInputEvent::GestureFlingStart) | 160 event.type != blink::WebInputEvent::GestureFlingStart) |
| 143 return false; | 161 return false; |
| 144 | 162 |
| 163 // Gesture scroll end is sent based on a timeout avoid | |
| 164 // resetting on events from the touchpad. | |
|
tdresser
2016/02/18 14:35:21
resetting what?
dtapuska
2016/02/18 14:41:17
Resetting the overscroll to OVERSCROLL_NONE state.
| |
| 165 if (event.type == blink::WebInputEvent::GestureScrollEnd && | |
| 166 !IsGestureEventFromTouchscreen(event)) | |
| 167 return false; | |
| 168 | |
| 145 if (!delegate_) | 169 if (!delegate_) |
| 146 return false; | 170 return false; |
| 147 | 171 |
| 148 gfx::Rect bounds = delegate_->GetVisibleBounds(); | 172 gfx::Rect bounds = delegate_->GetVisibleBounds(); |
| 149 if (bounds.IsEmpty()) | 173 if (bounds.IsEmpty()) |
| 150 return false; | 174 return false; |
| 151 | 175 |
| 152 if (event.type == blink::WebInputEvent::GestureFlingStart) { | 176 if (event.type == blink::WebInputEvent::GestureFlingStart) { |
| 153 // Check to see if the fling is in the same direction of the overscroll. | 177 // Check to see if the fling is in the same direction of the overscroll. |
| 154 const blink::WebGestureEvent gesture = | 178 const blink::WebGestureEvent gesture = |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 185 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE); | 209 threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE); |
| 186 } | 210 } |
| 187 | 211 |
| 188 return ratio >= threshold; | 212 return ratio >= threshold; |
| 189 } | 213 } |
| 190 | 214 |
| 191 bool OverscrollController::DispatchEventResetsState( | 215 bool OverscrollController::DispatchEventResetsState( |
| 192 const blink::WebInputEvent& event) const { | 216 const blink::WebInputEvent& event) const { |
| 193 switch (event.type) { | 217 switch (event.type) { |
| 194 case blink::WebInputEvent::MouseWheel: { | 218 case blink::WebInputEvent::MouseWheel: { |
| 195 // Only wheel events with precise deltas (i.e. from trackpad) contribute | 219 if (use_gesutre_wheel_scrolling_) { |
| 196 // to the overscroll gesture. | 220 return false; |
| 197 const blink::WebMouseWheelEvent& wheel = | 221 } else { |
|
tdresser
2016/02/18 14:35:20
Don't need the "else", as there's a return above.
dtapuska
2016/02/18 21:03:44
Done.
| |
| 198 static_cast<const blink::WebMouseWheelEvent&>(event); | 222 // Only wheel events with precise deltas (i.e. from trackpad) contribute |
| 199 return !wheel.hasPreciseScrollingDeltas; | 223 // to the overscroll gesture. |
| 224 const blink::WebMouseWheelEvent& wheel = | |
| 225 static_cast<const blink::WebMouseWheelEvent&>(event); | |
| 226 return !wheel.hasPreciseScrollingDeltas; | |
| 227 } | |
| 200 } | 228 } |
| 201 | 229 |
| 230 // Gesture scroll begin/ends come based on a timeout avoid | |
| 231 // resetting on events from the touchpad. | |
| 232 case blink::WebInputEvent::GestureScrollBegin: | |
| 233 case blink::WebInputEvent::GestureScrollEnd: | |
| 234 return IsGestureEventFromTouchscreen(event); | |
| 235 | |
| 202 case blink::WebInputEvent::GestureScrollUpdate: | 236 case blink::WebInputEvent::GestureScrollUpdate: |
| 203 case blink::WebInputEvent::GestureFlingCancel: | 237 case blink::WebInputEvent::GestureFlingCancel: |
| 204 return false; | 238 return false; |
| 205 | 239 |
| 206 default: | 240 default: |
| 207 // Touch events can arrive during an overscroll gesture initiated by | 241 // Touch events can arrive during an overscroll gesture initiated by |
| 208 // touch-scrolling. These events should not reset the overscroll state. | 242 // touch-scrolling. These events should not reset the overscroll state. |
| 209 return !blink::WebInputEvent::isTouchEventType(event.type); | 243 return !blink::WebInputEvent::isTouchEventType(event.type); |
| 210 } | 244 } |
| 211 } | 245 } |
| 212 | 246 |
| 213 bool OverscrollController::ProcessEventForOverscroll( | 247 bool OverscrollController::ProcessEventForOverscroll( |
| 214 const blink::WebInputEvent& event) { | 248 const blink::WebInputEvent& event) { |
| 215 bool event_processed = false; | 249 bool event_processed = false; |
| 216 switch (event.type) { | 250 switch (event.type) { |
| 217 case blink::WebInputEvent::MouseWheel: { | 251 case blink::WebInputEvent::MouseWheel: { |
| 218 const blink::WebMouseWheelEvent& wheel = | 252 const blink::WebMouseWheelEvent& wheel = |
| 219 static_cast<const blink::WebMouseWheelEvent&>(event); | 253 static_cast<const blink::WebMouseWheelEvent&>(event); |
| 220 if (!wheel.hasPreciseScrollingDeltas) | 254 if (use_gesutre_wheel_scrolling_ || !wheel.hasPreciseScrollingDeltas) |
| 221 break; | 255 break; |
| 222 event_processed = | 256 event_processed = |
| 223 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, | 257 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, |
| 224 wheel.deltaY * wheel.accelerationRatioY, | 258 wheel.deltaY * wheel.accelerationRatioY, true); |
| 225 wheel.type); | |
| 226 break; | 259 break; |
| 227 } | 260 } |
| 228 case blink::WebInputEvent::GestureScrollUpdate: { | 261 case blink::WebInputEvent::GestureScrollUpdate: { |
| 229 const blink::WebGestureEvent& gesture = | 262 const blink::WebGestureEvent& gesture = |
| 230 static_cast<const blink::WebGestureEvent&>(event); | 263 static_cast<const blink::WebGestureEvent&>(event); |
| 231 event_processed = ProcessOverscroll(gesture.data.scrollUpdate.deltaX, | 264 event_processed = ProcessOverscroll( |
| 232 gesture.data.scrollUpdate.deltaY, | 265 gesture.data.scrollUpdate.deltaX, gesture.data.scrollUpdate.deltaY, |
| 233 gesture.type); | 266 gesture.sourceDevice == blink::WebGestureDeviceTouchpad); |
| 234 break; | 267 break; |
| 235 } | 268 } |
| 236 case blink::WebInputEvent::GestureFlingStart: { | 269 case blink::WebInputEvent::GestureFlingStart: { |
| 237 const float kFlingVelocityThreshold = 1100.f; | 270 const float kFlingVelocityThreshold = 1100.f; |
| 238 const blink::WebGestureEvent& gesture = | 271 const blink::WebGestureEvent& gesture = |
| 239 static_cast<const blink::WebGestureEvent&>(event); | 272 static_cast<const blink::WebGestureEvent&>(event); |
| 240 float velocity_x = gesture.data.flingStart.velocityX; | 273 float velocity_x = gesture.data.flingStart.velocityX; |
| 241 float velocity_y = gesture.data.flingStart.velocityY; | 274 float velocity_y = gesture.data.flingStart.velocityY; |
| 242 if (fabs(velocity_x) > kFlingVelocityThreshold) { | 275 if (fabs(velocity_x) > kFlingVelocityThreshold) { |
| 243 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || | 276 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 263 default: | 296 default: |
| 264 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) || | 297 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) || |
| 265 blink::WebInputEvent::isTouchEventType(event.type)) | 298 blink::WebInputEvent::isTouchEventType(event.type)) |
| 266 << "Received unexpected event: " << event.type; | 299 << "Received unexpected event: " << event.type; |
| 267 } | 300 } |
| 268 return event_processed; | 301 return event_processed; |
| 269 } | 302 } |
| 270 | 303 |
| 271 bool OverscrollController::ProcessOverscroll(float delta_x, | 304 bool OverscrollController::ProcessOverscroll(float delta_x, |
| 272 float delta_y, | 305 float delta_y, |
| 273 blink::WebInputEvent::Type type) { | 306 bool is_touchpad) { |
| 274 if (scroll_state_ != STATE_CONTENT_SCROLLING) | 307 if (scroll_state_ != STATE_CONTENT_SCROLLING) |
| 275 overscroll_delta_x_ += delta_x; | 308 overscroll_delta_x_ += delta_x; |
| 276 overscroll_delta_y_ += delta_y; | 309 overscroll_delta_y_ += delta_y; |
| 277 | 310 |
| 278 float horiz_threshold = GetOverscrollConfig( | 311 float horiz_threshold = GetOverscrollConfig( |
| 279 WebInputEvent::isGestureEventType(type) ? | 312 is_touchpad ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD |
| 280 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN : | 313 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); |
| 281 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD); | |
| 282 float vert_threshold = GetOverscrollConfig( | 314 float vert_threshold = GetOverscrollConfig( |
| 283 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); | 315 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); |
| 284 if (fabs(overscroll_delta_x_) <= horiz_threshold && | 316 if (fabs(overscroll_delta_x_) <= horiz_threshold && |
| 285 fabs(overscroll_delta_y_) <= vert_threshold) { | 317 fabs(overscroll_delta_y_) <= vert_threshold) { |
| 286 SetOverscrollMode(OVERSCROLL_NONE); | 318 SetOverscrollMode(OVERSCROLL_NONE); |
| 287 return true; | 319 return true; |
| 288 } | 320 } |
| 289 | 321 |
| 290 // Compute the current overscroll direction. If the direction is different | 322 // Compute the current overscroll direction. If the direction is different |
| 291 // from the current direction, then always switch to no-overscroll mode first | 323 // from the current direction, then always switch to no-overscroll mode first |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 overscroll_mode_ = mode; | 388 overscroll_mode_ = mode; |
| 357 if (overscroll_mode_ == OVERSCROLL_NONE) | 389 if (overscroll_mode_ == OVERSCROLL_NONE) |
| 358 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 390 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
| 359 else | 391 else |
| 360 scroll_state_ = STATE_OVERSCROLLING; | 392 scroll_state_ = STATE_OVERSCROLLING; |
| 361 if (delegate_) | 393 if (delegate_) |
| 362 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); | 394 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); |
| 363 } | 395 } |
| 364 | 396 |
| 365 } // namespace content | 397 } // namespace content |
| OLD | NEW |