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 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1877 } | 1877 } |
1878 | 1878 |
1879 PassRefPtr<ComputedStyle> Element::originalStyleForLayoutObject() { | 1879 PassRefPtr<ComputedStyle> Element::originalStyleForLayoutObject() { |
1880 DCHECK(document().inStyleRecalc()); | 1880 DCHECK(document().inStyleRecalc()); |
1881 return document().ensureStyleResolver().styleForElement(this); | 1881 return document().ensureStyleResolver().styleForElement(this); |
1882 } | 1882 } |
1883 | 1883 |
1884 void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { | 1884 void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
1885 DCHECK(document().inStyleRecalc()); | 1885 DCHECK(document().inStyleRecalc()); |
1886 DCHECK(!document().lifecycle().inDetach()); | 1886 DCHECK(!document().lifecycle().inDetach()); |
1887 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | |
1888 DCHECK(inActiveDocument()); | 1887 DCHECK(inActiveDocument()); |
1889 | 1888 |
1890 if (hasCustomStyleCallbacks()) | 1889 if (hasCustomStyleCallbacks()) |
1891 willRecalcStyle(change); | 1890 willRecalcStyle(change); |
1892 | 1891 |
1893 if (change >= IndependentInherit || needsStyleRecalc()) { | 1892 if (change >= IndependentInherit || needsStyleRecalc()) { |
1894 if (hasRareData()) { | 1893 if (hasRareData()) { |
1895 ElementRareData* data = elementRareData(); | 1894 ElementRareData* data = elementRareData(); |
1896 if (change != IndependentInherit) | 1895 if (change != IndependentInherit) |
1897 data->clearComputedStyle(); | 1896 data->clearComputedStyle(); |
1898 | 1897 |
1899 if (change >= IndependentInherit) { | 1898 if (change >= IndependentInherit) { |
1900 if (ElementAnimations* elementAnimations = data->elementAnimations()) | 1899 if (ElementAnimations* elementAnimations = data->elementAnimations()) |
1901 elementAnimations->setAnimationStyleChange(false); | 1900 elementAnimations->setAnimationStyleChange(false); |
1902 } | 1901 } |
1903 } | 1902 } |
1904 if (parentComputedStyle()) | 1903 if (parentComputedStyle()) { |
1905 change = recalcOwnStyle(change, nextTextSibling); | 1904 change = recalcOwnStyle(change, nextTextSibling); |
1906 clearNeedsStyleRecalc(); | 1905 } else { |
1907 clearNeedsReattachLayoutTree(); | 1906 // In case we don't perform recalcOwnStyle we will never clear the |
1907 // NeedsReattachLayoutTree flag which is set on the creation of each | |
1908 // Node. Clear that here. | |
1909 clearNeedsReattachLayoutTree(); | |
1910 } | |
1908 } | 1911 } |
1909 | 1912 |
1910 // If we reattached we don't need to recalc the style of our descendants | 1913 // If we are going to reattach we don't need to recalc the style of |
1911 // anymore. | 1914 // our descendants anymore. |
1912 if ((change >= UpdatePseudoElements && change < Reattach) || | 1915 if (change < Reattach && |
1913 childNeedsStyleRecalc()) { | 1916 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) { |
1914 SelectorFilterParentScope filterScope(*this); | 1917 SelectorFilterParentScope filterScope(*this); |
1915 StyleSharingDepthScope sharingScope(*this); | 1918 StyleSharingDepthScope sharingScope(*this); |
1916 | 1919 |
1917 updatePseudoElement(PseudoIdBefore, change); | 1920 updatePseudoElement(PseudoIdBefore, change); |
1918 | 1921 |
1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { | 1922 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { |
1920 for (ShadowRoot* root = youngestShadowRoot(); root; | 1923 for (ShadowRoot* root = youngestShadowRoot(); root; |
1921 root = root->olderShadowRoot()) { | 1924 root = root->olderShadowRoot()) { |
1922 if (root->shouldCallRecalcStyle(change)) | 1925 if (root->shouldCallRecalcStyle(change)) |
1923 root->recalcStyle(change); | 1926 root->recalcStyle(change); |
1924 } | 1927 } |
1925 recalcDescendantStyles(change); | 1928 recalcDescendantStyles(change); |
1926 } | 1929 } |
1927 | 1930 |
1928 updatePseudoElement(PseudoIdAfter, change); | 1931 updatePseudoElement(PseudoIdAfter, change); |
1929 updatePseudoElement(PseudoIdBackdrop, change); | 1932 updatePseudoElement(PseudoIdBackdrop, change); |
1930 | 1933 |
1931 // If our children have changed then we need to force the first-letter | 1934 // If our children have changed then we need to force the first-letter |
1932 // checks as we don't know if they effected the first letter or not. | 1935 // checks as we don't know if they effected the first letter or not. |
1933 // This can be seen when a child transitions from floating to | 1936 // This can be seen when a child transitions from floating to |
1934 // non-floating we have to take it into account for the first letter. | 1937 // non-floating we have to take it into account for the first letter. |
1935 updatePseudoElement(PseudoIdFirstLetter, | 1938 updatePseudoElement(PseudoIdFirstLetter, |
1936 childNeedsStyleRecalc() ? Force : change); | 1939 childNeedsStyleRecalc() ? Force : change); |
1937 | 1940 |
1938 clearChildNeedsStyleRecalc(); | 1941 clearChildNeedsStyleRecalc(); |
1939 clearChildNeedsReattachLayoutTree(); | |
1940 } | 1942 } |
1941 | 1943 |
1944 if (!(needsReattachLayoutTree() || childNeedsReattachLayoutTree())) | |
esprehn
2017/02/13 22:19:41
Run demorgans here
nainar
2017/02/14 03:42:09
Done.
| |
1945 clearNeedsStyleRecalc(); | |
1946 | |
1942 if (hasCustomStyleCallbacks()) | 1947 if (hasCustomStyleCallbacks()) |
1943 didRecalcStyle(); | 1948 didRecalcStyle(); |
1944 } | 1949 } |
1945 | 1950 |
1946 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( | 1951 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( |
1947 StyleRecalcChange change) { | 1952 StyleRecalcChange change) { |
1948 if (change != IndependentInherit) | 1953 if (change != IndependentInherit) |
1949 return nullptr; | 1954 return nullptr; |
1950 if (isPseudoElement()) | 1955 if (isPseudoElement()) |
1951 return nullptr; | 1956 return nullptr; |
1952 if (needsStyleRecalc()) | 1957 if (needsStyleRecalc()) |
1953 return nullptr; | 1958 return nullptr; |
1954 if (hasAnimations()) | 1959 if (hasAnimations()) |
1955 return nullptr; | 1960 return nullptr; |
1956 const ComputedStyle* parentStyle = parentComputedStyle(); | 1961 const ComputedStyle* parentStyle = parentComputedStyle(); |
1957 DCHECK(parentStyle); | 1962 DCHECK(parentStyle); |
1958 const ComputedStyle* style = computedStyle(); | 1963 const ComputedStyle* style = computedStyle(); |
1959 if (!style || style->animations() || style->transitions()) | 1964 if (!style || style->animations() || style->transitions()) |
1960 return nullptr; | 1965 return nullptr; |
1961 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style); | 1966 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style); |
1962 newStyle->propagateIndependentInheritedProperties(*parentStyle); | 1967 newStyle->propagateIndependentInheritedProperties(*parentStyle); |
1963 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1968 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
1964 independentInheritedStylesPropagated, 1); | 1969 independentInheritedStylesPropagated, 1); |
1965 return newStyle; | 1970 return newStyle; |
1966 } | 1971 } |
1967 | 1972 |
1968 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, | 1973 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
1969 Text* nextTextSibling) { | 1974 Text* nextTextSibling) { |
1970 DCHECK(document().inStyleRecalc()); | 1975 DCHECK(document().inStyleRecalc()); |
1971 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | |
1972 DCHECK(change >= IndependentInherit || needsStyleRecalc()); | 1976 DCHECK(change >= IndependentInherit || needsStyleRecalc()); |
1973 DCHECK(parentComputedStyle()); | 1977 DCHECK(parentComputedStyle()); |
1974 | 1978 |
1975 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); | 1979 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); |
1976 | 1980 |
1977 // When propagating inherited changes, we don't need to do a full style recalc | 1981 // When propagating inherited changes, we don't need to do a full style recalc |
1978 // if the only changed properties are independent. In this case, we can simply | 1982 // if the only changed properties are independent. In this case, we can simply |
1979 // set these directly on the ComputedStyle object. | 1983 // set these directly on the ComputedStyle object. |
1980 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); | 1984 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); |
1981 if (!newStyle) | 1985 if (!newStyle) |
1982 newStyle = styleForLayoutObject(); | 1986 newStyle = styleForLayoutObject(); |
1983 DCHECK(newStyle); | 1987 DCHECK(newStyle); |
1984 | 1988 |
1985 StyleRecalcChange localChange = | 1989 StyleRecalcChange localChange = |
1986 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); | 1990 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); |
1987 if (localChange == NoChange) { | 1991 if (localChange == NoChange) { |
1988 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); | 1992 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); |
1989 } else { | 1993 } else { |
1990 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); | 1994 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); |
1991 } | 1995 } |
1992 | 1996 |
1993 if (localChange == Reattach) { | 1997 if (localChange == Reattach) { |
1994 StyleReattachData styleReattachData; | 1998 StyleReattachData styleReattachData; |
1995 styleReattachData.computedStyle = std::move(newStyle); | 1999 styleReattachData.computedStyle = std::move(newStyle); |
1996 styleReattachData.nextTextSibling = nextTextSibling; | 2000 styleReattachData.nextTextSibling = nextTextSibling; |
1997 document().addStyleReattachData(*this, styleReattachData); | 2001 document().addStyleReattachData(*this, styleReattachData); |
1998 setNeedsReattachLayoutTree(); | 2002 setNeedsReattachLayoutTree(); |
1999 return rebuildLayoutTree(); | 2003 return Reattach; |
2000 } | 2004 } |
2001 | 2005 |
2002 DCHECK(oldStyle); | 2006 DCHECK(oldStyle); |
2003 | 2007 |
2004 if (localChange != NoChange) | 2008 if (localChange != NoChange) |
2005 updateCallbackSelectors(oldStyle.get(), newStyle.get()); | 2009 updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
2006 | 2010 |
2007 if (LayoutObject* layoutObject = this->layoutObject()) { | 2011 if (LayoutObject* layoutObject = this->layoutObject()) { |
2008 if (localChange != NoChange || | 2012 if (localChange != NoChange || |
2009 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { | 2013 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { |
(...skipping 20 matching lines...) Expand all Loading... | |
2030 return Inherit; | 2034 return Inherit; |
2031 newStyle->copyChildDependentFlagsFrom(*oldStyle); | 2035 newStyle->copyChildDependentFlagsFrom(*oldStyle); |
2032 } | 2036 } |
2033 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) | 2037 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) |
2034 return UpdatePseudoElements; | 2038 return UpdatePseudoElements; |
2035 } | 2039 } |
2036 | 2040 |
2037 return localChange; | 2041 return localChange; |
2038 } | 2042 } |
2039 | 2043 |
2040 StyleRecalcChange Element::rebuildLayoutTree() { | 2044 void Element::rebuildLayoutTree() { |
2041 DCHECK(inActiveDocument()); | 2045 DCHECK(inActiveDocument()); |
2046 DCHECK(parentNode()); | |
2047 | |
2042 StyleReattachData styleReattachData = document().getStyleReattachData(*this); | 2048 StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
2043 AttachContext reattachContext; | 2049 AttachContext reattachContext; |
2044 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); | 2050 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
2045 bool layoutObjectWillChange = needsAttach() || layoutObject(); | 2051 bool layoutObjectWillChange = needsAttach() || layoutObject(); |
2046 | 2052 |
2047 // We are calling Element::rebuildLayoutTree() from inside | 2053 if (needsReattachLayoutTree()) { |
2048 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree | 2054 reattachLayoutTree(reattachContext); |
2049 // flag - so needsReattachLayoutTree() should always be true. | 2055 } else if (childNeedsReattachLayoutTree()) { |
2050 DCHECK(parentNode()); | 2056 DCHECK(!needsReattachLayoutTree()); |
esprehn
2017/02/13 22:19:41
Can we add these DCHECKs back?
nainar
2017/02/14 03:42:09
They are back. They moved above.
| |
2051 DCHECK(parentNode()->childNeedsReattachLayoutTree()); | 2057 SelectorFilterParentScope filterScope(*this); |
2052 DCHECK(needsReattachLayoutTree()); | 2058 StyleSharingDepthScope sharingScope(*this); |
2053 reattachLayoutTree(reattachContext); | 2059 reattachPseudoElementLayoutTree(PseudoIdBefore); |
2054 // Since needsReattachLayoutTree() is always true we go into | 2060 rebuildShadowRootLayoutTree(); |
2055 // reattachLayoutTree() which reattaches all the descendant | 2061 rebuildChildrenLayoutTrees(); |
2056 // sub-trees. At this point no child should need reattaching. | 2062 reattachPseudoElementLayoutTree(PseudoIdAfter); |
2063 reattachPseudoElementLayoutTree(PseudoIdBackdrop); | |
2064 reattachPseudoElementLayoutTree(PseudoIdFirstLetter); | |
2065 } | |
2066 DCHECK(!needsStyleRecalc()); | |
2067 DCHECK(!childNeedsStyleRecalc()); | |
2068 DCHECK(!needsReattachLayoutTree()); | |
2057 DCHECK(!childNeedsReattachLayoutTree()); | 2069 DCHECK(!childNeedsReattachLayoutTree()); |
2058 | 2070 |
2059 if (layoutObjectWillChange || layoutObject()) { | 2071 if (layoutObjectWillChange || layoutObject()) { |
2060 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles | 2072 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
2061 // we can either traverse the current subtree from this node onwards | 2073 // we can either traverse the current subtree from this node onwards |
2062 // or store it. | 2074 // or store it. |
2063 // The choice is between increased time and increased memory complexity. | 2075 // The choice is between increased time and increased memory complexity. |
2064 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); | 2076 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
2065 return Reattach; | 2077 } else { |
2078 clearNeedsStyleRecalc(); | |
2066 } | 2079 } |
2067 return ReattachNoLayoutObject; | 2080 } |
2081 | |
2082 void Element::rebuildShadowRootLayoutTree() { | |
2083 for (ShadowRoot* root = youngestShadowRoot(); root; | |
2084 root = root->olderShadowRoot()) { | |
2085 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree()) | |
2086 root->rebuildLayoutTree(); | |
2087 } | |
2088 } | |
2089 | |
2090 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) { | |
2091 if (PseudoElement* element = pseudoElement(pseudoId)) { | |
2092 if (element->needsReattachLayoutTree() || | |
2093 element->childNeedsReattachLayoutTree()) | |
2094 element->rebuildLayoutTree(); | |
2095 } else { | |
2096 createPseudoElementIfNeeded(pseudoId); | |
2097 } | |
2068 } | 2098 } |
2069 | 2099 |
2070 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, | 2100 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |
2071 const ComputedStyle* newStyle) { | 2101 const ComputedStyle* newStyle) { |
2072 Vector<String> emptyVector; | 2102 Vector<String> emptyVector; |
2073 const Vector<String>& oldCallbackSelectors = | 2103 const Vector<String>& oldCallbackSelectors = |
2074 oldStyle ? oldStyle->callbackSelectors() : emptyVector; | 2104 oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
2075 const Vector<String>& newCallbackSelectors = | 2105 const Vector<String>& newCallbackSelectors = |
2076 newStyle ? newStyle->callbackSelectors() : emptyVector; | 2106 newStyle ? newStyle->callbackSelectors() : emptyVector; |
2077 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) | 2107 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3207 Locale& Element::locale() const { | 3237 Locale& Element::locale() const { |
3208 return document().getCachedLocale(computeInheritedLanguage()); | 3238 return document().getCachedLocale(computeInheritedLanguage()); |
3209 } | 3239 } |
3210 | 3240 |
3211 void Element::cancelFocusAppearanceUpdate() { | 3241 void Element::cancelFocusAppearanceUpdate() { |
3212 if (document().focusedElement() == this) | 3242 if (document().focusedElement() == this) |
3213 document().cancelFocusAppearanceUpdate(); | 3243 document().cancelFocusAppearanceUpdate(); |
3214 } | 3244 } |
3215 | 3245 |
3216 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { | 3246 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { |
3217 DCHECK(!needsStyleRecalc()); | |
3218 PseudoElement* element = pseudoElement(pseudoId); | 3247 PseudoElement* element = pseudoElement(pseudoId); |
3219 | 3248 |
3220 if (element && (change == UpdatePseudoElements || | 3249 if (element && (change == UpdatePseudoElements || |
3221 element->shouldCallRecalcStyle(change))) { | 3250 element->shouldCallRecalcStyle(change))) { |
3222 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element)) | 3251 if (pseudoId == PseudoIdFirstLetter && updateFirstLetter(element)) |
3223 return; | 3252 return; |
3224 | 3253 |
3225 // Need to clear the cached style if the PseudoElement wants a recalc so it | 3254 // Need to clear the cached style if the PseudoElement wants a recalc so it |
3226 // computes a new style. | 3255 // computes a new style. |
3227 if (element->needsStyleRecalc()) | 3256 if (element->needsStyleRecalc()) |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4134 } | 4163 } |
4135 | 4164 |
4136 DEFINE_TRACE_WRAPPERS(Element) { | 4165 DEFINE_TRACE_WRAPPERS(Element) { |
4137 if (hasRareData()) { | 4166 if (hasRareData()) { |
4138 visitor->traceWrappers(elementRareData()); | 4167 visitor->traceWrappers(elementRareData()); |
4139 } | 4168 } |
4140 ContainerNode::traceWrappers(visitor); | 4169 ContainerNode::traceWrappers(visitor); |
4141 } | 4170 } |
4142 | 4171 |
4143 } // namespace blink | 4172 } // namespace blink |
OLD | NEW |