Skip to content

Commit

Permalink
style: Use static_prefs::pref!.
Browse files Browse the repository at this point in the history
It's much nicer.

One nice thing about this is that the new code is subject to the existing
threadedness checking, which identified that several of these should be atomic
because they're accessed off the main thread.

Differential Revision: https://phabricator.services.mozilla.com/D40792
  • Loading branch information
nnethercote authored and emilio committed Aug 15, 2019
1 parent ad1d028 commit bb032c1
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 60 deletions.
1 change: 1 addition & 0 deletions components/style/Cargo.toml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ servo_atoms = {path = "../atoms", optional = true}
servo_config = {path = "../config", optional = true} servo_config = {path = "../config", optional = true}
smallbitvec = "2.3.0" smallbitvec = "2.3.0"
smallvec = "0.6.6" smallvec = "0.6.6"
static_prefs = { path = "../../../modules/libpref/init/static_prefs" }
string_cache = { version = "0.7", optional = true } string_cache = { version = "0.7", optional = true }
style_derive = {path = "../style_derive"} style_derive = {path = "../style_derive"}
style_traits = {path = "../style_traits"} style_traits = {path = "../style_traits"}
Expand Down
10 changes: 2 additions & 8 deletions components/style/font_face.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -414,16 +414,10 @@ impl Parse for Source {


macro_rules! is_descriptor_enabled { macro_rules! is_descriptor_enabled {
("font-display") => { ("font-display") => {
unsafe { static_prefs::pref!("layout.css.font-display.enabled")
use crate::gecko_bindings::structs::mozilla;
mozilla::StaticPrefs::sVarCache_layout_css_font_display_enabled
}
}; };
("font-variation-settings") => { ("font-variation-settings") => {
unsafe { static_prefs::pref!("layout.css.font-variations.enabled")
use crate::gecko_bindings::structs::mozilla;
mozilla::StaticPrefs::sVarCache_layout_css_font_variations_enabled != 0
}
}; };
($name:tt) => { ($name:tt) => {
true true
Expand Down
3 changes: 1 addition & 2 deletions components/style/gecko/media_queries.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ impl Device {
if doc.mIsBeingUsedAsImage() { if doc.mIsBeingUsedAsImage() {
return true; return true;
} }
let document_color_use = let document_color_use = static_prefs::pref!("browser.display.document_color_use");
unsafe { structs::StaticPrefs::sVarCache_browser_display_document_color_use };
let prefs = self.pref_sheet_prefs(); let prefs = self.pref_sheet_prefs();
match document_color_use { match document_color_use {
1 => true, 1 => true,
Expand Down
7 changes: 2 additions & 5 deletions components/style/gecko/pseudo_element.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -187,11 +187,8 @@ impl PseudoElement {
PseudoElement::FirstLine => PropertyFlags::APPLIES_TO_FIRST_LINE, PseudoElement::FirstLine => PropertyFlags::APPLIES_TO_FIRST_LINE,
PseudoElement::Placeholder => PropertyFlags::APPLIES_TO_PLACEHOLDER, PseudoElement::Placeholder => PropertyFlags::APPLIES_TO_PLACEHOLDER,
PseudoElement::Cue => PropertyFlags::APPLIES_TO_CUE, PseudoElement::Cue => PropertyFlags::APPLIES_TO_CUE,
PseudoElement::Marker PseudoElement::Marker if static_prefs::pref!("layout.css.marker.restricted") =>
if unsafe { structs::StaticPrefs::sVarCache_layout_css_marker_restricted } => PropertyFlags::APPLIES_TO_MARKER,
{
PropertyFlags::APPLIES_TO_MARKER
},
_ => return None, _ => return None,
}) })
} }
Expand Down
6 changes: 2 additions & 4 deletions components/style/gecko/pseudo_element_definition.mako.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl PseudoElement {
% for pseudo in PSEUDOS: % for pseudo in PSEUDOS:
${pseudo_element_variant(pseudo)} => ${pseudo_element_variant(pseudo)} =>
% if pseudo.is_tree_pseudo_element(): % if pseudo.is_tree_pseudo_element():
if unsafe { structs::StaticPrefs::sVarCache_layout_css_xul_tree_pseudos_content_enabled } { if static_prefs::pref!("layout.css.xul-tree-pseudos.content.enabled") {
0 0
} else { } else {
structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME
Expand Down Expand Up @@ -209,9 +209,7 @@ impl PseudoElement {
if starts_with_ignore_ascii_case(name, "-moz-tree-") { if starts_with_ignore_ascii_case(name, "-moz-tree-") {
return PseudoElement::tree_pseudo_element(name, Box::new([])) return PseudoElement::tree_pseudo_element(name, Box::new([]))
} }
if unsafe { if static_prefs::pref!("layout.css.unknown-webkit-pseudo-element") {
structs::StaticPrefs::sVarCache_layout_css_unknown_webkit_pseudo_element
} {
const WEBKIT_PREFIX: &str = "-webkit-"; const WEBKIT_PREFIX: &str = "-webkit-";
if starts_with_ignore_ascii_case(name, WEBKIT_PREFIX) { if starts_with_ignore_ascii_case(name, WEBKIT_PREFIX) {
let part = string_as_ascii_lowercase(&name[WEBKIT_PREFIX.len()..]); let part = string_as_ascii_lowercase(&name[WEBKIT_PREFIX.len()..]);
Expand Down
10 changes: 3 additions & 7 deletions components/style/gecko/selector_parser.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Gecko-specific bits for selector-parsing. //! Gecko-specific bits for selector-parsing.


use crate::element_state::{DocumentState, ElementState}; use crate::element_state::{DocumentState, ElementState};
use crate::gecko_bindings::structs::{self, RawServoSelectorList}; use crate::gecko_bindings::structs::RawServoSelectorList;
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use crate::invalidation::element::document_state::InvalidationMatchingData; use crate::invalidation::element::document_state::InvalidationMatchingData;
use crate::selector_parser::{Direction, SelectorParser}; use crate::selector_parser::{Direction, SelectorParser};
Expand Down Expand Up @@ -170,13 +170,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 crate::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 => unsafe { NonTSPseudoClass::Fullscreen => static_prefs::pref!("full-screen-api.unprefix.enabled"),
mozilla::StaticPrefs::sVarCache_full_screen_api_unprefix_enabled
},
// 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.
_ => !self _ => !self
Expand Down Expand Up @@ -354,8 +351,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {


#[inline] #[inline]
fn parse_part(&self) -> bool { fn parse_part(&self) -> bool {
self.chrome_rules_enabled() || self.chrome_rules_enabled() || static_prefs::pref!("layout.css.shadow-parts.enabled")
unsafe { structs::StaticPrefs::sVarCache_layout_css_shadow_parts_enabled }
} }


fn parse_non_ts_pseudo_class( fn parse_non_ts_pseudo_class(
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extern crate servo_config;
extern crate servo_url; extern crate servo_url;
extern crate smallbitvec; extern crate smallbitvec;
extern crate smallvec; extern crate smallvec;
extern crate static_prefs;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
extern crate string_cache; extern crate string_cache;
#[macro_use] #[macro_use]
Expand Down
6 changes: 1 addition & 5 deletions components/style/media_queries/media_feature_expression.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use super::Device;
use crate::context::QuirksMode; use crate::context::QuirksMode;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use crate::gecko::media_features::MEDIA_FEATURES; use crate::gecko::media_features::MEDIA_FEATURES;
#[cfg(feature = "gecko")]
use crate::gecko_bindings::structs;
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES; use crate::servo::media_queries::MEDIA_FEATURES;
Expand Down Expand Up @@ -301,9 +299,7 @@ impl MediaFeatureExpression {
if starts_with_ignore_ascii_case(feature_name, "-webkit-") { if starts_with_ignore_ascii_case(feature_name, "-webkit-") {
feature_name = &feature_name[8..]; feature_name = &feature_name[8..];
requirements.insert(ParsingRequirements::WEBKIT_PREFIX); requirements.insert(ParsingRequirements::WEBKIT_PREFIX);
if unsafe { if static_prefs::pref!("layout.css.prefixes.device-pixel-ratio-webkit") {
structs::StaticPrefs::sVarCache_layout_css_prefixes_device_pixel_ratio_webkit
} {
requirements.insert( requirements.insert(
ParsingRequirements::WEBKIT_DEVICE_PIXEL_RATIO_PREF_ENABLED, ParsingRequirements::WEBKIT_DEVICE_PIXEL_RATIO_PREF_ENABLED,
); );
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/cascade.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -673,15 +673,15 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
#[inline] #[inline]
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn recompute_default_font_family_type_if_needed(&mut self) { fn recompute_default_font_family_type_if_needed(&mut self) {
use crate::gecko_bindings::{bindings, structs}; use crate::gecko_bindings::bindings;
use crate::values::computed::font::GenericFontFamily; use crate::values::computed::font::GenericFontFamily;


if !self.seen.contains(LonghandId::XLang) && if !self.seen.contains(LonghandId::XLang) &&
!self.seen.contains(LonghandId::FontFamily) { !self.seen.contains(LonghandId::FontFamily) {
return; return;
} }


let use_document_fonts = unsafe { structs::StaticPrefs::sVarCache_browser_display_use_document_fonts != 0 }; let use_document_fonts = static_prefs::pref!("browser.display.use_document_fonts") != 0;
let builder = &mut self.context.builder; let builder = &mut self.context.builder;
let (default_font_type, prioritize_user_fonts) = { let (default_font_type, prioritize_user_fonts) = {
let font = builder.get_font().gecko(); let font = builder.get_font().gecko();
Expand Down
8 changes: 3 additions & 5 deletions components/style/stylesheets/document_rule.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -253,20 +253,18 @@ impl DocumentCondition {


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn allowed_in(&self, context: &ParserContext) -> bool { fn allowed_in(&self, context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
use crate::stylesheets::Origin; use crate::stylesheets::Origin;
use static_prefs::pref;


if context.stylesheet_origin != Origin::Author { if context.stylesheet_origin != Origin::Author {
return true; return true;
} }


if unsafe { structs::StaticPrefs::sVarCache_layout_css_moz_document_content_enabled } { if pref!("layout.css.moz-document.content.enabled") {
return true; return true;
} }


if !unsafe { if !pref!("layout.css.moz-document.url-prefix-hack.enabled") {
structs::StaticPrefs::sVarCache_layout_css_moz_document_url_prefix_hack_enabled
} {
return false; return false;
} }


Expand Down
4 changes: 1 addition & 3 deletions components/style/stylesheets/supports_rule.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ impl RawSelector {
pub fn eval(&self, context: &ParserContext, namespaces: &Namespaces) -> bool { pub fn eval(&self, context: &ParserContext, namespaces: &Namespaces) -> bool {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if unsafe { if !static_prefs::pref!("layout.css.supports-selector.enabled") {
!crate::gecko_bindings::structs::StaticPrefs::sVarCache_layout_css_supports_selector_enabled
} {
return false; return false;
} }
} }
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/generics/easing.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ pub enum TimingKeyword {


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn step_position_jump_enabled(_context: &ParserContext) -> bool { fn step_position_jump_enabled(_context: &ParserContext) -> bool {
use crate::gecko_bindings::structs; static_prefs::pref!("layout.css.step-position-jump.enabled")
unsafe { structs::StaticPrefs::sVarCache_layout_css_step_position_jump_enabled }
} }


#[cfg(feature = "servo")] #[cfg(feature = "servo")]
Expand Down
5 changes: 1 addition & 4 deletions components/style/values/generics/text.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ impl<Value> Spacing<Value> {


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn line_height_moz_block_height_enabled(context: &ParserContext) -> bool { fn line_height_moz_block_height_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
context.in_ua_sheet() || context.in_ua_sheet() ||
unsafe { static_prefs::pref!("layout.css.line-height-moz-block-height.content.enabled")
structs::StaticPrefs::sVarCache_layout_css_line_height_moz_block_height_content_enabled
}
} }


/// A generic value for the `line-height` property. /// A generic value for the `line-height` property.
Expand Down
4 changes: 1 addition & 3 deletions components/style/values/specified/basic_shape.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ pub type Polygon = generic::GenericPolygon<LengthPercentage>;


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn is_clip_path_path_enabled(context: &ParserContext) -> bool { fn is_clip_path_path_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs::mozilla; context.chrome_rules_enabled() || static_prefs::pref!("layout.css.clip-path-path.enabled")
context.chrome_rules_enabled() ||
unsafe { mozilla::StaticPrefs::sVarCache_layout_css_clip_path_path_enabled }
} }
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
fn is_clip_path_path_enabled(_: &ParserContext) -> bool { fn is_clip_path_path_enabled(_: &ParserContext) -> bool {
Expand Down
8 changes: 2 additions & 6 deletions components/style/values/specified/box.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn moz_display_values_enabled(context: &ParserContext) -> bool { fn moz_display_values_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
context.in_ua_or_chrome_sheet() || context.in_ua_or_chrome_sheet() ||
unsafe { structs::StaticPrefs::sVarCache_layout_css_xul_display_values_content_enabled } static_prefs::pref!("layout.css.xul-display-values.content.enabled")
} }


#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn moz_box_display_values_enabled(context: &ParserContext) -> bool { fn moz_box_display_values_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
context.in_ua_or_chrome_sheet() || context.in_ua_or_chrome_sheet() ||
unsafe { static_prefs::pref!("layout.css.xul-box-display-values.content.enabled")
structs::StaticPrefs::sVarCache_layout_css_xul_box_display_values_content_enabled
}
} }


#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))] #[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/specified/grid.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ impl Parse for TrackList<LengthPercentage, Integer> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
#[inline] #[inline]
fn allow_grid_template_subgrids() -> bool { fn allow_grid_template_subgrids() -> bool {
use crate::gecko_bindings::structs::mozilla; static_prefs::pref!("layout.css.grid-template-subgrid-value.enabled")
unsafe { mozilla::StaticPrefs::sVarCache_layout_css_grid_template_subgrid_value_enabled }
} }


#[cfg(feature = "servo")] #[cfg(feature = "servo")]
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/specified/svg.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeLengthPerce
/// Whether the `context-value` value is enabled. /// Whether the `context-value` value is enabled.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub fn is_context_value_enabled() -> bool { pub fn is_context_value_enabled() -> bool {
use crate::gecko_bindings::structs::mozilla; static_prefs::pref!("gfx.font_rendering.opentype_svg.enabled")
unsafe { mozilla::StaticPrefs::sVarCache_gfx_font_rendering_opentype_svg_enabled }
} }


/// Whether the `context-value` value is enabled. /// Whether the `context-value` value is enabled.
Expand Down

0 comments on commit bb032c1

Please sign in to comment.