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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Clean up all the asserts Created 3 years, 10 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 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 if (change != IndependentInherit) 1896 if (change != IndependentInherit)
1897 data->clearComputedStyle(); 1897 data->clearComputedStyle();
1898 1898
1899 if (change >= IndependentInherit) { 1899 if (change >= IndependentInherit) {
1900 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1900 if (ElementAnimations* elementAnimations = data->elementAnimations())
1901 elementAnimations->setAnimationStyleChange(false); 1901 elementAnimations->setAnimationStyleChange(false);
1902 } 1902 }
1903 } 1903 }
1904 if (parentComputedStyle()) 1904 if (parentComputedStyle())
1905 change = recalcOwnStyle(change, nextTextSibling); 1905 change = recalcOwnStyle(change, nextTextSibling);
1906 clearNeedsStyleRecalc(); 1906 if (change != Reattach)
nainar 2017/02/16 08:05:57 This was initially if (!needsReattachLayoutTree) -
esprehn 2017/02/16 21:24:33 If we're going to reattach, then we did setNeedsRe
nainar 2017/02/16 22:26:09 change == Reattach does imply needsReattachLayoutT
1907 clearNeedsReattachLayoutTree(); 1907 clearNeedsStyleRecalc();
1908 } 1908 }
1909 1909
1910 // If we reattached we don't need to recalc the style of our descendants 1910 // If we are going to reattach we don't need to recalc the style of
1911 // anymore. 1911 // our descendants anymore.
1912 if ((change >= UpdatePseudoElements && change < Reattach) || 1912 if (change < Reattach &&
1913 childNeedsStyleRecalc()) { 1913 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) {
1914 SelectorFilterParentScope filterScope(*this); 1914 SelectorFilterParentScope filterScope(*this);
1915 StyleSharingDepthScope sharingScope(*this); 1915 StyleSharingDepthScope sharingScope(*this);
1916 1916
1917 updatePseudoElement(PseudoIdBefore, change); 1917 updatePseudoElement(PseudoIdBefore, change);
1918 1918
1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { 1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1920 for (ShadowRoot* root = youngestShadowRoot(); root; 1920 for (ShadowRoot* root = youngestShadowRoot(); root;
1921 root = root->olderShadowRoot()) { 1921 root = root->olderShadowRoot()) {
1922 if (root->shouldCallRecalcStyle(change)) 1922 if (root->shouldCallRecalcStyle(change))
1923 root->recalcStyle(change); 1923 root->recalcStyle(change);
1924 } 1924 }
1925 recalcDescendantStyles(change); 1925 recalcDescendantStyles(change);
1926 } 1926 }
1927 1927
1928 updatePseudoElement(PseudoIdAfter, change); 1928 updatePseudoElement(PseudoIdAfter, change);
1929 updatePseudoElement(PseudoIdBackdrop, change); 1929 updatePseudoElement(PseudoIdBackdrop, change);
1930 1930
1931 // If our children have changed then we need to force the first-letter 1931 // If our children have changed then we need to force the first-letter
1932 // checks as we don't know if they effected the first letter or not. 1932 // checks as we don't know if they effected the first letter or not.
1933 // This can be seen when a child transitions from floating to 1933 // This can be seen when a child transitions from floating to
1934 // non-floating we have to take it into account for the first letter. 1934 // non-floating we have to take it into account for the first letter.
1935 updatePseudoElement(PseudoIdFirstLetter, 1935 updatePseudoElement(PseudoIdFirstLetter,
1936 childNeedsStyleRecalc() ? Force : change); 1936 childNeedsStyleRecalc() ? Force : change);
1937 1937
1938 clearChildNeedsStyleRecalc(); 1938 clearChildNeedsStyleRecalc();
1939 clearChildNeedsReattachLayoutTree();
1940 } 1939 }
1941 1940
1942 if (hasCustomStyleCallbacks()) 1941 if (hasCustomStyleCallbacks())
1943 didRecalcStyle(); 1942 didRecalcStyle();
1944 } 1943 }
1945 1944
1946 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1945 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1947 StyleRecalcChange change) { 1946 StyleRecalcChange change) {
1948 if (change != IndependentInherit) 1947 if (change != IndependentInherit)
1949 return nullptr; 1948 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 } else { 1988 } else {
1990 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1989 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1991 } 1990 }
1992 1991
1993 if (localChange == Reattach) { 1992 if (localChange == Reattach) {
1994 StyleReattachData styleReattachData; 1993 StyleReattachData styleReattachData;
1995 styleReattachData.computedStyle = std::move(newStyle); 1994 styleReattachData.computedStyle = std::move(newStyle);
1996 styleReattachData.nextTextSibling = nextTextSibling; 1995 styleReattachData.nextTextSibling = nextTextSibling;
1997 document().addStyleReattachData(*this, styleReattachData); 1996 document().addStyleReattachData(*this, styleReattachData);
1998 setNeedsReattachLayoutTree(); 1997 setNeedsReattachLayoutTree();
1999 return rebuildLayoutTree(); 1998 return Reattach;
2000 } 1999 }
2001 2000
2002 DCHECK(oldStyle); 2001 DCHECK(oldStyle);
2003 2002
2004 if (localChange != NoChange) 2003 if (localChange != NoChange)
2005 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 2004 updateCallbackSelectors(oldStyle.get(), newStyle.get());
2006 2005
2007 if (LayoutObject* layoutObject = this->layoutObject()) { 2006 if (LayoutObject* layoutObject = this->layoutObject()) {
2008 if (localChange != NoChange || 2007 if (localChange != NoChange ||
2009 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 2008 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
2030 return Inherit; 2029 return Inherit;
2031 newStyle->copyChildDependentFlagsFrom(*oldStyle); 2030 newStyle->copyChildDependentFlagsFrom(*oldStyle);
2032 } 2031 }
2033 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 2032 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
2034 return UpdatePseudoElements; 2033 return UpdatePseudoElements;
2035 } 2034 }
2036 2035
2037 return localChange; 2036 return localChange;
2038 } 2037 }
2039 2038
2040 StyleRecalcChange Element::rebuildLayoutTree() { 2039 void Element::rebuildLayoutTree() {
2041 DCHECK(inActiveDocument()); 2040 DCHECK(inActiveDocument());
2041 DCHECK(parentNode());
2042
2042 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2043 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
2043 AttachContext reattachContext; 2044 AttachContext reattachContext;
2044 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2045 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2045 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2046 bool layoutObjectWillChange = needsAttach() || layoutObject();
2046 2047
2047 // We are calling Element::rebuildLayoutTree() from inside 2048 if (needsReattachLayoutTree()) {
2048 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2049 reattachLayoutTree(reattachContext);
2049 // flag - so needsReattachLayoutTree() should always be true. 2050 } else if (childNeedsReattachLayoutTree()) {
2050 DCHECK(parentNode()); 2051 DCHECK(!needsReattachLayoutTree());
2051 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2052 SelectorFilterParentScope filterScope(*this);
2052 DCHECK(needsReattachLayoutTree()); 2053 StyleSharingDepthScope sharingScope(*this);
2053 reattachLayoutTree(reattachContext); 2054 reattachPseudoElementLayoutTree(PseudoIdBefore);
2054 // Since needsReattachLayoutTree() is always true we go into 2055 rebuildShadowRootLayoutTree();
2055 // reattachLayoutTree() which reattaches all the descendant 2056 rebuildChildrenLayoutTrees();
2056 // sub-trees. At this point no child should need reattaching. 2057 reattachPseudoElementLayoutTree(PseudoIdAfter);
2058 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2059 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2060 }
2061 DCHECK(!needsStyleRecalc());
2062 DCHECK(!childNeedsStyleRecalc());
2063 DCHECK(!needsReattachLayoutTree());
2057 DCHECK(!childNeedsReattachLayoutTree()); 2064 DCHECK(!childNeedsReattachLayoutTree());
2058 2065
2059 if (layoutObjectWillChange || layoutObject()) { 2066 if (layoutObjectWillChange || layoutObject()) {
2060 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2067 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2061 // we can either traverse the current subtree from this node onwards 2068 // we can either traverse the current subtree from this node onwards
2062 // or store it. 2069 // or store it.
2063 // The choice is between increased time and increased memory complexity. 2070 // The choice is between increased time and increased memory complexity.
2064 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2071 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2065 return Reattach;
2066 } 2072 }
2067 return ReattachNoLayoutObject; 2073 }
2074
2075 void Element::rebuildShadowRootLayoutTree() {
2076 for (ShadowRoot* root = youngestShadowRoot(); root;
2077 root = root->olderShadowRoot()) {
2078 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2079 root->rebuildLayoutTree();
2080 }
2081 }
2082
2083 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2084 if (PseudoElement* element = pseudoElement(pseudoId)) {
2085 if (element->needsReattachLayoutTree() ||
2086 element->childNeedsReattachLayoutTree())
2087 element->rebuildLayoutTree();
2088 } else {
2089 createPseudoElementIfNeeded(pseudoId);
2090 }
2068 } 2091 }
2069 2092
2070 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2093 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2071 const ComputedStyle* newStyle) { 2094 const ComputedStyle* newStyle) {
2072 Vector<String> emptyVector; 2095 Vector<String> emptyVector;
2073 const Vector<String>& oldCallbackSelectors = 2096 const Vector<String>& oldCallbackSelectors =
2074 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2097 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2075 const Vector<String>& newCallbackSelectors = 2098 const Vector<String>& newCallbackSelectors =
2076 newStyle ? newStyle->callbackSelectors() : emptyVector; 2099 newStyle ? newStyle->callbackSelectors() : emptyVector;
2077 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2100 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 2056 matching lines...) Expand 10 before | Expand all | Expand 10 after
4134 } 4157 }
4135 4158
4136 DEFINE_TRACE_WRAPPERS(Element) { 4159 DEFINE_TRACE_WRAPPERS(Element) {
4137 if (hasRareData()) { 4160 if (hasRareData()) {
4138 visitor->traceWrappers(elementRareData()); 4161 visitor->traceWrappers(elementRareData());
4139 } 4162 }
4140 ContainerNode::traceWrappers(visitor); 4163 ContainerNode::traceWrappers(visitor);
4141 } 4164 }
4142 4165
4143 } // namespace blink 4166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698