0

Ash: fix ScrollViewGradientHelper DCHECKS in LinearGradient

If the ScrollView that a ScrollViewGradientHelper is attached to becomes
smaller than the requested gradient size, then UpdateGradientMask will
pass bogus values to gfx::LinearGradient. This then triggers DCHECKs in
LinearGradient.

This change clamps the gradient size so that for these degenerate cases,
the top and bottom gradients will be no larger than half of the height.

BUG=b:266711562

Change-Id: I1d37a0eeecae2ffeca024b8e8224e6f1010a36b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4195480
Commit-Queue: Daniel Andersson <dandersson@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1097115}
This commit is contained in:
Daniel Andersson
2023-01-25 23:56:25 +00:00
committed by Chromium LUCI CQ
parent c38ea4a0a3
commit 08a77273df

@ -62,8 +62,12 @@ void ScrollViewGradientHelper::UpdateGradientMask() {
// Vertical linear gradient, from top to bottom.
gfx::LinearGradient gradient_mask(/*angle=*/-90);
float fade_position =
static_cast<float>(gradient_height_) / scroll_view_->bounds().height();
// Clamp fade_position to the ~middle. If we don't do this, then in degenerate
// cases (where the gradients are larger than the scroll view itself) we would
// end up passing bogus values to the gradient mask.
const float fade_position = std::min(
static_cast<float>(gradient_height_) / scroll_view_->bounds().height(),
0.49f);
// Top fade in section.
if (show_top_gradient) {