diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 1125261dce4..a6571d0e093 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -662,8 +662,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> if node_is_input_or_text_area { style = self.style_context() .stylist - .style_for_anonymous_box(&PseudoElement::ServoInputText, &style, - &self.style_context().default_computed_values) + .style_for_anonymous_box(&PseudoElement::ServoInputText, + &style) } self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style) @@ -1100,7 +1100,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let wrapper_style = self.style_context() .stylist .style_for_anonymous_box(&PseudoElement::ServoTableWrapper, - &table_style, &self.style_context().default_computed_values); + &table_style); let wrapper_fragment = Fragment::from_opaque_node_and_style(node.opaque(), PseudoElementType::Normal, @@ -2080,7 +2080,8 @@ impl Legalizer { let reference_block = reference.as_block(); let mut new_style = reference_block.fragment.style.clone(); for pseudo in pseudos { - new_style = context.stylist.style_for_anonymous_box(pseudo, &new_style, &context.default_computed_values) + new_style = context.stylist.style_for_anonymous_box(pseudo, + &new_style) } let fragment = reference_block.fragment .create_similar_anonymous_fragment(new_style, diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 529100c06d8..d3e28e5f48d 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -114,7 +114,6 @@ use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter}; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; use style::parser::ParserContextExtraData; -use style::properties::ComputedValues; use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets}; use style::stylist::Stylist; @@ -510,11 +509,6 @@ impl LayoutThread { local_context_creation_data: Mutex::new(thread_local_style_context_creation_data), timer: self.timer.clone(), quirks_mode: self.quirks_mode.unwrap(), - // 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. - default_computed_values: Arc::new(ComputedValues::initial_values().clone()), }, image_cache_thread: Mutex::new(self.image_cache_thread.clone()), font_cache_thread: Mutex::new(self.font_cache_thread.clone()), diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index d8768384245..0e7cb160334 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -407,7 +407,6 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + context.stylist.precomputed_values_for_pseudo( &style_pseudo, Some(data.styles().primary.values()), - &context.default_computed_values, CascadeFlags::empty()); data.styles_mut().pseudos .insert(style_pseudo.clone(), new_style); @@ -424,8 +423,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + .lazily_compute_pseudo_element_style( unsafe { &self.unsafe_get() }, &style_pseudo, - data.styles().primary.values(), - &context.default_computed_values); + data.styles().primary.values()); data.styles_mut().pseudos .insert(style_pseudo.clone(), new_style.unwrap()); } diff --git a/components/style/animation.rs b/components/style/animation.rs index aa167efe3e5..27c10401e2d 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -431,7 +431,6 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, iter, previous_style, previous_style, - &context.default_computed_values, /* cascade_info = */ None, context.error_reporter.clone(), /* Metrics provider */ None, diff --git a/components/style/context.rs b/components/style/context.rs index fa3e6182c0f..a40c0679b76 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -14,7 +14,6 @@ use error_reporting::ParseErrorReporter; use euclid::Size2D; use matching::StyleSharingCandidateCache; use parking_lot::RwLock; -use properties::ComputedValues; use selector_parser::PseudoElement; use selectors::matching::ElementSelectorFlags; use servo_config::opts; @@ -84,10 +83,6 @@ pub struct SharedStyleContext { /// The QuirksMode state which the document needs to be rendered with pub quirks_mode: QuirksMode, - - /// The default computed values to use for elements with no rules - /// applying to them. - pub default_computed_values: Arc, } impl SharedStyleContext { diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index 89c18fa6a06..627b3845051 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -103,7 +103,7 @@ impl PerDocumentStyleDataImpl { /// Get the default computed values for this document. pub fn default_computed_values(&self) -> &Arc { - self.stylist.device.default_values_arc() + self.stylist.device.default_computed_values_arc() } } diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 0b52da21668..4b557aa2f8c 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -54,10 +54,16 @@ impl Device { /// Returns the default computed values as a reference, in order to match /// Servo. - pub fn default_values(&self) -> &ComputedValues { + pub fn default_computed_values(&self) -> &ComputedValues { &*self.default_values } + /// Returns the default computed values, but wrapped in an arc for cheap + /// cloning. + pub fn default_computed_values_arc(&self) -> &Arc { + &self.default_values + } + /// Returns the default computed values as an `Arc`, in order to avoid /// clones. pub fn default_values_arc(&self) -> &Arc { @@ -491,7 +497,7 @@ impl Expression { self.feature.mRangeType == nsMediaFeature_RangeType::eMinMaxAllowed, "Whoops, wrong range"); - let default_values = device.default_values(); + let default_values = device.default_computed_values(); // http://dev.w3.org/csswg/mediaqueries3/#units // em units are relative to the initial font-size. diff --git a/components/style/matching.rs b/components/style/matching.rs index ceb021227b6..00a0a187844 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -543,7 +543,6 @@ trait PrivateMatchMethods: TElement { rule_node, inherited_values, layout_parent_style, - &shared_context.default_computed_values, Some(&mut cascade_info), shared_context.error_reporter.clone(), cascade_flags)); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index aa059acb258..691f5cb5641 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -83,7 +83,7 @@ pub struct ComputedValues { } impl ComputedValues { - pub fn inherit_from(parent: &Arc, default: &Arc) -> Arc { + pub fn inherit_from(parent: &Self, default: &Self) -> Arc { Arc::new(ComputedValues { custom_properties: parent.custom_properties.clone(), shareable: parent.shareable, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index eb4628ce8be..a6cdc1af632 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1807,16 +1807,24 @@ pub fn cascade(device: &Device, rule_node: &StrongRuleNode, parent_style: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>, - default_style: &ComputedValues, cascade_info: Option<<&mut CascadeInfo>, error_reporter: StdBox, flags: CascadeFlags) -> ComputedValues { debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some()); let (is_root_element, inherited_style, layout_parent_style) = match parent_style { - Some(parent_style) => (false, parent_style, layout_parent_style.unwrap()), - None => (true, &*default_style, &*default_style), + Some(parent_style) => { + (false, + parent_style, + layout_parent_style.unwrap()) + }, + None => { + (true, + device.default_computed_values(), + device.default_computed_values()) + } }; + // Hold locks until after the apply_declarations() call returns. // Use filter_map because the root node has no style source. let lock_guards = rule_node.self_and_ancestors().filter_map(|node| { @@ -1841,7 +1849,6 @@ pub fn cascade(device: &Device, iter_declarations, inherited_style, layout_parent_style, - default_style, cascade_info, error_reporter, None, @@ -1855,7 +1862,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device, iter_declarations: F, inherited_style: &ComputedValues, layout_parent_style: &ComputedValues, - default_style: &ComputedValues, mut cascade_info: Option<<&mut CascadeInfo>, mut error_reporter: StdBox, font_metrics_provider: Option<<&FontMetricsProvider>, @@ -1864,6 +1870,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device, where F: Fn() -> I, I: Iterator, { + let default_style = device.default_computed_values(); let inherited_custom_properties = inherited_style.custom_properties(); let mut custom_properties = None; let mut seen_custom = HashSet::new(); diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index ffea9e5e1bc..75bd789766f 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -39,7 +39,10 @@ impl Device { } /// Return the default computed values for this device. - pub fn default_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. ComputedValues::initial_values() } @@ -171,7 +174,7 @@ pub enum Range { impl Range { fn to_computed_range(&self, device: &Device) -> Range { - let default_values = device.default_values(); + let default_values = device.default_computed_values(); // http://dev.w3.org/csswg/mediaqueries3/#units // em units are relative to the initial font-size. let context = computed::Context { diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 069c8f21a26..7acb9baf641 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -295,7 +295,6 @@ impl Stylist { pub fn precomputed_values_for_pseudo(&self, pseudo: &PseudoElement, parent: Option<&Arc>, - default: &ComputedValues, cascade_flags: CascadeFlags) -> ComputedStyle { debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); @@ -329,7 +328,6 @@ impl Stylist { &rule_node, parent.map(|p| &**p), parent.map(|p| &**p), - default, None, Box::new(StdoutErrorReporter), cascade_flags); @@ -340,8 +338,7 @@ impl Stylist { #[cfg(feature = "servo")] pub fn style_for_anonymous_box(&self, pseudo: &PseudoElement, - parent_style: &Arc, - default_style: &ComputedValues) + parent_style: &Arc) -> Arc { // For most (but not all) pseudo-elements, we inherit all values from the parent. let inherit_all = match *pseudo { @@ -364,7 +361,7 @@ impl Stylist { if inherit_all { cascade_flags.insert(INHERIT_ALL); } - self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), default_style, cascade_flags) + self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), cascade_flags) .values.unwrap() } @@ -378,8 +375,7 @@ impl Stylist { pub fn lazily_compute_pseudo_element_style(&self, element: &E, pseudo: &PseudoElement, - parent: &Arc, - default: &Arc) + parent: &Arc) -> Option where E: TElement + fmt::Debug + @@ -414,7 +410,6 @@ impl Stylist { &rule_node, Some(&**parent), Some(&**parent), - default, None, Box::new(StdoutErrorReporter), CascadeFlags::empty()); diff --git a/components/style/viewport.rs b/components/style/viewport.rs index d01d734a2d2..9c364dc7249 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -688,9 +688,9 @@ impl MaybeNew for ViewportConstraints { let context = Context { is_root_element: false, device: device, - inherited_style: device.default_values(), - layout_parent_style: device.default_values(), - style: device.default_values().clone(), + inherited_style: device.default_computed_values(), + layout_parent_style: device.default_computed_values(), + style: device.default_computed_values().clone(), font_metrics_provider: None, // TODO: Should have! }; diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 2c36b5d1123..b46540dc5cf 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -171,7 +171,6 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle timer: Timer::new(), // FIXME Find the real QuirksMode information for this document quirks_mode: QuirksMode::NoQuirks, - default_computed_values: per_doc_data.default_computed_values().clone(), } } @@ -634,7 +633,6 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP); } data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, - data.default_computed_values(), cascade_flags) .values.unwrap() .into_strong() @@ -680,8 +678,7 @@ fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom, let base = styles.primary.values(); d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, - base, - &d.default_computed_values()) + base) .map(|s| s.values().clone()) }, } @@ -1438,7 +1435,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis let style = ComputedValues::as_arc(&style); let parent_style = parent_style.as_ref().map(|r| &**ComputedValues::as_arc(&r)); - let default_values = data.stylist.device.default_values(); + let default_values = data.default_computed_values(); let context = Context { is_root_element: false,