Skip to content

Commit 8b7a414

Browse files
heycamemilio
authored andcommitted
style: Use RestyleDamage to determine whether we must continue cascading style changes to children.
1 parent 715d18d commit 8b7a414

File tree

5 files changed

+221
-109
lines changed

5 files changed

+221
-109
lines changed

components/layout/animation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ pub fn recalc_style_for_animations(context: &LayoutContext,
160160
animation,
161161
&mut fragment.style,
162162
&ServoMetricsProvider);
163-
damage |= RestyleDamage::compute(&old_style, &fragment.style);
163+
let difference =
164+
RestyleDamage::compute_style_difference(&old_style, &fragment.style);
165+
damage |= difference.damage;
164166
}
165167
}
166168
});

components/style/gecko/restyle_damage.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gecko_bindings::bindings;
88
use gecko_bindings::structs;
99
use gecko_bindings::structs::{nsChangeHint, nsStyleContext};
1010
use gecko_bindings::sugar::ownership::FFIArcHelpers;
11+
use matching::{StyleChange, StyleDifference};
1112
use properties::ComputedValues;
1213
use std::ops::{BitAnd, BitOr, BitOrAssign, Not};
1314
use stylearc::Arc;
@@ -38,15 +39,17 @@ impl GeckoRestyleDamage {
3839
self.0 == nsChangeHint(0)
3940
}
4041

41-
/// Computes a change hint given an old style (in the form of a
42-
/// `nsStyleContext`, and a new style (in the form of `ComputedValues`).
42+
/// Computes the `StyleDifference` (including the appropriate change hint)
43+
/// given an old style (in the form of a `nsStyleContext`, and a new style
44+
/// (in the form of `ComputedValues`).
4345
///
4446
/// Note that we could in theory just get two `ComputedValues` here and diff
4547
/// them, but Gecko has an interesting optimization when they mark accessed
4648
/// structs, so they effectively only diff structs that have ever been
4749
/// accessed from layout.
48-
pub fn compute(source: &nsStyleContext,
49-
new_style: &Arc<ComputedValues>) -> Self {
50+
pub fn compute_style_difference(source: &nsStyleContext,
51+
new_style: &Arc<ComputedValues>)
52+
-> StyleDifference {
5053
// TODO(emilio): Const-ify this?
5154
let context = source as *const nsStyleContext as *mut nsStyleContext;
5255
let mut any_style_changed: bool = false;
@@ -55,7 +58,8 @@ impl GeckoRestyleDamage {
5558
new_style.as_borrowed_opt().unwrap(),
5659
&mut any_style_changed)
5760
};
58-
GeckoRestyleDamage(hint)
61+
let change = if any_style_changed { StyleChange::Changed } else { StyleChange::Unchanged };
62+
StyleDifference::new(GeckoRestyleDamage(hint), change)
5963
}
6064

6165
/// Returns true if this restyle damage contains all the damage of |other|.

0 commit comments

Comments
 (0)