diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-03-29 13:41:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-29 12:41:04 +0000 |
commit | b5c8164e9982ebd6212ad21910826ce8b2631930 (patch) | |
tree | 91359e4206965cc592f53bf8ee86f030c0e67fe0 /components/layout_2020/dom.rs | |
parent | c30ad5a30e10b9aabe5842624db24b9846c3d5d4 (diff) | |
download | servo-b5c8164e9982ebd6212ad21910826ce8b2631930.tar.gz servo-b5c8164e9982ebd6212ad21910826ce8b2631930.zip |
layout: Simplify and generalize the usage of pseudo-elements (#36202)
- Remove the last remaining Servo-specific PseudoElement enum from
layout. This was made to select `::before` and `::after` (both eager
pseudo-elements), but now `traverse_pseudo_element` is called
`traverse_eager_pseudo_element` and should work on any eager pseudo
element.
- Expose a single way of getting psuedo-element variants of
ThreadSafeLayoutElement in the Layout DOM, which returns `None` when
the pseudo-element doesn't apply (not defined for eager
pseudo-elements or when trying to get `<details>` related
pseudo-elements on elements that they don't apply to).
- Ensure that NodeAndStyleInfo always refers to a node. This is done by
making sure that anonymous boxes are all associated with their
originating node.
These changes are prepatory work for implementation of the `::marker`
pseudo-element as well as ensuring that all anonymous boxes can be
cached into the box tree eventually.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/layout_2020/dom.rs')
-rw-r--r-- | components/layout_2020/dom.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/components/layout_2020/dom.rs b/components/layout_2020/dom.rs index b0323a4e56b..f8b3d6f9c29 100644 --- a/components/layout_2020/dom.rs +++ b/components/layout_2020/dom.rs @@ -17,10 +17,10 @@ use script_layout_interface::{ }; use servo_arc::Arc as ServoArc; use style::properties::ComputedValues; +use style::selector_parser::PseudoElement; use crate::cell::ArcRefCell; use crate::context::LayoutContext; -use crate::dom_traversal::WhichPseudoElement; use crate::flexbox::FlexLevelBox; use crate::flow::BlockLevelBox; use crate::flow::inline::InlineItem; @@ -108,8 +108,8 @@ pub(crate) trait NodeExt<'dom>: 'dom + LayoutNode<'dom> { fn layout_data_mut(self) -> AtomicRefMut<'dom, InnerDOMLayoutData>; fn layout_data(self) -> Option<AtomicRef<'dom, InnerDOMLayoutData>>; fn element_box_slot(&self) -> BoxSlot<'dom>; - fn pseudo_element_box_slot(&self, which: WhichPseudoElement) -> BoxSlot<'dom>; - fn unset_pseudo_element_box(self, which: WhichPseudoElement); + fn pseudo_element_box_slot(&self, which: PseudoElement) -> BoxSlot<'dom>; + fn unset_pseudo_element_box(self, which: PseudoElement); /// Remove boxes for the element itself, and its `:before` and `:after` if any. fn unset_all_boxes(self); @@ -217,20 +217,28 @@ where BoxSlot::new(self.layout_data_mut().self_box.clone()) } - fn pseudo_element_box_slot(&self, which: WhichPseudoElement) -> BoxSlot<'dom> { + fn pseudo_element_box_slot(&self, pseudo_element_type: PseudoElement) -> BoxSlot<'dom> { let data = self.layout_data_mut(); - let cell = match which { - WhichPseudoElement::Before => &data.pseudo_before_box, - WhichPseudoElement::After => &data.pseudo_after_box, + let cell = match pseudo_element_type { + PseudoElement::Before => &data.pseudo_before_box, + PseudoElement::After => &data.pseudo_after_box, + _ => unreachable!( + "Asked for box slot for unsupported pseudo-element: {:?}", + pseudo_element_type + ), }; BoxSlot::new(cell.clone()) } - fn unset_pseudo_element_box(self, which: WhichPseudoElement) { + fn unset_pseudo_element_box(self, pseudo_element_type: PseudoElement) { let data = self.layout_data_mut(); - let cell = match which { - WhichPseudoElement::Before => &data.pseudo_before_box, - WhichPseudoElement::After => &data.pseudo_after_box, + let cell = match pseudo_element_type { + PseudoElement::Before => &data.pseudo_before_box, + PseudoElement::After => &data.pseudo_after_box, + _ => unreachable!( + "Asked for box slot for unsupported pseudo-element: {:?}", + pseudo_element_type + ), }; *cell.borrow_mut() = None; } |