OLD | NEW |
(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 { |
| 17 m_watchedSelectorsRuleSet = nullptr; |
| 18 CSSSelectorWatch* watch = CSSSelectorWatch::fromIfExists(document); |
| 19 if (!watch) |
| 20 return; |
| 21 const HeapVector<Member<StyleRule>>& watchedSelectors = watch->watchedCallba
ckSelectors(); |
| 22 if (!watchedSelectors.size()) |
| 23 return; |
| 24 m_watchedSelectorsRuleSet = RuleSet::create(); |
| 25 for (unsigned i = 0; i < watchedSelectors.size(); ++i) |
| 26 m_watchedSelectorsRuleSet->addStyleRule(watchedSelectors[i].get(), RuleH
asNoSpecialState); |
| 27 } |
| 28 |
| 29 static RuleSet* makeRuleSet(const HeapVector<RuleFeature>& rules) |
| 30 { |
| 31 size_t size = rules.size(); |
| 32 if (!size) |
| 33 return nullptr; |
| 34 RuleSet* ruleSet = RuleSet::create(); |
| 35 for (size_t i = 0; i < size; ++i) |
| 36 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocu
mentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState); |
| 37 return ruleSet; |
| 38 } |
| 39 |
| 40 void CSSGlobalRuleSet::update(Document& document) |
| 41 { |
| 42 m_features.clear(); |
| 43 |
| 44 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(
); |
| 45 if (defaultStyleSheets.defaultStyle()) |
| 46 m_features.add(defaultStyleSheets.defaultStyle()->features()); |
| 47 |
| 48 if (document.isViewSource()) |
| 49 m_features.add(defaultStyleSheets.defaultViewSourceStyle()->features()); |
| 50 |
| 51 if (m_watchedSelectorsRuleSet) |
| 52 m_features.add(m_watchedSelectorsRuleSet->features()); |
| 53 |
| 54 document.styleEngine().collectScopedStyleFeaturesTo(m_features); |
| 55 |
| 56 m_siblingRuleSet = makeRuleSet(m_features.siblingRules); |
| 57 m_uncommonAttributeRuleSet = makeRuleSet(m_features.uncommonAttributeRules); |
| 58 } |
| 59 |
| 60 DEFINE_TRACE(CSSGlobalRuleSet) |
| 61 { |
| 62 visitor->trace(m_features); |
| 63 visitor->trace(m_siblingRuleSet); |
| 64 visitor->trace(m_uncommonAttributeRuleSet); |
| 65 visitor->trace(m_watchedSelectorsRuleSet); |
| 66 } |
| 67 |
| 68 } // namespace blink |
OLD | NEW |