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

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Address esprehn's comments 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 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 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 if (hasRareData()) { 1848 if (hasRareData()) {
1849 ElementRareData* data = elementRareData(); 1849 ElementRareData* data = elementRareData();
1850 if (change != IndependentInherit) 1850 if (change != IndependentInherit)
1851 data->clearComputedStyle(); 1851 data->clearComputedStyle();
1852 1852
1853 if (change >= IndependentInherit) { 1853 if (change >= IndependentInherit) {
1854 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1854 if (ElementAnimations* elementAnimations = data->elementAnimations())
1855 elementAnimations->setAnimationStyleChange(false); 1855 elementAnimations->setAnimationStyleChange(false);
1856 } 1856 }
1857 } 1857 }
1858 if (parentComputedStyle()) 1858 if (parentComputedStyle()) {
1859 change = recalcOwnStyle(change, nextTextSibling); 1859 change = recalcOwnStyle(change, nextTextSibling);
1860 } else {
1861 // In case we don't perform recalcOwnStyle we will never clear the
1862 // NeedsReattachLayoutTree flag which is set on the creation of each
1863 // Node. Clear that here.
1864 clearNeedsReattachLayoutTree();
1865 }
1860 clearNeedsStyleRecalc(); 1866 clearNeedsStyleRecalc();
1861 clearNeedsReattachLayoutTree();
1862 } 1867 }
1863 1868
1864 // If we reattached we don't need to recalc the style of our descendants 1869 // If we reattached we don't need to recalc the style of our descendants
1865 // anymore. 1870 // anymore.
1866 if ((change >= UpdatePseudoElements && change < Reattach) || 1871 if ((change >= UpdatePseudoElements && change < Reattach) ||
1867 childNeedsStyleRecalc()) { 1872 childNeedsStyleRecalc()) {
1868 SelectorFilterParentScope filterScope(*this); 1873 SelectorFilterParentScope filterScope(*this);
1869 StyleSharingDepthScope sharingScope(*this); 1874 StyleSharingDepthScope sharingScope(*this);
1870 1875
1871 updatePseudoElement(PseudoIdBefore, change); 1876 updatePseudoElement(PseudoIdBefore, change);
(...skipping 11 matching lines...) Expand all
1883 updatePseudoElement(PseudoIdBackdrop, change); 1888 updatePseudoElement(PseudoIdBackdrop, change);
1884 1889
1885 // If our children have changed then we need to force the first-letter 1890 // If our children have changed then we need to force the first-letter
1886 // checks as we don't know if they effected the first letter or not. 1891 // checks as we don't know if they effected the first letter or not.
1887 // This can be seen when a child transitions from floating to 1892 // This can be seen when a child transitions from floating to
1888 // non-floating we have to take it into account for the first letter. 1893 // non-floating we have to take it into account for the first letter.
1889 updatePseudoElement(PseudoIdFirstLetter, 1894 updatePseudoElement(PseudoIdFirstLetter,
1890 childNeedsStyleRecalc() ? Force : change); 1895 childNeedsStyleRecalc() ? Force : change);
1891 1896
1892 clearChildNeedsStyleRecalc(); 1897 clearChildNeedsStyleRecalc();
1893 clearChildNeedsReattachLayoutTree();
1894 } 1898 }
1895 1899
1896 if (hasCustomStyleCallbacks()) 1900 if (hasCustomStyleCallbacks())
1897 didRecalcStyle(change); 1901 didRecalcStyle(change);
1898 } 1902 }
1899 1903
1900 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1904 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1901 StyleRecalcChange change) { 1905 StyleRecalcChange change) {
1902 if (change != IndependentInherit) 1906 if (change != IndependentInherit)
1903 return nullptr; 1907 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 } else { 1947 } else {
1944 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1948 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1945 } 1949 }
1946 1950
1947 if (localChange == Reattach) { 1951 if (localChange == Reattach) {
1948 StyleReattachData styleReattachData; 1952 StyleReattachData styleReattachData;
1949 styleReattachData.computedStyle = std::move(newStyle); 1953 styleReattachData.computedStyle = std::move(newStyle);
1950 styleReattachData.nextTextSibling = nextTextSibling; 1954 styleReattachData.nextTextSibling = nextTextSibling;
1951 document().addStyleReattachData(*this, styleReattachData); 1955 document().addStyleReattachData(*this, styleReattachData);
1952 setNeedsReattachLayoutTree(); 1956 setNeedsReattachLayoutTree();
1953 return rebuildLayoutTree(); 1957 return Reattach;
1954 } 1958 }
1955 1959
1956 DCHECK(oldStyle); 1960 DCHECK(oldStyle);
1957 1961
1958 if (localChange != NoChange) 1962 if (localChange != NoChange)
1959 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 1963 updateCallbackSelectors(oldStyle.get(), newStyle.get());
1960 1964
1961 if (LayoutObject* layoutObject = this->layoutObject()) { 1965 if (LayoutObject* layoutObject = this->layoutObject()) {
1962 if (localChange != NoChange || 1966 if (localChange != NoChange ||
1963 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 1967 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
1984 return Inherit; 1988 return Inherit;
1985 newStyle->copyChildDependentFlagsFrom(*oldStyle); 1989 newStyle->copyChildDependentFlagsFrom(*oldStyle);
1986 } 1990 }
1987 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 1991 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
1988 return UpdatePseudoElements; 1992 return UpdatePseudoElements;
1989 } 1993 }
1990 1994
1991 return localChange; 1995 return localChange;
1992 } 1996 }
1993 1997
1994 StyleRecalcChange Element::rebuildLayoutTree() { 1998 void Element::rebuildLayoutTree() {
1995 DCHECK(inActiveDocument()); 1999 DCHECK(inActiveDocument());
2000 DCHECK(!needsStyleRecalc());
2001 DCHECK(!childNeedsStyleRecalc());
esprehn 2016/12/14 04:30:47 Yeah so you assert !childNeedsStyleRecalc here so
nainar 2016/12/14 22:21:54 ACK.
2002 DCHECK(parentNode());
2003
1996 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2004 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
1997 AttachContext reattachContext; 2005 AttachContext reattachContext;
1998 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2006 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
1999 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2007 bool layoutObjectWillChange = needsAttach() || layoutObject();
2000 2008
2001 // We are calling Element::rebuildLayoutTree() from inside 2009 if (needsReattachLayoutTree()) {
2002 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2010 reattachLayoutTree(reattachContext);
2003 // flag - so needsReattachLayoutTree() should always be true. 2011 } else if (childNeedsReattachLayoutTree()) {
2004 DCHECK(parentNode()); 2012 SelectorFilterParentScope filterScope(*this);
2005 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2013 StyleSharingDepthScope sharingScope(*this);
2006 DCHECK(needsReattachLayoutTree()); 2014 reattachPseudoElementLayoutTree(PseudoIdBefore);
2007 reattachLayoutTree(reattachContext); 2015 rebuildShadowRootLayoutTree();
2008 // Since needsReattachLayoutTree() is always true we go into 2016 rebuildChildrenLayoutTrees();
2009 // reattachLayoutTree() which reattaches all the descendant 2017 reattachPseudoElementLayoutTree(PseudoIdAfter);
2010 // sub-trees. At this point no child should need reattaching. 2018 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2019 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2020 }
2021 DCHECK(!needsReattachLayoutTree());
2011 DCHECK(!childNeedsReattachLayoutTree()); 2022 DCHECK(!childNeedsReattachLayoutTree());
2012 2023
2013 if (layoutObjectWillChange || layoutObject()) { 2024 if (layoutObjectWillChange || layoutObject()) {
2014 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2025 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2015 // we can either traverse the current subtree from this node onwards 2026 // we can either traverse the current subtree from this node onwards
2016 // or store it. 2027 // or store it.
2017 // The choice is between increased time and increased memory complexity. 2028 // The choice is between increased time and increased memory complexity.
2018 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2029 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2019 return Reattach;
2020 } 2030 }
2021 return ReattachNoLayoutObject; 2031 }
2032
2033 void Element::rebuildShadowRootLayoutTree() {
2034 DCHECK(!needsStyleRecalc());
2035 DCHECK(!childNeedsStyleRecalc());
2036 DCHECK(!needsReattachLayoutTree());
2037 for (ShadowRoot* root = youngestShadowRoot(); root;
2038 root = root->olderShadowRoot()) {
2039 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2040 root->rebuildLayoutTree();
2041 }
2042 }
2043
2044 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2045 DCHECK(!needsStyleRecalc());
2046 DCHECK(!childNeedsStyleRecalc());
2047 DCHECK(!needsReattachLayoutTree());
2048 if (PseudoElement* element = pseudoElement(pseudoId)) {
2049 if (element->needsReattachLayoutTree() ||
2050 element->childNeedsReattachLayoutTree())
2051 element->rebuildLayoutTree();
2052 } else {
2053 createPseudoElementIfNeeded(pseudoId);
2054 }
2022 } 2055 }
2023 2056
2024 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2057 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2025 const ComputedStyle* newStyle) { 2058 const ComputedStyle* newStyle) {
2026 Vector<String> emptyVector; 2059 Vector<String> emptyVector;
2027 const Vector<String>& oldCallbackSelectors = 2060 const Vector<String>& oldCallbackSelectors =
2028 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2061 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2029 const Vector<String>& newCallbackSelectors = 2062 const Vector<String>& newCallbackSelectors =
2030 newStyle ? newStyle->callbackSelectors() : emptyVector; 2063 newStyle ? newStyle->callbackSelectors() : emptyVector;
2031 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2064 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after
4091 } 4124 }
4092 4125
4093 DEFINE_TRACE_WRAPPERS(Element) { 4126 DEFINE_TRACE_WRAPPERS(Element) {
4094 if (hasRareData()) { 4127 if (hasRareData()) {
4095 visitor->traceWrappers(elementRareData()); 4128 visitor->traceWrappers(elementRareData());
4096 } 4129 }
4097 ContainerNode::traceWrappers(visitor); 4130 ContainerNode::traceWrappers(visitor);
4098 } 4131 }
4099 4132
4100 } // namespace blink 4133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698