Skip to content

Commit 68aa48d

Browse files
committed
Allow more user action pseudo classes after -webkit-scrollbar
Fixes parcel-bundler/parcel#7885
1 parent 7c1db82 commit 68aa48d

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

selectors/parser.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ pub trait NonTSPseudoClass<'i>: Sized + ToCss {
5555
/// https://drafts.csswg.org/selectors-4/#useraction-pseudos
5656
fn is_user_action_state(&self) -> bool;
5757

58-
fn is_webkit_scrollbar_state(&self) -> bool {
58+
fn is_valid_before_webkit_scrollbar(&self) -> bool {
59+
false
60+
}
61+
62+
fn is_valid_after_webkit_scrollbar(&self) -> bool {
5963
false
6064
}
6165

@@ -2591,14 +2595,14 @@ where
25912595

25922596
let pseudo_class = P::parse_non_ts_pseudo_class(parser, location, name)?;
25932597
if state.intersects(SelectorParsingState::AFTER_WEBKIT_SCROLLBAR) {
2594-
if !pseudo_class.is_webkit_scrollbar_state() {
2598+
if !pseudo_class.is_valid_after_webkit_scrollbar() {
25952599
return Err(location.new_custom_error(SelectorParseErrorKind::InvalidPseudoClassAfterWebKitScrollbar));
25962600
}
25972601
} else if state.intersects(SelectorParsingState::AFTER_PSEUDO_ELEMENT) {
25982602
if !pseudo_class.is_user_action_state() {
25992603
return Err(location.new_custom_error(SelectorParseErrorKind::InvalidPseudoClassAfterPseudoElement));
26002604
}
2601-
} else if pseudo_class.is_webkit_scrollbar_state() {
2605+
} else if !pseudo_class.is_valid_before_webkit_scrollbar() {
26022606
return Err(location.new_custom_error(SelectorParseErrorKind::InvalidPseudoClassBeforeWebKitScrollbar));
26032607
}
26042608
Ok(Component::NonTSPseudoClass(pseudo_class))

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4565,6 +4565,10 @@ mod tests {
45654565
"-webkit-resizer",
45664566
] {
45674567
for class in [
4568+
"enabled",
4569+
"disabled",
4570+
"hover",
4571+
"active",
45684572
"horizontal",
45694573
"vertical",
45704574
"decrement",
@@ -4611,7 +4615,7 @@ mod tests {
46114615
"-webkit-resizer",
46124616
] {
46134617
error_test(
4614-
&format!("::{}:hover {{color:red}}", element),
4618+
&format!("::{}:focus {{color:red}}", element),
46154619
ParserError::SelectorError(SelectorError::InvalidPseudoClassAfterWebKitScrollbar),
46164620
);
46174621
}

src/selector.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,30 @@ impl<'i> parcel_selectors::parser::NonTSPseudoClass<'i> for PseudoClass<'i> {
403403
}
404404

405405
fn is_user_action_state(&self) -> bool {
406-
matches!(*self, PseudoClass::Active | PseudoClass::Hover | PseudoClass::Focus)
406+
matches!(
407+
*self,
408+
PseudoClass::Active
409+
| PseudoClass::Hover
410+
| PseudoClass::Focus
411+
| PseudoClass::FocusWithin
412+
| PseudoClass::FocusVisible
413+
)
414+
}
415+
416+
fn is_valid_before_webkit_scrollbar(&self) -> bool {
417+
!matches!(*self, PseudoClass::WebKitScrollbar(..))
407418
}
408419

409-
fn is_webkit_scrollbar_state(&self) -> bool {
410-
matches!(*self, PseudoClass::WebKitScrollbar(..))
420+
fn is_valid_after_webkit_scrollbar(&self) -> bool {
421+
// https://github.com/WebKit/WebKit/blob/02fbf9b7aa435edb96cbf563a8d4dcf1aa73b4b3/Source/WebCore/css/parser/CSSSelectorParser.cpp#L285
422+
matches!(
423+
*self,
424+
PseudoClass::WebKitScrollbar(..)
425+
| PseudoClass::Enabled
426+
| PseudoClass::Disabled
427+
| PseudoClass::Hover
428+
| PseudoClass::Active
429+
)
411430
}
412431
}
413432

0 commit comments

Comments
 (0)