mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Hoist possibly_expired_animations into CurrentElementInfo.
The current mechanism requires threading a lot of this state through a bunch of callsites that are several layers of abstraction above the code that actually uses this vector (which is only compiled for servo). Putting it in CurrentElementInfo gets it nicely out of the way. MozReview-Commit-ID: 9PLBKcJreN0
This commit is contained in:
parent
3beaa8d2e9
commit
788d9ad0aa
3 changed files with 23 additions and 24 deletions
|
@ -5,7 +5,7 @@
|
||||||
//! The context within which style is calculated.
|
//! The context within which style is calculated.
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use animation::Animation;
|
use animation::{Animation, PropertyAnimation};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use bloom::StyleBloom;
|
use bloom::StyleBloom;
|
||||||
use data::ElementData;
|
use data::ElementData;
|
||||||
|
@ -103,13 +103,16 @@ impl<'a> SharedStyleContext<'a> {
|
||||||
/// Information about the current element being processed. We group this together
|
/// Information about the current element being processed. We group this together
|
||||||
/// into a single struct within ThreadLocalStyleContext so that we can instantiate
|
/// into a single struct within ThreadLocalStyleContext so that we can instantiate
|
||||||
/// and destroy it easily at the beginning and end of element processing.
|
/// and destroy it easily at the beginning and end of element processing.
|
||||||
struct CurrentElementInfo {
|
pub struct CurrentElementInfo {
|
||||||
/// The element being processed. Currently we use an OpaqueNode since we only
|
/// The element being processed. Currently we use an OpaqueNode since we only
|
||||||
/// use this for identity checks, but we could use SendElement if there were
|
/// use this for identity checks, but we could use SendElement if there were
|
||||||
/// a good reason to.
|
/// a good reason to.
|
||||||
element: OpaqueNode,
|
element: OpaqueNode,
|
||||||
/// Whether the element is being styled for the first time.
|
/// Whether the element is being styled for the first time.
|
||||||
is_initial_style: bool,
|
is_initial_style: bool,
|
||||||
|
/// A Vec of possibly expired animations. Used only by Servo.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub possibly_expired_animations: Vec<PropertyAnimation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Statistics gathered during the traversal. We gather statistics on each thread
|
/// Statistics gathered during the traversal. We gather statistics on each thread
|
||||||
|
@ -276,7 +279,7 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
||||||
/// Statistics about the traversal.
|
/// Statistics about the traversal.
|
||||||
pub statistics: TraversalStatistics,
|
pub statistics: TraversalStatistics,
|
||||||
/// Information related to the current element, non-None during processing.
|
/// Information related to the current element, non-None during processing.
|
||||||
current_element_info: Option<CurrentElementInfo>,
|
pub current_element_info: Option<CurrentElementInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: TElement> ThreadLocalStyleContext<E> {
|
impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
|
@ -298,6 +301,7 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
self.current_element_info = Some(CurrentElementInfo {
|
self.current_element_info = Some(CurrentElementInfo {
|
||||||
element: element.as_node().opaque(),
|
element: element.as_node().opaque(),
|
||||||
is_initial_style: !data.has_styles(),
|
is_initial_style: !data.has_styles(),
|
||||||
|
possibly_expired_animations: Vec::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -534,7 +534,6 @@ trait PrivateMatchMethods: TElement {
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
data: &mut ElementData,
|
data: &mut ElementData,
|
||||||
pseudo: Option<&PseudoElement>,
|
pseudo: Option<&PseudoElement>,
|
||||||
possibly_expired_animations: &mut Vec<PropertyAnimation>,
|
|
||||||
animate: bool) {
|
animate: bool) {
|
||||||
// Collect some values.
|
// Collect some values.
|
||||||
let (mut styles, restyle) = data.styles_and_restyle_mut();
|
let (mut styles, restyle) = data.styles_and_restyle_mut();
|
||||||
|
@ -553,8 +552,7 @@ trait PrivateMatchMethods: TElement {
|
||||||
self.process_animations(context,
|
self.process_animations(context,
|
||||||
&mut old_values,
|
&mut old_values,
|
||||||
&mut new_values,
|
&mut new_values,
|
||||||
pseudo,
|
pseudo);
|
||||||
possibly_expired_animations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accumulate restyle damage.
|
// Accumulate restyle damage.
|
||||||
|
@ -602,8 +600,7 @@ trait PrivateMatchMethods: TElement {
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
old_values: &mut Option<Arc<ComputedValues>>,
|
old_values: &mut Option<Arc<ComputedValues>>,
|
||||||
new_values: &mut Arc<ComputedValues>,
|
new_values: &mut Arc<ComputedValues>,
|
||||||
pseudo: Option<&PseudoElement>,
|
pseudo: Option<&PseudoElement>) {
|
||||||
_possibly_expired_animations: &mut Vec<PropertyAnimation>) {
|
|
||||||
use context::{CSS_ANIMATIONS, EFFECT_PROPERTIES};
|
use context::{CSS_ANIMATIONS, EFFECT_PROPERTIES};
|
||||||
use context::UpdateAnimationsTasks;
|
use context::UpdateAnimationsTasks;
|
||||||
|
|
||||||
|
@ -646,8 +643,10 @@ trait PrivateMatchMethods: TElement {
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
old_values: &mut Option<Arc<ComputedValues>>,
|
old_values: &mut Option<Arc<ComputedValues>>,
|
||||||
new_values: &mut Arc<ComputedValues>,
|
new_values: &mut Arc<ComputedValues>,
|
||||||
_pseudo: Option<&PseudoElement>,
|
_pseudo: Option<&PseudoElement>) {
|
||||||
possibly_expired_animations: &mut Vec<PropertyAnimation>) {
|
let possibly_expired_animations =
|
||||||
|
&mut context.thread_local.current_element_info.as_mut().unwrap()
|
||||||
|
.possibly_expired_animations;
|
||||||
let shared_context = context.shared;
|
let shared_context = context.shared;
|
||||||
if let Some(ref mut old) = *old_values {
|
if let Some(ref mut old) = *old_values {
|
||||||
self.update_animations_for_cascade(shared_context, old,
|
self.update_animations_for_cascade(shared_context, old,
|
||||||
|
@ -797,14 +796,13 @@ pub trait MatchMethods : TElement {
|
||||||
let _rule_node_changed = self.match_primary(context, data, &mut primary_relations);
|
let _rule_node_changed = self.match_primary(context, data, &mut primary_relations);
|
||||||
|
|
||||||
// Cascade properties and compute primary values.
|
// Cascade properties and compute primary values.
|
||||||
let mut expired = vec![];
|
self.cascade_primary(context, data);
|
||||||
self.cascade_primary(context, data, &mut expired);
|
|
||||||
|
|
||||||
// Match and cascade eager pseudo-elements.
|
// Match and cascade eager pseudo-elements.
|
||||||
if !data.styles().is_display_none() {
|
if !data.styles().is_display_none() {
|
||||||
let _pseudo_rule_nodes_changed =
|
let _pseudo_rule_nodes_changed =
|
||||||
self.match_pseudos(context, data);
|
self.match_pseudos(context, data);
|
||||||
self.cascade_pseudos(context, data, &mut expired);
|
self.cascade_pseudos(context, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have any pseudo elements, indicate so in the primary StyleRelations.
|
// If we have any pseudo elements, indicate so in the primary StyleRelations.
|
||||||
|
@ -827,9 +825,8 @@ pub trait MatchMethods : TElement {
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
mut data: &mut ElementData)
|
mut data: &mut ElementData)
|
||||||
{
|
{
|
||||||
let mut possibly_expired_animations = vec![];
|
self.cascade_primary(context, &mut data);
|
||||||
self.cascade_primary(context, &mut data, &mut possibly_expired_animations);
|
self.cascade_pseudos(context, &mut data);
|
||||||
self.cascade_pseudos(context, &mut data, &mut possibly_expired_animations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs selector matching to (re)compute the primary rule node for this element.
|
/// Runs selector matching to (re)compute the primary rule node for this element.
|
||||||
|
@ -1218,18 +1215,15 @@ pub trait MatchMethods : TElement {
|
||||||
/// Performs the cascade for the element's primary style.
|
/// Performs the cascade for the element's primary style.
|
||||||
fn cascade_primary(&self,
|
fn cascade_primary(&self,
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
mut data: &mut ElementData,
|
mut data: &mut ElementData)
|
||||||
possibly_expired_animations: &mut Vec<PropertyAnimation>)
|
|
||||||
{
|
{
|
||||||
self.cascade_primary_or_pseudo(context, &mut data, None,
|
self.cascade_primary_or_pseudo(context, &mut data, None, /* animate = */ true);
|
||||||
possibly_expired_animations, /* animate = */ true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the cascade for the element's eager pseudos.
|
/// Performs the cascade for the element's eager pseudos.
|
||||||
fn cascade_pseudos(&self,
|
fn cascade_pseudos(&self,
|
||||||
context: &mut StyleContext<Self>,
|
context: &mut StyleContext<Self>,
|
||||||
mut data: &mut ElementData,
|
mut data: &mut ElementData)
|
||||||
possibly_expired_animations: &mut Vec<PropertyAnimation>)
|
|
||||||
{
|
{
|
||||||
// Note that we've already set up the map of matching pseudo-elements
|
// Note that we've already set up the map of matching pseudo-elements
|
||||||
// in match_pseudos (and handled the damage implications of changing
|
// in match_pseudos (and handled the damage implications of changing
|
||||||
|
@ -1240,8 +1234,7 @@ pub trait MatchMethods : TElement {
|
||||||
for pseudo in matched_pseudos {
|
for pseudo in matched_pseudos {
|
||||||
// Only ::before and ::after are animatable.
|
// Only ::before and ::after are animatable.
|
||||||
let animate = pseudo.is_before_or_after();
|
let animate = pseudo.is_before_or_after();
|
||||||
self.cascade_primary_or_pseudo(context, data, Some(&pseudo),
|
self.cascade_primary_or_pseudo(context, data, Some(&pseudo), animate);
|
||||||
possibly_expired_animations, animate);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -395,7 +395,9 @@ fn resolve_style_internal<E, F>(context: &mut StyleContext<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute our style.
|
// Compute our style.
|
||||||
|
context.thread_local.begin_element(element, &data);
|
||||||
element.match_and_cascade(context, &mut data, StyleSharingBehavior::Disallow);
|
element.match_and_cascade(context, &mut data, StyleSharingBehavior::Disallow);
|
||||||
|
context.thread_local.end_element(element);
|
||||||
|
|
||||||
// Conservatively mark us as having dirty descendants, since there might
|
// Conservatively mark us as having dirty descendants, since there might
|
||||||
// be other unstyled siblings we miss when walking straight up the parent
|
// be other unstyled siblings we miss when walking straight up the parent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue