commit 8d0f56f4c055ea9071b37d8f14581c230979870d
parent 82cae826f866869c31e8152558b91f091035648f
Author: Boris Chiou <boris.chiou@gmail.com>
Date: Wed, 10 Dec 2025 07:37:32 +0000
Bug 1919415 - Handle zero range for scroll-driven animations on the compositor thread. r=hiro,layout-reviewers
It is possible to get a zero range from APZ sampler (e.g. see the test
in this patch), so we have to early return it.
Differential Revision: https://phabricator.services.mozilla.com/D275732
Diffstat:
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/gfx/layers/AnimationHelper.cpp b/gfx/layers/AnimationHelper.cpp
@@ -46,8 +46,15 @@ static dom::Nullable<TimeDuration> CalculateElapsedTimeForScrollTimeline(
aOptions.axis() == layers::ScrollDirection::eHorizontal;
double range =
isHorizontal ? aScrollMeta->mRange.width : aScrollMeta->mRange.height;
+ // The APZ sampler may give us a zero range (e.g. if the user resizes the
+ // element).
+ if (range == 0.0) {
+ // If the range is zero, we cannot calculate the progress, so just return
+ // nullptr.
+ return nullptr;
+ }
MOZ_ASSERT(
- range > 0,
+ range > 0.0,
"We don't expect to get a zero or negative range on the compositor");
// The offset may be negative if the writing mode is from right to left.
diff --git a/testing/web-platform/tests/scroll-animations/crashtests/scroll-timeline-resize.html b/testing/web-platform/tests/scroll-animations/crashtests/scroll-timeline-resize.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html class="test-wait">
+<title>This test passes if it does not crash when resizing the scroller</title>
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/">
+<script src="/web-animations/testcommon.js"></script>
+<style>
+@keyframes scrolling {
+ from, to { background: lightblue; }
+}
+#box {
+ width: 200px;
+ height: 50px;
+ overflow: auto;
+ animation: scrolling;
+ animation-timeline: scroll(self);
+}
+</style>
+<body onload="run()">
+ <div id="box">
+ <h3>Resize this box!</h3>
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer finibus elit sed ultricies semper. Proin faucibus sollicitudin nisi, id pellentesque lectus iaculis id.</p>
+ </div>
+</body>
+<script>
+async function run() {
+ let anims = document.getAnimations();
+ await anims[0].ready;
+ // Wait for some frames to wait for the setup of compositor animations.
+ await waitForAnimationFrames(2);
+ box.style.height = "200px";
+ await waitForAnimationFrames(2);
+ document.documentElement.className = "";
+}
+</script>