<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[196031] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196031">196031</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2016-02-02 14:34:45 -0800 (Tue, 02 Feb 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Factor style sharing code out of StyleResolver
https://bugs.webkit.org/show_bug.cgi?id=153768
Reviewed by Darin Adler.
Move the code to a new class, Style::SharingResolver.
When resolving document style we query the sharing resolver first before using the regular style resolver.
Other paths that call style resolver were mostly already disabling it with DisallowStyleSharing flag.
* WebCore.xcodeproj/project.pbxproj:
* css/ElementRuleCollector.cpp:
(WebCore::MatchRequest::MatchRequest):
(WebCore::ElementRuleCollector::matchAllRules):
(WebCore::ElementRuleCollector::hasAnyMatchingRules):
More const.
* css/ElementRuleCollector.h:
(WebCore::ElementRuleCollector::setRegionForStyling):
(WebCore::ElementRuleCollector::setMedium):
* css/MediaQueryMatcher.cpp:
(WebCore::MediaQueryMatcher::prepareEvaluator):
* css/StyleMedia.cpp:
(WebCore::StyleMedia::matchMedium):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::State::cacheBorderAndBackground):
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::sweepMatchedPropertiesCache):
(WebCore::StyleResolver::State::State):
(WebCore::StyleResolver::State::setStyle):
(WebCore::isAtShadowBoundary):
(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::classNamesAffectedByRules): Deleted.
(WebCore::parentElementPreventsSharing): Deleted.
(WebCore::StyleResolver::locateCousinList): Deleted.
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet): Deleted.
(WebCore::StyleResolver::canShareStyleWithControl): Deleted.
(WebCore::elementHasDirectionAuto): Deleted.
(WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes): Deleted.
(WebCore::StyleResolver::canShareStyleWithElement): Deleted.
(WebCore::StyleResolver::findSiblingForStyleSharing): Deleted.
(WebCore::StyleResolver::locateSharedStyle): Deleted.
Style sharing code moves to SharingResolver.
* css/StyleResolver.h:
(WebCore::StyleResolver::mediaQueryEvaluator):
(WebCore::StyleResolver::State::regionForStyling):
(WebCore::StyleResolver::State::elementLinkState):
(WebCore::StyleResolver::State::setApplyPropertyToRegularStyle):
(WebCore::StyleResolver::State::setApplyPropertyToVisitedLinkStyle):
(WebCore::StyleResolver::state):
(WebCore::StyleResolver::setTextOrientation):
(WebCore::StyleResolver::State::setElementAffectedByClassRules): Deleted.
(WebCore::StyleResolver::State::elementAffectedByClassRules): Deleted.
(WebCore::StyleResolver::styleNotYetAvailable): Deleted.
Placeholder code moves to TreeResolver.
* dom/VisitedLinkState.cpp:
(WebCore::linkAttribute):
(WebCore::VisitedLinkState::invalidateStyleForAllLinks):
(WebCore::linkHashForElement):
(WebCore::VisitedLinkState::invalidateStyleForLink):
(WebCore::VisitedLinkState::determineLinkStateSlowCase):
* dom/VisitedLinkState.h:
(WebCore::VisitedLinkState::determineLinkState):
* html/HTMLFormControlElement.h:
* rendering/RenderElement.cpp:
(WebCore::RenderElement::getUncachedPseudoStyle):
* rendering/RenderNamedFlowFragment.cpp:
(WebCore::RenderNamedFlowFragment::computeStyleInRegion):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::isStyleAvailable):
(WebCore::RenderStyle::hasUniquePseudoStyle):
* style/StyleSharingResolver.cpp: Added.
(WebCore::Style::SharingResolver::SharingResolver):
(WebCore::Style::parentElementPreventsSharing):
(WebCore::Style::elementHasDirectionAuto):
(WebCore::Style::SharingResolver::searchSimilar):
(WebCore::Style::SharingResolver::findSibling):
(WebCore::Style::SharingResolver::locateCousinList):
(WebCore::Style::canShareStyleWithControl):
(WebCore::Style::SharingResolver::canShareStyleWithElement):
(WebCore::Style::SharingResolver::styleSharingCandidateMatchesRuleSet):
(WebCore::Style::SharingResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
(WebCore::Style::SharingResolver::classNamesAffectedByRules):
* style/StyleSharingResolver.h: Added.
* style/StyleTreeResolver.cpp:
(WebCore::Style::ensurePlaceholderStyle):
(WebCore::Style::TreeResolver::TreeResolver):
(WebCore::Style::TreeResolver::styleForElement):
Try to use SharingResolver first.
Also move placeholder style handling here, it is only relevant when resolving document style.
(WebCore::Style::postResolutionCallbacksAreSuspended):
(WebCore::Style::isPlaceholderStyle):
* style/StyleTreeResolver.h:
* svg/SVGElement.cpp:
(WebCore::SVGElement::customStyleForRenderer):
* svg/SVGElementRareData.h:
(WebCore::SVGElementRareData::overrideComputedStyle):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorcpp">trunk/Source/WebCore/css/ElementRuleCollector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorh">trunk/Source/WebCore/css/ElementRuleCollector.h</a></li>
<li><a href="#trunkSourceWebCorecssMediaQueryMatchercpp">trunk/Source/WebCore/css/MediaQueryMatcher.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleMediacpp">trunk/Source/WebCore/css/StyleMedia.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolverh">trunk/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#trunkSourceWebCoredomVisitedLinkStatecpp">trunk/Source/WebCore/dom/VisitedLinkState.cpp</a></li>
<li><a href="#trunkSourceWebCoredomVisitedLinkStateh">trunk/Source/WebCore/dom/VisitedLinkState.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLFormControlElementh">trunk/Source/WebCore/html/HTMLFormControlElement.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderElementcpp">trunk/Source/WebCore/rendering/RenderElement.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderNamedFlowFragmentcpp">trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingstyleRenderStylecpp">trunk/Source/WebCore/rendering/style/RenderStyle.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleTreeResolvercpp">trunk/Source/WebCore/style/StyleTreeResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleTreeResolverh">trunk/Source/WebCore/style/StyleTreeResolver.h</a></li>
<li><a href="#trunkSourceWebCoresvgSVGElementcpp">trunk/Source/WebCore/svg/SVGElement.cpp</a></li>
<li><a href="#trunkSourceWebCoresvgSVGElementRareDatah">trunk/Source/WebCore/svg/SVGElementRareData.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorestyleStyleSharingResolvercpp">trunk/Source/WebCore/style/StyleSharingResolver.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleSharingResolverh">trunk/Source/WebCore/style/StyleSharingResolver.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/CMakeLists.txt        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -2639,6 +2639,7 @@
</span><span class="cx"> style/StyleChange.cpp
</span><span class="cx"> style/StyleFontSizeFunctions.cpp
</span><span class="cx"> style/StyleResolveForDocument.cpp
</span><ins>+ style/StyleSharingResolver.cpp
</ins><span class="cx"> style/StyleTreeResolver.cpp
</span><span class="cx">
</span><span class="cx"> svg/SVGAElement.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/ChangeLog        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -1,3 +1,110 @@
</span><ins>+2016-02-02 Antti Koivisto <antti@apple.com>
+
+ Factor style sharing code out of StyleResolver
+ https://bugs.webkit.org/show_bug.cgi?id=153768
+
+ Reviewed by Darin Adler.
+
+ Move the code to a new class, Style::SharingResolver.
+
+ When resolving document style we query the sharing resolver first before using the regular style resolver.
+ Other paths that call style resolver were mostly already disabling it with DisallowStyleSharing flag.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * css/ElementRuleCollector.cpp:
+ (WebCore::MatchRequest::MatchRequest):
+ (WebCore::ElementRuleCollector::matchAllRules):
+ (WebCore::ElementRuleCollector::hasAnyMatchingRules):
+
+ More const.
+
+ * css/ElementRuleCollector.h:
+ (WebCore::ElementRuleCollector::setRegionForStyling):
+ (WebCore::ElementRuleCollector::setMedium):
+ * css/MediaQueryMatcher.cpp:
+ (WebCore::MediaQueryMatcher::prepareEvaluator):
+ * css/StyleMedia.cpp:
+ (WebCore::StyleMedia::matchMedium):
+ * css/StyleResolver.cpp:
+ (WebCore::StyleResolver::State::cacheBorderAndBackground):
+ (WebCore::StyleResolver::StyleResolver):
+ (WebCore::StyleResolver::sweepMatchedPropertiesCache):
+ (WebCore::StyleResolver::State::State):
+ (WebCore::StyleResolver::State::setStyle):
+ (WebCore::isAtShadowBoundary):
+ (WebCore::StyleResolver::styleForElement):
+ (WebCore::StyleResolver::classNamesAffectedByRules): Deleted.
+ (WebCore::parentElementPreventsSharing): Deleted.
+ (WebCore::StyleResolver::locateCousinList): Deleted.
+ (WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet): Deleted.
+ (WebCore::StyleResolver::canShareStyleWithControl): Deleted.
+ (WebCore::elementHasDirectionAuto): Deleted.
+ (WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes): Deleted.
+ (WebCore::StyleResolver::canShareStyleWithElement): Deleted.
+ (WebCore::StyleResolver::findSiblingForStyleSharing): Deleted.
+ (WebCore::StyleResolver::locateSharedStyle): Deleted.
+
+ Style sharing code moves to SharingResolver.
+
+ * css/StyleResolver.h:
+ (WebCore::StyleResolver::mediaQueryEvaluator):
+ (WebCore::StyleResolver::State::regionForStyling):
+ (WebCore::StyleResolver::State::elementLinkState):
+ (WebCore::StyleResolver::State::setApplyPropertyToRegularStyle):
+ (WebCore::StyleResolver::State::setApplyPropertyToVisitedLinkStyle):
+ (WebCore::StyleResolver::state):
+ (WebCore::StyleResolver::setTextOrientation):
+ (WebCore::StyleResolver::State::setElementAffectedByClassRules): Deleted.
+ (WebCore::StyleResolver::State::elementAffectedByClassRules): Deleted.
+ (WebCore::StyleResolver::styleNotYetAvailable): Deleted.
+
+ Placeholder code moves to TreeResolver.
+
+ * dom/VisitedLinkState.cpp:
+ (WebCore::linkAttribute):
+ (WebCore::VisitedLinkState::invalidateStyleForAllLinks):
+ (WebCore::linkHashForElement):
+ (WebCore::VisitedLinkState::invalidateStyleForLink):
+ (WebCore::VisitedLinkState::determineLinkStateSlowCase):
+ * dom/VisitedLinkState.h:
+ (WebCore::VisitedLinkState::determineLinkState):
+ * html/HTMLFormControlElement.h:
+ * rendering/RenderElement.cpp:
+ (WebCore::RenderElement::getUncachedPseudoStyle):
+ * rendering/RenderNamedFlowFragment.cpp:
+ (WebCore::RenderNamedFlowFragment::computeStyleInRegion):
+ * rendering/style/RenderStyle.cpp:
+ (WebCore::RenderStyle::isStyleAvailable):
+ (WebCore::RenderStyle::hasUniquePseudoStyle):
+ * style/StyleSharingResolver.cpp: Added.
+ (WebCore::Style::SharingResolver::SharingResolver):
+ (WebCore::Style::parentElementPreventsSharing):
+ (WebCore::Style::elementHasDirectionAuto):
+ (WebCore::Style::SharingResolver::searchSimilar):
+ (WebCore::Style::SharingResolver::findSibling):
+ (WebCore::Style::SharingResolver::locateCousinList):
+ (WebCore::Style::canShareStyleWithControl):
+ (WebCore::Style::SharingResolver::canShareStyleWithElement):
+ (WebCore::Style::SharingResolver::styleSharingCandidateMatchesRuleSet):
+ (WebCore::Style::SharingResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
+ (WebCore::Style::SharingResolver::classNamesAffectedByRules):
+ * style/StyleSharingResolver.h: Added.
+ * style/StyleTreeResolver.cpp:
+ (WebCore::Style::ensurePlaceholderStyle):
+ (WebCore::Style::TreeResolver::TreeResolver):
+ (WebCore::Style::TreeResolver::styleForElement):
+
+ Try to use SharingResolver first.
+ Also move placeholder style handling here, it is only relevant when resolving document style.
+
+ (WebCore::Style::postResolutionCallbacksAreSuspended):
+ (WebCore::Style::isPlaceholderStyle):
+ * style/StyleTreeResolver.h:
+ * svg/SVGElement.cpp:
+ (WebCore::SVGElement::customStyleForRenderer):
+ * svg/SVGElementRareData.h:
+ (WebCore::SVGElementRareData::overrideComputedStyle):
+
</ins><span class="cx"> 2016-02-02 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> <attachment> icon should be a folder for the custom MIME type multipart/x-folder
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -19245,6 +19245,7 @@
</span><span class="cx"> <ClCompile Include="..\style\StyleChange.cpp" />
</span><span class="cx"> <ClCompile Include="..\style\StyleFontSizeFunctions.cpp" />
</span><span class="cx"> <ClCompile Include="..\style\StyleResolveForDocument.cpp" />
</span><ins>+ <ClCompile Include="..\style\StyleSharingResolver.cpp" />
</ins><span class="cx"> <ClCompile Include="..\style\StyleTreeResolver.cpp" />
</span><span class="cx"> <ClCompile Include="..\bridge\jsc\BridgeJSC.cpp" />
</span><span class="cx"> <ClCompile Include="..\bridge\c\c_class.cpp" />
</span><span class="lines">@@ -22812,6 +22813,7 @@
</span><span class="cx"> <ClInclude Include="..\style\StyleChange.h" />
</span><span class="cx"> <ClInclude Include="..\style\StyleFontSizeFunctions.h" />
</span><span class="cx"> <ClInclude Include="..\style\StyleResolveForDocument.h" />
</span><ins>+ <ClInclude Include="..\style\StyleSharingResolver.h" />
</ins><span class="cx"> <ClInclude Include="..\style\StyleTreeResolver.h" />
</span><span class="cx"> <ClInclude Include="..\bridge\Bridge.h" />
</span><span class="cx"> <ClInclude Include="..\bridge\jsc\BridgeJSC.h" />
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -6588,6 +6588,8 @@
</span><span class="cx">                 E47127CB163438AE00ED6F5A /* StyleInvalidationAnalysis.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */; };
</span><span class="cx">                 E4778B7F115A581A00B5D372 /* JSCustomEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */; };
</span><span class="cx">                 E4778B80115A581A00B5D372 /* JSCustomEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E4778B7E115A581A00B5D372 /* JSCustomEvent.h */; };
</span><ins>+                E47A3AC31C5EABBE00CCBFA7 /* StyleSharingResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */; };
+                E47A3AC61C5EAC9D00CCBFA7 /* StyleSharingResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A3AC41C5EAC7900CCBFA7 /* StyleSharingResolver.h */; };
</ins><span class="cx">                 E47B4BE80E71241600038854 /* CachedResourceHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = E47B4BE60E71241600038854 /* CachedResourceHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 E47B4BE90E71241600038854 /* CachedResourceHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */; };
</span><span class="cx">                 E47E276516036ED200EE2AFB /* ExtensionStyleSheets.h in Headers */ = {isa = PBXBuildFile; fileRef = E47E276416036ED200EE2AFB /* ExtensionStyleSheets.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -14553,6 +14555,8 @@
</span><span class="cx">                 E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementChildIterator.h; sourceTree = "<group>"; };
</span><span class="cx">                 E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomEvent.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 E4778B7E115A581A00B5D372 /* JSCustomEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomEvent.h; sourceTree = "<group>"; };
</span><ins>+                E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSharingResolver.cpp; sourceTree = "<group>"; };
+                E47A3AC41C5EAC7900CCBFA7 /* StyleSharingResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSharingResolver.h; sourceTree = "<group>"; };
</ins><span class="cx">                 E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleInvalidationAnalysis.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleInvalidationAnalysis.h; sourceTree = "<group>"; };
</span><span class="cx">                 E47B4BE60E71241600038854 /* CachedResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedResourceHandle.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -23342,6 +23346,8 @@
</span><span class="cx">                                 E4D58EB317B4DBDC00CBDCA8 /* StyleResolveForDocument.h */,
</span><span class="cx">                                 E4DEAA1517A93DC3000E0430 /* StyleTreeResolver.cpp */,
</span><span class="cx">                                 E4DEAA1617A93DC3000E0430 /* StyleTreeResolver.h */,
</span><ins>+                                E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */,
+                                E47A3AC41C5EAC7900CCBFA7 /* StyleSharingResolver.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = style;
</span><span class="cx">                         sourceTree = "<group>";
</span><span class="lines">@@ -26896,6 +26902,7 @@
</span><span class="cx">                                 44A28AAF12DFB8BF00AE923B /* MathMLNames.h in Headers */,
</span><span class="cx">                                 439046E012DA25E17BAF80A2 /* MathMLOperatorDictionary.h in Headers */,
</span><span class="cx">                                 FA654A6C1108ABED002615E0 /* MathMLTextElement.h in Headers */,
</span><ins>+                                E47A3AC61C5EAC9D00CCBFA7 /* StyleSharingResolver.h in Headers */,
</ins><span class="cx">                                 49D5DC2C0F423A73008F20FD /* Matrix3DTransformOperation.h in Headers */,
</span><span class="cx">                                 49E911C70EF86D47009D0CAF /* MatrixTransformOperation.h in Headers */,
</span><span class="cx">                                 5CBC8DAD1AAA302200E1C803 /* MediaAccessibilitySoftLink.h in Headers */,
</span><span class="lines">@@ -30091,6 +30098,7 @@
</span><span class="cx">                                 A80E7E9A0A1A83E3007FB8C5 /* JSHTMLOptionElement.cpp in Sources */,
</span><span class="cx">                                 448A29C00A46D9CB0030759F /* JSHTMLOptionsCollection.cpp in Sources */,
</span><span class="cx">                                 448AD27C0A48137A0023D179 /* JSHTMLOptionsCollectionCustom.cpp in Sources */,
</span><ins>+                                E47A3AC31C5EABBE00CCBFA7 /* StyleSharingResolver.cpp in Sources */,
</ins><span class="cx">                                 4AD0173C127E82860015035F /* JSHTMLOutputElement.cpp in Sources */,
</span><span class="cx">                                 1AE2ABA60A1CE90500B42B25 /* JSHTMLParagraphElement.cpp in Sources */,
</span><span class="cx">                                 1AE2ABA80A1CE90500B42B25 /* JSHTMLParamElement.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -68,7 +68,7 @@
</span><span class="cx">
</span><span class="cx"> class MatchRequest {
</span><span class="cx"> public:
</span><del>- MatchRequest(RuleSet* ruleSet, bool includeEmptyRules = false)
</del><ins>+ MatchRequest(const RuleSet* ruleSet, bool includeEmptyRules = false)
</ins><span class="cx"> : ruleSet(ruleSet)
</span><span class="cx"> , includeEmptyRules(includeEmptyRules)
</span><span class="cx"> {
</span><span class="lines">@@ -529,7 +529,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet)
</del><ins>+bool ElementRuleCollector::hasAnyMatchingRules(const RuleSet* ruleSet)
</ins><span class="cx"> {
</span><span class="cx"> clearMatchedRules();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx"> void setRegionForStyling(const RenderRegion* regionForStyling) { m_regionForStyling = regionForStyling; }
</span><span class="cx"> void setMedium(const MediaQueryEvaluator* medium) { m_isPrintStyle = medium->mediaTypeMatchSpecific("print"); }
</span><span class="cx">
</span><del>- bool hasAnyMatchingRules(RuleSet*);
</del><ins>+ bool hasAnyMatchingRules(const RuleSet*);
</ins><span class="cx">
</span><span class="cx"> StyleResolver::MatchResult& matchedResult();
</span><span class="cx"> const Vector<RefPtr<StyleRule>>& matchedRuleList() const;
</span></span></pre></div>
<a id="trunkSourceWebCorecssMediaQueryMatchercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/MediaQueryMatcher.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/MediaQueryMatcher.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/MediaQueryMatcher.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -85,7 +85,7 @@
</span><span class="cx"> if (!documentElement)
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><del>- RefPtr<RenderStyle> rootStyle = m_document->ensureStyleResolver().styleForElement(*documentElement, m_document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
</del><ins>+ RefPtr<RenderStyle> rootStyle = m_document->ensureStyleResolver().styleForElement(*documentElement, m_document->renderStyle(), MatchOnlyUserAgentRules);
</ins><span class="cx">
</span><span class="cx"> return std::make_unique<MediaQueryEvaluator>(mediaType(), m_document->frame(), rootStyle.get());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleMediacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleMedia.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleMedia.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/StyleMedia.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx"> if (!documentElement)
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- RefPtr<RenderStyle> rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
</del><ins>+ RefPtr<RenderStyle> rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), MatchOnlyUserAgentRules);
</ins><span class="cx">
</span><span class="cx"> RefPtr<MediaQuerySet> media = MediaQuerySet::create();
</span><span class="cx"> if (!media->parse(query))
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -176,8 +176,6 @@
</span><span class="cx">
</span><span class="cx"> static void extractDirectionAndWritingMode(const RenderStyle&, const StyleResolver::MatchResult&, TextDirection&, WritingMode&);
</span><span class="cx">
</span><del>-RenderStyle* StyleResolver::s_styleNotYetAvailable;
-
</del><span class="cx"> inline void StyleResolver::State::cacheBorderAndBackground()
</span><span class="cx"> {
</span><span class="cx"> m_hasUAAppearance = m_style->hasAppearance();
</span><span class="lines">@@ -264,7 +262,7 @@
</span><span class="cx"> m_medium = std::make_unique<MediaQueryEvaluator>("all");
</span><span class="cx">
</span><span class="cx"> if (root)
</span><del>- m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
</del><ins>+ m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), MatchOnlyUserAgentRules);
</ins><span class="cx">
</span><span class="cx"> if (m_rootDefaultStyle && view)
</span><span class="cx"> m_medium = std::make_unique<MediaQueryEvaluator>(view->mediaType(), &view->frame(), m_rootDefaultStyle.get());
</span><span class="lines">@@ -332,15 +330,6 @@
</span><span class="cx"> m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool StyleResolver::classNamesAffectedByRules(const SpaceSplitString& classNames) const
-{
- for (unsigned i = 0; i < classNames.size(); ++i) {
- if (m_ruleSets.features().classesInRules.contains(classNames[i].impl()))
- return true;
- }
- return false;
-}
-
</del><span class="cx"> StyleResolver::State::State(Element& element, RenderStyle* parentStyle, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
</span><span class="cx"> : m_element(&element)
</span><span class="cx"> , m_parentStyle(parentStyle)
</span><span class="lines">@@ -369,305 +358,6 @@
</span><span class="cx"> m_style = WTFMove(style);
</span><span class="cx"> updateConversionData();
</span><span class="cx"> }
</span><del>-
-static const unsigned cStyleSearchThreshold = 10;
-static const unsigned cStyleSearchLevelThreshold = 10;
-
-static inline bool parentElementPreventsSharing(const Element* parentElement)
-{
- if (!parentElement)
- return false;
- return parentElement->hasFlagsSetDuringStylingOfChildren();
-}
-
-Node* StyleResolver::locateCousinList(Element* parent, unsigned& visitedNodeCount) const
-{
- if (visitedNodeCount >= cStyleSearchThreshold * cStyleSearchLevelThreshold)
- return nullptr;
- if (!is<StyledElement>(parent))
- return nullptr;
- StyledElement* styledParent = downcast<StyledElement>(parent);
- if (styledParent->inlineStyle())
- return nullptr;
- if (is<SVGElement>(*styledParent) && downcast<SVGElement>(*styledParent).animatedSMILStyleProperties())
- return nullptr;
- if (styledParent->hasID() && m_ruleSets.features().idsInRules.contains(styledParent->idForStyleResolution().impl()))
- return nullptr;
-
- RenderStyle* parentStyle = styledParent->renderStyle();
- unsigned subcount = 0;
- Node* thisCousin = styledParent;
- Node* currentNode = styledParent->previousSibling();
-
- // Reserve the tries for this level. This effectively makes sure that the algorithm
- // will never go deeper than cStyleSearchLevelThreshold levels into recursion.
- visitedNodeCount += cStyleSearchThreshold;
- while (thisCousin) {
- while (currentNode) {
- ++subcount;
- if (currentNode->renderStyle() == parentStyle && currentNode->lastChild()
- && is<Element>(*currentNode) && !parentElementPreventsSharing(downcast<Element>(currentNode))
- ) {
- // Adjust for unused reserved tries.
- visitedNodeCount -= cStyleSearchThreshold - subcount;
- return currentNode->lastChild();
- }
- if (subcount >= cStyleSearchThreshold)
- return nullptr;
- currentNode = currentNode->previousSibling();
- }
- currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeCount);
- thisCousin = currentNode;
- }
-
- return nullptr;
-}
-
-bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet)
-{
- if (!ruleSet)
- return false;
-
- ElementRuleCollector collector(*m_state.element(), m_state.style(), m_ruleSets, m_state.selectorFilter());
- return collector.hasAnyMatchingRules(ruleSet);
-}
-
-bool StyleResolver::canShareStyleWithControl(StyledElement& element) const
-{
- const State& state = m_state;
- if (!is<HTMLInputElement>(element) || !is<HTMLInputElement>(*state.element()))
- return false;
-
- auto& thisInputElement = downcast<HTMLInputElement>(element);
- auto& otherInputElement = downcast<HTMLInputElement>(*state.element());
-
- if (thisInputElement.isAutoFilled() != otherInputElement.isAutoFilled())
- return false;
- if (thisInputElement.shouldAppearChecked() != otherInputElement.shouldAppearChecked())
- return false;
- if (thisInputElement.shouldAppearIndeterminate() != otherInputElement.shouldAppearIndeterminate())
- return false;
- if (thisInputElement.isRequired() != otherInputElement.isRequired())
- return false;
-
- if (element.isDisabledFormControl() != state.element()->isDisabledFormControl())
- return false;
-
- if (element.isDefaultButtonForForm() != state.element()->isDefaultButtonForForm())
- return false;
-
- if (element.isInRange() != state.element()->isInRange())
- return false;
-
- if (element.isOutOfRange() != state.element()->isOutOfRange())
- return false;
-
- return true;
-}
-
-static inline bool elementHasDirectionAuto(Element& element)
-{
- // FIXME: This line is surprisingly hot, we may wish to inline hasDirectionAuto into StyleResolver.
- return is<HTMLElement>(element) && downcast<HTMLElement>(element).hasDirectionAuto();
-}
-
-bool StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement& sharingCandidate) const
-{
- const State& state = m_state;
- if (state.element()->elementData() == sharingCandidate.elementData())
- return true;
- if (state.element()->fastGetAttribute(XMLNames::langAttr) != sharingCandidate.fastGetAttribute(XMLNames::langAttr))
- return false;
- if (state.element()->fastGetAttribute(langAttr) != sharingCandidate.fastGetAttribute(langAttr))
- return false;
-
- if (!state.elementAffectedByClassRules()) {
- if (sharingCandidate.hasClass() && classNamesAffectedByRules(sharingCandidate.classNames()))
- return false;
- } else if (sharingCandidate.hasClass()) {
- // SVG elements require a (slow!) getAttribute comparision because "class" is an animatable attribute for SVG.
- if (state.element()->isSVGElement()) {
- if (state.element()->getAttribute(classAttr) != sharingCandidate.getAttribute(classAttr))
- return false;
- } else {
- if (state.element()->classNames() != sharingCandidate.classNames())
- return false;
- }
- } else
- return false;
-
- if (downcast<StyledElement>(*state.element()).presentationAttributeStyle() != sharingCandidate.presentationAttributeStyle())
- return false;
-
- if (state.element()->hasTagName(progressTag)) {
- if (state.element()->shouldAppearIndeterminate() != sharingCandidate.shouldAppearIndeterminate())
- return false;
- }
-
- return true;
-}
-
-bool StyleResolver::canShareStyleWithElement(StyledElement& element) const
-{
- auto* style = element.renderStyle();
- const State& state = m_state;
-
- if (!style)
- return false;
- if (style->unique())
- return false;
- if (style->hasUniquePseudoStyle())
- return false;
- if (element.tagQName() != state.element()->tagQName())
- return false;
- if (element.inlineStyle())
- return false;
- if (element.needsStyleRecalc())
- return false;
- if (element.isSVGElement() && downcast<SVGElement>(element).animatedSMILStyleProperties())
- return false;
- if (element.isLink() != state.element()->isLink())
- return false;
- if (element.hovered() != state.element()->hovered())
- return false;
- if (element.active() != state.element()->active())
- return false;
- if (element.focused() != state.element()->focused())
- return false;
- if (element.shadowPseudoId() != state.element()->shadowPseudoId())
- return false;
- if (&element == element.document().cssTarget())
- return false;
- if (!sharingCandidateHasIdenticalStyleAffectingAttributes(element))
- return false;
- if (element.additionalPresentationAttributeStyle() != downcast<StyledElement>(*state.element()).additionalPresentationAttributeStyle())
- return false;
- if (element.affectsNextSiblingElementStyle() || element.styleIsAffectedByPreviousSibling())
- return false;
-
- if (element.hasID() && m_ruleSets.features().idsInRules.contains(element.idForStyleResolution().impl()))
- return false;
-
- bool isControl = is<HTMLFormControlElement>(element);
-
- if (isControl != is<HTMLFormControlElement>(*state.element()))
- return false;
-
- if (isControl && !canShareStyleWithControl(element))
- return false;
-
- if (style->transitions() || style->animations())
- return false;
-
- // Turn off style sharing for elements that can gain layers for reasons outside of the style system.
- // See comments in RenderObject::setStyle().
- if (element.hasTagName(iframeTag) || element.hasTagName(frameTag) || element.hasTagName(embedTag) || element.hasTagName(objectTag) || element.hasTagName(appletTag) || element.hasTagName(canvasTag))
- return false;
-
- if (elementHasDirectionAuto(element))
- return false;
-
- if (element.isLink() && state.elementLinkState() != style->insideLink())
- return false;
-
- if (element.elementData() != state.element()->elementData()) {
- if (element.fastGetAttribute(readonlyAttr) != state.element()->fastGetAttribute(readonlyAttr))
- return false;
- if (element.isSVGElement()) {
- if (element.getAttribute(typeAttr) != state.element()->getAttribute(typeAttr))
- return false;
- } else {
- if (element.fastGetAttribute(typeAttr) != state.element()->fastGetAttribute(typeAttr))
- return false;
- }
- }
-
- if (element.matchesValidPseudoClass() != state.element()->matchesValidPseudoClass())
- return false;
-
- if (element.matchesInvalidPseudoClass() != state.element()->matchesValidPseudoClass())
- return false;
-
-#if ENABLE(VIDEO_TRACK)
- // Deny sharing styles between WebVTT and non-WebVTT nodes.
- if (is<WebVTTElement>(*state.element()))
- return false;
-#endif
-
-#if ENABLE(FULLSCREEN_API)
- if (&element == element.document().webkitCurrentFullScreenElement() || state.element() == state.document().webkitCurrentFullScreenElement())
- return false;
-#endif
- return true;
-}
-
-inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsigned& count) const
-{
- for (; node; node = node->previousSibling()) {
- if (!is<StyledElement>(*node))
- continue;
- if (canShareStyleWithElement(downcast<StyledElement>(*node)))
- break;
- if (count++ == cStyleSearchThreshold)
- return nullptr;
- }
- return downcast<StyledElement>(node);
-}
-
-RenderStyle* StyleResolver::locateSharedStyle()
-{
- State& state = m_state;
- if (!is<StyledElement>(state.element()) || !state.parentStyle())
- return nullptr;
- auto& styledElement = downcast<StyledElement>(*state.element());
-
- // If the element has inline style it is probably unique.
- if (styledElement.inlineStyle())
- return nullptr;
- if (styledElement.isSVGElement() && downcast<SVGElement>(styledElement).animatedSMILStyleProperties())
- return nullptr;
- // Ids stop style sharing if they show up in the stylesheets.
- if (styledElement.hasID() && m_ruleSets.features().idsInRules.contains(styledElement.idForStyleResolution().impl()))
- return nullptr;
- if (parentElementPreventsSharing(styledElement.parentElement()))
- return nullptr;
- if (state.element() == state.document().cssTarget())
- return nullptr;
- if (elementHasDirectionAuto(*state.element()))
- return nullptr;
-
- // Cache whether state.element is affected by any known class selectors.
- // FIXME: This shouldn't be a member variable. The style sharing code could be factored out of StyleResolver.
- state.setElementAffectedByClassRules(state.element() && state.element()->hasClass() && classNamesAffectedByRules(state.element()->classNames()));
-
- // Check previous siblings and their cousins.
- unsigned count = 0;
- unsigned visitedNodeCount = 0;
- StyledElement* shareElement = nullptr;
- Node* cousinList = styledElement.previousSibling();
- while (cousinList) {
- shareElement = findSiblingForStyleSharing(cousinList, count);
- if (shareElement)
- break;
- cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCount);
- }
-
- // If we have exhausted all our budget or our cousins.
- if (!shareElement)
- return nullptr;
-
- // Can't share if sibling rules apply. This is checked at the end as it should rarely fail.
- if (styleSharingCandidateMatchesRuleSet(m_ruleSets.sibling()))
- return nullptr;
- // Can't share if attribute rules apply.
- if (styleSharingCandidateMatchesRuleSet(m_ruleSets.uncommonAttribute()))
- return nullptr;
- // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
- if (parentElementPreventsSharing(styledElement.parentElement()))
- return nullptr;
- return shareElement->renderStyle();
-}
-
</del><span class="cx"> static inline bool isAtShadowBoundary(const Element* element)
</span><span class="cx"> {
</span><span class="cx"> if (!element)
</span><span class="lines">@@ -676,33 +366,13 @@
</span><span class="cx"> return parentNode && parentNode->isShadowRoot();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-Ref<RenderStyle> StyleResolver::styleForElement(Element& element, RenderStyle* parentStyle,
- StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
</del><ins>+Ref<RenderStyle> StyleResolver::styleForElement(Element& element, RenderStyle* parentStyle, RuleMatchingBehavior matchingBehavior, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
</ins><span class="cx"> {
</span><span class="cx"> RELEASE_ASSERT(!m_inLoadPendingImages);
</span><span class="cx">
</span><del>- // Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
- // will vanish if a style recalc happens during loading.
- if (sharingBehavior == AllowStyleSharing && !m_document.haveStylesheetsLoaded() && !element.renderer()) {
- if (!s_styleNotYetAvailable) {
- s_styleNotYetAvailable = &RenderStyle::create().leakRef();
- s_styleNotYetAvailable->setDisplay(NONE);
- s_styleNotYetAvailable->fontCascade().update(&m_document.fontSelector());
- }
- m_document.setHasNodesWithPlaceholderStyle();
- return *s_styleNotYetAvailable;
- }
-
</del><span class="cx"> m_state = State(element, parentStyle, regionForStyling, selectorFilter);
</span><span class="cx"> State& state = m_state;
</span><span class="cx">
</span><del>- if (sharingBehavior == AllowStyleSharing) {
- if (RenderStyle* sharedStyle = locateSharedStyle()) {
- state.clear();
- return *sharedStyle;
- }
- }
-
</del><span class="cx"> if (state.parentStyle()) {
</span><span class="cx"> state.setStyle(RenderStyle::create());
</span><span class="cx"> state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(&element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/css/StyleResolver.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -93,11 +93,6 @@
</span><span class="cx"> class WebKitCSSFilterValue;
</span><span class="cx"> struct ResourceLoaderOptions;
</span><span class="cx">
</span><del>-enum StyleSharingBehavior {
- AllowStyleSharing,
- DisallowStyleSharing,
-};
-
</del><span class="cx"> // MatchOnlyUserAgentRules is used in media queries, where relative units
</span><span class="cx"> // are interpreted according to the document root element style, and styled only
</span><span class="cx"> // from the User Agent Stylesheet rules.
</span><span class="lines">@@ -135,8 +130,7 @@
</span><span class="cx"> StyleResolver(Document&);
</span><span class="cx"> ~StyleResolver();
</span><span class="cx">
</span><del>- Ref<RenderStyle> styleForElement(Element&, RenderStyle* parentStyle, StyleSharingBehavior = AllowStyleSharing,
- RuleMatchingBehavior = MatchAllRules, const RenderRegion* regionForStyling = nullptr, const SelectorFilter* = nullptr);
</del><ins>+ Ref<RenderStyle> styleForElement(Element&, RenderStyle* parentStyle, RuleMatchingBehavior = MatchAllRules, const RenderRegion* regionForStyling = nullptr, const SelectorFilter* = nullptr);
</ins><span class="cx">
</span><span class="cx"> void keyframeStylesForAnimation(Element&, const RenderStyle*, KeyframeList&);
</span><span class="cx">
</span><span class="lines">@@ -160,12 +154,6 @@
</span><span class="cx"> const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- RenderStyle* locateSharedStyle();
- bool styleSharingCandidateMatchesRuleSet(RuleSet*);
- Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
- StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
- bool canShareStyleWithElement(StyledElement&) const;
-
</del><span class="cx"> Ref<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
</span><span class="cx">
</span><span class="cx"> public:
</span><span class="lines">@@ -378,8 +366,6 @@
</span><span class="cx">
</span><span class="cx"> const RenderRegion* regionForStyling() const { return m_regionForStyling; }
</span><span class="cx"> EInsideLink elementLinkState() const { return m_elementLinkState; }
</span><del>- void setElementAffectedByClassRules(bool isAffected) { m_elementAffectedByClassRules = isAffected; }
- bool elementAffectedByClassRules() const { return m_elementAffectedByClassRules; }
</del><span class="cx">
</span><span class="cx"> void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
</span><span class="cx"> void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
</span><span class="lines">@@ -435,7 +421,6 @@
</span><span class="cx">
</span><span class="cx"> EInsideLink m_elementLinkState { NotInsideLink };
</span><span class="cx">
</span><del>- bool m_elementAffectedByClassRules { false };
</del><span class="cx"> bool m_applyPropertyToRegularStyle { true };
</span><span class="cx"> bool m_applyPropertyToVisitedLinkStyle { false };
</span><span class="cx"> bool m_fontDirty { false };
</span><span class="lines">@@ -459,8 +444,6 @@
</span><span class="cx">
</span><span class="cx"> State& state() { return m_state; }
</span><span class="cx">
</span><del>- static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
-
</del><span class="cx"> PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue&);
</span><span class="cx"> PassRefPtr<StyleImage> cachedOrPendingFromValue(CSSPropertyID, CSSImageValue&);
</span><span class="cx"> PassRefPtr<StyleImage> generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue&);
</span><span class="lines">@@ -488,12 +471,8 @@
</span><span class="cx"> void setTextOrientation(TextOrientation textOrientation) { m_state.setTextOrientation(textOrientation); }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- static RenderStyle* s_styleNotYetAvailable;
-
</del><span class="cx"> void cacheBorderAndBackground();
</span><span class="cx">
</span><del>- bool canShareStyleWithControl(StyledElement&) const;
-
</del><span class="cx"> void applyProperty(CSSPropertyID, CSSValue*, SelectorChecker::LinkMatchMask = SelectorChecker::MatchDefault, const MatchResult* = nullptr);
</span><span class="cx"> RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSVariableDependentValue&);
</span><span class="cx">
</span><span class="lines">@@ -520,9 +499,6 @@
</span><span class="cx"> // the last reference to a style declaration are garbage collected.
</span><span class="cx"> void sweepMatchedPropertiesCache();
</span><span class="cx">
</span><del>- bool classNamesAffectedByRules(const SpaceSplitString&) const;
- bool sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement&) const;
-
</del><span class="cx"> unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep;
</span><span class="cx">
</span><span class="cx"> typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
</span></span></pre></div>
<a id="trunkSourceWebCoredomVisitedLinkStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/VisitedLinkState.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/VisitedLinkState.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/dom/VisitedLinkState.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx">
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx">
</span><del>-inline static const AtomicString* linkAttribute(Element& element)
</del><ins>+inline static const AtomicString* linkAttribute(const Element& element)
</ins><span class="cx"> {
</span><span class="cx"> if (!element.isLink())
</span><span class="cx"> return 0;
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-inline static LinkHash linkHashForElement(Document& document, Element& element)
</del><ins>+inline static LinkHash linkHashForElement(Document& document, const Element& element)
</ins><span class="cx"> {
</span><span class="cx"> if (is<HTMLAnchorElement>(element))
</span><span class="cx"> return downcast<HTMLAnchorElement>(element).visitedLinkHash();
</span><span class="lines">@@ -86,7 +86,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-EInsideLink VisitedLinkState::determineLinkStateSlowCase(Element& element)
</del><ins>+EInsideLink VisitedLinkState::determineLinkStateSlowCase(const Element& element)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(element.isLink());
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomVisitedLinkStateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/VisitedLinkState.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/VisitedLinkState.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/dom/VisitedLinkState.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -45,16 +45,16 @@
</span><span class="cx">
</span><span class="cx"> void invalidateStyleForAllLinks();
</span><span class="cx"> void invalidateStyleForLink(LinkHash);
</span><del>- EInsideLink determineLinkState(Element&);
</del><ins>+ EInsideLink determineLinkState(const Element&);
</ins><span class="cx">
</span><span class="cx"> private:
</span><del>- EInsideLink determineLinkStateSlowCase(Element&);
</del><ins>+ EInsideLink determineLinkStateSlowCase(const Element&);
</ins><span class="cx">
</span><span class="cx"> Document& m_document;
</span><span class="cx"> HashSet<LinkHash, LinkHashHash> m_linksCheckedForVisitedState;
</span><span class="cx"> };
</span><span class="cx">
</span><del>-inline EInsideLink VisitedLinkState::determineLinkState(Element& element)
</del><ins>+inline EInsideLink VisitedLinkState::determineLinkState(const Element& element)
</ins><span class="cx"> {
</span><span class="cx"> if (!element.isLink())
</span><span class="cx"> return NotInsideLink;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLFormControlElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLFormControlElement.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -71,6 +71,7 @@
</span><span class="cx"> void dispatchFormControlInputEvent();
</span><span class="cx">
</span><span class="cx"> virtual bool isDisabledFormControl() const override;
</span><ins>+ virtual bool isDefaultButtonForForm() const override;
</ins><span class="cx">
</span><span class="cx"> virtual bool isFocusable() const override;
</span><span class="cx"> virtual bool isEnumeratable() const override { return false; }
</span><span class="lines">@@ -168,7 +169,6 @@
</span><span class="cx"> virtual short tabIndex() const override final;
</span><span class="cx">
</span><span class="cx"> virtual HTMLFormElement* virtualForm() const override;
</span><del>- virtual bool isDefaultButtonForForm() const override;
</del><span class="cx"> bool isValidFormControlElement() const;
</span><span class="cx">
</span><span class="cx"> bool computeIsDisabledByFieldsetAncestor() const;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderElement.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -1590,7 +1590,7 @@
</span><span class="cx"> auto& styleResolver = element()->styleResolver();
</span><span class="cx">
</span><span class="cx"> if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
</span><del>- RefPtr<RenderStyle> result = styleResolver.styleForElement(*element(), parentStyle, DisallowStyleSharing);
</del><ins>+ RefPtr<RenderStyle> result = styleResolver.styleForElement(*element(), parentStyle);
</ins><span class="cx"> result->setStyleType(FIRST_LINE_INHERITED);
</span><span class="cx"> return result.release();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderNamedFlowFragmentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -352,7 +352,7 @@
</span><span class="cx"> ASSERT(!renderer.isAnonymous());
</span><span class="cx">
</span><span class="cx"> // FIXME: Region styling fails for pseudo-elements because the renderers don't have a node.
</span><del>- RefPtr<RenderStyle> renderObjectRegionStyle = renderer.element()->styleResolver().styleForElement(*renderer.element(), &parentStyle, DisallowStyleSharing, MatchAllRules, this);
</del><ins>+ RefPtr<RenderStyle> renderObjectRegionStyle = renderer.element()->styleResolver().styleForElement(*renderer.element(), &parentStyle, MatchAllRules, this);
</ins><span class="cx">
</span><span class="cx"> return renderObjectRegionStyle.release();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingstyleRenderStylecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> #include "StyleResolver.h"
</span><span class="cx"> #include "StyleScrollSnapPoints.h"
</span><span class="cx"> #include "StyleSelfAlignmentData.h"
</span><ins>+#include "StyleTreeResolver.h"
</ins><span class="cx"> #include "WillChangeData.h"
</span><span class="cx"> #include <wtf/MathExtras.h>
</span><span class="cx"> #include <wtf/PointerComparison.h>
</span><span class="lines">@@ -293,7 +294,7 @@
</span><span class="cx">
</span><span class="cx"> bool RenderStyle::isStyleAvailable() const
</span><span class="cx"> {
</span><del>- return this != StyleResolver::styleNotYetAvailable();
</del><ins>+ return !Style::isPlaceholderStyle(*this);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool RenderStyle::hasUniquePseudoStyle() const
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleSharingResolvercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/style/StyleSharingResolver.cpp (0 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleSharingResolver.cpp         (rev 0)
+++ trunk/Source/WebCore/style/StyleSharingResolver.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -0,0 +1,373 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StyleSharingResolver.h"
+
+#include "DocumentRuleSets.h"
+#include "ElementRuleCollector.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "NodeRenderStyle.h"
+#include "RenderStyle.h"
+#include "SVGElement.h"
+#include "StyledElement.h"
+#include "VisitedLinkState.h"
+#include "WebVTTElement.h"
+#include "XMLNames.h"
+
+namespace WebCore {
+namespace Style {
+
+static const unsigned cStyleSearchThreshold = 10;
+static const unsigned cStyleSearchLevelThreshold = 10;
+
+struct SharingResolver::Context {
+ const StyledElement& element;
+ bool elementAffectedByClassRules;
+ EInsideLink elementLinkState;
+};
+
+SharingResolver::SharingResolver(const Document& document, const DocumentRuleSets& ruleSets, const SelectorFilter& selectorFilter)
+ : m_document(document)
+ , m_ruleSets(ruleSets)
+ , m_selectorFilter(selectorFilter)
+{
+}
+
+static inline bool parentElementPreventsSharing(const Element& parentElement)
+{
+ return parentElement.hasFlagsSetDuringStylingOfChildren();
+}
+
+static inline bool elementHasDirectionAuto(const Element& element)
+{
+ // FIXME: This line is surprisingly hot, we may wish to inline hasDirectionAuto into StyleResolver.
+ return is<HTMLElement>(element) && downcast<HTMLElement>(element).hasDirectionAuto();
+}
+
+const Element* SharingResolver::resolve(const Element& searchElement) const
+{
+ if (!is<StyledElement>(searchElement))
+ return nullptr;
+ auto& element = downcast<StyledElement>(searchElement);
+ if (!element.parentElement())
+ return nullptr;
+ auto& parentElement = *element.parentElement();
+ if (!parentElement.renderStyle())
+ return nullptr;
+ // If the element has inline style it is probably unique.
+ if (element.inlineStyle())
+ return nullptr;
+ if (element.isSVGElement() && downcast<SVGElement>(element).animatedSMILStyleProperties())
+ return nullptr;
+ // Ids stop style sharing if they show up in the stylesheets.
+ if (element.hasID() && m_ruleSets.features().idsInRules.contains(element.idForStyleResolution().impl()))
+ return nullptr;
+ if (parentElementPreventsSharing(parentElement))
+ return nullptr;
+ if (&element == m_document.cssTarget())
+ return nullptr;
+ if (elementHasDirectionAuto(element))
+ return nullptr;
+
+ Context context {
+ element,
+ element.hasClass() && classNamesAffectedByRules(element.classNames()),
+ m_document.visitedLinkState().determineLinkState(element)
+ };
+
+ // Check previous siblings and their cousins.
+ unsigned count = 0;
+ unsigned visitedNodeCount = 0;
+ StyledElement* shareElement = nullptr;
+ Node* cousinList = element.previousSibling();
+ while (cousinList) {
+ shareElement = findSibling(context, cousinList, count);
+ if (shareElement)
+ break;
+ cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCount);
+ }
+
+ // If we have exhausted all our budget or our cousins.
+ if (!shareElement)
+ return nullptr;
+
+ // Can't share if sibling rules apply. This is checked at the end as it should rarely fail.
+ if (styleSharingCandidateMatchesRuleSet(element, m_ruleSets.sibling()))
+ return nullptr;
+ // Can't share if attribute rules apply.
+ if (styleSharingCandidateMatchesRuleSet(element, m_ruleSets.uncommonAttribute()))
+ return nullptr;
+ // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
+ if (parentElementPreventsSharing(parentElement))
+ return nullptr;
+
+ return shareElement;
+}
+
+StyledElement* SharingResolver::findSibling(const Context& context, Node* node, unsigned& count) const
+{
+ for (; node; node = node->previousSibling()) {
+ if (!is<StyledElement>(*node))
+ continue;
+ if (canShareStyleWithElement(context, downcast<StyledElement>(*node)))
+ break;
+ if (count++ == cStyleSearchThreshold)
+ return nullptr;
+ }
+ return downcast<StyledElement>(node);
+}
+
+Node* SharingResolver::locateCousinList(Element* parent, unsigned& visitedNodeCount) const
+{
+ if (visitedNodeCount >= cStyleSearchThreshold * cStyleSearchLevelThreshold)
+ return nullptr;
+ if (!is<StyledElement>(parent))
+ return nullptr;
+ auto& styledParent = downcast<StyledElement>(*parent);
+ if (styledParent.inlineStyle())
+ return nullptr;
+ if (is<SVGElement>(styledParent) && downcast<SVGElement>(styledParent).animatedSMILStyleProperties())
+ return nullptr;
+ if (styledParent.hasID() && m_ruleSets.features().idsInRules.contains(styledParent.idForStyleResolution().impl()))
+ return nullptr;
+
+ RenderStyle* parentStyle = styledParent.renderStyle();
+ unsigned subcount = 0;
+ Node* thisCousin = &styledParent;
+ Node* currentNode = styledParent.previousSibling();
+
+ // Reserve the tries for this level. This effectively makes sure that the algorithm
+ // will never go deeper than cStyleSearchLevelThreshold levels into recursion.
+ visitedNodeCount += cStyleSearchThreshold;
+ while (thisCousin) {
+ for (; currentNode; currentNode = currentNode->previousSibling()) {
+ if (++subcount > cStyleSearchThreshold)
+ return nullptr;
+ if (!is<Element>(*currentNode))
+ continue;
+ auto& currentElement = downcast<Element>(*currentNode);
+ if (currentElement.renderStyle() != parentStyle)
+ continue;
+ if (!currentElement.lastChild())
+ continue;
+ if (!parentElementPreventsSharing(currentElement)) {
+ // Adjust for unused reserved tries.
+ visitedNodeCount -= cStyleSearchThreshold - subcount;
+ return currentNode->lastChild();
+ }
+ }
+ currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeCount);
+ thisCousin = currentNode;
+ }
+
+ return nullptr;
+}
+
+static bool canShareStyleWithControl(const HTMLFormControlElement& element, const HTMLFormControlElement& formElement)
+{
+ if (!is<HTMLInputElement>(formElement) || !is<HTMLInputElement>(element))
+ return false;
+
+ auto& thisInputElement = downcast<HTMLInputElement>(formElement);
+ auto& otherInputElement = downcast<HTMLInputElement>(element);
+
+ if (thisInputElement.isAutoFilled() != otherInputElement.isAutoFilled())
+ return false;
+ if (thisInputElement.shouldAppearChecked() != otherInputElement.shouldAppearChecked())
+ return false;
+ if (thisInputElement.shouldAppearIndeterminate() != otherInputElement.shouldAppearIndeterminate())
+ return false;
+ if (thisInputElement.isRequired() != otherInputElement.isRequired())
+ return false;
+
+ if (formElement.isDisabledFormControl() != element.isDisabledFormControl())
+ return false;
+
+ if (formElement.isDefaultButtonForForm() != element.isDefaultButtonForForm())
+ return false;
+
+ if (formElement.isInRange() != element.isInRange())
+ return false;
+
+ if (formElement.isOutOfRange() != element.isOutOfRange())
+ return false;
+
+ return true;
+}
+
+bool SharingResolver::canShareStyleWithElement(const Context& context, const StyledElement& candidateElement) const
+{
+ auto& element = context.element;
+ auto* style = candidateElement.renderStyle();
+ if (!style)
+ return false;
+ if (style->unique())
+ return false;
+ if (style->hasUniquePseudoStyle())
+ return false;
+ if (candidateElement.tagQName() != element.tagQName())
+ return false;
+ if (candidateElement.inlineStyle())
+ return false;
+ if (candidateElement.needsStyleRecalc())
+ return false;
+ if (candidateElement.isSVGElement() && downcast<SVGElement>(candidateElement).animatedSMILStyleProperties())
+ return false;
+ if (candidateElement.isLink() != element.isLink())
+ return false;
+ if (candidateElement.hovered() != element.hovered())
+ return false;
+ if (candidateElement.active() != element.active())
+ return false;
+ if (candidateElement.focused() != element.focused())
+ return false;
+ if (candidateElement.shadowPseudoId() != element.shadowPseudoId())
+ return false;
+ if (&candidateElement == m_document.cssTarget())
+ return false;
+ if (!sharingCandidateHasIdenticalStyleAffectingAttributes(context, candidateElement))
+ return false;
+ if (const_cast<StyledElement&>(candidateElement).additionalPresentationAttributeStyle() != const_cast<StyledElement&>(element).additionalPresentationAttributeStyle())
+ return false;
+ if (candidateElement.affectsNextSiblingElementStyle() || candidateElement.styleIsAffectedByPreviousSibling())
+ return false;
+
+ if (candidateElement.hasID() && m_ruleSets.features().idsInRules.contains(candidateElement.idForStyleResolution().impl()))
+ return false;
+
+ bool isControl = is<HTMLFormControlElement>(candidateElement);
+
+ if (isControl != is<HTMLFormControlElement>(element))
+ return false;
+
+ if (isControl && !canShareStyleWithControl(downcast<HTMLFormControlElement>(element), downcast<HTMLFormControlElement>(candidateElement)))
+ return false;
+
+ if (style->transitions() || style->animations())
+ return false;
+
+ // Turn off style sharing for elements that can gain layers for reasons outside of the style system.
+ // See comments in RenderObject::setStyle().
+ if (candidateElement.hasTagName(HTMLNames::iframeTag) || candidateElement.hasTagName(HTMLNames::frameTag))
+ return false;
+
+ if (candidateElement.hasTagName(HTMLNames::embedTag) || candidateElement.hasTagName(HTMLNames::objectTag) || candidateElement.hasTagName(HTMLNames::appletTag) || candidateElement.hasTagName(HTMLNames::canvasTag))
+ return false;
+
+ if (elementHasDirectionAuto(candidateElement))
+ return false;
+
+ if (candidateElement.isLink() && context.elementLinkState != style->insideLink())
+ return false;
+
+ if (candidateElement.elementData() != element.elementData()) {
+ if (candidateElement.fastGetAttribute(HTMLNames::readonlyAttr) != element.fastGetAttribute(HTMLNames::readonlyAttr))
+ return false;
+ if (candidateElement.isSVGElement()) {
+ if (candidateElement.getAttribute(HTMLNames::typeAttr) != element.getAttribute(HTMLNames::typeAttr))
+ return false;
+ } else {
+ if (candidateElement.fastGetAttribute(HTMLNames::typeAttr) != element.fastGetAttribute(HTMLNames::typeAttr))
+ return false;
+ }
+ }
+
+ if (candidateElement.matchesValidPseudoClass() != element.matchesValidPseudoClass())
+ return false;
+
+ if (element.matchesInvalidPseudoClass() != element.matchesValidPseudoClass())
+ return false;
+
+#if ENABLE(VIDEO_TRACK)
+ // Deny sharing styles between WebVTT and non-WebVTT nodes.
+ if (is<WebVTTElement>(element))
+ return false;
+#endif
+
+#if ENABLE(FULLSCREEN_API)
+ if (&element == m_document.webkitCurrentFullScreenElement() || &element == m_document.webkitCurrentFullScreenElement())
+ return false;
+#endif
+ return true;
+}
+
+bool SharingResolver::styleSharingCandidateMatchesRuleSet(const StyledElement& element, const RuleSet* ruleSet) const
+{
+ if (!ruleSet)
+ return false;
+
+ ElementRuleCollector collector(const_cast<StyledElement&>(element), nullptr, m_ruleSets, &m_selectorFilter);
+ return collector.hasAnyMatchingRules(ruleSet);
+}
+
+bool SharingResolver::sharingCandidateHasIdenticalStyleAffectingAttributes(const Context& context, const StyledElement& sharingCandidate) const
+{
+ auto& element = context.element;
+ if (element.elementData() == sharingCandidate.elementData())
+ return true;
+ if (element.fastGetAttribute(XMLNames::langAttr) != sharingCandidate.fastGetAttribute(XMLNames::langAttr))
+ return false;
+ if (element.fastGetAttribute(HTMLNames::langAttr) != sharingCandidate.fastGetAttribute(HTMLNames::langAttr))
+ return false;
+
+ if (context.elementAffectedByClassRules) {
+ if (!sharingCandidate.hasClass())
+ return false;
+ // SVG elements require a (slow!) getAttribute comparision because "class" is an animatable attribute for SVG.
+ if (element.isSVGElement()) {
+ if (element.getAttribute(HTMLNames::classAttr) != sharingCandidate.getAttribute(HTMLNames::classAttr))
+ return false;
+ } else {
+ if (element.classNames() != sharingCandidate.classNames())
+ return false;
+ }
+ } else if (sharingCandidate.hasClass() && classNamesAffectedByRules(sharingCandidate.classNames()))
+ return false;
+
+ if (const_cast<StyledElement&>(element).presentationAttributeStyle() != const_cast<StyledElement&>(sharingCandidate).presentationAttributeStyle())
+ return false;
+
+ if (element.hasTagName(HTMLNames::progressTag)) {
+ if (element.shouldAppearIndeterminate() != sharingCandidate.shouldAppearIndeterminate())
+ return false;
+ }
+
+ return true;
+}
+
+bool SharingResolver::classNamesAffectedByRules(const SpaceSplitString& classNames) const
+{
+ for (unsigned i = 0; i < classNames.size(); ++i) {
+ if (m_ruleSets.features().classesInRules.contains(classNames[i].impl()))
+ return true;
+ }
+ return false;
+}
+
+
+}
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorestyleStyleSharingResolverh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/style/StyleSharingResolver.h (0 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleSharingResolver.h         (rev 0)
+++ trunk/Source/WebCore/style/StyleSharingResolver.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -0,0 +1,66 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef StyleSharingResolver_h
+#define StyleSharingResolver_h
+
+namespace WebCore {
+
+class Document;
+class DocumentRuleSets;
+class Element;
+class Node;
+class RuleSet;
+class SelectorFilter;
+class SpaceSplitString;
+class StyledElement;
+
+namespace Style {
+
+class SharingResolver {
+public:
+ SharingResolver(const Document&, const DocumentRuleSets&, const SelectorFilter&);
+
+ const Element* resolve(const Element&) const;
+
+private:
+ struct Context;
+
+ StyledElement* findSibling(const Context&, Node*, unsigned& count) const;
+ Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
+ bool canShareStyleWithElement(const Context&, const StyledElement& candidateElement) const;
+ bool styleSharingCandidateMatchesRuleSet(const StyledElement&, const RuleSet*) const;
+ bool sharingCandidateHasIdenticalStyleAffectingAttributes(const Context&, const StyledElement& sharingCandidate) const;
+ bool classNamesAffectedByRules(const SpaceSplitString& classNames) const;
+
+ const Document& m_document;
+ const DocumentRuleSets& m_ruleSets;
+ const SelectorFilter& m_selectorFilter;
+};
+
+}
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCorestyleStyleTreeResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleTreeResolver.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -96,10 +96,24 @@
</span><span class="cx"> bool m_didPush { false };
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+
+static RenderStyle* placeholderStyle;
+
+static void ensurePlaceholderStyle(Document& document)
+{
+ if (placeholderStyle)
+ return;
+ placeholderStyle = &RenderStyle::create().leakRef();
+ placeholderStyle->setDisplay(NONE);
+ placeholderStyle->fontCascade().update(&document.fontSelector());
+}
+
</ins><span class="cx"> TreeResolver::TreeResolver(Document& document)
</span><span class="cx"> : m_document(document)
</span><span class="cx"> , m_styleResolver(document.ensureStyleResolver())
</span><ins>+ , m_sharingResolver(document, m_styleResolver.ruleSets(), m_selectorFilter)
</ins><span class="cx"> {
</span><ins>+ ensurePlaceholderStyle(document);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TreeResolver::TreeResolver(ShadowRoot& shadowRoot, TreeResolver& shadowHostTreeResolver)
</span><span class="lines">@@ -107,6 +121,7 @@
</span><span class="cx"> , m_styleResolver(shadowRoot.styleResolver())
</span><span class="cx"> , m_shadowRoot(&shadowRoot)
</span><span class="cx"> , m_shadowHostTreeResolver(&shadowHostTreeResolver)
</span><ins>+ , m_sharingResolver(m_document, m_styleResolver.ruleSets(), m_selectorFilter)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -123,11 +138,20 @@
</span><span class="cx">
</span><span class="cx"> Ref<RenderStyle> TreeResolver::styleForElement(Element& element, RenderStyle& inheritedStyle)
</span><span class="cx"> {
</span><ins>+ if (!m_document.haveStylesheetsLoaded() && !element.renderer()) {
+ m_document.setHasNodesWithPlaceholderStyle();
+ return *placeholderStyle;
+ }
+
</ins><span class="cx"> if (element.hasCustomStyleResolveCallbacks()) {
</span><span class="cx"> if (RefPtr<RenderStyle> style = element.customStyleForRenderer(inheritedStyle))
</span><span class="cx"> return style.releaseNonNull();
</span><span class="cx"> }
</span><del>- return m_styleResolver.styleForElement(element, &inheritedStyle, AllowStyleSharing, MatchAllRules, nullptr, &m_selectorFilter);
</del><ins>+
+ if (auto* sharingElement = m_sharingResolver.resolve(element))
+ return *sharingElement->renderStyle();
+
+ return m_styleResolver.styleForElement(element, &inheritedStyle, MatchAllRules, nullptr, &m_selectorFilter);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if ENABLE(CSS_REGIONS)
</span><span class="lines">@@ -948,5 +972,10 @@
</span><span class="cx"> return resolutionNestingDepth;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool isPlaceholderStyle(const RenderStyle& style)
+{
+ return &style == placeholderStyle;
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins></span></pre></div>
<a id="trunkSourceWebCorestyleStyleTreeResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleTreeResolver.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleTreeResolver.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/style/StyleTreeResolver.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include "RenderStyleConstants.h"
</span><span class="cx"> #include "SelectorFilter.h"
</span><span class="cx"> #include "StyleChange.h"
</span><ins>+#include "StyleSharingResolver.h"
</ins><span class="cx"> #include <functional>
</span><span class="cx"> #include <wtf/RefPtr.h>
</span><span class="cx">
</span><span class="lines">@@ -85,6 +86,7 @@
</span><span class="cx"> TreeResolver* m_shadowHostTreeResolver { nullptr };
</span><span class="cx">
</span><span class="cx"> SelectorFilter m_selectorFilter;
</span><ins>+ SharingResolver m_sharingResolver;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> void detachRenderTree(Element&);
</span><span class="lines">@@ -95,6 +97,8 @@
</span><span class="cx"> void queuePostResolutionCallback(std::function<void ()>);
</span><span class="cx"> bool postResolutionCallbacksAreSuspended();
</span><span class="cx">
</span><ins>+bool isPlaceholderStyle(const RenderStyle&);
+
</ins><span class="cx"> class PostResolutionCallbackDisabler {
</span><span class="cx"> public:
</span><span class="cx"> explicit PostResolutionCallbackDisabler(Document&);
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElement.cpp (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElement.cpp        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/svg/SVGElement.cpp        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -793,7 +793,7 @@
</span><span class="cx"> {
</span><span class="cx"> // If the element is in a <use> tree we get the style from the definition tree.
</span><span class="cx"> if (auto* styleElement = this->correspondingElement())
</span><del>- return styleElement->styleResolver().styleForElement(*styleElement, &parentStyle, DisallowStyleSharing);
</del><ins>+ return styleElement->styleResolver().styleForElement(*styleElement, &parentStyle);
</ins><span class="cx">
</span><span class="cx"> return resolveStyle(&parentStyle);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementRareDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElementRareData.h (196030 => 196031)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElementRareData.h        2016-02-02 22:34:40 UTC (rev 196030)
+++ trunk/Source/WebCore/svg/SVGElementRareData.h        2016-02-02 22:34:45 UTC (rev 196031)
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx"> return 0;
</span><span class="cx"> if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
</span><span class="cx"> // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
</span><del>- m_overrideComputedStyle = element.styleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
</del><ins>+ m_overrideComputedStyle = element.styleResolver().styleForElement(element, parentStyle, MatchAllRulesExcludingSMIL);
</ins><span class="cx"> m_needsOverrideComputedStyleUpdate = false;
</span><span class="cx"> }
</span><span class="cx"> ASSERT(m_overrideComputedStyle);
</span></span></pre>
</div>
</div>
</body>
</html>