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

Unified Diff: third_party/WebKit/Source/core/css/CSSGlobalRuleSet.cpp

Issue 2451893003: Move Document global rule data to CSSGlobalRuleSet. (Closed)
Patch Set: Rebased. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/CSSGlobalRuleSet.cpp
diff --git a/third_party/WebKit/Source/core/css/CSSGlobalRuleSet.cpp b/third_party/WebKit/Source/core/css/CSSGlobalRuleSet.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5e596a95f20ab7d8b3ba1500e9c564bd55dd4af2
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/CSSGlobalRuleSet.cpp
@@ -0,0 +1,79 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/css/CSSGlobalRuleSet.h"
+
+#include "core/css/CSSDefaultStyleSheets.h"
+#include "core/css/RuleSet.h"
+#include "core/dom/CSSSelectorWatch.h"
+#include "core/dom/Document.h"
+#include "core/dom/StyleEngine.h"
+
+namespace blink {
+
+void CSSGlobalRuleSet::initWatchedSelectorsRuleSet(Document& document) {
+ markDirty();
+ m_watchedSelectorsRuleSet = nullptr;
+ CSSSelectorWatch* watch = CSSSelectorWatch::fromIfExists(document);
+ if (!watch)
+ return;
+ const HeapVector<Member<StyleRule>>& watchedSelectors =
+ watch->watchedCallbackSelectors();
+ if (!watchedSelectors.size())
+ return;
+ m_watchedSelectorsRuleSet = RuleSet::create();
+ for (unsigned i = 0; i < watchedSelectors.size(); ++i) {
+ m_watchedSelectorsRuleSet->addStyleRule(watchedSelectors[i],
+ RuleHasNoSpecialState);
+ }
+}
+
+static RuleSet* makeRuleSet(const HeapVector<RuleFeature>& rules) {
+ size_t size = rules.size();
+ if (!size)
+ return nullptr;
+ RuleSet* ruleSet = RuleSet::create();
+ for (size_t i = 0; i < size; ++i) {
+ ruleSet->addRule(rules[i].rule, rules[i].selectorIndex,
+ rules[i].hasDocumentSecurityOrigin
+ ? RuleHasDocumentSecurityOrigin
+ : RuleHasNoSpecialState);
+ }
+ return ruleSet;
+}
+
+void CSSGlobalRuleSet::update(Document& document) {
+ if (!m_isDirty)
+ return;
+
+ m_isDirty = false;
+ m_features.clear();
+ m_hasFullscreenUAStyle = false;
+
+ CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance();
+ if (defaultStyleSheets.defaultStyle()) {
+ m_features.add(defaultStyleSheets.defaultStyle()->features());
+ m_hasFullscreenUAStyle = defaultStyleSheets.fullscreenStyleSheet();
+ }
+
+ if (document.isViewSource())
+ m_features.add(defaultStyleSheets.defaultViewSourceStyle()->features());
+
+ if (m_watchedSelectorsRuleSet)
+ m_features.add(m_watchedSelectorsRuleSet->features());
+
+ document.styleEngine().collectScopedStyleFeaturesTo(m_features);
+
+ m_siblingRuleSet = makeRuleSet(m_features.siblingRules);
+ m_uncommonAttributeRuleSet = makeRuleSet(m_features.uncommonAttributeRules);
+}
+
+DEFINE_TRACE(CSSGlobalRuleSet) {
+ visitor->trace(m_features);
+ visitor->trace(m_siblingRuleSet);
+ visitor->trace(m_uncommonAttributeRuleSet);
+ visitor->trace(m_watchedSelectorsRuleSet);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSGlobalRuleSet.h ('k') | third_party/WebKit/Source/core/css/resolver/StyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698