Commit 9349a45e authored by jdduke's avatar jdduke Committed by Commit bot

[Android] Add slack to allow refresh after overscrolling

Allow pull-to-refresh activation when the overscroll glow effect is
active but mostly transparent. This accomodates accidental refresh
prevention while easing the frustration of having to wait until
the overscroll glow has completely faded.

BUG=428429

Review URL: https://codereview.chromium.org/993613007

Cr-Commit-Position: refs/heads/master@{#320986}
parent a0d04a4b
...@@ -305,6 +305,10 @@ bool EdgeEffect::Update(base::TimeTicks current_time) { ...@@ -305,6 +305,10 @@ bool EdgeEffect::Update(base::TimeTicks current_time) {
return !IsFinished(); return !IsFinished();
} }
float EdgeEffect::GetAlpha() const {
return IsFinished() ? 0.f : std::max(glow_alpha_, edge_alpha_);
}
void EdgeEffect::ApplyToLayers(const gfx::SizeF& size, void EdgeEffect::ApplyToLayers(const gfx::SizeF& size,
const gfx::Transform& transform) { const gfx::Transform& transform) {
if (IsFinished()) if (IsFinished())
......
...@@ -37,6 +37,7 @@ class EdgeEffect : public EdgeEffectBase { ...@@ -37,6 +37,7 @@ class EdgeEffect : public EdgeEffectBase {
void Finish() override; void Finish() override;
bool IsFinished() const override; bool IsFinished() const override;
float GetAlpha() const override;
void ApplyToLayers(const gfx::SizeF& size, void ApplyToLayers(const gfx::SizeF& size,
const gfx::Transform& transform) override; const gfx::Transform& transform) override;
......
...@@ -38,6 +38,7 @@ class EdgeEffectBase { ...@@ -38,6 +38,7 @@ class EdgeEffectBase {
virtual void Finish() = 0; virtual void Finish() = 0;
virtual bool IsFinished() const = 0; virtual bool IsFinished() const = 0;
virtual float GetAlpha() const = 0;
virtual void ApplyToLayers(const gfx::SizeF& size, virtual void ApplyToLayers(const gfx::SizeF& size,
const gfx::Transform& transform) = 0; const gfx::Transform& transform) = 0;
......
...@@ -211,6 +211,10 @@ bool EdgeEffectL::Update(base::TimeTicks current_time) { ...@@ -211,6 +211,10 @@ bool EdgeEffectL::Update(base::TimeTicks current_time) {
return !IsFinished() || one_last_frame; return !IsFinished() || one_last_frame;
} }
float EdgeEffectL::GetAlpha() const {
return IsFinished() ? 0.f : glow_alpha_;
}
void EdgeEffectL::ApplyToLayers(const gfx::SizeF& size, void EdgeEffectL::ApplyToLayers(const gfx::SizeF& size,
const gfx::Transform& transform) { const gfx::Transform& transform) {
if (IsFinished()) if (IsFinished())
......
...@@ -40,6 +40,7 @@ class EdgeEffectL : public EdgeEffectBase { ...@@ -40,6 +40,7 @@ class EdgeEffectL : public EdgeEffectBase {
void Finish() override; void Finish() override;
bool IsFinished() const override; bool IsFinished() const override;
float GetAlpha() const override;
void ApplyToLayers(const gfx::SizeF& size, void ApplyToLayers(const gfx::SizeF& size,
const gfx::Transform& transform) override; const gfx::Transform& transform) override;
......
...@@ -30,20 +30,31 @@ const int kAndroidLSDKVersion = 21; ...@@ -30,20 +30,31 @@ const int kAndroidLSDKVersion = 21;
// action will be activated. // action will be activated.
const int kDefaultRefreshDragTargetDips = 64; const int kDefaultRefreshDragTargetDips = 64;
// If the glow effect alpha is greater than this value, the refresh effect will
// be suppressed. This value was experimentally determined to provide a
// reasonable balance between avoiding accidental refresh activation and
// minimizing the wait required to refresh after the glow has been triggered.
const float kMinGlowAlphaToDisableRefreshOnL = 0.085f;
bool IsAndroidLOrNewer() { bool IsAndroidLOrNewer() {
static bool android_l_or_newer = static bool android_l_or_newer =
base::android::BuildInfo::GetInstance()->sdk_int() >= kAndroidLSDKVersion; base::android::BuildInfo::GetInstance()->sdk_int() >= kAndroidLSDKVersion;
return android_l_or_newer; return android_l_or_newer;
} }
bool ShouldDisableRefreshWhenGlowActive() { // Suppressing refresh detection when the glow is still animating prevents
// Suppressing refresh detection when the glow is still animating prevents // visual confusion and accidental activation after repeated scrolls.
// visual confusion and accidental activation after repeated scrolls. However, float MinGlowAlphaToDisableRefresh() {
// only the L effect is guaranteed to be both sufficiently brief and prominent // Only the L effect is guaranteed to be both sufficiently brief and prominent
// to provide a meaningful "wait" signal. The refresh effect on previous // to provide a meaningful "wait" signal. The refresh effect on previous
// Android releases can be quite faint, depending on the OEM-supplied // Android releases can be quite faint, depending on the OEM-supplied
// overscroll resources, and lasts nearly twice as long. // overscroll resources, and lasts nearly twice as long.
return IsAndroidLOrNewer(); if (IsAndroidLOrNewer())
return kMinGlowAlphaToDisableRefreshOnL;
// Any value greater than 1 effectively prevents the glow effect from ever
// suppressing the refresh effect.
return 1.01f;
} }
scoped_ptr<EdgeEffectBase> CreateGlowEdgeEffect( scoped_ptr<EdgeEffectBase> CreateGlowEdgeEffect(
...@@ -116,8 +127,9 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent( ...@@ -116,8 +127,9 @@ bool OverscrollControllerAndroid::WillHandleGestureEvent(
if (is_fullscreen_) if (is_fullscreen_)
return false; return false;
if (glow_effect_) { // Suppress refresh detection if the glow effect is still prominent.
if (glow_effect_->IsActive() && ShouldDisableRefreshWhenGlowActive()) if (glow_effect_ && glow_effect_->IsActive()) {
if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh())
return false; return false;
} }
......
...@@ -102,6 +102,15 @@ bool OverscrollGlow::IsActive() const { ...@@ -102,6 +102,15 @@ bool OverscrollGlow::IsActive() const {
return false; return false;
} }
float OverscrollGlow::GetVisibleAlpha() const {
float max_alpha = 0;
for (size_t i = 0; i < EDGE_COUNT; ++i) {
if (!edge_effects_[i]->IsFinished())
max_alpha = std::max(max_alpha, edge_effects_[i]->GetAlpha());
}
return std::min(max_alpha, 1.f);
}
bool OverscrollGlow::OnOverscrolled(base::TimeTicks current_time, bool OverscrollGlow::OnOverscrolled(base::TimeTicks current_time,
gfx::Vector2dF accumulated_overscroll, gfx::Vector2dF accumulated_overscroll,
gfx::Vector2dF overscroll_delta, gfx::Vector2dF overscroll_delta,
......
...@@ -69,6 +69,10 @@ class OverscrollGlow { ...@@ -69,6 +69,10 @@ class OverscrollGlow {
// Whether the effect is active, either being pulled or receding. // Whether the effect is active, either being pulled or receding.
bool IsActive() const; bool IsActive() const;
// The maximum alpha value (in the range [0,1]) of any animated edge layers.
// If the effect is inactive, this will be 0.
float GetVisibleAlpha() const;
private: private:
enum Axis { AXIS_X, AXIS_Y }; enum Axis { AXIS_X, AXIS_Y };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment