Index: third_party/WebKit/Source/core/dom/Element.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp |
index 047e339cba3e817a5c7eb056291cb3d2776f7584..5e02a35786251f612018dd4c899e23e505ecbf2b 100644 |
--- a/third_party/WebKit/Source/core/dom/Element.cpp |
+++ b/third_party/WebKit/Source/core/dom/Element.cpp |
@@ -1860,6 +1860,7 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
if (parentComputedStyle()) |
change = recalcOwnStyle(change); |
clearNeedsStyleRecalc(); |
+ clearNeedsReattachLayoutTree(); |
} |
// If we reattached we don't need to recalc the style of our descendants |
@@ -1891,13 +1892,11 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
childNeedsStyleRecalc() ? Force : change); |
clearChildNeedsStyleRecalc(); |
+ clearChildNeedsReattachLayoutTree(); |
} |
if (hasCustomStyleCallbacks()) |
didRecalcStyle(change); |
- |
- if (change == Reattach) |
- reattachWhitespaceSiblingsIfNeeded(nextTextSibling); |
} |
PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( |
@@ -1946,6 +1945,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) { |
if (localChange == Reattach) { |
document().addNonAttachedStyle(*this, std::move(newStyle)); |
+ setNeedsReattachLayoutTree(); |
return rebuildLayoutTree(); |
} |
@@ -1992,9 +1992,31 @@ StyleRecalcChange Element::rebuildLayoutTree() { |
AttachContext reattachContext; |
reattachContext.resolvedStyle = document().getNonAttachedStyle(*this); |
bool layoutObjectWillChange = needsAttach() || layoutObject(); |
- reattachLayoutTree(reattachContext); |
- if (layoutObjectWillChange || layoutObject()) |
+ |
+ if (needsReattachLayoutTree()) |
+ reattachLayoutTree(reattachContext); |
+ else if (childNeedsReattachLayoutTree()) |
Bugs Nash
2016/10/14 00:36:47
I think this would be better as a DCHECK
nainar
2016/10/14 03:28:10
Done.
|
+ NOTREACHED(); |
+ |
+ if (layoutObjectWillChange || layoutObject()) { |
+ // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
+ // we can either traverse the parent's tree to get this node or store it |
+ // (like WebKit does). |
Bugs Nash
2016/10/14 00:36:47
I wouldn't include what webkit does in a comment -
nainar
2016/10/14 03:28:10
Done.
|
+ // The choice is between increased time and increased memory complexity |
+ Text* nextTextSibling = nullptr; |
+ for (Node* sibling = this->nextSibling(); sibling; |
+ sibling = sibling->nextSibling()) { |
+ if (sibling->isElementNode() && toElement(sibling)->layoutObject()) { |
Bugs Nash
2016/10/14 00:36:47
could avoid this branch by adding it to the for lo
nainar
2016/10/14 03:28:10
Done.
|
+ break; |
+ } |
+ if (sibling->isTextNode()) { |
+ nextTextSibling = toText(sibling); |
+ break; |
+ } |
+ } |
+ reattachWhitespaceSiblingsIfNeeded(nextTextSibling); |
return Reattach; |
+ } |
return ReattachNoLayoutObject; |
} |