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 // Needed because the rebuildLayoutTree code needs to see what the | 1906 clearNeedsStyleRecalc(); |
1907 // styleChangeType() was on reattach roots. See Node::reattachLayoutTree() | 1907 clearNeedsReattachLayoutTree(); |
1908 // for an example. | |
1909 if (change != Reattach) | |
1910 clearNeedsStyleRecalc(); | |
1911 } | 1908 } |
1912 | 1909 |
1913 // If we are going to reattach we don't need to recalc the style of | 1910 // If we reattached we don't need to recalc the style of our descendants |
1914 // our descendants anymore. | 1911 // anymore. |
1915 if (change < Reattach && | 1912 if ((change >= UpdatePseudoElements && change < Reattach) || |
1916 (change >= UpdatePseudoElements || childNeedsStyleRecalc())) { | 1913 childNeedsStyleRecalc()) { |
1917 SelectorFilterParentScope filterScope(*this); | 1914 SelectorFilterParentScope filterScope(*this); |
1918 StyleSharingDepthScope sharingScope(*this); | 1915 StyleSharingDepthScope sharingScope(*this); |
1919 | 1916 |
1920 updatePseudoElement(PseudoIdBefore, change); | 1917 updatePseudoElement(PseudoIdBefore, change); |
1921 | 1918 |
1922 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { | 1919 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) { |
1923 for (ShadowRoot* root = youngestShadowRoot(); root; | 1920 for (ShadowRoot* root = youngestShadowRoot(); root; |
1924 root = root->olderShadowRoot()) { | 1921 root = root->olderShadowRoot()) { |
1925 if (root->shouldCallRecalcStyle(change)) | 1922 if (root->shouldCallRecalcStyle(change)) |
1926 root->recalcStyle(change); | 1923 root->recalcStyle(change); |
1927 } | 1924 } |
1928 recalcDescendantStyles(change); | 1925 recalcDescendantStyles(change); |
1929 } | 1926 } |
1930 | 1927 |
1931 updatePseudoElement(PseudoIdAfter, change); | 1928 updatePseudoElement(PseudoIdAfter, change); |
1932 updatePseudoElement(PseudoIdBackdrop, change); | 1929 updatePseudoElement(PseudoIdBackdrop, change); |
1933 | 1930 |
1934 // 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 |
1935 // 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. |
1936 // This can be seen when a child transitions from floating to | 1933 // This can be seen when a child transitions from floating to |
1937 // 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. |
1938 updatePseudoElement(PseudoIdFirstLetter, | 1935 updatePseudoElement(PseudoIdFirstLetter, |
1939 childNeedsStyleRecalc() ? Force : change); | 1936 childNeedsStyleRecalc() ? Force : change); |
1940 | 1937 |
1941 clearChildNeedsStyleRecalc(); | 1938 clearChildNeedsStyleRecalc(); |
| 1939 clearChildNeedsReattachLayoutTree(); |
1942 } | 1940 } |
1943 | 1941 |
1944 if (hasCustomStyleCallbacks()) | 1942 if (hasCustomStyleCallbacks()) |
1945 didRecalcStyle(); | 1943 didRecalcStyle(); |
1946 } | 1944 } |
1947 | 1945 |
1948 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( | 1946 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties( |
1949 StyleRecalcChange change) { | 1947 StyleRecalcChange change) { |
1950 if (change != IndependentInherit) | 1948 if (change != IndependentInherit) |
1951 return nullptr; | 1949 return nullptr; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 } else { | 1989 } else { |
1992 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); | 1990 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); |
1993 } | 1991 } |
1994 | 1992 |
1995 if (localChange == Reattach) { | 1993 if (localChange == Reattach) { |
1996 StyleReattachData styleReattachData; | 1994 StyleReattachData styleReattachData; |
1997 styleReattachData.computedStyle = std::move(newStyle); | 1995 styleReattachData.computedStyle = std::move(newStyle); |
1998 styleReattachData.nextTextSibling = nextTextSibling; | 1996 styleReattachData.nextTextSibling = nextTextSibling; |
1999 document().addStyleReattachData(*this, styleReattachData); | 1997 document().addStyleReattachData(*this, styleReattachData); |
2000 setNeedsReattachLayoutTree(); | 1998 setNeedsReattachLayoutTree(); |
2001 return Reattach; | 1999 return rebuildLayoutTree(); |
2002 } | 2000 } |
2003 | 2001 |
2004 DCHECK(oldStyle); | 2002 DCHECK(oldStyle); |
2005 | 2003 |
2006 if (localChange != NoChange) | 2004 if (localChange != NoChange) |
2007 updateCallbackSelectors(oldStyle.get(), newStyle.get()); | 2005 updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
2008 | 2006 |
2009 if (LayoutObject* layoutObject = this->layoutObject()) { | 2007 if (LayoutObject* layoutObject = this->layoutObject()) { |
2010 if (localChange != NoChange || | 2008 if (localChange != NoChange || |
2011 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { | 2009 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { |
(...skipping 20 matching lines...) Expand all Loading... |
2032 return Inherit; | 2030 return Inherit; |
2033 newStyle->copyChildDependentFlagsFrom(*oldStyle); | 2031 newStyle->copyChildDependentFlagsFrom(*oldStyle); |
2034 } | 2032 } |
2035 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) | 2033 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) |
2036 return UpdatePseudoElements; | 2034 return UpdatePseudoElements; |
2037 } | 2035 } |
2038 | 2036 |
2039 return localChange; | 2037 return localChange; |
2040 } | 2038 } |
2041 | 2039 |
2042 void Element::rebuildLayoutTree() { | 2040 StyleRecalcChange Element::rebuildLayoutTree() { |
2043 DCHECK(inActiveDocument()); | 2041 DCHECK(inActiveDocument()); |
| 2042 StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
| 2043 AttachContext reattachContext; |
| 2044 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
| 2045 bool layoutObjectWillChange = needsAttach() || layoutObject(); |
| 2046 |
| 2047 // We are calling Element::rebuildLayoutTree() from inside |
| 2048 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree |
| 2049 // flag - so needsReattachLayoutTree() should always be true. |
2044 DCHECK(parentNode()); | 2050 DCHECK(parentNode()); |
| 2051 DCHECK(parentNode()->childNeedsReattachLayoutTree()); |
| 2052 DCHECK(needsReattachLayoutTree()); |
| 2053 reattachLayoutTree(reattachContext); |
| 2054 // Since needsReattachLayoutTree() is always true we go into |
| 2055 // reattachLayoutTree() which reattaches all the descendant |
| 2056 // sub-trees. At this point no child should need reattaching. |
| 2057 DCHECK(!childNeedsReattachLayoutTree()); |
2045 | 2058 |
2046 if (needsReattachLayoutTree()) { | 2059 if (layoutObjectWillChange || layoutObject()) { |
2047 StyleReattachData styleReattachData = | 2060 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
2048 document().getStyleReattachData(*this); | 2061 // we can either traverse the current subtree from this node onwards |
2049 AttachContext reattachContext; | 2062 // or store it. |
2050 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); | 2063 // The choice is between increased time and increased memory complexity. |
2051 bool layoutObjectWillChange = | 2064 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
2052 getStyleChangeType() == NeedsReattachStyleChange || layoutObject(); | 2065 return Reattach; |
2053 reattachLayoutTree(reattachContext); | |
2054 if (layoutObjectWillChange || layoutObject()) { | |
2055 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles | |
2056 // we can either traverse the current subtree from this node onwards | |
2057 // or store it. | |
2058 // The choice is between increased time and increased memory complexity. | |
2059 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); | |
2060 } | |
2061 } else if (childNeedsReattachLayoutTree()) { | |
2062 DCHECK(!needsReattachLayoutTree()); | |
2063 SelectorFilterParentScope filterScope(*this); | |
2064 StyleSharingDepthScope sharingScope(*this); | |
2065 reattachPseudoElementLayoutTree(PseudoIdBefore); | |
2066 rebuildShadowRootLayoutTree(); | |
2067 rebuildChildrenLayoutTrees(); | |
2068 reattachPseudoElementLayoutTree(PseudoIdAfter); | |
2069 reattachPseudoElementLayoutTree(PseudoIdBackdrop); | |
2070 reattachPseudoElementLayoutTree(PseudoIdFirstLetter); | |
2071 } | 2066 } |
2072 DCHECK(!needsStyleRecalc()); | 2067 return ReattachNoLayoutObject; |
2073 DCHECK(!childNeedsStyleRecalc()); | |
2074 DCHECK(!needsReattachLayoutTree()); | |
2075 DCHECK(!childNeedsReattachLayoutTree()); | |
2076 } | |
2077 | |
2078 void Element::rebuildShadowRootLayoutTree() { | |
2079 for (ShadowRoot* root = youngestShadowRoot(); root; | |
2080 root = root->olderShadowRoot()) { | |
2081 if (root->needsReattachLayoutTree() || root->childNeedsReattachLayoutTree()) | |
2082 root->rebuildLayoutTree(); | |
2083 } | |
2084 } | |
2085 | |
2086 void Element::reattachPseudoElementLayoutTree(PseudoId pseudoId) { | |
2087 if (PseudoElement* element = pseudoElement(pseudoId)) { | |
2088 if (element->needsReattachLayoutTree() || | |
2089 element->childNeedsReattachLayoutTree()) | |
2090 element->rebuildLayoutTree(); | |
2091 } else { | |
2092 createPseudoElementIfNeeded(pseudoId); | |
2093 } | |
2094 } | 2068 } |
2095 | 2069 |
2096 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, | 2070 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |
2097 const ComputedStyle* newStyle) { | 2071 const ComputedStyle* newStyle) { |
2098 Vector<String> emptyVector; | 2072 Vector<String> emptyVector; |
2099 const Vector<String>& oldCallbackSelectors = | 2073 const Vector<String>& oldCallbackSelectors = |
2100 oldStyle ? oldStyle->callbackSelectors() : emptyVector; | 2074 oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
2101 const Vector<String>& newCallbackSelectors = | 2075 const Vector<String>& newCallbackSelectors = |
2102 newStyle ? newStyle->callbackSelectors() : emptyVector; | 2076 newStyle ? newStyle->callbackSelectors() : emptyVector; |
2103 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) | 2077 if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) |
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4168 } | 4142 } |
4169 | 4143 |
4170 DEFINE_TRACE_WRAPPERS(Element) { | 4144 DEFINE_TRACE_WRAPPERS(Element) { |
4171 if (hasRareData()) { | 4145 if (hasRareData()) { |
4172 visitor->traceWrappers(elementRareData()); | 4146 visitor->traceWrappers(elementRareData()); |
4173 } | 4147 } |
4174 ContainerNode::traceWrappers(visitor); | 4148 ContainerNode::traceWrappers(visitor); |
4175 } | 4149 } |
4176 | 4150 |
4177 } // namespace blink | 4151 } // namespace blink |
OLD | NEW |