Skip to content

Commit

Permalink
Auto merge of #18076 - upsuper:fullscreen-pref, r=TYLin
Browse files Browse the repository at this point in the history
Check pref when parsing :fullscreen pseudo-class

This is the Servo side change of [bug 1374902](https://bugzilla.mozilla.org/show_bug.cgi?id=1374902).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18076)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 15, 2017
2 parents 6f5e763 + d3baa4f commit 4771e6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions components/style/gecko/generated/structs_debug.rs
Expand Up @@ -9216,6 +9216,11 @@ pub mod root {
"_ZN7mozilla10StylePrefs28sFramesTimingFunctionEnabledE"]
pub static mut StylePrefs_sFramesTimingFunctionEnabled: bool;
}
extern "C" {
#[link_name =
"_ZN7mozilla10StylePrefs31sUnprefixedFullscreenApiEnabledE"]
pub static mut StylePrefs_sUnprefixedFullscreenApiEnabled: bool;
}
#[test]
fn bindgen_test_layout_StylePrefs() {
assert_eq!(::std::mem::size_of::<StylePrefs>() , 1usize , concat !
Expand Down
5 changes: 5 additions & 0 deletions components/style/gecko/generated/structs_release.rs
Expand Up @@ -9062,6 +9062,11 @@ pub mod root {
"_ZN7mozilla10StylePrefs28sFramesTimingFunctionEnabledE"]
pub static mut StylePrefs_sFramesTimingFunctionEnabled: bool;
}
extern "C" {
#[link_name =
"_ZN7mozilla10StylePrefs31sUnprefixedFullscreenApiEnabledE"]
pub static mut StylePrefs_sUnprefixedFullscreenApiEnabled: bool;
}
#[test]
fn bindgen_test_layout_StylePrefs() {
assert_eq!(::std::mem::size_of::<StylePrefs>() , 1usize , concat !
Expand Down
4 changes: 1 addition & 3 deletions components/style/gecko/non_ts_pseudo_class_list.rs
Expand Up @@ -61,9 +61,7 @@ macro_rules! apply_non_ts_list {
("indeterminate", Indeterminate, indeterminate, IN_INDETERMINATE_STATE, _),
("-moz-devtools-highlighted", MozDevtoolsHighlighted, mozDevtoolsHighlighted, IN_DEVTOOLS_HIGHLIGHTED_STATE, _),
("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, mozStyleeditorTransitioning, IN_STYLEEDITOR_TRANSITIONING_STATE, _),
// TODO(emilio): Needs pref check for full-screen-api.unprefix.enabled!
// TODO(TYLin): Needs to use CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME?
("fullscreen", Fullscreen, fullscreen, IN_FULLSCREEN_STATE, _),
("fullscreen", Fullscreen, fullscreen, IN_FULLSCREEN_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME),
("-moz-full-screen", MozFullScreen, mozFullScreen, IN_FULLSCREEN_STATE, _),
// TODO(emilio): This is inconsistently named (the capital R).
("-moz-focusring", MozFocusRing, mozFocusRing, IN_FOCUSRING_STATE, _),
Expand Down
34 changes: 22 additions & 12 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -125,12 +125,11 @@ impl SelectorMethods for NonTSPseudoClass {


impl NonTSPseudoClass {
/// Returns true if this pseudo-class is enabled under the context of
/// the given flag.
fn is_enabled_in(&self, flag: NonTSPseudoClassFlag) -> bool {
/// Returns true if this pseudo-class has any of the given flags set.
fn has_any_flag(&self, flags: NonTSPseudoClassFlag) -> bool {
macro_rules! check_flag {
(_) => (false);
($flags:expr) => ($flags.contains(flag));
($flags:expr) => ($flags.intersects(flags));
}
macro_rules! pseudo_class_check_is_enabled_in {
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
Expand All @@ -147,6 +146,20 @@ impl NonTSPseudoClass {
apply_non_ts_list!(pseudo_class_check_is_enabled_in)
}

/// Returns whether the pseudo-class is enabled in content sheets.
fn is_enabled_in_content(&self) -> bool {
use gecko_bindings::structs::mozilla;
match self {
// For pseudo-classes with pref, the availability in content
// depends on the pref.
&NonTSPseudoClass::Fullscreen =>
unsafe { mozilla::StylePrefs_sUnprefixedFullscreenApiEnabled },
// Otherwise, a pseudo-class is enabled in content when it
// doesn't have any enabled flag.
_ => !self.has_any_flag(PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME),
}
}

/// https://drafts.csswg.org/selectors-4/#useraction-pseudos
///
/// We intentionally skip the link-related ones.
Expand Down Expand Up @@ -270,14 +283,11 @@ impl<'a> SelectorParser<'a> {
fn is_pseudo_class_enabled(&self,
pseudo_class: &NonTSPseudoClass)
-> bool {
let enabled_in_ua = pseudo_class.is_enabled_in(PSEUDO_CLASS_ENABLED_IN_UA_SHEETS);
let enabled_in_chrome = pseudo_class.is_enabled_in(PSEUDO_CLASS_ENABLED_IN_CHROME);
if !enabled_in_ua && !enabled_in_chrome {
true
} else {
(enabled_in_ua && self.in_user_agent_stylesheet()) ||
(enabled_in_chrome && self.in_chrome_stylesheet())
}
pseudo_class.is_enabled_in_content() ||
(self.in_user_agent_stylesheet() &&
pseudo_class.has_any_flag(PSEUDO_CLASS_ENABLED_IN_UA_SHEETS)) ||
(self.in_chrome_stylesheet() &&
pseudo_class.has_any_flag(PSEUDO_CLASS_ENABLED_IN_CHROME))
}
}

Expand Down

0 comments on commit 4771e6e

Please sign in to comment.