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

Unified Diff: content/browser/android/overscroll_controller_android.cc

Issue 2884423003: Use scroll-boundary-behavior to control overscroll-refresh/glow on android. (Closed)
Patch Set: rebase Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/android/overscroll_controller_android.cc
diff --git a/content/browser/android/overscroll_controller_android.cc b/content/browser/android/overscroll_controller_android.cc
index 3be50dac488ac9fdad7f86d83d778b8ef26cd3fd..9998e41bab27ce0c058becfae943f242ea2cb4f8 100644
--- a/content/browser/android/overscroll_controller_android.cc
+++ b/content/browser/android/overscroll_controller_android.cc
@@ -96,17 +96,29 @@ std::unique_ptr<OverscrollRefresh> CreateRefreshEffect(
} // namespace
OverscrollControllerAndroid::OverscrollControllerAndroid(
- ui::OverscrollRefreshHandler* overscroll_refresh_handler,
ui::WindowAndroidCompositor* compositor,
- float dpi_scale)
+ float dpi_scale,
+ ui::OverscrollGlow* glow_effect,
+ ui::OverscrollRefresh* refresh_effect)
: compositor_(compositor),
dpi_scale_(dpi_scale),
enabled_(true),
- glow_effect_(CreateGlowEffect(this, dpi_scale_)),
- refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) {
+ scroll_update_consumed_(false),
+ glow_effect_(glow_effect),
+ refresh_effect_(refresh_effect) {
DCHECK(compositor_);
}
+OverscrollControllerAndroid::OverscrollControllerAndroid(
+ ui::OverscrollRefreshHandler* overscroll_refresh_handler,
+ ui::WindowAndroidCompositor* compositor,
+ float dpi_scale)
+ : OverscrollControllerAndroid(
+ compositor,
+ dpi_scale,
+ CreateGlowEffect(this, dpi_scale_).get(),
+ CreateRefreshEffect(overscroll_refresh_handler).get()) {}
+
OverscrollControllerAndroid::~OverscrollControllerAndroid() {
}
@@ -128,6 +140,7 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
switch (event.GetType()) {
case blink::WebInputEvent::kGestureScrollBegin:
refresh_effect_->OnScrollBegin();
+ scroll_update_consumed_ = false;
break;
case blink::WebInputEvent::kGestureScrollUpdate: {
@@ -189,10 +202,9 @@ void OverscrollControllerAndroid::OnGestureEventAck(
refresh_effect_) {
// The effect should only be allowed if both the causal touch events go
// unconsumed and the generated scroll events go unconsumed.
- bool consumed =
+ scroll_update_consumed_ =
ack_result == INPUT_EVENT_ACK_STATE_CONSUMED ||
event.data.scroll_update.previous_update_in_sequence_prevented;
- refresh_effect_->OnScrollUpdateAck(consumed);
}
}
@@ -201,22 +213,51 @@ void OverscrollControllerAndroid::OnOverscrolled(
if (!enabled_)
return;
- if (refresh_effect_ && (refresh_effect_->IsActive() ||
- refresh_effect_->IsAwaitingScrollUpdateAck())) {
- // An active (or potentially active) refresh effect should always pre-empt
- // the passive glow effect.
- return;
+ if (refresh_effect_) {
+ bool can_navigate =
+ (!scroll_update_consumed_) &&
+ (params.scroll_boundary_behavior.y ==
+ cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
+ kScrollBoundaryBehaviorTypeAuto);
+ refresh_effect_->OnOverscrolled(can_navigate);
+
+ if (refresh_effect_->IsActive() ||
+ refresh_effect_->IsAwaitingScrollUpdateAck()) {
+ // An active (or potentially active) refresh effect should always pre-empt
+ // the passive glow effect.
+ return;
+ }
+ }
+
+ gfx::Vector2dF accumulated_overscroll =
+ gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_);
+ gfx::Vector2dF latest_overscroll_delta =
+ gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_);
+ gfx::Vector2dF current_fling_velocity =
+ gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_);
+ gfx::Vector2dF overscroll_location = gfx::ScaleVector2d(
+ params.causal_event_viewport_point.OffsetFromOrigin(), dpi_scale_);
+
+ if (params.scroll_boundary_behavior.x ==
+ cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
+ kScrollBoundaryBehaviorTypeNone) {
+ accumulated_overscroll.set_x(0);
+ latest_overscroll_delta.set_x(0);
+ current_fling_velocity.set_x(0);
+ }
+
+ if (params.scroll_boundary_behavior.y ==
+ cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
+ kScrollBoundaryBehaviorTypeNone) {
+ accumulated_overscroll.set_y(0);
+ latest_overscroll_delta.set_y(0);
+ current_fling_velocity.set_y(0);
}
- if (glow_effect_ &&
- glow_effect_->OnOverscrolled(
- base::TimeTicks::Now(),
- gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_),
- gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_),
- gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_),
- gfx::ScaleVector2d(
- params.causal_event_viewport_point.OffsetFromOrigin(),
- dpi_scale_))) {
+ if (glow_effect_ && glow_effect_->OnOverscrolled(
+ base::TimeTicks::Now(), accumulated_overscroll,
+ latest_overscroll_delta, current_fling_velocity,
+ overscroll_location)) {
SetNeedsAnimate();
}
}

Powered by Google App Engine
This is Rietveld 408576698