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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Split up didRecalcStyle into didRecalcStyle and didRebuildLayoutTree 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 } else {
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 }
1900 clearNeedsStyleRecalc(); 1906 clearNeedsStyleRecalc();
1901 clearNeedsReattachLayoutTree();
1902 } 1907 }
1903 1908
1904 // If we reattached we don't need to recalc the style of our descendants 1909 // If we are going to reattach we don't need to recalc the style of
1905 // anymore. 1910 // our descendants anymore.
1906 if ((change >= UpdatePseudoElements && change < Reattach) || 1911 if (change < Reattach &&
1907 childNeedsStyleRecalc()) { 1912 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) {
1908 SelectorFilterParentScope filterScope(*this); 1913 SelectorFilterParentScope filterScope(*this);
1909 StyleSharingDepthScope sharingScope(*this); 1914 StyleSharingDepthScope sharingScope(*this);
1910 1915
1911 updatePseudoElement(PseudoIdBefore, change); 1916 updatePseudoElement(PseudoIdBefore, change);
1912 1917
1913 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { 1918 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1914 for (ShadowRoot* root = youngestShadowRoot(); root; 1919 for (ShadowRoot* root = youngestShadowRoot(); root;
1915 root = root->olderShadowRoot()) { 1920 root = root->olderShadowRoot()) {
1916 if (root->shouldCallRecalcStyle(change)) 1921 if (root->shouldCallRecalcStyle(change)) {
1917 root->recalcStyle(change); 1922 root->recalcStyle(change);
1923 } else {
1924 // In case we don't perform recalcStyle we will never clear the
1925 // NeedsReattachLayoutTree flag which is set on the creation of each
1926 // Node. Clear that here.
1927 root->clearNeedsReattachLayoutTree();
1928 }
1918 } 1929 }
1919 recalcDescendantStyles(change); 1930 recalcDescendantStyles(change);
1920 } 1931 }
1921 1932
1922 updatePseudoElement(PseudoIdAfter, change); 1933 updatePseudoElement(PseudoIdAfter, change);
1923 updatePseudoElement(PseudoIdBackdrop, change); 1934 updatePseudoElement(PseudoIdBackdrop, change);
1924 1935
1925 // If our children have changed then we need to force the first-letter 1936 // 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. 1937 // 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 1938 // 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. 1939 // non-floating we have to take it into account for the first letter.
1929 updatePseudoElement(PseudoIdFirstLetter, 1940 updatePseudoElement(PseudoIdFirstLetter,
1930 childNeedsStyleRecalc() ? Force : change); 1941 childNeedsStyleRecalc() ? Force : change);
1931 1942
1932 clearChildNeedsStyleRecalc(); 1943 clearChildNeedsStyleRecalc();
1933 clearChildNeedsReattachLayoutTree();
1934 } 1944 }
1935 1945
1936 if (hasCustomStyleCallbacks()) 1946 if (hasCustomStyleCallbacks())
1937 didRecalcStyle(); 1947 didRecalcStyle();
1938 } 1948 }
1939 1949
1940 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( 1950 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(
1941 StyleRecalcChange change) { 1951 StyleRecalcChange change) {
1942 if (change != IndependentInherit) 1952 if (change != IndependentInherit)
1943 return nullptr; 1953 return nullptr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 } else { 1993 } else {
1984 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 1994 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
1985 } 1995 }
1986 1996
1987 if (localChange == Reattach) { 1997 if (localChange == Reattach) {
1988 StyleReattachData styleReattachData; 1998 StyleReattachData styleReattachData;
1989 styleReattachData.computedStyle = std::move(newStyle); 1999 styleReattachData.computedStyle = std::move(newStyle);
1990 styleReattachData.nextTextSibling = nextTextSibling; 2000 styleReattachData.nextTextSibling = nextTextSibling;
1991 document().addStyleReattachData(*this, styleReattachData); 2001 document().addStyleReattachData(*this, styleReattachData);
1992 setNeedsReattachLayoutTree(); 2002 setNeedsReattachLayoutTree();
1993 return rebuildLayoutTree(); 2003 return Reattach;
1994 } 2004 }
1995 2005
1996 DCHECK(oldStyle); 2006 DCHECK(oldStyle);
1997 2007
1998 if (localChange != NoChange) 2008 if (localChange != NoChange)
1999 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 2009 updateCallbackSelectors(oldStyle.get(), newStyle.get());
2000 2010
2001 if (LayoutObject* layoutObject = this->layoutObject()) { 2011 if (LayoutObject* layoutObject = this->layoutObject()) {
2002 if (localChange != NoChange || 2012 if (localChange != NoChange ||
2003 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 2013 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
(...skipping 20 matching lines...) Expand all
2024 return Inherit; 2034 return Inherit;
2025 newStyle->copyChildDependentFlagsFrom(*oldStyle); 2035 newStyle->copyChildDependentFlagsFrom(*oldStyle);
2026 } 2036 }
2027 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 2037 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
2028 return UpdatePseudoElements; 2038 return UpdatePseudoElements;
2029 } 2039 }
2030 2040
2031 return localChange; 2041 return localChange;
2032 } 2042 }
2033 2043
2034 StyleRecalcChange Element::rebuildLayoutTree() { 2044 void Element::rebuildLayoutTree() {
2035 DCHECK(inActiveDocument()); 2045 DCHECK(inActiveDocument());
2046 DCHECK(!needsStyleRecalc());
2047 DCHECK(parentNode());
2048
2036 StyleReattachData styleReattachData = document().getStyleReattachData(*this); 2049 StyleReattachData styleReattachData = document().getStyleReattachData(*this);
2037 AttachContext reattachContext; 2050 AttachContext reattachContext;
2038 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2051 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2039 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2052 bool layoutObjectWillChange = needsAttach() || layoutObject();
2040 2053
2041 // We are calling Element::rebuildLayoutTree() from inside 2054 if (needsReattachLayoutTree()) {
2042 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree 2055 reattachLayoutTree(reattachContext);
2043 // flag - so needsReattachLayoutTree() should always be true. 2056 } else if (childNeedsReattachLayoutTree()) {
2044 DCHECK(parentNode()); 2057 DCHECK(!needsReattachLayoutTree());
2045 DCHECK(parentNode()->childNeedsReattachLayoutTree()); 2058 SelectorFilterParentScope filterScope(*this);
2046 DCHECK(needsReattachLayoutTree()); 2059 StyleSharingDepthScope sharingScope(*this);
2047 reattachLayoutTree(reattachContext); 2060 reattachPseudoElementLayoutTree(PseudoIdBefore);
2048 // Since needsReattachLayoutTree() is always true we go into 2061 rebuildShadowRootLayoutTree();
2049 // reattachLayoutTree() which reattaches all the descendant 2062 rebuildChildrenLayoutTrees();
2050 // sub-trees. At this point no child should need reattaching. 2063 reattachPseudoElementLayoutTree(PseudoIdAfter);
2064 reattachPseudoElementLayoutTree(PseudoIdBackdrop);
2065 reattachPseudoElementLayoutTree(PseudoIdFirstLetter);
2066 }
2067 DCHECK(!needsReattachLayoutTree());
2051 DCHECK(!childNeedsReattachLayoutTree()); 2068 DCHECK(!childNeedsReattachLayoutTree());
2052 2069
2070 if (hasCustomStyleCallbacks())
2071 didRebuildLayoutTree();
2072
2053 if (layoutObjectWillChange || layoutObject()) { 2073 if (layoutObjectWillChange || layoutObject()) {
2054 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2074 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2055 // we can either traverse the current subtree from this node onwards 2075 // we can either traverse the current subtree from this node onwards
2056 // or store it. 2076 // or store it.
2057 // The choice is between increased time and increased memory complexity. 2077 // The choice is between increased time and increased memory complexity.
2058 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2078 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2059 return Reattach;
2060 } 2079 }
2061 return ReattachNoLayoutObject; 2080 }
2081
2082 void Element::rebuildShadowRootLayoutTree() {
2083 DCHECK(!needsStyleRecalc());
2084 DCHECK(!childNeedsStyleRecalc());
2085 DCHECK(!needsReattachLayoutTree());
2086 for (ShadowRoot* root = youngestShadowRoot(); root;
2087 root = root->olderShadowRoot()) {
2088 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree())
2089 root->rebuildLayoutTree();
2090 }
2091 }
2092
2093 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) {
2094 DCHECK(!needsStyleRecalc());
2095 DCHECK(!childNeedsStyleRecalc());
2096 DCHECK(!needsReattachLayoutTree());
2097 if (PseudoElement* element = pseudoElement(pseudoId)) {
2098 if (element->needsReattachLayoutTree() ||
2099 element->childNeedsReattachLayoutTree())
2100 element->rebuildLayoutTree();
2101 } else {
2102 createPseudoElementIfNeeded(pseudoId);
2103 }
2062 } 2104 }
2063 2105
2064 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, 2106 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle,
2065 const ComputedStyle* newStyle) { 2107 const ComputedStyle* newStyle) {
2066 Vector<String> emptyVector; 2108 Vector<String> emptyVector;
2067 const Vector<String>& oldCallbackSelectors = 2109 const Vector<String>& oldCallbackSelectors =
2068 oldStyle ? oldStyle->callbackSelectors() : emptyVector; 2110 oldStyle ? oldStyle->callbackSelectors() : emptyVector;
2069 const Vector<String>& newCallbackSelectors = 2111 const Vector<String>& newCallbackSelectors =
2070 newStyle ? newStyle->callbackSelectors() : emptyVector; 2112 newStyle ? newStyle->callbackSelectors() : emptyVector;
2071 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) 2113 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty())
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 } 3767 }
3726 3768
3727 void Element::willRecalcStyle(StyleRecalcChange) { 3769 void Element::willRecalcStyle(StyleRecalcChange) {
3728 DCHECK(hasCustomStyleCallbacks()); 3770 DCHECK(hasCustomStyleCallbacks());
3729 } 3771 }
3730 3772
3731 void Element::didRecalcStyle() { 3773 void Element::didRecalcStyle() {
3732 DCHECK(hasCustomStyleCallbacks()); 3774 DCHECK(hasCustomStyleCallbacks());
3733 } 3775 }
3734 3776
3777 void Element::didRebuildLayoutTree() {
3778 DCHECK(hasCustomStyleCallbacks());
3779 }
3780
3735 PassRefPtr<ComputedStyle> Element::customStyleForLayoutObject() { 3781 PassRefPtr<ComputedStyle> Element::customStyleForLayoutObject() {
3736 DCHECK(hasCustomStyleCallbacks()); 3782 DCHECK(hasCustomStyleCallbacks());
3737 return nullptr; 3783 return nullptr;
3738 } 3784 }
3739 3785
3740 void Element::cloneAttributesFromElement(const Element& other) { 3786 void Element::cloneAttributesFromElement(const Element& other) {
3741 if (hasRareData()) 3787 if (hasRareData())
3742 detachAllAttrNodesFromElement(); 3788 detachAllAttrNodesFromElement();
3743 3789
3744 other.synchronizeAllAttributes(); 3790 other.synchronizeAllAttributes();
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 } 4174 }
4129 4175
4130 DEFINE_TRACE_WRAPPERS(Element) { 4176 DEFINE_TRACE_WRAPPERS(Element) {
4131 if (hasRareData()) { 4177 if (hasRareData()) {
4132 visitor->traceWrappers(elementRareData()); 4178 visitor->traceWrappers(elementRareData());
4133 } 4179 }
4134 ContainerNode::traceWrappers(visitor); 4180 ContainerNode::traceWrappers(visitor);
4135 } 4181 }
4136 4182
4137 } // namespace blink 4183 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698