mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Let layout invalidations happen in the flat tree (#35769)
When invalidating layout, computing dirty roots and such, we want to work in the flat tree. That means that the children of slots are their assigned slottables, parents of assigned slottables are their slots and the children of an element include children of a potential shadow dom. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
fc891fff11
commit
37634b1251
2 changed files with 43 additions and 8 deletions
|
@ -528,7 +528,7 @@ impl Document {
|
|||
return;
|
||||
}
|
||||
|
||||
let parent = match node.inclusive_ancestors(ShadowIncluding::Yes).nth(1) {
|
||||
let parent = match node.parent_in_flat_tree() {
|
||||
Some(parent) => parent,
|
||||
None => {
|
||||
// There is no parent so this is the Document node, so we
|
||||
|
@ -542,7 +542,7 @@ impl Document {
|
|||
// ancestors as dirty until the document element.
|
||||
for ancestor in dirty_root
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors(ShadowIncluding::Yes)
|
||||
.inclusive_ancestors_in_flat_tree()
|
||||
{
|
||||
if ancestor.is::<Element>() {
|
||||
ancestor.set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, true);
|
||||
|
@ -596,13 +596,11 @@ impl Document {
|
|||
Some(root) => root,
|
||||
};
|
||||
|
||||
for ancestor in element
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors(ShadowIncluding::Yes)
|
||||
{
|
||||
for ancestor in element.upcast::<Node>().inclusive_ancestors_in_flat_tree() {
|
||||
if ancestor.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ancestor.is::<Element>() {
|
||||
ancestor.set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, true);
|
||||
}
|
||||
|
@ -610,13 +608,13 @@ impl Document {
|
|||
|
||||
let new_dirty_root = element
|
||||
.upcast::<Node>()
|
||||
.common_ancestor(dirty_root.upcast(), ShadowIncluding::Yes)
|
||||
.common_ancestor_in_flat_tree(dirty_root.upcast())
|
||||
.expect("Couldn't find common ancestor");
|
||||
|
||||
let mut has_dirty_descendants = true;
|
||||
for ancestor in dirty_root
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors(ShadowIncluding::Yes)
|
||||
.inclusive_ancestors_in_flat_tree()
|
||||
{
|
||||
ancestor.set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, has_dirty_descendants);
|
||||
has_dirty_descendants &= *ancestor != *new_dirty_root;
|
||||
|
|
|
@ -777,6 +777,14 @@ impl Node {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn common_ancestor_in_flat_tree(&self, other: &Node) -> Option<DomRoot<Node>> {
|
||||
self.inclusive_ancestors_in_flat_tree().find(|ancestor| {
|
||||
other
|
||||
.inclusive_ancestors_in_flat_tree()
|
||||
.any(|node| node == *ancestor)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn is_inclusive_ancestor_of(&self, parent: &Node) -> bool {
|
||||
self == parent || self.is_ancestor_of(parent)
|
||||
}
|
||||
|
@ -1395,6 +1403,35 @@ impl Node {
|
|||
.slottable_data
|
||||
.manual_slot_assignment = manually_assigned_slot.map(Dom::from_ref);
|
||||
}
|
||||
|
||||
/// Gets the parent of this node from the perspective of layout and style.
|
||||
///
|
||||
/// The returned node is the node's assigned slot, if any, or the
|
||||
/// shadow host if it's a shadow root. Otherwise, it is the node's
|
||||
/// parent.
|
||||
pub(crate) fn parent_in_flat_tree(&self) -> Option<DomRoot<Node>> {
|
||||
if let Some(assigned_slot) = self.assigned_slot() {
|
||||
return Some(DomRoot::upcast(assigned_slot));
|
||||
}
|
||||
|
||||
let parent_or_none = self.GetParentNode();
|
||||
if let Some(parent) = parent_or_none.as_deref() {
|
||||
if let Some(shadow_root) = parent.downcast::<ShadowRoot>() {
|
||||
return Some(DomRoot::from_ref(shadow_root.Host().upcast::<Node>()));
|
||||
}
|
||||
}
|
||||
|
||||
parent_or_none
|
||||
}
|
||||
|
||||
pub(crate) fn inclusive_ancestors_in_flat_tree(
|
||||
&self,
|
||||
) -> impl Iterator<Item = DomRoot<Node>> + use<> {
|
||||
SimpleNodeIterator {
|
||||
current: Some(DomRoot::from_ref(self)),
|
||||
next_node: move |n| n.parent_in_flat_tree(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterate through `nodes` until we find a `Node` that is not in `not_in`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue