From fe8638a6185e231c1a4886a60ca1e41d7943dea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 18 Jul 2017 16:47:13 +0200 Subject: [PATCH] style: More ComputedValuesInner cleanup. MozReview-Commit-ID: 8rkAP3pMEpD --- components/style/dom.rs | 4 ++-- .../style/properties/declaration_block.rs | 6 ++--- .../helpers/animated_properties.mako.rs | 12 +++++----- .../style/properties/properties.mako.rs | 9 ++++---- components/style/servo/media_queries.rs | 2 +- components/style/style_adjuster.rs | 22 +++++++++---------- ports/geckolib/glue.rs | 5 +++-- tests/unit/style/parsing/mod.rs | 7 +++--- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/components/style/dom.rs b/components/style/dom.rs index c14b59b763a..abc733cb0b2 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -15,7 +15,7 @@ use data::ElementData; use element_state::ElementState; use font_metrics::FontMetricsProvider; use media_queries::Device; -use properties::{AnimationRules, ComputedValues, ComputedValuesInner, PropertyDeclarationBlock}; +use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock}; #[cfg(feature = "gecko")] use properties::animated_properties::AnimationValue; #[cfg(feature = "gecko")] use properties::animated_properties::TransitionProperty; use rule_tree::CascadeLevel; @@ -437,7 +437,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone + fn may_generate_pseudo( &self, pseudo: &PseudoElement, - _primary_style: &ComputedValuesInner, + _primary_style: &ComputedValues, ) -> bool { // ::before/::after are always supported for now, though we could try to // optimize out leaf elements. diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 0e2bb0eb040..3570fc7210b 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -110,13 +110,13 @@ impl<'a> Iterator for PropertyDeclarationIterator<'a> { pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> { iter: Iter<'a, (PropertyDeclaration, Importance)>, context: &'cx mut Context<'cx_a>, - default_values: &'a ComputedValuesInner, + default_values: &'a ComputedValues, } impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> { fn new(declarations: &'a PropertyDeclarationBlock, context: &'cx mut Context<'cx_a>, - default_values: &'a ComputedValuesInner) -> AnimationValueIterator<'a, 'cx, 'cx_a> { + default_values: &'a ComputedValues) -> AnimationValueIterator<'a, 'cx, 'cx_a> { AnimationValueIterator { iter: declarations.declarations().iter(), context: context, @@ -204,7 +204,7 @@ impl PropertyDeclarationBlock { /// Return an iterator of (AnimatableLonghand, AnimationValue). pub fn to_animation_value_iter<'a, 'cx, 'cx_a:'cx>(&'a self, context: &'cx mut Context<'cx_a>, - default_values: &'a ComputedValuesInner) + default_values: &'a ComputedValues) -> AnimationValueIterator<'a, 'cx, 'cx_a> { AnimationValueIterator::new(self, context, default_values) } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index f4c16093f91..d81028284e3 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -29,7 +29,7 @@ use smallvec::SmallVec; use std::cmp; #[cfg(feature = "gecko")] use fnv::FnvHashMap; use style_traits::ParseError; -use super::ComputedValuesInner; +use super::ComputedValues; #[cfg(any(feature = "gecko", feature = "testing"))] use values::Auto; use values::{CSSFloat, CustomIdent, Either}; @@ -394,7 +394,7 @@ impl AnimatedProperty { /// Update `style` with the proper computed style corresponding to this /// animation at `progress`. - pub fn update(&self, style: &mut ComputedValuesInner, progress: f64) { + pub fn update(&self, style: &mut ComputedValues, progress: f64) { match *self { % for prop in data.longhands: % if prop.animatable: @@ -427,8 +427,8 @@ impl AnimatedProperty { /// Get an animatable value from a transition-property, an old style, and a /// new style. pub fn from_animatable_longhand(property: &AnimatableLonghand, - old_style: &ComputedValuesInner, - new_style: &ComputedValuesInner) + old_style: &ComputedValues, + new_style: &ComputedValues) -> AnimatedProperty { match *property { % for prop in data.longhands: @@ -521,7 +521,7 @@ impl AnimationValue { /// Construct an AnimationValue from a property declaration pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, - initial: &ComputedValuesInner) -> Option { + initial: &ComputedValues) -> Option { use properties::LonghandId; match *decl { @@ -593,7 +593,7 @@ impl AnimationValue { /// Get an AnimationValue for an AnimatableLonghand from a given computed values. pub fn from_computed_values(property: &AnimatableLonghand, - computed_values: &ComputedValuesInner) + computed_values: &ComputedValues) -> Self { match *property { % for prop in data.longhands: diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index cbf12c2cf6a..7fb32603173 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -124,6 +124,11 @@ impl FontComputationData { pub fn default_font_size_keyword() -> Option<(longhands::font_size::KeywordSize, f32)> { Some((Default::default(), 1.)) } + + /// Gets a FontComputationData with the default values. + pub fn default_values() -> Self { + Self::new(Self::default_font_size_keyword()) + } } impl MaybeBoxed for T { @@ -1953,10 +1958,6 @@ impl ComputedValues { /// Get the initial computed values. pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } - - /// Servo doesn't track the pseudo-element, so no need to do anything fancy - /// here. - fn pseudo(&self) -> Option<<&PseudoElement> { None } } #[cfg(feature = "servo")] diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index c9d42a68388..3570fb1d66b 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -62,7 +62,7 @@ impl Device { } /// Return the default computed values for this device. - pub fn default_computed_values(&self) -> &ComputedValues{ + pub fn default_computed_values(&self) -> &ComputedValues { // FIXME(bz): This isn't really right, but it's no more wrong // than what we used to do. See // https://github.com/servo/servo/issues/14773 for fixing it properly. diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 72c4e675c8b..805a7063cb1 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -6,7 +6,7 @@ //! a computed style needs in order for it to adhere to the CSS spec. use app_units::Au; -use properties::{self, CascadeFlags, ComputedValuesInner}; +use properties::{self, CascadeFlags, ComputedValues}; use properties::{IS_ROOT_ELEMENT, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, StyleBuilder}; use properties::longhands::display::computed_value::T as display; use properties::longhands::float::computed_value::T as float; @@ -54,7 +54,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Apply the blockification rules based on the table in CSS 2.2 section 9.7. /// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo fn blockify_if_necessary(&mut self, - layout_parent_style: &ComputedValuesInner, + layout_parent_style: &ComputedValues, flags: CascadeFlags) { let mut blockify = false; macro_rules! blockify_if { @@ -136,7 +136,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html /// https://github.com/servo/servo/issues/15754 fn adjust_for_writing_mode(&mut self, - layout_parent_style: &ComputedValuesInner) { + layout_parent_style: &ComputedValues) { let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode(); let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode(); @@ -196,7 +196,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// /// See https://github.com/servo/servo/issues/15229 #[cfg(feature = "servo")] - fn adjust_for_alignment(&mut self, layout_parent_style: &ComputedValuesInner) { + fn adjust_for_alignment(&mut self, layout_parent_style: &ComputedValues) { use computed_values::align_items::T as align_items; use computed_values::align_self::T as align_self; @@ -295,7 +295,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// this type into its ::-moz-fieldset-content anonymous box. #[cfg(feature = "gecko")] fn adjust_for_fieldset_content(&mut self, - layout_parent_style: &ComputedValuesInner, + layout_parent_style: &ComputedValues, flags: CascadeFlags) { use properties::IS_FIELDSET_CONTENT; if !flags.contains(IS_FIELDSET_CONTENT) { @@ -340,7 +340,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } /// Set the HAS_TEXT_DECORATION_LINES flag based on parent style. - fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValuesInner) { + fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValues) { use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES; if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) || !self.style.get_text().clone_text_decoration_line().is_empty() { @@ -349,7 +349,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } #[cfg(feature = "gecko")] - fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValuesInner) -> bool { + fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool { use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; // Line break suppression should only be propagated to in-flow children. if self.style.floated() || self.style.out_of_flow_positioned() { @@ -386,8 +386,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// * correct unicode-bidi. #[cfg(feature = "gecko")] fn adjust_for_ruby(&mut self, - layout_parent_style: &ComputedValuesInner, - default_computed_values: &'b ComputedValuesInner, + layout_parent_style: &ComputedValues, + default_computed_values: &'b ComputedValues, flags: CascadeFlags) { use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; @@ -431,8 +431,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// When comparing to Gecko, this is similar to the work done by /// `nsStyleContext::ApplyStyleFixups`. pub fn adjust(&mut self, - layout_parent_style: &ComputedValuesInner, - _default_computed_values: &'b ComputedValuesInner, + layout_parent_style: &ComputedValues, + _default_computed_values: &'b ComputedValues, flags: CascadeFlags) { #[cfg(feature = "gecko")] { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index edb8050c145..b56d56c8e85 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -723,15 +723,16 @@ pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawSe } #[no_mangle] -pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(computed_values: ServoComputedValuesBorrowed, +pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(computed_values: ServoStyleContextBorrowed, property_id: nsCSSPropertyID) -> RawServoAnimationValueStrong { let property = match AnimatableLonghand::from_nscsspropertyid(property_id) { Some(longhand) => longhand, - None => { return Strong::null(); } + None => return Strong::null(), }; + let computed_values = ComputedValues::as_arc(&computed_values); Arc::new(AnimationValue::from_computed_values(&property, computed_values)).into_strong() } diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index a896e6f9aa3..ab1038de1d1 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -11,7 +11,7 @@ use style::context::QuirksMode; use style::font_metrics::ServoMetricsProvider; use style::media_queries::{Device, MediaType}; use style::parser::ParserContext; -use style::properties::{ComputedValues, ComputedValuesInner, StyleBuilder}; +use style::properties::{ComputedValues, StyleBuilder}; use style::stylesheets::{CssRuleType, Origin}; use style::values::computed::{Context, ToComputedValue}; use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError}; @@ -49,15 +49,14 @@ fn assert_computed_serialization(f: F, input: &'static str, output: &st T: ToComputedValue, C: ToCss { let viewport_size = TypedSize2D::new(0., 0.); - let initial_style = ComputedValuesInner::initial_values(); + let initial_style = ComputedValues::initial_values(); let device = Device::new(MediaType::Screen, viewport_size); let context = Context { is_root_element: true, device: &device, inherited_style: initial_style, - layout_parent_style: initial_style, - style: StyleBuilder::for_derived_style(&initial_style), + style: StyleBuilder::for_derived_style(&device, initial_style, None), cached_system_font: None, font_metrics_provider: &ServoMetricsProvider, in_media_query: false,