Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Unified Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: FirstLetterPseudoElements are not being created Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 7c286936357b055b17ba342c2581c8daf2be69cc..c09f3f45f0f1165eaa056cd560d4cff48d7d99a7 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -1855,10 +1855,12 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
elementAnimations->setAnimationStyleChange(false);
}
}
- if (parentComputedStyle())
+ if (parentComputedStyle()) {
change = recalcOwnStyle(change, nextTextSibling);
+ } else {
+ clearNeedsReattachLayoutTree();
nainar 2016/12/07 14:48:21 In case we don't perform recalcOwnStyle we will ne
Bugs Nash 2016/12/07 23:21:44 good explanation, would be useful in a code commen
nainar 2016/12/07 23:49:10 Done locally.
+ }
clearNeedsStyleRecalc();
- clearNeedsReattachLayoutTree();
}
// If we reattached we don't need to recalc the style of our descendants
@@ -1890,7 +1892,6 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
childNeedsStyleRecalc() ? Force : change);
clearChildNeedsStyleRecalc();
- clearChildNeedsReattachLayoutTree();
}
if (hasCustomStyleCallbacks())
@@ -1950,7 +1951,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
styleReattachData.nextTextSibling = nextTextSibling;
document().addStyleReattachData(*this, styleReattachData);
setNeedsReattachLayoutTree();
- return rebuildLayoutTree();
+ return Reattach;
}
DCHECK(oldStyle);
@@ -1991,23 +1992,30 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
return localChange;
}
-StyleRecalcChange Element::rebuildLayoutTree() {
+void Element::rebuildLayoutTree() {
DCHECK(inActiveDocument());
+ DCHECK(!needsStyleRecalc());
+ DCHECK(!childNeedsStyleRecalc());
+ 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()) {
+ SelectorFilterParentScope filterScope(*this);
+ StyleSharingDepthScope sharingScope(*this);
+ reattachPseudoElementLayoutTree(PseudoIdBefore);
+ rebuildShadowRootLayoutTree();
+ rebuildDescendantLayoutTrees();
+ reattachPseudoElementLayoutTree(PseudoIdAfter);
+ reattachPseudoElementLayoutTree(PseudoIdBackdrop);
+ reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
+ }
+ DCHECK(!needsReattachLayoutTree());
DCHECK(!childNeedsReattachLayoutTree());
if (layoutObjectWillChange || layoutObject()) {
@@ -2016,9 +2024,29 @@ 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() {
+ DCHECK(!needsStyleRecalc());
+ DCHECK(!childNeedsStyleRecalc());
+ DCHECK(!needsReattachLayoutTree());
+ for (ShadowRoot* root = youngestShadowRoot(); root;
+ root = root->olderShadowRoot()) {
+ if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
+ root->rebuildLayoutTree();
+ }
+}
+
+void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
+ DCHECK(!needsStyleRecalc());
+ DCHECK(!childNeedsStyleRecalc());
+ DCHECK(!needsReattachLayoutTree());
+ if (PseudoElement* element = pseudoElement(pseudoId)) {
+ if (element->needsReattachLayoutTree() ||
+ element->childNeedsReattachLayoutTree())
+ element->rebuildLayoutTree();
+ }
}
void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
@@ -3246,7 +3274,6 @@ void Element::createPseudoElementIfNeeded(PseudoId pseudoId) {
document().addToTopLayer(element, this);
element->insertedInto(this);
element->attachLayoutTree();
-
Bugs Nash 2016/12/07 23:21:44 was this intentional?
nainar 2016/12/07 23:49:10 Nope - haven't sanitized the code for erroneous fo
InspectorInstrumentation::pseudoElementCreated(element);
ensureElementRareData().setPseudoElement(pseudoId, element);

Powered by Google App Engine
This is Rietveld 408576698