diff --git a/components/style/media_queries/media_feature_expression.rs b/components/style/media_queries/media_feature_expression.rs index 6a9db93e889..53e24ae5b17 100644 --- a/components/style/media_queries/media_feature_expression.rs +++ b/components/style/media_queries/media_feature_expression.rs @@ -17,7 +17,6 @@ use crate::parser::{Parse, ParserContext}; #[cfg(feature = "servo")] use crate::servo::media_queries::MEDIA_FEATURES; use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase}; -use crate::stylesheets::Origin; use crate::values::computed::{self, ToComputedValue}; use crate::values::specified::{Integer, Length, Number, Resolution}; use crate::values::{serialize_atom_identifier, CSSFloat}; @@ -290,7 +289,7 @@ impl MediaFeatureExpression { let mut requirements = ParsingRequirements::empty(); - if context.chrome_rules_enabled() || context.stylesheet_origin == Origin::UserAgent { + if context.in_ua_or_chrome_sheet() { requirements.insert(ParsingRequirements::CHROME_AND_UA_ONLY); } diff --git a/components/style/parser.rs b/components/style/parser.rs index 6e9d4496cd7..f3190f7f72b 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -146,10 +146,23 @@ impl<'a> ParserContext<'a> { error_reporter.report_error(self.url_data, location, error) } + /// Whether we're in a user-agent stylesheet. + #[inline] + pub fn in_ua_sheet(&self) -> bool { + self.stylesheet_origin == Origin::UserAgent + } + /// Returns whether chrome-only rules should be parsed. + #[inline] pub fn chrome_rules_enabled(&self) -> bool { self.url_data.is_chrome() || self.stylesheet_origin == Origin::User } + + /// Whether we're in a user-agent stylesheet or chrome rules are enabled. + #[inline] + pub fn in_ua_or_chrome_sheet(&self) -> bool { + self.in_ua_sheet() || self.chrome_rules_enabled() + } } /// A trait to abstract parsing of a specified value given a `ParserContext` and diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index 45f6f97812d..3ed0595aa44 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -223,8 +223,7 @@ impl SupportsCondition { #[cfg(feature = "gecko")] fn eval_moz_bool_pref(name: &CStr, cx: &ParserContext) -> bool { use crate::gecko_bindings::bindings; - use crate::stylesheets::Origin; - if cx.stylesheet_origin != Origin::UserAgent && !cx.chrome_rules_enabled() { + if !cx.in_ua_or_chrome_sheet() { return false; } unsafe { bindings::Gecko_GetBoolPrefValue(name.as_ptr()) } diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index ab81d4c3450..11ab02f045f 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -21,22 +21,17 @@ use std::fmt::{self, Write}; use style_traits::{CssWriter, KeywordsCollectFn, ParseError}; use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss}; -fn in_ua_or_chrome_sheet(context: &ParserContext) -> bool { - use crate::stylesheets::Origin; - context.stylesheet_origin == Origin::UserAgent || context.chrome_rules_enabled() -} - #[cfg(feature = "gecko")] fn moz_display_values_enabled(context: &ParserContext) -> bool { use crate::gecko_bindings::structs; - in_ua_or_chrome_sheet(context) || + context.in_ua_or_chrome_sheet() || unsafe { structs::StaticPrefs_sVarCache_layout_css_xul_display_values_content_enabled } } #[cfg(feature = "gecko")] fn moz_box_display_values_enabled(context: &ParserContext) -> bool { use crate::gecko_bindings::structs; - in_ua_or_chrome_sheet(context) || + context.in_ua_or_chrome_sheet() || unsafe { structs::StaticPrefs_sVarCache_layout_css_xul_box_display_values_content_enabled } @@ -988,27 +983,27 @@ pub enum Appearance { /// A typical dialog button. Button, /// Various arrows that go in buttons - #[parse(condition = "in_ua_or_chrome_sheet")] + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] ButtonArrowDown, - #[parse(condition = "in_ua_or_chrome_sheet")] + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] ButtonArrowNext, - #[parse(condition = "in_ua_or_chrome_sheet")] + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] ButtonArrowPrevious, - #[parse(condition = "in_ua_or_chrome_sheet")] + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] ButtonArrowUp, /// A rectangular button that contains complex content /// like images (e.g. HTML