Auto merge of #14922 - heycam:pseudo-inherit, r=emilio

Don't inherit all properties for eagerly computed pseudos if there are no matching rules.

<!-- Please describe your changes on the following line: -->

When we resolve style for an eagerly computed pseudo-element, such as an anonymous box, if there are no matching rules we currently just clone the parent's style.  We should only do that if `inherit_all` is true, otherwise we should inherit only the inherited properties from the parent.

I was going to use `.unwrap_or_default()` on the result of looking up `precomputed_pseudo_element_decls`, but that didn't seem to work since that map lookup returns a reference and not a `Vec` itself.

r? @emilio

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1329121

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14922)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-09 02:46:09 -08:00 committed by GitHub
commit ebd4a8b3ee
3 changed files with 27 additions and 27 deletions

View file

@ -394,7 +394,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
&context.default_computed_values,
false);
data.styles_mut().pseudos
.insert(style_pseudo.clone(), new_style.unwrap());
.insert(style_pseudo.clone(), new_style);
}
}
PseudoElementCascadeType::Lazy => {

View file

@ -276,14 +276,18 @@ impl Stylist {
parent: Option<&Arc<ComputedValues>>,
default: &Arc<ComputedValues>,
inherit_all: bool)
-> Option<ComputedStyle> {
-> ComputedStyle {
debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed());
if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) {
let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
Some(declarations) => {
// FIXME(emilio): When we've taken rid of the cascade we can just
// use into_iter.
let rule_node =
self.rule_tree.insert_ordered_rules(
declarations.into_iter().map(|a| (a.source.clone(), a.importance)));
declarations.into_iter().map(|a| (a.source.clone(), a.importance)))
}
None => self.rule_tree.root(),
};
let mut flags = CascadeFlags::empty();
if inherit_all {
@ -298,10 +302,7 @@ impl Stylist {
None,
Box::new(StdoutErrorReporter),
flags);
Some(ComputedStyle::new(rule_node, Arc::new(computed)))
} else {
parent.map(|p| ComputedStyle::new(self.rule_tree.root(), p.clone()))
}
ComputedStyle::new(rule_node, Arc::new(computed))
}
/// Returns the style for an anonymous box of the given type.
@ -329,7 +330,6 @@ impl Stylist {
}
};
self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), default_style, inherit_all)
.expect("style_for_anonymous_box(): No precomputed values for that pseudo!")
.values
}

View file

@ -521,10 +521,10 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(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,
data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent,
&data.default_computed_values, false)
.map(|styles| styles.values);
new_computed.map_or(Strong::null(), |c| c.into_strong())
.values
.into_strong()
}
#[no_mangle]