Auto merge of #19551 - emilio:anon-box-visited, r=heycam

style: Make anon boxes account for :visited.

This should fix one of the test failures of:

  https://bugzilla.mozilla.org/show_bug.cgi?id=616436

<!-- 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/19551)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-12-13 22:47:38 -06:00 committed by GitHub
commit c258bfb430
2 changed files with 61 additions and 62 deletions

View file

@ -666,7 +666,7 @@ impl Stylist {
parent, parent,
cascade_flags, cascade_flags,
font_metrics, font_metrics,
&rule_node rule_node
) )
} }
@ -679,37 +679,19 @@ impl Stylist {
parent: Option<&ComputedValues>, parent: Option<&ComputedValues>,
cascade_flags: CascadeFlags, cascade_flags: CascadeFlags,
font_metrics: &FontMetricsProvider, font_metrics: &FontMetricsProvider,
rule_node: &StrongRuleNode rule_node: StrongRuleNode
) -> Arc<ComputedValues> { ) -> Arc<ComputedValues> {
// NOTE(emilio): We skip calculating the proper layout parent style self.compute_pseudo_element_style_with_inputs(
// here. &CascadeInputs {
// rules: Some(rule_node),
// It'd be fine to assert that this isn't called with a parent style visited_rules: None,
// where display contents is in effect, but in practice this is hard to },
// do for stuff like :-moz-fieldset-content with a pseudo,
// <fieldset style="display: contents">. That is, the computed value of
// display for the fieldset is "contents", even though it's not the used
// value, so we don't need to adjust in a different way anyway.
//
// In practice, I don't think any anonymous content can be a direct
// descendant of a display: contents element where display: contents is
// the actual used value, and the computed value of it would need
// blockification.
properties::cascade(
&self.device,
Some(pseudo),
rule_node,
guards, guards,
parent, parent,
parent,
parent,
None,
font_metrics, font_metrics,
cascade_flags, cascade_flags,
self.quirks_mode, ).unwrap()
/* rule_cache = */ None,
&mut Default::default(),
)
} }
/// Returns the rule node for given precomputed pseudo-element. /// Returns the rule node for given precomputed pseudo-element.
@ -835,8 +817,9 @@ impl Stylist {
&cascade_inputs, &cascade_inputs,
pseudo, pseudo,
guards, guards,
parent_style, Some(parent_style),
font_metrics, font_metrics,
CascadeFlags::empty(),
) )
} }
@ -849,8 +832,9 @@ impl Stylist {
inputs: &CascadeInputs, inputs: &CascadeInputs,
pseudo: &PseudoElement, pseudo: &PseudoElement,
guards: &StylesheetGuards, guards: &StylesheetGuards,
parent_style: &ComputedValues, parent_style: Option<&ComputedValues>,
font_metrics: &FontMetricsProvider font_metrics: &FontMetricsProvider,
cascade_flags: CascadeFlags,
) -> Option<Arc<ComputedValues>> { ) -> Option<Arc<ComputedValues>> {
// We may have only visited rules in cases when we are actually // We may have only visited rules in cases when we are actually
// resolving, not probing, pseudo-element style. // resolving, not probing, pseudo-element style.
@ -863,6 +847,13 @@ impl Stylist {
// pseudos other than before and after, so it's probably ok. // pseudos other than before and after, so it's probably ok.
// //
// (Though the flags don't indicate so!) // (Though the flags don't indicate so!)
//
// It'd be fine to assert that this isn't called with a parent style
// where display contents is in effect, but in practice this is hard to
// do for stuff like :-moz-fieldset-content with a
// <fieldset style="display: contents">. That is, the computed value of
// display for the fieldset is "contents", even though it's not the used
// value, so we don't need to adjust in a different way anyway.
Some(self.compute_style_with_inputs( Some(self.compute_style_with_inputs(
inputs, inputs,
Some(pseudo), Some(pseudo),
@ -871,7 +862,7 @@ impl Stylist {
parent_style, parent_style,
parent_style, parent_style,
font_metrics, font_metrics,
CascadeFlags::empty(), cascade_flags,
)) ))
} }
@ -895,15 +886,18 @@ impl Stylist {
inputs: &CascadeInputs, inputs: &CascadeInputs,
pseudo: Option<&PseudoElement>, pseudo: Option<&PseudoElement>,
guards: &StylesheetGuards, guards: &StylesheetGuards,
parent_style: &ComputedValues, parent_style: Option<&ComputedValues>,
parent_style_ignoring_first_line: &ComputedValues, parent_style_ignoring_first_line: Option<&ComputedValues>,
layout_parent_style: &ComputedValues, layout_parent_style: Option<&ComputedValues>,
font_metrics: &FontMetricsProvider, font_metrics: &FontMetricsProvider,
cascade_flags: CascadeFlags cascade_flags: CascadeFlags
) -> Arc<ComputedValues> { ) -> Arc<ComputedValues> {
// We need to compute visited values if we have visited rules or if our // We need to compute visited values if we have visited rules or if our
// parent has visited values. // parent has visited values.
let visited_values = if inputs.visited_rules.is_some() || parent_style.visited_style().is_some() { let mut visited_values = None;
if inputs.visited_rules.is_some() ||
parent_style.and_then(|s| s.visited_style()).is_some()
{
// At this point inputs may have visited rules, or rules, or both, // At this point inputs may have visited rules, or rules, or both,
// or neither (e.g. if it's a text style it may have neither). So // or neither (e.g. if it's a text style it may have neither). So
// we have to be a bit careful here. // we have to be a bit careful here.
@ -923,31 +917,35 @@ impl Stylist {
// We want to use the visited bits (if any) from our parent // We want to use the visited bits (if any) from our parent
// style as our parent. // style as our parent.
inherited_style = inherited_style =
parent_style.visited_style().unwrap_or(parent_style); parent_style.map(|parent_style| {
parent_style.visited_style().unwrap_or(parent_style)
});
inherited_style_ignoring_first_line = inherited_style_ignoring_first_line =
parent_style_ignoring_first_line.visited_style().unwrap_or(parent_style_ignoring_first_line); parent_style_ignoring_first_line.map(|parent_style| {
parent_style.visited_style().unwrap_or(parent_style)
});
layout_parent_style_for_visited = layout_parent_style_for_visited =
layout_parent_style.visited_style().unwrap_or(layout_parent_style); layout_parent_style.map(|parent_style| {
parent_style.visited_style().unwrap_or(parent_style)
});
} }
Some(properties::cascade( visited_values = Some(properties::cascade(
&self.device, &self.device,
pseudo, pseudo,
rule_node, rule_node,
guards, guards,
Some(inherited_style), inherited_style,
Some(inherited_style_ignoring_first_line), inherited_style_ignoring_first_line,
Some(layout_parent_style_for_visited), layout_parent_style_for_visited,
None, None,
font_metrics, font_metrics,
cascade_flags | CascadeFlags::VISITED_DEPENDENT_ONLY, cascade_flags | CascadeFlags::VISITED_DEPENDENT_ONLY,
self.quirks_mode, self.quirks_mode,
/* rule_cache = */ None, /* rule_cache = */ None,
&mut Default::default(), &mut Default::default(),
)) ));
} else { }
None
};
// We may not have non-visited rules, if we only had visited ones. In // We may not have non-visited rules, if we only had visited ones. In
// that case we want to use the root rulenode for our non-visited rules. // that case we want to use the root rulenode for our non-visited rules.
@ -962,9 +960,9 @@ impl Stylist {
pseudo, pseudo,
rules, rules,
guards, guards,
Some(parent_style), parent_style,
Some(parent_style_ignoring_first_line), parent_style_ignoring_first_line,
Some(layout_parent_style), layout_parent_style,
visited_values, visited_values,
font_metrics, font_metrics,
cascade_flags, cascade_flags,

View file

@ -2028,7 +2028,7 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
parent_style_or_null.map(|x| &*x), parent_style_or_null.map(|x| &*x),
cascade_flags, cascade_flags,
&metrics, &metrics,
&rule_node rule_node
).into() ).into()
} }
@ -2218,8 +2218,9 @@ fn get_pseudo_style(
&inputs, &inputs,
pseudo, pseudo,
&guards, &guards,
inherited_styles, Some(inherited_styles),
&metrics &metrics,
CascadeFlags::empty(),
) )
}) })
}, },
@ -3644,16 +3645,16 @@ pub extern "C" fn Servo_ReparentStyle(
} }
} }
doc_data.stylist doc_data.stylist.compute_style_with_inputs(
.compute_style_with_inputs(&inputs, &inputs,
pseudo.as_ref(), pseudo.as_ref(),
&StylesheetGuards::same(&guard), &StylesheetGuards::same(&guard),
parent_style, Some(parent_style),
parent_style_ignoring_first_line, Some(parent_style_ignoring_first_line),
layout_parent_style, Some(layout_parent_style),
&metrics, &metrics,
cascade_flags) cascade_flags,
.into() ).into()
} }
#[cfg(feature = "gecko_debug")] #[cfg(feature = "gecko_debug")]