Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2220873002: Add a fast-path for independent inherited properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for shadow roots Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) 1721 void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling)
1722 { 1722 {
1723 DCHECK(document().inStyleRecalc()); 1723 DCHECK(document().inStyleRecalc());
1724 DCHECK(!document().lifecycle().inDetach()); 1724 DCHECK(!document().lifecycle().inDetach());
1725 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); 1725 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc());
1726 DCHECK(inActiveDocument()); 1726 DCHECK(inActiveDocument());
1727 1727
1728 if (hasCustomStyleCallbacks()) 1728 if (hasCustomStyleCallbacks())
1729 willRecalcStyle(change); 1729 willRecalcStyle(change);
1730 1730
1731 if (change >= Inherit || needsStyleRecalc()) { 1731 if (change >= IndependentInherit || needsStyleRecalc()) {
1732 if (hasRareData()) { 1732 if (hasRareData()) {
1733 ElementRareData* data = elementRareData(); 1733 ElementRareData* data = elementRareData();
1734 data->clearComputedStyle(); 1734 if (change != IndependentInherit)
1735 data->clearComputedStyle();
1735 1736
1736 if (change >= Inherit) { 1737 if (change >= IndependentInherit) {
1737 if (ElementAnimations* elementAnimations = data->elementAnimatio ns()) 1738 if (ElementAnimations* elementAnimations = data->elementAnimatio ns())
1738 elementAnimations->setAnimationStyleChange(false); 1739 elementAnimations->setAnimationStyleChange(false);
1739 } 1740 }
1740 } 1741 }
1741 if (parentComputedStyle()) 1742 if (parentComputedStyle())
1742 change = recalcOwnStyle(change); 1743 change = recalcOwnStyle(change);
1743 clearNeedsStyleRecalc(); 1744 clearNeedsStyleRecalc();
1744 } 1745 }
1745 1746
1746 // If we reattached we don't need to recalc the style of our descendants any more. 1747 // If we reattached we don't need to recalc the style of our descendants any more.
(...skipping 23 matching lines...) Expand all
1770 clearChildNeedsStyleRecalc(); 1771 clearChildNeedsStyleRecalc();
1771 } 1772 }
1772 1773
1773 if (hasCustomStyleCallbacks()) 1774 if (hasCustomStyleCallbacks())
1774 didRecalcStyle(change); 1775 didRecalcStyle(change);
1775 1776
1776 if (change == Reattach) 1777 if (change == Reattach)
1777 reattachWhitespaceSiblingsIfNeeded(nextTextSibling); 1778 reattachWhitespaceSiblingsIfNeeded(nextTextSibling);
1778 } 1779 }
1779 1780
1781 PassRefPtr<ComputedStyle> Element::propagateInheritedProperties(StyleRecalcChang e change)
1782 {
1783 if (change != IndependentInherit)
1784 return nullptr;
1785 if (needsStyleRecalc())
1786 return nullptr;
1787 if (hasAnimations())
1788 return nullptr;
1789 const ComputedStyle* parentStyle = parentComputedStyle();
1790 DCHECK(parentStyle);
1791 const ComputedStyle* style = computedStyle();
1792 if (!style || style->animations() || style->transitions())
1793 return nullptr;
1794 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style);
1795 newStyle->propagateIndependentInheritedProperties(*parentStyle);
1796 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), independentInherited StylesPropagated, 1);
1797 return newStyle;
1798 }
1799
1780 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) 1800 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change)
1781 { 1801 {
1782 DCHECK(document().inStyleRecalc()); 1802 DCHECK(document().inStyleRecalc());
1783 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); 1803 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc());
1784 DCHECK(change >= Inherit || needsStyleRecalc()); 1804 DCHECK(change >= IndependentInherit || needsStyleRecalc());
1785 DCHECK(parentComputedStyle()); 1805 DCHECK(parentComputedStyle());
1786 1806
1787 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle(); 1807 RefPtr<ComputedStyle> oldStyle = mutableComputedStyle();
1788 RefPtr<ComputedStyle> newStyle = styleForLayoutObject(); 1808
1809 // When propagating inherited changes, we don't need to do a full style reca lc
1810 // if the only changed properties are independent. In this case, we can simp ly
1811 // set these directly on the ComputedStyle object.
1812 RefPtr<ComputedStyle> newStyle = propagateInheritedProperties(change);
1813 if (!newStyle)
1814 newStyle = styleForLayoutObject();
1789 DCHECK(newStyle); 1815 DCHECK(newStyle);
1790 1816
1791 StyleRecalcChange localChange = ComputedStyle::stylePropagationDiff(oldStyle .get(), newStyle.get()); 1817 StyleRecalcChange localChange = ComputedStyle::stylePropagationDiff(oldStyle .get(), newStyle.get());
1792 if (localChange == NoChange) { 1818 if (localChange == NoChange) {
1793 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); 1819 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1);
1794 } else { 1820 } else {
1795 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1 ); 1821 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1 );
1796 } 1822 }
1797 1823
1798 if (localChange == Reattach) { 1824 if (localChange == Reattach) {
(...skipping 19 matching lines...) Expand all
1818 layoutObject->setStyleInternal(newStyle.get()); 1844 layoutObject->setStyleInternal(newStyle.get());
1819 } 1845 }
1820 } 1846 }
1821 1847
1822 if (getStyleChangeType() >= SubtreeStyleChange) 1848 if (getStyleChangeType() >= SubtreeStyleChange)
1823 return Force; 1849 return Force;
1824 1850
1825 if (change > Inherit || localChange > Inherit) 1851 if (change > Inherit || localChange > Inherit)
1826 return max(localChange, change); 1852 return max(localChange, change);
1827 1853
1828 if (localChange < Inherit) { 1854 if (localChange < IndependentInherit) {
1829 if (oldStyle->hasChildDependentFlags()) { 1855 if (oldStyle->hasChildDependentFlags()) {
1830 if (childNeedsStyleRecalc()) 1856 if (childNeedsStyleRecalc())
1831 return Inherit; 1857 return Inherit;
1832 newStyle->copyChildDependentFlagsFrom(*oldStyle); 1858 newStyle->copyChildDependentFlagsFrom(*oldStyle);
1833 } 1859 }
1834 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle ()) 1860 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle ())
1835 return UpdatePseudoElements; 1861 return UpdatePseudoElements;
1836 } 1862 }
1837 1863
1838 return localChange; 1864 return localChange;
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
3815 3841
3816 DEFINE_TRACE_WRAPPERS(Element) 3842 DEFINE_TRACE_WRAPPERS(Element)
3817 { 3843 {
3818 if (hasRareData()) { 3844 if (hasRareData()) {
3819 visitor->traceWrappers(elementRareData()); 3845 visitor->traceWrappers(elementRareData());
3820 } 3846 }
3821 ContainerNode::traceWrappers(visitor); 3847 ContainerNode::traceWrappers(visitor);
3822 } 3848 }
3823 3849
3824 } // namespace blink 3850 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698