OLD | NEW |
---|---|
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 Loading... | |
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); |
1926 } else { | |
1927 // In case we don't perform recalcStyle we will never clear the | |
1928 // NeedsReattachLayoutTree flag which is set on the creation of each | |
1929 // Node. Clear that here. | |
1930 root->clearNeedsReattachLayoutTree(); | |
esprehn
2017/02/02 08:37:09
I wonder how this can happen, how do we get here w
nainar
2017/02/02 23:13:06
Yup this is redundant code and never executed. Rem
| |
1931 } | |
1918 } | 1932 } |
1919 recalcDescendantStyles(change); | 1933 recalcDescendantStyles(change); |
1920 } | 1934 } |
1921 | 1935 |
1922 updatePseudoElement(PseudoIdAfter, change); | 1936 updatePseudoElement(PseudoIdAfter, change); |
1923 updatePseudoElement(PseudoIdBackdrop, change); | 1937 updatePseudoElement(PseudoIdBackdrop, change); |
1924 | 1938 |
1925 // If our children have changed then we need to force the first-letter | 1939 // 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. | 1940 // 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 | 1941 // 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. | 1942 // non-floating we have to take it into account for the first letter. |
1929 updatePseudoElement(PseudoIdFirstLetter, | 1943 updatePseudoElement(PseudoIdFirstLetter, |
1930 childNeedsStyleRecalc() ? Force : change); | 1944 childNeedsStyleRecalc() ? Force : change); |
1931 | 1945 |
1932 clearChildNeedsStyleRecalc(); | 1946 clearChildNeedsStyleRecalc(); |
1933 clearChildNeedsReattachLayoutTree(); | |
1934 } | 1947 } |
1935 | 1948 |
1936 if (hasCustomStyleCallbacks()) | 1949 if (hasCustomStyleCallbacks()) |
1937 didRecalcStyle(); | 1950 didRecalcStyle(); |
1938 } | 1951 } |
1939 | 1952 |
1940 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( | 1953 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( |
1941 StyleRecalcChange change) { | 1954 StyleRecalcChange change) { |
1942 if (change != IndependentInherit) | 1955 if (change != IndependentInherit) |
1943 return nullptr; | 1956 return nullptr; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1983 } else { | 1996 } else { |
1984 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); | 1997 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); |
1985 } | 1998 } |
1986 | 1999 |
1987 if (localChange == Reattach) { | 2000 if (localChange == Reattach) { |
1988 StyleReattachData styleReattachData; | 2001 StyleReattachData styleReattachData; |
1989 styleReattachData.computedStyle = std::move(newStyle); | 2002 styleReattachData.computedStyle = std::move(newStyle); |
1990 styleReattachData.nextTextSibling = nextTextSibling; | 2003 styleReattachData.nextTextSibling = nextTextSibling; |
1991 document().addStyleReattachData(*this, styleReattachData); | 2004 document().addStyleReattachData(*this, styleReattachData); |
1992 setNeedsReattachLayoutTree(); | 2005 setNeedsReattachLayoutTree(); |
1993 return rebuildLayoutTree(); | 2006 return Reattach; |
1994 } | 2007 } |
1995 | 2008 |
1996 DCHECK(oldStyle); | 2009 DCHECK(oldStyle); |
1997 | 2010 |
1998 if (localChange != NoChange) | 2011 if (localChange != NoChange) |
1999 updateCallbackSelectors(oldStyle.get(), newStyle.get()); | 2012 updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
2000 | 2013 |
2001 if (LayoutObject* layoutObject = this->layoutObject()) { | 2014 if (LayoutObject* layoutObject = this->layoutObject()) { |
2002 if (localChange != NoChange || | 2015 if (localChange != NoChange || |
2003 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { | 2016 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { |
(...skipping 20 matching lines...) Expand all Loading... | |
2024 return Inherit; | 2037 return Inherit; |
2025 newStyle->copyChildDependentFlagsFrom(*oldStyle); | 2038 newStyle->copyChildDependentFlagsFrom(*oldStyle); |
2026 } | 2039 } |
2027 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) | 2040 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) |
2028 return UpdatePseudoElements; | 2041 return UpdatePseudoElements; |
2029 } | 2042 } |
2030 | 2043 |
2031 return localChange; | 2044 return localChange; |
2032 } | 2045 } |
2033 | 2046 |
2034 StyleRecalcChange Element::rebuildLayoutTree() { | 2047 void Element::rebuildLayoutTree() { |
2035 DCHECK(inActiveDocument()); | 2048 DCHECK(inActiveDocument()); |
2049 DCHECK(parentNode()); | |
2050 | |
2036 StyleReattachData styleReattachData = document().getStyleReattachData(*this); | 2051 StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
2037 AttachContext reattachContext; | 2052 AttachContext reattachContext; |
2038 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); | 2053 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
2039 bool layoutObjectWillChange = needsAttach() || layoutObject(); | 2054 bool layoutObjectWillChange = needsAttach() || layoutObject(); |
2040 | 2055 |
2041 // We are calling Element::rebuildLayoutTree() from inside | 2056 if (needsReattachLayoutTree()) { |
2042 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree | 2057 reattachLayoutTree(reattachContext); |
2043 // flag - so needsReattachLayoutTree() should always be true. | 2058 } else if (childNeedsReattachLayoutTree()) { |
2044 DCHECK(parentNode()); | 2059 DCHECK(!needsReattachLayoutTree()); |
2045 DCHECK(parentNode()->childNeedsReattachLayoutTree()); | 2060 SelectorFilterParentScope filterScope(*this); |
2046 DCHECK(needsReattachLayoutTree()); | 2061 StyleSharingDepthScope sharingScope(*this); |
2047 reattachLayoutTree(reattachContext); | 2062 reattachPseudoElementLayoutTree(PseudoIdBefore); |
2048 // Since needsReattachLayoutTree() is always true we go into | 2063 rebuildShadowRootLayoutTree(); |
2049 // reattachLayoutTree() which reattaches all the descendant | 2064 rebuildChildrenLayoutTrees(); |
2050 // sub-trees. At this point no child should need reattaching. | 2065 reattachPseudoElementLayoutTree(PseudoIdAfter); |
2066 reattachPseudoElementLayoutTree(PseudoIdBackdrop); | |
2067 reattachPseudoElementLayoutTree(PseudoIdFirstLetter); | |
2068 } | |
2069 DCHECK(!needsStyleRecalc()); | |
2070 DCHECK(!childNeedsStyleRecalc()); | |
2071 DCHECK(!needsReattachLayoutTree()); | |
2051 DCHECK(!childNeedsReattachLayoutTree()); | 2072 DCHECK(!childNeedsReattachLayoutTree()); |
2052 | 2073 |
2053 if (layoutObjectWillChange || layoutObject()) { | 2074 if (layoutObjectWillChange || layoutObject()) { |
2054 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles | 2075 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
2055 // we can either traverse the current subtree from this node onwards | 2076 // we can either traverse the current subtree from this node onwards |
2056 // or store it. | 2077 // or store it. |
2057 // The choice is between increased time and increased memory complexity. | 2078 // The choice is between increased time and increased memory complexity. |
2058 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); | 2079 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
2059 return Reattach; | |
2060 } | 2080 } |
2061 return ReattachNoLayoutObject; | 2081 } |
2082 | |
2083 void Element::rebuildShadowRootLayoutTree() { | |
2084 for (ShadowRoot* root = youngestShadowRoot(); root; | |
2085 root = root->olderShadowRoot()) { | |
2086 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree()) | |
2087 root->rebuildLayoutTree(); | |
2088 } | |
2089 } | |
2090 | |
2091 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) { | |
2092 if (PseudoElement* element = pseudoElement(pseudoId)) { | |
2093 if (element->needsReattachLayoutTree() || | |
2094 element->childNeedsReattachLayoutTree()) | |
2095 element->rebuildLayoutTree(); | |
2096 } else { | |
2097 createPseudoElementIfNeeded(pseudoId); | |
2098 } | |
2062 } | 2099 } |
2063 | 2100 |
2064 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, | 2101 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |
2065 const ComputedStyle* newStyle) { | 2102 const ComputedStyle* newStyle) { |
2066 Vector<String> emptyVector; | 2103 Vector<String> emptyVector; |
2067 const Vector<String>& oldCallbackSelectors = | 2104 const Vector<String>& oldCallbackSelectors = |
2068 oldStyle ? oldStyle->callbackSelectors() : emptyVector; | 2105 oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
2069 const Vector<String>& newCallbackSelectors = | 2106 const Vector<String>& newCallbackSelectors = |
2070 newStyle ? newStyle->callbackSelectors() : emptyVector; | 2107 newStyle ? newStyle->callbackSelectors() : emptyVector; |
2071 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) | 2108 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3201 Locale& Element::locale() const { | 3238 Locale& Element::locale() const { |
3202 return document().getCachedLocale(computeInheritedLanguage()); | 3239 return document().getCachedLocale(computeInheritedLanguage()); |
3203 } | 3240 } |
3204 | 3241 |
3205 void Element::cancelFocusAppearanceUpdate() { | 3242 void Element::cancelFocusAppearanceUpdate() { |
3206 if (document().focusedElement() == this) | 3243 if (document().focusedElement() == this) |
3207 document().cancelFocusAppearanceUpdate(); | 3244 document().cancelFocusAppearanceUpdate(); |
3208 } | 3245 } |
3209 | 3246 |
3210 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { | 3247 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { |
3211 DCHECK(!needsStyleRecalc()); | |
3212 PseudoElement* element = pseudoElement(pseudoId); | 3248 PseudoElement* element = pseudoElement(pseudoId); |
3213 | 3249 |
3214 if (element && (change == UpdatePseudoElements || | 3250 if (element && (change == UpdatePseudoElements || |
3215 element->shouldCallRecalcStyle(change))) { | 3251 element->shouldCallRecalcStyle(change))) { |
3216 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element)) | 3252 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element)) |
3217 return; | 3253 return; |
3218 | 3254 |
3219 // Need to clear the cached style if the PseudoElement wants a recalc so it | 3255 // Need to clear the cached style if the PseudoElement wants a recalc so it |
3220 // computes a new style. | 3256 // computes a new style. |
3221 if (element->needsStyleRecalc()) | 3257 if (element->needsStyleRecalc()) |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4141 } | 4177 } |
4142 | 4178 |
4143 DEFINE_TRACE_WRAPPERS(Element) { | 4179 DEFINE_TRACE_WRAPPERS(Element) { |
4144 if (hasRareData()) { | 4180 if (hasRareData()) { |
4145 visitor->traceWrappers(elementRareData()); | 4181 visitor->traceWrappers(elementRareData()); |
4146 } | 4182 } |
4147 ContainerNode::traceWrappers(visitor); | 4183 ContainerNode::traceWrappers(visitor); |
4148 } | 4184 } |
4149 | 4185 |
4150 } // namespace blink | 4186 } // namespace blink |
OLD | NEW |