OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "core/dom/ContainerNode.h" | 32 #include "core/dom/ContainerNode.h" |
33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
34 #include "core/dom/ElementTraversal.h" | 34 #include "core/dom/ElementTraversal.h" |
35 #include "core/dom/TreeScope.h" | 35 #include "core/dom/TreeScope.h" |
36 #include "core/dom/shadow/ShadowRoot.h" | 36 #include "core/dom/shadow/ShadowRoot.h" |
37 #include "core/html/HTMLStyleElement.h" | 37 #include "core/html/HTMLStyleElement.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 StyleSheetInvalidationAnalysis::StyleSheetInvalidationAnalysis(const TreeScope&
treeScope, const WillBeHeapVector<RawPtrWillBeMember<StyleSheetContents>>& sheet
s) | 41 StyleSheetInvalidationAnalysis::StyleSheetInvalidationAnalysis(const TreeScope&
treeScope, const WillBeHeapVector<RawPtrWillBeMember<StyleSheetContents>>& sheet
s) |
42 : m_treeScope(treeScope) | 42 : m_treeScope(&treeScope) |
43 { | 43 { |
44 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) | 44 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) |
45 analyzeStyleSheet(sheets[i]); | 45 analyzeStyleSheet(sheets[i]); |
46 } | 46 } |
47 | 47 |
48 static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
<StringImpl*>& idScopes, HashSet<StringImpl*>& classScopes) | 48 static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
<StringImpl*>& idScopes, HashSet<StringImpl*>& classScopes) |
49 { | 49 { |
50 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { | 50 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { |
51 const CSSSelector* scopeSelector = 0; | 51 const CSSSelector* scopeSelector = 0; |
52 // This picks the widest scope, not the narrowest, to minimize the numbe
r of found scopes. | 52 // This picks the widest scope, not the narrowest, to minimize the numbe
r of found scopes. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Then test if we actually have any of those in the tree at the moment. | 132 // Then test if we actually have any of those in the tree at the moment. |
133 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport>>& importRules = s
tyleSheetContents->importRules(); | 133 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport>>& importRules = s
tyleSheetContents->importRules(); |
134 for (unsigned i = 0; i < importRules.size(); ++i) { | 134 for (unsigned i = 0; i < importRules.size(); ++i) { |
135 if (!importRules[i]->styleSheet()) | 135 if (!importRules[i]->styleSheet()) |
136 continue; | 136 continue; |
137 analyzeStyleSheet(importRules[i]->styleSheet()); | 137 analyzeStyleSheet(importRules[i]->styleSheet()); |
138 if (m_dirtiesAllStyle) | 138 if (m_dirtiesAllStyle) |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 if (m_treeScope.rootNode().isShadowRoot()) { | 142 if (m_treeScope->rootNode().isShadowRoot()) { |
143 if (hasDistributedRule(styleSheetContents)) | 143 if (hasDistributedRule(styleSheetContents)) |
144 m_hasDistributedRules = true; | 144 m_hasDistributedRules = true; |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase>>& rules = styleShee
tContents->childRules(); | 148 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase>>& rules = styleShee
tContents->childRules(); |
149 for (unsigned i = 0; i < rules.size(); i++) { | 149 for (unsigned i = 0; i < rules.size(); i++) { |
150 StyleRuleBase* rule = rules[i].get(); | 150 StyleRuleBase* rule = rules[i].get(); |
151 if (!rule->isStyleRule()) { | 151 if (!rule->isStyleRule()) { |
152 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { | 152 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { |
(...skipping 29 matching lines...) Expand all Loading... |
182 ContainerNode* host = root.host(); | 182 ContainerNode* host = root.host(); |
183 while (host->isInShadowTree()) | 183 while (host->isInShadowTree()) |
184 host = host->containingShadowRoot()->host(); | 184 host = host->containingShadowRoot()->host(); |
185 return host; | 185 return host; |
186 } | 186 } |
187 | 187 |
188 void StyleSheetInvalidationAnalysis::invalidateStyle() | 188 void StyleSheetInvalidationAnalysis::invalidateStyle() |
189 { | 189 { |
190 ASSERT(!m_dirtiesAllStyle); | 190 ASSERT(!m_dirtiesAllStyle); |
191 | 191 |
192 if (m_treeScope.rootNode().isShadowRoot()) { | 192 if (m_treeScope->rootNode().isShadowRoot()) { |
193 ContainerNode* invalidationRoot = &m_treeScope.rootNode(); | 193 ContainerNode* invalidationRoot = &m_treeScope->rootNode(); |
194 if (m_hasDistributedRules) | 194 if (m_hasDistributedRules) |
195 invalidationRoot = outermostShadowHost(*toShadowRoot(invalidationRoo
t)); | 195 invalidationRoot = outermostShadowHost(*toShadowRoot(invalidationRoo
t)); |
196 invalidationRoot->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeRea
sonForTracing::create(StyleChangeReason::StyleSheetChange)); | 196 invalidationRoot->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeRea
sonForTracing::create(StyleChangeReason::StyleSheetChange)); |
197 return; | 197 return; |
198 } | 198 } |
199 | 199 |
200 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) | 200 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) |
201 return; | 201 return; |
202 Element* element = ElementTraversal::firstWithin(m_treeScope.document()); | 202 Element* element = ElementTraversal::firstWithin(m_treeScope->document()); |
203 while (element) { | 203 while (element) { |
204 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { | 204 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { |
205 element->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonFo
rTracing::create(StyleChangeReason::StyleSheetChange)); | 205 element->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonFo
rTracing::create(StyleChangeReason::StyleSheetChange)); |
206 // The whole subtree is now invalidated, we can skip to the next sib
ling. | 206 // The whole subtree is now invalidated, we can skip to the next sib
ling. |
207 element = ElementTraversal::nextSkippingChildren(*element); | 207 element = ElementTraversal::nextSkippingChildren(*element); |
208 continue; | 208 continue; |
209 } | 209 } |
210 element = ElementTraversal::next(*element); | 210 element = ElementTraversal::next(*element); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 } | 214 } |
OLD | NEW |