mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #14214 - bholley:dirtiness_overhaul, r=emilio
Overhaul dirtiness handling in Servo to prepare for the new incremental restyle architecture <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14214) <!-- Reviewable:end -->
This commit is contained in:
commit
e4a27c4d16
12 changed files with 192 additions and 183 deletions
|
@ -149,8 +149,6 @@ bitflags! {
|
|||
pub flags NodeFlags: u8 {
|
||||
#[doc = "Specifies whether this node is in a document."]
|
||||
const IS_IN_DOC = 0x01,
|
||||
#[doc = "Specifies whether this node _must_ be reflowed regardless of style differences."]
|
||||
const HAS_CHANGED = 0x02,
|
||||
#[doc = "Specifies whether this node needs style recalc on next reflow."]
|
||||
const IS_DIRTY = 0x04,
|
||||
#[doc = "Specifies whether this node has descendants (inclusive of itself) which \
|
||||
|
@ -175,7 +173,7 @@ bitflags! {
|
|||
|
||||
impl NodeFlags {
|
||||
pub fn new() -> NodeFlags {
|
||||
HAS_CHANGED | IS_DIRTY | HAS_DIRTY_DESCENDANTS
|
||||
IS_DIRTY
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,6 +249,8 @@ impl Node {
|
|||
let parent_in_doc = self.is_in_doc();
|
||||
for node in new_child.traverse_preorder() {
|
||||
node.set_flag(IS_IN_DOC, parent_in_doc);
|
||||
// Out-of-document elements never have the descendants flag set.
|
||||
debug_assert!(!node.get_flag(HAS_DIRTY_DESCENDANTS));
|
||||
vtable_for(&&*node).bind_to_tree(parent_in_doc);
|
||||
}
|
||||
let document = new_child.owner_doc();
|
||||
|
@ -289,7 +289,8 @@ impl Node {
|
|||
self.children_count.set(self.children_count.get() - 1);
|
||||
|
||||
for node in child.traverse_preorder() {
|
||||
node.set_flag(IS_IN_DOC, false);
|
||||
// Out-of-document elements never have the descendants flag set.
|
||||
node.set_flag(IS_IN_DOC | HAS_DIRTY_DESCENDANTS, false);
|
||||
vtable_for(&&*node).unbind_from_tree(&context);
|
||||
node.style_and_layout_data.get().map(|d| node.dispose(d));
|
||||
}
|
||||
|
@ -428,14 +429,6 @@ impl Node {
|
|||
self.flags.set(flags);
|
||||
}
|
||||
|
||||
pub fn has_changed(&self) -> bool {
|
||||
self.get_flag(HAS_CHANGED)
|
||||
}
|
||||
|
||||
pub fn set_has_changed(&self, state: bool) {
|
||||
self.set_flag(HAS_CHANGED, state)
|
||||
}
|
||||
|
||||
pub fn is_dirty(&self) -> bool {
|
||||
self.get_flag(IS_DIRTY)
|
||||
}
|
||||
|
@ -452,10 +445,6 @@ impl Node {
|
|||
self.set_flag(HAS_DIRTY_DESCENDANTS, state)
|
||||
}
|
||||
|
||||
pub fn force_dirty_ancestors(&self, damage: NodeDamage) {
|
||||
self.dirty_impl(damage, true)
|
||||
}
|
||||
|
||||
pub fn rev_version(&self) {
|
||||
// The new version counter is 1 plus the max of the node's current version counter,
|
||||
// its descendants version, and the document's version. Normally, this will just be
|
||||
|
@ -470,30 +459,18 @@ impl Node {
|
|||
}
|
||||
|
||||
pub fn dirty(&self, damage: NodeDamage) {
|
||||
self.dirty_impl(damage, false)
|
||||
}
|
||||
|
||||
pub fn dirty_impl(&self, damage: NodeDamage, force_ancestors: bool) {
|
||||
// 0. Set version counter
|
||||
self.rev_version();
|
||||
|
||||
// 1. Dirty self.
|
||||
match damage {
|
||||
NodeDamage::NodeStyleDamaged => {}
|
||||
NodeDamage::OtherNodeDamage => self.set_has_changed(true),
|
||||
if !self.is_in_doc() {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.is_dirty() && !force_ancestors {
|
||||
return
|
||||
}
|
||||
|
||||
self.set_flag(IS_DIRTY, true);
|
||||
|
||||
// 4. Dirty ancestors.
|
||||
for ancestor in self.ancestors() {
|
||||
if !force_ancestors && ancestor.has_dirty_descendants() { break }
|
||||
ancestor.set_has_dirty_descendants(true);
|
||||
}
|
||||
match self.type_id() {
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) =>
|
||||
self.parent_node.get().unwrap().downcast::<Element>().unwrap().restyle(damage),
|
||||
NodeTypeId::Element(_) =>
|
||||
self.downcast::<Element>().unwrap().restyle(damage),
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
|
||||
/// The maximum version number of this node's descendants, including itself
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue