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 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 isInTopLayer()); | 1826 isInTopLayer()); |
1827 | 1827 |
1828 return style.release(); | 1828 return style.release(); |
1829 } | 1829 } |
1830 | 1830 |
1831 PassRefPtr<ComputedStyle> Element::originalStyleForLayoutObject() { | 1831 PassRefPtr<ComputedStyle> Element::originalStyleForLayoutObject() { |
1832 DCHECK(document().inStyleRecalc()); | 1832 DCHECK(document().inStyleRecalc()); |
1833 return document().ensureStyleResolver().styleForElement(this); | 1833 return document().ensureStyleResolver().styleForElement(this); |
1834 } | 1834 } |
1835 | 1835 |
1836 void Element::recalcStyle(StyleRecalcChange change) { | 1836 void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) { |
1837 DCHECK(document().inStyleRecalc()); | 1837 DCHECK(document().inStyleRecalc()); |
1838 DCHECK(!document().lifecycle().inDetach()); | 1838 DCHECK(!document().lifecycle().inDetach()); |
1839 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | 1839 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); |
1840 DCHECK(inActiveDocument()); | 1840 DCHECK(inActiveDocument()); |
1841 | 1841 |
1842 if (hasCustomStyleCallbacks()) | 1842 if (hasCustomStyleCallbacks()) |
1843 willRecalcStyle(change); | 1843 willRecalcStyle(change); |
1844 | 1844 |
1845 if (change >= IndependentInherit || needsStyleRecalc()) { | 1845 if (change >= IndependentInherit || needsStyleRecalc()) { |
1846 if (hasRareData()) { | 1846 if (hasRareData()) { |
1847 ElementRareData* data = elementRareData(); | 1847 ElementRareData* data = elementRareData(); |
1848 if (change != IndependentInherit) | 1848 if (change != IndependentInherit) |
1849 data->clearComputedStyle(); | 1849 data->clearComputedStyle(); |
1850 | 1850 |
1851 if (change >= IndependentInherit) { | 1851 if (change >= IndependentInherit) { |
1852 if (ElementAnimations* elementAnimations = data->elementAnimations()) | 1852 if (ElementAnimations* elementAnimations = data->elementAnimations()) |
1853 elementAnimations->setAnimationStyleChange(false); | 1853 elementAnimations->setAnimationStyleChange(false); |
1854 } | 1854 } |
1855 } | 1855 } |
1856 if (parentComputedStyle()) | 1856 if (parentComputedStyle()) |
1857 change = recalcOwnStyle(change); | 1857 change = recalcOwnStyle(change, nextTextSibling); |
1858 clearNeedsStyleRecalc(); | 1858 clearNeedsStyleRecalc(); |
1859 clearNeedsReattachLayoutTree(); | 1859 clearNeedsReattachLayoutTree(); |
1860 } | 1860 } |
1861 | 1861 |
1862 // If we reattached we don't need to recalc the style of our descendants | 1862 // If we reattached we don't need to recalc the style of our descendants |
1863 // anymore. | 1863 // anymore. |
1864 if ((change >= UpdatePseudoElements && change < Reattach) || | 1864 if ((change >= UpdatePseudoElements && change < Reattach) || |
1865 childNeedsStyleRecalc()) { | 1865 childNeedsStyleRecalc()) { |
1866 SelectorFilterParentScope filterScope(*this); | 1866 SelectorFilterParentScope filterScope(*this); |
1867 StyleSharingDepthScope sharingScope(*this); | 1867 StyleSharingDepthScope sharingScope(*this); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 const ComputedStyle* style = computedStyle(); | 1910 const ComputedStyle* style = computedStyle(); |
1911 if (!style || style->animations() || style->transitions()) | 1911 if (!style || style->animations() || style->transitions()) |
1912 return nullptr; | 1912 return nullptr; |
1913 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style); | 1913 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style); |
1914 newStyle->propagateIndependentInheritedProperties(*parentStyle); | 1914 newStyle->propagateIndependentInheritedProperties(*parentStyle); |
1915 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1915 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
1916 independentInheritedStylesPropagated, 1); | 1916 independentInheritedStylesPropagated, 1); |
1917 return newStyle; | 1917 return newStyle; |
1918 } | 1918 } |
1919 | 1919 |
1920 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) { | 1920 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change, |
| 1921 Text* nextTextSibling) { |
1921 DCHECK(document().inStyleRecalc()); | 1922 DCHECK(document().inStyleRecalc()); |
1922 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | 1923 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); |
1923 DCHECK(change >= IndependentInherit || needsStyleRecalc()); | 1924 DCHECK(change >= IndependentInherit || needsStyleRecalc()); |
1924 DCHECK(parentComputedStyle()); | 1925 DCHECK(parentComputedStyle()); |
1925 | 1926 |
1926 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); | 1927 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); |
1927 | 1928 |
1928 // When propagating inherited changes, we don't need to do a full style recalc | 1929 // When propagating inherited changes, we don't need to do a full style recalc |
1929 // if the only changed properties are independent. In this case, we can simply | 1930 // if the only changed properties are independent. In this case, we can simply |
1930 // set these directly on the ComputedStyle object. | 1931 // set these directly on the ComputedStyle object. |
1931 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); | 1932 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change); |
1932 if (!newStyle) | 1933 if (!newStyle) |
1933 newStyle = styleForLayoutObject(); | 1934 newStyle = styleForLayoutObject(); |
1934 DCHECK(newStyle); | 1935 DCHECK(newStyle); |
1935 | 1936 |
1936 StyleRecalcChange localChange = | 1937 StyleRecalcChange localChange = |
1937 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); | 1938 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); |
1938 if (localChange == NoChange) { | 1939 if (localChange == NoChange) { |
1939 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); | 1940 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); |
1940 } else { | 1941 } else { |
1941 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); | 1942 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); |
1942 } | 1943 } |
1943 | 1944 |
1944 if (localChange == Reattach) { | 1945 if (localChange == Reattach) { |
1945 document().addNonAttachedStyle(*this, std::move(newStyle)); | 1946 StyleReattachData styleReattachData; |
| 1947 styleReattachData.computedStyle = std::move(newStyle); |
| 1948 styleReattachData.nextTextSibling = nextTextSibling; |
| 1949 document().addStyleReattachData(*this, styleReattachData); |
1946 setNeedsReattachLayoutTree(); | 1950 setNeedsReattachLayoutTree(); |
1947 return rebuildLayoutTree(); | 1951 return rebuildLayoutTree(); |
1948 } | 1952 } |
1949 | 1953 |
1950 DCHECK(oldStyle); | 1954 DCHECK(oldStyle); |
1951 | 1955 |
1952 if (localChange != NoChange) | 1956 if (localChange != NoChange) |
1953 updateCallbackSelectors(oldStyle.get(), newStyle.get()); | 1957 updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
1954 | 1958 |
1955 if (LayoutObject* layoutObject = this->layoutObject()) { | 1959 if (LayoutObject* layoutObject = this->layoutObject()) { |
(...skipping 24 matching lines...) Expand all Loading... |
1980 } | 1984 } |
1981 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) | 1985 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) |
1982 return UpdatePseudoElements; | 1986 return UpdatePseudoElements; |
1983 } | 1987 } |
1984 | 1988 |
1985 return localChange; | 1989 return localChange; |
1986 } | 1990 } |
1987 | 1991 |
1988 StyleRecalcChange Element::rebuildLayoutTree() { | 1992 StyleRecalcChange Element::rebuildLayoutTree() { |
1989 DCHECK(inActiveDocument()); | 1993 DCHECK(inActiveDocument()); |
| 1994 StyleReattachData styleReattachData = document().getStyleReattachData(*this); |
1990 AttachContext reattachContext; | 1995 AttachContext reattachContext; |
1991 reattachContext.resolvedStyle = document().getNonAttachedStyle(*this); | 1996 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); |
1992 bool layoutObjectWillChange = needsAttach() || layoutObject(); | 1997 bool layoutObjectWillChange = needsAttach() || layoutObject(); |
1993 | 1998 |
1994 // We are calling Element::rebuildLayoutTree() from inside | 1999 // We are calling Element::rebuildLayoutTree() from inside |
1995 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree | 2000 // Element::recalcOwnStyle where we set the NeedsReattachLayoutTree |
1996 // flag - so needsReattachLayoutTree() should always be true. | 2001 // flag - so needsReattachLayoutTree() should always be true. |
1997 DCHECK(parentNode()); | 2002 DCHECK(parentNode()); |
1998 DCHECK(parentNode()->childNeedsReattachLayoutTree()); | 2003 DCHECK(parentNode()->childNeedsReattachLayoutTree()); |
1999 DCHECK(needsReattachLayoutTree()); | 2004 DCHECK(needsReattachLayoutTree()); |
2000 reattachLayoutTree(reattachContext); | 2005 reattachLayoutTree(reattachContext); |
2001 // Since needsReattachLayoutTree() is always true we go into | 2006 // Since needsReattachLayoutTree() is always true we go into |
2002 // reattachLayoutTree() which reattaches all the descendant | 2007 // reattachLayoutTree() which reattaches all the descendant |
2003 // sub-trees. At this point no child should need reattaching. | 2008 // sub-trees. At this point no child should need reattaching. |
2004 DCHECK(!childNeedsReattachLayoutTree()); | 2009 DCHECK(!childNeedsReattachLayoutTree()); |
2005 | 2010 |
2006 if (layoutObjectWillChange || layoutObject()) { | 2011 if (layoutObjectWillChange || layoutObject()) { |
2007 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles | 2012 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles |
2008 // we can either traverse the current subtree from this node onwards | 2013 // we can either traverse the current subtree from this node onwards |
2009 // or store it. | 2014 // or store it. |
2010 // The choice is between increased time and increased memory complexity. | 2015 // The choice is between increased time and increased memory complexity. |
2011 reattachWhitespaceSiblingsIfNeeded(nextTextSibling()); | 2016 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); |
2012 return Reattach; | 2017 return Reattach; |
2013 } | 2018 } |
2014 return ReattachNoLayoutObject; | 2019 return ReattachNoLayoutObject; |
2015 } | 2020 } |
2016 | 2021 |
2017 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, | 2022 void Element::updateCallbackSelectors(const ComputedStyle* oldStyle, |
2018 const ComputedStyle* newStyle) { | 2023 const ComputedStyle* newStyle) { |
2019 Vector<String> emptyVector; | 2024 Vector<String> emptyVector; |
2020 const Vector<String>& oldCallbackSelectors = | 2025 const Vector<String>& oldCallbackSelectors = |
2021 oldStyle ? oldStyle->callbackSelectors() : emptyVector; | 2026 oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
(...skipping 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4084 } | 4089 } |
4085 | 4090 |
4086 DEFINE_TRACE_WRAPPERS(Element) { | 4091 DEFINE_TRACE_WRAPPERS(Element) { |
4087 if (hasRareData()) { | 4092 if (hasRareData()) { |
4088 visitor->traceWrappers(elementRareData()); | 4093 visitor->traceWrappers(elementRareData()); |
4089 } | 4094 } |
4090 ContainerNode::traceWrappers(visitor); | 4095 ContainerNode::traceWrappers(visitor); |
4091 } | 4096 } |
4092 | 4097 |
4093 } // namespace blink | 4098 } // namespace blink |
OLD | NEW |