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 f33de88828625bc869a80e4e0fb9c2575863396d..01d23094393f1fcf9dd99b7a35fede1f99f18025 100644 |
| --- a/third_party/WebKit/Source/core/dom/Element.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Element.cpp |
| @@ -26,6 +26,7 @@ |
| #include "core/dom/Element.h" |
| +#include <memory> |
|
nainar
2017/03/09 02:53:03
git cl format. Will get rid of this.
|
| #include "bindings/core/v8/DOMDataStore.h" |
| #include "bindings/core/v8/Dictionary.h" |
| #include "bindings/core/v8/ExceptionMessages.h" |
| @@ -110,6 +111,7 @@ |
| #include "core/html/HTMLFormControlsCollection.h" |
| #include "core/html/HTMLFrameElementBase.h" |
| #include "core/html/HTMLFrameOwnerElement.h" |
| +#include "core/html/HTMLObjectElement.h" |
|
nainar
2017/03/09 02:53:03
Not needed.
|
| #include "core/html/HTMLOptionsCollection.h" |
| #include "core/html/HTMLPlugInElement.h" |
| #include "core/html/HTMLSlotElement.h" |
| @@ -146,7 +148,6 @@ |
| #include "wtf/text/CString.h" |
| #include "wtf/text/StringBuilder.h" |
| #include "wtf/text/TextPosition.h" |
| -#include <memory> |
| namespace blink { |
| @@ -1739,6 +1740,7 @@ void Element::attachLayoutTree(const AttachContext& context) { |
| SelectorFilterParentScope filterScope(*this); |
| StyleSharingDepthScope sharingScope(*this); |
| + clearNeedsReattachLayoutTree(); |
| createPseudoElementIfNeeded(PseudoIdBefore); |
| // When a shadow root exists, it does the work of attaching the children. |
| @@ -2021,11 +2023,14 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| } |
| if (localChange == Reattach) { |
| + // This mimicks Element::recalcStyleForReattach except it also stores the |
| + // nextTextSibling information. |
| StyleReattachData styleReattachData; |
| styleReattachData.computedStyle = std::move(newStyle); |
| styleReattachData.nextTextSibling = nextTextSibling; |
| document().addStyleReattachData(*this, styleReattachData); |
| setNeedsReattachLayoutTree(); |
| + recalcContainedStyleForReattach(); |
| return Reattach; |
| } |
| @@ -2070,6 +2075,44 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| return localChange; |
| } |
| +void Element::recalcStyleForReattach() { |
| + StyleReattachData styleReattachData; |
| + styleReattachData.computedStyle = styleForLayoutObject(); |
| + if (layoutObjectIsNeeded(*styleReattachData.computedStyle.get())) { |
| + document().addStyleReattachData(*this, styleReattachData); |
| + setNeedsReattachLayoutTree(); |
| + recalcContainedStyleForReattach(); |
| + } |
| +} |
| + |
| +void Element::recalcContainedStyleForReattach() { |
| + if (!childrenCanHaveStyle()) |
| + return; |
| + if (hasCustomStyleCallbacks()) |
| + return; |
| + |
| + SelectorFilterParentScope filterScope(*this); |
| + StyleSharingDepthScope sharingScope(*this); |
| + recalcPseudoStyleForReattach(PseudoIdBefore); |
| + recalcShadowRootStylesForReattach(); |
| + recalcDescendantStylesForReattach(); |
| + recalcPseudoStyleForReattach(PseudoIdAfter); |
| + recalcPseudoStyleForReattach(PseudoIdBackdrop); |
| + recalcPseudoStyleForReattach(PseudoIdFirstLetter); |
| +} |
| + |
| +void Element::recalcPseudoStyleForReattach(PseudoId pseudoId) { |
| + if (PseudoElement* element = pseudoElement(pseudoId)) |
| + element->recalcStyleForReattach(); |
| +} |
| + |
| +void Element::recalcShadowRootStylesForReattach() { |
| + for (ShadowRoot* root = youngestShadowRoot(); root; |
| + root = root->olderShadowRoot()) { |
| + root->recalcDescendantStylesForReattach(); |
| + } |
| +} |
| + |
| void Element::rebuildLayoutTree() { |
| DCHECK(inActiveDocument()); |
| DCHECK(parentNode()); |
| @@ -2078,6 +2121,7 @@ void Element::rebuildLayoutTree() { |
| StyleReattachData styleReattachData = |
| document().getStyleReattachData(*this); |
| AttachContext reattachContext; |
| + // TODO(nainar): Shouldn't need AttachContext.resolvedStyle anymore |
| reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
| bool layoutObjectWillChange = needsAttach() || layoutObject(); |
| reattachLayoutTree(reattachContext); |