mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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>
This commit is contained in:
parent
c30ad5a30e
commit
b5c8164e99
15 changed files with 278 additions and 354 deletions
|
@ -14,6 +14,7 @@ use script_layout_interface::wrapper_traits::{
|
|||
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
||||
};
|
||||
use script_layout_interface::{LayoutNodeType, StyleData};
|
||||
use selectors::Element as _;
|
||||
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::bloom::{BLOOM_HASH_MASK, BloomFilter};
|
||||
use selectors::matching::{ElementSelectorFlags, MatchingContext, VisitedHandlingMode};
|
||||
|
@ -805,11 +806,35 @@ impl<'dom> ThreadSafeLayoutElement<'dom> for ServoThreadSafeLayoutElement<'dom>
|
|||
self.pseudo
|
||||
}
|
||||
|
||||
fn with_pseudo(&self, pseudo: PseudoElement) -> Self {
|
||||
ServoThreadSafeLayoutElement {
|
||||
element: self.element,
|
||||
pseudo: Some(pseudo),
|
||||
fn with_pseudo(&self, pseudo_element_type: PseudoElement) -> Option<Self> {
|
||||
if pseudo_element_type.is_eager() &&
|
||||
self.style_data()
|
||||
.styles
|
||||
.pseudos
|
||||
.get(&pseudo_element_type)
|
||||
.is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if pseudo_element_type == PseudoElement::DetailsSummary &&
|
||||
(!self.has_local_name(&local_name!("details")) || !self.has_namespace(&ns!(html)))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if pseudo_element_type == PseudoElement::DetailsContent &&
|
||||
(!self.has_local_name(&local_name!("details")) ||
|
||||
!self.has_namespace(&ns!(html)) ||
|
||||
self.get_attr(&ns!(), &local_name!("open")).is_none())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(ServoThreadSafeLayoutElement {
|
||||
element: self.element,
|
||||
pseudo: Some(pseudo_element_type),
|
||||
})
|
||||
}
|
||||
|
||||
fn type_id(&self) -> Option<LayoutNodeType> {
|
||||
|
|
|
@ -436,8 +436,8 @@ impl<'dom> ServoThreadSafeLayoutNodeChildrenIterator<'dom> {
|
|||
pub fn new(parent: ServoThreadSafeLayoutNode<'dom>) -> Self {
|
||||
let first_child = match parent.pseudo_element() {
|
||||
None => parent
|
||||
.get_pseudo(PseudoElement::Before)
|
||||
.or_else(|| parent.get_details_summary_pseudo())
|
||||
.with_pseudo(PseudoElement::Before)
|
||||
.or_else(|| parent.with_pseudo(PseudoElement::DetailsSummary))
|
||||
.or_else(|| unsafe { parent.dangerous_first_child() }),
|
||||
Some(PseudoElement::DetailsContent) | Some(PseudoElement::DetailsSummary) => unsafe {
|
||||
parent.dangerous_first_child()
|
||||
|
@ -503,18 +503,18 @@ impl<'dom> Iterator for ServoThreadSafeLayoutNodeChildrenIterator<'dom> {
|
|||
self.current_node = match node.pseudo_element() {
|
||||
Some(PseudoElement::Before) => self
|
||||
.parent_node
|
||||
.get_details_summary_pseudo()
|
||||
.with_pseudo(PseudoElement::DetailsSummary)
|
||||
.or_else(|| unsafe { self.parent_node.dangerous_first_child() })
|
||||
.or_else(|| self.parent_node.get_pseudo(PseudoElement::After)),
|
||||
.or_else(|| self.parent_node.with_pseudo(PseudoElement::After)),
|
||||
Some(PseudoElement::DetailsSummary) => {
|
||||
self.parent_node.get_details_content_pseudo()
|
||||
self.parent_node.with_pseudo(PseudoElement::DetailsContent)
|
||||
},
|
||||
Some(PseudoElement::DetailsContent) => {
|
||||
self.parent_node.get_pseudo(PseudoElement::After)
|
||||
self.parent_node.with_pseudo(PseudoElement::After)
|
||||
},
|
||||
Some(PseudoElement::After) => None,
|
||||
None | Some(_) => unsafe { node.dangerous_next_sibling() }
|
||||
.or_else(|| self.parent_node.get_pseudo(PseudoElement::After)),
|
||||
.or_else(|| self.parent_node.with_pseudo(PseudoElement::After)),
|
||||
};
|
||||
}
|
||||
node
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue