Skip to content

Truly independent web browser

LibWeb: Name the readers of an animated color from the record below

Andreas Klinge7b1892f5295
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs b/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs
index 24eab12349b..92a77e8d68d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs
@@ -393,8 +393,6 @@ pub(in crate::css::style) unsafe fn publish_sampled_animation_overlay(
};
let old_view = crate::css::style::StyleRecordView::of_host_record(&old_record);
let rebuilt = engine.build_animation_overlay_payloads(
- node,
- pseudo_kind,
old_view,
longhands,
overlay,
diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rs
index 47973da746e..04d3f9a1d4a 100644
--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs
@@ -1020,11 +1020,6 @@ impl ComputedGroupSets {
}
}
- /// The installed record `record` names, while it is live.
- fn installed(&self, record: FinalStyleRecordID) -> Option<&InstalledRecord> {
- self.installed.get(record.installed_record()?)
- }
-
/// Take a slot for a record the engine computed, or answer the one it holds already.
/// `dependency_flags` says what the view of a record in a new slot depends on.
pub(super) fn install_record(
@@ -1587,10 +1582,6 @@ impl ComputedGroupSets {
.filter_map(|row| row.published.then_some(row.kind))
}
- fn longhands_for_target(&self, target: ComputedStyleTarget) -> Option<ViewLonghands<'_>> {
- let installed = self.installed(self.assigned_final_style_record(target)?)?;
- Some(ViewLonghands::of_record(installed.record()))
- }
/// The groups whose values read, from `values`, the recorded specified values of the longhands
/// whose computed values depend on what the element inherits, one that `depends_on_input`.
pub(super) fn specified_value_dependency_mask_of<'a>(
@@ -1605,19 +1596,15 @@ impl ComputedGroupSets {
.fold(0, |mask, groups| mask | groups)
}
- /// The groups whose previous specified values actually read `currentColor` while computing.
- /// Missing dependency coverage stays typed so a color winner change can widen safely.
+ /// The groups whose specified values in `longhands` actually read `currentColor` while computing.
#[must_use]
- pub fn current_color_dependency_mask(&self, target: ComputedStyleTarget) -> Option<u32> {
- let longhands = self.longhands_for_target(target)?;
- Some(
- Self::specified_value_dependency_mask_of(
- longhands.inheritance_dependent_values(),
- retained_value_depends_on_current_color,
- ) | crate::css::table_group_builder::groups_reading_current_color_through_inherited_values(|property| {
- longhands.value(property)
- }),
- )
+ pub(crate) fn current_color_dependency_mask(longhands: ViewLonghands<'_>) -> u32 {
+ Self::specified_value_dependency_mask_of(
+ longhands.inheritance_dependent_values(),
+ retained_value_depends_on_current_color,
+ ) | crate::css::table_group_builder::groups_reading_current_color_through_inherited_values(|property| {
+ longhands.value(property)
+ })
}
/// Whether a raw final record identity still names a live installed record.
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
index 7fc540f1495..222f4ad7031 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
@@ -193,8 +193,6 @@ impl RetainedState {
#[allow(clippy::too_many_arguments)]
pub(crate) fn build_animation_overlay_payloads(
&self,
- node: StyleNodeID,
- pseudo_kind: u8,
view: StyleRecordView<'_>,
longhands: ViewLonghands<'_>,
overlay: Option<&AnimatedOverlay>,
@@ -213,8 +211,7 @@ impl RetainedState {
bits: view.base_payloads.style_bits(),
});
};
- // A value no group is known to hold, or an animated `color` whose readers the engine cannot
- // name, rebuilds every group.
+ // A value no group is known to hold rebuilds every group.
let named_groups = overlay.entries().iter().try_fold(0u32, |groups, entry| {
// NB: A value the inherited bits hold is in no group: the sample holds it beside them.
if crate::css::computed_values::StyleBitField::of(entry.property).is_some() {
@@ -222,7 +219,7 @@ impl RetainedState {
}
let group = crate::css::property_metadata::property_style_group_index(entry.property)?;
let readers = match entry.property {
- prop::COLOR => self.current_color_dependent_group_mask(node, pseudo_kind)?,
+ prop::COLOR => Self::current_color_dependent_group_mask(longhands)?,
_ => 0,
};
Some(groups | 1 << group | readers)
@@ -482,13 +479,7 @@ impl super::StyleEngine {
if outcome == crate::css::style_compute::FfiHostAnimationSampleOutcome::Cleared {
overlay = AnimatedOverlay::default();
}
- let sample = self.compose_overlay_over_record(
- node,
- crate::css::cascaded_properties::NO_PSEUDO_ELEMENT,
- record,
- &overlay,
- bounds,
- )?;
+ let sample = self.compose_overlay_over_record(node, record, &overlay, bounds)?;
Ok((sample, overlay))
}
@@ -499,7 +490,6 @@ impl super::StyleEngine {
pub(crate) fn compose_overlay_over_record(
&mut self,
node: StyleNodeID,
- pseudo_kind: u8,
record: &std::sync::Arc<super::pipeline::Record>,
overlay: &AnimatedOverlay,
bounds: super::style_invalidation::SampleBounds,
@@ -522,8 +512,6 @@ impl super::StyleEngine {
let mut payloads = [std::ptr::null(); group_index::COUNT];
let mut build = |engine: &Self, font: Option<&FfiFontGroupBuildInputs>| {
engine.build_animation_overlay_payloads(
- node,
- pseudo_kind,
view,
longhands,
Some(overlay),
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index ae45c31bd30..15222858ab2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -642,9 +642,8 @@ impl RetainedState {
self.computed_group_sets.unpin_style_record(style_record);
}
- pub(crate) fn current_color_dependent_group_mask(&self, node: StyleNodeID, pseudo_kind: u8) -> Option<u32> {
- let target = computed::ComputedStyleTarget::new(node, pseudo_kind);
- let dependencies = self.computed_group_sets.current_color_dependency_mask(target)?;
+ pub(crate) fn current_color_dependent_group_mask(longhands: ViewLonghands<'_>) -> Option<u32> {
+ let dependencies = computed::ComputedGroupSets::current_color_dependency_mask(longhands);
let caret_color_group = computed_group_output_mask(crate::css::property_metadata::property_id::CARET_COLOR)?;
let accent_color_group = computed_group_output_mask(crate::css::property_metadata::property_id::ACCENT_COLOR)?;
Some(dependencies | caret_color_group | accent_color_group)
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index 2fd56a3bdf2..6772709a28d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -8,7 +8,7 @@ use super::bridge::{ElementBoxKind, FfiAnimationInvalidation, FfiStyleInvalidati
use super::computed::{ComputedGroupSets, FinalStyleRecordID, StyleRecordView, ViewLonghands};
use super::{RetainedState, StyleNodeID};
use crate::css::animated_overlay::{AnimatedOverlay, overlay_wins};
-use crate::css::computed_value_types::SVG_PAINT_NONE;
+use crate::css::computed_value_types::{ComputedFilter, SVG_PAINT_NONE};
use crate::css::computed_value_views::ComputedValuesView;
use crate::css::property_metadata::{
self, FIRST_LONGHAND_PROPERTY_ID, LAST_LONGHAND_PROPERTY_ID, NUMBER_OF_LONGHAND_PROPERTIES, property_id,
@@ -748,6 +748,31 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Comput
result
}
+/// Whether `old` and `new`, the operations of one filter value, bake different colors.
+fn filter_colors_differ(old: &ComputedFilter, new: &ComputedFilter) -> bool {
+ let (old, new) = (old.operations.as_slice(), new.operations.as_slice());
+ old.len() == new.len()
+ && old
+ .iter()
+ .zip(new)
+ .any(|(old, new)| old.shadow_color != new.shadow_color)
+}
+
+/// What a move from `old` to `new` damages through the filters that bake the element's color: a filter stays the same
+/// value as that color moves, so no comparison of values finds it, and the visual context holding it would keep painting
+/// the old color.
+fn baked_filter_color_damage(old: ComputedValuesView<'_>, new: ComputedValuesView<'_>) -> StyleInvalidation {
+ let (old_effects, new_effects) = (old.effects(), new.effects());
+ let mut damage = StyleInvalidation::default();
+ if filter_colors_differ(&old_effects.filter, &new_effects.filter) {
+ damage.merge(property_invalidation(property_id::FILTER, old, new));
+ }
+ if filter_colors_differ(&old_effects.backdrop_filter, &new_effects.backdrop_filter) {
+ damage.merge(property_invalidation(property_id::BACKDROP_FILTER, old, new));
+ }
+ damage
+}
+
/// The value of `property` in the record viewed by `view`, whose longhands are `longhands`, with
/// the view's animated values over them.
fn effective_value<'a>(
@@ -899,6 +924,7 @@ impl RetainedState {
}
invalidation.merge(property_damage);
}
+ invalidation.merge(baked_filter_color_damage(old_values, new_values));
// Animated properties other than text-decoration-line cannot make an undecorated box decorated.
if invalidation.repaint_text_decorations
@@ -958,9 +984,9 @@ impl RetainedState {
|| self.projection.first_element_child(node).is_none())
}
- /// What moving a box from the record `old_style_record` to `new_style_record` damages, of `properties` alone, read
- /// from the records' payloads: a sample of animations over a record keeps the record's longhand table, and holds
- /// the values it animates only in its payloads.
+ /// What moving a box from the record `old_style_record` to `new_style_record` damages, of `properties` and the
+ /// filters that bake the element's color alone, read from the records' payloads: a sample of animations over a
+ /// record keeps the record's longhand table, and holds the values it animates only in its payloads.
pub(crate) fn sampled_properties_damage(
&self,
old_style_record: u64,
@@ -982,6 +1008,7 @@ impl RetainedState {
for &property in properties {
result.merge(property_invalidation(property, old_values, new_values));
}
+ result.merge(baked_filter_color_damage(old_values, new_values));
result.pack()
}
@@ -1253,6 +1280,7 @@ fn record_move_damage(
}
result.merge(invalidation);
}
+ result.merge(baked_filter_color_damage(old_values, new_values));
let old_overlay = old_record.animated_overlay;
let new_overlay = new_record.animated_overlay;
if old_overlay.is_some() || new_overlay.is_some() {
diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rs
index cd86911808e..94c5cdf5a3e 100644
--- a/Libraries/LibWeb/Rust/src/css/style_value.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs
@@ -4919,8 +4919,9 @@ pub(crate) fn value_depends_on_current_color(value: &StyleValueData) -> bool {
retained_data_depends(light) || retained_data_depends(dark)
}
StyleValueData::Shadow(shadow_payload) => {
+ // A shadow without a color is `currentcolor`.
let ShadowPayload { color, .. } = &**shadow_payload;
- retained_data_depends(color)
+ color.optional_data().is_none_or(value_depends_on_current_color)
}
StyleValueData::Filter { value, .. } => retained_data_depends(value),
StyleValueData::ScrollbarColor(scrollbar_color_payload) => {
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs b/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
index 1d23b5092b0..e8eecfb97f0 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
@@ -18,9 +18,7 @@ use crate::css::style::layout_style::DerivedStyleRecord;
use crate::css::style::tree::StyleNodeID;
use crate::css::style::{SampleBounds, StyleEngine};
use crate::css::transition::{HoverTransitions, LaneTransitions};
-use crate::layout::node_data::{
- GENERATED_FOR_AFTER, GENERATED_FOR_BEFORE, GENERATED_FOR_MARKER, NodeSlotId, pseudo_kind_of,
-};
+use crate::layout::node_data::{GENERATED_FOR_AFTER, GENERATED_FOR_BEFORE, GENERATED_FOR_MARKER, NodeSlotId};
use crate::layout::{LayoutNodeArena, SampleKind, StyleRelayout};
use crate::painting::host::FfiVisualAnimationTargetKind;
use crate::painting::record::damage::PaintDamage;
@@ -516,13 +514,10 @@ impl Lane {
inherited.set_owned(property, entry.clone_value(), true, false);
}
}
- match state.engine_mut().compose_overlay_over_record(
- *descendant,
- crate::css::cascaded_properties::NO_PSEUDO_ELEMENT,
- &host_record,
- &inherited,
- bounds,
- ) {
+ match state
+ .engine_mut()
+ .compose_overlay_over_record(*descendant, &host_record, &inherited, bounds)
+ {
Ok(sample) => samples.push((row, *descendant, sample, &properties[..])),
Err(needs_host) => {
composed = Err(needs_host);
@@ -626,13 +621,9 @@ impl Lane {
}
}
let host_record = state.engine_ref().host_record(host_record).ok_or(NeedsHost)?.clone();
- let sample = state.engine_mut().compose_overlay_over_record(
- *node,
- pseudo_kind_of(generated_for),
- &host_record,
- &inherited,
- bounds,
- )?;
+ let sample = state
+ .engine_mut()
+ .compose_overlay_over_record(*node, &host_record, &inherited, bounds)?;
composed.push((row, sample, inherited_properties));
}
}
diff --git a/Tests/LibWeb/Ref/expected/css/style-engine/filter-shadow-follows-moved-color-ref.html b/Tests/LibWeb/Ref/expected/css/style-engine/filter-shadow-follows-moved-color-ref.html
new file mode 100644
index 00000000000..88baa08e9f9
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/css/style-engine/filter-shadow-follows-moved-color-ref.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<style>
+ .box { width: 50px; height: 50px; margin: 30px; background: gray; }
+ .implicit { filter: drop-shadow(8px 8px); }
+ .explicit { filter: drop-shadow(8px 8px currentcolor); }
+ .backdrop-root { position: relative; width: 200px; height: 200px; opacity: 0.99; }
+ .square { position: absolute; left: 40px; top: 40px; width: 20px; height: 20px; background: black; }
+ .backdrop { position: absolute; left: 10px; top: 10px; width: 120px; height: 120px; backdrop-filter: drop-shadow(8px 8px); }
+ .pseudo::before { content: ""; display: block; width: 50px; height: 50px; margin: 30px; background: gray; filter: drop-shadow(8px 8px); }
+</style>
+<div style="color: rgb(0, 0, 255)">
+ <div class="box implicit"></div>
+ <div class="box explicit"></div>
+</div>
+<div style="color: rgb(0, 0, 255)">
+ <div class="box implicit"></div>
+ <div class="box explicit"></div>
+</div>
+<div class="backdrop-root">
+ <div class="square"></div>
+ <div class="backdrop" style="color: rgb(0, 0, 255)"></div>
+</div>
+<div class="pseudo" style="color: rgb(0, 0, 255)"></div>
diff --git a/Tests/LibWeb/Ref/input/css/style-engine/filter-shadow-follows-moved-color.html b/Tests/LibWeb/Ref/input/css/style-engine/filter-shadow-follows-moved-color.html
new file mode 100644
index 00000000000..51a8cad8839
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/css/style-engine/filter-shadow-follows-moved-color.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="match" href="../../../expected/css/style-engine/filter-shadow-follows-moved-color-ref.html">
+<style>
+ .box { width: 50px; height: 50px; margin: 30px; background: gray; }
+ .implicit { filter: drop-shadow(8px 8px); }
+ .explicit { filter: drop-shadow(8px 8px currentcolor); }
+ .backdrop-root { position: relative; width: 200px; height: 200px; opacity: 0.99; }
+ .square { position: absolute; left: 40px; top: 40px; width: 20px; height: 20px; background: black; }
+ .backdrop { position: absolute; left: 10px; top: 10px; width: 120px; height: 120px; backdrop-filter: drop-shadow(8px 8px); }
+ .pseudo::before { content: ""; display: block; width: 50px; height: 50px; margin: 30px; background: gray; filter: drop-shadow(8px 8px); }
+</style>
+<div id="animated" style="color: rgb(255, 0, 0)">
+ <div class="box implicit"></div>
+ <div class="box explicit"></div>
+</div>
+<div id="inherited" style="color: rgb(255, 0, 0)">
+ <div class="box implicit"></div>
+ <div class="box explicit"></div>
+</div>
+<div class="backdrop-root">
+ <div class="square"></div>
+ <div id="backdrop" class="backdrop" style="color: rgb(255, 0, 0)"></div>
+</div>
+<div id="pseudo" class="pseudo" style="color: rgb(255, 0, 0)"></div>
+<script>
+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ const animation = document.getElementById("animated").animate([
+ { color: "rgb(0, 128, 0)", offset: 0 },
+ { color: "rgb(0, 128, 0)", offset: 0.5 },
+ { color: "rgb(0, 0, 255)", offset: 0.5 },
+ { color: "rgb(0, 0, 255)", offset: 1 },
+ ], { duration: 1000, fill: "both" });
+ const keyframes = animation.effect.getKeyframes();
+ const backdropAnimation = document.getElementById("backdrop").animate(keyframes, { duration: 1000, fill: "both" });
+ const pseudoAnimation = document.getElementById("pseudo").animate(keyframes, { duration: 1000, fill: "both" });
+ animation.pause();
+ backdropAnimation.pause();
+ pseudoAnimation.pause();
+ (async () => {
+ animation.currentTime = backdropAnimation.currentTime = pseudoAnimation.currentTime = 250;
+ await nextFrame();
+ animation.currentTime = backdropAnimation.currentTime = pseudoAnimation.currentTime = 750;
+ document.getElementById("inherited").style.color = "rgb(0, 0, 255)";
+ await nextFrame();
+ document.documentElement.classList.remove("reftest-wait");
+ })();
+</script>
+</html>