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

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

Issue 2398293003: Move Layout Tree Construction code into Element::rebuildLayoutTree() (Closed)
Patch Set: Run git cl format third_party/WebKit Created 4 years, 2 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
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 047e339cba3e817a5c7eb056291cb3d2776f7584..35d54685e34eb107deb829435a20c713570b2858 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -1860,6 +1860,7 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
if (parentComputedStyle())
change = recalcOwnStyle(change);
clearNeedsStyleRecalc();
+ clearNeedsReattachLayoutTree();
}
// If we reattached we don't need to recalc the style of our descendants
@@ -1891,13 +1892,11 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) {
childNeedsStyleRecalc() ? Force : change);
clearChildNeedsStyleRecalc();
+ clearChildNeedsReattachLayoutTree();
}
if (hasCustomStyleCallbacks())
didRecalcStyle(change);
-
nainar 2016/10/07 05:05:05 Moved this to rebuildLayoutTree()
- if (change == Reattach)
- reattachWhitespaceSiblingsIfNeeded(nextTextSibling);
}
PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
@@ -1946,6 +1945,7 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) {
if (localChange == Reattach) {
document().addNonAttachedStyle(*this, std::move(newStyle));
+ setNeedsReattachLayoutTree();
return rebuildLayoutTree();
}
@@ -1992,12 +1992,49 @@ StyleRecalcChange Element::rebuildLayoutTree() {
AttachContext reattachContext;
reattachContext.resolvedStyle = document().getNonAttachedStyle(*this);
bool layoutObjectWillChange = needsAttach() || layoutObject();
- reattachLayoutTree(reattachContext);
- if (layoutObjectWillChange || layoutObject())
+
+ if (needsReattachLayoutTree()) {
+ reattachLayoutTree(reattachContext);
+ } else if (childNeedsReattachLayoutTree()) {
+ reattachPseudoElementLayoutTree(PseudoIdBefore);
+
+ for (Node* child = firstChild(); child && child->isElementNode();
+ child = child->nextSibling())
+ toElement(child)->rebuildLayoutTree();
+
+ reattachPseudoElementLayoutTree(PseudoIdAfter);
+ reattachPseudoElementLayoutTree(PseudoIdBackdrop);
+ }
+
+ if (layoutObjectWillChange || layoutObject()) {
+ // This is information passed on to recalcStyle from recalcDescendantStyles
nainar 2016/10/07 05:05:05 Need to decide if this method is preferable or whe
+ // we can either traverse the parent's tree to get this node or store it
+ // (like WebKit does).
+ // The choice is between increased time and increased memory complexity
+ Text* lastTextNode = nullptr;
+ for (Node* child = parentNode()->lastChild(); child;
+ child = child->previousSibling()) {
+ if (child->isTextNode()) {
+ lastTextNode = toText(child);
+ } else if (child->isElementNode() && toElement(child) == this) {
+ // This check: toElement(child) == this is present so that we don't do
+ // added work for a siblingNode of this element
+ reattachWhitespaceSiblingsIfNeeded(lastTextNode);
+ break;
+ }
+ }
return Reattach;
+ }
return ReattachNoLayoutObject;
}
+void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
+ if (PseudoElement* element = pseudoElement(pseudoId)) {
+ if (element->needsReattachLayoutTree())
+ element->rebuildLayoutTree();
+ }
+}
+
void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
const ComputedStyle* newStyle) {
Vector<String> emptyVector;

Powered by Google App Engine
This is Rietveld 408576698