Skip to content
Permalink
Browse files

style: Use `static_prefs::pref!`.

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 7, 2019
1 parent ad1d028 commit bb032c1ddc7076120b75c02cdd53b923a9ed21b9
@@ -66,6 +66,7 @@ servo_atoms = {path = "../atoms", optional = true}
servo_config = {path = "../config", optional = true}
smallbitvec = "2.3.0"
smallvec = "0.6.6"
static_prefs = { path = "../../../modules/libpref/init/static_prefs" }
string_cache = { version = "0.7", optional = true }
style_derive = {path = "../style_derive"}
style_traits = {path = "../style_traits"}
@@ -414,16 +414,10 @@ impl Parse for Source {

macro_rules! is_descriptor_enabled {
("font-display") => {
unsafe {
use crate::gecko_bindings::structs::mozilla;
mozilla::StaticPrefs::sVarCache_layout_css_font_display_enabled
}
static_prefs::pref!("layout.css.font-display.enabled")
};
("font-variation-settings") => {
unsafe {
use crate::gecko_bindings::structs::mozilla;
mozilla::StaticPrefs::sVarCache_layout_css_font_variations_enabled != 0
}
static_prefs::pref!("layout.css.font-variations.enabled")
};
($name:tt) => {
true
@@ -268,8 +268,7 @@ impl Device {
if doc.mIsBeingUsedAsImage() {
return true;
}
let document_color_use =
unsafe { structs::StaticPrefs::sVarCache_browser_display_document_color_use };
let document_color_use = static_prefs::pref!("browser.display.document_color_use");
let prefs = self.pref_sheet_prefs();
match document_color_use {
1 => true,
@@ -187,11 +187,8 @@ impl PseudoElement {
PseudoElement::FirstLine => PropertyFlags::APPLIES_TO_FIRST_LINE,
PseudoElement::Placeholder => PropertyFlags::APPLIES_TO_PLACEHOLDER,
PseudoElement::Cue => PropertyFlags::APPLIES_TO_CUE,
PseudoElement::Marker
if unsafe { structs::StaticPrefs::sVarCache_layout_css_marker_restricted } =>
{
PropertyFlags::APPLIES_TO_MARKER
},
PseudoElement::Marker if static_prefs::pref!("layout.css.marker.restricted") =>
PropertyFlags::APPLIES_TO_MARKER,
_ => return None,
})
}
@@ -112,7 +112,7 @@ impl PseudoElement {
% for pseudo in PSEUDOS:
${pseudo_element_variant(pseudo)} =>
% 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
} else {
structs::CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME
@@ -209,9 +209,7 @@ impl PseudoElement {
if starts_with_ignore_ascii_case(name, "-moz-tree-") {
return PseudoElement::tree_pseudo_element(name, Box::new([]))
}
if unsafe {
structs::StaticPrefs::sVarCache_layout_css_unknown_webkit_pseudo_element
} {
if static_prefs::pref!("layout.css.unknown-webkit-pseudo-element") {
const WEBKIT_PREFIX: &str = "-webkit-";
if starts_with_ignore_ascii_case(name, WEBKIT_PREFIX) {
let part = string_as_ascii_lowercase(&name[WEBKIT_PREFIX.len()..]);
@@ -5,7 +5,7 @@
//! Gecko-specific bits for selector-parsing.

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::invalidation::element::document_state::InvalidationMatchingData;
use crate::selector_parser::{Direction, SelectorParser};
@@ -170,13 +170,10 @@ impl NonTSPseudoClass {

/// Returns whether the pseudo-class is enabled in content sheets.
fn is_enabled_in_content(&self) -> bool {
use crate::gecko_bindings::structs::mozilla;
match *self {
// For pseudo-classes with pref, the availability in content
// depends on the pref.
NonTSPseudoClass::Fullscreen => unsafe {
mozilla::StaticPrefs::sVarCache_full_screen_api_unprefix_enabled
},
NonTSPseudoClass::Fullscreen => static_prefs::pref!("full-screen-api.unprefix.enabled"),
// Otherwise, a pseudo-class is enabled in content when it
// doesn't have any enabled flag.
_ => !self
@@ -354,8 +351,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {

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

fn parse_non_ts_pseudo_class(
@@ -91,6 +91,7 @@ extern crate servo_config;
extern crate servo_url;
extern crate smallbitvec;
extern crate smallvec;
extern crate static_prefs;
#[cfg(feature = "servo")]
extern crate string_cache;
#[macro_use]
@@ -11,8 +11,6 @@ use super::Device;
use crate::context::QuirksMode;
#[cfg(feature = "gecko")]
use crate::gecko::media_features::MEDIA_FEATURES;
#[cfg(feature = "gecko")]
use crate::gecko_bindings::structs;
use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES;
@@ -301,9 +299,7 @@ impl MediaFeatureExpression {
if starts_with_ignore_ascii_case(feature_name, "-webkit-") {
feature_name = &feature_name[8..];
requirements.insert(ParsingRequirements::WEBKIT_PREFIX);
if unsafe {
structs::StaticPrefs::sVarCache_layout_css_prefixes_device_pixel_ratio_webkit
} {
if static_prefs::pref!("layout.css.prefixes.device-pixel-ratio-webkit") {
requirements.insert(
ParsingRequirements::WEBKIT_DEVICE_PIXEL_RATIO_PREF_ENABLED,
);
@@ -673,15 +673,15 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
#[inline]
#[cfg(feature = "gecko")]
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;

if !self.seen.contains(LonghandId::XLang) &&
!self.seen.contains(LonghandId::FontFamily) {
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 (default_font_type, prioritize_user_fonts) = {
let font = builder.get_font().gecko();
@@ -253,20 +253,18 @@ impl DocumentCondition {

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

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

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

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

@@ -323,9 +323,7 @@ impl RawSelector {
pub fn eval(&self, context: &ParserContext, namespaces: &Namespaces) -> bool {
#[cfg(feature = "gecko")]
{
if unsafe {
!crate::gecko_bindings::structs::StaticPrefs::sVarCache_layout_css_supports_selector_enabled
} {
if !static_prefs::pref!("layout.css.supports-selector.enabled") {
return false;
}
}
@@ -69,8 +69,7 @@ pub enum TimingKeyword {

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

#[cfg(feature = "servo")]
@@ -72,11 +72,8 @@ impl<Value> Spacing<Value> {

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

/// A generic value for the `line-height` property.
@@ -58,9 +58,7 @@ pub type Polygon = generic::GenericPolygon<LengthPercentage>;

#[cfg(feature = "gecko")]
fn is_clip_path_path_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs::mozilla;
context.chrome_rules_enabled() ||
unsafe { mozilla::StaticPrefs::sVarCache_layout_css_clip_path_path_enabled }
context.chrome_rules_enabled() || static_prefs::pref!("layout.css.clip-path-path.enabled")
}
#[cfg(feature = "servo")]
fn is_clip_path_path_enabled(_: &ParserContext) -> bool {
@@ -23,18 +23,14 @@ use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};

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

#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
@@ -305,8 +305,7 @@ impl Parse for TrackList<LengthPercentage, Integer> {
#[cfg(feature = "gecko")]
#[inline]
fn allow_grid_template_subgrids() -> bool {
use crate::gecko_bindings::structs::mozilla;
unsafe { mozilla::StaticPrefs::sVarCache_layout_css_grid_template_subgrid_value_enabled }
static_prefs::pref!("layout.css.grid-template-subgrid-value.enabled")
}

#[cfg(feature = "servo")]
@@ -32,8 +32,7 @@ pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeLengthPerce
/// Whether the `context-value` value is enabled.
#[cfg(feature = "gecko")]
pub fn is_context_value_enabled() -> bool {
use crate::gecko_bindings::structs::mozilla;
unsafe { mozilla::StaticPrefs::sVarCache_gfx_font_rendering_opentype_svg_enabled }
static_prefs::pref!("gfx.font_rendering.opentype_svg.enabled")
}

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

0 comments on commit bb032c1

Please sign in to comment.
You can’t perform that action at this time.