diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 67506a154d4..a32a6e6b99c 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -416,7 +416,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + &style_pseudo, Some(data.styles.primary()), CascadeFlags::empty(), - &ServoMetricsProvider, (), ()) + &ServoMetricsProvider) .clone() } PseudoElementCascadeType::Lazy => { @@ -428,7 +428,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + RuleInclusion::All, data.styles.primary(), /* is_probe = */ false, - &ServoMetricsProvider, (), ()) + &ServoMetricsProvider) .unwrap() .clone() } diff --git a/components/style/animation.rs b/components/style/animation.rs index 84392bead13..8d652d8e0e9 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -11,7 +11,7 @@ use context::SharedStyleContext; use dom::OpaqueNode; use euclid::Point2D; use font_metrics::FontMetricsProvider; -use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner, Importance}; +use properties::{self, CascadeFlags, ComputedValues, Importance}; use properties::animated_properties::{AnimatableLonghand, AnimatedProperty, TransitionProperty}; use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection; use properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount; @@ -347,8 +347,8 @@ impl PropertyAnimation { fn from_animatable_longhand(animatable_longhand: &AnimatableLonghand, timing_function: TimingFunction, duration: Time, - old_style: &ComputedValuesInner, - new_style: &ComputedValuesInner) + old_style: &ComputedValues, + new_style: &ComputedValues) -> Option { let animated_property = AnimatedProperty::from_animatable_longhand(animatable_longhand, old_style, @@ -480,10 +480,10 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Sender fn compute_style_for_animation_step(context: &SharedStyleContext, step: &KeyframesStep, - previous_style: &ComputedValuesInner, - style_from_cascade: &ComputedValuesInner, + previous_style: &ComputedValues, + style_from_cascade: &Arc, font_metrics_provider: &FontMetricsProvider) - -> ComputedValuesInner { + -> Arc { match step.value { KeyframesStepValue::ComputedValues => style_from_cascade.clone(), KeyframesStepValue::Declarations { block: ref declarations } => { @@ -502,10 +502,11 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, // as existing browsers don't appear to animate visited styles. let computed = properties::apply_declarations(context.stylist.device(), + /* pseudo = */ None, previous_style.rules(), iter, - previous_style, - previous_style, + Some(previous_style), + Some(previous_style), /* cascade_info = */ None, /* visited_style = */ None, font_metrics_provider, diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 4426e482b0d..408934eacf5 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -72,13 +72,46 @@ pub mod style_structs { % endfor } - +/// FIXME(emilio): This is completely duplicated with the other properties code. pub type ComputedValuesInner = ::gecko_bindings::structs::ServoComputedValues; #[derive(Debug)] #[repr(C)] pub struct ComputedValues(::gecko_bindings::structs::mozilla::ServoStyleContext); +impl ComputedValues { + pub fn new( + device: &Device, + parent: Option<<&ComputedValues>, + pseudo: Option<<&PseudoElement>, + custom_properties: Option>, + writing_mode: WritingMode, + font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>, + flags: ComputedValueFlags, + rules: Option, + visited_style: Option>, + % for style_struct in data.style_structs: + ${style_struct.ident}: Arc, + % endfor + ) -> Arc { + ComputedValuesInner::new( + custom_properties, + writing_mode, + font_size_keyword, + flags, + rules, + visited_style, + % for style_struct in data.style_structs: + ${style_struct.ident}, + % endfor + ).to_outer( + device, + parent, + pseudo.map(|p| p.pseudo_info()) + ) + } +} + impl Drop for ComputedValues { fn drop(&mut self) { unsafe { @@ -154,6 +187,7 @@ impl ComputedValuesInner { % endfor } } + pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo, info: Option) -> Arc { let (tag, ty) = if let Some(info) = info { diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 580e2fd6329..e59be799737 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -292,7 +292,7 @@ #[allow(unused_imports)] use properties::{DeclaredValue, LonghandId, LonghandIdSet}; #[allow(unused_imports)] - use properties::{CSSWideKeyword, ComputedValuesInner, PropertyDeclaration}; + use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration}; #[allow(unused_imports)] use properties::style_structs; #[allow(unused_imports)] @@ -310,8 +310,8 @@ ${caller.body()} #[allow(unused_variables)] pub fn cascade_property(declaration: &PropertyDeclaration, - inherited_style: &ComputedValuesInner, - default_style: &ComputedValuesInner, + inherited_style: &ComputedValues, + default_style: &ComputedValues, context: &mut computed::Context, cacheable: &mut bool, cascade_info: &mut Option<<&mut CascadeInfo>) { diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 10e1358e48d..f2c3c8d517e 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -181,7 +181,7 @@ % if product == "servo": fn cascade_property_custom(_declaration: &PropertyDeclaration, - _inherited_style: &ComputedValuesInner, + _inherited_style: &ComputedValues, context: &mut computed::Context, _cacheable: &mut bool) { longhands::_servo_display_for_hypothetical_box::derive_from_display(context); diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index c2ec468f7c1..3be23f1681e 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -249,7 +249,7 @@ ${helpers.single_keyword("unicode-bidi", % if product == "servo": fn cascade_property_custom(_declaration: &PropertyDeclaration, - _inherited_style: &ComputedValuesInner, + _inherited_style: &ComputedValues, context: &mut computed::Context, _cacheable: &mut bool) { longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index b04f03547a1..1244fa86b0f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -32,6 +32,7 @@ use media_queries::Device; use parser::{Parse, ParserContext}; use properties::animated_properties::AnimatableLonghand; #[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont; +use selector_parser::PseudoElement; use selectors::parser::SelectorParseError; #[cfg(feature = "servo")] use servo_config::prefs::PREFS; use shared_lock::StylesheetGuards; @@ -107,19 +108,20 @@ pub struct FontComputationData { /// /// When this is Some, we compute font sizes by computing the keyword against /// the generic font, and then multiplying it by the ratio. - pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)> + pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)> } impl FontComputationData { - /// Assigns values for variables in struct FontComputationData + /// Assigns values for variables in struct FontComputationData pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self { FontComputationData { font_size_keyword: font_size_keyword } } - /// Assigns default values for variables in struct FontComputationData - pub fn default_values() -> Self { + + /// Assigns default values for variables in struct FontComputationData + pub fn default_values() -> Self { FontComputationData{ font_size_keyword: Some((Default::default(), 1.)) } @@ -1873,14 +1875,6 @@ pub mod style_structs { #[cfg(feature = "gecko")] pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo}; -#[cfg(feature = "servo")] -/// Servo doesn't have style contexts so this is extraneous info -pub type PseudoInfo = (); -#[cfg(feature = "servo")] -/// Servo doesn't have style contexts so this is extraneous info -pub type ParentStyleContextInfo = (); - - #[cfg(feature = "servo")] #[cfg_attr(feature = "servo", derive(Clone, Debug))] /// Actual data of ComputedValues, to match up with Gecko @@ -1891,6 +1885,7 @@ pub struct ComputedValuesInner { custom_properties: Option>, /// The writing mode of this computed values struct. pub writing_mode: WritingMode, + /// The keyword behind the current font-size property, if any pub font_computation_data: FontComputationData, @@ -1923,12 +1918,51 @@ pub struct ComputedValues { /// whereas ComputedValuesInner is the core set of computed values. /// /// We maintain this distinction in servo to reduce the amount of special casing. - pub inner: ComputedValuesInner, + inner: ComputedValuesInner, +} + +impl ComputedValues { + /// Create a new refcounted `ComputedValues` + pub fn new( + _: &Device, + _: Option<<&ComputedValues>, + _: Option<<&PseudoElement>, + custom_properties: Option>, + writing_mode: WritingMode, + font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>, + flags: ComputedValueFlags, + rules: Option, + visited_style: Option>, + % for style_struct in data.active_style_structs(): + ${style_struct.ident}: Arc, + % endfor + ) -> Arc { + Arc::new(Self { + inner: ComputedValuesInner::new( + custom_properties, + writing_mode, + font_size_keyword, + flags, + rules, + visited_style, + % for style_struct in data.active_style_structs(): + ${style_struct.ident}, + % endfor + ) + }) + } + + /// 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")] impl ComputedValuesInner { - /// Construct a `ComputedValues` instance. + /// Construct a `ComputedValuesInner` instance. pub fn new( custom_properties: Option>, writing_mode: WritingMode, @@ -1952,9 +1986,6 @@ impl ComputedValuesInner { % endfor } } - - /// Get the initial computed values. - pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } } #[cfg(feature = "servo")] @@ -1974,12 +2005,6 @@ impl ops::DerefMut for ComputedValues { #[cfg(feature = "servo")] impl ComputedValuesInner { - /// Convert to an Arc - pub fn to_outer(self, _: &Device, _: ParentStyleContextInfo, - _: Option) -> Arc { - Arc::new(ComputedValues {inner: self}) - } - % for style_struct in data.active_style_structs(): /// Clone the ${style_struct.name} struct. #[inline] @@ -2428,6 +2453,9 @@ impl<'a, T: 'a> ops::Deref for StyleStructRef<'a, T> { /// actually cloning them, until we either build the style, or mutate the /// inherited value. pub struct StyleBuilder<'a> { + device: &'a Device, + parent_style: Option<<&'a ComputedValues>, + pseudo: Option<<&'a PseudoElement>, /// The rule node representing the ordered list of rules matched for this /// node. rules: Option, @@ -2452,8 +2480,11 @@ pub struct StyleBuilder<'a> { impl<'a> StyleBuilder<'a> { /// Trivially construct a `StyleBuilder`. fn new( - inherited_style: &'a ComputedValuesInner, - reset_style: &'a ComputedValuesInner, + device: &'a Device, + parent_style: Option<<&'a ComputedValues>, + reset_style: &'a ComputedValues, + pseudo: Option<<&'a PseudoElement>, + cascade_flags: CascadeFlags, rules: Option, custom_properties: Option>, writing_mode: WritingMode, @@ -2461,7 +2492,17 @@ impl<'a> StyleBuilder<'a> { flags: ComputedValueFlags, visited_style: Option>, ) -> Self { + let inherited_style = parent_style.unwrap_or(reset_style); + let reset_style = if cascade_flags.contains(INHERIT_ALL) { + inherited_style + } else { + reset_style + }; + StyleBuilder { + device, + parent_style, + pseudo, rules, custom_properties, writing_mode, @@ -2480,19 +2521,27 @@ impl<'a> StyleBuilder<'a> { /// Creates a StyleBuilder holding only references to the structs of `s`, in /// order to create a derived style. - pub fn for_derived_style(s: &'a ComputedValuesInner) -> Self { - Self::for_inheritance(s, s) + pub fn for_derived_style(device: &'a Device, s: &'a ComputedValues) -> Self { + Self::for_inheritance(device, s, s, s.pseudo()) } /// Inherits style from the parent element, accounting for the default /// computed values that need to be provided as well. pub fn for_inheritance( - parent: &'a ComputedValuesInner, - default: &'a ComputedValuesInner + device: &'a Device, + parent: &'a ComputedValues, + reset: &'a ComputedValues, + pseudo: Option<<&'a PseudoElement>, ) -> Self { + // FIXME(emilio): This Some(parent) here is inconsistent with what we + // usually do if `parent` is the default computed values, but that's + // fine, and we want to eventually get rid of it. Self::new( - parent, - default, + device, + Some(parent), + reset, + pseudo, + CascadeFlags::empty(), /* rules = */ None, parent.custom_properties(), parent.writing_mode, @@ -2566,16 +2615,20 @@ impl<'a> StyleBuilder<'a> { /// Turns this `StyleBuilder` into a proper `ComputedValues` instance. - pub fn build(self) -> ComputedValuesInner { - ComputedValuesInner::new(self.custom_properties, - self.writing_mode, - self.font_size_keyword, - self.flags, - self.rules, - self.visited_style, - % for style_struct in data.active_style_structs(): - self.${style_struct.ident}.build(), - % endfor + pub fn build(self) -> Arc { + ComputedValues::new( + self.device, + self.parent_style, + self.pseudo, + self.custom_properties, + self.writing_mode, + self.font_size_keyword, + self.flags, + self.rules, + self.visited_style, + % for style_struct in data.active_style_structs(): + self.${style_struct.ident}.build(), + % endfor ) } @@ -2597,28 +2650,30 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES; mod lazy_static_module { use logical_geometry::WritingMode; use stylearc::Arc; - use super::{ComputedValuesInner, longhands, style_structs, FontComputationData}; + use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData}; use super::computed_value_flags::ComputedValueFlags; /// The initial values for all style structs as defined by the specification. lazy_static! { - pub static ref INITIAL_SERVO_VALUES: ComputedValuesInner = ComputedValuesInner { - % for style_struct in data.active_style_structs(): - ${style_struct.ident}: Arc::new(style_structs::${style_struct.name} { - % for longhand in style_struct.longhands: - ${longhand.ident}: longhands::${longhand.ident}::get_initial_value(), - % endfor - % if style_struct.name == "Font": - hash: 0, - % endif - }), - % endfor - custom_properties: None, - writing_mode: WritingMode::empty(), - font_computation_data: FontComputationData::default_values(), - rules: None, - visited_style: None, - flags: ComputedValueFlags::empty(), + pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues { + inner: ComputedValuesInner { + % for style_struct in data.active_style_structs(): + ${style_struct.ident}: Arc::new(style_structs::${style_struct.name} { + % for longhand in style_struct.longhands: + ${longhand.ident}: longhands::${longhand.ident}::get_initial_value(), + % endfor + % if style_struct.name == "Font": + hash: 0, + % endif + }), + % endfor + custom_properties: None, + writing_mode: WritingMode::empty(), + font_computation_data: FontComputationData::default_values(), + rules: None, + visited_style: None, + flags: ComputedValueFlags::empty(), + } }; } } @@ -2626,8 +2681,8 @@ mod lazy_static_module { /// A per-longhand function that performs the CSS cascade for that longhand. pub type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration, - inherited_style: &ComputedValuesInner, - default_style: &ComputedValuesInner, + inherited_style: &ComputedValues, + default_style: &ComputedValues, context: &mut computed::Context, cacheable: &mut bool, cascade_info: &mut Option<<&mut CascadeInfo>); @@ -2688,29 +2743,19 @@ bitflags! { /// Returns the computed values. /// * `flags`: Various flags. /// -pub fn cascade(device: &Device, - rule_node: &StrongRuleNode, - guards: &StylesheetGuards, - parent_style: Option<<&ComputedValuesInner>, - layout_parent_style: Option<<&ComputedValuesInner>, - visited_style: Option>, - cascade_info: Option<<&mut CascadeInfo>, - font_metrics_provider: &FontMetricsProvider, - flags: CascadeFlags, - quirks_mode: QuirksMode) - -> ComputedValuesInner { - debug_assert!(layout_parent_style.is_none() || parent_style.is_some()); - let (inherited_style, layout_parent_style) = match parent_style { - Some(parent_style) => { - (parent_style, - layout_parent_style.unwrap_or(parent_style)) - }, - None => { - (device.default_computed_values(), - device.default_computed_values()) - } - }; - +pub fn cascade( + device: &Device, + pseudo: Option<<&PseudoElement>, + rule_node: &StrongRuleNode, + guards: &StylesheetGuards, + parent_style: Option<<&ComputedValues>, + layout_parent_style: Option<<&ComputedValues>, + visited_style: Option>, + cascade_info: Option<<&mut CascadeInfo>, + font_metrics_provider: &FontMetricsProvider, + flags: CascadeFlags, + quirks_mode: QuirksMode +) -> Arc { let iter_declarations = || { rule_node.self_and_ancestors().flat_map(|node| { let cascade_level = node.cascade_level(); @@ -2735,35 +2780,53 @@ pub fn cascade(device: &Device, }) }) }; - apply_declarations(device, - rule_node, - iter_declarations, - inherited_style, - layout_parent_style, - visited_style, - cascade_info, - font_metrics_provider, - flags, - quirks_mode) + apply_declarations( + device, + pseudo, + rule_node, + iter_declarations, + parent_style, + layout_parent_style, + visited_style, + cascade_info, + font_metrics_provider, + flags, + quirks_mode, + ) } /// NOTE: This function expects the declaration with more priority to appear /// first. #[allow(unused_mut)] // conditionally compiled code for "position" -pub fn apply_declarations<'a, F, I>(device: &Device, - rules: &StrongRuleNode, - iter_declarations: F, - inherited_style: &ComputedValuesInner, - layout_parent_style: &ComputedValuesInner, - visited_style: Option>, - mut cascade_info: Option<<&mut CascadeInfo>, - font_metrics_provider: &FontMetricsProvider, - flags: CascadeFlags, - quirks_mode: QuirksMode) - -> ComputedValuesInner - where F: Fn() -> I, - I: Iterator, +pub fn apply_declarations<'a, F, I>( + device: &Device, + pseudo: Option<<&PseudoElement>, + rules: &StrongRuleNode, + iter_declarations: F, + parent_style: Option<<&ComputedValues>, + layout_parent_style: Option<<&ComputedValues>, + visited_style: Option>, + mut cascade_info: Option<<&mut CascadeInfo>, + font_metrics_provider: &FontMetricsProvider, + flags: CascadeFlags, + quirks_mode: QuirksMode, +) -> Arc +where + F: Fn() -> I, + I: Iterator, { + debug_assert!(layout_parent_style.is_none() || parent_style.is_some()); + let (inherited_style, layout_parent_style) = match parent_style { + Some(parent_style) => { + (parent_style, + layout_parent_style.unwrap_or(parent_style)) + }, + None => { + (device.default_computed_values(), + device.default_computed_values()) + } + }; + let default_style = device.default_computed_values(); let inherited_custom_properties = inherited_style.custom_properties(); let mut custom_properties = None; @@ -2780,23 +2843,19 @@ pub fn apply_declarations<'a, F, I>(device: &Device, ::custom_properties::finish_cascade( custom_properties, &inherited_custom_properties); - let reset_style = if flags.contains(INHERIT_ALL) { - inherited_style - } else { - default_style - }; - let mut context = computed::Context { is_root_element: flags.contains(IS_ROOT_ELEMENT), device: device, inherited_style: inherited_style, - layout_parent_style: layout_parent_style, // We'd really like to own the rules here to avoid refcount traffic, but // animation's usage of `apply_declarations` make this tricky. See bug // 1375525. style: StyleBuilder::new( - inherited_style, - reset_style, + device, + parent_style, + device.default_computed_values(), + pseudo, + flags, Some(rules.clone()), custom_properties, WritingMode::empty(), @@ -3038,8 +3097,11 @@ pub fn apply_declarations<'a, F, I>(device: &Device, { StyleAdjuster::new(&mut style) - .adjust(context.layout_parent_style, - context.device.default_computed_values(), flags); + .adjust( + layout_parent_style, + context.device.default_computed_values(), + flags + ); } % if product == "gecko": diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index ba758af514d..3fe2640de72 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -11,7 +11,7 @@ use euclid::{Size2D, TypedSize2D}; use font_metrics::ServoMetricsProvider; use media_queries::MediaType; use parser::ParserContext; -use properties::{ComputedValuesInner, StyleBuilder}; +use properties::{ComputedValues, StyleBuilder}; use properties::longhands::font_size; use selectors::parser::SelectorParseError; use std::fmt; @@ -62,11 +62,11 @@ impl Device { } /// Return the default computed values for this device. - pub fn default_computed_values(&self) -> &ComputedValuesInner { + 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. - ComputedValuesInner::initial_values() + ComputedValues::initial_values() } /// Get the font size of the root element (for rem) @@ -231,8 +231,7 @@ impl Range { is_root_element: false, device: device, inherited_style: default_values, - layout_parent_style: default_values, - style: StyleBuilder::for_derived_style(default_values), + style: StyleBuilder::for_derived_style(device, default_values), // Servo doesn't support font metrics // A real provider will be needed here once we do; since // ch units can exist in media queries. diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index c4323ca6b60..0ef0d17c88c 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -11,7 +11,7 @@ use data::{ElementStyles, EagerPseudoStyles}; use dom::TElement; use log::LogLevel::Trace; use matching::{CascadeVisitedMode, MatchMethods}; -use properties::{AnimationRules, CascadeFlags, ComputedValues, ComputedValuesInner}; +use properties::{AnimationRules, CascadeFlags, ComputedValues}; use properties::{IS_ROOT_ELEMENT, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP}; use properties::{VISITED_DEPENDENT_ONLY, cascade}; use rule_tree::StrongRuleNode; @@ -47,7 +47,7 @@ pub struct PrimaryStyle { fn with_default_parent_styles(element: E, f: F) -> R where E: TElement, - F: FnOnce(Option<&ComputedValues>, Option<&ComputedValuesInner>) -> R, + F: FnOnce(Option<&ComputedValues>, Option<&ComputedValues>) -> R, { let parent_el = element.inheritance_parent(); let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data()); @@ -72,7 +72,7 @@ where layout_parent_style = Some(layout_parent_data.styles.primary()); } - f(parent_style.map(|x| &**x), layout_parent_style.map(|s| &***s)) + f(parent_style.map(|x| &**x), layout_parent_style.map(|s| &**s)) } impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E> @@ -99,7 +99,7 @@ where pub fn resolve_primary_style( &mut self, parent_style: Option<&ComputedValues>, - layout_parent_style: Option<&ComputedValuesInner>, + layout_parent_style: Option<&ComputedValues>, ) -> PrimaryStyle { let primary_results = self.match_primary(VisitedHandlingMode::AllLinksUnvisited); @@ -147,7 +147,7 @@ where pub fn resolve_style( &mut self, parent_style: Option<&ComputedValues>, - layout_parent_style: Option<&ComputedValuesInner>, + layout_parent_style: Option<&ComputedValues>, ) -> ElementStyles { use properties::longhands::display::computed_value::T as display; @@ -168,7 +168,7 @@ where if primary_style.style.is_display_contents() { layout_parent_style } else { - Some(&**primary_style.style) + Some(&*primary_style.style) }; SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { let pseudo_style = self.resolve_pseudo_style( @@ -216,7 +216,7 @@ where &mut self, inputs: CascadeInputs, parent_style: Option<&ComputedValues>, - layout_parent_style: Option<&ComputedValuesInner>, + layout_parent_style: Option<&ComputedValues>, pseudo: Option<&PseudoElement>, ) -> Arc { let mut style_if_visited = None; @@ -272,7 +272,7 @@ where if primary_style.style.is_display_contents() { layout_parent_style } else { - Some(&**primary_style.style) + Some(&*primary_style.style) }; for (i, mut inputs) in pseudo_array.unwrap().iter_mut().enumerate() { @@ -302,7 +302,7 @@ where &mut self, pseudo: &PseudoElement, originating_element_style: &PrimaryStyle, - layout_parent_style: Option<&ComputedValuesInner>, + layout_parent_style: Option<&ComputedValues>, ) -> Option> { let rules = self.match_pseudo( &originating_element_style.style, @@ -398,7 +398,7 @@ where fn match_pseudo( &mut self, - originating_element_style: &ComputedValuesInner, + originating_element_style: &ComputedValues, pseudo_element: &PseudoElement, visited_handling: VisitedHandlingMode, ) -> Option { @@ -463,7 +463,7 @@ where rules: Option<&StrongRuleNode>, style_if_visited: Option>, mut parent_style: Option<&ComputedValues>, - layout_parent_style: Option<&ComputedValuesInner>, + layout_parent_style: Option<&ComputedValues>, cascade_visited: CascadeVisitedMode, pseudo: Option<&PseudoElement>, ) -> Arc { @@ -485,17 +485,14 @@ where cascade_flags.insert(IS_ROOT_ELEMENT); } - #[cfg(feature = "gecko")] - let parent_style_context = parent_style; - #[cfg(feature = "servo")] - let parent_style_context = (); - + let implemented_pseudo = self.element.implemented_pseudo_element(); let values = cascade( self.context.shared.stylist.device(), + pseudo.or(implemented_pseudo.as_ref()), rules.unwrap_or(self.context.shared.stylist.rule_tree().root()), &self.context.shared.guards, - parent_style.map(|x| &**x), + parent_style, layout_parent_style, style_if_visited, Some(&mut cascade_info), @@ -506,17 +503,6 @@ where cascade_info.finish(&self.element.as_node()); - // In case of NAC like ::placeholder we style it via - // cascade_primary without a PseudoElement, but - // the element itself is a pseudo, so try to use that - // when `pseudo` is unset - let pseudo_info = if let Some(pseudo) = pseudo { - Some(pseudo.pseudo_info()) - } else { - self.element.implemented_pseudo_element().map(|x| x.pseudo_info()) - }; - values.to_outer(self.context.shared.stylist.device(), - parent_style_context, - pseudo_info) + values } } diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index e2d826228a5..787eda5525a 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -702,13 +702,11 @@ impl MaybeNew for ViewportConstraints { let default_values = device.default_computed_values(); - // TODO(emilio): Stop cloning `ComputedValues` around! let context = Context { is_root_element: false, device: device, inherited_style: default_values, - layout_parent_style: default_values, - style: StyleBuilder::for_derived_style(default_values), + style: StyleBuilder::for_derived_style(device, default_values), font_metrics_provider: &provider, cached_system_font: None, in_media_query: false, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index ac57c187b27..99c39930ea4 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -16,8 +16,8 @@ use gecko_bindings::structs::{nsIAtom, StyleRuleInclusion}; use invalidation::element::invalidation_map::InvalidationMap; use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey}; use media_queries::Device; -use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner}; -use properties::{AnimationRules, PropertyDeclarationBlock, PseudoInfo, ParentStyleContextInfo}; +use properties::{self, CascadeFlags, ComputedValues}; +use properties::{AnimationRules, PropertyDeclarationBlock}; #[cfg(feature = "servo")] use properties::INHERIT_ALL; use rule_tree::{CascadeLevel, RuleTree, StyleSource}; @@ -599,11 +599,9 @@ impl Stylist { pub fn precomputed_values_for_pseudo(&self, guards: &StylesheetGuards, pseudo: &PseudoElement, - parent: Option<&ComputedValuesInner>, + parent: Option<&ComputedValues>, cascade_flags: CascadeFlags, - font_metrics: &FontMetricsProvider, - pseudo_info: PseudoInfo, - parent_style_context: ParentStyleContextInfo) + font_metrics: &FontMetricsProvider) -> Arc { debug_assert!(pseudo.is_precomputed()); @@ -632,6 +630,7 @@ impl Stylist { // the actual used value, and the computed value of it would need // blockification. properties::cascade(&self.device, + Some(pseudo), &rule_node, guards, parent, @@ -640,8 +639,7 @@ impl Stylist { None, font_metrics, cascade_flags, - self.quirks_mode).to_outer(self.device(), parent_style_context, - Some(pseudo_info)) + self.quirks_mode) } /// Returns the style for an anonymous box of the given type. @@ -649,7 +647,7 @@ impl Stylist { pub fn style_for_anonymous(&self, guards: &StylesheetGuards, pseudo: &PseudoElement, - parent_style: &ComputedValuesInner) + parent_style: &ComputedValues) -> Arc { use font_metrics::ServoMetricsProvider; @@ -678,7 +676,7 @@ impl Stylist { cascade_flags.insert(INHERIT_ALL); } self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags, - &ServoMetricsProvider, (), ()) + &ServoMetricsProvider) } /// Computes a pseudo-element style lazily during layout. @@ -693,22 +691,19 @@ impl Stylist { element: &E, pseudo: &PseudoElement, rule_inclusion: RuleInclusion, - parent_style: &ComputedValuesInner, + parent_style: &ComputedValues, is_probe: bool, - font_metrics: &FontMetricsProvider, - pseudo_info: PseudoInfo, - parent_style_context: ParentStyleContextInfo) + font_metrics: &FontMetricsProvider) -> Option> where E: TElement, { let cascade_inputs = self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion); self.compute_pseudo_element_style_with_inputs(&cascade_inputs, + pseudo, guards, parent_style, - font_metrics, - pseudo_info, - parent_style_context) + font_metrics) } /// Computes a pseudo-element style lazily using the given CascadeInputs. @@ -717,11 +712,10 @@ impl Stylist { /// their style with a new parent style. pub fn compute_pseudo_element_style_with_inputs(&self, inputs: &CascadeInputs, + pseudo: &PseudoElement, guards: &StylesheetGuards, - parent_style: &ComputedValuesInner, - font_metrics: &FontMetricsProvider, - pseudo_info: PseudoInfo, - parent_style_context: ParentStyleContextInfo) + parent_style: &ComputedValues, + font_metrics: &FontMetricsProvider) -> Option> { // We may have only visited rules in cases when we are actually @@ -743,7 +737,7 @@ impl Stylist { // We want to use the visited bits (if any) from our parent style as // our parent. let inherited_style = - parent_style.get_visited_style().map(|x| &**x).unwrap_or(parent_style); + parent_style.get_visited_style().unwrap_or(parent_style); // FIXME(emilio): The lack of layout_parent_style here could be // worrying, but we're probably dropping the display fixup for @@ -752,6 +746,7 @@ impl Stylist { // (Though the flags don't indicate so!) let computed = properties::cascade(&self.device, + Some(pseudo), rule_node, guards, Some(inherited_style), @@ -760,8 +755,7 @@ impl Stylist { None, font_metrics, CascadeFlags::empty(), - self.quirks_mode).to_outer(self.device(), parent_style_context, - Some(pseudo_info.clone())); + self.quirks_mode); Some(computed) } else { @@ -777,17 +771,16 @@ impl Stylist { // (tl;dr: It doesn't apply for replaced elements and such, but the // computed value is still "contents"). Some(properties::cascade(&self.device, - rules, - guards, - Some(parent_style), - Some(parent_style), - visited_values, - None, - font_metrics, - CascadeFlags::empty(), - self.quirks_mode).to_outer(self.device(), - parent_style_context, - Some(pseudo_info))) + Some(pseudo), + rules, + guards, + Some(parent_style), + Some(parent_style), + visited_values, + None, + font_metrics, + CascadeFlags::empty(), + self.quirks_mode)) } /// Computes the cascade inputs for a lazily-cascaded pseudo-element. @@ -1324,9 +1317,8 @@ impl Stylist { /// Computes styles for a given declaration with parent_style. pub fn compute_for_declarations(&self, guards: &StylesheetGuards, - parent_style: &ComputedValuesInner, - declarations: Arc>, - parent_style_context: ParentStyleContextInfo) + parent_style: &ComputedValues, + declarations: Arc>) -> Arc { use font_metrics::get_metrics_provider_for_product; @@ -1341,7 +1333,9 @@ impl Stylist { // font styles in via Servo_StyleSet_ResolveForDeclarations. // It is unclear if visited styles are meaningful for this case. let metrics = get_metrics_provider_for_product(); + // FIXME(emilio): the pseudo bit looks quite dubious! properties::cascade(&self.device, + /* pseudo = */ None, &rule_node, guards, Some(parent_style), @@ -1350,7 +1344,7 @@ impl Stylist { None, &metrics, CascadeFlags::empty(), - self.quirks_mode).to_outer(self.device(), parent_style_context, None) + self.quirks_mode) } /// Accessor for a shared reference to the device. diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 689967da295..ed6635eb01b 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -486,7 +486,7 @@ where StyleResolverForElement::new(*ancestor, context, rule_inclusion) .resolve_primary_style( style.as_ref().map(|s| &**s), - layout_parent_style.as_ref().map(|s| &***s) + layout_parent_style.as_ref().map(|s| &**s) ); let is_display_contents = primary_style.style.is_display_contents(); @@ -503,7 +503,7 @@ where StyleResolverForElement::new(element, context, rule_inclusion) .resolve_style( style.as_ref().map(|s| &**s), - layout_parent_style.as_ref().map(|s| &***s) + layout_parent_style.as_ref().map(|s| &**s) ) } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 8d06fe57a7b..329a83b2d0b 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -11,7 +11,7 @@ use font_metrics::FontMetricsProvider; use media_queries::Device; #[cfg(feature = "gecko")] use properties; -use properties::{ComputedValuesInner, StyleBuilder}; +use properties::{ComputedValues, StyleBuilder}; use std::f32; use std::f64; use std::f64::consts::PI; @@ -72,13 +72,7 @@ pub struct Context<'a> { pub device: &'a Device, /// The style we're inheriting from. - pub inherited_style: &'a ComputedValuesInner, - - /// The style of the layout parent node. This will almost always be - /// `inherited_style`, except when `display: contents` is at play, in which - /// case it's the style of the last ancestor with a `display` value that - /// isn't `contents`. - pub layout_parent_style: &'a ComputedValuesInner, + pub inherited_style: &'a ComputedValues, /// Values accessed through this need to be in the properties "computed /// early": color, text-decoration, font-size, display, position, float, @@ -115,7 +109,7 @@ impl<'a> Context<'a> { /// The current viewport size. pub fn viewport_size(&self) -> Size2D { self.device.au_viewport_size() } /// The style we're inheriting from. - pub fn inherited_style(&self) -> &ComputedValuesInner { &self.inherited_style } + pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style } /// The current style. Note that only "eager" properties should be accessed /// from here, see the comment in the member. pub fn style(&self) -> &StyleBuilder { &self.style }