style: Kill SharedStyleContext::default_computed_values.

Now that cascade() gets a Device, we can use the default computed values from
there to avoid propagating that state all over the place.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-03-13 22:50:43 +01:00
parent 16e318d055
commit eaf27ccfa0
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
14 changed files with 41 additions and 47 deletions

View file

@ -662,8 +662,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
if node_is_input_or_text_area { if node_is_input_or_text_area {
style = self.style_context() style = self.style_context()
.stylist .stylist
.style_for_anonymous_box(&PseudoElement::ServoInputText, &style, .style_for_anonymous_box(&PseudoElement::ServoInputText,
&self.style_context().default_computed_values) &style)
} }
self.create_fragments_for_node_text_content(&mut initial_fragments, node, &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() let wrapper_style = self.style_context()
.stylist .stylist
.style_for_anonymous_box(&PseudoElement::ServoTableWrapper, .style_for_anonymous_box(&PseudoElement::ServoTableWrapper,
&table_style, &self.style_context().default_computed_values); &table_style);
let wrapper_fragment = let wrapper_fragment =
Fragment::from_opaque_node_and_style(node.opaque(), Fragment::from_opaque_node_and_style(node.opaque(),
PseudoElementType::Normal, PseudoElementType::Normal,
@ -2080,7 +2080,8 @@ impl Legalizer {
let reference_block = reference.as_block(); let reference_block = reference.as_block();
let mut new_style = reference_block.fragment.style.clone(); let mut new_style = reference_block.fragment.style.clone();
for pseudo in pseudos { 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 let fragment = reference_block.fragment
.create_similar_anonymous_fragment(new_style, .create_similar_anonymous_fragment(new_style,

View file

@ -114,7 +114,6 @@ use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter};
use style::logical_geometry::LogicalPoint; use style::logical_geometry::LogicalPoint;
use style::media_queries::{Device, MediaType}; use style::media_queries::{Device, MediaType};
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
use style::properties::ComputedValues;
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets}; use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
use style::stylist::Stylist; use style::stylist::Stylist;
@ -510,11 +509,6 @@ impl LayoutThread {
local_context_creation_data: Mutex::new(thread_local_style_context_creation_data), local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
timer: self.timer.clone(), timer: self.timer.clone(),
quirks_mode: self.quirks_mode.unwrap(), 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()), image_cache_thread: Mutex::new(self.image_cache_thread.clone()),
font_cache_thread: Mutex::new(self.font_cache_thread.clone()), font_cache_thread: Mutex::new(self.font_cache_thread.clone()),

View file

@ -407,7 +407,6 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
context.stylist.precomputed_values_for_pseudo( context.stylist.precomputed_values_for_pseudo(
&style_pseudo, &style_pseudo,
Some(data.styles().primary.values()), Some(data.styles().primary.values()),
&context.default_computed_values,
CascadeFlags::empty()); CascadeFlags::empty());
data.styles_mut().pseudos data.styles_mut().pseudos
.insert(style_pseudo.clone(), new_style); .insert(style_pseudo.clone(), new_style);
@ -424,8 +423,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
.lazily_compute_pseudo_element_style( .lazily_compute_pseudo_element_style(
unsafe { &self.unsafe_get() }, unsafe { &self.unsafe_get() },
&style_pseudo, &style_pseudo,
data.styles().primary.values(), data.styles().primary.values());
&context.default_computed_values);
data.styles_mut().pseudos data.styles_mut().pseudos
.insert(style_pseudo.clone(), new_style.unwrap()); .insert(style_pseudo.clone(), new_style.unwrap());
} }

View file

@ -431,7 +431,6 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
iter, iter,
previous_style, previous_style,
previous_style, previous_style,
&context.default_computed_values,
/* cascade_info = */ None, /* cascade_info = */ None,
context.error_reporter.clone(), context.error_reporter.clone(),
/* Metrics provider */ None, /* Metrics provider */ None,

View file

@ -14,7 +14,6 @@ use error_reporting::ParseErrorReporter;
use euclid::Size2D; use euclid::Size2D;
use matching::StyleSharingCandidateCache; use matching::StyleSharingCandidateCache;
use parking_lot::RwLock; use parking_lot::RwLock;
use properties::ComputedValues;
use selector_parser::PseudoElement; use selector_parser::PseudoElement;
use selectors::matching::ElementSelectorFlags; use selectors::matching::ElementSelectorFlags;
use servo_config::opts; use servo_config::opts;
@ -84,10 +83,6 @@ pub struct SharedStyleContext {
/// The QuirksMode state which the document needs to be rendered with /// The QuirksMode state which the document needs to be rendered with
pub quirks_mode: QuirksMode, pub quirks_mode: QuirksMode,
/// The default computed values to use for elements with no rules
/// applying to them.
pub default_computed_values: Arc<ComputedValues>,
} }
impl SharedStyleContext { impl SharedStyleContext {

View file

@ -103,7 +103,7 @@ impl PerDocumentStyleDataImpl {
/// Get the default computed values for this document. /// Get the default computed values for this document.
pub fn default_computed_values(&self) -> &Arc<ComputedValues> { pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
self.stylist.device.default_values_arc() self.stylist.device.default_computed_values_arc()
} }
} }

View file

@ -54,10 +54,16 @@ impl Device {
/// Returns the default computed values as a reference, in order to match /// Returns the default computed values as a reference, in order to match
/// Servo. /// Servo.
pub fn default_values(&self) -> &ComputedValues { pub fn default_computed_values(&self) -> &ComputedValues {
&*self.default_values &*self.default_values
} }
/// Returns the default computed values, but wrapped in an arc for cheap
/// cloning.
pub fn default_computed_values_arc(&self) -> &Arc<ComputedValues> {
&self.default_values
}
/// Returns the default computed values as an `Arc`, in order to avoid /// Returns the default computed values as an `Arc`, in order to avoid
/// clones. /// clones.
pub fn default_values_arc(&self) -> &Arc<ComputedValues> { pub fn default_values_arc(&self) -> &Arc<ComputedValues> {
@ -491,7 +497,7 @@ impl Expression {
self.feature.mRangeType == nsMediaFeature_RangeType::eMinMaxAllowed, self.feature.mRangeType == nsMediaFeature_RangeType::eMinMaxAllowed,
"Whoops, wrong range"); "Whoops, wrong range");
let default_values = device.default_values(); let default_values = device.default_computed_values();
// http://dev.w3.org/csswg/mediaqueries3/#units // http://dev.w3.org/csswg/mediaqueries3/#units
// em units are relative to the initial font-size. // em units are relative to the initial font-size.

View file

@ -543,7 +543,6 @@ trait PrivateMatchMethods: TElement {
rule_node, rule_node,
inherited_values, inherited_values,
layout_parent_style, layout_parent_style,
&shared_context.default_computed_values,
Some(&mut cascade_info), Some(&mut cascade_info),
shared_context.error_reporter.clone(), shared_context.error_reporter.clone(),
cascade_flags)); cascade_flags));

View file

@ -83,7 +83,7 @@ pub struct ComputedValues {
} }
impl ComputedValues { impl ComputedValues {
pub fn inherit_from(parent: &Arc<Self>, default: &Arc<Self>) -> Arc<Self> { pub fn inherit_from(parent: &Self, default: &Self) -> Arc<Self> {
Arc::new(ComputedValues { Arc::new(ComputedValues {
custom_properties: parent.custom_properties.clone(), custom_properties: parent.custom_properties.clone(),
shareable: parent.shareable, shareable: parent.shareable,

View file

@ -1807,16 +1807,24 @@ pub fn cascade(device: &Device,
rule_node: &StrongRuleNode, rule_node: &StrongRuleNode,
parent_style: Option<<&ComputedValues>, parent_style: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>,
default_style: &ComputedValues,
cascade_info: Option<<&mut CascadeInfo>, cascade_info: Option<<&mut CascadeInfo>,
error_reporter: StdBox<ParseErrorReporter + Send>, error_reporter: StdBox<ParseErrorReporter + Send>,
flags: CascadeFlags) flags: CascadeFlags)
-> ComputedValues { -> ComputedValues {
debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some()); debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some());
let (is_root_element, inherited_style, layout_parent_style) = match parent_style { let (is_root_element, inherited_style, layout_parent_style) = match parent_style {
Some(parent_style) => (false, parent_style, layout_parent_style.unwrap()), Some(parent_style) => {
None => (true, &*default_style, &*default_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. // Hold locks until after the apply_declarations() call returns.
// Use filter_map because the root node has no style source. // Use filter_map because the root node has no style source.
let lock_guards = rule_node.self_and_ancestors().filter_map(|node| { let lock_guards = rule_node.self_and_ancestors().filter_map(|node| {
@ -1841,7 +1849,6 @@ pub fn cascade(device: &Device,
iter_declarations, iter_declarations,
inherited_style, inherited_style,
layout_parent_style, layout_parent_style,
default_style,
cascade_info, cascade_info,
error_reporter, error_reporter,
None, None,
@ -1855,7 +1862,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
iter_declarations: F, iter_declarations: F,
inherited_style: &ComputedValues, inherited_style: &ComputedValues,
layout_parent_style: &ComputedValues, layout_parent_style: &ComputedValues,
default_style: &ComputedValues,
mut cascade_info: Option<<&mut CascadeInfo>, mut cascade_info: Option<<&mut CascadeInfo>,
mut error_reporter: StdBox<ParseErrorReporter + Send>, mut error_reporter: StdBox<ParseErrorReporter + Send>,
font_metrics_provider: Option<<&FontMetricsProvider>, font_metrics_provider: Option<<&FontMetricsProvider>,
@ -1864,6 +1870,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
where F: Fn() -> I, where F: Fn() -> I,
I: Iterator<Item = &'a PropertyDeclaration>, I: Iterator<Item = &'a PropertyDeclaration>,
{ {
let default_style = device.default_computed_values();
let inherited_custom_properties = inherited_style.custom_properties(); let inherited_custom_properties = inherited_style.custom_properties();
let mut custom_properties = None; let mut custom_properties = None;
let mut seen_custom = HashSet::new(); let mut seen_custom = HashSet::new();

View file

@ -39,7 +39,10 @@ impl Device {
} }
/// Return the default computed values for this 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() ComputedValues::initial_values()
} }
@ -171,7 +174,7 @@ pub enum Range<T> {
impl Range<specified::Length> { impl Range<specified::Length> {
fn to_computed_range(&self, device: &Device) -> Range<Au> { fn to_computed_range(&self, device: &Device) -> Range<Au> {
let default_values = device.default_values(); let default_values = device.default_computed_values();
// http://dev.w3.org/csswg/mediaqueries3/#units // http://dev.w3.org/csswg/mediaqueries3/#units
// em units are relative to the initial font-size. // em units are relative to the initial font-size.
let context = computed::Context { let context = computed::Context {

View file

@ -295,7 +295,6 @@ impl Stylist {
pub fn precomputed_values_for_pseudo(&self, pub fn precomputed_values_for_pseudo(&self,
pseudo: &PseudoElement, pseudo: &PseudoElement,
parent: Option<&Arc<ComputedValues>>, parent: Option<&Arc<ComputedValues>>,
default: &ComputedValues,
cascade_flags: CascadeFlags) cascade_flags: CascadeFlags)
-> ComputedStyle { -> ComputedStyle {
debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed());
@ -329,7 +328,6 @@ impl Stylist {
&rule_node, &rule_node,
parent.map(|p| &**p), parent.map(|p| &**p),
parent.map(|p| &**p), parent.map(|p| &**p),
default,
None, None,
Box::new(StdoutErrorReporter), Box::new(StdoutErrorReporter),
cascade_flags); cascade_flags);
@ -340,8 +338,7 @@ impl Stylist {
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub fn style_for_anonymous_box(&self, pub fn style_for_anonymous_box(&self,
pseudo: &PseudoElement, pseudo: &PseudoElement,
parent_style: &Arc<ComputedValues>, parent_style: &Arc<ComputedValues>)
default_style: &ComputedValues)
-> Arc<ComputedValues> { -> Arc<ComputedValues> {
// For most (but not all) pseudo-elements, we inherit all values from the parent. // For most (but not all) pseudo-elements, we inherit all values from the parent.
let inherit_all = match *pseudo { let inherit_all = match *pseudo {
@ -364,7 +361,7 @@ impl Stylist {
if inherit_all { if inherit_all {
cascade_flags.insert(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() .values.unwrap()
} }
@ -378,8 +375,7 @@ impl Stylist {
pub fn lazily_compute_pseudo_element_style<E>(&self, pub fn lazily_compute_pseudo_element_style<E>(&self,
element: &E, element: &E,
pseudo: &PseudoElement, pseudo: &PseudoElement,
parent: &Arc<ComputedValues>, parent: &Arc<ComputedValues>)
default: &Arc<ComputedValues>)
-> Option<ComputedStyle> -> Option<ComputedStyle>
where E: TElement + where E: TElement +
fmt::Debug + fmt::Debug +
@ -414,7 +410,6 @@ impl Stylist {
&rule_node, &rule_node,
Some(&**parent), Some(&**parent),
Some(&**parent), Some(&**parent),
default,
None, None,
Box::new(StdoutErrorReporter), Box::new(StdoutErrorReporter),
CascadeFlags::empty()); CascadeFlags::empty());

View file

@ -688,9 +688,9 @@ impl MaybeNew for ViewportConstraints {
let context = Context { let context = Context {
is_root_element: false, is_root_element: false,
device: device, device: device,
inherited_style: device.default_values(), inherited_style: device.default_computed_values(),
layout_parent_style: device.default_values(), layout_parent_style: device.default_computed_values(),
style: device.default_values().clone(), style: device.default_computed_values().clone(),
font_metrics_provider: None, // TODO: Should have! font_metrics_provider: None, // TODO: Should have!
}; };

View file

@ -171,7 +171,6 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle
timer: Timer::new(), timer: Timer::new(),
// FIXME Find the real QuirksMode information for this document // FIXME Find the real QuirksMode information for this document
quirks_mode: QuirksMode::NoQuirks, 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); cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP);
} }
data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent,
data.default_computed_values(),
cascade_flags) cascade_flags)
.values.unwrap() .values.unwrap()
.into_strong() .into_strong()
@ -680,8 +678,7 @@ fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom,
let base = styles.primary.values(); let base = styles.primary.values();
d.stylist.lazily_compute_pseudo_element_style(&element, d.stylist.lazily_compute_pseudo_element_style(&element,
&pseudo, &pseudo,
base, base)
&d.default_computed_values())
.map(|s| s.values().clone()) .map(|s| s.values().clone())
}, },
} }
@ -1438,7 +1435,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
let style = ComputedValues::as_arc(&style); let style = ComputedValues::as_arc(&style);
let parent_style = parent_style.as_ref().map(|r| &**ComputedValues::as_arc(&r)); 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 { let context = Context {
is_root_element: false, is_root_element: false,