Bug 1298588 part 9, servo piece. Pass through useful default styles to cascade(). r=bholley

This commit is contained in:
Boris Zbarsky 2017-01-04 13:48:23 -05:00
parent 09c74190b9
commit 61f6025dc3
6 changed files with 22 additions and 10 deletions

View file

@ -661,7 +661,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, &style,
&self.style_context().default_computed_values)
} }
self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style) self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style)
@ -1093,7 +1094,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); &table_style, &self.style_context().default_computed_values);
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,
@ -2064,7 +2065,7 @@ 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) new_style = context.stylist.style_for_anonymous_box(pseudo, &new_style, &context.default_computed_values)
} }
let fragment = reference_block.fragment let fragment = reference_block.fragment
.create_similar_anonymous_fragment(new_style, .create_similar_anonymous_fragment(new_style,

View file

@ -391,6 +391,7 @@ 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,
false); false);
data.styles_mut().pseudos data.styles_mut().pseudos
.insert(style_pseudo.clone(), new_style.unwrap()); .insert(style_pseudo.clone(), new_style.unwrap());
@ -407,7 +408,8 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
.lazily_compute_pseudo_element_style( .lazily_compute_pseudo_element_style(
self, self,
&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

@ -470,6 +470,7 @@ trait PrivateMatchMethods: TElement {
cascade(shared_context.viewport_size, cascade(shared_context.viewport_size,
rule_node, rule_node,
Some(&***parent_style), Some(&***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)
@ -478,6 +479,7 @@ trait PrivateMatchMethods: TElement {
cascade(shared_context.viewport_size, cascade(shared_context.viewport_size,
rule_node, rule_node,
None, None,
&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

@ -1714,13 +1714,14 @@ bitflags! {
pub fn cascade(viewport_size: Size2D<Au>, pub fn cascade(viewport_size: Size2D<Au>,
rule_node: &StrongRuleNode, rule_node: &StrongRuleNode,
parent_style: Option<<&ComputedValues>, parent_style: Option<<&ComputedValues>,
default_style: &Arc<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 {
let (is_root_element, inherited_style) = match parent_style { let (is_root_element, inherited_style) = match parent_style {
Some(parent_style) => (false, parent_style), Some(parent_style) => (false, parent_style),
None => (true, ComputedValues::initial_values()), None => (true, &**default_style),
}; };
// 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.

View file

@ -274,6 +274,7 @@ 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: &Arc<ComputedValues>,
inherit_all: bool) inherit_all: bool)
-> Option<ComputedStyle> { -> Option<ComputedStyle> {
debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed());
@ -293,6 +294,7 @@ impl Stylist {
properties::cascade(self.device.au_viewport_size(), properties::cascade(self.device.au_viewport_size(),
&rule_node, &rule_node,
parent.map(|p| &**p), parent.map(|p| &**p),
default,
None, None,
Box::new(StdoutErrorReporter), Box::new(StdoutErrorReporter),
flags); flags);
@ -306,7 +308,8 @@ 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: &Arc<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 {
@ -325,7 +328,7 @@ impl Stylist {
unreachable!("That pseudo doesn't represent an anonymous box!") unreachable!("That pseudo doesn't represent an anonymous box!")
} }
}; };
self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), inherit_all) self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), default_style, inherit_all)
.expect("style_for_anonymous_box(): No precomputed values for that pseudo!") .expect("style_for_anonymous_box(): No precomputed values for that pseudo!")
.values .values
} }
@ -340,7 +343,8 @@ 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: ElementExt + where E: ElementExt +
fmt::Debug + fmt::Debug +
@ -368,6 +372,7 @@ impl Stylist {
properties::cascade(self.device.au_viewport_size(), properties::cascade(self.device.au_viewport_size(),
&rule_node, &rule_node,
Some(&**parent), Some(&**parent),
default,
None, None,
Box::new(StdoutErrorReporter), Box::new(StdoutErrorReporter),
CascadeFlags::empty()); CascadeFlags::empty());

View file

@ -531,7 +531,8 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
let maybe_parent = ComputedValues::arc_from_borrowed(&parent_style_or_null); let maybe_parent = ComputedValues::arc_from_borrowed(&parent_style_or_null);
let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, false) let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent,
&data.default_computed_values, false)
.map(|styles| styles.values); .map(|styles| styles.values);
new_computed.map_or(Strong::null(), |c| c.into_strong()) new_computed.map_or(Strong::null(), |c| c.into_strong())
} }
@ -574,7 +575,7 @@ fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom,
PseudoElementCascadeType::Lazy => { PseudoElementCascadeType::Lazy => {
let d = doc_data.borrow_mut(); let d = doc_data.borrow_mut();
let base = &styles.primary.values; let base = &styles.primary.values;
d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base) d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base, &d.default_computed_values)
.map(|s| s.values.clone()) .map(|s| s.values.clone())
}, },
} }