diff --git a/components/style/element_state.rs b/components/style/element_state.rs index 8165c73ef14..cf943cc3c4e 100644 --- a/components/style/element_state.rs +++ b/components/style/element_state.rs @@ -137,6 +137,10 @@ bitflags! { const IN_AUTOFILL_STATE = 1 << 50; /// Non-standard & undocumented. const IN_AUTOFILL_PREVIEW_STATE = 1 << 51; + /// :focus-visible + /// + /// https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo + const IN_FOCUS_VISIBLE_STATE = 1 << 52; } } diff --git a/components/style/gecko/non_ts_pseudo_class_list.rs b/components/style/gecko/non_ts_pseudo_class_list.rs index 8d9fc3d2d85..f8f23e1bfe0 100644 --- a/components/style/gecko/non_ts_pseudo_class_list.rs +++ b/components/style/gecko/non_ts_pseudo_class_list.rs @@ -42,6 +42,7 @@ macro_rules! apply_non_ts_list { ("enabled", Enabled, enabled, IN_ENABLED_STATE, _), ("focus", Focus, focus, IN_FOCUS_STATE, _), ("focus-within", FocusWithin, focusWithin, IN_FOCUS_WITHIN_STATE, _), + ("focus-visible", FocusVisible, focusVisible, IN_FOCUS_VISIBLE_STATE, _), ("hover", Hover, hover, IN_HOVER_STATE, _), ("-moz-drag-over", MozDragOver, mozDragOver, IN_DRAGOVER_STATE, _), ("target", Target, target, IN_TARGET_STATE, _), diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 9f5b49c5c13..96d7fcb5790 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -172,6 +172,9 @@ impl NonTSPseudoClass { /// Returns whether the pseudo-class is enabled in content sheets. #[inline] fn is_enabled_in_content(&self) -> bool { + if matches!(*self, NonTSPseudoClass::FocusVisible) { + return static_prefs::pref!("layout.css.focus-visible.enabled") + } !self.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME) } diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 2b842e72d9b..7071c818579 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -2064,6 +2064,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { NonTSPseudoClass::MozReadOnly | NonTSPseudoClass::MozReadWrite | NonTSPseudoClass::FocusWithin | + NonTSPseudoClass::FocusVisible | NonTSPseudoClass::MozDragOver | NonTSPseudoClass::MozDevtoolsHighlighted | NonTSPseudoClass::MozStyleeditorTransitioning |