style: Make input[type=number] pseudo-elements accessible to chrome.

Bug: 1433389
Reviewed-by: jwatt
MozReview-Commit-ID: 2ycajPYd3CV
This commit is contained in:
Emilio Cobos Álvarez 2018-01-26 14:13:14 +01:00
parent f2df3052d9
commit b76bbdf501
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 62 additions and 28 deletions

View file

@ -124,16 +124,26 @@ impl PseudoElement {
!self.is_eager() && !self.is_precomputed() !self.is_eager() && !self.is_precomputed()
} }
/// Whether this pseudo-element is web-exposed.
pub fn exposed_in_non_ua_sheets(&self) -> bool {
(self.flags() & structs::CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY) == 0
}
/// Whether this pseudo-element supports user action selectors. /// Whether this pseudo-element supports user action selectors.
pub fn supports_user_action_state(&self) -> bool { pub fn supports_user_action_state(&self) -> bool {
(self.flags() & structs::CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE) != 0 (self.flags() & structs::CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE) != 0
} }
/// Whether this pseudo-element is enabled for all content.
pub fn enabled_in_content(&self) -> bool {
(self.flags() & structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME) == 0
}
/// Whether this pseudo is enabled explicitly in UA sheets.
pub fn enabled_in_ua_sheets(&self) -> bool {
(self.flags() & structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS) != 0
}
/// Whether this pseudo is enabled explicitly in chrome sheets.
pub fn enabled_in_chrome(&self) -> bool {
(self.flags() & structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME) != 0
}
/// Whether this pseudo-element skips flex/grid container display-based /// Whether this pseudo-element skips flex/grid container display-based
/// fixup. /// fixup.
#[inline] #[inline]

View file

@ -114,7 +114,7 @@ impl PseudoElement {
% if pseudo.is_tree_pseudo_element(): % if pseudo.is_tree_pseudo_element():
0, 0,
% elif pseudo.is_anon_box(): % elif pseudo.is_anon_box():
structs::CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY, structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS,
% else: % else:
structs::SERVO_CSS_PSEUDO_ELEMENT_FLAGS_${pseudo.original_ident}, structs::SERVO_CSS_PSEUDO_ELEMENT_FLAGS_${pseudo.original_ident},
% endif % endif
@ -224,19 +224,24 @@ impl PseudoElement {
/// ///
/// Returns `None` if the pseudo-element is not recognised. /// Returns `None` if the pseudo-element is not recognised.
#[inline] #[inline]
pub fn from_slice(s: &str, in_ua_stylesheet: bool) -> Option<Self> { pub fn from_slice(name: &str) -> Option<Self> {
#[allow(unused_imports)] use std::ascii::AsciiExt;
// We don't need to support tree pseudos because functional // We don't need to support tree pseudos because functional
// pseudo-elements needs arguments, and thus should be created // pseudo-elements needs arguments, and thus should be created
// via other methods. // via other methods.
match_ignore_ascii_case! { name,
% for pseudo in SIMPLE_PSEUDOS: % for pseudo in SIMPLE_PSEUDOS:
if in_ua_stylesheet || ${pseudo_element_variant(pseudo)}.exposed_in_non_ua_sheets() { "${pseudo.value[1:]}" => {
if s.eq_ignore_ascii_case("${pseudo.value[1:]}") { return Some(${pseudo_element_variant(pseudo)})
return Some(${pseudo_element_variant(pseudo)});
}
} }
% endfor % endfor
_ => {
// FIXME: -moz-tree check should probably be
// ascii-case-insensitive.
if name.starts_with("-moz-tree-") {
return PseudoElement::tree_pseudo_element(name, Box::new([]))
}
}
}
None None
} }

View file

@ -159,10 +159,10 @@ impl NonTSPseudoClass {
/// Returns whether the pseudo-class is enabled in content sheets. /// Returns whether the pseudo-class is enabled in content sheets.
fn is_enabled_in_content(&self) -> bool { fn is_enabled_in_content(&self) -> bool {
use gecko_bindings::structs::mozilla; use gecko_bindings::structs::mozilla;
match self { match *self {
// For pseudo-classes with pref, the availability in content // For pseudo-classes with pref, the availability in content
// depends on the pref. // depends on the pref.
&NonTSPseudoClass::Fullscreen => NonTSPseudoClass::Fullscreen =>
unsafe { mozilla::StylePrefs_sUnprefixedFullscreenApiEnabled }, unsafe { mozilla::StylePrefs_sUnprefixedFullscreenApiEnabled },
// Otherwise, a pseudo-class is enabled in content when it // Otherwise, a pseudo-class is enabled in content when it
// doesn't have any enabled flag. // doesn't have any enabled flag.
@ -322,6 +322,25 @@ impl<'a> SelectorParser<'a> {
return false; return false;
} }
fn is_pseudo_element_enabled(
&self,
pseudo_element: &PseudoElement,
) -> bool {
if pseudo_element.enabled_in_content() {
return true;
}
if self.in_user_agent_stylesheet() && pseudo_element.enabled_in_ua_sheets() {
return true;
}
if self.chrome_rules_enabled() && pseudo_element.enabled_in_chrome() {
return true;
}
return false;
}
} }
impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
@ -418,17 +437,15 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
location: SourceLocation, location: SourceLocation,
name: CowRcStr<'i>, name: CowRcStr<'i>,
) -> Result<PseudoElement, ParseError<'i>> { ) -> Result<PseudoElement, ParseError<'i>> {
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) if let Some(pseudo) = PseudoElement::from_slice(&name) {
.or_else(|| { if self.is_pseudo_element_enabled(&pseudo) {
// FIXME: -moz-tree check should probably be return Ok(pseudo);
// ascii-case-insensitive.
if name.starts_with("-moz-tree-") {
PseudoElement::tree_pseudo_element(&name, Box::new([]))
} else {
None
} }
}) }
.ok_or(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())))
Err(location.new_custom_error(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)
))
} }
fn parse_functional_pseudo_element<'t>( fn parse_functional_pseudo_element<'t>(
@ -456,7 +473,9 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
return Ok(pseudo); return Ok(pseudo);
} }
} }
Err(parser.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone()))) Err(parser.new_custom_error(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)
))
} }
fn default_namespace(&self) -> Option<Namespace> { fn default_namespace(&self) -> Option<Namespace> {