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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/css/StyleInvalidationAnalysis.h" | 27 #include "core/css/invalidation/StyleSheetInvalidationAnalysis.h" |
28 | 28 |
29 #include "core/css/CSSSelectorList.h" | 29 #include "core/css/CSSSelectorList.h" |
30 #include "core/css/StyleRuleImport.h" | 30 #include "core/css/StyleRuleImport.h" |
31 #include "core/css/StyleSheetContents.h" | 31 #include "core/css/StyleSheetContents.h" |
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/shadow/ShadowRoot.h" | 35 #include "core/dom/shadow/ShadowRoot.h" |
36 #include "core/html/HTMLStyleElement.h" | 36 #include "core/html/HTMLStyleElement.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 StyleInvalidationAnalysis::StyleInvalidationAnalysis(const WillBeHeapVector<RawP
trWillBeMember<StyleSheetContents> >& sheets) | 40 StyleSheetInvalidationAnalysis::StyleSheetInvalidationAnalysis(const WillBeHeapV
ector<RawPtrWillBeMember<StyleSheetContents> >& sheets) |
41 : m_dirtiesAllStyle(false) | 41 : m_dirtiesAllStyle(false) |
42 { | 42 { |
43 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) | 43 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) |
44 analyzeStyleSheet(sheets[i]); | 44 analyzeStyleSheet(sheets[i]); |
45 } | 45 } |
46 | 46 |
47 static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
<StringImpl*>& idScopes, HashSet<StringImpl*>& classScopes) | 47 static bool determineSelectorScopes(const CSSSelectorList& selectorList, HashSet
<StringImpl*>& idScopes, HashSet<StringImpl*>& classScopes) |
48 { | 48 { |
49 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { | 49 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { |
50 const CSSSelector* scopeSelector = 0; | 50 const CSSSelector* scopeSelector = 0; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 case StyleRule::Unknown: | 134 case StyleRule::Unknown: |
135 case StyleRule::Charset: | 135 case StyleRule::Charset: |
136 case StyleRule::Keyframe: | 136 case StyleRule::Keyframe: |
137 case StyleRule::Style: | 137 case StyleRule::Style: |
138 break; | 138 break; |
139 } | 139 } |
140 ASSERT_NOT_REACHED(); | 140 ASSERT_NOT_REACHED(); |
141 return true; | 141 return true; |
142 } | 142 } |
143 | 143 |
144 void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheet
Contents) | 144 void StyleSheetInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* style
SheetContents) |
145 { | 145 { |
146 ASSERT(!styleSheetContents->isLoading()); | 146 ASSERT(!styleSheetContents->isLoading()); |
147 | 147 |
148 // See if all rules on the sheet are scoped to some specific ids or classes. | 148 // See if all rules on the sheet are scoped to some specific ids or classes. |
149 // Then test if we actually have any of those in the tree at the moment. | 149 // Then test if we actually have any of those in the tree at the moment. |
150 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport> >& importRules =
styleSheetContents->importRules(); | 150 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport> >& importRules =
styleSheetContents->importRules(); |
151 for (unsigned i = 0; i < importRules.size(); ++i) { | 151 for (unsigned i = 0; i < importRules.size(); ++i) { |
152 if (!importRules[i]->styleSheet()) | 152 if (!importRules[i]->styleSheet()) |
153 continue; | 153 continue; |
154 analyzeStyleSheet(importRules[i]->styleSheet()); | 154 analyzeStyleSheet(importRules[i]->styleSheet()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 if (classScopes.isEmpty() || !element->hasClass()) | 188 if (classScopes.isEmpty() || !element->hasClass()) |
189 return false; | 189 return false; |
190 const SpaceSplitString& classNames = element->classNames(); | 190 const SpaceSplitString& classNames = element->classNames(); |
191 for (unsigned i = 0; i < classNames.size(); ++i) { | 191 for (unsigned i = 0; i < classNames.size(); ++i) { |
192 if (classScopes.contains(classNames[i].impl())) | 192 if (classScopes.contains(classNames[i].impl())) |
193 return true; | 193 return true; |
194 } | 194 } |
195 return false; | 195 return false; |
196 } | 196 } |
197 | 197 |
198 void StyleInvalidationAnalysis::invalidateStyle(Document& document) | 198 void StyleSheetInvalidationAnalysis::invalidateStyle(Document& document) |
199 { | 199 { |
200 ASSERT(!m_dirtiesAllStyle); | 200 ASSERT(!m_dirtiesAllStyle); |
201 | 201 |
202 if (!m_scopingNodes.isEmpty()) { | 202 if (!m_scopingNodes.isEmpty()) { |
203 for (unsigned i = 0; i < m_scopingNodes.size(); ++i) | 203 for (unsigned i = 0; i < m_scopingNodes.size(); ++i) |
204 m_scopingNodes.at(i)->setNeedsStyleRecalc(SubtreeStyleChange); | 204 m_scopingNodes.at(i)->setNeedsStyleRecalc(SubtreeStyleChange); |
205 } | 205 } |
206 | 206 |
207 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) | 207 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) |
208 return; | 208 return; |
209 Element* element = ElementTraversal::firstWithin(document); | 209 Element* element = ElementTraversal::firstWithin(document); |
210 while (element) { | 210 while (element) { |
211 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { | 211 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { |
212 element->setNeedsStyleRecalc(SubtreeStyleChange); | 212 element->setNeedsStyleRecalc(SubtreeStyleChange); |
213 // The whole subtree is now invalidated, we can skip to the next sib
ling. | 213 // The whole subtree is now invalidated, we can skip to the next sib
ling. |
214 element = ElementTraversal::nextSkippingChildren(*element); | 214 element = ElementTraversal::nextSkippingChildren(*element); |
215 continue; | 215 continue; |
216 } | 216 } |
217 element = ElementTraversal::next(*element); | 217 element = ElementTraversal::next(*element); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 } | 221 } |
OLD | NEW |