Commit f6fa0238 authored by Rune Lillesveen's avatar Rune Lillesveen

Clear style invalidation on node removal.

We need to clear style invalidation on nodes being disconnected from the
document. It was done for various instances of DetachLayoutTree(), but
we would like Attach/DetachLayoutTree to be independent from style
invalidation and recalc and it is more logical to do this in RemovedFrom
on the nodes instead.

Change-Id: If8728cc5ca0f02ee83783b6e8614772cf4d4d0ef
Reviewed-on: https://chromium-review.googlesource.com/c/1314628Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605069}
parent 0301a791
...@@ -727,11 +727,8 @@ void ContainerNode::RemoveBetween(Node* previous_child, ...@@ -727,11 +727,8 @@ void ContainerNode::RemoveBetween(Node* previous_child,
DCHECK_EQ(old_child.parentNode(), this); DCHECK_EQ(old_child.parentNode(), this);
if (!old_child.NeedsAttach()) { if (!old_child.NeedsAttach())
AttachContext context; old_child.DetachLayoutTree();
context.clear_invalidation = true;
old_child.DetachLayoutTree(context);
}
if (next_child) if (next_child)
next_child->SetPreviousSibling(previous_child); next_child->SetPreviousSibling(previous_child);
...@@ -954,6 +951,20 @@ void ContainerNode::NotifyNodeRemoved(Node& root) { ...@@ -954,6 +951,20 @@ void ContainerNode::NotifyNodeRemoved(Node& root) {
} }
} }
void ContainerNode::RemovedFrom(ContainerNode& insertion_point) {
if (isConnected()) {
if (NeedsStyleInvalidation()) {
GetDocument()
.GetStyleEngine()
.GetPendingNodeInvalidations()
.ClearInvalidation(*this);
ClearNeedsStyleInvalidation();
}
ClearChildNeedsStyleInvalidation();
}
Node::RemovedFrom(insertion_point);
}
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
namespace { namespace {
...@@ -994,11 +1005,8 @@ void ContainerNode::AttachLayoutTree(AttachContext& context) { ...@@ -994,11 +1005,8 @@ void ContainerNode::AttachLayoutTree(AttachContext& context) {
} }
void ContainerNode::DetachLayoutTree(const AttachContext& context) { void ContainerNode::DetachLayoutTree(const AttachContext& context) {
AttachContext children_context(context);
children_context.clear_invalidation = true;
for (Node* child = firstChild(); child; child = child->nextSibling()) for (Node* child = firstChild(); child; child = child->nextSibling())
child->DetachLayoutTree(children_context); child->DetachLayoutTree(context);
SetChildNeedsStyleRecalc(); SetChildNeedsStyleRecalc();
Node::DetachLayoutTree(context); Node::DetachLayoutTree(context);
......
...@@ -158,6 +158,7 @@ class CORE_EXPORT ContainerNode : public Node { ...@@ -158,6 +158,7 @@ class CORE_EXPORT ContainerNode : public Node {
void SetActive(bool = true) override; void SetActive(bool = true) override;
void SetDragged(bool) override; void SetDragged(bool) override;
void SetHovered(bool = true) override; void SetHovered(bool = true) override;
void RemovedFrom(ContainerNode& insertion_point) override;
bool ChildrenOrSiblingsAffectedByFocus() const { bool ChildrenOrSiblingsAffectedByFocus() const {
return HasRestyleFlag( return HasRestyleFlag(
......
...@@ -1926,13 +1926,6 @@ void Element::RemovedFrom(ContainerNode& insertion_point) { ...@@ -1926,13 +1926,6 @@ void Element::RemovedFrom(ContainerNode& insertion_point) {
CustomElement::EnqueueDisconnectedCallback(this); CustomElement::EnqueueDisconnectedCallback(this);
else if (IsUpgradedV0CustomElement()) else if (IsUpgradedV0CustomElement())
V0CustomElement::DidDetach(this, insertion_point.GetDocument()); V0CustomElement::DidDetach(this, insertion_point.GetDocument());
if (NeedsStyleInvalidation()) {
GetDocument()
.GetStyleEngine()
.GetPendingNodeInvalidations()
.ClearInvalidation(*this);
}
} }
GetDocument().GetRootScrollerController().ElementRemoved(*this); GetDocument().GetRootScrollerController().ElementRemoved(*this);
...@@ -2086,13 +2079,6 @@ void Element::DetachLayoutTree(const AttachContext& context) { ...@@ -2086,13 +2079,6 @@ void Element::DetachLayoutTree(const AttachContext& context) {
GetDocument().UserActionElements().DidDetach(*this); GetDocument().UserActionElements().DidDetach(*this);
} }
if (context.clear_invalidation) {
GetDocument()
.GetStyleEngine()
.GetPendingNodeInvalidations()
.ClearInvalidation(*this);
}
SetNeedsResizeObserverUpdate(); SetNeedsResizeObserverUpdate();
DCHECK(NeedsAttach()); DCHECK(NeedsAttach());
......
...@@ -1393,7 +1393,6 @@ void Node::DetachLayoutTree(const AttachContext& context) { ...@@ -1393,7 +1393,6 @@ void Node::DetachLayoutTree(const AttachContext& context) {
GetLayoutObject()->DestroyAndCleanupAnonymousWrappers(); GetLayoutObject()->DestroyAndCleanupAnonymousWrappers();
SetLayoutObject(nullptr); SetLayoutObject(nullptr);
SetStyleChange(kNeedsReattachStyleChange); SetStyleChange(kNeedsReattachStyleChange);
ClearChildNeedsStyleInvalidation();
} }
const ComputedStyle* Node::VirtualEnsureComputedStyle( const ComputedStyle* Node::VirtualEnsureComputedStyle(
......
...@@ -657,7 +657,6 @@ class CORE_EXPORT Node : public EventTarget { ...@@ -657,7 +657,6 @@ class CORE_EXPORT Node : public EventTarget {
// objects when we need to do whitespace re-attachment. // objects when we need to do whitespace re-attachment.
LayoutObject* previous_in_flow = nullptr; LayoutObject* previous_in_flow = nullptr;
bool performing_reattach = false; bool performing_reattach = false;
bool clear_invalidation = false;
// True if the previous_in_flow member is up-to-date, even if it is nullptr. // True if the previous_in_flow member is up-to-date, even if it is nullptr.
bool use_previous_in_flow = false; bool use_previous_in_flow = false;
......
...@@ -164,16 +164,6 @@ void ShadowRoot::RebuildLayoutTree(WhitespaceAttacher& whitespace_attacher) { ...@@ -164,16 +164,6 @@ void ShadowRoot::RebuildLayoutTree(WhitespaceAttacher& whitespace_attacher) {
ClearChildNeedsReattachLayoutTree(); ClearChildNeedsReattachLayoutTree();
} }
void ShadowRoot::DetachLayoutTree(const AttachContext& context) {
Node::AttachContext children_context(context);
children_context.clear_invalidation = true;
GetDocument()
.GetStyleEngine()
.GetPendingNodeInvalidations()
.ClearInvalidation(*this);
DocumentFragment::DetachLayoutTree(children_context);
}
Node::InsertionNotificationRequest ShadowRoot::InsertedInto( Node::InsertionNotificationRequest ShadowRoot::InsertedInto(
ContainerNode& insertion_point) { ContainerNode& insertion_point) {
DocumentFragment::InsertedInto(insertion_point); DocumentFragment::InsertedInto(insertion_point);
...@@ -212,12 +202,6 @@ void ShadowRoot::RemovedFrom(ContainerNode& insertion_point) { ...@@ -212,12 +202,6 @@ void ShadowRoot::RemovedFrom(ContainerNode& insertion_point) {
root->RemoveChildShadowRoot(); root->RemoveChildShadowRoot();
registered_with_parent_shadow_root_ = false; registered_with_parent_shadow_root_ = false;
} }
if (NeedsStyleInvalidation()) {
GetDocument()
.GetStyleEngine()
.GetPendingNodeInvalidations()
.ClearInvalidation(*this);
}
} }
DocumentFragment::RemovedFrom(insertion_point); DocumentFragment::RemovedFrom(insertion_point);
......
...@@ -105,8 +105,6 @@ class CORE_EXPORT ShadowRoot final : public DocumentFragment, public TreeScope { ...@@ -105,8 +105,6 @@ class CORE_EXPORT ShadowRoot final : public DocumentFragment, public TreeScope {
} }
bool IsUserAgent() const { return GetType() == ShadowRootType::kUserAgent; } bool IsUserAgent() const { return GetType() == ShadowRootType::kUserAgent; }
void DetachLayoutTree(const AttachContext& = AttachContext()) override;
InsertionNotificationRequest InsertedInto(ContainerNode&) override; InsertionNotificationRequest InsertedInto(ContainerNode&) override;
void RemovedFrom(ContainerNode&) override; void RemovedFrom(ContainerNode&) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment