<!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>[163592] 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/163592">163592</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2014-02-06 17:58:40 -0800 (Thu, 06 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Check selectors exactly when invalidating style
https://bugs.webkit.org/show_bug.cgi?id=128321
Reviewed by Andreas Kling.
Selectors are now really fast to match with the JIT. Take advantage of this by invalidating
the document style exactly when a new stylesheet arrives (instead of using heuristics).
This reduces need for large style recalculations in some common cases.
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::clearMatchedRules):
(WebCore::ElementRuleCollector::collectMatchingRulesForList):
* css/ElementRuleCollector.h:
(WebCore::ElementRuleCollector::hasMatchedRules):
* css/RuleSet.h:
(WebCore::RuleSet::hasShadowPseudoElementRules):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::matchRecursively):
* css/SelectorChecker.h:
Add new mode where all pseudo elements match so we can invalidate their element.
* css/StyleInvalidationAnalysis.cpp:
(WebCore::shouldDirtyAllStyle):
(WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
(WebCore::invalidateStyleRecursively):
(WebCore::StyleInvalidationAnalysis::invalidateStyle):
Switch to real selector checker.
* css/StyleInvalidationAnalysis.h:
* css/StyleResolver.cpp:
(WebCore::StyleResolver::MatchedProperties::~MatchedProperties):
* css/StyleResolver.h:
(WebCore::StyleResolver::mediaQueryEvaluator):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</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="#trunkSourceWebCorecssRuleSeth">trunk/Source/WebCore/css/RuleSet.h</a></li>
<li><a href="#trunkSourceWebCorecssSelectorCheckercpp">trunk/Source/WebCore/css/SelectorChecker.cpp</a></li>
<li><a href="#trunkSourceWebCorecssSelectorCheckerh">trunk/Source/WebCore/css/SelectorChecker.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleInvalidationAnalysiscpp">trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp</a></li>
<li><a href="#trunkSourceWebCorecssStyleInvalidationAnalysish">trunk/Source/WebCore/css/StyleInvalidationAnalysis.h</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="#trunkSourceWebCoredomDocumentStyleSheetCollectioncpp">trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/ChangeLog        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2014-02-06 Antti Koivisto <antti@apple.com>
+
+ Check selectors exactly when invalidating style
+ https://bugs.webkit.org/show_bug.cgi?id=128321
+
+ Reviewed by Andreas Kling.
+
+ Selectors are now really fast to match with the JIT. Take advantage of this by invalidating
+ the document style exactly when a new stylesheet arrives (instead of using heuristics).
+
+ This reduces need for large style recalculations in some common cases.
+
+ * css/ElementRuleCollector.cpp:
+ (WebCore::ElementRuleCollector::clearMatchedRules):
+ (WebCore::ElementRuleCollector::collectMatchingRulesForList):
+ * css/ElementRuleCollector.h:
+ (WebCore::ElementRuleCollector::hasMatchedRules):
+ * css/RuleSet.h:
+ (WebCore::RuleSet::hasShadowPseudoElementRules):
+ * css/SelectorChecker.cpp:
+ (WebCore::SelectorChecker::matchRecursively):
+ * css/SelectorChecker.h:
+
+ Add new mode where all pseudo elements match so we can invalidate their element.
+
+ * css/StyleInvalidationAnalysis.cpp:
+ (WebCore::shouldDirtyAllStyle):
+ (WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
+ (WebCore::invalidateStyleRecursively):
+ (WebCore::StyleInvalidationAnalysis::invalidateStyle):
+
+ Switch to real selector checker.
+
+ * css/StyleInvalidationAnalysis.h:
+ * css/StyleResolver.cpp:
+ (WebCore::StyleResolver::MatchedProperties::~MatchedProperties):
+ * css/StyleResolver.h:
+ (WebCore::StyleResolver::mediaQueryEvaluator):
+ * dom/DocumentStyleSheetCollection.cpp:
+ (WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):
+
</ins><span class="cx"> 2014-02-06 Gavin Barraclough <barraclough@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove ChildProcess::m_activeTasks
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -94,7 +94,7 @@
</span><span class="cx"> m_matchedRules->append(rule);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-inline void ElementRuleCollector::clearMatchedRules()
</del><ins>+void ElementRuleCollector::clearMatchedRules()
</ins><span class="cx"> {
</span><span class="cx"> if (!m_matchedRules)
</span><span class="cx"> return;
</span><span class="lines">@@ -359,7 +359,7 @@
</span><span class="cx"> PseudoId dynamicPseudo = NOPSEUDO;
</span><span class="cx"> if (ruleMatches(ruleData, dynamicPseudo)) {
</span><span class="cx"> // For SharingRules testing, any match is good enough, we don't care what is matched.
</span><del>- if (m_mode == SelectorChecker::SharingRules) {
</del><ins>+ if (m_mode == SelectorChecker::SharingRules || m_mode == SelectorChecker::StyleInvalidation) {
</ins><span class="cx"> addMatchedRule(&ruleData);
</span><span class="cx"> break;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.h        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -70,6 +70,9 @@
</span><span class="cx"> StyleResolver::MatchResult& matchedResult();
</span><span class="cx"> const Vector<RefPtr<StyleRuleBase>>& matchedRuleList() const;
</span><span class="cx">
</span><ins>+ bool hasMatchedRules() const { return m_matchedRules && !m_matchedRules->isEmpty(); }
+ void clearMatchedRules();
+
</ins><span class="cx"> private:
</span><span class="cx"> void addElementStyleProperties(const StyleProperties*, bool isCacheable = true);
</span><span class="cx">
</span><span class="lines">@@ -84,7 +87,6 @@
</span><span class="cx"> void sortAndTransferMatchedRules();
</span><span class="cx">
</span><span class="cx"> void addMatchedRule(const RuleData*);
</span><del>- void clearMatchedRules();
</del><span class="cx">
</span><span class="cx"> Element& m_element;
</span><span class="cx"> RenderStyle* m_style;
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.h (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.h        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/RuleSet.h        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -166,6 +166,8 @@
</span><span class="cx">
</span><span class="cx"> unsigned ruleCount() const { return m_ruleCount; }
</span><span class="cx">
</span><ins>+ bool hasShadowPseudoElementRules() const { return !m_shadowPseudoElementRules.isEmpty(); }
+
</ins><span class="cx"> private:
</span><span class="cx"> void addChildRules(const Vector<RefPtr<StyleRuleBase>>&, const MediaQueryEvaluator& medium, StyleResolver*, bool hasDocumentSecurityOrigin, AddRuleFlags);
</span><span class="cx"> bool findBestRuleSetAndAdd(const CSSSelector*, RuleData&);
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorChecker.cpp        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
</span><span class="cx"> * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
</span><span class="cx"> * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
</span><del>- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx"> * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
</span><span class="cx"> * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
</span><span class="cx"> * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
</span><span class="lines">@@ -162,13 +162,14 @@
</span><span class="cx">
</span><span class="cx"> if (context.selector->pseudoType() == CSSSelector::PseudoWebKitCustomElement && root->type() != ShadowRoot::UserAgentShadowRoot)
</span><span class="cx"> return SelectorFailsLocally;
</span><del>- } else
</del><ins>+ } else if (m_mode != StyleInvalidation)
</ins><span class="cx"> return SelectorFailsLocally;
</span><span class="cx"> } else {
</span><span class="cx"> if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
</span><span class="cx"> return SelectorFailsLocally;
</span><span class="cx">
</span><del>- PseudoId pseudoId = CSSSelector::pseudoId(context.selector->pseudoType());
</del><ins>+ // When invalidating style all pseudo elements need to match.
+ PseudoId pseudoId = m_mode == StyleInvalidation ? NOPSEUDO : CSSSelector::pseudoId(context.selector->pseudoType());
</ins><span class="cx"> if (pseudoId == FIRST_LETTER)
</span><span class="cx"> context.element->document().styleSheetCollection().setUsesFirstLetterRules(true);
</span><span class="cx"> if (pseudoId != NOPSEUDO)
</span></span></pre></div>
<a id="trunkSourceWebCorecssSelectorCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/SelectorChecker.h (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/SelectorChecker.h        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/SelectorChecker.h        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">
</span><span class="cx"> public:
</span><span class="cx"> enum VisitedMatchType { VisitedMatchDisabled, VisitedMatchEnabled };
</span><del>- enum Mode { ResolvingStyle = 0, CollectingRules, QueryingRules, SharingRules };
</del><ins>+ enum Mode { ResolvingStyle = 0, CollectingRules, QueryingRules, SharingRules, StyleInvalidation };
</ins><span class="cx">
</span><span class="cx"> SelectorChecker(Document&, Mode);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleInvalidationAnalysiscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -29,106 +29,100 @@
</span><span class="cx"> #include "CSSSelectorList.h"
</span><span class="cx"> #include "Document.h"
</span><span class="cx"> #include "ElementIterator.h"
</span><ins>+#include "ElementRuleCollector.h"
+#include "SelectorFilter.h"
</ins><span class="cx"> #include "StyleRuleImport.h"
</span><span class="cx"> #include "StyleSheetContents.h"
</span><del>-#include "StyledElement.h"
</del><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-StyleInvalidationAnalysis::StyleInvalidationAnalysis(const Vector<StyleSheetContents*>& sheets)
- : m_dirtiesAllStyle(false)
</del><ins>+static bool shouldDirtyAllStyle(const Vector<RefPtr<StyleRuleBase>> rules)
</ins><span class="cx"> {
</span><del>- for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i)
- analyzeStyleSheet(sheets[i]);
-}
-
-static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes)
-{
- for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector)) {
- const CSSSelector* scopeSelector = 0;
- // This picks the widest scope, not the narrowest, to minimize the number of found scopes.
- for (const CSSSelector* current = selector; current; current = current->tagHistory()) {
- // Prefer ids over classes.
- if (current->m_match == CSSSelector::Id)
- scopeSelector = current;
- else if (current->m_match == CSSSelector::Class && (!scopeSelector || scopeSelector->m_match != CSSSelector::Id))
- scopeSelector = current;
- CSSSelector::Relation relation = current->relation();
- if (relation != CSSSelector::Descendant && relation != CSSSelector::Child && relation != CSSSelector::SubSelector)
- break;
</del><ins>+ for (auto& rule : rules) {
+ if (rule->isMediaRule()) {
+ if (shouldDirtyAllStyle(static_cast<StyleRuleMedia&>(*rule).childRules()))
+ return true;
+ continue;
</ins><span class="cx"> }
</span><del>- if (!scopeSelector)
- return false;
- ASSERT(scopeSelector->m_match == CSSSelector::Class || scopeSelector->m_match == CSSSelector::Id);
- if (scopeSelector->m_match == CSSSelector::Id)
- idScopes.add(scopeSelector->value().impl());
- else
- classScopes.add(scopeSelector->value().impl());
</del><ins>+ // FIXME: At least font faces don't need full recalc in all cases.
+ if (!rule->isStyleRule())
+ return true;
</ins><span class="cx"> }
</span><del>- return true;
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheetContents)
</del><ins>+static bool shouldDirtyAllStyle(const StyleSheetContents& sheet)
</ins><span class="cx"> {
</span><del>- ASSERT(!styleSheetContents->isLoading());
-
- // See if all rules on the sheet are scoped to some specific ids or classes.
- // Then test if we actually have any of those in the tree at the moment.
- const Vector<RefPtr<StyleRuleImport>>& importRules = styleSheetContents->importRules();
- for (unsigned i = 0; i < importRules.size(); ++i) {
- if (!importRules[i]->styleSheet())
</del><ins>+ for (auto& import : sheet.importRules()) {
+ if (!import->styleSheet())
</ins><span class="cx"> continue;
</span><del>- analyzeStyleSheet(importRules[i]->styleSheet());
- if (m_dirtiesAllStyle)
- return;
</del><ins>+ if (shouldDirtyAllStyle(*import->styleSheet()))
+ return true;
</ins><span class="cx"> }
</span><del>- const Vector<RefPtr<StyleRuleBase>>& rules = styleSheetContents->childRules();
- for (unsigned i = 0; i < rules.size(); i++) {
- StyleRuleBase* rule = rules[i].get();
- if (!rule->isStyleRule()) {
- // FIXME: Media rules and maybe some others could be allowed.
- m_dirtiesAllStyle = true;
- return;
- }
- StyleRule* styleRule = static_cast<StyleRule*>(rule);
- if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_classScopes)) {
- m_dirtiesAllStyle = true;
- return;
- }
- }
</del><ins>+ if (shouldDirtyAllStyle(sheet.childRules()))
+ return true;
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static bool elementMatchesSelectorScopes(const Element& element, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes)
</del><ins>+static bool shouldDirtyAllStyle(const Vector<StyleSheetContents*>& sheets)
</ins><span class="cx"> {
</span><del>- if (!idScopes.isEmpty() && element.hasID() && idScopes.contains(element.idForStyleResolution().impl()))
- return true;
- if (classScopes.isEmpty() || !element.hasClass())
- return false;
- const SpaceSplitString& classNames = element.classNames();
- for (unsigned i = 0; i < classNames.size(); ++i) {
- if (classScopes.contains(classNames[i].impl()))
</del><ins>+ for (auto& sheet : sheets) {
+ if (shouldDirtyAllStyle(*sheet))
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+StyleInvalidationAnalysis::StyleInvalidationAnalysis(const Vector<StyleSheetContents*>& sheets, const MediaQueryEvaluator& mediaQueryEvaluator)
+ : m_dirtiesAllStyle(shouldDirtyAllStyle(sheets))
+{
+ if (m_dirtiesAllStyle)
+ return;
+
+ m_ruleSets.resetAuthorStyle();
+ for (auto& sheet : sheets)
+ m_ruleSets.authorStyle()->addRulesFromSheet(sheet, mediaQueryEvaluator);
+
+ // FIXME: We don't descent into shadow trees or otherwise handle shadow pseudo elements.
+ if (m_ruleSets.authorStyle()->hasShadowPseudoElementRules())
+ m_dirtiesAllStyle = true;
+}
+
+static void invalidateStyleRecursively(Element& element, SelectorFilter& filter, const DocumentRuleSets& ruleSets)
+{
+ if (element.styleChangeType() > InlineStyleChange)
+ return;
+ if (element.styleChangeType() == NoStyleChange) {
+ ElementRuleCollector ruleCollector(element, nullptr, ruleSets, filter);
+ ruleCollector.setMode(SelectorChecker::StyleInvalidation);
+ ruleCollector.matchAuthorRules(false);
+
+ if (ruleCollector.hasMatchedRules())
+ element.setNeedsStyleRecalc(InlineStyleChange);
+ }
+
+ auto children = childrenOfType<Element>(element);
+ if (!children.first())
+ return;
+ filter.pushParent(&element);
+ for (auto& child : children)
+ invalidateStyleRecursively(child, filter, ruleSets);
+ filter.popParent();
+}
+
</ins><span class="cx"> void StyleInvalidationAnalysis::invalidateStyle(Document& document)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(!m_dirtiesAllStyle);
</span><del>- if (m_idScopes.isEmpty() && m_classScopes.isEmpty())
</del><ins>+ if (!m_ruleSets.authorStyle())
</ins><span class="cx"> return;
</span><span class="cx">
</span><del>- auto it = descendantsOfType<Element>(document).begin();
- auto end = descendantsOfType<Element>(document).end();
- while (it != end) {
- if (elementMatchesSelectorScopes(*it, m_idScopes, m_classScopes)) {
- it->setNeedsStyleRecalc();
- // The whole subtree is now invalidated, we can skip to the next sibling.
- it.traverseNextSkippingChildren();
- continue;
- }
- ++it;
- }
</del><ins>+ Element* documentElement = document.documentElement();
+ if (!documentElement)
+ return;
+
+ SelectorFilter filter;
+ filter.setupParentStack(documentElement);
+ invalidateStyleRecursively(*documentElement, filter, m_ruleSets);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleInvalidationAnalysish"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleInvalidationAnalysis.h (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.h        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.h        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #ifndef StyleInvalidationAnalysis_h
</span><span class="cx"> #define StyleInvalidationAnalysis_h
</span><span class="cx">
</span><ins>+#include "DocumentRuleSets.h"
</ins><span class="cx"> #include <wtf/HashSet.h>
</span><span class="cx"> #include <wtf/text/AtomicStringImpl.h>
</span><span class="cx">
</span><span class="lines">@@ -36,18 +37,14 @@
</span><span class="cx">
</span><span class="cx"> class StyleInvalidationAnalysis {
</span><span class="cx"> public:
</span><del>- StyleInvalidationAnalysis(const Vector<StyleSheetContents*>&);
</del><ins>+ StyleInvalidationAnalysis(const Vector<StyleSheetContents*>&, const MediaQueryEvaluator&);
</ins><span class="cx">
</span><span class="cx"> bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
</span><span class="cx"> void invalidateStyle(Document&);
</span><span class="cx">
</span><span class="cx"> private:
</span><del>-
- void analyzeStyleSheet(StyleSheetContents*);
-
</del><span class="cx"> bool m_dirtiesAllStyle;
</span><del>- HashSet<AtomicStringImpl*> m_idScopes;
- HashSet<AtomicStringImpl*> m_classScopes;
</del><ins>+ DocumentRuleSets m_ruleSets;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -3657,7 +3657,7 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>-inline StyleResolver::MatchedProperties::~MatchedProperties()
</del><ins>+StyleResolver::MatchedProperties::~MatchedProperties()
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.h (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.h        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/css/StyleResolver.h        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -168,6 +168,8 @@
</span><span class="cx"> const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
</span><span class="cx"> SelectorFilter& selectorFilter() { return m_selectorFilter; }
</span><span class="cx">
</span><ins>+ const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }
+
</ins><span class="cx"> private:
</span><span class="cx"> void initElement(Element*);
</span><span class="cx"> RenderStyle* locateSharedStyle();
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentStyleSheetCollectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (163591 => 163592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp        2014-02-07 01:57:37 UTC (rev 163591)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp        2014-02-07 01:58:40 UTC (rev 163592)
</span><span class="lines">@@ -366,6 +366,7 @@
</span><span class="cx"> return;
</span><span class="cx"> if (!m_document.styleResolverIfExists())
</span><span class="cx"> return;
</span><ins>+ StyleResolver& styleResolver = *m_document.styleResolverIfExists();
</ins><span class="cx">
</span><span class="cx"> // Find out which stylesheets are new.
</span><span class="cx"> unsigned oldStylesheetCount = m_activeAuthorStyleSheets.size();
</span><span class="lines">@@ -396,7 +397,7 @@
</span><span class="cx"> // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs.
</span><span class="cx"> if (!m_document.body() || m_document.hasNodesWithPlaceholderStyle())
</span><span class="cx"> return;
</span><del>- StyleInvalidationAnalysis invalidationAnalysis(addedSheets);
</del><ins>+ StyleInvalidationAnalysis invalidationAnalysis(addedSheets, styleResolver.mediaQueryEvaluator());
</ins><span class="cx"> if (invalidationAnalysis.dirtiesAllStyle())
</span><span class="cx"> return;
</span><span class="cx"> invalidationAnalysis.invalidateStyle(m_document);
</span></span></pre>
</div>
</div>
</body>
</html>