Chromium Code Reviews| 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 03583eda3b36d35f71497a02778a6aaf8280ea5a..249eff8f30fd0b0e8928724c8ead467e59394e81 100644 |
| --- a/third_party/WebKit/Source/core/dom/Element.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Element.cpp |
| @@ -1903,14 +1903,14 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
| } |
| if (parentComputedStyle()) |
| change = recalcOwnStyle(change, nextTextSibling); |
| - clearNeedsStyleRecalc(); |
| - clearNeedsReattachLayoutTree(); |
| + if (change != Reattach) |
|
esprehn
2017/02/22 01:13:17
You could add a comment above this that says this
nainar
2017/02/22 03:12:07
Done.
|
| + clearNeedsStyleRecalc(); |
| } |
| - // If we reattached we don't need to recalc the style of our descendants |
| - // anymore. |
| - if ((change >= UpdatePseudoElements && change < Reattach) || |
| - childNeedsStyleRecalc()) { |
| + // If we are going to reattach we don't need to recalc the style of |
| + // our descendants anymore. |
| + if (change < Reattach && |
| + (change >= UpdatePseudoElements || childNeedsStyleRecalc())) { |
| SelectorFilterParentScope filterScope(*this); |
| StyleSharingDepthScope sharingScope(*this); |
| @@ -1936,7 +1936,6 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
| childNeedsStyleRecalc() ? Force : change); |
| clearChildNeedsStyleRecalc(); |
| - clearChildNeedsReattachLayoutTree(); |
| } |
| if (hasCustomStyleCallbacks()) |
| @@ -1996,7 +1995,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| styleReattachData.nextTextSibling = nextTextSibling; |
| document().addStyleReattachData(*this, styleReattachData); |
| setNeedsReattachLayoutTree(); |
| - return rebuildLayoutTree(); |
| + return Reattach; |
| } |
| DCHECK(oldStyle); |
| @@ -2037,23 +2036,32 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| return localChange; |
| } |
| -StyleRecalcChange Element::rebuildLayoutTree() { |
| +void Element::rebuildLayoutTree() { |
| DCHECK(inActiveDocument()); |
| + DCHECK(parentNode()); |
| + |
| StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
|
esprehn
2017/02/22 01:13:17
Move this whole block into the needsReattachLayout
nainar
2017/02/22 03:12:07
Done.
|
| AttachContext reattachContext; |
| reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
| - bool layoutObjectWillChange = needsAttach() || layoutObject(); |
| + bool layoutObjectWillChange = |
|
nainar
2017/02/22 01:07:58
Changed from last patch
esprehn
2017/02/22 01:13:17
Move this into the needsReattachLayoutTree() case.
nainar
2017/02/22 03:12:07
Done.
|
| + getStyleChangeType() == NeedsReattachStyleChange || 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()) { |
| + DCHECK(!needsReattachLayoutTree()); |
| + SelectorFilterParentScope filterScope(*this); |
| + StyleSharingDepthScope sharingScope(*this); |
| + reattachPseudoElementLayoutTree(PseudoIdBefore); |
| + rebuildShadowRootLayoutTree(); |
| + rebuildChildrenLayoutTrees(); |
| + reattachPseudoElementLayoutTree(PseudoIdAfter); |
| + reattachPseudoElementLayoutTree(PseudoIdBackdrop); |
| + reattachPseudoElementLayoutTree(PseudoIdFirstLetter); |
| + } |
| + DCHECK(!needsStyleRecalc()); |
| + DCHECK(!childNeedsStyleRecalc()); |
| + DCHECK(!needsReattachLayoutTree()); |
| DCHECK(!childNeedsReattachLayoutTree()); |
| if (layoutObjectWillChange || layoutObject()) { |
|
esprehn
2017/02/22 01:13:17
You want to move this whole block into the needsRe
nainar
2017/02/22 03:12:07
Done.
|
| @@ -2062,9 +2070,25 @@ StyleRecalcChange Element::rebuildLayoutTree() { |
| // or store it. |
| // The choice is between increased time and increased memory complexity. |
| reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
| - return Reattach; |
| } |
| - return ReattachNoLayoutObject; |
| +} |
| + |
| +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->childNeedsReattachLayoutTree()) |
| + element->rebuildLayoutTree(); |
| + } else { |
| + createPseudoElementIfNeeded(pseudoId); |
| + } |
| } |
| void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |