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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Make needsAttach() only check if getStyleChangeType flag is NeedsReattachStyleChange and add a Layo… Created 3 years, 9 months 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/dom/Node.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 945e0dc673290e2e4f6a04363892934c68ea2543..cc1d397aa1aa561fd9b5f602560c0ba9359cbf72 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -1930,14 +1930,17 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
}
if (parentComputedStyle())
change = recalcOwnStyle(change, nextTextSibling);
- clearNeedsStyleRecalc();
- clearNeedsReattachLayoutTree();
+ // Needed because the rebuildLayoutTree code needs to see what the
+ // styleChangeType() was on reattach roots. See Node::reattachLayoutTree()
+ // for an example.
+ 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);
@@ -1963,7 +1966,6 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
childNeedsStyleRecalc() ? Force : change);
clearChildNeedsStyleRecalc();
- clearChildNeedsReattachLayoutTree();
}
if (hasCustomStyleCallbacks())
@@ -2023,7 +2025,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
styleReattachData.nextTextSibling = nextTextSibling;
document().addStyleReattachData(*this, styleReattachData);
setNeedsReattachLayoutTree();
- return rebuildLayoutTree();
+ return Reattach;
}
DCHECK(oldStyle);
@@ -2067,34 +2069,57 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change,
return localChange;
}
-StyleRecalcChange Element::rebuildLayoutTree() {
+void Element::rebuildLayoutTree() {
DCHECK(inActiveDocument());
- 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()) {
+ StyleReattachData styleReattachData =
+ document().getStyleReattachData(*this);
+ AttachContext reattachContext;
+ reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
+ bool layoutObjectWillChange = needsAttach() || layoutObject();
+ reattachLayoutTree(reattachContext);
+ 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.
+ reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
+ }
+ } 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()) {
- // 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.
- reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
- return Reattach;
+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);
}
- return ReattachNoLayoutObject;
}
void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/dom/Node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698