Skip to content

Truly independent web browser

LibWeb: Decline read-only hover frames over animation overlay records

Andreas Klingb1ed9fda8b45
diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rs
index a79a73088e1..52e05fdc0a9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs
@@ -913,7 +913,7 @@ pub struct ComputedGroupSets {
style_record_column: Vec<Option<StyleRecordID>>,
base_style_record_pins: HashMap<StyleRecordID, u64>,
/// Long-lived immutable readers pin only the base records they actually read. Expired readers leave weak entries
- /// that the next publication removes, so they neither block reclamation nor need to call back into the owner.
+ /// that the next lease removes, so they neither block reclamation nor need to call back into the owner.
selected_style_record_leases: std::sync::Arc<std::sync::Mutex<Vec<std::sync::Weak<[u64]>>>>,
columns: PublishedComputedColumns,
// Recyclable animation overlays are deliberately separate from the permanent base records
@@ -1014,12 +1014,14 @@ impl ComputedGroupSets {
.collect()
}
- pub(crate) fn lease_selected_style_records(&self, records: Vec<u64>) -> std::sync::Arc<[u64]> {
+ /// Leases `records` to an immutable hover frame, or answers none where one of them is an animation overlay record,
+ /// whose payloads such a lease does not keep.
+ pub(crate) fn lease_selected_style_records(&self, records: Vec<u64>) -> Option<std::sync::Arc<[u64]>> {
for &raw_record in &records {
let record = FinalStyleRecordID(raw_record);
- let base = record
- .base_record()
- .expect("an immutable hover frame reads only base records");
+ // NB: A row can name an overlay record no element is assigned anymore, such as the row of a removed
+ // element, which pins its record until the rebuild of its parent frees it.
+ let base = record.base_record()?;
assert!(self.style_record_generation_is_live(base, record.base_generation()));
}
let records: std::sync::Arc<[u64]> = records.into();
@@ -1029,7 +1031,7 @@ impl ComputedGroupSets {
.expect("selected style-record leases");
leases.retain(|lease| lease.strong_count() != 0);
leases.push(std::sync::Arc::downgrade(&records));
- records
+ Some(records)
}
fn style_records_are_leased(&self) -> bool {
@@ -4659,6 +4661,39 @@ mod tests {
assert_eq!(sets.node_pseudo_style_mask(node), None);
}
+ #[test]
+ fn a_selected_record_lease_declines_the_overlay_record_of_a_removed_element() {
+ let mut sets = ComputedGroupSets::default();
+ let node = StyleNodeID::from_raw(1).unwrap();
+ let animated_overlay = crate::css::animated_overlay::AnimatedOverlay::default();
+ let mut overlay_metadata = metadata(0, 0, 0);
+ overlay_metadata.animation_overlay_identity = 1;
+ overlay_metadata.animated_overlay = HostShared::new(std::ptr::from_ref(&animated_overlay));
+ let overlay = sets
+ .publish_unowned(
+ Some(ComputedStyleTarget::new(node, u8::MAX)),
+ &[],
+ 0,
+ 0,
+ overlay_metadata,
+ )
+ .style_record_identity;
+ let base = sets
+ .publish_unowned(None, &[], 0, 0, metadata(1, 0, 0))
+ .style_record_identity;
+ // The row of the removed element pins its record until the rebuild of its parent frees the row.
+ sets.pin_style_record(overlay.raw());
+ sets.remove(node);
+ assert_eq!(sets.live_animation_overlay_records(), 0);
+ assert_eq!(sets.retired_animation_overlay_records(), 0);
+ assert!(
+ sets.lease_selected_style_records(vec![base.raw(), overlay.raw()])
+ .is_none()
+ );
+ assert!(sets.lease_selected_style_records(vec![base.raw()]).is_some());
+ sets.unpin_style_record(overlay.raw());
+ }
+
#[test]
fn a_selected_record_lease_allows_other_records_to_be_reclaimed() {
let mut sets = ComputedGroupSets::default();
@@ -4668,7 +4703,7 @@ mod tests {
let discarded = sets
.publish_unowned(None, &[], 0, 0, metadata(2, 0, 0))
.style_record_identity;
- let lease = sets.lease_selected_style_records(vec![kept.raw()]);
+ let lease = sets.lease_selected_style_records(vec![kept.raw()]).unwrap();
let mut fork = sets.clone();
sets.reclaim_unreachable();
fork.reclaim_unreachable();
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index 65a0bef47d8..6ba659fa3bb 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -4014,7 +4014,7 @@ impl RetainedState {
|| self.computed_group_sets.retired_animation_overlay_records() != 0
}
- pub(crate) fn lease_selected_style_records(&self, records: Vec<u64>) -> std::sync::Arc<[u64]> {
+ pub(crate) fn lease_selected_style_records(&self, records: Vec<u64>) -> Option<std::sync::Arc<[u64]>> {
self.computed_group_sets.lease_selected_style_records(records)
}
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
index 1de3dac4678..2bce1e7fd45 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
@@ -203,13 +203,16 @@ impl HoverPlan {
// NB: Keep the frame's geometry and dispatch identities even when the host moves its boxes in the next task.
// Published rows share immutable columns instead of copying the mutable arena and style engine. The lease
// pins only these rows' records, leaving unrelated records reclaimable. Frames with animation overlays
- // use the regular lane above.
+ // use the regular lane above, and so do frames with a row that still names an overlay record no element
+ // is assigned, which the lease declines.
let visual_context = state.arena.arena().paint_state().borrow().visual_context.clone();
if visual_context.tree.is_none() {
return;
}
let records = state.arena.arena().hover_frame_style_records();
- let style_records = state.engine_ref().lease_selected_style_records(records);
+ let Some(style_records) = state.engine_ref().lease_selected_style_records(records) else {
+ return;
+ };
self.read_only_frame = Some(ReadOnlyHoverFrame {
rows: state.arena.arena_mut().publish_rows(),
bound_rows: state.arena.arena_mut().bound_rows_mut().publish(),