mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Factor out a few invalidation functions that are going to be shared soon.
This commit is contained in:
parent
b91efadd8d
commit
268f0f75b9
1 changed files with 49 additions and 26 deletions
|
@ -93,6 +93,50 @@ impl<'a, 'b: 'a, E: TElement> StateAndAttrInvalidationProcessor<'a, 'b, E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Whether we should process the descendants of a given element for style
|
||||||
|
/// invalidation.
|
||||||
|
pub fn should_process_descendants(data: &ElementData) -> bool {
|
||||||
|
!data.styles.is_display_none() &&
|
||||||
|
!data.hint.contains(RestyleHint::RESTYLE_DESCENDANTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Propagates the bits after invalidating a descendant child.
|
||||||
|
pub fn invalidated_descendants<E>(element: E, child: E)
|
||||||
|
where
|
||||||
|
E: TElement,
|
||||||
|
{
|
||||||
|
if child.get_data().is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The child may not be a flattened tree child of the current element,
|
||||||
|
// but may be arbitrarily deep.
|
||||||
|
//
|
||||||
|
// Since we keep the traversal flags in terms of the flattened tree,
|
||||||
|
// we need to propagate it as appropriate.
|
||||||
|
let mut current = child.traversal_parent();
|
||||||
|
while let Some(parent) = current.take() {
|
||||||
|
unsafe { parent.set_dirty_descendants() };
|
||||||
|
current = parent.traversal_parent();
|
||||||
|
|
||||||
|
if parent == element {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the appropriate restyle hint after invalidating the style of a given
|
||||||
|
/// element.
|
||||||
|
pub fn invalidated_self<E>(element: E)
|
||||||
|
where
|
||||||
|
E: TElement,
|
||||||
|
{
|
||||||
|
if let Some(mut data) = element.mutate_data() {
|
||||||
|
data.hint.insert(RestyleHint::RESTYLE_SELF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b: 'a, E: 'a> InvalidationProcessor<'a, E> for StateAndAttrInvalidationProcessor<'a, 'b, E>
|
impl<'a, 'b: 'a, E: 'a> InvalidationProcessor<'a, E> for StateAndAttrInvalidationProcessor<'a, 'b, E>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
|
@ -251,17 +295,15 @@ where
|
||||||
|
|
||||||
fn should_process_descendants(&mut self, element: E) -> bool {
|
fn should_process_descendants(&mut self, element: E) -> bool {
|
||||||
if element == self.element {
|
if element == self.element {
|
||||||
return !self.data.styles.is_display_none() &&
|
return should_process_descendants(&self.data)
|
||||||
!self.data.hint.contains(RestyleHint::RESTYLE_DESCENDANTS)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = match element.borrow_data() {
|
let data = match element.borrow_data() {
|
||||||
|
Some(d) => d,
|
||||||
None => return false,
|
None => return false,
|
||||||
Some(data) => data,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
!data.styles.is_display_none() &&
|
should_process_descendants(&data)
|
||||||
!data.hint.contains(RestyleHint::RESTYLE_DESCENDANTS)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recursion_limit_exceeded(&mut self, element: E) {
|
fn recursion_limit_exceeded(&mut self, element: E) {
|
||||||
|
@ -276,31 +318,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidated_descendants(&mut self, element: E, child: E) {
|
fn invalidated_descendants(&mut self, element: E, child: E) {
|
||||||
if child.get_data().is_none() {
|
invalidated_descendants(element, child)
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The child may not be a flattened tree child of the current element,
|
|
||||||
// but may be arbitrarily deep.
|
|
||||||
//
|
|
||||||
// Since we keep the traversal flags in terms of the flattened tree,
|
|
||||||
// we need to propagate it as appropriate.
|
|
||||||
let mut current = child.traversal_parent();
|
|
||||||
while let Some(parent) = current.take() {
|
|
||||||
unsafe { parent.set_dirty_descendants() };
|
|
||||||
current = parent.traversal_parent();
|
|
||||||
|
|
||||||
if parent == element {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidated_self(&mut self, element: E) {
|
fn invalidated_self(&mut self, element: E) {
|
||||||
debug_assert_ne!(element, self.element);
|
debug_assert_ne!(element, self.element);
|
||||||
if let Some(mut data) = element.mutate_data() {
|
invalidated_self(element);
|
||||||
data.hint.insert(RestyleHint::RESTYLE_SELF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue