Skip to content

Truly independent web browser

LibWeb: Settle kept hidden styles by what a pass tells children from

Andreas Kling2372d7339848
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs
index 9b510358f82..9cac42e04a0 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs
@@ -15,7 +15,9 @@ use super::super::container_queries::ContainerVerdict;
use super::super::publication::{DemandedEngineRecord, RecordDemand, RecordDemandAnswer};
use super::super::*;
use super::live::Live;
-use super::records::{ChildImpact, MatchList, PseudoElementRecords, Record, RecordCells, Records, RetainedRecords};
+use super::records::{
+ ChildImpact, MatchList, PseudoElementRecords, Record, RecordCells, Records, RetainedRecords, highlights_moved,
+};
use super::rule_changes::RuleIndexChanges;
use super::rules::RuleIndex;
use super::traversal::{self, DemandedPseudoElement, PassContext, PseudoElementRead};
@@ -40,6 +42,9 @@ struct KeptComputation {
matches: Option<MatchList>,
/// What it computed, which what inherits through it computed from.
record: Arc<Record>,
+ /// The records of its highlight pseudo-elements beside `record`, which those of what inherits
+ /// through it computed from.
+ highlights: PseudoElementRecords,
}
/// Which records of the elements that keep their style below an element that is not displayed
@@ -295,6 +300,15 @@ impl Live {
}
}
+ /// The records of the highlight pseudo-elements of `node`, beside its current record.
+ fn demanded_highlights(&self, node: StyleNodeID) -> PseudoElementRecords {
+ self.demanded_pseudo_element_records(node)
+ .iter()
+ .filter(|(kind, _)| super::HIGHLIGHT_KINDS.contains(kind))
+ .cloned()
+ .collect()
+ }
+
/// What the container conditions of the current record of `node` read of its containers.
pub(super) fn demanded_container_reads(&self, node: StyleNodeID) -> Option<&Arc<ContainerVerdict>> {
match self.computed_on_demand(node) {
@@ -582,25 +596,30 @@ impl StyleEngine {
let live = self.retained.live_style.as_ref().expect("the engine owns the document");
let kept = &live.kept_hidden_records;
// NB: The chain of one element can compute another of them, so what each held is taken first.
- let mut reached: Vec<(StyleNodeID, Arc<Record>)> = kept
+ let mut reached: Vec<(StyleNodeID, Arc<Record>, PseudoElementRecords)> = kept
.moved
.iter()
.filter(|node| !kept.descendants_moved.contains(node) && self.retained.projection.is_live(**node))
- .filter_map(|&node| Some((node, kept.computed.get(&node)?.record.clone())))
+ .filter_map(|&node| {
+ let computation = kept.computed.get(&node)?;
+ Some((node, computation.record.clone(), computation.highlights.clone()))
+ })
.collect();
- reached.sort_unstable_by_key(|&(node, _)| node);
+ reached.sort_unstable_by_key(|&(node, ..)| node);
let mut installed = Vec::new();
- for (node, held) in reached {
+ for (node, held, held_highlights) in reached {
let mut demanded = self.demand_kept_chain(node);
let state = &self.retained;
let live = state.live_style.as_ref().expect("the engine owns the document");
let kept = &live.kept_hidden_records;
// NB: An element a pass styles now holds its record, not one computed on demand.
let current = live.demanded_record(node).filter(|_| kept.computed(node)).cloned();
+ let highlights = live.demanded_highlights(node);
let holds_the_same = current.as_ref().is_some_and(|record| record.holds_the_same_as(&held));
let children_stand = current.as_ref().is_some_and(|record| {
record.pseudo_element_styles() == held.pseudo_element_styles()
- && match ChildImpact::of_records(record, &held, &held.payloads) {
+ && !highlights_moved(&highlights, &held_highlights)
+ && match state.child_impact_of_records(node, record, &held) {
ChildImpact::None => true,
ChildImpact::ResetReaders => state.projection.style_children(node).all(|child| {
let record = kept.computed.get(&child).map(|computation| &computation.record);
@@ -614,6 +633,7 @@ impl StyleEngine {
let live = self.retained.live_style.as_mut().expect("the engine owns the document");
if let (Some(record), Some(computation)) = (current, live.kept_hidden_records.computed.get_mut(&node)) {
computation.record = record;
+ computation.highlights = highlights;
}
if children_stand {
live.kept_hidden_records.moved.remove(&node);
@@ -645,6 +665,7 @@ impl StyleEngine {
environment_reads: record.rare().reads.environment_reads,
matches: live.demand_records().matches_of(element).cloned(),
record: record.clone(),
+ highlights: live.demanded_highlights(element),
})
});
match computation {
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
index 26c55f319f4..f7674bbd01b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
@@ -1085,6 +1085,46 @@ impl Record {
}
impl RetainedState {
+ /// Which children of `node`, an element computing `new` where it computed `old`, compute anew:
+ /// those computing from something `new` differs in from what they inherited before, `old` or
+ /// the composition of its animations over that. A child computes from its parent's inherited
+ /// groups, color, zoom, publication dependencies, display and custom properties, as a result
+ /// is reused by, and from its other groups only where it read them.
+ pub(super) fn child_impact_of_records(
+ &self,
+ node: StyleNodeID,
+ new: &Arc<Record>,
+ old: &Arc<Record>,
+ ) -> ChildImpact {
+ if Arc::ptr_eq(new, old) {
+ return ChildImpact::None;
+ }
+ // The children inherited the composition of the element's animations over the record it
+ // held, where the host composed one, and the custom properties those sampled.
+ let composition = self.computed_group_sets.composition_over_record(node, old);
+ if self.sampled_custom_property_store(node).is_some() {
+ return ChildImpact::All;
+ }
+ ChildImpact::of_records(new, old, composition.map_or(&old.payloads, |view| view.payloads))
+ }
+
+ /// The custom properties the animations of `node` sampled, where the host sampled them over
+ /// the environment of the record the element holds, borrowed.
+ fn sampled_custom_property_store(
+ &self,
+ node: StyleNodeID,
+ ) -> Option<Option<&Arc<crate::css::custom_properties::CustomPropertyStore>>> {
+ let environment = self.computed_group_sets.custom_property_environment_identity(node);
+ let sampled = self
+ .element_custom_property_data
+ .get(&node)
+ .filter(|held| {
+ held.sampled_over.is_some() && (environment == Some(held.identity) || held.sampled_over == environment)
+ })?
+ .identity;
+ Some(self.custom_property_environments.store(sampled))
+ }
+
/// Install the record of a style the host made holding `payloads`, whose computed values are
/// the initial ones, and answer its identity. Nothing holds
/// the record yet: the next sweep frees it unless a holder pins it first.
@@ -1236,6 +1276,25 @@ pub(super) type BorrowedCustomProperties<'a> = Option<Cow<'a, Arc<crate::css::cu
pub(super) type PseudoElementRecords = smallvec::SmallVec<[(u8, Arc<Record>); 2]>;
+/// https://drafts.csswg.org/css-pseudo-4/#highlight-cascade
+/// Whether the highlight pseudo-elements of `new` hold other styles than those of `old`, which the
+/// highlight pseudo-elements of an element's children inherit from.
+pub(super) fn highlights_moved(new: &[(u8, Arc<Record>)], old: &[(u8, Arc<Record>)]) -> bool {
+ let of_kind = |records: &'_ [(u8, Arc<Record>)], kind: u8| {
+ records
+ .iter()
+ .find(|(held, _)| *held == kind)
+ .map(|(_, record)| record.clone())
+ };
+ super::HIGHLIGHT_KINDS
+ .iter()
+ .any(|&kind| match (of_kind(new, kind), of_kind(old, kind)) {
+ (None, None) => false,
+ (Some(new), Some(old)) => !Arc::ptr_eq(&new, &old) && !new.holds_the_same_as(&old),
+ _ => true,
+ })
+}
+
/// One element's record, with the identity it shares under. Elements holding one record need not
/// share an identity: a record reused for an equal cascade says nothing of the elements' selectors.
/// The rule index entries an element matched, in index order, behind one thin pointer, which the
@@ -1832,7 +1891,9 @@ impl<'a> Records<'a> {
/// the environment of the record the element holds: the element's own custom properties with
/// the animated values in place of theirs.
pub(super) fn sampled_custom_properties(&self, node: StyleNodeID) -> Option<HeldCustomProperties> {
- self.sampled_custom_property_store(node).map(|store| store.cloned())
+ self.state
+ .sampled_custom_property_store(node)
+ .map(|store| store.cloned())
}
/// The custom properties the animations of the pseudo-element of `kind` of `node` sampled:
@@ -1848,26 +1909,6 @@ impl<'a> Records<'a> {
self.state.custom_property_environments.store(held.identity).cloned()
}
- /// As [`Self::sampled_custom_properties`], borrowed.
- fn sampled_custom_property_store(
- &self,
- node: StyleNodeID,
- ) -> Option<Option<&'a Arc<crate::css::custom_properties::CustomPropertyStore>>> {
- let environment = self
- .state
- .computed_group_sets
- .custom_property_environment_identity(node);
- let sampled = self
- .state
- .element_custom_property_data
- .get(&node)
- .filter(|held| {
- held.sampled_over.is_some() && (environment == Some(held.identity) || held.sampled_over == environment)
- })?
- .identity;
- Some(self.state.custom_property_environments.store(sampled))
- }
-
/// The record `node` held before this pass, or the one the host holds for it or composes its animations over, where
/// it holds the style `record` does: what it keeps in place of `record`, so that its children compute from it as
/// they did, and the host has nothing to take.
@@ -1910,11 +1951,9 @@ impl<'a> Records<'a> {
.is_none_or(|held| !Arc::ptr_eq(held, record) && !held.holds_the_same_style_as(record))
}
- /// Which children of `node` the record this pass computed for it restyles: those computing
- /// from something it differs in from what they inherited before, the one it held or the
- /// composition of its animations over that. A child computes from its parent's
- /// inherited groups, color, zoom, publication dependencies, display and custom properties, as
- /// a result is reused by, and from its other groups only where it read them.
+ /// Which children of `node` the record this pass computed for it restyles, as
+ /// [`RetainedState::child_impact_of_records`] finds of the one it held before, or all of them
+ /// where its highlight pseudo-elements moved.
pub(super) fn child_impact(&self, node: StyleNodeID) -> ChildImpact {
let (Some(new), Some(old)) = (
self.cells.held(node.element_slot()),
@@ -1927,17 +1966,7 @@ impl<'a> Records<'a> {
if self.highlights_moved(node) {
return ChildImpact::All;
}
- let new = &new.record;
- if Arc::ptr_eq(new, old) {
- return ChildImpact::None;
- }
- // The children inherited the composition of the element's animations over the record it
- // held, where the host composed one, and the custom properties those sampled.
- let composition = self.state.computed_group_sets.composition_over_record(node, old);
- if self.sampled_custom_properties(node).is_some() {
- return ChildImpact::All;
- }
- ChildImpact::of_records(new, old, composition.map_or(&old.payloads, |view| view.payloads))
+ self.state.child_impact_of_records(node, &new.record, old)
}
/// Whether the records this pass computed for the highlight pseudo-elements of `node` hold
@@ -1949,19 +1978,7 @@ impl<'a> Records<'a> {
let old = self
.previous
.map_or(&[][..], |previous| previous.pseudo_element_records(node));
- let of_kind = |records: &'_ [(u8, Arc<Record>)], kind: u8| {
- records
- .iter()
- .find(|(held, _)| *held == kind)
- .map(|(_, record)| record.clone())
- };
- super::HIGHLIGHT_KINDS
- .iter()
- .any(|&kind| match (of_kind(new, kind), of_kind(old, kind)) {
- (None, None) => false,
- (Some(new), Some(old)) => !Arc::ptr_eq(&new, &old) && !new.holds_the_same_as(&old),
- _ => true,
- })
+ highlights_moved(new, old)
}
pub(super) fn get(&self, node: StyleNodeID) -> Option<&'a Record> {
@@ -2273,7 +2290,7 @@ impl ContainerRecords for Records<'_> {
}
let record = self.get_shared(node)?;
if self.samples_custom_properties_of(node, record)
- && let Some(sampled) = self.sampled_custom_property_store(node)
+ && let Some(sampled) = self.state.sampled_custom_property_store(node)
{
return Some(sampled.map(|store| &**store));
}