mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Move the bounds up in InvalidationProcessor.
This commit is contained in:
parent
a5e2f2c76c
commit
557353c1f6
2 changed files with 34 additions and 58 deletions
|
@ -53,8 +53,11 @@ where
|
||||||
/// changes.
|
/// changes.
|
||||||
pub struct StateAndAttrInvalidationProcessor;
|
pub struct StateAndAttrInvalidationProcessor;
|
||||||
|
|
||||||
impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
impl<E> InvalidationProcessor<E> for StateAndAttrInvalidationProcessor
|
||||||
fn collect_invalidations<E>(
|
where
|
||||||
|
E: TElement,
|
||||||
|
{
|
||||||
|
fn collect_invalidations(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
mut data: Option<&mut ElementData>,
|
mut data: Option<&mut ElementData>,
|
||||||
|
@ -62,10 +65,7 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
||||||
shared_context: &SharedStyleContext,
|
shared_context: &SharedStyleContext,
|
||||||
descendant_invalidations: &mut InvalidationVector,
|
descendant_invalidations: &mut InvalidationVector,
|
||||||
sibling_invalidations: &mut InvalidationVector,
|
sibling_invalidations: &mut InvalidationVector,
|
||||||
) -> bool
|
) -> bool {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
debug_assert!(element.has_snapshot(), "Why bothering?");
|
debug_assert!(element.has_snapshot(), "Why bothering?");
|
||||||
debug_assert!(data.is_some(), "How exactly?");
|
debug_assert!(data.is_some(), "How exactly?");
|
||||||
|
|
||||||
|
@ -176,14 +176,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
||||||
invalidated_self
|
invalidated_self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_process_descendants<E>(
|
fn should_process_descendants(
|
||||||
&self,
|
&self,
|
||||||
_element: E,
|
_element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
) -> bool
|
) -> bool {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
let data = match data {
|
let data = match data {
|
||||||
None => return false,
|
None => return false,
|
||||||
Some(ref data) => data,
|
Some(ref data) => data,
|
||||||
|
@ -196,28 +193,22 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
||||||
!data.hint.contains_subtree()
|
!data.hint.contains_subtree()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recursion_limit_exceeded<E>(
|
fn recursion_limit_exceeded(
|
||||||
&self,
|
&self,
|
||||||
_element: E,
|
_element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
) {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
if let Some(data) = data {
|
if let Some(data) = data {
|
||||||
data.hint.insert(RESTYLE_DESCENDANTS);
|
data.hint.insert(RESTYLE_DESCENDANTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidated_child<E>(
|
fn invalidated_child(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
_data: Option<&mut ElementData>,
|
_data: Option<&mut ElementData>,
|
||||||
child: E,
|
child: E,
|
||||||
)
|
) {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
if child.get_data().is_none() {
|
if child.get_data().is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -238,14 +229,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidated_descendants<E>(
|
fn invalidated_descendants(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
) {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
// FIXME(emilio): We probably want to walk the flattened tree here too,
|
// FIXME(emilio): We probably want to walk the flattened tree here too,
|
||||||
// and remove invalidated_child instead, or something like that.
|
// and remove invalidated_child instead, or something like that.
|
||||||
if data.as_ref().map_or(false, |d| !d.styles.is_display_none()) {
|
if data.as_ref().map_or(false, |d| !d.styles.is_display_none()) {
|
||||||
|
@ -253,14 +241,11 @@ impl InvalidationProcessor for StateAndAttrInvalidationProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidated_self<E>(
|
fn invalidated_self(
|
||||||
&self,
|
&self,
|
||||||
_element: E,
|
_element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
) {
|
||||||
where
|
|
||||||
E: TElement,
|
|
||||||
{
|
|
||||||
if let Some(data) = data {
|
if let Some(data) = data {
|
||||||
data.hint.insert(RESTYLE_SELF);
|
data.hint.insert(RESTYLE_SELF);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,14 @@ use std::fmt;
|
||||||
///
|
///
|
||||||
/// The `data` argument is a mutable reference to the element's style data, if
|
/// The `data` argument is a mutable reference to the element's style data, if
|
||||||
/// any.
|
/// any.
|
||||||
pub trait InvalidationProcessor {
|
pub trait InvalidationProcessor<E>
|
||||||
|
where
|
||||||
|
E: TElement,
|
||||||
|
{
|
||||||
/// Collect invalidations for a given element's descendants and siblings.
|
/// Collect invalidations for a given element's descendants and siblings.
|
||||||
///
|
///
|
||||||
/// Returns whether the element itself was invalidated.
|
/// Returns whether the element itself was invalidated.
|
||||||
fn collect_invalidations<E>(
|
fn collect_invalidations(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
|
@ -33,57 +36,45 @@ pub trait InvalidationProcessor {
|
||||||
shared_context: &SharedStyleContext,
|
shared_context: &SharedStyleContext,
|
||||||
descendant_invalidations: &mut InvalidationVector,
|
descendant_invalidations: &mut InvalidationVector,
|
||||||
sibling_invalidations: &mut InvalidationVector,
|
sibling_invalidations: &mut InvalidationVector,
|
||||||
) -> bool
|
) -> bool;
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
|
|
||||||
/// Returns whether the invalidation process should process the descendants
|
/// Returns whether the invalidation process should process the descendants
|
||||||
/// of the given element.
|
/// of the given element.
|
||||||
fn should_process_descendants<E>(
|
fn should_process_descendants(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
) -> bool
|
) -> bool;
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
|
|
||||||
/// Executes an arbitrary action when the recursion limit is exceded (if
|
/// Executes an arbitrary action when the recursion limit is exceded (if
|
||||||
/// any).
|
/// any).
|
||||||
fn recursion_limit_exceeded<E>(
|
fn recursion_limit_exceeded(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
);
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
|
|
||||||
/// Executes an arbitrary action when a direct child is invalidated.
|
/// Executes an arbitrary action when a direct child is invalidated.
|
||||||
fn invalidated_child<E>(
|
fn invalidated_child(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
child: E,
|
child: E,
|
||||||
)
|
);
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
|
|
||||||
/// Executes an action when `Self` is invalidated.
|
/// Executes an action when `Self` is invalidated.
|
||||||
fn invalidated_self<E>(
|
fn invalidated_self(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
);
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
|
|
||||||
/// Executes an action when any descendant of `Self` is invalidated.
|
/// Executes an action when any descendant of `Self` is invalidated.
|
||||||
fn invalidated_descendants<E>(
|
fn invalidated_descendants(
|
||||||
&self,
|
&self,
|
||||||
element: E,
|
element: E,
|
||||||
data: Option<&mut ElementData>,
|
data: Option<&mut ElementData>,
|
||||||
)
|
);
|
||||||
where
|
|
||||||
E: TElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The struct that takes care of encapsulating all the logic on where and how
|
/// 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>
|
pub struct TreeStyleInvalidator<'a, 'b: 'a, E, P: 'a>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
P: InvalidationProcessor
|
P: InvalidationProcessor<E>
|
||||||
{
|
{
|
||||||
element: E,
|
element: E,
|
||||||
// TODO(emilio): It's tempting enough to just avoid running invalidation for
|
// 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>
|
impl<'a, 'b: 'a, E, P: 'a> TreeStyleInvalidator<'a, 'b, E, P>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
P: InvalidationProcessor,
|
P: InvalidationProcessor<E>,
|
||||||
{
|
{
|
||||||
/// Trivially constructs a new `TreeStyleInvalidator`.
|
/// Trivially constructs a new `TreeStyleInvalidator`.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue