mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Refactor the selector parser to make implementing ::part() easier.
::slotted() is already weird in the sense that it supports a pseudo-element afterwards (so ::slotted(*)::before is valid for example). ::part() is weirder because you are supposed to allow stuff like ::part(foo):hover, ::part(foo):hover::before, etc. In order to avoid making the already-complex parse_compound_selector more complex, shuffle stuff so that we pass the progress of our current compound selector around, and is the parsing code for each selector which decides whether it's ok to parse at the given point. Differential Revision: https://phabricator.services.mozilla.com/D27158
This commit is contained in:
parent
498a163cdf
commit
09d497db3d
3 changed files with 191 additions and 193 deletions
|
@ -184,16 +184,6 @@ impl NonTSPseudoClass {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/selectors-4/#useraction-pseudos>
|
||||
///
|
||||
/// We intentionally skip the link-related ones.
|
||||
pub fn is_safe_user_action_state(&self) -> bool {
|
||||
matches!(
|
||||
*self,
|
||||
NonTSPseudoClass::Hover | NonTSPseudoClass::Active | NonTSPseudoClass::Focus
|
||||
)
|
||||
}
|
||||
|
||||
/// Get the state flag associated with a pseudo-class, if any.
|
||||
pub fn state_flag(&self) -> ElementState {
|
||||
macro_rules! flag {
|
||||
|
@ -279,6 +269,15 @@ impl ::selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
|
|||
fn is_active_or_hover(&self) -> bool {
|
||||
matches!(*self, NonTSPseudoClass::Active | NonTSPseudoClass::Hover)
|
||||
}
|
||||
|
||||
/// We intentionally skip the link-related ones.
|
||||
#[inline]
|
||||
fn is_user_action_state(&self) -> bool {
|
||||
matches!(
|
||||
*self,
|
||||
NonTSPseudoClass::Hover | NonTSPseudoClass::Active | NonTSPseudoClass::Focus
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The dummy struct we use to implement our selector parsing.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue