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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: FirstLetterPseudoElements are not being created 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 clearNeedsReattachLayoutTree();
nainar 2016/12/07 14:48:21 In case we don't perform recalcOwnStyle we will ne
Bugs Nash 2016/12/07 23:21:44 good explanation, would be useful in a code commen
nainar 2016/12/07 23:49:10 Done locally.
1862 }
1860 clearNeedsStyleRecalc(); 1863 clearNeedsStyleRecalc();
1861 clearNeedsReattachLayoutTree();
1862 } 1864 }
1863 1865
1864 // If we reattached we don't need to recalc the style of our descendants 1866 // If we reattached we don't need to recalc the style of our descendants
1865 // anymore. 1867 // anymore.
1866 if ((change >= UpdatePseudoElements && change < Reattach) || 1868 if ((change >= UpdatePseudoElements && change < Reattach) ||
1867 childNeedsStyleRecalc()) { 1869 childNeedsStyleRecalc()) {
1868 SelectorFilterParentScope filterScope(*this); 1870 SelectorFilterParentScope filterScope(*this);
1869 StyleSharingDepthScope sharingScope(*this); 1871 StyleSharingDepthScope sharingScope(*this);
1870 1872
1871 updatePseudoElement(PseudoIdBefore, change); 1873 updatePseudoElement(PseudoIdBefore, change);
(...skipping 11 matching lines...) Expand all
1883 updatePseudoElement(PseudoIdBackdrop, change); 1885 updatePseudoElement(PseudoIdBackdrop, change);
1884 1886
1885 // If our children have changed then we need to force the first-letter 1887 // 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. 1888 // 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 1889 // 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. 1890 // non-floating we have to take it into account for the first letter.
1889 updatePseudoElement(PseudoIdFirstLetter, 1891 updatePseudoElement(PseudoIdFirstLetter,
1890 childNeedsStyleRecalc() ? Force : change); 1892 childNeedsStyleRecalc() ? Force : change);
1891 1893
1892 clearChildNeedsStyleRecalc(); 1894 clearChildNeedsStyleRecalc();
1893 clearChildNeedsReattachLayoutTree();
1894 } 1895 }
1895 1896
1896 if (hasCustomStyleCallbacks()) 1897 if (hasCustomStyleCallbacks())
1897 didRecalcStyle(change); 1898 didRecalcStyle(change);
1898 } 1899 }
1899 1900
1900 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1901 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1901 StyleRecalcChange change) { 1902 StyleRecalcChange change) {
1902 if (change != IndependentInherit) 1903 if (change != IndependentInherit)
1903 return nullptr; 1904 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 } else { 1944 } else {
1944 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1945 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1945 } 1946 }
1946 1947
1947 if (localChange == Reattach) { 1948 if (localChange == Reattach) {
1948 StyleReattachData styleReattachData; 1949 StyleReattachData styleReattachData;
1949 styleReattachData.computedStyle = std::move(newStyle); 1950 styleReattachData.computedStyle = std::move(newStyle);
1950 styleReattachData.nextTextSibling = nextTextSibling; 1951 styleReattachData.nextTextSibling = nextTextSibling;
1951 document().addStyleReattachData(*this, styleReattachData); 1952 document().addStyleReattachData(*this, styleReattachData);
1952 setNeedsReattachLayoutTree(); 1953 setNeedsReattachLayoutTree();
1953 return rebuildLayoutTree(); 1954 return Reattach;
1954 } 1955 }
1955 1956
1956 DCHECK(oldStyle); 1957 DCHECK(oldStyle);
1957 1958
1958 if (localChange != NoChange) 1959 if (localChange != NoChange)
1959 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 1960 updateCallbackSelectors(oldStyle.get(), newStyle.get());
1960 1961
1961 if (LayoutObject* layoutObject = this->layoutObject()) { 1962 if (LayoutObject* layoutObject = this->layoutObject()) {
1962 if (localChange != NoChange || 1963 if (localChange != NoChange ||
1963 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 1964 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
1984 return Inherit; 1985 return Inherit;
1985 newStyle->copyChildDependentFlagsFrom(*oldStyle); 1986 newStyle->copyChildDependentFlagsFrom(*oldStyle);
1986 } 1987 }
1987 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 1988 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
1988 return UpdatePseudoElements; 1989 return UpdatePseudoElements;
1989 } 1990 }
1990 1991
1991 return localChange; 1992 return localChange;
1992 } 1993 }
1993 1994
1994 StyleRecalcChange Element::rebuildLayoutTree() { 1995 void Element::rebuildLayoutTree() {
1995 DCHECK(inActiveDocument()); 1996 DCHECK(inActiveDocument());
1997 DCHECK(!needsStyleRecalc());
1998 DCHECK(!childNeedsStyleRecalc());
1999 DCHECK(parentNode());
2000
1996 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2001 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
1997 AttachContext reattachContext; 2002 AttachContext reattachContext;
1998 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2003 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
1999 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2004 bool layoutObjectWillChange = needsAttach() || layoutObject();
2000 2005
2001 // We are calling Element::rebuildLayoutTree() from inside 2006 if (needsReattachLayoutTree()) {
2002 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2007 reattachLayoutTree(reattachContext);
2003 // flag - so needsReattachLayoutTree() should always be true. 2008 } else if (childNeedsReattachLayoutTree()) {
2004 DCHECK(parentNode()); 2009 SelectorFilterParentScope filterScope(*this);
2005 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2010 StyleSharingDepthScope sharingScope(*this);
2006 DCHECK(needsReattachLayoutTree()); 2011 reattachPseudoElementLayoutTree(PseudoIdBefore);
2007 reattachLayoutTree(reattachContext); 2012 rebuildShadowRootLayoutTree();
2008 // Since needsReattachLayoutTree() is always true we go into 2013 rebuildDescendantLayoutTrees();
2009 // reattachLayoutTree() which reattaches all the descendant 2014 reattachPseudoElementLayoutTree(PseudoIdAfter);
2010 // sub-trees. At this point no child should need reattaching. 2015 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2016 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2017 }
2018 DCHECK(!needsReattachLayoutTree());
2011 DCHECK(!childNeedsReattachLayoutTree()); 2019 DCHECK(!childNeedsReattachLayoutTree());
2012 2020
2013 if (layoutObjectWillChange || layoutObject()) { 2021 if (layoutObjectWillChange || layoutObject()) {
2014 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2022 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2015 // we can either traverse the current subtree from this node onwards 2023 // we can either traverse the current subtree from this node onwards
2016 // or store it. 2024 // or store it.
2017 // The choice is between increased time and increased memory complexity. 2025 // The choice is between increased time and increased memory complexity.
2018 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2026 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2019 return Reattach;
2020 } 2027 }
2021 return ReattachNoLayoutObject; 2028 }
2029
2030 void Element::rebuildShadowRootLayoutTree() {
2031 DCHECK(!needsStyleRecalc());
2032 DCHECK(!childNeedsStyleRecalc());
2033 DCHECK(!needsReattachLayoutTree());
2034 for (ShadowRoot* root = youngestShadowRoot(); root;
2035 root = root->olderShadowRoot()) {
2036 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2037 root->rebuildLayoutTree();
2038 }
2039 }
2040
2041 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2042 DCHECK(!needsStyleRecalc());
2043 DCHECK(!childNeedsStyleRecalc());
2044 DCHECK(!needsReattachLayoutTree());
2045 if (PseudoElement* element = pseudoElement(pseudoId)) {
2046 if (element->needsReattachLayoutTree() ||
2047 element->childNeedsReattachLayoutTree())
2048 element->rebuildLayoutTree();
2049 }
2022 } 2050 }
2023 2051
2024 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2052 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2025 const ComputedStyle* newStyle) { 2053 const ComputedStyle* newStyle) {
2026 Vector<String> emptyVector; 2054 Vector<String> emptyVector;
2027 const Vector<String>& oldCallbackSelectors = 2055 const Vector<String>& oldCallbackSelectors =
2028 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2056 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2029 const Vector<String>& newCallbackSelectors = 2057 const Vector<String>& newCallbackSelectors =
2030 newStyle ? newStyle->callbackSelectors() : emptyVector; 2058 newStyle ? newStyle->callbackSelectors() : emptyVector;
2031 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2059 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 PseudoElement* element = 3267 PseudoElement* element =
3240 document().styleEngine().ensureResolver().createPseudoElementIfNeeded( 3268 document().styleEngine().ensureResolver().createPseudoElementIfNeeded(
3241 *this, pseudoId); 3269 *this, pseudoId);
3242 if (!element) 3270 if (!element)
3243 return; 3271 return;
3244 3272
3245 if (pseudoId == PseudoIdBackdrop) 3273 if (pseudoId == PseudoIdBackdrop)
3246 document().addToTopLayer(element, this); 3274 document().addToTopLayer(element, this);
3247 element->insertedInto(this); 3275 element->insertedInto(this);
3248 element->attachLayoutTree(); 3276 element->attachLayoutTree();
3249
Bugs Nash 2016/12/07 23:21:44 was this intentional?
nainar 2016/12/07 23:49:10 Nope - haven't sanitized the code for erroneous fo
3250 InspectorInstrumentation::pseudoElementCreated(element); 3277 InspectorInstrumentation::pseudoElementCreated(element);
3251 3278
3252 ensureElementRareData().setPseudoElement(pseudoId, element); 3279 ensureElementRareData().setPseudoElement(pseudoId, element);
3253 } 3280 }
3254 3281
3255 PseudoElement* Element::pseudoElement(PseudoId pseudoId) const { 3282 PseudoElement* Element::pseudoElement(PseudoId pseudoId) const {
3256 return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : nullptr; 3283 return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : nullptr;
3257 } 3284 }
3258 3285
3259 LayoutObject* Element::pseudoElementLayoutObject(PseudoId pseudoId) const { 3286 LayoutObject* Element::pseudoElementLayoutObject(PseudoId pseudoId) const {
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
4091 } 4118 }
4092 4119
4093 DEFINE_TRACE_WRAPPERS(Element) { 4120 DEFINE_TRACE_WRAPPERS(Element) {
4094 if (hasRareData()) { 4121 if (hasRareData()) {
4095 visitor->traceWrappers(elementRareData()); 4122 visitor->traceWrappers(elementRareData());
4096 } 4123 }
4097 ContainerNode::traceWrappers(visitor); 4124 ContainerNode::traceWrappers(visitor);
4098 } 4125 }
4099 4126
4100 } // namespace blink 4127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698