Skip to content

Commit

Permalink
Make it possible to construct StyleBuilder with two different inherit…
Browse files Browse the repository at this point in the history
…ed styles.

Part 3 of Gecko bug 1382806.  r=emilio
  • Loading branch information
bzbarsky committed Jul 26, 2017
1 parent f991b76 commit 048044f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/style/animation.rs
Expand Up @@ -499,6 +499,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
iter,
Some(previous_style),
Some(previous_style),
Some(previous_style),
/* cascade_info = */ None,
/* visited_style = */ None,
font_metrics_provider,
Expand Down
36 changes: 35 additions & 1 deletion components/style/properties/properties.mako.rs
Expand Up @@ -14,6 +14,7 @@ use servo_arc::{Arc, UniqueArc};
use std::borrow::Cow;
use std::collections::HashSet;
use std::{fmt, mem, ops};
#[cfg(feature = "gecko")] use std::ptr;

use app_units::Au;
#[cfg(feature = "servo")] use cssparser::RGBA;
Expand Down Expand Up @@ -2512,6 +2513,7 @@ impl<'a> StyleBuilder<'a> {
fn new(
device: &'a Device,
parent_style: Option<<&'a ComputedValues>,
parent_style_ignoring_first_line: Option<<&'a ComputedValues>,
pseudo: Option<<&'a PseudoElement>,
cascade_flags: CascadeFlags,
rules: Option<StrongRuleNode>,
Expand All @@ -2521,8 +2523,19 @@ impl<'a> StyleBuilder<'a> {
flags: ComputedValueFlags,
visited_style: Option<Arc<ComputedValues>>,
) -> Self {
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
#[cfg(feature = "gecko")]
debug_assert!(parent_style.is_none() ||
ptr::eq(parent_style.unwrap(),
parent_style_ignoring_first_line.unwrap()) ||
parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine));
let reset_style = device.default_computed_values();
let inherited_style = parent_style.unwrap_or(reset_style);
let inherited_style_ignoring_first_line = parent_style_ignoring_first_line.unwrap_or(reset_style);
// FIXME(bz): INHERIT_ALL seems like a fundamentally broken idea. I'm
// 99% sure it should give incorrect behavior for table anonymous box
// backgrounds, for example. This code doesn't attempt to make it play
// nice with inherited_style_ignoring_first_line.
let reset_style = if cascade_flags.contains(INHERIT_ALL) {
inherited_style
} else {
Expand All @@ -2533,7 +2546,7 @@ impl<'a> StyleBuilder<'a> {
device,
parent_style,
inherited_style,
inherited_style_ignoring_first_line: inherited_style,
inherited_style_ignoring_first_line,
reset_style,
pseudo,
rules,
Expand Down Expand Up @@ -2562,10 +2575,14 @@ impl<'a> StyleBuilder<'a> {
) -> Self {
let reset_style = device.default_computed_values();
let inherited_style = parent_style.unwrap_or(reset_style);
#[cfg(feature = "gecko")]
debug_assert!(parent_style.is_none() ||
parent_style.unwrap().pseudo() != Some(PseudoElement::FirstLine));
StyleBuilder {
device,
parent_style,
inherited_style,
// None of our callers pass in ::first-line parent styles.
inherited_style_ignoring_first_line: inherited_style,
reset_style,
pseudo,
Expand Down Expand Up @@ -2651,6 +2668,7 @@ impl<'a> StyleBuilder<'a> {
Self::new(
device,
Some(parent),
Some(parent),
pseudo,
CascadeFlags::empty(),
/* rules = */ None,
Expand Down Expand Up @@ -2910,13 +2928,20 @@ pub fn cascade(
rule_node: &StrongRuleNode,
guards: &StylesheetGuards,
parent_style: Option<<&ComputedValues>,
parent_style_ignoring_first_line: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
cascade_info: Option<<&mut CascadeInfo>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode
) -> Arc<ComputedValues> {
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
#[cfg(feature = "gecko")]
debug_assert!(parent_style.is_none() ||
ptr::eq(parent_style.unwrap(),
parent_style_ignoring_first_line.unwrap()) ||
parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine));
let iter_declarations = || {
rule_node.self_and_ancestors().flat_map(|node| {
let cascade_level = node.cascade_level();
Expand Down Expand Up @@ -2962,6 +2987,7 @@ pub fn cascade(
rule_node,
iter_declarations,
parent_style,
parent_style_ignoring_first_line,
layout_parent_style,
visited_style,
cascade_info,
Expand All @@ -2980,6 +3006,7 @@ pub fn apply_declarations<'a, F, I>(
rules: &StrongRuleNode,
iter_declarations: F,
parent_style: Option<<&ComputedValues>,
parent_style_ignoring_first_line: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>,
visited_style: Option<Arc<ComputedValues>>,
mut cascade_info: Option<<&mut CascadeInfo>,
Expand All @@ -2992,6 +3019,12 @@ where
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
{
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
#[cfg(feature = "gecko")]
debug_assert!(parent_style.is_none() ||
ptr::eq(parent_style.unwrap(),
parent_style_ignoring_first_line.unwrap()) ||
parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine));
let (inherited_style, layout_parent_style) = match parent_style {
Some(parent_style) => {
(parent_style,
Expand Down Expand Up @@ -3026,6 +3059,7 @@ where
builder: StyleBuilder::new(
device,
parent_style,
parent_style_ignoring_first_line,
pseudo,
flags,
Some(rules.clone()),
Expand Down
1 change: 1 addition & 0 deletions components/style/style_resolver.rs
Expand Up @@ -479,6 +479,7 @@ where
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
&self.context.shared.guards,
parent_style,
parent_style,
layout_parent_style,
style_if_visited,
Some(&mut cascade_info),
Expand Down
4 changes: 4 additions & 0 deletions components/style/stylist.rs
Expand Up @@ -637,6 +637,7 @@ impl Stylist {
guards,
parent,
parent,
parent,
None,
None,
font_metrics,
Expand Down Expand Up @@ -753,6 +754,7 @@ impl Stylist {
guards,
Some(inherited_style),
Some(inherited_style),
Some(inherited_style),
None,
None,
font_metrics,
Expand All @@ -778,6 +780,7 @@ impl Stylist {
guards,
Some(parent_style),
Some(parent_style),
Some(parent_style),
visited_values,
None,
font_metrics,
Expand Down Expand Up @@ -1342,6 +1345,7 @@ impl Stylist {
guards,
Some(parent_style),
Some(parent_style),
Some(parent_style),
None,
None,
&metrics,
Expand Down

0 comments on commit 048044f

Please sign in to comment.