Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Add a static_prefs implementation #31351

Merged
merged 1 commit into from Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/style/Cargo.toml
Expand Up @@ -73,6 +73,7 @@ servo_url = { path = "../url", optional = true }
smallbitvec = "2.3.0"
smallvec = "1.0"
static_assertions = "1.1"
static_prefs = { path = "../style_static_prefs" }
string_cache = { version = "0.8", optional = true }
style_derive = { path = "../style_derive" }
style_traits = { workspace = true }
Expand Down
12 changes: 2 additions & 10 deletions components/style/driver.rs
Expand Up @@ -63,10 +63,7 @@ fn with_pool_in_place_scope<'scope, R>(

/// See documentation of the pref for performance characteristics.
fn work_unit_max() -> usize {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.stylo-work-unit-size") as usize;
#[cfg(feature = "servo")]
return 16;
static_prefs::pref!("layout.css.stylo-work-unit-size") as usize
}

/// Do a DOM traversal for top-down and (optionally) bottom-up processing, generic over `D`.
Expand Down Expand Up @@ -127,12 +124,7 @@ where
discovered,
root.as_node().opaque(),
work_unit_max,
(|| {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.stylo-local-work-queue.in-main-thread") as usize;
#[cfg(feature = "servo")]
return 32;
})(),
static_prefs::pref!("layout.css.stylo-local-work-queue.in-main-thread") as usize,
PerLevelTraversalData { current_dom_depth: root.depth() },
maybe_scope,
traversal,
Expand Down
14 changes: 4 additions & 10 deletions components/style/font_face.rs
Expand Up @@ -577,13 +577,6 @@ impl<'a, 'b, 'i> RuleBodyItemParser<'i, (), StyleParseErrorKind<'i>>
}
}

fn font_tech_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.font-tech.enabled");
#[cfg(feature = "servo")]
return false;
}

impl Parse for Source {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down Expand Up @@ -618,9 +611,10 @@ impl Parse for Source {
};

// Parse optional tech()
let tech_flags = if font_tech_enabled() && input
.try_parse(|input| input.expect_function_matching("tech"))
.is_ok()
let tech_flags = if static_prefs::pref!("layout.css.font-tech.enabled") &&
input
.try_parse(|input| input.expect_function_matching("tech"))
.is_ok()
{
input.parse_nested_block(|input| FontFaceSourceTechFlags::parse(context, input))?
} else {
Expand Down
7 changes: 1 addition & 6 deletions components/style/parallel.rs
Expand Up @@ -93,12 +93,7 @@ fn distribute_one_chunk<'a, 'scope, E, D>(
items,
traversal_root,
work_unit_max,
(|| {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.stylo-local-work-queue.in-worker") as usize;
#[cfg(feature = "servo")]
return 0;
})(),
static_prefs::pref!("layout.css.stylo-local-work-queue.in-worker") as usize,
traversal_data,
Some(scope),
traversal,
Expand Down
9 changes: 1 addition & 8 deletions components/style/properties/shorthands/ui.mako.rs
Expand Up @@ -190,13 +190,6 @@ macro_rules! try_parse_one {
% endfor
}

fn scroll_driven_animations_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.scroll-driven-animations.enabled");
#[cfg(feature = "servo")]
return false;
}

fn parse_one_animation<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
Expand All @@ -221,7 +214,7 @@ macro_rules! try_parse_one {
try_parse_one!(context, input, fill_mode, animation_fill_mode);
try_parse_one!(context, input, play_state, animation_play_state);
try_parse_one!(context, input, name, animation_name);
if scroll_driven_animations_enabled() {
if static_prefs::pref!("layout.css.scroll-driven-animations.enabled") {
try_parse_one!(context, input, timeline, animation_timeline);
}

Expand Down
3 changes: 0 additions & 3 deletions components/style/selector_map.rs
Expand Up @@ -153,10 +153,7 @@ impl<T> SelectorMap<T> {
namespace_hash: HashMap::default(),
rare_pseudo_classes: SmallVec::new(),
other: SmallVec::new(),
#[cfg(feature = "gecko")]
bucket_attributes: static_prefs::pref!("layout.css.bucket-attribute-names.enabled"),
#[cfg(feature = "servo")]
bucket_attributes: false,
count: 0,
}
}
Expand Down
7 changes: 1 addition & 6 deletions components/style/stylesheets/import_rule.rs
Expand Up @@ -262,12 +262,7 @@ impl ImportRule {
.unwrap_or(ImportLayer::None)
};

#[cfg(feature = "gecko")]
let supports_enabled = static_prefs::pref!("layout.css.import-supports.enabled");
#[cfg(feature = "servo")]
let supports_enabled = false;

let supports = if !supports_enabled {
let supports = if !static_prefs::pref!("layout.css.import-supports.enabled") {
None
} else {
input
Expand Down
21 changes: 2 additions & 19 deletions components/style/stylesheets/rule_parser.rs
Expand Up @@ -5,7 +5,6 @@
//! Parsing of the stylesheet contents.

use crate::counter_style::{parse_counter_style_body, parse_counter_style_name_definition};
#[cfg(feature = "gecko")]
use crate::custom_properties::parse_name as parse_custom_property_name;
use crate::error_reporting::ContextualParseError;
use crate::font_face::parse_font_face_block;
Expand All @@ -32,7 +31,6 @@ use crate::stylesheets::{
};
use crate::values::computed::font::FamilyName;
use crate::values::{CssUrl, CustomIdent, DashedIdent, KeyframesName};
#[cfg(feature = "gecko")]
use crate::Atom;
use crate::{Namespace, Prefix};
use cssparser::{
Expand Down Expand Up @@ -455,10 +453,7 @@ impl<'a, 'b, 'i> NestedRuleParser<'a, 'b, 'i> {
if !self.context.rule_types.contains(CssRuleType::Style) {
return true;
}
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.nesting.enabled");
#[cfg(feature = "servo")]
return false;
static_prefs::pref!("layout.css.nesting.enabled")
}

fn nest_for_rule<R>(&mut self, rule_type: CssRuleType, cb: impl FnOnce(&mut Self) -> R) -> R {
Expand Down Expand Up @@ -520,16 +515,6 @@ impl<'a, 'b, 'i> NestedRuleParser<'a, 'b, 'i> {
}
}

fn container_queries_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.container-queries.enabled");
#[cfg(feature = "servo")]
return servo_config::prefs::pref_map()
.get("layout.container-queries.enabled")
.as_bool()
.unwrap_or(false);
}

impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b, 'i> {
type Prelude = AtRulePrelude;
type AtRule = ();
Expand All @@ -556,7 +541,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b, 'i> {
"font-face" => {
AtRulePrelude::FontFace
},
"container" if container_queries_enabled() => {
"container" if static_prefs::pref!("layout.css.container-queries.enabled") => {
let condition = Arc::new(ContainerCondition::parse(self.context, input)?);
AtRulePrelude::Container(condition)
},
Expand All @@ -572,7 +557,6 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b, 'i> {
let family_names = parse_family_name_list(self.context, input)?;
AtRulePrelude::FontFeatureValues(family_names)
},
#[cfg(feature = "gecko")]
"font-palette-values" if static_prefs::pref!("layout.css.font-palette.enabled") => {
let name = DashedIdent::parse(self.context, input)?;
AtRulePrelude::FontPaletteValues(name)
Expand Down Expand Up @@ -602,7 +586,6 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b, 'i> {
input.try_parse(|i| PageSelectors::parse(self.context, i)).unwrap_or_default()
)
},
#[cfg(feature = "gecko")]
"property" if static_prefs::pref!("layout.css.properties-and-values.enabled") => {
let name = input.expect_ident_cloned()?;
let name = parse_custom_property_name(&name).map_err(|_| {
Expand Down
2 changes: 0 additions & 2 deletions components/style/stylesheets/supports_rule.rs
Expand Up @@ -170,12 +170,10 @@ impl SupportsCondition {
input.slice_from(pos).to_owned()
)))
},
#[cfg(feature = "gecko")]
"font-format" if static_prefs::pref!("layout.css.font-tech.enabled") => {
let kw = FontFaceSourceFormatKeyword::parse(input)?;
Ok(SupportsCondition::FontFormat(kw))
},
#[cfg(feature = "gecko")]
"font-tech" if static_prefs::pref!("layout.css.font-tech.enabled") => {
let flag = FontFaceSourceTechFlags::parse_one(input)?;
Ok(SupportsCondition::FontTech(flag))
Expand Down
5 changes: 1 addition & 4 deletions components/style/values/computed/font.rs
Expand Up @@ -517,10 +517,7 @@ pub enum SingleFontFamily {
}

fn system_ui_enabled(_: &ParserContext) -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.system-ui.enabled");
#[cfg(feature = "servo")]
return false;
static_prefs::pref!("layout.css.system-ui.enabled")
}

/// A generic font-family name.
Expand Down
5 changes: 1 addition & 4 deletions components/style/values/mod.rs
Expand Up @@ -93,10 +93,7 @@ where
}

fn nan_inf_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.nan-inf.enabled");
#[cfg(feature = "servo")]
return false;
static_prefs::pref!("layout.css.nan-inf.enabled")
}

/// Serialize a number with calc, and NaN/infinity handling (if enabled)
Expand Down
11 changes: 2 additions & 9 deletions components/style/values/resolved/counters.rs
Expand Up @@ -7,14 +7,6 @@
use super::{Context, ToResolvedValue};
use crate::values::computed;

#[inline]
fn allow_element_content_none() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.element-content-none.enabled");
#[cfg(feature = "servo")]
return false;
}

/// https://drafts.csswg.org/css-content/#content-property
///
/// We implement this at resolved value time because otherwise it causes us to
Expand Down Expand Up @@ -43,7 +35,8 @@ impl ToResolvedValue for computed::Content {
// Ditto for non-pseudo elements if the pref is disabled.
Self::None
if (is_pseudo && !is_before_or_after && !is_marker) ||
(!is_pseudo && !allow_element_content_none()) =>
(!is_pseudo &&
!static_prefs::pref!("layout.css.element-content-none.enabled")) =>
{
Self::Normal
},
Expand Down
1 change: 0 additions & 1 deletion components/style/values/specified/box.rs
Expand Up @@ -1832,7 +1832,6 @@ impl Parse for Overflow {
"-moz-hidden-unscrollable" if static_prefs::pref!("layout.css.overflow-moz-hidden-unscrollable.enabled") => {
Overflow::Clip
},
#[cfg(feature = "gecko")]
"overlay" if static_prefs::pref!("layout.css.overflow-overlay.enabled") => {
Overflow::Auto
},
Expand Down
37 changes: 5 additions & 32 deletions components/style/values/specified/calc.rs
Expand Up @@ -21,38 +21,11 @@ use style_traits::values::specified::AllowedNumericType;
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};

fn trig_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.trig.enabled");
#[cfg(feature = "servo")]
return false;
static_prefs::pref!("layout.css.trig.enabled")
}

fn nan_inf_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.nan-inf.enabled");
#[cfg(feature = "servo")]
return false;
}

