| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // HTMLTemplateElement's document, because those documents have no frame. | 74 // HTMLTemplateElement's document, because those documents have no frame. |
| 75 m_fontSelector = CSSFontSelector::create(&document); | 75 m_fontSelector = CSSFontSelector::create(&document); |
| 76 m_fontSelector->registerForInvalidationCallbacks(this); | 76 m_fontSelector->registerForInvalidationCallbacks(this); |
| 77 } | 77 } |
| 78 if (document.isInMainFrame()) | 78 if (document.isInMainFrame()) |
| 79 m_viewportResolver = ViewportStyleResolver::create(document); | 79 m_viewportResolver = ViewportStyleResolver::create(document); |
| 80 } | 80 } |
| 81 | 81 |
| 82 StyleEngine::~StyleEngine() {} | 82 StyleEngine::~StyleEngine() {} |
| 83 | 83 |
| 84 static bool isStyleElement(Node& node) { | |
| 85 return isHTMLStyleElement(node) || isSVGStyleElement(node); | |
| 86 } | |
| 87 | |
| 88 inline Document* StyleEngine::master() { | 84 inline Document* StyleEngine::master() { |
| 89 if (isMaster()) | 85 if (isMaster()) |
| 90 return m_document; | 86 return m_document; |
| 91 HTMLImportsController* import = document().importsController(); | 87 HTMLImportsController* import = document().importsController(); |
| 92 // Document::import() can return null while executing its destructor. | 88 // Document::import() can return null while executing its destructor. |
| 93 if (!import) | 89 if (!import) |
| 94 return nullptr; | 90 return nullptr; |
| 95 return import->master(); | 91 return import->master(); |
| 96 } | 92 } |
| 97 | 93 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 m_pendingScriptBlockingStylesheets++; | 148 m_pendingScriptBlockingStylesheets++; |
| 153 | 149 |
| 154 context.addingPendingSheet(document()); | 150 context.addingPendingSheet(document()); |
| 155 if (context.addedPendingSheetBeforeBody()) | 151 if (context.addedPendingSheetBeforeBody()) |
| 156 m_pendingRenderBlockingStylesheets++; | 152 m_pendingRenderBlockingStylesheets++; |
| 157 } | 153 } |
| 158 | 154 |
| 159 // This method is called whenever a top-level stylesheet has finished loading. | 155 // This method is called whenever a top-level stylesheet has finished loading. |
| 160 void StyleEngine::removePendingSheet(Node& styleSheetCandidateNode, | 156 void StyleEngine::removePendingSheet(Node& styleSheetCandidateNode, |
| 161 const StyleEngineContext& context) { | 157 const StyleEngineContext& context) { |
| 162 TreeScope* treeScope = isStyleElement(styleSheetCandidateNode) | |
| 163 ? &styleSheetCandidateNode.treeScope() | |
| 164 : m_document.get(); | |
| 165 if (styleSheetCandidateNode.isConnected()) | 158 if (styleSheetCandidateNode.isConnected()) |
| 166 markTreeScopeDirty(*treeScope); | 159 markTreeScopeDirty(styleSheetCandidateNode.treeScope()); |
| 167 | 160 |
| 168 if (context.addedPendingSheetBeforeBody()) { | 161 if (context.addedPendingSheetBeforeBody()) { |
| 169 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0); | 162 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0); |
| 170 m_pendingRenderBlockingStylesheets--; | 163 m_pendingRenderBlockingStylesheets--; |
| 171 } | 164 } |
| 172 | 165 |
| 173 // Make sure we knew this sheet was pending, and that our count isn't out of | 166 // Make sure we knew this sheet was pending, and that our count isn't out of |
| 174 // sync. | 167 // sync. |
| 175 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0); | 168 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0); |
| 176 | 169 |
| 177 m_pendingScriptBlockingStylesheets--; | 170 m_pendingScriptBlockingStylesheets--; |
| 178 if (m_pendingScriptBlockingStylesheets) | 171 if (m_pendingScriptBlockingStylesheets) |
| 179 return; | 172 return; |
| 180 | 173 |
| 181 document().didRemoveAllPendingStylesheet(); | 174 document().didRemoveAllPendingStylesheet(); |
| 182 } | 175 } |
| 183 | 176 |
| 184 void StyleEngine::setNeedsActiveStyleUpdate( | 177 void StyleEngine::setNeedsActiveStyleUpdate( |
| 185 StyleSheet* sheet, | 178 StyleSheet* sheet, |
| 186 StyleResolverUpdateMode updateMode) { | 179 StyleResolverUpdateMode updateMode) { |
| 187 // resolverChanged() is called for inactive non-master documents because | 180 // resolverChanged() is called for inactive non-master documents because |
| 188 // import documents are inactive documents. resolverChanged() for imports | 181 // import documents are inactive documents. resolverChanged() for imports |
| 189 // will call resolverChanged() for the master document and update the active | 182 // will call resolverChanged() for the master document and update the active |
| 190 // stylesheets including the ones from the import. | 183 // stylesheets including the ones from the import. |
| 191 if (!document().isActive() && isMaster()) | 184 if (!document().isActive() && isMaster()) |
| 192 return; | 185 return; |
| 193 | 186 |
| 194 if (sheet && document().isActive()) { | 187 if (sheet && document().isActive()) { |
| 195 Node* node = sheet->ownerNode(); | 188 Node* node = sheet->ownerNode(); |
| 196 if (node && node->isConnected()) { | 189 if (node && node->isConnected()) |
| 197 TreeScope& treeScope = | 190 markTreeScopeDirty(node->treeScope()); |
| 198 isStyleElement(*node) ? node->treeScope() : *m_document; | |
| 199 DCHECK(isStyleElement(*node) || node->treeScope() == m_document); | |
| 200 markTreeScopeDirty(treeScope); | |
| 201 } | |
| 202 } | 191 } |
| 203 | 192 |
| 204 resolverChanged(updateMode); | 193 resolverChanged(updateMode); |
| 205 } | 194 } |
| 206 | 195 |
| 207 void StyleEngine::addStyleSheetCandidateNode(Node& node) { | 196 void StyleEngine::addStyleSheetCandidateNode(Node& node) { |
| 208 if (!node.isConnected() || document().isDetached()) | 197 if (!node.isConnected() || document().isDetached()) |
| 209 return; | 198 return; |
| 210 | 199 |
| 211 DCHECK(!isXSLStyleSheet(node)); | 200 DCHECK(!isXSLStyleSheet(node)); |
| 212 TreeScope& treeScope = node.treeScope(); | 201 TreeScope& treeScope = node.treeScope(); |
| 213 TreeScopeStyleSheetCollection* collection = | 202 TreeScopeStyleSheetCollection* collection = |
| 214 ensureStyleSheetCollectionFor(treeScope); | 203 ensureStyleSheetCollectionFor(treeScope); |
| 215 DCHECK(collection); | 204 DCHECK(collection); |
| 216 collection->addStyleSheetCandidateNode(node); | 205 collection->addStyleSheetCandidateNode(node); |
| 217 | 206 |
| 218 markTreeScopeDirty(treeScope); | 207 markTreeScopeDirty(treeScope); |
| 219 if (treeScope != m_document) | 208 if (treeScope != m_document) |
| 220 m_activeTreeScopes.add(&treeScope); | 209 m_activeTreeScopes.add(&treeScope); |
| 221 } | 210 } |
| 222 | 211 |
| 223 void StyleEngine::removeStyleSheetCandidateNode(Node& node) { | 212 void StyleEngine::removeStyleSheetCandidateNode(Node& node) { |
| 224 removeStyleSheetCandidateNode(node, *m_document); | 213 removeStyleSheetCandidateNode(node, *m_document); |
| 225 } | 214 } |
| 226 | 215 |
| 227 void StyleEngine::removeStyleSheetCandidateNode(Node& node, | 216 void StyleEngine::removeStyleSheetCandidateNode(Node& node, |
| 228 TreeScope& treeScope) { | 217 TreeScope& treeScope) { |
| 229 DCHECK(isStyleElement(node) || treeScope == m_document); | |
| 230 DCHECK(!isXSLStyleSheet(node)); | 218 DCHECK(!isXSLStyleSheet(node)); |
| 231 | 219 |
| 232 TreeScopeStyleSheetCollection* collection = | 220 TreeScopeStyleSheetCollection* collection = |
| 233 styleSheetCollectionFor(treeScope); | 221 styleSheetCollectionFor(treeScope); |
| 234 // After detaching document, collection could be null. In the case, | 222 // After detaching document, collection could be null. In the case, |
| 235 // we should not update anything. Instead, just return. | 223 // we should not update anything. Instead, just return. |
| 236 if (!collection) | 224 if (!collection) |
| 237 return; | 225 return; |
| 238 collection->removeStyleSheetCandidateNode(node); | 226 collection->removeStyleSheetCandidateNode(node); |
| 239 | 227 |
| 240 markTreeScopeDirty(treeScope); | 228 markTreeScopeDirty(treeScope); |
| 241 } | 229 } |
| 242 | 230 |
| 243 void StyleEngine::modifiedStyleSheetCandidateNode(Node& node) { | 231 void StyleEngine::modifiedStyleSheetCandidateNode(Node& node) { |
| 244 if (!node.isConnected()) | 232 if (!node.isConnected()) |
| 245 return; | 233 return; |
| 246 | 234 |
| 247 TreeScope& treeScope = isStyleElement(node) ? node.treeScope() : *m_document; | 235 markTreeScopeDirty(node.treeScope()); |
| 248 DCHECK(isStyleElement(node) || treeScope == m_document); | |
| 249 markTreeScopeDirty(treeScope); | |
| 250 resolverChanged(AnalyzedStyleUpdate); | 236 resolverChanged(AnalyzedStyleUpdate); |
| 251 } | 237 } |
| 252 | 238 |
| 253 void StyleEngine::watchedSelectorsChanged() { | 239 void StyleEngine::watchedSelectorsChanged() { |
| 254 m_globalRuleSet.initWatchedSelectorsRuleSet(document()); | 240 m_globalRuleSet.initWatchedSelectorsRuleSet(document()); |
| 255 // TODO(rune@opera.com): Should be able to use RuleSetInvalidation here. | 241 // TODO(rune@opera.com): Should be able to use RuleSetInvalidation here. |
| 256 document().setNeedsStyleRecalc(SubtreeStyleChange, | 242 document().setNeedsStyleRecalc(SubtreeStyleChange, |
| 257 StyleChangeReasonForTracing::create( | 243 StyleChangeReasonForTracing::create( |
| 258 StyleChangeReason::DeclarativeContent)); | 244 StyleChangeReason::DeclarativeContent)); |
| 259 } | 245 } |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 } | 1040 } |
| 1055 | 1041 |
| 1056 DEFINE_TRACE_WRAPPERS(StyleEngine) { | 1042 DEFINE_TRACE_WRAPPERS(StyleEngine) { |
| 1057 for (auto sheet : m_injectedAuthorStyleSheets) { | 1043 for (auto sheet : m_injectedAuthorStyleSheets) { |
| 1058 visitor->traceWrappers(sheet); | 1044 visitor->traceWrappers(sheet); |
| 1059 } | 1045 } |
| 1060 visitor->traceWrappers(m_documentStyleSheetCollection); | 1046 visitor->traceWrappers(m_documentStyleSheetCollection); |
| 1061 } | 1047 } |
| 1062 | 1048 |
| 1063 } // namespace blink | 1049 } // namespace blink |
| OLD | NEW |