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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Remove redundant clear for root's NeedReattachLayoutTree flag 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 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 if (hasRareData()) { 1888 if (hasRareData()) {
1889 ElementRareData* data = elementRareData(); 1889 ElementRareData* data = elementRareData();
1890 if (change != IndependentInherit) 1890 if (change != IndependentInherit)
1891 data->clearComputedStyle(); 1891 data->clearComputedStyle();
1892 1892
1893 if (change >= IndependentInherit) { 1893 if (change >= IndependentInherit) {
1894 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1894 if (ElementAnimations* elementAnimations = data->elementAnimations())
1895 elementAnimations->setAnimationStyleChange(false); 1895 elementAnimations->setAnimationStyleChange(false);
1896 } 1896 }
1897 } 1897 }
1898 if (parentComputedStyle()) 1898 if (parentComputedStyle()) {
1899 change = recalcOwnStyle(change, nextTextSibling); 1899 change = recalcOwnStyle(change, nextTextSibling);
1900 clearNeedsStyleRecalc(); 1900 } else {
1901 clearNeedsReattachLayoutTree(); 1901 // In case we don't perform recalcOwnStyle we will never clear the
1902 // NeedsReattachLayoutTree flag which is set on the creation of each
1903 // Node. Clear that here.
1904 clearNeedsReattachLayoutTree();
1905 }
1906 // If you are going to reattachLayoutTree you need to retain this flag
1907 // to determine if detachLayoutTree() needs to happen.
1908 if (!needsReattachLayoutTree())
1909 clearNeedsStyleRecalc();
1902 } 1910 }
1903 1911
1904 // If we reattached we don't need to recalc the style of our descendants 1912 // If we are going to reattach we don't need to recalc the style of
1905 // anymore. 1913 // our descendants anymore.
1906 if ((change >= UpdatePseudoElements && change < Reattach) || 1914 if (change < Reattach &&
1907 childNeedsStyleRecalc()) { 1915 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) {
1908 SelectorFilterParentScope filterScope(*this); 1916 SelectorFilterParentScope filterScope(*this);
1909 StyleSharingDepthScope sharingScope(*this); 1917 StyleSharingDepthScope sharingScope(*this);
1910 1918
1911 updatePseudoElement(PseudoIdBefore, change); 1919 updatePseudoElement(PseudoIdBefore, change);
1912 1920
1913 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { 1921 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1914 for (ShadowRoot* root = youngestShadowRoot(); root; 1922 for (ShadowRoot* root = youngestShadowRoot(); root;
1915 root = root->olderShadowRoot()) { 1923 root = root->olderShadowRoot()) {
1916 if (root->shouldCallRecalcStyle(change)) 1924 if (root->shouldCallRecalcStyle(change))
1917 root->recalcStyle(change); 1925 root->recalcStyle(change);
1918 } 1926 }
1919 recalcDescendantStyles(change); 1927 recalcDescendantStyles(change);
1920 } 1928 }
1921 1929
1922 updatePseudoElement(PseudoIdAfter, change); 1930 updatePseudoElement(PseudoIdAfter, change);
1923 updatePseudoElement(PseudoIdBackdrop, change); 1931 updatePseudoElement(PseudoIdBackdrop, change);
1924 1932
1925 // If our children have changed then we need to force the first-letter 1933 // If our children have changed then we need to force the first-letter
1926 // checks as we don't know if they effected the first letter or not. 1934 // checks as we don't know if they effected the first letter or not.
1927 // This can be seen when a child transitions from floating to 1935 // This can be seen when a child transitions from floating to
1928 // non-floating we have to take it into account for the first letter. 1936 // non-floating we have to take it into account for the first letter.
1929 updatePseudoElement(PseudoIdFirstLetter, 1937 updatePseudoElement(PseudoIdFirstLetter,
1930 childNeedsStyleRecalc() ? Force : change); 1938 childNeedsStyleRecalc() ? Force : change);
1931 1939
1932 clearChildNeedsStyleRecalc(); 1940 clearChildNeedsStyleRecalc();
1933 clearChildNeedsReattachLayoutTree();
1934 } 1941 }
1935 1942
1936 if (hasCustomStyleCallbacks()) 1943 if (hasCustomStyleCallbacks())
1937 didRecalcStyle(); 1944 didRecalcStyle();
1938 } 1945 }
1939 1946
1940 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1947 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1941 StyleRecalcChange change) { 1948 StyleRecalcChange change) {
1942 if (change != IndependentInherit) 1949 if (change != IndependentInherit)
1943 return nullptr; 1950 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 } else { 1990 } else {
1984 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1991 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1985 } 1992 }
1986 1993
1987 if (localChange == Reattach) { 1994 if (localChange == Reattach) {
1988 StyleReattachData styleReattachData; 1995 StyleReattachData styleReattachData;
1989 styleReattachData.computedStyle = std::move(newStyle); 1996 styleReattachData.computedStyle = std::move(newStyle);
1990 styleReattachData.nextTextSibling = nextTextSibling; 1997 styleReattachData.nextTextSibling = nextTextSibling;
1991 document().addStyleReattachData(*this, styleReattachData); 1998 document().addStyleReattachData(*this, styleReattachData);
1992 setNeedsReattachLayoutTree(); 1999 setNeedsReattachLayoutTree();
1993 return rebuildLayoutTree(); 2000 return Reattach;
1994 } 2001 }
1995 2002
1996 DCHECK(oldStyle); 2003 DCHECK(oldStyle);
1997 2004
1998 if (localChange != NoChange) 2005 if (localChange != NoChange)
1999 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 2006 updateCallbackSelectors(oldStyle.get(), newStyle.get());
2000 2007
2001 if (LayoutObject* layoutObject = this->layoutObject()) { 2008 if (LayoutObject* layoutObject = this->layoutObject()) {
2002 if (localChange != NoChange || 2009 if (localChange != NoChange ||
2003 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 2010 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
2024 return Inherit; 2031 return Inherit;
2025 newStyle->copyChildDependentFlagsFrom(*oldStyle); 2032 newStyle->copyChildDependentFlagsFrom(*oldStyle);
2026 } 2033 }
2027 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 2034 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
2028 return UpdatePseudoElements; 2035 return UpdatePseudoElements;
2029 } 2036 }
2030 2037
2031 return localChange; 2038 return localChange;
2032 } 2039 }
2033 2040
2034 StyleRecalcChange Element::rebuildLayoutTree() { 2041 void Element::rebuildLayoutTree() {
2035 DCHECK(inActiveDocument()); 2042 DCHECK(inActiveDocument());
2043 DCHECK(parentNode());
2044
2036 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2045 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
2037 AttachContext reattachContext; 2046 AttachContext reattachContext;
2038 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2047 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2039 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2048 bool layoutObjectWillChange = needsAttach() || layoutObject();
2040 2049
2041 // We are calling Element::rebuildLayoutTree() from inside 2050 if (needsReattachLayoutTree()) {
2042 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2051 reattachLayoutTree(reattachContext);
2043 // flag - so needsReattachLayoutTree() should always be true. 2052 } else if (childNeedsReattachLayoutTree()) {
2044 DCHECK(parentNode()); 2053 DCHECK(!needsReattachLayoutTree());
2045 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2054 SelectorFilterParentScope filterScope(*this);
2046 DCHECK(needsReattachLayoutTree()); 2055 StyleSharingDepthScope sharingScope(*this);
2047 reattachLayoutTree(reattachContext); 2056 reattachPseudoElementLayoutTree(PseudoIdBefore);
2048 // Since needsReattachLayoutTree() is always true we go into 2057 rebuildShadowRootLayoutTree();
2049 // reattachLayoutTree() which reattaches all the descendant 2058 rebuildChildrenLayoutTrees();
2050 // sub-trees. At this point no child should need reattaching. 2059 reattachPseudoElementLayoutTree(PseudoIdAfter);
2060 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2061 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2062 }
2063 DCHECK(!needsStyleRecalc());
2064 DCHECK(!childNeedsStyleRecalc());
2065 DCHECK(!needsReattachLayoutTree());
2051 DCHECK(!childNeedsReattachLayoutTree()); 2066 DCHECK(!childNeedsReattachLayoutTree());
2052 2067
2053 if (layoutObjectWillChange || layoutObject()) { 2068 if (layoutObjectWillChange || layoutObject()) {
2054 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2069 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2055 // we can either traverse the current subtree from this node onwards 2070 // we can either traverse the current subtree from this node onwards
2056 // or store it. 2071 // or store it.
2057 // The choice is between increased time and increased memory complexity. 2072 // The choice is between increased time and increased memory complexity.
2058 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2073 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2059 return Reattach;
2060 } 2074 }
2061 return ReattachNoLayoutObject; 2075 }
2076
2077 void Element::rebuildShadowRootLayoutTree() {
2078 for (ShadowRoot* root = youngestShadowRoot(); root;
2079 root = root->olderShadowRoot()) {
2080 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2081 root->rebuildLayoutTree();
2082 }
2083 }
2084
2085 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2086 if (PseudoElement* element = pseudoElement(pseudoId)) {
2087 if (element->needsReattachLayoutTree() ||
2088 element->childNeedsReattachLayoutTree())
2089 element->rebuildLayoutTree();
2090 } else {
2091 createPseudoElementIfNeeded(pseudoId);
2092 }
2062 } 2093 }
2063 2094
2064 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2095 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2065 const ComputedStyle* newStyle) { 2096 const ComputedStyle* newStyle) {
2066 Vector<String> emptyVector; 2097 Vector<String> emptyVector;
2067 const Vector<String>& oldCallbackSelectors = 2098 const Vector<String>& oldCallbackSelectors =
2068 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2099 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2069 const Vector<String>& newCallbackSelectors = 2100 const Vector<String>& newCallbackSelectors =
2070 newStyle ? newStyle->callbackSelectors() : emptyVector; 2101 newStyle ? newStyle->callbackSelectors() : emptyVector;
2071 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2102 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 Locale& Element::locale() const { 3232 Locale& Element::locale() const {
3202 return document().getCachedLocale(computeInheritedLanguage()); 3233 return document().getCachedLocale(computeInheritedLanguage());
3203 } 3234 }
3204 3235
3205 void Element::cancelFocusAppearanceUpdate() { 3236 void Element::cancelFocusAppearanceUpdate() {
3206 if (document().focusedElement() == this) 3237 if (document().focusedElement() == this)
3207 document().cancelFocusAppearanceUpdate(); 3238 document().cancelFocusAppearanceUpdate();
3208 } 3239 }
3209 3240
3210 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { 3241 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) {
3211 DCHECK(!needsStyleRecalc());
3212 PseudoElement* element = pseudoElement(pseudoId); 3242 PseudoElement* element = pseudoElement(pseudoId);
3213 3243
3214 if (element && (change == UpdatePseudoElements || 3244 if (element && (change == UpdatePseudoElements ||
3215 element->shouldCallRecalcStyle(change))) { 3245 element->shouldCallRecalcStyle(change))) {
3216 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element)) 3246 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element))
3217 return; 3247 return;
3218 3248
3219 // Need to clear the cached style if the PseudoElement wants a recalc so it 3249 // Need to clear the cached style if the PseudoElement wants a recalc so it
3220 // computes a new style. 3250 // computes a new style.
3221 if (element->needsStyleRecalc()) 3251 if (element->needsStyleRecalc())
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
4141 } 4171 }
4142 4172
4143 DEFINE_TRACE_WRAPPERS(Element) { 4173 DEFINE_TRACE_WRAPPERS(Element) {
4144 if (hasRareData()) { 4174 if (hasRareData()) {
4145 visitor->traceWrappers(elementRareData()); 4175 visitor->traceWrappers(elementRareData());
4146 } 4176 }
4147 ContainerNode::traceWrappers(visitor); 4177 ContainerNode::traceWrappers(visitor);
4148 } 4178 }
4149 4179
4150 } // namespace blink 4180 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698