From 557353c1f62b93b98736fdfaa64423887066f0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 12 Oct 2017 17:22:34 +0200 Subject: [PATCH] style: Move the bounds up in InvalidationProcessor. --- .../style/invalidation/element/collector.rs | 47 +++++++------------ .../style/invalidation/element/invalidator.rs | 45 +++++++----------- 2 files changed, 34 insertions(+), 58 deletions(-) diff --git a/components/style/invalidation/element/collector.rs b/components/style/invalidation/element/collector.rs index b80dbb3db5b..f6fbff96707 100644 --- a/components/style/invalidation/element/collector.rs +++ b/components/style/invalidation/element/collector.rs @@ -53,8 +53,11 @@ where /// changes. pub struct StateAndAttrInvalidationProcessor; -impl InvalidationProcessor for StateAndAttrInvalidationProcessor { - fn collect_invalidations( +impl InvalidationProcessor for StateAndAttrInvalidationProcessor +where + E: TElement, +{ + fn collect_invalidations( &self, element: E, mut data: Option<&mut ElementData>, @@ -62,10 +65,7 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor { shared_context: &SharedStyleContext, descendant_invalidations: &mut InvalidationVector, sibling_invalidations: &mut InvalidationVector, - ) -> bool - where - E: TElement, - { + ) -> bool { debug_assert!(element.has_snapshot(), "Why bothering?"); debug_assert!(data.is_some(), "How exactly?"); @@ -176,14 +176,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor { invalidated_self } - fn should_process_descendants( + fn should_process_descendants( &self, _element: E, data: Option<&mut ElementData>, - ) -> bool - where - E: TElement, - { + ) -> bool { let data = match data { None => return false, Some(ref data) => data, @@ -196,28 +193,22 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor { !data.hint.contains_subtree() } - fn recursion_limit_exceeded( + fn recursion_limit_exceeded( &self, _element: E, data: Option<&mut ElementData>, - ) - where - E: TElement, - { + ) { if let Some(data) = data { data.hint.insert(RESTYLE_DESCENDANTS); } } - fn invalidated_child( + fn invalidated_child( &self, element: E, _data: Option<&mut ElementData>, child: E, - ) - where - E: TElement, - { + ) { if child.get_data().is_none() { return; } @@ -238,14 +229,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor { } } - fn invalidated_descendants( + fn invalidated_descendants( &self, element: E, data: Option<&mut ElementData>, - ) - where - E: TElement, - { + ) { // FIXME(emilio): We probably want to walk the flattened tree here too, // and remove invalidated_child instead, or something like that. if data.as_ref().map_or(false, |d| !d.styles.is_display_none()) { @@ -253,14 +241,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor { } } - fn invalidated_self( + fn invalidated_self( &self, _element: E, data: Option<&mut ElementData>, - ) - where - E: TElement, - { + ) { if let Some(data) = data { data.hint.insert(RESTYLE_SELF); } diff --git a/components/style/invalidation/element/invalidator.rs b/components/style/invalidation/element/invalidator.rs index 0c7636cc1c3..682e7b23c6b 100644 --- a/components/style/invalidation/element/invalidator.rs +++ b/components/style/invalidation/element/invalidator.rs @@ -21,11 +21,14 @@ use std::fmt; /// /// The `data` argument is a mutable reference to the element's style data, if /// any. -pub trait InvalidationProcessor { +pub trait InvalidationProcessor +where + E: TElement, +{ /// Collect invalidations for a given element's descendants and siblings. /// /// Returns whether the element itself was invalidated. - fn collect_invalidations( + fn collect_invalidations( &self, element: E, data: Option<&mut ElementData>, @@ -33,57 +36,45 @@ pub trait InvalidationProcessor { shared_context: &SharedStyleContext, descendant_invalidations: &mut InvalidationVector, sibling_invalidations: &mut InvalidationVector, - ) -> bool - where - E: TElement; + ) -> bool; /// Returns whether the invalidation process should process the descendants /// of the given element. - fn should_process_descendants( + fn should_process_descendants( &self, element: E, data: Option<&mut ElementData>, - ) -> bool - where - E: TElement; + ) -> bool; /// Executes an arbitrary action when the recursion limit is exceded (if /// any). - fn recursion_limit_exceeded( + fn recursion_limit_exceeded( &self, element: E, data: Option<&mut ElementData>, - ) - where - E: TElement; + ); /// Executes an arbitrary action when a direct child is invalidated. - fn invalidated_child( + fn invalidated_child( &self, element: E, data: Option<&mut ElementData>, child: E, - ) - where - E: TElement; + ); /// Executes an action when `Self` is invalidated. - fn invalidated_self( + fn invalidated_self( &self, element: E, data: Option<&mut ElementData>, - ) - where - E: TElement; + ); /// Executes an action when any descendant of `Self` is invalidated. - fn invalidated_descendants( + fn invalidated_descendants( &self, element: E, data: Option<&mut ElementData>, - ) - where - E: TElement; + ); } /// The struct that takes care of encapsulating all the logic on where and how @@ -91,7 +82,7 @@ pub trait InvalidationProcessor { pub struct TreeStyleInvalidator<'a, 'b: 'a, E, P: 'a> where E: TElement, - P: InvalidationProcessor + P: InvalidationProcessor { element: E, // TODO(emilio): It's tempting enough to just avoid running invalidation for @@ -242,7 +233,7 @@ impl InvalidationResult { impl<'a, 'b: 'a, E, P: 'a> TreeStyleInvalidator<'a, 'b, E, P> where E: TElement, - P: InvalidationProcessor, + P: InvalidationProcessor, { /// Trivially constructs a new `TreeStyleInvalidator`. pub fn new(