Truly independent web browser
LibWeb: Forget a last successful position option on style changes
Aliaksandr Kalenik472d67810ef0
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rsindex c7185a3b551..33be799c0ce 100644--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs@@ -1312,6 +1312,50 @@ pub(crate) fn style_payloads_layout_inputs_equal(})}+/// https://drafts.csswg.org/css-anchor-position-1/#fallback-sensitive+pub(crate) fn style_payloads_position_fallback_inputs_equal(+ a: crate::css::computed_value_views::ComputedValuesView<'_>,+ b: crate::css::computed_value_views::ComputedValuesView<'_>,+) -> bool {+ if a.position() != b.position() {+ return false;+ }+ let (a, b) = (&a.record_groups().0, &b.record_groups().0);+ /// # Safety+ /// `T` must be the payload type of the group at `group`.+ unsafe fn payloads_of_group<'a, T>(a: &'a StyleGroups, b: &'a StyleGroups, group: usize) -> (&'a T, &'a T) {+ // SAFETY: Each style holds a live payload of each group, of the type the caller names.+ unsafe { (payload_ref::<T>(a[group].as_ptr()), payload_ref::<T>(b[group].as_ptr())) }+ }+ // SAFETY: Each group is read as its own payload type.+ let (surround_a, surround_b) = unsafe { payloads_of_group::<SurroundValues>(a, b, group_index::SURROUND) };+ // SAFETY: As above.+ let (sizing_a, sizing_b) = unsafe { payloads_of_group::<SizingValues>(a, b, group_index::SIZING) };+ // SAFETY: As above.+ let (alignment_a, alignment_b) = unsafe { payloads_of_group::<AlignmentValues>(a, b, group_index::ALIGNMENT) };+ // SAFETY: As above.+ let (anchor_a, anchor_b) = unsafe { payloads_of_group::<AnchorValues>(a, b, group_index::ANCHOR) };+ surround_a.inset == surround_b.inset+ && surround_a.top_anchor_inset == surround_b.top_anchor_inset+ && surround_a.right_anchor_inset == surround_b.right_anchor_inset+ && surround_a.bottom_anchor_inset == surround_b.bottom_anchor_inset+ && surround_a.left_anchor_inset == surround_b.left_anchor_inset+ && surround_a.position_anchor == surround_b.position_anchor+ && surround_a.margin == surround_b.margin+ && sizing_a == sizing_b+ && alignment_a.align_self == alignment_b.align_self+ && alignment_a.align_self_is_last_baseline == alignment_b.align_self_is_last_baseline+ && alignment_a.align_self_overflow == alignment_b.align_self_overflow+ && alignment_a.justify_self == alignment_b.justify_self+ && alignment_a.justify_self_overflow == alignment_b.justify_self_overflow+ && anchor_a.position_anchor_type == anchor_b.position_anchor_type+ && anchor_a.position_anchor_name == anchor_b.position_anchor_name+ && anchor_a.position_area == anchor_b.position_area+ && anchor_a.position_try_fallbacks == anchor_b.position_try_fallbacks+ && anchor_a.has_position_try_order == anchor_b.has_position_try_order+ && anchor_a.position_try_order == anchor_b.position_try_order+}+/// Whether `a` and `b` hold equal payloads in each group `compares` answers true for.pub(crate) fn style_groups_equal_in(a: crate::css::computed_value_views::ComputedValuesView<'_>,diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 60b8ed563a8..4eedf92c73a 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3546,17 +3546,14 @@ impl<'pass> AbsposEngine<'pass> {// 1. Let current styles be the current used styles of abspos, as derived from the computed base style (which// might be the result of earlier fallback).- // NB: A box whose base styles, or the @position-try rule of its last successful position option, changed has- // no last successful position option.+ // NB: A box whose @position-try rule of its last successful position option changed has no last successful+ // position option.let last_successful_option = arena.last_successful_position_option(node).filter(|choice| {- choice.base_style_record == base_style_record- && entry_of(choice.option)- .map_or(crate::css::style::position_try::PositionTryRuleID::NONE, |(_, rule)| {- rule- })- == choice.rule+ entry_of(choice.option).map_or(crate::css::style::position_try::PositionTryRuleID::NONE, |(_, rule)| {+ rule+ }) == choice.rule}).map_or(0, |choice| choice.option);let current = options@@ -3566,7 +3563,6 @@ impl<'pass> AbsposEngine<'pass> {.expect("the base styles are a position option");let choice_of = |option: u32| abspos_inputs::PositionOptionChoice {option,- base_style_record,rule: entry_of(option).map_or(crate::css::style::position_try::PositionTryRuleID::NONE, |(_, rule)| {rule}),diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs b/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rsindex db4a86713a2..64ddce60412 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs@@ -165,14 +165,12 @@ pub(crate) struct DefaultScrollShift {pub(crate) compensates_for_vertical_scroll: bool,}-/// The position option a box was laid out with: an entry of its position options list, which was made of the base-/// styles of one style record.+/// The position option a box was laid out with: an entry of its position options list./// https://drafts.csswg.org/css-anchor-position-1/#last-successful-position-option#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct PositionOptionChoice {/// 0 for the base styles, or one more than the index of the position-try-fallbacks entry that made the option.pub(crate) option: u32,- pub(crate) base_style_record: u64,/// The @position-try rule the entry names./// NB: A choice whose rule was replaced since is no longer the box's last successful position option.pub(crate) rule: crate::css::style::position_try::PositionTryRuleID,diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex d3a0bfda061..b62f0bc05c0 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -2329,11 +2329,41 @@ impl LayoutNodeArena {}self.publish_new_size_container_geometry(slot);self.enroll_node_for_svg_paint_resources_sync(slot);- if previous_payloads.is_some_and(|previous| !self.style_move_keeps_layout_inputs(slot, previous, payloads)) {+ let Some(previous_payloads) = previous_payloads else {+ return;+ };+ self.forget_last_successful_position_option_after_fallback_sensitive_change(slot, previous_payloads, payloads);+ if !self.style_move_keeps_layout_inputs(slot, previous_payloads, payloads) {self.invalidate_fragments_and_intrinsic_sizes_of_self_and_ancestors(slot);}}+ /// https://drafts.csswg.org/css-anchor-position-1/#last-successful-position-option+ fn forget_last_successful_position_option_after_fallback_sensitive_change(+ &mut self,+ slot: NodeSlotId,+ previous: Option<LayoutStyleRef>,+ new: Option<LayoutStyleRef>,+ ) {+ if previous == new+ || self.last_successful_position_options.is_empty()+ || !self.last_successful_position_options.contains_key(&slot)+ {+ return;+ }+ let made_fallback_sensitive_change = match (previous, new) {+ (Some(previous), Some(new)) => {+ // SAFETY: A row's style is that of the record pinned for it.+ let (previous, new) = unsafe { (previous.view(), new.view()) };+ !crate::css::computed_values::style_payloads_position_fallback_inputs_equal(previous, new)+ }+ _ => true,+ };+ if made_fallback_sensitive_change {+ self.last_successful_position_options.remove(&slot);+ }+ }+pub(crate) fn install_style_record_in_place_of_derived_style(&mut self,slot: NodeSlotId,