Skip to content

Commit

Permalink
style: Correctly style dark scrollbars in tree components.
Browse files Browse the repository at this point in the history
We need to ensure the rules that override all properties for scrollbar
part elements only apply to those that are NAC (and so will be eligible
for NAC style sharing).  We have some uses of non-NAC <scrollbar>
elements that should continue to inherit properties from their parents.

To avoid any changes in rule matching order that come with changing specificity,
we add a new :-moz-native-anonymous-no-specificity pseudo-class.

While we're here, we note :-moz-native-anonymous-no-specificity (and the
regular :-moz-native-anonymous pseudo-class) as not needing style
sharing cache revalidation, as we never share NAC styles.

Differential Revision: https://phabricator.services.mozilla.com/D56154
  • Loading branch information
heycam authored and emilio committed Dec 16, 2019
1 parent e944962 commit 6973317
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
10 changes: 7 additions & 3 deletions components/selectors/builder.rs
Expand Up @@ -17,7 +17,7 @@
//! is non-trivial. This module encapsulates those details and presents an
//! easy-to-use API for the parser.

use crate::parser::{Combinator, Component, SelectorImpl};
use crate::parser::{Combinator, Component, NonTSPseudoClass, SelectorImpl};
use crate::sink::Push;
use servo_arc::{Arc, HeaderWithLength, ThinArc};
use smallvec::{self, SmallVec};
Expand Down Expand Up @@ -322,9 +322,13 @@ where
Component::NthLastOfType(..) |
Component::FirstOfType |
Component::LastOfType |
Component::OnlyOfType |
Component::NonTSPseudoClass(..) => {
Component::OnlyOfType => {
specificity.class_like_selectors += 1;
}
Component::NonTSPseudoClass(ref pseudo) => {
if !pseudo.has_zero_specificity() {
specificity.class_like_selectors += 1;
}
},
Component::ExplicitUniversalType |
Component::ExplicitAnyNamespace |
Expand Down
8 changes: 8 additions & 0 deletions components/selectors/parser.rs
Expand Up @@ -52,6 +52,9 @@ pub trait NonTSPseudoClass: Sized + ToCss {
///
/// https://drafts.csswg.org/selectors-4/#useraction-pseudos
fn is_user_action_state(&self) -> bool;

/// Whether this pseudo-class has zero specificity.
fn has_zero_specificity(&self) -> bool;
}

/// Returns a Cow::Borrowed if `s` is already ASCII lowercase, and a
Expand Down Expand Up @@ -2336,6 +2339,11 @@ pub mod tests {
fn is_user_action_state(&self) -> bool {
self.is_active_or_hover()
}

#[inline]
fn has_zero_specificity(&self) -> bool {
false
}
}

impl ToCss for PseudoClass {
Expand Down
1 change: 1 addition & 0 deletions components/style/gecko/non_ts_pseudo_class_list.rs
Expand Up @@ -94,6 +94,7 @@ macro_rules! apply_non_ts_list {
("-moz-last-node", MozLastNode, lastNode, _, _),
("-moz-only-whitespace", MozOnlyWhitespace, mozOnlyWhitespace, _, _),
("-moz-native-anonymous", MozNativeAnonymous, mozNativeAnonymous, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-native-anonymous-no-specificity", MozNativeAnonymousNoSpecificity, mozNativeAnonymousNoSpecificity, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-use-shadow-tree-root", MozUseShadowTreeRoot, mozUseShadowTreeRoot, _, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-is-html", MozIsHTML, mozIsHTML, _, _),
("-moz-placeholder", MozPlaceholder, mozPlaceholder, _, _),
Expand Down
8 changes: 8 additions & 0 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -233,6 +233,9 @@ impl NonTSPseudoClass {
// across all the elements involved and the latter is already
// checked for by our caching precondtions.
NonTSPseudoClass::MozIsHTML |
// We prevent style sharing for NAC.
NonTSPseudoClass::MozNativeAnonymous |
NonTSPseudoClass::MozNativeAnonymousNoSpecificity |
// :-moz-placeholder is parsed but never matches.
NonTSPseudoClass::MozPlaceholder |
// :-moz-locale-dir and :-moz-window-inactive depend only on
Expand Down Expand Up @@ -275,6 +278,11 @@ impl ::selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
NonTSPseudoClass::Hover | NonTSPseudoClass::Active | NonTSPseudoClass::Focus
)
}

#[inline]
fn has_zero_specificity(&self) -> bool {
matches!(*self, NonTSPseudoClass::MozNativeAnonymousNoSpecificity)
}
}

/// The dummy struct we use to implement our selector parsing.
Expand Down
3 changes: 2 additions & 1 deletion components/style/gecko/wrapper.rs
Expand Up @@ -2130,7 +2130,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
}
true
},
NonTSPseudoClass::MozNativeAnonymous => self.is_in_native_anonymous_subtree(),
NonTSPseudoClass::MozNativeAnonymous |
NonTSPseudoClass::MozNativeAnonymousNoSpecificity => self.is_in_native_anonymous_subtree(),
NonTSPseudoClass::MozUseShadowTreeRoot => self.is_root_of_use_element_shadow_tree(),
NonTSPseudoClass::MozTableBorderNonzero => unsafe {
bindings::Gecko_IsTableBorderNonzero(self.0)
Expand Down
5 changes: 5 additions & 0 deletions components/style/servo/selector_parser.rs
Expand Up @@ -309,6 +309,11 @@ impl ::selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
NonTSPseudoClass::Active | NonTSPseudoClass::Hover | NonTSPseudoClass::Focus
)
}

#[inline]
fn has_zero_specificity(&self) -> bool {
false
}
}

impl ToCss for NonTSPseudoClass {
Expand Down

0 comments on commit 6973317

Please sign in to comment.