OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // HTMLTemplateElement's document, because those documents have no frame. | 75 // HTMLTemplateElement's document, because those documents have no frame. |
76 m_fontSelector = CSSFontSelector::create(&document); | 76 m_fontSelector = CSSFontSelector::create(&document); |
77 m_fontSelector->registerForInvalidationCallbacks(this); | 77 m_fontSelector->registerForInvalidationCallbacks(this); |
78 } | 78 } |
79 if (document.isInMainFrame()) | 79 if (document.isInMainFrame()) |
80 m_viewportResolver = ViewportStyleResolver::create(document); | 80 m_viewportResolver = ViewportStyleResolver::create(document); |
81 } | 81 } |
82 | 82 |
83 StyleEngine::~StyleEngine() {} | 83 StyleEngine::~StyleEngine() {} |
84 | 84 |
85 static bool isStyleElement(Node& node) { | |
86 return isHTMLStyleElement(node) || isSVGStyleElement(node); | |
87 } | |
88 | |
89 inline Document* StyleEngine::master() { | 85 inline Document* StyleEngine::master() { |
90 if (isMaster()) | 86 if (isMaster()) |
91 return m_document; | 87 return m_document; |
92 HTMLImportsController* import = document().importsController(); | 88 HTMLImportsController* import = document().importsController(); |
93 // Document::import() can return null while executing its destructor. | 89 // Document::import() can return null while executing its destructor. |
94 if (!import) | 90 if (!import) |
95 return nullptr; | 91 return nullptr; |
96 return import->master(); | 92 return import->master(); |
97 } | 93 } |
98 | 94 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 m_pendingScriptBlockingStylesheets++; | 149 m_pendingScriptBlockingStylesheets++; |
154 | 150 |
155 context.addingPendingSheet(document()); | 151 context.addingPendingSheet(document()); |
156 if (context.addedPendingSheetBeforeBody()) | 152 if (context.addedPendingSheetBeforeBody()) |
157 m_pendingRenderBlockingStylesheets++; | 153 m_pendingRenderBlockingStylesheets++; |
158 } | 154 } |
159 | 155 |
160 // This method is called whenever a top-level stylesheet has finished loading. | 156 // This method is called whenever a top-level stylesheet has finished loading. |
161 void StyleEngine::removePendingSheet(Node& styleSheetCandidateNode, | 157 void StyleEngine::removePendingSheet(Node& styleSheetCandidateNode, |
162 const StyleEngineContext& context) { | 158 const StyleEngineContext& context) { |
163 TreeScope* treeScope = isStyleElement(styleSheetCandidateNode) | |
164 ? &styleSheetCandidateNode.treeScope() | |
165 : m_document.get(); | |
166 if (styleSheetCandidateNode.isConnected()) | 159 if (styleSheetCandidateNode.isConnected()) |
167 markTreeScopeDirty(*treeScope); | 160 markTreeScopeDirty(styleSheetCandidateNode.treeScope()); |
168 | 161 |
169 if (context.addedPendingSheetBeforeBody()) { | 162 if (context.addedPendingSheetBeforeBody()) { |
170 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0); | 163 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0); |
171 m_pendingRenderBlockingStylesheets--; | 164 m_pendingRenderBlockingStylesheets--; |
172 } | 165 } |
173 | 166 |
174 // Make sure we knew this sheet was pending, and that our count isn't out of | 167 // Make sure we knew this sheet was pending, and that our count isn't out of |
175 // sync. | 168 // sync. |
176 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0); | 169 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0); |
177 | 170 |
178 m_pendingScriptBlockingStylesheets--; | 171 m_pendingScriptBlockingStylesheets--; |
179 if (m_pendingScriptBlockingStylesheets) | 172 if (m_pendingScriptBlockingStylesheets) |
180 return; | 173 return; |
181 | 174 |
182 document().didRemoveAllPendingStylesheet(); | 175 document().didRemoveAllPendingStylesheet(); |
183 } | 176 } |
184 | 177 |
185 void StyleEngine::setNeedsActiveStyleUpdate( | 178 void StyleEngine::setNeedsActiveStyleUpdate( |
186 StyleSheet* sheet, | 179 StyleSheet* sheet, |
187 StyleResolverUpdateMode updateMode) { | 180 StyleResolverUpdateMode updateMode) { |
188 // resolverChanged() is called for inactive non-master documents because | 181 // resolverChanged() is called for inactive non-master documents because |
189 // import documents are inactive documents. resolverChanged() for imports | 182 // import documents are inactive documents. resolverChanged() for imports |
190 // will call resolverChanged() for the master document and update the active | 183 // will call resolverChanged() for the master document and update the active |
191 // stylesheets including the ones from the import. | 184 // stylesheets including the ones from the import. |
192 if (!document().isActive() && isMaster()) | 185 if (!document().isActive() && isMaster()) |
193 return; | 186 return; |
194 | 187 |
195 if (sheet && document().isActive()) { | 188 if (sheet && document().isActive()) { |
196 Node* node = sheet->ownerNode(); | 189 Node* node = sheet->ownerNode(); |
197 if (node && node->isConnected()) { | 190 if (node && node->isConnected()) |
198 TreeScope& treeScope = | 191 markTreeScopeDirty(node->treeScope()); |
199 isStyleElement(*node) ? node->treeScope() : *m_document; | |
200 DCHECK(isStyleElement(*node) || node->treeScope() == m_document); | |
201 markTreeScopeDirty(treeScope); | |
202 } | |
203 } | 192 } |
204 | 193 |
205 resolverChanged(updateMode); | 194 resolverChanged(updateMode); |
206 } | 195 } |
207 | 196 |
208 void StyleEngine::addStyleSheetCandidateNode(Node& node) { | 197 void StyleEngine::addStyleSheetCandidateNode(Node& node) { |
209 if (!node.isConnected() || document().isDetached()) | 198 if (!node.isConnected() || document().isDetached()) |
210 return; | 199 return; |
211 | 200 |
212 DCHECK(!isXSLStyleSheet(node)); | 201 DCHECK(!isXSLStyleSheet(node)); |
213 TreeScope& treeScope = node.treeScope(); | 202 TreeScope& treeScope = node.treeScope(); |
214 TreeScopeStyleSheetCollection* collection = | 203 TreeScopeStyleSheetCollection* collection = |
215 ensureStyleSheetCollectionFor(treeScope); | 204 ensureStyleSheetCollectionFor(treeScope); |
216 DCHECK(collection); | 205 DCHECK(collection); |
217 collection->addStyleSheetCandidateNode(node); | 206 collection->addStyleSheetCandidateNode(node); |
218 | 207 |
219 markTreeScopeDirty(treeScope); | 208 markTreeScopeDirty(treeScope); |
220 if (treeScope != m_document) | 209 if (treeScope != m_document) |
221 m_activeTreeScopes.add(&treeScope); | 210 m_activeTreeScopes.add(&treeScope); |
222 } | 211 } |
223 | 212 |
224 void StyleEngine::removeStyleSheetCandidateNode(Node& node) { | 213 void StyleEngine::removeStyleSheetCandidateNode(Node& node) { |
225 removeStyleSheetCandidateNode(node, *m_document); | 214 removeStyleSheetCandidateNode(node, *m_document); |
226 } | 215 } |
227 | 216 |
228 void StyleEngine::removeStyleSheetCandidateNode(Node& node, | 217 void StyleEngine::removeStyleSheetCandidateNode(Node& node, |
229 TreeScope& treeScope) { | 218 TreeScope& treeScope) { |
230 DCHECK(isStyleElement(node) || treeScope == m_document); | |
231 DCHECK(!isXSLStyleSheet(node)); | 219 DCHECK(!isXSLStyleSheet(node)); |
232 | 220 |
233 TreeScopeStyleSheetCollection* collection = | 221 TreeScopeStyleSheetCollection* collection = |
234 styleSheetCollectionFor(treeScope); | 222 styleSheetCollectionFor(treeScope); |
235 // After detaching document, collection could be null. In the case, | 223 // After detaching document, collection could be null. In the case, |
236 // we should not update anything. Instead, just return. | 224 // we should not update anything. Instead, just return. |
237 if (!collection) | 225 if (!collection) |
238 return; | 226 return; |
239 collection->removeStyleSheetCandidateNode(node); | 227 collection->removeStyleSheetCandidateNode(node); |
240 | 228 |
241 markTreeScopeDirty(treeScope); | 229 markTreeScopeDirty(treeScope); |
242 } | 230 } |
243 | 231 |
244 void StyleEngine::modifiedStyleSheetCandidateNode(Node& node) { | 232 void StyleEngine::modifiedStyleSheetCandidateNode(Node& node) { |
245 if (!node.isConnected()) | 233 if (!node.isConnected()) |
246 return; | 234 return; |
247 | 235 |
248 TreeScope& treeScope = isStyleElement(node) ? node.treeScope() : *m_document; | 236 markTreeScopeDirty(node.treeScope()); |
249 DCHECK(isStyleElement(node) || treeScope == m_document); | |
250 markTreeScopeDirty(treeScope); | |
251 resolverChanged(AnalyzedStyleUpdate); | 237 resolverChanged(AnalyzedStyleUpdate); |
252 } | 238 } |
253 | 239 |
254 void StyleEngine::watchedSelectorsChanged() { | 240 void StyleEngine::watchedSelectorsChanged() { |
255 m_globalRuleSet.initWatchedSelectorsRuleSet(document()); | 241 m_globalRuleSet.initWatchedSelectorsRuleSet(document()); |
256 // TODO(rune@opera.com): Should be able to use RuleSetInvalidation here. | 242 // TODO(rune@opera.com): Should be able to use RuleSetInvalidation here. |
257 document().setNeedsStyleRecalc(SubtreeStyleChange, | 243 document().setNeedsStyleRecalc(SubtreeStyleChange, |
258 StyleChangeReasonForTracing::create( | 244 StyleChangeReasonForTracing::create( |
259 StyleChangeReason::DeclarativeContent)); | 245 StyleChangeReason::DeclarativeContent)); |
260 } | 246 } |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 } | 1051 } |
1066 | 1052 |
1067 DEFINE_TRACE_WRAPPERS(StyleEngine) { | 1053 DEFINE_TRACE_WRAPPERS(StyleEngine) { |
1068 for (auto sheet : m_injectedAuthorStyleSheets) { | 1054 for (auto sheet : m_injectedAuthorStyleSheets) { |
1069 visitor->traceWrappers(sheet); | 1055 visitor->traceWrappers(sheet); |
1070 } | 1056 } |
1071 visitor->traceWrappers(m_documentStyleSheetCollection); | 1057 visitor->traceWrappers(m_documentStyleSheetCollection); |
1072 } | 1058 } |
1073 | 1059 |
1074 } // namespace blink | 1060 } // namespace blink |
OLD | NEW |