| 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 4b146314627f4c71e8e39040cffaf7eb002c7094..cee73bf707efa517229c0af489d0b990ed6d0be1 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)
|
| + 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())
|
| @@ -1972,6 +1971,14 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
|
| DCHECK(change >= IndependentInherit || needsStyleRecalc());
|
| DCHECK(parentComputedStyle());
|
|
|
| + if (needsReattachLayoutTree()) {
|
| + StyleReattachData styleReattachData;
|
| + styleReattachData.nextTextSibling = nextTextSibling;
|
| + document().addStyleReattachData(*this, styleReattachData);
|
| + setNeedsReattachLayoutTree();
|
| + return Reattach;
|
| + }
|
| +
|
| RefPtr<ComputedStyle> oldStyle = mutableComputedStyle();
|
|
|
| // When propagating inherited changes, we don't need to do a full style recalc
|
| @@ -1996,7 +2003,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
|
| styleReattachData.nextTextSibling = nextTextSibling;
|
| document().addStyleReattachData(*this, styleReattachData);
|
| setNeedsReattachLayoutTree();
|
| - return rebuildLayoutTree();
|
| + return Reattach;
|
| }
|
|
|
| DCHECK(oldStyle);
|
| @@ -2037,23 +2044,31 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
|
| return localChange;
|
| }
|
|
|
| -StyleRecalcChange Element::rebuildLayoutTree() {
|
| +void Element::rebuildLayoutTree() {
|
| DCHECK(inActiveDocument());
|
| + DCHECK(parentNode());
|
| +
|
| StyleReattachData styleReattachData = document().getStyleReattachData(*this);
|
| AttachContext reattachContext;
|
| reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
|
| 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()) {
|
| + 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()) {
|
| @@ -2062,9 +2077,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,
|
|
|