LibWeb/CSS: Invalidate color-stop caches when source data changes

We previously only invalidated the cached color-stop data when the
painted area's size changed. However, multiple elements can use the
same gradient and be the same size, but have different parameters that
affect the gradient stop positions, for example if a stop has an em
position. This can also change for the same element over time.

The new cache instead uses these parameters as the cache key. So we
recompute the cache if lengths would resolve differently, or the area's
size is different.

The included test fails without this change.
This commit is contained in:
Sam Atkins 2025-02-21 16:45:07 +00:00 committed by Andreas Kling
commit 6a4a60cbd5
Notes: github-actions[bot] 2025-02-28 12:52:25 +00:00
9 changed files with 109 additions and 25 deletions

View file

@ -1,7 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -38,8 +38,14 @@ String ConicGradientStyleValue::to_string(SerializationMode mode) const
void ConicGradientStyleValue::resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const& node, CSSPixelSize size) const
{
if (!m_resolved.has_value())
ResolvedDataCacheKey cache_key {
.length_resolution_context = Length::ResolutionContext::for_layout_node(node),
.size = size,
};
if (m_resolved_data_cache_key != cache_key) {
m_resolved_data_cache_key = move(cache_key);
m_resolved = ResolvedData { Painting::resolve_conic_gradient_data(node, *this), {} };
}
m_resolved->position = m_properties.position->resolved(node, CSSPixelRect { { 0, 0 }, size });
}