fn round_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.round.enabled");
#[cfg(feature = "servo")]
return false;
}

fn mod_rem_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.mod-rem.enabled");
#[cfg(feature = "servo")]
return false;
}

fn exp_enabled() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.exp.enabled");
#[cfg(feature = "servo")]
return false;
static_prefs::pref!("layout.css.nan-inf.enabled")
}

/// The name of the mathematical function that we're parsing.
Expand Down Expand Up @@ -929,11 +902,11 @@ impl CalcNode {
} else if matches!(function, Sin | Cos | Tan | Asin | Acos | Atan | Atan2) {
trig_enabled()
} else if matches!(function, Round) {
round_enabled()
static_prefs::pref!("layout.css.round.enabled")
} else if matches!(function, Mod | Rem) {
mod_rem_enabled()
static_prefs::pref!("layout.css.mod-rem.enabled")
} else if matches!(function, Pow | Sqrt | Hypot | Log | Exp) {
exp_enabled()
static_prefs::pref!("layout.css.exp.enabled")
} else {
true
};
Expand Down
24 changes: 4 additions & 20 deletions components/style/values/specified/color.rs
Expand Up @@ -25,30 +25,14 @@ use style_traits::{SpecifiedValueInfo, ToCss, ValueParseErrorKind};
/// A specified color-mix().
pub type ColorMix = GenericColorMix<Color, Percentage>;

#[inline]
fn allow_color_mix() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.color-mix.enabled");
#[cfg(feature = "servo")]
return true;
}

#[inline]
fn allow_more_color_4() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.more_color_4.enabled");
#[cfg(feature = "servo")]
return true;
}

impl ColorMix {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
preserve_authored: PreserveAuthored,
) -> Result<Self, ParseError<'i>> {
let enabled =
context.chrome_rules_enabled() || allow_color_mix();
context.chrome_rules_enabled() || static_prefs::pref!("layout.css.color-mix.enabled");

if !enabled {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
Expand Down Expand Up @@ -639,7 +623,7 @@ impl Color {
);
let is_color_function =
absolute.color.flags.contains(ColorFlags::AS_COLOR_FUNCTION);
let pref_enabled = allow_more_color_4();
let pref_enabled = static_prefs::pref!("layout.css.more_color_4.enabled");

(is_legacy_color && !is_color_function) || pref_enabled
};
Expand Down Expand Up @@ -971,10 +955,10 @@ impl SpecifiedValueInfo for Color {
"currentColor",
"transparent",
]);
if allow_color_mix() {
if static_prefs::pref!("layout.css.color-mix.enabled") {
f(&["color-mix"]);
}
if allow_more_color_4() {
if static_prefs::pref!("layout.css.more_color_4.enabled") {
f(&["color", "lab", "lch", "oklab", "oklch"]);
}
}
Expand Down