Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/android/overscroll_controller_android.h" | 5 #include "content/browser/android/overscroll_controller_android.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 88 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 89 switches::kDisablePullToRefreshEffect)) { | 89 switches::kDisablePullToRefreshEffect)) { |
| 90 return nullptr; | 90 return nullptr; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); | 93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 OverscrollControllerAndroid::OverscrollControllerAndroid( | 98 OverscrollControllerAndroid::OverscrollControllerAndroid( |
|
boliu
2017/08/23 19:17:02
this is only for tests right? Make that clear by m
sunyunjia
2017/08/23 23:47:05
Done.
| |
| 99 ui::WindowAndroidCompositor* compositor, | |
| 100 float dpi_scale, | |
| 101 std::unique_ptr<ui::OverscrollGlow> glow_effect, | |
| 102 std::unique_ptr<ui::OverscrollRefresh> refresh_effect) | |
| 103 : compositor_(compositor), | |
| 104 dpi_scale_(dpi_scale), | |
| 105 enabled_(true), | |
| 106 glow_effect_(std::move(glow_effect)), | |
| 107 refresh_effect_(std::move(refresh_effect)) {} | |
| 108 | |
| 109 OverscrollControllerAndroid::OverscrollControllerAndroid( | |
| 99 ui::OverscrollRefreshHandler* overscroll_refresh_handler, | 110 ui::OverscrollRefreshHandler* overscroll_refresh_handler, |
| 100 ui::WindowAndroidCompositor* compositor, | 111 ui::WindowAndroidCompositor* compositor, |
| 101 float dpi_scale) | 112 float dpi_scale) |
| 102 : compositor_(compositor), | 113 : OverscrollControllerAndroid( |
| 103 dpi_scale_(dpi_scale), | 114 compositor, |
| 104 enabled_(true), | 115 dpi_scale, |
| 105 glow_effect_(CreateGlowEffect(this, dpi_scale_)), | 116 CreateGlowEffect(this, dpi_scale), |
| 106 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) { | 117 CreateRefreshEffect(overscroll_refresh_handler)) {} |
| 107 DCHECK(compositor_); | |
|
boliu
2017/08/23 19:17:02
ditto don't remove production checks
sunyunjia
2017/08/23 23:47:05
Done.
| |
| 108 } | |
| 109 | 118 |
| 110 OverscrollControllerAndroid::~OverscrollControllerAndroid() { | 119 OverscrollControllerAndroid::~OverscrollControllerAndroid() { |
| 111 } | 120 } |
| 112 | 121 |
| 113 bool OverscrollControllerAndroid::WillHandleGestureEvent( | 122 bool OverscrollControllerAndroid::WillHandleGestureEvent( |
| 114 const blink::WebGestureEvent& event) { | 123 const blink::WebGestureEvent& event) { |
| 115 if (!enabled_) | 124 if (!enabled_) |
| 116 return false; | 125 return false; |
| 117 | 126 |
| 118 if (!refresh_effect_) | 127 if (!refresh_effect_) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // sent from the renderer compositor. | 191 // sent from the renderer compositor. |
| 183 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || | 192 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || |
| 184 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { | 193 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { |
| 185 OnOverscrolled(DidOverscrollParams()); | 194 OnOverscrolled(DidOverscrollParams()); |
| 186 } | 195 } |
| 187 | 196 |
| 188 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && | 197 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && |
| 189 refresh_effect_) { | 198 refresh_effect_) { |
| 190 // The effect should only be allowed if both the causal touch events go | 199 // The effect should only be allowed if both the causal touch events go |
| 191 // unconsumed and the generated scroll events go unconsumed. | 200 // unconsumed and the generated scroll events go unconsumed. |
| 192 bool consumed = | 201 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || |
| 193 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || | 202 event.data.scroll_update.previous_update_in_sequence_prevented) |
|
boliu
2017/08/23 19:17:02
style nit: need braces
sunyunjia
2017/08/23 23:47:05
Done.
| |
| 194 event.data.scroll_update.previous_update_in_sequence_prevented; | 203 refresh_effect_->Reset(); |
| 195 refresh_effect_->OnScrollUpdateAck(consumed); | |
| 196 } | 204 } |
| 197 } | 205 } |
| 198 | 206 |
| 199 void OverscrollControllerAndroid::OnOverscrolled( | 207 void OverscrollControllerAndroid::OnOverscrolled( |
| 200 const DidOverscrollParams& params) { | 208 const DidOverscrollParams& params) { |
| 201 if (!enabled_) | 209 if (!enabled_) |
| 202 return; | 210 return; |
| 203 | 211 |
| 204 if (refresh_effect_ && (refresh_effect_->IsActive() || | 212 if (refresh_effect_) { |
| 205 refresh_effect_->IsAwaitingScrollUpdateAck())) { | 213 if (params.scroll_boundary_behavior.y != |
| 206 // An active (or potentially active) refresh effect should always pre-empt | 214 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: |
| 207 // the passive glow effect. | 215 kScrollBoundaryBehaviorTypeAuto) |
| 208 return; | 216 refresh_effect_->Reset(); |
| 217 else | |
| 218 refresh_effect_->OnOverscrolled(); | |
| 219 | |
| 220 if (refresh_effect_->IsActive() || | |
| 221 refresh_effect_->IsAwaitingScrollUpdateAck()) { | |
| 222 // An active (or potentially active) refresh effect should always pre-empt | |
| 223 // the passive glow effect. | |
| 224 return; | |
| 225 } | |
| 209 } | 226 } |
| 210 | 227 |
| 211 if (glow_effect_ && | 228 gfx::Vector2dF accumulated_overscroll = |
| 212 glow_effect_->OnOverscrolled( | 229 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_); |
| 213 base::TimeTicks::Now(), | 230 gfx::Vector2dF latest_overscroll_delta = |
| 214 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_), | 231 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_); |
| 215 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_), | 232 gfx::Vector2dF current_fling_velocity = |
| 216 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_), | 233 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_); |
| 217 gfx::ScaleVector2d( | 234 gfx::Vector2dF overscroll_location = gfx::ScaleVector2d( |
| 218 params.causal_event_viewport_point.OffsetFromOrigin(), | 235 params.causal_event_viewport_point.OffsetFromOrigin(), dpi_scale_); |
| 219 dpi_scale_))) { | 236 |
| 237 if (params.scroll_boundary_behavior.x == | |
| 238 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: | |
| 239 kScrollBoundaryBehaviorTypeNone) { | |
| 240 accumulated_overscroll.set_x(0); | |
| 241 latest_overscroll_delta.set_x(0); | |
| 242 current_fling_velocity.set_x(0); | |
| 243 } | |
| 244 | |
| 245 if (params.scroll_boundary_behavior.y == | |
| 246 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType:: | |
| 247 kScrollBoundaryBehaviorTypeNone) { | |
| 248 accumulated_overscroll.set_y(0); | |
| 249 latest_overscroll_delta.set_y(0); | |
| 250 current_fling_velocity.set_y(0); | |
| 251 } | |
| 252 | |
| 253 if (glow_effect_ && glow_effect_->OnOverscrolled( | |
| 254 base::TimeTicks::Now(), accumulated_overscroll, | |
| 255 latest_overscroll_delta, current_fling_velocity, | |
| 256 overscroll_location)) { | |
| 220 SetNeedsAnimate(); | 257 SetNeedsAnimate(); |
| 221 } | 258 } |
| 222 } | 259 } |
| 223 | 260 |
| 224 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time, | 261 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time, |
| 225 cc::Layer* parent_layer) { | 262 cc::Layer* parent_layer) { |
| 226 DCHECK(parent_layer); | 263 DCHECK(parent_layer); |
| 227 if (!enabled_ || !glow_effect_) | 264 if (!enabled_ || !glow_effect_) |
| 228 return false; | 265 return false; |
| 229 | 266 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 glow_effect_->Reset(); | 307 glow_effect_->Reset(); |
| 271 } | 308 } |
| 272 } | 309 } |
| 273 | 310 |
| 274 std::unique_ptr<EdgeEffectBase> | 311 std::unique_ptr<EdgeEffectBase> |
| 275 OverscrollControllerAndroid::CreateEdgeEffect() { | 312 OverscrollControllerAndroid::CreateEdgeEffect() { |
| 276 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); | 313 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); |
| 277 } | 314 } |
| 278 | 315 |
| 279 void OverscrollControllerAndroid::SetNeedsAnimate() { | 316 void OverscrollControllerAndroid::SetNeedsAnimate() { |
| 280 compositor_->SetNeedsAnimate(); | 317 if (compositor_) |
|
boliu
2017/08/23 19:17:02
for testing again, right?
should either set a non
sunyunjia
2017/08/23 23:47:05
Done.
| |
| 318 compositor_->SetNeedsAnimate(); | |
| 281 } | 319 } |
| 282 | 320 |
| 283 } // namespace content | 321 } // namespace content |
| OLD | NEW |