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

Side by Side 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, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/css/CSSGlobalRuleSet.h"
6
7 #include "core/css/CSSDefaultStyleSheets.h"
8 #include "core/css/RuleSet.h"
9 #include "core/dom/CSSSelectorWatch.h"
10 #include "core/dom/Document.h"
11 #include "core/dom/StyleEngine.h"
12
13 namespace blink {
14
15 void CSSGlobalRuleSet::initWatchedSelectorsRuleSet(Document& document) {
16 markDirty();
17 m_watchedSelectorsRuleSet = nullptr;
18 CSSSelectorWatch* watch = CSSSelectorWatch::fromIfExists(document);
19 if (!watch)
20 return;
21 const HeapVector<Member<StyleRule>>& watchedSelectors =
22 watch->watchedCallbackSelectors();
23 if (!watchedSelectors.size())
24 return;
25 m_watchedSelectorsRuleSet = RuleSet::create();
26 for (unsigned i = 0; i < watchedSelectors.size(); ++i) {
27 m_watchedSelectorsRuleSet->addStyleRule(watchedSelectors[i],
28 RuleHasNoSpecialState);
29 }
30 }
31
32 static RuleSet* makeRuleSet(const HeapVector<RuleFeature>& rules) {
33 size_t size = rules.size();
34 if (!size)
35 return nullptr;
36 RuleSet* ruleSet = RuleSet::create();
37 for (size_t i = 0; i < size; ++i) {
38 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex,
39 rules[i].hasDocumentSecurityOrigin
40 ? RuleHasDocumentSecurityOrigin
41 : RuleHasNoSpecialState);
42 }
43 return ruleSet;
44 }
45
46 void CSSGlobalRuleSet::update(Document& document) {
47 if (!m_isDirty)
48 return;
49
50 m_isDirty = false;
51 m_features.clear();
52 m_hasFullscreenUAStyle = false;
53
54 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance();
55 if (defaultStyleSheets.defaultStyle()) {
56 m_features.add(defaultStyleSheets.defaultStyle()->features());
57 m_hasFullscreenUAStyle = defaultStyleSheets.fullscreenStyleSheet();
58 }
59
60 if (document.isViewSource())
61 m_features.add(defaultStyleSheets.defaultViewSourceStyle()->features());
62
63 if (m_watchedSelectorsRuleSet)
64 m_features.add(m_watchedSelectorsRuleSet->features());
65
66 document.styleEngine().collectScopedStyleFeaturesTo(m_features);
67
68 m_siblingRuleSet = makeRuleSet(m_features.siblingRules);
69 m_uncommonAttributeRuleSet = makeRuleSet(m_features.uncommonAttributeRules);
70 }
71
72 DEFINE_TRACE(CSSGlobalRuleSet) {
73 visitor->trace(m_features);
74 visitor->trace(m_siblingRuleSet);
75 visitor->trace(m_uncommonAttributeRuleSet);
76 visitor->trace(m_watchedSelectorsRuleSet);
77 }
78
79 } // namespace blink
OLDNEW
« 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