OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
30 #include "core/css/CSSFontSelector.h" | 30 #include "core/css/CSSFontSelector.h" |
31 #include "core/css/CSSStyleSheet.h" | 31 #include "core/css/CSSStyleSheet.h" |
32 #include "core/css/FontFace.h" | 32 #include "core/css/FontFace.h" |
33 #include "core/css/PageRuleCollector.h" | 33 #include "core/css/PageRuleCollector.h" |
34 #include "core/css/RuleFeature.h" | 34 #include "core/css/RuleFeature.h" |
35 #include "core/css/StyleRule.h" | 35 #include "core/css/StyleRule.h" |
36 #include "core/css/StyleSheetContents.h" | 36 #include "core/css/StyleSheetContents.h" |
37 #include "core/css/resolver/MatchRequest.h" | 37 #include "core/css/resolver/MatchRequest.h" |
38 #include "core/css/resolver/ViewportStyleResolver.h" | |
39 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
40 #include "core/dom/StyleEngine.h" | 39 #include "core/dom/StyleEngine.h" |
41 #include "core/dom/shadow/ElementShadow.h" | 40 #include "core/dom/shadow/ElementShadow.h" |
42 #include "core/dom/shadow/ShadowRoot.h" | 41 #include "core/dom/shadow/ShadowRoot.h" |
43 #include "core/html/HTMLStyleElement.h" | 42 #include "core/html/HTMLStyleElement.h" |
44 #include "core/svg/SVGStyleElement.h" | 43 #include "core/svg/SVGStyleElement.h" |
45 | 44 |
46 namespace blink { | 45 namespace blink { |
47 | 46 |
48 ScopedStyleResolver* ScopedStyleResolver::parent() const | 47 ScopedStyleResolver* ScopedStyleResolver::parent() const |
(...skipping 18 matching lines...) Expand all Loading... |
67 if (!treeScope().rootNode().isDocumentNode()) | 66 if (!treeScope().rootNode().isDocumentNode()) |
68 return; | 67 return; |
69 | 68 |
70 Document& document = treeScope().document(); | 69 Document& document = treeScope().document(); |
71 CSSFontSelector* cssFontSelector = document.styleEngine().fontSelector(); | 70 CSSFontSelector* cssFontSelector = document.styleEngine().fontSelector(); |
72 const HeapVector<Member<StyleRuleFontFace>> fontFaceRules = ruleSet.fontFace
Rules(); | 71 const HeapVector<Member<StyleRuleFontFace>> fontFaceRules = ruleSet.fontFace
Rules(); |
73 for (auto& fontFaceRule : fontFaceRules) { | 72 for (auto& fontFaceRule : fontFaceRules) { |
74 if (FontFace* fontFace = FontFace::create(&document, fontFaceRule)) | 73 if (FontFace* fontFace = FontFace::create(&document, fontFaceRule)) |
75 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule,
fontFace); | 74 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule,
fontFace); |
76 } | 75 } |
77 if (fontFaceRules.size()) | 76 if (fontFaceRules.size() && document.styleResolver()) |
78 document.styleResolver()->invalidateMatchedPropertiesCache(); | 77 document.styleResolver()->invalidateMatchedPropertiesCache(); |
79 } | 78 } |
80 | 79 |
81 void ScopedStyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet, const Med
iaQueryEvaluator& medium) | 80 void ScopedStyleResolver::appendActiveStyleSheets(unsigned index, const ActiveSt
yleSheetVector& activeSheets) |
82 { | 81 { |
83 unsigned index = m_authorStyleSheets.size(); | 82 DCHECK(index == m_authorStyleSheets.size()); |
84 m_authorStyleSheets.append(&cssSheet); | |
85 StyleSheetContents* sheet = cssSheet.contents(); | |
86 AddRuleFlags addRuleFlags = treeScope().document().getSecurityOrigin()->canR
equest(sheet->baseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState
; | |
87 const RuleSet& ruleSet = sheet->ensureRuleSet(medium, addRuleFlags); | |
88 | 83 |
89 addKeyframeRules(ruleSet); | 84 for (auto activeIterator = activeSheets.begin() + index; activeIterator != a
ctiveSheets.end(); activeIterator++) { |
90 addFontFaceRules(ruleSet); | 85 CSSStyleSheet* sheet = activeIterator->first; |
91 addTreeBoundaryCrossingRules(ruleSet, &cssSheet, index); | 86 m_viewportDependentMediaQueryResults.appendVector(sheet->viewportDepende
ntMediaQueryResults()); |
92 treeScope().document().styleResolver()->addViewportDependentMediaQueries(rul
eSet.viewportDependentMediaQueryResults()); | 87 m_deviceDependentMediaQueryResults.appendVector(sheet->deviceDependentMe
diaQueryResults()); |
93 treeScope().document().styleResolver()->addDeviceDependentMediaQueries(ruleS
et.deviceDependentMediaQueryResults()); | 88 if (activeIterator->second == RuleSet::emptyRuleSet()) |
| 89 continue; |
| 90 const RuleSet& ruleSet = *activeIterator->second; |
| 91 m_authorStyleSheets.append(sheet); |
| 92 addKeyframeRules(ruleSet); |
| 93 addFontFaceRules(ruleSet); |
| 94 addTreeBoundaryCrossingRules(ruleSet, sheet, index++); |
| 95 } |
94 } | 96 } |
95 | 97 |
96 void ScopedStyleResolver::collectFeaturesTo(RuleFeatureSet& features, HeapHashSe
t<Member<const StyleSheetContents>>& visitedSharedStyleSheetContents) const | 98 void ScopedStyleResolver::collectFeaturesTo(RuleFeatureSet& features, HeapHashSe
t<Member<const StyleSheetContents>>& visitedSharedStyleSheetContents) const |
97 { | 99 { |
| 100 features.viewportDependentMediaQueryResults.appendVector(m_viewportDependent
MediaQueryResults); |
| 101 features.deviceDependentMediaQueryResults.appendVector(m_deviceDependentMedi
aQueryResults); |
| 102 |
98 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { | 103 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |
99 ASSERT(m_authorStyleSheets[i]->ownerNode()); | 104 ASSERT(m_authorStyleSheets[i]->ownerNode()); |
100 StyleSheetContents* contents = m_authorStyleSheets[i]->contents(); | 105 StyleSheetContents* contents = m_authorStyleSheets[i]->contents(); |
101 if (contents->hasOneClient() || visitedSharedStyleSheetContents.add(cont
ents).isNewEntry) | 106 if (contents->hasOneClient() || visitedSharedStyleSheetContents.add(cont
ents).isNewEntry) |
102 features.add(contents->ruleSet().features()); | 107 features.add(contents->ruleSet().features()); |
103 } | 108 } |
104 | 109 |
105 if (!m_treeBoundaryCrossingRuleSet) | 110 if (!m_treeBoundaryCrossingRuleSet) |
106 return; | 111 return; |
107 | 112 |
108 for (const auto& rules : *m_treeBoundaryCrossingRuleSet) | 113 for (const auto& rules : *m_treeBoundaryCrossingRuleSet) |
109 features.add(rules->m_ruleSet->features()); | 114 features.add(rules->m_ruleSet->features()); |
110 } | 115 } |
111 | 116 |
112 void ScopedStyleResolver::resetAuthorStyle() | 117 void ScopedStyleResolver::resetAuthorStyle() |
113 { | 118 { |
114 m_authorStyleSheets.clear(); | 119 m_authorStyleSheets.clear(); |
| 120 m_viewportDependentMediaQueryResults.clear(); |
| 121 m_deviceDependentMediaQueryResults.clear(); |
115 m_keyframesRuleMap.clear(); | 122 m_keyframesRuleMap.clear(); |
116 m_treeBoundaryCrossingRuleSet = nullptr; | 123 m_treeBoundaryCrossingRuleSet = nullptr; |
117 m_hasDeepOrShadowSelector = false; | 124 m_hasDeepOrShadowSelector = false; |
118 } | 125 } |
119 | 126 |
120 StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const String
Impl* animationName) | 127 StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const String
Impl* animationName) |
121 { | 128 { |
122 if (m_keyframesRuleMap.isEmpty()) | 129 if (m_keyframesRuleMap.isEmpty()) |
123 return nullptr; | 130 return nullptr; |
124 | 131 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 181 } |
175 | 182 |
176 void ScopedStyleResolver::matchPageRules(PageRuleCollector& collector) | 183 void ScopedStyleResolver::matchPageRules(PageRuleCollector& collector) |
177 { | 184 { |
178 // Only consider the global author RuleSet for @page rules, as per the HTML5
spec. | 185 // Only consider the global author RuleSet for @page rules, as per the HTML5
spec. |
179 ASSERT(m_scope->rootNode().isDocumentNode()); | 186 ASSERT(m_scope->rootNode().isDocumentNode()); |
180 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) | 187 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) |
181 collector.matchPageRules(&m_authorStyleSheets[i]->contents()->ruleSet())
; | 188 collector.matchPageRules(&m_authorStyleSheets[i]->contents()->ruleSet())
; |
182 } | 189 } |
183 | 190 |
184 void ScopedStyleResolver::collectViewportRulesTo(ViewportStyleResolver* resolver
) const | |
185 { | |
186 if (!m_scope->rootNode().isDocumentNode()) | |
187 return; | |
188 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) | |
189 resolver->collectViewportRules(&m_authorStyleSheets[i]->contents()->rule
Set(), ViewportStyleResolver::AuthorOrigin); | |
190 } | |
191 | |
192 DEFINE_TRACE(ScopedStyleResolver) | 191 DEFINE_TRACE(ScopedStyleResolver) |
193 { | 192 { |
194 visitor->trace(m_scope); | 193 visitor->trace(m_scope); |
195 visitor->trace(m_authorStyleSheets); | 194 visitor->trace(m_authorStyleSheets); |
| 195 visitor->trace(m_viewportDependentMediaQueryResults); |
| 196 visitor->trace(m_deviceDependentMediaQueryResults); |
196 visitor->trace(m_keyframesRuleMap); | 197 visitor->trace(m_keyframesRuleMap); |
197 visitor->trace(m_treeBoundaryCrossingRuleSet); | 198 visitor->trace(m_treeBoundaryCrossingRuleSet); |
198 } | 199 } |
199 | 200 |
200 static void addRules(RuleSet* ruleSet, const HeapVector<MinimalRuleData>& rules) | 201 static void addRules(RuleSet* ruleSet, const HeapVector<MinimalRuleData>& rules) |
201 { | 202 { |
202 for (unsigned i = 0; i < rules.size(); ++i) { | 203 for (unsigned i = 0; i < rules.size(); ++i) { |
203 const MinimalRuleData& info = rules[i]; | 204 const MinimalRuleData& info = rules[i]; |
204 ruleSet->addRule(info.m_rule, info.m_selectorIndex, info.m_flags); | 205 ruleSet->addRule(info.m_rule, info.m_selectorIndex, info.m_flags); |
205 } | 206 } |
(...skipping 12 matching lines...) Expand all Loading... |
218 RuleSet* ruleSetForScope = RuleSet::create(); | 219 RuleSet* ruleSetForScope = RuleSet::create(); |
219 addRules(ruleSetForScope, authorRules.deepCombinatorOrShadowPseudoRules()); | 220 addRules(ruleSetForScope, authorRules.deepCombinatorOrShadowPseudoRules()); |
220 | 221 |
221 if (!isDocumentScope) { | 222 if (!isDocumentScope) { |
222 addRules(ruleSetForScope, authorRules.contentPseudoElementRules()); | 223 addRules(ruleSetForScope, authorRules.contentPseudoElementRules()); |
223 addRules(ruleSetForScope, authorRules.slottedPseudoElementRules()); | 224 addRules(ruleSetForScope, authorRules.slottedPseudoElementRules()); |
224 } | 225 } |
225 | 226 |
226 if (!m_treeBoundaryCrossingRuleSet) { | 227 if (!m_treeBoundaryCrossingRuleSet) { |
227 m_treeBoundaryCrossingRuleSet = new CSSStyleSheetRuleSubSet(); | 228 m_treeBoundaryCrossingRuleSet = new CSSStyleSheetRuleSubSet(); |
228 treeScope().document().styleResolver()->addTreeBoundaryCrossingScope(tre
eScope().rootNode()); | 229 treeScope().document().styleEngine().addTreeBoundaryCrossingScope(treeSc
ope().rootNode()); |
229 } | 230 } |
230 | 231 |
231 m_treeBoundaryCrossingRuleSet->append(RuleSubSet::create(parentStyleSheet, s
heetIndex, ruleSetForScope)); | 232 m_treeBoundaryCrossingRuleSet->append(RuleSubSet::create(parentStyleSheet, s
heetIndex, ruleSetForScope)); |
232 } | 233 } |
233 | 234 |
234 DEFINE_TRACE(ScopedStyleResolver::RuleSubSet) | 235 DEFINE_TRACE(ScopedStyleResolver::RuleSubSet) |
235 { | 236 { |
236 visitor->trace(m_parentStyleSheet); | 237 visitor->trace(m_parentStyleSheet); |
237 visitor->trace(m_ruleSet); | 238 visitor->trace(m_ruleSet); |
238 } | 239 } |
239 | 240 |
240 } // namespace blink | 241 } // namespace blink |
OLD | NEW |