From 99a58c137f574655923a360229d853be8694a023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 15 May 2023 20:57:59 +0000 Subject: [PATCH] Bug 1833229 - Move a bit declaration_block and cascade modules. r=boris So that they aren't imported via #[path]. This allows cargo to see them even before building. Differential Revision: https://phabricator.services.mozilla.com/D178105 --- servo/components/style/lib.rs | 15 +--- servo/components/style/properties/cascade.rs | 28 ++++--- .../style/properties/declaration_block.rs | 8 +- servo/components/style/properties/mod.rs | 27 +++++++ .../style/properties/properties.mako.rs | 77 ++++++++++--------- servo/ports/geckolib/glue.rs | 2 +- 6 files changed, 91 insertions(+), 66 deletions(-) create mode 100644 servo/components/style/properties/mod.rs diff --git a/servo/components/style/lib.rs b/servo/components/style/lib.rs index 893b0d95ade75..621494a925bef 100644 --- a/servo/components/style/lib.rs +++ b/servo/components/style/lib.rs @@ -165,14 +165,7 @@ pub use style_traits::owned_str::OwnedStr; use std::hash::{BuildHasher, Hash}; -/// The CSS properties supported by the style system. -/// Generated from the properties.mako.rs template by build.rs -#[macro_use] -#[allow(unsafe_code)] -#[deny(missing_docs)] -pub mod properties { - include!(concat!(env!("OUT_DIR"), "/properties.rs")); -} +pub mod properties; #[cfg(feature = "gecko")] #[allow(unsafe_code)] @@ -183,12 +176,6 @@ pub mod gecko; #[allow(unsafe_code)] pub mod servo; -#[cfg(feature = "gecko")] -#[allow(unsafe_code, missing_docs)] -pub mod gecko_properties { - include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs")); -} - macro_rules! reexport_computed_values { ( $( { $name: ident } )+ ) => { /// Types for [computed values][computed]. diff --git a/servo/components/style/properties/cascade.rs b/servo/components/style/properties/cascade.rs index 60d591537c5d6..79b0262f95b0e 100644 --- a/servo/components/style/properties/cascade.rs +++ b/servo/components/style/properties/cascade.rs @@ -6,25 +6,27 @@ use crate::applicable_declarations::CascadePriority; use crate::color::AbsoluteColor; +use crate::computed_value_flags::ComputedValueFlags; use crate::context::QuirksMode; use crate::custom_properties::CustomPropertiesBuilder; use crate::dom::TElement; use crate::font_metrics::FontMetricsOrientation; -use crate::values::specified::length::FontBaseSize; use crate::logical_geometry::WritingMode; use crate::media_queries::Device; -use crate::properties::{ - CSSWideKeyword, ComputedValueFlags, ComputedValues, DeclarationImportanceIterator, Importance, - LonghandId, LonghandIdSet, PropertyDeclaration, PropertyDeclarationId, PropertyFlags, - ShorthandsWithPropertyReferencesCache, StyleBuilder, CASCADE_PROPERTY, +use crate::properties::declaration_block::{DeclarationImportanceIterator, Importance}; +use crate::properties::generated::{ + CSSWideKeyword, ComputedValues, LonghandId, LonghandIdSet, PropertyDeclaration, + PropertyDeclarationId, PropertyFlags, ShorthandsWithPropertyReferencesCache, StyleBuilder, + CASCADE_PROPERTY, }; use crate::rule_cache::{RuleCache, RuleCacheConditions}; -use crate::rule_tree::{StrongRuleNode, CascadeLevel}; +use crate::rule_tree::{CascadeLevel, StrongRuleNode}; use crate::selector_parser::PseudoElement; use crate::shared_lock::StylesheetGuards; use crate::style_adjuster::StyleAdjuster; -use crate::stylesheets::{Origin, layer_rule::LayerOrder}; use crate::stylesheets::container_rule::ContainerSizeQuery; +use crate::stylesheets::{layer_rule::LayerOrder, Origin}; +use crate::values::specified::length::FontBaseSize; use crate::values::{computed, specified}; use fxhash::FxHashMap; use servo_arc::Arc; @@ -595,7 +597,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { declaration.value.substitute_variables( declaration.id, self.context.builder.writing_mode, - self.context.builder.custom_properties.as_ref(), + self.context.builder.custom_properties(), self.context.quirks_mode, self.context.device(), cache, @@ -958,14 +960,16 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { }; let font = builder.mutate_font(); - font.mFont.family.families.prioritize_first_generic_or_prepend(default_font_type); + font.mFont + .family + .families + .prioritize_first_generic_or_prepend(default_font_type); } /// Some keyword sizes depend on the font family and language. #[cfg(feature = "gecko")] fn recompute_keyword_font_size_if_needed(&mut self) { use crate::values::computed::ToComputedValue; - use crate::values::specified; if !self.seen.contains(LonghandId::XLang) && !self.seen.contains(LonghandId::FontFamily) { return; @@ -1077,7 +1081,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { return; } - const SCALE_FACTOR_WHEN_INCREMENTING_MATH_DEPTH_BY_ONE : f32 = 0.71; + const SCALE_FACTOR_WHEN_INCREMENTING_MATH_DEPTH_BY_ONE: f32 = 0.71; // Helper function that calculates the scale factor applied to font-size // when math-depth goes from parent_math_depth to computed_math_depth. @@ -1160,7 +1164,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { parent_font.mMathDepth as i32, font.mMathDepth as i32, font_metrics.script_percent_scale_down, - font_metrics.script_script_percent_scale_down + font_metrics.script_script_percent_scale_down, ) }; diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index 152e111bd86ec..7f35ee6410af8 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -6,11 +6,16 @@ #![deny(missing_docs)] -use super::*; +use super::generated::{ + shorthands, AllShorthand, ComputedValues, LogicalGroupSet, LonghandIdSet, + NonCustomPropertyIdSet, PropertyDeclaration, PropertyDeclarationId, PropertyId, ShorthandId, + SourcePropertyDeclaration, SourcePropertyDeclarationDrain, SubpropertiesVec, +}; use crate::applicable_declarations::CascadePriority; use crate::context::QuirksMode; use crate::custom_properties::{self, CustomPropertiesBuilder}; use crate::error_reporting::{ContextualParseError, ParseErrorReporter}; +use crate::media_queries::Device; use crate::parser::ParserContext; use crate::properties::animated_properties::{AnimationValue, AnimationValueMap}; use crate::rule_tree::CascadeLevel; @@ -26,6 +31,7 @@ use cssparser::{ }; use itertools::Itertools; use selectors::SelectorList; +use servo_arc::Arc; use smallbitvec::{self, SmallBitVec}; use smallvec::SmallVec; use std::fmt::{self, Write}; diff --git a/servo/components/style/properties/mod.rs b/servo/components/style/properties/mod.rs new file mode 100644 index 0000000000000..c6fe96c393883 --- /dev/null +++ b/servo/components/style/properties/mod.rs @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! Supported CSS properties and the cascade. + +pub mod declaration_block; +pub mod cascade; + +/// The CSS properties supported by the style system. +/// Generated from the properties.mako.rs template by build.rs +#[macro_use] +#[allow(unsafe_code)] +#[deny(missing_docs)] +pub mod generated { + include!(concat!(env!("OUT_DIR"), "/properties.rs")); + + #[cfg(feature = "gecko")] + #[allow(unsafe_code, missing_docs)] + pub mod gecko { + include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs")); + } +} + +pub use self::cascade::*; +pub use self::declaration_block::*; +pub use self::generated::*; diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 5b89ff7e99f47..3a0ab1d728699 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -48,9 +48,7 @@ use crate::rule_tree::StrongRuleNode; use crate::Zero; use crate::str::{CssString, CssStringWriter}; use std::cell::Cell; - -pub use self::declaration_block::*; -pub use self::cascade::*; +use super::declaration_block::AppendableValue; <%! from collections import defaultdict @@ -59,11 +57,6 @@ pub use self::cascade::*; import os.path %> -#[path="${repr(os.path.join(os.path.dirname(__file__), 'declaration_block.rs'))[1:-1]}"] -pub mod declaration_block; -#[path="${repr(os.path.join(os.path.dirname(__file__), 'cascade.rs'))[1:-1]}"] -pub mod cascade; - /// Conversion with fewer impls than From/Into pub trait MaybeBoxed { /// Convert @@ -428,7 +421,7 @@ impl PropertyDeclaration { /// Returns the color value of a given property, for high-contrast-mode /// tweaks. - pub(crate) fn color_value(&self) -> Option<<&crate::values::specified::Color> { + pub(super) fn color_value(&self) -> Option<<&crate::values::specified::Color> { ${static_longhand_id_set("COLOR_PROPERTIES", lambda p: p.predefined_type == "Color")} <% # sanity check @@ -1004,7 +997,7 @@ impl LonghandIdSet { /// Only a few properties are allowed to depend on the visited state of /// links. When cascading visited styles, we can save time by only /// processing these properties. - fn visited_dependent() -> &'static Self { + pub(super) fn visited_dependent() -> &'static Self { ${static_longhand_id_set( "VISITED_DEPENDENT", lambda p: is_visited_dependent(p) @@ -1014,7 +1007,7 @@ impl LonghandIdSet { } #[inline] - fn writing_mode_group() -> &'static Self { + pub(super) fn writing_mode_group() -> &'static Self { ${static_longhand_id_set( "WRITING_MODE_GROUP", lambda p: p.name in CASCADE_GROUPS["writing_mode"] @@ -1023,7 +1016,7 @@ impl LonghandIdSet { } #[inline] - fn fonts_and_color_group() -> &'static Self { + pub(super) fn fonts_and_color_group() -> &'static Self { ${static_longhand_id_set( "FONTS_AND_COLOR_GROUP", lambda p: p.name in CASCADE_GROUPS["fonts_and_color"] @@ -1032,13 +1025,13 @@ impl LonghandIdSet { } #[inline] - fn late_group_only_inherited() -> &'static Self { + pub(super) fn late_group_only_inherited() -> &'static Self { ${static_longhand_id_set("LATE_GROUP_ONLY_INHERITED", lambda p: p.style_struct.inherited and in_late_group(p))} &LATE_GROUP_ONLY_INHERITED } #[inline] - fn late_group() -> &'static Self { + pub(super) fn late_group() -> &'static Self { ${static_longhand_id_set("LATE_GROUP", lambda p: in_late_group(p))} &LATE_GROUP } @@ -1271,7 +1264,8 @@ impl LonghandId { !LonghandIdSet::reset().contains(self) } - fn shorthands(&self) -> NonCustomPropertyIterator { + /// Returns an iterator over all the shorthands that include this longhand. + pub fn shorthands(&self) -> NonCustomPropertyIterator { // first generate longhand to shorthands lookup map // // NOTE(emilio): This currently doesn't exclude the "all" shorthand. It @@ -1440,7 +1434,7 @@ impl LonghandId { /// Returns true if the property is one that is ignored when document /// colors are disabled. #[inline] - fn ignored_when_document_colors_disabled(self) -> bool { + pub fn ignored_when_document_colors_disabled(self) -> bool { LonghandIdSet::ignored_when_colors_disabled().contains(self) } } @@ -1709,7 +1703,7 @@ pub type ShorthandsWithPropertyReferencesCache = FxHashMap<(ShorthandId, LonghandId), PropertyDeclaration>; impl UnparsedValue { - fn substitute_variables<'cache>( + pub(super) fn substitute_variables<'cache>( &self, longhand_id: LonghandId, writing_mode: WritingMode, @@ -2231,10 +2225,12 @@ pub struct WideKeywordDeclaration { #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, PartialEq, ToCss, ToShmem)] pub struct VariableDeclaration { + /// The id of the property this declaration represents. #[css(skip)] - id: LonghandId, + pub id: LonghandId, + /// The unparsed value of the variable. #[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")] - value: Arc, + pub value: Arc, } /// A custom property declaration value is either an unparsed value or a CSS @@ -2592,16 +2588,17 @@ const SUB_PROPERTIES_ARRAY_CAP: usize = ${max(len(s.sub_properties) for s in data.shorthands_except_all()) \ if data.shorthands_except_all() else 0}; -type SubpropertiesVec = ArrayVec; +/// An ArrayVec of subproperties, contains space for the longest shorthand except all. +pub type SubpropertiesVec = ArrayVec; /// A stack-allocated vector of `PropertyDeclaration` /// large enough to parse one CSS `key: value` declaration. /// (Shorthands expand to multiple `PropertyDeclaration`s.) pub struct SourcePropertyDeclaration { - declarations: SubpropertiesVec, - + /// The storage for the actual declarations (except for all). + pub declarations: SubpropertiesVec, /// Stored separately to keep SubpropertiesVec smaller. - all_shorthand: AllShorthand, + pub all_shorthand: AllShorthand, } // This is huge, but we allocate it on the stack and then never move it, @@ -2652,20 +2649,26 @@ impl SourcePropertyDeclaration { /// Return type of SourcePropertyDeclaration::drain pub struct SourcePropertyDeclarationDrain<'a> { - declarations: ArrayVecDrain<'a, PropertyDeclaration, SUB_PROPERTIES_ARRAY_CAP>, - all_shorthand: AllShorthand, + /// A drain over the non-all declarations. + pub declarations: ArrayVecDrain<'a, PropertyDeclaration, SUB_PROPERTIES_ARRAY_CAP>, + /// The all shorthand that was set. + pub all_shorthand: AllShorthand, } -enum AllShorthand { +/// A parsed all-shorthand value. +pub enum AllShorthand { + /// Not present. NotSet, + /// A CSS-wide keyword. CSSWideKeyword(CSSWideKeyword), + /// An all shorthand with var() references that we can't resolve right now. WithVariables(Arc) } impl AllShorthand { /// Iterates property declarations from the given all shorthand value. #[inline] - fn declarations(&self) -> AllShorthandDeclarationIterator { + pub fn declarations(&self) -> AllShorthandDeclarationIterator { AllShorthandDeclarationIterator { all_shorthand: self, longhands: ShorthandId::All.longhands(), @@ -2673,7 +2676,8 @@ impl AllShorthand { } } -struct AllShorthandDeclarationIterator<'a> { +/// An iterator over the all shorthand's shorthand declarations. +pub struct AllShorthandDeclarationIterator<'a> { all_shorthand: &'a AllShorthand, longhands: NonCustomPropertyIterator, } @@ -2701,7 +2705,7 @@ impl<'a> Iterator for AllShorthandDeclarationIterator<'a> { } #[cfg(feature = "gecko")] -pub use crate::gecko_properties::style_structs; +pub use super::gecko::style_structs; /// The module where all the style structs are defined. #[cfg(feature = "servo")] @@ -3013,7 +3017,7 @@ pub mod style_structs { #[cfg(feature = "gecko")] -pub use crate::gecko_properties::{ComputedValues, ComputedValuesInner}; +pub use super::gecko::{ComputedValues, ComputedValuesInner}; #[cfg(feature = "servo")] #[cfg_attr(feature = "servo", derive(Clone, Debug))] @@ -3684,7 +3688,7 @@ pub struct StyleBuilder<'a> { /// The element's style if visited, only computed if there's a relevant link /// for this element. A element's "relevant link" is the element being /// matched if it is a link or the nearest ancestor link. - visited_style: Option>, + pub visited_style: Option>, % for style_struct in data.active_style_structs(): ${style_struct.ident}: StyleStructRef<'a, style_structs::${style_struct.name}>, % endfor @@ -3692,7 +3696,7 @@ pub struct StyleBuilder<'a> { impl<'a> StyleBuilder<'a> { /// Trivially construct a `StyleBuilder`. - fn new( + pub(super) fn new( device: &'a Device, parent_style: Option<<&'a ComputedValues>, parent_style_ignoring_first_line: Option<<&'a ComputedValues>, @@ -3977,13 +3981,13 @@ impl<'a> StyleBuilder<'a> { } /// Clears the "have any reset structs been modified" flag. - fn clear_modified_reset(&mut self) { + pub fn clear_modified_reset(&mut self) { self.modified_reset = false; } /// Returns whether we have mutated any reset structs since the the last /// time `clear_modified_reset` was called. - fn modified_reset(&self) -> bool { + pub fn modified_reset(&self) -> bool { self.modified_reset } @@ -4023,10 +4027,7 @@ impl<'a> StyleBuilder<'a> { } /// Get the custom properties map if necessary. - /// - /// Cloning the Arc here is fine because it only happens in the case where - /// we have custom properties, and those are both rare and expensive. - fn custom_properties(&self) -> Option<<&Arc> { + pub fn custom_properties(&self) -> Option<<&Arc> { self.custom_properties.as_ref() } diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index a235f04ecac5f..fbd276287d6c2 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -4313,7 +4313,7 @@ pub extern "C" fn Servo_StyleSet_Init(doc: &structs::Document) -> *mut PerDocume // Do this here rather than in Servo_Initialize since we need a document to // get the default computed values from. - style::gecko_properties::assert_initial_values_match(&data); + style::properties::generated::gecko::assert_initial_values_match(&data); Box::into_raw(data) as *mut PerDocumentStyleData }