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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Commit the renames 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Element* Element::create(const QualifiedName& tagName, Document* document) { 176 Element* Element::create(const QualifiedName& tagName, Document* document) {
177 return new Element(tagName, document, CreateElement); 177 return new Element(tagName, document, CreateElement);
178 } 178 }
179 179
180 Element::Element(const QualifiedName& tagName, 180 Element::Element(const QualifiedName& tagName,
181 Document* document, 181 Document* document,
182 ConstructionType type) 182 ConstructionType type)
183 : ContainerNode(document, type), m_tagName(tagName) {} 183 : ContainerNode(document, type), m_tagName(tagName) {}
184 184
185 Element::~Element() { 185 Element::~Element() {
186 DCHECK(needsAttach());
nainar 2016/11/29 06:13:39 See comment in ContainerNode destructor.
187 } 186 }
188 187
189 inline ElementRareData* Element::elementRareData() const { 188 inline ElementRareData* Element::elementRareData() const {
190 DCHECK(hasRareData()); 189 DCHECK(hasRareData());
191 return static_cast<ElementRareData*>(rareData()); 190 return static_cast<ElementRareData*>(rareData());
192 } 191 }
193 192
194 inline ElementRareData& Element::ensureElementRareData() { 193 inline ElementRareData& Element::ensureElementRareData() {
195 return static_cast<ElementRareData&>(ensureRareData()); 194 return static_cast<ElementRareData&>(ensureRareData());
196 } 195 }
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 1654
1656 if (document().frame()) 1655 if (document().frame())
1657 document().frame()->eventHandler().elementRemoved(this); 1656 document().frame()->eventHandler().elementRemoved(this);
1658 } 1657 }
1659 1658
1660 void Element::attachLayoutTree(const AttachContext& context) { 1659 void Element::attachLayoutTree(const AttachContext& context) {
1661 DCHECK(document().inStyleRecalc()); 1660 DCHECK(document().inStyleRecalc());
1662 1661
1663 // We've already been through detach when doing an attach, but we might 1662 // We've already been through detach when doing an attach, but we might
1664 // need to clear any state that's been added since then. 1663 // need to clear any state that's been added since then.
1665 if (hasRareData() && getStyleChangeType() == NeedsReattachStyleChange) { 1664 if (hasRareData() && needsReattachLayoutTree()) {
nainar 2016/11/29 06:13:39 We are setting the corresponging NeedsReattachLayo
1666 ElementRareData* data = elementRareData(); 1665 ElementRareData* data = elementRareData();
1667 data->clearComputedStyle(); 1666 data->clearComputedStyle();
1668 } 1667 }
1669 1668
1670 if (!isActiveSlotOrActiveInsertionPoint()) 1669 if (!isActiveSlotOrActiveInsertionPoint())
1671 LayoutTreeBuilderForElement(*this, context.resolvedStyle) 1670 LayoutTreeBuilderForElement(*this, context.resolvedStyle)
1672 .createLayoutObjectIfNeeded(); 1671 .createLayoutObjectIfNeeded();
1673 1672
1674 addCallbackSelectors(); 1673 addCallbackSelectors();
1675 1674
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 if (inActiveChain()) 1742 if (inActiveChain())
1744 document().activeChainNodeDetached(*this); 1743 document().activeChainNodeDetached(*this);
1745 document().userActionElements().didDetach(*this); 1744 document().userActionElements().didDetach(*this);
1746 } 1745 }
1747 1746
1748 if (context.clearInvalidation) 1747 if (context.clearInvalidation)
1749 document().styleEngine().styleInvalidator().clearInvalidation(*this); 1748 document().styleEngine().styleInvalidator().clearInvalidation(*this);
1750 1749
1751 setNeedsResizeObserverUpdate(); 1750 setNeedsResizeObserverUpdate();
1752 1751
1753 DCHECK(needsAttach()); 1752 DCHECK(needsReattachLayoutTree());
1754 } 1753 }
1755 1754
1756 bool Element::pseudoStyleCacheIsInvalid(const ComputedStyle* currentStyle, 1755 bool Element::pseudoStyleCacheIsInvalid(const ComputedStyle* currentStyle,
1757 ComputedStyle* newStyle) { 1756 ComputedStyle* newStyle) {
1758 DCHECK_EQ(currentStyle, computedStyle()); 1757 DCHECK_EQ(currentStyle, computedStyle());
1759 DCHECK(layoutObject()); 1758 DCHECK(layoutObject());
1760 1759
1761 if (!currentStyle) 1760 if (!currentStyle)
1762 return false; 1761 return false;
1763 1762
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 data->clearComputedStyle(); 1848 data->clearComputedStyle();
1850 1849
1851 if (change >= IndependentInherit) { 1850 if (change >= IndependentInherit) {
1852 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1851 if (ElementAnimations* elementAnimations = data->elementAnimations())
1853 elementAnimations->setAnimationStyleChange(false); 1852 elementAnimations->setAnimationStyleChange(false);
1854 } 1853 }
1855 } 1854 }
1856 if (parentComputedStyle()) 1855 if (parentComputedStyle())
1857 change = recalcOwnStyle(change, nextTextSibling); 1856 change = recalcOwnStyle(change, nextTextSibling);
1858 clearNeedsStyleRecalc(); 1857 clearNeedsStyleRecalc();
1859 clearNeedsReattachLayoutTree();
1860 } 1858 }
1861 1859
1862 // If we reattached we don't need to recalc the style of our descendants 1860 // If we reattached we don't need to recalc the style of our descendants
1863 // anymore. 1861 // anymore.
1864 if ((change >= UpdatePseudoElements && change < Reattach) || 1862 if ((change >= UpdatePseudoElements && change < Reattach) ||
1865 childNeedsStyleRecalc()) { 1863 childNeedsStyleRecalc()) {
1866 SelectorFilterParentScope filterScope(*this); 1864 SelectorFilterParentScope filterScope(*this);
1867 StyleSharingDepthScope sharingScope(*this); 1865 StyleSharingDepthScope sharingScope(*this);
1868 1866
1869 updatePseudoElement(PseudoIdBefore, change); 1867 updatePseudoElement(PseudoIdBefore, change);
1870 1868
1871 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { 1869 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1872 for (ShadowRoot* root = youngestShadowRoot(); root; 1870 for (ShadowRoot* root = youngestShadowRoot(); root;
1873 root = root->olderShadowRoot()) { 1871 root = root->olderShadowRoot()) {
1874 if (root->shouldCallRecalcStyle(change)) 1872 if (root->shouldCallRecalcStyle(change))
1875 root->recalcStyle(change); 1873 root->recalcStyle(change);
1876 } 1874 }
1877 recalcDescendantStyles(change); 1875 recalcDescendantStyles(change);
1878 } 1876 }
1879 1877
1880 updatePseudoElement(PseudoIdAfter, change); 1878 updatePseudoElement(PseudoIdAfter, change);
1881 updatePseudoElement(PseudoIdBackdrop, change); 1879 updatePseudoElement(PseudoIdBackdrop, change);
1882 1880
1883 // If our children have changed then we need to force the first-letter 1881 // If our children have changed then we need to force the first-letter
1884 // checks as we don't know if they effected the first letter or not. 1882 // checks as we don't know if they effected the first letter or not.
1885 // This can be seen when a child transitions from floating to 1883 // This can be seen when a child transitions from floating to
1886 // non-floating we have to take it into account for the first letter. 1884 // non-floating we have to take it into account for the first letter.
1887 updatePseudoElement(PseudoIdFirstLetter, 1885 updatePseudoElement(PseudoIdFirstLetter,
1888 childNeedsStyleRecalc() ? Force : change); 1886 childNeedsStyleRecalc() ? Force : change);
1889
1890 clearChildNeedsStyleRecalc();
1891 clearChildNeedsReattachLayoutTree();
1892 } 1887 }
1893 1888
1894 if (hasCustomStyleCallbacks()) 1889 if (hasCustomStyleCallbacks())
1895 didRecalcStyle(change); 1890 didRecalcStyle(change);
1896 } 1891 }
1897 1892
1898 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1893 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1899 StyleRecalcChange change) { 1894 StyleRecalcChange change) {
1900 if (change != IndependentInherit) 1895 if (change != IndependentInherit)
1901 return nullptr; 1896 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 } else { 1936 } else {
1942 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1937 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1943 } 1938 }
1944 1939
1945 if (localChange == Reattach) { 1940 if (localChange == Reattach) {
1946 StyleReattachData styleReattachData; 1941 StyleReattachData styleReattachData;
1947 styleReattachData.computedStyle = std::move(newStyle); 1942 styleReattachData.computedStyle = std::move(newStyle);
1948 styleReattachData.nextTextSibling = nextTextSibling; 1943 styleReattachData.nextTextSibling = nextTextSibling;
1949 document().addStyleReattachData(*this, styleReattachData); 1944 document().addStyleReattachData(*this, styleReattachData);
1950 setNeedsReattachLayoutTree(); 1945 setNeedsReattachLayoutTree();
1951 return rebuildLayoutTree(); 1946 return Reattach;
1952 } 1947 }
1953 1948
1954 DCHECK(oldStyle); 1949 DCHECK(oldStyle);
1955 1950
1956 if (localChange != NoChange) 1951 if (localChange != NoChange)
1957 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 1952 updateCallbackSelectors(oldStyle.get(), newStyle.get());
1958 1953
1959 if (LayoutObject* layoutObject = this->layoutObject()) { 1954 if (LayoutObject* layoutObject = this->layoutObject()) {
1960 if (localChange != NoChange || 1955 if (localChange != NoChange ||
1961 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 1956 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
1982 return Inherit; 1977 return Inherit;
1983 newStyle->copyChildDependentFlagsFrom(*oldStyle); 1978 newStyle->copyChildDependentFlagsFrom(*oldStyle);
1984 } 1979 }
1985 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 1980 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
1986 return UpdatePseudoElements; 1981 return UpdatePseudoElements;
1987 } 1982 }
1988 1983
1989 return localChange; 1984 return localChange;
1990 } 1985 }
1991 1986
1992 StyleRecalcChange Element::rebuildLayoutTree() { 1987 void Element::rebuildLayoutTree() {
1993 DCHECK(inActiveDocument()); 1988 DCHECK(inActiveDocument());
1989 DCHECK(!needsStyleRecalc());
1990 DCHECK(!childNeedsStyleRecalc());
1991 DCHECK(parentNode());
1992 DCHECK(parentNode()->childNeedsReattachLayoutTree());
1993
1994 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 1994 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
1995 AttachContext reattachContext; 1995 AttachContext reattachContext;
1996 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 1996 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
1997 bool layoutObjectWillChange = needsAttach() || layoutObject(); 1997 bool layoutObjectWillChange = needsReattachLayoutTree() || layoutObject();
1998 1998
1999 // We are calling Element::rebuildLayoutTree() from inside 1999 if (needsReattachLayoutTree()) {
2000 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2000 reattachLayoutTree(reattachContext);
2001 // flag - so needsReattachLayoutTree() should always be true. 2001 } else if (childNeedsReattachLayoutTree()) {
2002 DCHECK(parentNode()); 2002 SelectorFilterParentScope filterScope(*this);
2003 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2003 StyleSharingDepthScope sharingScope(*this);
2004 DCHECK(needsReattachLayoutTree()); 2004 reattachPseudoElementLayoutTree(PseudoIdBefore);
2005 reattachLayoutTree(reattachContext); 2005 rebuildShadowRootLayoutTree();
2006 // Since needsReattachLayoutTree() is always true we go into 2006 rebuildDescendantLayoutTree();
2007 // reattachLayoutTree() which reattaches all the descendant 2007 reattachPseudoElementLayoutTree(PseudoIdAfter);
2008 // sub-trees. At this point no child should need reattaching. 2008 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2009 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2010 }
2011 DCHECK(!needsReattachLayoutTree());
2009 DCHECK(!childNeedsReattachLayoutTree()); 2012 DCHECK(!childNeedsReattachLayoutTree());
2010 2013
2011 if (layoutObjectWillChange || layoutObject()) { 2014 if (layoutObjectWillChange || layoutObject()) {
2012 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2015 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2013 // we can either traverse the current subtree from this node onwards 2016 // we can either traverse the current subtree from this node onwards
2014 // or store it. 2017 // or store it.
2015 // The choice is between increased time and increased memory complexity. 2018 // The choice is between increased time and increased memory complexity.
2016 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2019 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2017 return Reattach;
2018 } 2020 }
2019 return ReattachNoLayoutObject; 2021 }
2022
2023 void Element::rebuildShadowRootLayoutTree() {
2024 DCHECK(!needsStyleRecalc());
2025 DCHECK(!childNeedsStyleRecalc());
2026 DCHECK(!needsReattachLayoutTree());
2027 for (ShadowRoot* root = youngestShadowRoot(); root;
2028 root = root->olderShadowRoot()) {
2029 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2030 root->rebuildLayoutTree();
2031 }
2032 }
2033
2034 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2035 DCHECK(!needsStyleRecalc());
2036 DCHECK(!childNeedsStyleRecalc());
2037 DCHECK(!needsReattachLayoutTree());
2038 if (PseudoElement* element = pseudoElement(pseudoId)) {
2039 if (element->needsReattachLayoutTree() ||
2040 element->childNeedsReattachLayoutTree())
2041 element->rebuildLayoutTree();
2042 }
2020 } 2043 }
2021 2044
2022 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2045 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2023 const ComputedStyle* newStyle) { 2046 const ComputedStyle* newStyle) {
2024 Vector<String> emptyVector; 2047 Vector<String> emptyVector;
2025 const Vector<String>& oldCallbackSelectors = 2048 const Vector<String>& oldCallbackSelectors =
2026 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2049 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2027 const Vector<String>& newCallbackSelectors = 2050 const Vector<String>& newCallbackSelectors =
2028 newStyle ? newStyle->callbackSelectors() : emptyVector; 2051 newStyle ? newStyle->callbackSelectors() : emptyVector;
2029 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2052 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 // avoid it here. 3259 // avoid it here.
3237 PseudoElement* element = 3260 PseudoElement* element =
3238 document().styleEngine().ensureResolver().createPseudoElementIfNeeded( 3261 document().styleEngine().ensureResolver().createPseudoElementIfNeeded(
3239 *this, pseudoId); 3262 *this, pseudoId);
3240 if (!element) 3263 if (!element)
3241 return; 3264 return;
3242 3265
3243 if (pseudoId == PseudoIdBackdrop) 3266 if (pseudoId == PseudoIdBackdrop)
3244 document().addToTopLayer(element, this); 3267 document().addToTopLayer(element, this);
3245 element->insertedInto(this); 3268 element->insertedInto(this);
3269 element->setLocalNeedsReattachLayoutTree();
nainar 2016/11/29 06:13:39 Only the Pseudo Element needs to be reattached.
3246 element->attachLayoutTree(); 3270 element->attachLayoutTree();
3247 3271 DCHECK(!element->needsReattachLayoutTree());
3248 InspectorInstrumentation::pseudoElementCreated(element); 3272 InspectorInstrumentation::pseudoElementCreated(element);
3249 3273
3250 ensureElementRareData().setPseudoElement(pseudoId, element); 3274 ensureElementRareData().setPseudoElement(pseudoId, element);
3251 } 3275 }
3252 3276
3253 PseudoElement* Element::pseudoElement(PseudoId pseudoId) const { 3277 PseudoElement* Element::pseudoElement(PseudoId pseudoId) const {
3254 return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : nullptr; 3278 return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : nullptr;
3255 } 3279 }
3256 3280
3257 LayoutObject* Element::pseudoElementLayoutObject(PseudoId pseudoId) const { 3281 LayoutObject* Element::pseudoElementLayoutObject(PseudoId pseudoId) const {
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
4089 } 4113 }
4090 4114
4091 DEFINE_TRACE_WRAPPERS(Element) { 4115 DEFINE_TRACE_WRAPPERS(Element) {
4092 if (hasRareData()) { 4116 if (hasRareData()) {
4093 visitor->traceWrappers(elementRareData()); 4117 visitor->traceWrappers(elementRareData());
4094 } 4118 }
4095 ContainerNode::traceWrappers(visitor); 4119 ContainerNode::traceWrappers(visitor);
4096 } 4120 }
4097 4121
4098 } // namespace blink 4122 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698