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 7aae88c83b5a16951b3eb756e306129b334a7f90..8502f9bf89cf5abd7e0719a234ef30557fae738d 100644 |
--- a/third_party/WebKit/Source/core/dom/Element.cpp |
+++ b/third_party/WebKit/Source/core/dom/Element.cpp |
@@ -1857,7 +1857,6 @@ void Element::recalcStyle(StyleRecalcChange change) { |
if (parentComputedStyle()) |
change = recalcOwnStyle(change); |
clearNeedsStyleRecalc(); |
- clearNeedsReattachLayoutTree(); |
} |
// If we reattached we don't need to recalc the style of our descendants |
@@ -1876,6 +1875,7 @@ void Element::recalcStyle(StyleRecalcChange change) { |
root->recalcStyle(change); |
} |
recalcDescendantStyles(change); |
+ clearChildNeedsStyleRecalc(); |
} |
updatePseudoElement(PseudoIdAfter, change); |
@@ -1887,9 +1887,6 @@ void Element::recalcStyle(StyleRecalcChange change) { |
// non-floating we have to take it into account for the first letter. |
updatePseudoElement(PseudoIdFirstLetter, |
childNeedsStyleRecalc() ? Force : change); |
- |
- clearChildNeedsStyleRecalc(); |
- clearChildNeedsReattachLayoutTree(); |
} |
if (hasCustomStyleCallbacks()) |
@@ -1943,7 +1940,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) { |
if (localChange == Reattach) { |
document().addNonAttachedStyle(*this, std::move(newStyle)); |
setNeedsReattachLayoutTree(); |
- return rebuildLayoutTree(); |
+ return Reattach; |
} |
DCHECK(oldStyle); |
@@ -1985,33 +1982,52 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) { |
return localChange; |
} |
-StyleRecalcChange Element::rebuildLayoutTree() { |
+void Element::rebuildLayoutTree() { |
DCHECK(inActiveDocument()); |
+ DCHECK(!needsStyleRecalc()); |
+ DCHECK(!childNeedsStyleRecalc()); |
+ DCHECK(parentNode()); |
+ DCHECK(parentNode()->childNeedsReattachLayoutTree()); |
+ |
AttachContext reattachContext; |
reattachContext.resolvedStyle = document().getNonAttachedStyle(*this); |
bool layoutObjectWillChange = needsAttach() || layoutObject(); |
- // We are calling Element::rebuildLayoutTree() from inside |
- // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree |
- // flag - so needsReattachLayoutTree() should always be true. |
- DCHECK(parentNode()); |
- DCHECK(parentNode()->childNeedsReattachLayoutTree()); |
- DCHECK(needsReattachLayoutTree()); |
- reattachLayoutTree(reattachContext); |
- // Since needsReattachLayoutTree() is always true we go into |
- // reattachLayoutTree() which reattaches all the descendant |
- // sub-trees. At this point no child should need reattaching. |
+ if (needsReattachLayoutTree()) { |
+ reattachLayoutTree(reattachContext); |
+ } else if (childNeedsReattachLayoutTree()) { |
esprehn
2016/11/07 22:32:08
You're missing:
SelectorFilterParentScope filte
|
+ rebuildShadowRootLayoutTree(); |
+ rebuildDescendantLayoutTree(); |
+ reattachPseudoElementLayoutTree(PseudoIdAfter); |
+ reattachPseudoElementLayoutTree(PseudoIdBackdrop); |
+ } |
+ DCHECK(!needsReattachLayoutTree()); |
DCHECK(!childNeedsReattachLayoutTree()); |
if (layoutObjectWillChange || layoutObject()) { |
// nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
// we can either traverse the current subtree from this node onwards |
// or store it. |
- // The choice is between increased time and increased memory complexity. |
+ // The choice is between increased time and increased memory complexity |
+ // (for the duration of Style recalc and Layout Tree Construction). |
+ // TODO(bugsnash): This is a performance regression - bugsnash is working on |
+ // alleviating this regression. |
reattachWhitespaceSiblingsIfNeeded(nextTextSibling()); |
- return Reattach; |
} |
- return ReattachNoLayoutObject; |
esprehn
2016/11/07 22:32:08
Is ReattachNoLayoutObject dead code now?
|
+} |
+ |
+void Element::rebuildShadowRootLayoutTree() { |
+ for (ShadowRoot* root = youngestShadowRoot(); root; |
+ root = root->olderShadowRoot()) { |
+ if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree()) |
+ root->rebuildLayoutTree(); |
+ } |
+} |
+void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) { |
+ if (PseudoElement* element = pseudoElement(pseudoId)) { |
+ if (element->needsReattachLayoutTree()) |
+ element->rebuildLayoutTree(); |
+ } |
} |
void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |