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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * (C) 2007 Eric Seidel (eric@webkit.org) 9 * (C) 2007 Eric Seidel (eric@webkit.org)
10 * 10 *
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 data->clearComputedStyle(); 1853 data->clearComputedStyle();
1854 1854
1855 if (change >= IndependentInherit) { 1855 if (change >= IndependentInherit) {
1856 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1856 if (ElementAnimations* elementAnimations = data->elementAnimations())
1857 elementAnimations->setAnimationStyleChange(false); 1857 elementAnimations->setAnimationStyleChange(false);
1858 } 1858 }
1859 } 1859 }
1860 if (parentComputedStyle()) 1860 if (parentComputedStyle())
1861 change = recalcOwnStyle(change); 1861 change = recalcOwnStyle(change);
1862 clearNeedsStyleRecalc(); 1862 clearNeedsStyleRecalc();
1863 clearNeedsReattachLayoutTree();
1863 } 1864 }
1864 1865
1865 // If we reattached we don't need to recalc the style of our descendants 1866 // If we reattached we don't need to recalc the style of our descendants
1866 // anymore. 1867 // anymore.
1867 if ((change >= UpdatePseudoElements && change < Reattach) || 1868 if ((change >= UpdatePseudoElements && change < Reattach) ||
1868 childNeedsStyleRecalc()) { 1869 childNeedsStyleRecalc()) {
1869 SelectorFilterParentScope filterScope(*this); 1870 SelectorFilterParentScope filterScope(*this);
1870 StyleSharingDepthScope sharingScope(*this); 1871 StyleSharingDepthScope sharingScope(*this);
1871 1872
1872 updatePseudoElement(PseudoIdBefore, change); 1873 updatePseudoElement(PseudoIdBefore, change);
(...skipping 11 matching lines...) Expand all
1884 updatePseudoElement(PseudoIdBackdrop, change); 1885 updatePseudoElement(PseudoIdBackdrop, change);
1885 1886
1886 // If our children have changed then we need to force the first-letter 1887 // If our children have changed then we need to force the first-letter
1887 // checks as we don't know if they effected the first letter or not. 1888 // checks as we don't know if they effected the first letter or not.
1888 // This can be seen when a child transitions from floating to 1889 // This can be seen when a child transitions from floating to
1889 // non-floating we have to take it into account for the first letter. 1890 // non-floating we have to take it into account for the first letter.
1890 updatePseudoElement(PseudoIdFirstLetter, 1891 updatePseudoElement(PseudoIdFirstLetter,
1891 childNeedsStyleRecalc() ? Force : change); 1892 childNeedsStyleRecalc() ? Force : change);
1892 1893
1893 clearChildNeedsStyleRecalc(); 1894 clearChildNeedsStyleRecalc();
1895 clearChildNeedsReattachLayoutTree();
1894 } 1896 }
1895 1897
1896 if (hasCustomStyleCallbacks()) 1898 if (hasCustomStyleCallbacks())
1897 didRecalcStyle(change); 1899 didRecalcStyle(change);
1898
nainar 2016/10/07 05:05:05 Moved this to rebuildLayoutTree()
1899 if (change == Reattach)
1900 reattachWhitespaceSiblingsIfNeeded(nextTextSibling);
1901 } 1900 }
1902 1901
1903 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1902 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1904 StyleRecalcChange change) { 1903 StyleRecalcChange change) {
1905 if (change != IndependentInherit) 1904 if (change != IndependentInherit)
1906 return nullptr; 1905 return nullptr;
1907 if (needsStyleRecalc()) 1906 if (needsStyleRecalc())
1908 return nullptr; 1907 return nullptr;
1909 if (hasAnimations()) 1908 if (hasAnimations())
1910 return nullptr; 1909 return nullptr;
(...skipping 28 matching lines...) Expand all
1939 StyleRecalcChange localChange = 1938 StyleRecalcChange localChange =
1940 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); 1939 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get());
1941 if (localChange == NoChange) { 1940 if (localChange == NoChange) {
1942 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); 1941 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1);
1943 } else { 1942 } else {
1944 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1943 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1945 } 1944 }
1946 1945
1947 if (localChange == Reattach) { 1946 if (localChange == Reattach) {
1948 document().addNonAttachedStyle(*this, std::move(newStyle)); 1947 document().addNonAttachedStyle(*this, std::move(newStyle));
1948 setNeedsReattachLayoutTree();
1949 return rebuildLayoutTree(); 1949 return rebuildLayoutTree();
1950 } 1950 }
1951 1951
1952 DCHECK(oldStyle); 1952 DCHECK(oldStyle);
1953 1953
1954 if (localChange != NoChange) 1954 if (localChange != NoChange)
1955 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 1955 updateCallbackSelectors(oldStyle.get(), newStyle.get());
1956 1956
1957 if (LayoutObject* layoutObject = this->layoutObject()) { 1957 if (LayoutObject* layoutObject = this->layoutObject()) {
1958 if (localChange != NoChange || 1958 if (localChange != NoChange ||
(...skipping 26 matching lines...) Expand all
1985 return UpdatePseudoElements; 1985 return UpdatePseudoElements;
1986 } 1986 }
1987 1987
1988 return localChange; 1988 return localChange;
1989 } 1989 }
1990 1990
1991 StyleRecalcChange Element::rebuildLayoutTree() { 1991 StyleRecalcChange Element::rebuildLayoutTree() {
1992 AttachContext reattachContext; 1992 AttachContext reattachContext;
1993 reattachContext.resolvedStyle = document().getNonAttachedStyle(*this); 1993 reattachContext.resolvedStyle = document().getNonAttachedStyle(*this);
1994 bool layoutObjectWillChange = needsAttach() || layoutObject(); 1994 bool layoutObjectWillChange = needsAttach() || layoutObject();
1995 reattachLayoutTree(reattachContext); 1995
1996 if (layoutObjectWillChange || layoutObject()) 1996 if (needsReattachLayoutTree()) {
1997 reattachLayoutTree(reattachContext);
1998 } else if (childNeedsReattachLayoutTree()) {
1999 reattachPseudoElementLayoutTree(PseudoIdBefore);
2000
2001 for (Node* child = firstChild(); child && child->isElementNode();
2002 child = child->nextSibling())
2003 toElement(child)->rebuildLayoutTree();
2004
2005 reattachPseudoElementLayoutTree(PseudoIdAfter);
2006 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2007 }
2008
2009 if (layoutObjectWillChange || layoutObject()) {
2010 // 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
2011 // we can either traverse the parent's tree to get this node or store it
2012 // (like WebKit does).
2013 // The choice is between increased time and increased memory complexity
2014 Text* lastTextNode = nullptr;
2015 for (Node* child = parentNode()->lastChild(); child;
2016 child = child->previousSibling()) {
2017 if (child->isTextNode()) {
2018 lastTextNode = toText(child);
2019 } else if (child->isElementNode() && toElement(child) == this) {
2020 // This check: toElement(child) == this is present so that we don't do
2021 // added work for a siblingNode of this element
2022 reattachWhitespaceSiblingsIfNeeded(lastTextNode);
2023 break;
2024 }
2025 }
1997 return Reattach; 2026 return Reattach;
2027 }
1998 return ReattachNoLayoutObject; 2028 return ReattachNoLayoutObject;
1999 } 2029 }
2000 2030
2031 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2032 if (PseudoElement* element = pseudoElement(pseudoId)) {
2033 if (element->needsReattachLayoutTree())
2034 element->rebuildLayoutTree();
2035 }
2036 }
2037
2001 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2038 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2002 const ComputedStyle* newStyle) { 2039 const ComputedStyle* newStyle) {
2003 Vector<String> emptyVector; 2040 Vector<String> emptyVector;
2004 const Vector<String>& oldCallbackSelectors = 2041 const Vector<String>& oldCallbackSelectors =
2005 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2042 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2006 const Vector<String>& newCallbackSelectors = 2043 const Vector<String>& newCallbackSelectors =
2007 newStyle ? newStyle->callbackSelectors() : emptyVector; 2044 newStyle ? newStyle->callbackSelectors() : emptyVector;
2008 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2045 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
2009 return; 2046 return;
2010 if (oldCallbackSelectors != newCallbackSelectors) 2047 if (oldCallbackSelectors != newCallbackSelectors)
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 } 4119 }
4083 4120
4084 DEFINE_TRACE_WRAPPERS(Element) { 4121 DEFINE_TRACE_WRAPPERS(Element) {
4085 if (hasRareData()) { 4122 if (hasRareData()) {
4086 visitor->traceWrappers(elementRareData()); 4123 visitor->traceWrappers(elementRareData());
4087 } 4124 }
4088 ContainerNode::traceWrappers(visitor); 4125 ContainerNode::traceWrappers(visitor);
4089 } 4126 }
4090 4127
4091 } // namespace blink 4128 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698