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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Make needsAttach() only check if getStyleChangeType flag is NeedsReattachStyleChange and add a Layo… Created 3 years, 9 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 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 } 1923 }
1924 } 1924 }
1925 1925
1926 if (change >= IndependentInherit) { 1926 if (change >= IndependentInherit) {
1927 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1927 if (ElementAnimations* elementAnimations = data->elementAnimations())
1928 elementAnimations->setAnimationStyleChange(false); 1928 elementAnimations->setAnimationStyleChange(false);
1929 } 1929 }
1930 } 1930 }
1931 if (parentComputedStyle()) 1931 if (parentComputedStyle())
1932 change = recalcOwnStyle(change, nextTextSibling); 1932 change = recalcOwnStyle(change, nextTextSibling);
1933 clearNeedsStyleRecalc(); 1933 // Needed because the rebuildLayoutTree code needs to see what the
1934 clearNeedsReattachLayoutTree(); 1934 // styleChangeType() was on reattach roots. See Node::reattachLayoutTree()
1935 // for an example.
1936 if (change != Reattach)
1937 clearNeedsStyleRecalc();
1935 } 1938 }
1936 1939
1937 // If we reattached we don't need to recalc the style of our descendants 1940 // If we are going to reattach we don't need to recalc the style of
1938 // anymore. 1941 // our descendants anymore.
1939 if ((change >= UpdatePseudoElements && change < Reattach) || 1942 if (change < Reattach &&
1940 childNeedsStyleRecalc()) { 1943 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) {
1941 SelectorFilterParentScope filterScope(*this); 1944 SelectorFilterParentScope filterScope(*this);
1942 StyleSharingDepthScope sharingScope(*this); 1945 StyleSharingDepthScope sharingScope(*this);
1943 1946
1944 updatePseudoElement(PseudoIdBefore, change); 1947 updatePseudoElement(PseudoIdBefore, change);
1945 1948
1946 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { 1949 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1947 for (ShadowRoot* root = youngestShadowRoot(); root; 1950 for (ShadowRoot* root = youngestShadowRoot(); root;
1948 root = root->olderShadowRoot()) { 1951 root = root->olderShadowRoot()) {
1949 if (root->shouldCallRecalcStyle(change)) 1952 if (root->shouldCallRecalcStyle(change))
1950 root->recalcStyle(change); 1953 root->recalcStyle(change);
1951 } 1954 }
1952 recalcDescendantStyles(change); 1955 recalcDescendantStyles(change);
1953 } 1956 }
1954 1957
1955 updatePseudoElement(PseudoIdAfter, change); 1958 updatePseudoElement(PseudoIdAfter, change);
1956 updatePseudoElement(PseudoIdBackdrop, change); 1959 updatePseudoElement(PseudoIdBackdrop, change);
1957 1960
1958 // If our children have changed then we need to force the first-letter 1961 // If our children have changed then we need to force the first-letter
1959 // checks as we don't know if they effected the first letter or not. 1962 // checks as we don't know if they effected the first letter or not.
1960 // This can be seen when a child transitions from floating to 1963 // This can be seen when a child transitions from floating to
1961 // non-floating we have to take it into account for the first letter. 1964 // non-floating we have to take it into account for the first letter.
1962 updatePseudoElement(PseudoIdFirstLetter, 1965 updatePseudoElement(PseudoIdFirstLetter,
1963 childNeedsStyleRecalc() ? Force : change); 1966 childNeedsStyleRecalc() ? Force : change);
1964 1967
1965 clearChildNeedsStyleRecalc(); 1968 clearChildNeedsStyleRecalc();
1966 clearChildNeedsReattachLayoutTree();
1967 } 1969 }
1968 1970
1969 if (hasCustomStyleCallbacks()) 1971 if (hasCustomStyleCallbacks())
1970 didRecalcStyle(); 1972 didRecalcStyle();
1971 } 1973 }
1972 1974
1973 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1975 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1974 StyleRecalcChange change) { 1976 StyleRecalcChange change) {
1975 if (change != IndependentInherit) 1977 if (change != IndependentInherit)
1976 return nullptr; 1978 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 } else { 2018 } else {
2017 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 2019 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
2018 } 2020 }
2019 2021
2020 if (localChange == Reattach) { 2022 if (localChange == Reattach) {
2021 StyleReattachData styleReattachData; 2023 StyleReattachData styleReattachData;
2022 styleReattachData.computedStyle = std::move(newStyle); 2024 styleReattachData.computedStyle = std::move(newStyle);
2023 styleReattachData.nextTextSibling = nextTextSibling; 2025 styleReattachData.nextTextSibling = nextTextSibling;
2024 document().addStyleReattachData(*this, styleReattachData); 2026 document().addStyleReattachData(*this, styleReattachData);
2025 setNeedsReattachLayoutTree(); 2027 setNeedsReattachLayoutTree();
2026 return rebuildLayoutTree(); 2028 return Reattach;
2027 } 2029 }
2028 2030
2029 DCHECK(oldStyle); 2031 DCHECK(oldStyle);
2030 2032
2031 if (localChange != NoChange) 2033 if (localChange != NoChange)
2032 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 2034 updateCallbackSelectors(oldStyle.get(), newStyle.get());
2033 2035
2034 if (LayoutObject* layoutObject = this->layoutObject()) { 2036 if (LayoutObject* layoutObject = this->layoutObject()) {
2035 if (localChange != NoChange || 2037 if (localChange != NoChange ||
2036 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 2038 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 23 matching lines...) Expand all
2060 return Inherit; 2062 return Inherit;
2061 newStyle->copyChildDependentFlagsFrom(*oldStyle); 2063 newStyle->copyChildDependentFlagsFrom(*oldStyle);
2062 } 2064 }
2063 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 2065 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
2064 return UpdatePseudoElements; 2066 return UpdatePseudoElements;
2065 } 2067 }
2066 2068
2067 return localChange; 2069 return localChange;
2068 } 2070 }
2069 2071
2070 StyleRecalcChange Element::rebuildLayoutTree() { 2072 void Element::rebuildLayoutTree() {
2071 DCHECK(inActiveDocument()); 2073 DCHECK(inActiveDocument());
2072 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2074 DCHECK(parentNode());
2073 AttachContext reattachContext;
2074 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2075 bool layoutObjectWillChange = needsAttach() || layoutObject();
2076 2075
2077 // We are calling Element::rebuildLayoutTree() from inside 2076 if (needsReattachLayoutTree()) {
2078 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2077 StyleReattachData styleReattachData =
2079 // flag - so needsReattachLayoutTree() should always be true. 2078 document().getStyleReattachData(*this);
2080 DCHECK(parentNode()); 2079 AttachContext reattachContext;
2081 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2080 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2082 DCHECK(needsReattachLayoutTree()); 2081 bool layoutObjectWillChange = needsAttach() || layoutObject();
2083 reattachLayoutTree(reattachContext); 2082 reattachLayoutTree(reattachContext);
2084 // Since needsReattachLayoutTree() is always true we go into 2083 if (layoutObjectWillChange || layoutObject()) {
2085 // reattachLayoutTree() which reattaches all the descendant 2084 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2086 // sub-trees. At this point no child should need reattaching. 2085 // we can either traverse the current subtree from this node onwards
2086 // or store it.
2087 // The choice is between increased time and increased memory complexity.
2088 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2089 }
2090 } else if (childNeedsReattachLayoutTree()) {
2091 DCHECK(!needsReattachLayoutTree());
2092 SelectorFilterParentScope filterScope(*this);
2093 StyleSharingDepthScope sharingScope(*this);
2094 reattachPseudoElementLayoutTree(PseudoIdBefore);
2095 rebuildShadowRootLayoutTree();
2096 rebuildChildrenLayoutTrees();
2097 reattachPseudoElementLayoutTree(PseudoIdAfter);
2098 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2099 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2100 }
2101 DCHECK(!needsStyleRecalc());
2102 DCHECK(!childNeedsStyleRecalc());
2103 DCHECK(!needsReattachLayoutTree());
2087 DCHECK(!childNeedsReattachLayoutTree()); 2104 DCHECK(!childNeedsReattachLayoutTree());
2105 }
2088 2106
2089 if (layoutObjectWillChange || layoutObject()) { 2107 void Element::rebuildShadowRootLayoutTree() {
2090 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2108 for (ShadowRoot* root = youngestShadowRoot(); root;
2091 // we can either traverse the current subtree from this node onwards 2109 root = root->olderShadowRoot()) {
2092 // or store it. 2110 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2093 // The choice is between increased time and increased memory complexity. 2111 root->rebuildLayoutTree();
2094 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2095 return Reattach;
2096 } 2112 }
2097 return ReattachNoLayoutObject; 2113 }
2114
2115 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2116 if (PseudoElement* element = pseudoElement(pseudoId)) {
2117 if (element->needsReattachLayoutTree() ||
2118 element->childNeedsReattachLayoutTree())
2119 element->rebuildLayoutTree();
2120 } else {
2121 createPseudoElementIfNeeded(pseudoId);
2122 }
2098 } 2123 }
2099 2124
2100 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2125 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2101 const ComputedStyle* newStyle) { 2126 const ComputedStyle* newStyle) {
2102 Vector<String> emptyVector; 2127 Vector<String> emptyVector;
2103 const Vector<String>& oldCallbackSelectors = 2128 const Vector<String>& oldCallbackSelectors =
2104 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2129 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2105 const Vector<String>& newCallbackSelectors = 2130 const Vector<String>& newCallbackSelectors =
2106 newStyle ? newStyle->callbackSelectors() : emptyVector; 2131 newStyle ? newStyle->callbackSelectors() : emptyVector;
2107 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2132 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 } 4226 }
4202 4227
4203 DEFINE_TRACE_WRAPPERS(Element) { 4228 DEFINE_TRACE_WRAPPERS(Element) {
4204 if (hasRareData()) { 4229 if (hasRareData()) {
4205 visitor->traceWrappers(elementRareData()); 4230 visitor->traceWrappers(elementRareData());
4206 } 4231 }
4207 ContainerNode::traceWrappers(visitor); 4232 ContainerNode::traceWrappers(visitor);
4208 } 4233 }
4209 4234
4210 } // namespace blink 4235 } // 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