Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 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
Expand Up @@ -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"}
Expand Down
10 changes: 2 additions & 8 deletions components/style/font_face.rs
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions components/style/gecko/media_queries.rs
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions components/style/gecko/pseudo_element.rs
Expand Up @@ -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,
})
}
Expand Down
6 changes: 2 additions & 4 deletions components/style/gecko/pseudo_element_definition.mako.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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()..]);
Expand Down
10 changes: 3 additions & 7 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions components/style/media_queries/media_feature_expression.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/cascade.rs
Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions components/style/stylesheets/document_rule.rs
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions components/style/stylesheets/supports_rule.rs
Expand Up @@ -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;
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/generics/easing.rs
Expand Up @@ -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")]
Expand Down
5 changes: 1 addition & 4 deletions components/style/values/generics/text.rs
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions components/style/values/specified/basic_shape.rs
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions components/style/values/specified/box.rs
Expand Up @@ -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"))]
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/specified/grid.rs
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/specified/svg.rs
Expand Up @@ -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.
Expand Down

0 comments on commit bb032c1

Please sign in to comment.