Skip to content

Truly independent web browser

LibWeb: Keep a hover seal's disabled elements beside the written rows

Andreas Klingac285161e1a6
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/pending_inputs.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/pending_inputs.rs
index 90546541c0c..68e9b9cb34c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/pending_inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/pending_inputs.rs
@@ -33,8 +33,6 @@ pub(in crate::css::style) struct HoverSealMemo {
struct HoverSealCandidates {
projection: ProjectionGeneration,
invalidation: Option<Arc<InvalidationMap>>,
- /// The elements whose written facts say they are disabled.
- disabled: FastSet<StyleNodeID>,
hover_keyed: HoverKeyedElements,
}
@@ -235,7 +233,7 @@ impl StyleEngine {
let tree = self.tree();
let under_root =
|node: &StyleNodeID| tree.is_live(*node) && projection.is_in_shadow_including_subtree_of(*node, root);
- candidates.disabled.iter().any(under_root)
+ projection.written_disabled().iter().any(under_root)
|| match &candidates.hover_keyed {
HoverKeyedElements::Every => true,
HoverKeyedElements::Carrying(elements) => elements.iter().any(under_root),
@@ -259,7 +257,6 @@ impl StyleEngine {
HoverSealCandidates {
projection: generation.clone(),
invalidation: None,
- disabled: FastSet::default(),
hover_keyed: HoverKeyedElements::Every,
},
true,
@@ -268,25 +265,6 @@ impl StyleEngine {
let projection = &self.retained.projection;
let every_slot: Vec<_> = std::iter::once(0..projection.element_slot_count()).collect();
let element_at = |slot: usize| StyleNodeID::element(u32::try_from(slot).expect("element slot exceeds u32"));
- let disabled_slots = match first_read {
- true => every_slot.clone(),
- false => generation.written_slots_changed_since(&candidates.projection),
- };
- for node in disabled_slots
- .into_iter()
- .flatten()
- .filter(|&slot| slot != 0)
- .map(element_at)
- {
- if projection
- .written_facts(node)
- .is_some_and(|facts| facts.states().contains(StateFact::Disabled))
- {
- candidates.disabled.insert(node);
- } else {
- candidates.disabled.remove(&node);
- }
- }
let hover = Trigger::State(StateFact::Hover);
candidates.hover_keyed = match self.current_invalidation() {
Some((live, map)) if map.queries_testing(&hover).next().is_none() => {
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
index 1824c7c44b7..2502a859f8c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
@@ -607,11 +607,6 @@ impl ProjectionGeneration {
Some(host.unwrap_or(parent))
}
- /// The element slots whose written rows may differ between `older` and this generation.
- pub(in crate::css::style) fn written_slots_changed_since(&self, older: &Self) -> Vec<std::ops::Range<usize>> {
- self.rows.changed_rows_since(&older.rows)
- }
-
/// The element slots whose committed rows may differ between `older` and this generation.
pub(in crate::css::style) fn committed_slots_changed_since(&self, older: &Self) -> Vec<std::ops::Range<usize>> {
self.committed.changed_rows_since(&older.committed)
@@ -691,6 +686,8 @@ pub(in crate::css::style) struct Projection {
host_fact_sets: Arc<HostFactSets>,
/// A slotted text node's slot. Text nodes have no rows, and a slotted one is rare.
text_assigned_slots: Arc<HashMap<StyleNodeID, StyleNodeID>>,
+ /// The elements whose facts say they are disabled, as the host last published them.
+ disabled: Arc<HashSet<StyleNodeID>>,
/// The elements whose rows the host's publications wrote since the last barrier.
written: WrittenRows,
/// Each write since the last barrier, which whether a written row changes the committed
@@ -816,6 +813,7 @@ impl Projection {
bytes += texts.values().map(|text| size_of_val::<[u16]>(text)).sum::<usize>();
}
bytes += sizer.arc_shallow(&self.text_assigned_slots) + map_bytes(&self.text_assigned_slots);
+ bytes += sizer.arc_shallow(&self.disabled) + crate::heap_size::set_bytes(&self.disabled);
if sizer.arc_shallow(&self.structural_flags) != 0 {
bytes += crate::heap_size::ARC_HEADER_BYTES
+ size_of::<StructuralFlagsColumn>()
@@ -1157,6 +1155,7 @@ impl Projection {
catalogs,
host_fact_sets,
text_assigned_slots,
+ disabled,
written,
links_written,
relations_written,
@@ -1171,6 +1170,7 @@ impl Projection {
self.catalogs = catalogs;
self.host_fact_sets = host_fact_sets;
self.text_assigned_slots = text_assigned_slots;
+ self.disabled = disabled;
for node in written {
self.note_written(node, node.element_slot());
self.pending_change_scan.writes.push(node);
@@ -1208,6 +1208,12 @@ impl Projection {
// -- Reads ---------------------------------------------------------------------------------
+ /// The elements whose facts as written say they are disabled.
+ #[must_use]
+ pub(in crate::css::style) fn written_disabled(&self) -> &HashSet<StyleNodeID> {
+ &self.disabled
+ }
+
/// One past the greatest element slot the projection holds a row for.
#[must_use]
pub(in crate::css::style) fn element_slot_count(&self) -> usize {
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection/writer.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection/writer.rs
index ed00878e10d..de8cfaedc03 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection/writer.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection/writer.rs
@@ -14,6 +14,7 @@
//! published before keep its facts, which is where the render owner reads what a departed element carried.
use super::super::super::fast_hash::FastMap as HashMap;
+use super::super::super::fast_hash::FastSet as HashSet;
use super::super::super::index::AttributeFact;
use super::super::super::index::AttributeNameForms;
use super::super::super::index::StyleAtomID;
@@ -75,6 +76,8 @@ pub(in crate::css::style) struct ProjectionWriter {
recent_lists: RecentFactLists,
/// A slotted text node's slot. Text nodes have no rows, and a slotted one is rare.
text_assigned_slots: Arc<HashMap<StyleNodeID, StyleNodeID>>,
+ /// The elements whose facts say they are disabled, which only the writes of their states and their departures move.
+ disabled: Arc<HashSet<StyleNodeID>>,
/// The elements whose rows were written since the last publication.
written: WrittenRows,
/// Of those, the elements whose links were written.
@@ -101,6 +104,7 @@ pub(in crate::css::style) struct ProjectionPublication {
pub(super) catalogs: Catalogs,
pub(super) host_fact_sets: Arc<HostFactSets>,
pub(super) text_assigned_slots: Arc<HashMap<StyleNodeID, StyleNodeID>>,
+ pub(super) disabled: Arc<HashSet<StyleNodeID>>,
pub(super) written: Vec<StyleNodeID>,
pub(super) links_written: Vec<StyleNodeID>,
pub(super) relations_written: Vec<StyleNodeID>,
@@ -146,6 +150,7 @@ impl ProjectionWriter {
bytes += texts.values().map(|text| size_of_val::<[u16]>(text)).sum::<usize>();
}
bytes += sizer.arc_shallow(&self.text_assigned_slots) + map_bytes(&self.text_assigned_slots);
+ bytes += sizer.arc_shallow(&self.disabled) + crate::heap_size::set_bytes(&self.disabled);
bytes += [&self.written, &self.links_written, &self.relations_written]
.iter()
.map(|rows| rows.heap_size())
@@ -179,6 +184,7 @@ impl ProjectionWriter {
// NB: Nothing routes from a departed element's facts but the generations published before, which keep them.
for &node in &departed {
self.retire(node);
+ self.note_disabled(node, false);
if let Some(mut row) = self.rows.row_mut(node.element_slot()) {
row.facts = row.facts.forgotten();
}
@@ -201,6 +207,7 @@ impl ProjectionWriter {
catalogs: self.catalogs.clone(),
host_fact_sets: Arc::clone(&self.host_fact_sets),
text_assigned_slots: Arc::clone(&self.text_assigned_slots),
+ disabled: Arc::clone(&self.disabled),
written: self.written.take(),
links_written: self.links_written.take(),
relations_written: self.relations_written.take(),
@@ -229,6 +236,19 @@ impl ProjectionWriter {
self.links_written.insert(node, node.element_slot());
}
+ /// Note whether the facts of `node` say it is disabled.
+ fn note_disabled(&mut self, node: StyleNodeID, disabled: bool) {
+ if self.disabled.contains(&node) == disabled {
+ return;
+ }
+ let elements = Arc::make_mut(&mut self.disabled);
+ if disabled {
+ elements.insert(node);
+ } else {
+ elements.remove(&node);
+ }
+ }
+
/// The element's facts as written, or none where nothing was written of it.
#[must_use]
pub(in crate::css::style) fn written_facts(&self, node: StyleNodeID) -> Option<&ElementFacts> {
@@ -445,6 +465,7 @@ impl ProjectionWriter {
/// They leave what style reads when the transaction is released.
pub(in crate::css::style) fn forget(&mut self, node: StyleNodeID) {
if self.row(node).is_some_and(|row| row.facts.resident()) {
+ self.note_disabled(node, false);
self.edit(node, |row| row.facts = row.facts.forgotten());
}
}
@@ -480,6 +501,9 @@ impl ProjectionWriter {
}
pub(in crate::css::style) fn set_state(&mut self, node: StyleNodeID, fact: StateFact, value: bool) {
+ if fact == StateFact::Disabled {
+ self.note_disabled(node, value);
+ }
self.edit_facts(node, |facts| match value {
true => facts.states.insert(fact),
false => facts.states.remove(fact),
@@ -627,6 +651,9 @@ impl ProjectionWriter {
false => arrival.folded_tag,
};
let lists = Self::make_lists(&mut self.recent_lists, &self.catalogs.name_forms, lists);
+ if arrival.states.contains(StateFact::Disabled) {
+ self.note_disabled(node, true);
+ }
self.edit_facts(node, |facts| {
facts.tag = arrival.tag;
facts.set_flag(ElementFacts::IS_SLOT, arrival.is_slot);
diff --git a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-document-by-owner.txt b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-document-by-owner.txt
index 9d0a23e26c4..855d2a453b6 100644
--- a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-document-by-owner.txt
+++ b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-document-by-owner.txt
@@ -13,7 +13,7 @@ customProperties: within 0
retainedSlots: within 540
recordCells: within 112
installed: within 1320
-projection: within 5216
+projection: within 5408
hostTree: within 4672
elementDeclarations: within 16
heldRecordMaps: within 1168
diff --git a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-document-by-owner.html b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-document-by-owner.html
index 1b96db04245..1efd51b7ce5 100644
--- a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-document-by-owner.html
+++ b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-document-by-owner.html
@@ -30,7 +30,7 @@
retainedSlots: 540,
recordCells: 112,
installed: 1320,
- projection: 5216,
+ projection: 5408,
hostTree: 4672,
elementDeclarations: 16,
heldRecordMaps: 1168,