use std::fmt::Debug;
use malloc_size_of_derive::MallocSizeOf;
use style::selector_parser::PseudoElement;
#[derive(Clone, Copy, Debug, Default, Eq, Hash, MallocSizeOf, PartialEq)]
pub struct PseudoElementChain {
pub primary: Option<PseudoElement>,
pub secondary: Option<PseudoElement>,
}
impl PseudoElementChain {
pub fn unnested(pseudo_element: PseudoElement) -> Self {
Self {
primary: Some(pseudo_element),
secondary: None,
}
}
pub fn innermost(&self) -> Option<PseudoElement> {
self.secondary.or(self.primary)
}
pub fn with_pseudo(&self, pseudo_element: PseudoElement) -> Self {
match self.primary {
Some(primary) if primary.is_before_or_after() => Self {
primary: self.primary,
secondary: Some(pseudo_element),
},
_ => {
assert!(self.secondary.is_none());
Self::unnested(pseudo_element)
},
}
}
pub fn without_innermost(&self) -> Option<Self> {
let primary = self.primary?;
Some(
self.secondary
.map_or_else(Self::default, |_| Self::unnested(primary)),
)
}
pub fn is_empty(&self) -> bool {
self.primary.is_none()
}
}