mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
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:
parent
16e318d055
commit
eaf27ccfa0
14 changed files with 41 additions and 47 deletions
|
@ -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,
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<ComputedValues>,
|
||||
}
|
||||
|
||||
impl SharedStyleContext {
|
||||
|
|
|
@ -103,7 +103,7 @@ impl PerDocumentStyleDataImpl {
|
|||
|
||||
/// Get the default computed values for this document.
|
||||
pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
|
||||
self.stylist.device.default_values_arc()
|
||||
self.stylist.device.default_computed_values_arc()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ComputedValues> {
|
||||
&self.default_values
|
||||
}
|
||||
|
||||
/// Returns the default computed values as an `Arc`, in order to avoid
|
||||
/// clones.
|
||||
pub fn default_values_arc(&self) -> &Arc<ComputedValues> {
|
||||
|
@ -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.
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -83,7 +83,7 @@ pub struct 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 {
|
||||
custom_properties: parent.custom_properties.clone(),
|
||||
shareable: parent.shareable,
|
||||
|
|
|
@ -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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
font_metrics_provider: Option<<&FontMetricsProvider>,
|
||||
|
@ -1864,6 +1870,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
where F: Fn() -> I,
|
||||
I: Iterator<Item = &'a PropertyDeclaration>,
|
||||
{
|
||||
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();
|
||||
|
|
|
@ -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<T> {
|
|||
|
||||
impl Range<specified::Length> {
|
||||
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
|
||||
// em units are relative to the initial font-size.
|
||||
let context = computed::Context {
|
||||
|
|
|
@ -295,7 +295,6 @@ impl Stylist {
|
|||
pub fn precomputed_values_for_pseudo(&self,
|
||||
pseudo: &PseudoElement,
|
||||
parent: Option<&Arc<ComputedValues>>,
|
||||
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<ComputedValues>,
|
||||
default_style: &ComputedValues)
|
||||
parent_style: &Arc<ComputedValues>)
|
||||
-> Arc<ComputedValues> {
|
||||
// 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<E>(&self,
|
||||
element: &E,
|
||||
pseudo: &PseudoElement,
|
||||
parent: &Arc<ComputedValues>,
|
||||
default: &Arc<ComputedValues>)
|
||||
parent: &Arc<ComputedValues>)
|
||||
-> Option<ComputedStyle>
|
||||
where E: TElement +
|
||||
fmt::Debug +
|
||||
|
@ -414,7 +410,6 @@ impl Stylist {
|
|||
&rule_node,
|
||||
Some(&**parent),
|
||||
Some(&**parent),
|
||||
default,
|
||||
None,
|
||||
Box::new(StdoutErrorReporter),
|
||||
CascadeFlags::empty());
|
||||
|
|
|
@ -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!
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue