servo: Merge #16291 - Hoist possibly_expired_animations into CurrentElementInfo (from bholley:possibly_expired); r=emilio

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.

Source-Repo: https://github.com/servo/servo
Source-Revision: 48a412abc7d56529770bdbe2cf0f5e6af852538e

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 0835e398d3db3ff28992d71ee648485033c3c94d
This commit is contained in:
Bobby Holley 2017-04-06 20:07:48 -05:00
Родитель e27d2e7dbe
Коммит 8f3f795143
3 изменённых файлов: 23 добавлений и 24 удалений

Просмотреть файл

@ -5,7 +5,7 @@
//! The context within which style is calculated.
#![deny(missing_docs)]
use animation::Animation;
use animation::{Animation, PropertyAnimation};
use app_units::Au;
use bloom::StyleBloom;
use data::ElementData;
@ -103,13 +103,16 @@ impl<'a> SharedStyleContext<'a> {
/// Information about the current element being processed. We group this together
/// into a single struct within ThreadLocalStyleContext so that we can instantiate
/// 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
/// use this for identity checks, but we could use SendElement if there were
/// a good reason to.
element: OpaqueNode,
/// Whether the element is being styled for the first time.
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
@ -276,7 +279,7 @@ pub struct ThreadLocalStyleContext<E: TElement> {
/// Statistics about the traversal.
pub statistics: TraversalStatistics,
/// 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> {
@ -298,6 +301,7 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
self.current_element_info = Some(CurrentElementInfo {
element: element.as_node().opaque(),
is_initial_style: !data.has_styles(),
possibly_expired_animations: Vec::new(),
});
}

Просмотреть файл

@ -534,7 +534,6 @@ trait PrivateMatchMethods: TElement {
context: &mut StyleContext<Self>,
data: &mut ElementData,
pseudo: Option<&PseudoElement>,
possibly_expired_animations: &mut Vec<PropertyAnimation>,
animate: bool) {
// Collect some values.
let (mut styles, restyle) = data.styles_and_restyle_mut();
@ -553,8 +552,7 @@ trait PrivateMatchMethods: TElement {
self.process_animations(context,
&mut old_values,
&mut new_values,
pseudo,
possibly_expired_animations);
pseudo);
}
// Accumulate restyle damage.
@ -602,8 +600,7 @@ trait PrivateMatchMethods: TElement {
context: &mut StyleContext<Self>,
old_values: &mut Option<Arc<ComputedValues>>,
new_values: &mut Arc<ComputedValues>,
pseudo: Option<&PseudoElement>,
_possibly_expired_animations: &mut Vec<PropertyAnimation>) {
pseudo: Option<&PseudoElement>) {
use context::{CSS_ANIMATIONS, EFFECT_PROPERTIES};
use context::UpdateAnimationsTasks;
@ -646,8 +643,10 @@ trait PrivateMatchMethods: TElement {
context: &mut StyleContext<Self>,
old_values: &mut Option<Arc<ComputedValues>>,
new_values: &mut Arc<ComputedValues>,
_pseudo: Option<&PseudoElement>,
possibly_expired_animations: &mut Vec<PropertyAnimation>) {
_pseudo: Option<&PseudoElement>) {
let possibly_expired_animations =
&mut context.thread_local.current_element_info.as_mut().unwrap()
.possibly_expired_animations;
let shared_context = context.shared;
if let Some(ref mut old) = *old_values {
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);
// Cascade properties and compute primary values.
let mut expired = vec![];
self.cascade_primary(context, data, &mut expired);
self.cascade_primary(context, data);
// Match and cascade eager pseudo-elements.
if !data.styles().is_display_none() {
let _pseudo_rule_nodes_changed =
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.
@ -827,9 +825,8 @@ pub trait MatchMethods : TElement {
context: &mut StyleContext<Self>,
mut data: &mut ElementData)
{
let mut possibly_expired_animations = vec![];
self.cascade_primary(context, &mut data, &mut possibly_expired_animations);
self.cascade_pseudos(context, &mut data, &mut possibly_expired_animations);
self.cascade_primary(context, &mut data);
self.cascade_pseudos(context, &mut data);
}
/// 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.
fn cascade_primary(&self,
context: &mut StyleContext<Self>,
mut data: &mut ElementData,
possibly_expired_animations: &mut Vec<PropertyAnimation>)
mut data: &mut ElementData)
{
self.cascade_primary_or_pseudo(context, &mut data, None,
possibly_expired_animations, /* animate = */ true);
self.cascade_primary_or_pseudo(context, &mut data, None, /* animate = */ true);
}
/// Performs the cascade for the element's eager pseudos.
fn cascade_pseudos(&self,
context: &mut StyleContext<Self>,
mut data: &mut ElementData,
possibly_expired_animations: &mut Vec<PropertyAnimation>)
mut data: &mut ElementData)
{
// Note that we've already set up the map of matching pseudo-elements
// in match_pseudos (and handled the damage implications of changing
@ -1240,8 +1234,7 @@ pub trait MatchMethods : TElement {
for pseudo in matched_pseudos {
// Only ::before and ::after are animatable.
let animate = pseudo.is_before_or_after();
self.cascade_primary_or_pseudo(context, data, Some(&pseudo),
possibly_expired_animations, animate);
self.cascade_primary_or_pseudo(context, data, Some(&pseudo), animate);
}
}

Просмотреть файл

@ -395,7 +395,9 @@ fn resolve_style_internal<E, F>(context: &mut StyleContext<E>,
}
// Compute our style.
context.thread_local.begin_element(element, &data);
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
// be other unstyled siblings we miss when walking straight up the parent