diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 9c39a957796..da2ed780eec 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -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"} diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 50814c5f5e8..d45cd340c85 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -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 diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index ecd9115a4cb..bb126e16948 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -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, diff --git a/components/style/gecko/pseudo_element.rs b/components/style/gecko/pseudo_element.rs index 501611830ff..9bea09b45ee 100644 --- a/components/style/gecko/pseudo_element.rs +++ b/components/style/gecko/pseudo_element.rs @@ -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, }) } diff --git a/components/style/gecko/pseudo_element_definition.mako.rs b/components/style/gecko/pseudo_element_definition.mako.rs index 562b4c18444..d8d80d60165 100644 --- a/components/style/gecko/pseudo_element_definition.mako.rs +++ b/components/style/gecko/pseudo_element_definition.mako.rs @@ -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()..]); diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 1da352249d4..2aad41adc9c 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -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( diff --git a/components/style/lib.rs b/components/style/lib.rs index 587b926efc6..31356d911d5 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -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] diff --git a/components/style/media_queries/media_feature_expression.rs b/components/style/media_queries/media_feature_expression.rs index 310cbd2b8bb..98c7d59c7e1 100644 --- a/components/style/media_queries/media_feature_expression.rs +++ b/components/style/media_queries/media_feature_expression.rs @@ -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, ); diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index c3ce242eadd..da95840a08a 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -673,7 +673,7 @@ 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) && @@ -681,7 +681,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { 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(); diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 62e814ac48b..942d60a7d17 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -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; } diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index 4b709974c7d..9ef3558bd1c 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -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; } } diff --git a/components/style/values/generics/easing.rs b/components/style/values/generics/easing.rs index aab2ef547ba..b234b6a54e0 100644 --- a/components/style/values/generics/easing.rs +++ b/components/style/values/generics/easing.rs @@ -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")] diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index b55a9ad62dc..50db1a1017e 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -72,11 +72,8 @@ impl Spacing { #[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. diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 8dccf4594f0..3c32144e71c 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -58,9 +58,7 @@ pub type Polygon = generic::GenericPolygon; #[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 { diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 0811a48be1a..346dc8f931f 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -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"))] diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 2bbfd9164fd..a504f0cdda5 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -305,8 +305,7 @@ impl Parse for TrackList { #[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")] diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index 9279707935f..4858fbaec6b 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -32,8 +32,7 @@ pub type SVGStrokeDashArray = generic::SVGStrokeDashArray 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.