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

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: Clear nextTextSibling pointer where there is a LayoutObject between the element and text node 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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();
esprehn 2016/10/10 21:50:42 this breaks at the first non element, ex. text or
nainar 2016/10/10 22:56:34 Added NOTREACHED() here and noted the changes need
2002 child = child->nextSibling())
2003 toElement(child)->rebuildLayoutTree();
2004
2005 reattachPseudoElementLayoutTree(PseudoIdAfter);
2006 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2007 }
2008
2009 if (layoutObjectWillChange || layoutObject()) {
2010 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
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* nextTextSibling = nullptr;
2015 for (Node* child = parentNode()->lastChild(); child;
esprehn 2016/10/10 21:50:42 This is n^2, if you appendChild 500 elements, this
nainar 2016/10/10 22:56:34 Done. Starting iteration from this->nextSibling.
2016 child = child->previousSibling()) {
2017 if (child->isTextNode()) {
2018 nextTextSibling = toText(child);
2019 } else if (child->isElementNode()) {
2020 if (toElement(child) == this) {
2021 reattachWhitespaceSiblingsIfNeeded(nextTextSibling);
2022 break;
2023 }
2024 if (toElement(child)->layoutObject()) {
2025 nextTextSibling = nullptr;
2026 }
2027 }
2028 }
1997 return Reattach; 2029 return Reattach;
2030 }
1998 return ReattachNoLayoutObject; 2031 return ReattachNoLayoutObject;
1999 } 2032 }
2000 2033
2034 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2035 if (PseudoElement* element = pseudoElement(pseudoId)) {
2036 if (element->needsReattachLayoutTree())
2037 element->rebuildLayoutTree();
2038 }
2039 }
2040
2001 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2041 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2002 const ComputedStyle* newStyle) { 2042 const ComputedStyle* newStyle) {
2003 Vector<String> emptyVector; 2043 Vector<String> emptyVector;
2004 const Vector<String>& oldCallbackSelectors = 2044 const Vector<String>& oldCallbackSelectors =
2005 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2045 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2006 const Vector<String>& newCallbackSelectors = 2046 const Vector<String>& newCallbackSelectors =
2007 newStyle ? newStyle->callbackSelectors() : emptyVector; 2047 newStyle ? newStyle->callbackSelectors() : emptyVector;
2008 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2048 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
2009 return; 2049 return;
2010 if (oldCallbackSelectors != newCallbackSelectors) 2050 if (oldCallbackSelectors != newCallbackSelectors)
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 } 4122 }
4083 4123
4084 DEFINE_TRACE_WRAPPERS(Element) { 4124 DEFINE_TRACE_WRAPPERS(Element) {
4085 if (hasRareData()) { 4125 if (hasRareData()) {
4086 visitor->traceWrappers(elementRareData()); 4126 visitor->traceWrappers(elementRareData());
4087 } 4127 }
4088 ContainerNode::traceWrappers(visitor); 4128 ContainerNode::traceWrappers(visitor);
4089 } 4129 }
4090 4130
4091 } // namespace blink 4131 } // namespace blink
OLDNEW
« 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