Skip to content

Commit ab99903

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Linear gradients: clamp stops at same position instead of replacing them
https://bugs.webkit.org/show_bug.cgi?id=306400 rdar://169063497 Reviewed by Simon Fraser. When all color stops in a linear gradient are at the same position, they should create a hard color transition at that clamped position, preserving all stop colors to maintain proper color interpolation. Previously, LinearGradientAdapter::normalizeStopsAndEndpointsOutsideRange would clamp all stops to offset 1, but this didn't properly handle cases where stops were at positions outside the [0, 1] range. The fix clamps the offset to the [0, 1] range while preserving all color stops at that position, allowing the gradient renderer to correctly handle the hard transition with proper color interpolation when needed. NOTE - the test name includes `radial` but in actual, it is for `linear-gradient`. * Source/WebCore/style/values/images/StyleGradient.cpp: (WebCore::Style::LinearGradientAdapter::normalizeStopsAndEndpointsOutsideRange): * LayoutTests/TestExpectations: Progressions Canonical link: https://commits.webkit.org/306823@main
1 parent cf5db81 commit ab99903

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

LayoutTests/TestExpectations

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,8 +5360,6 @@ webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/image-orienta
53605360
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/image-orientation/svg-image-orientation.html [ ImageOnlyFailure ]
53615361
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/image-orientation/svg-image-orientation-none.html [ ImageOnlyFailure ]
53625362
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/infinite-radial-gradient-refcrash.html [ ImageOnlyFailure ]
5363-
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/normalization-linear.html [ ImageOnlyFailure ]
5364-
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/normalization-radial.html [ ImageOnlyFailure ]
53655363
webkit.org/b/214456 imported/w3c/web-platform-tests/css/css-images/out-of-range-color-stop-conic.html [ ImageOnlyFailure ]
53665364

53675365
# Crashes

Source/WebCore/style/values/images/StyleGradient.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Apple Inc. All rights reserved.
2+
* Copyright (C) 2022-2026 Apple Inc. All rights reserved.
33
* Copyright (C) 2024-2025 Samuel Weinig <[email protected]>
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -205,9 +205,11 @@ class LinearGradientAdapter {
205205
m_data.point0 = { p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y()) };
206206
m_data.point1 = { p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y()) };
207207
} else {
208-
// There's a single position that is outside the scale, clamp the positions to 1.
208+
// All stops at same position - clamp offsets but keep all colors.
209+
// This creates a hard color stop at the clamped position.
210+
float clampedOffset = std::clamp(firstOffset, 0.0f, 1.0f);
209211
for (auto& stop : stops)
210-
stop.offset = 1;
212+
stop.offset = clampedOffset;
211213
}
212214
}
213215

0 commit comments

Comments
 (0)