| 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 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 if (change != IndependentInherit) | 1896 if (change != IndependentInherit) |
| 1897 data->clearComputedStyle(); | 1897 data->clearComputedStyle(); |
| 1898 | 1898 |
| 1899 if (change >= IndependentInherit) { | 1899 if (change >= IndependentInherit) { |
| 1900 if (ElementAnimations* elementAnimations = data->elementAnimations()) | 1900 if (ElementAnimations* elementAnimations = data->elementAnimations()) |
| 1901 elementAnimations->setAnimationStyleChange(false); | 1901 elementAnimations->setAnimationStyleChange(false); |
| 1902 } | 1902 } |
| 1903 } | 1903 } |
| 1904 if (parentComputedStyle()) | 1904 if (parentComputedStyle()) |
| 1905 change = recalcOwnStyle(change, nextTextSibling); | 1905 change = recalcOwnStyle(change, nextTextSibling); |
| 1906 clearNeedsStyleRecalc(); | 1906 if (change != Reattach) |
| 1907 clearNeedsReattachLayoutTree(); | 1907 clearNeedsStyleRecalc(); |
| 1908 } | 1908 } |
| 1909 | 1909 |
| 1910 // If we reattached we don't need to recalc the style of our descendants | 1910 // If we are going to reattach we don't need to recalc the style of |
| 1911 // anymore. | 1911 // our descendants anymore. |
| 1912 if ((change >= UpdatePseudoElements && change < Reattach) || | 1912 if (change < Reattach && |
| 1913 childNeedsStyleRecalc()) { | 1913 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) { |
| 1914 SelectorFilterParentScope filterScope(*this); | 1914 SelectorFilterParentScope filterScope(*this); |
| 1915 StyleSharingDepthScope sharingScope(*this); | 1915 StyleSharingDepthScope sharingScope(*this); |
| 1916 | 1916 |
| 1917 updatePseudoElement(PseudoIdBefore, change); | 1917 updatePseudoElement(PseudoIdBefore, change); |
| 1918 | 1918 |
| 1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { | 1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { |
| 1920 for (ShadowRoot* root = youngestShadowRoot(); root; | 1920 for (ShadowRoot* root = youngestShadowRoot(); root; |
| 1921 root = root->olderShadowRoot()) { | 1921 root = root->olderShadowRoot()) { |
| 1922 if (root->shouldCallRecalcStyle(change)) | 1922 if (root->shouldCallRecalcStyle(change)) |
| 1923 root->recalcStyle(change); | 1923 root->recalcStyle(change); |
| 1924 } | 1924 } |
| 1925 recalcDescendantStyles(change); | 1925 recalcDescendantStyles(change); |
| 1926 } | 1926 } |
| 1927 | 1927 |
| 1928 updatePseudoElement(PseudoIdAfter, change); | 1928 updatePseudoElement(PseudoIdAfter, change); |
| 1929 updatePseudoElement(PseudoIdBackdrop, change); | 1929 updatePseudoElement(PseudoIdBackdrop, change); |
| 1930 | 1930 |
| 1931 // If our children have changed then we need to force the first-letter | 1931 // 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. | 1932 // 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 | 1933 // 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. | 1934 // non-floating we have to take it into account for the first letter. |
| 1935 updatePseudoElement(PseudoIdFirstLetter, | 1935 updatePseudoElement(PseudoIdFirstLetter, |
| 1936 childNeedsStyleRecalc() ? Force : change); | 1936 childNeedsStyleRecalc() ? Force : change); |
| 1937 | 1937 |
| 1938 clearChildNeedsStyleRecalc(); | 1938 clearChildNeedsStyleRecalc(); |
| 1939 clearChildNeedsReattachLayoutTree(); | |
| 1940 } | 1939 } |
| 1941 | 1940 |
| 1942 if (hasCustomStyleCallbacks()) | 1941 if (hasCustomStyleCallbacks()) |
| 1943 didRecalcStyle(); | 1942 didRecalcStyle(); |
| 1944 } | 1943 } |
| 1945 | 1944 |
| 1946 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( | 1945 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( |
| 1947 StyleRecalcChange change) { | 1946 StyleRecalcChange change) { |
| 1948 if (change != IndependentInherit) | 1947 if (change != IndependentInherit) |
| 1949 return nullptr; | 1948 return nullptr; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1965 return newStyle; | 1964 return newStyle; |
| 1966 } | 1965 } |
| 1967 | 1966 |
| 1968 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, | 1967 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| 1969 Text* nextTextSibling) { | 1968 Text* nextTextSibling) { |
| 1970 DCHECK(document().inStyleRecalc()); | 1969 DCHECK(document().inStyleRecalc()); |
| 1971 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | 1970 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); |
| 1972 DCHECK(change >= IndependentInherit || needsStyleRecalc()); | 1971 DCHECK(change >= IndependentInherit || needsStyleRecalc()); |
| 1973 DCHECK(parentComputedStyle()); | 1972 DCHECK(parentComputedStyle()); |
| 1974 | 1973 |
| 1974 if (needsReattachLayoutTree()) { |
| 1975 StyleReattachData styleReattachData; |
| 1976 styleReattachData.nextTextSibling = nextTextSibling; |
| 1977 document().addStyleReattachData(*this, styleReattachData); |
| 1978 setNeedsReattachLayoutTree(); |
| 1979 return Reattach; |
| 1980 } |
| 1981 |
| 1975 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); | 1982 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); |
| 1976 | 1983 |
| 1977 // When propagating inherited changes, we don't need to do a full style recalc | 1984 // 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 | 1985 // if the only changed properties are independent. In this case, we can simply |
| 1979 // set these directly on the ComputedStyle object. | 1986 // set these directly on the ComputedStyle object. |
| 1980 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); | 1987 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); |
| 1981 if (!newStyle) | 1988 if (!newStyle) |
| 1982 newStyle = styleForLayoutObject(); | 1989 newStyle = styleForLayoutObject(); |
| 1983 DCHECK(newStyle); | 1990 DCHECK(newStyle); |
| 1984 | 1991 |
| 1985 StyleRecalcChange localChange = | 1992 StyleRecalcChange localChange = |
| 1986 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); | 1993 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); |
| 1987 if (localChange == NoChange) { | 1994 if (localChange == NoChange) { |
| 1988 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); | 1995 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); |
| 1989 } else { | 1996 } else { |
| 1990 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); | 1997 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); |
| 1991 } | 1998 } |
| 1992 | 1999 |
| 1993 if (localChange == Reattach) { | 2000 if (localChange == Reattach) { |
| 1994 StyleReattachData styleReattachData; | 2001 StyleReattachData styleReattachData; |
| 1995 styleReattachData.computedStyle = std::move(newStyle); | 2002 styleReattachData.computedStyle = std::move(newStyle); |
| 1996 styleReattachData.nextTextSibling = nextTextSibling; | 2003 styleReattachData.nextTextSibling = nextTextSibling; |
| 1997 document().addStyleReattachData(*this, styleReattachData); | 2004 document().addStyleReattachData(*this, styleReattachData); |
| 1998 setNeedsReattachLayoutTree(); | 2005 setNeedsReattachLayoutTree(); |
| 1999 return rebuildLayoutTree(); | 2006 return Reattach; |
| 2000 } | 2007 } |
| 2001 | 2008 |
| 2002 DCHECK(oldStyle); | 2009 DCHECK(oldStyle); |
| 2003 | 2010 |
| 2004 if (localChange != NoChange) | 2011 if (localChange != NoChange) |
| 2005 updateCallbackSelectors(oldStyle.get(), newStyle.get()); | 2012 updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
| 2006 | 2013 |
| 2007 if (LayoutObject* layoutObject = this->layoutObject()) { | 2014 if (LayoutObject* layoutObject = this->layoutObject()) { |
| 2008 if (localChange != NoChange || | 2015 if (localChange != NoChange || |
| 2009 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { | 2016 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2030 return Inherit; | 2037 return Inherit; |
| 2031 newStyle->copyChildDependentFlagsFrom(*oldStyle); | 2038 newStyle->copyChildDependentFlagsFrom(*oldStyle); |
| 2032 } | 2039 } |
| 2033 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) | 2040 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) |
| 2034 return UpdatePseudoElements; | 2041 return UpdatePseudoElements; |
| 2035 } | 2042 } |
| 2036 | 2043 |
| 2037 return localChange; | 2044 return localChange; |
| 2038 } | 2045 } |
| 2039 | 2046 |
| 2040 StyleRecalcChange Element::rebuildLayoutTree() { | 2047 void Element::rebuildLayoutTree() { |
| 2041 DCHECK(inActiveDocument()); | 2048 DCHECK(inActiveDocument()); |
| 2049 DCHECK(parentNode()); |
| 2050 |
| 2042 StyleReattachData styleReattachData = document().getStyleReattachData(*this); | 2051 StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
| 2043 AttachContext reattachContext; | 2052 AttachContext reattachContext; |
| 2044 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); | 2053 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
| 2045 bool layoutObjectWillChange = needsAttach() || layoutObject(); | 2054 bool layoutObjectWillChange = needsAttach() || layoutObject(); |
| 2046 | 2055 |
| 2047 // We are calling Element::rebuildLayoutTree() from inside | 2056 if (needsReattachLayoutTree()) { |
| 2048 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree | 2057 reattachLayoutTree(reattachContext); |
| 2049 // flag - so needsReattachLayoutTree() should always be true. | 2058 } else if (childNeedsReattachLayoutTree()) { |
| 2050 DCHECK(parentNode()); | 2059 DCHECK(!needsReattachLayoutTree()); |
| 2051 DCHECK(parentNode()->childNeedsReattachLayoutTree()); | 2060 SelectorFilterParentScope filterScope(*this); |
| 2052 DCHECK(needsReattachLayoutTree()); | 2061 StyleSharingDepthScope sharingScope(*this); |
| 2053 reattachLayoutTree(reattachContext); | 2062 reattachPseudoElementLayoutTree(PseudoIdBefore); |
| 2054 // Since needsReattachLayoutTree() is always true we go into | 2063 rebuildShadowRootLayoutTree(); |
| 2055 // reattachLayoutTree() which reattaches all the descendant | 2064 rebuildChildrenLayoutTrees(); |
| 2056 // 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()); |
| 2057 DCHECK(!childNeedsReattachLayoutTree()); | 2072 DCHECK(!childNeedsReattachLayoutTree()); |
| 2058 | 2073 |
| 2059 if (layoutObjectWillChange || layoutObject()) { | 2074 if (layoutObjectWillChange || layoutObject()) { |
| 2060 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles | 2075 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
| 2061 // we can either traverse the current subtree from this node onwards | 2076 // we can either traverse the current subtree from this node onwards |
| 2062 // or store it. | 2077 // or store it. |
| 2063 // The choice is between increased time and increased memory complexity. | 2078 // The choice is between increased time and increased memory complexity. |
| 2064 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); | 2079 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
| 2065 return Reattach; | |
| 2066 } | 2080 } |
| 2067 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 } |
| 2068 } | 2099 } |
| 2069 | 2100 |
| 2070 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, | 2101 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |
| 2071 const ComputedStyle* newStyle) { | 2102 const ComputedStyle* newStyle) { |
| 2072 Vector<String> emptyVector; | 2103 Vector<String> emptyVector; |
| 2073 const Vector<String>& oldCallbackSelectors = | 2104 const Vector<String>& oldCallbackSelectors = |
| 2074 oldStyle ? oldStyle->callbackSelectors() : emptyVector; | 2105 oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
| 2075 const Vector<String>& newCallbackSelectors = | 2106 const Vector<String>& newCallbackSelectors = |
| 2076 newStyle ? newStyle->callbackSelectors() : emptyVector; | 2107 newStyle ? newStyle->callbackSelectors() : emptyVector; |
| 2077 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) | 2108 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) |
| (...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4139 } | 4170 } |
| 4140 | 4171 |
| 4141 DEFINE_TRACE_WRAPPERS(Element) { | 4172 DEFINE_TRACE_WRAPPERS(Element) { |
| 4142 if (hasRareData()) { | 4173 if (hasRareData()) { |
| 4143 visitor->traceWrappers(elementRareData()); | 4174 visitor->traceWrappers(elementRareData()); |
| 4144 } | 4175 } |
| 4145 ContainerNode::traceWrappers(visitor); | 4176 ContainerNode::traceWrappers(visitor); |
| 4146 } | 4177 } |
| 4147 | 4178 |
| 4148 } // namespace blink | 4179 } // namespace blink |
| OLD | NEW |