| 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 r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. |
| 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "sky/engine/config.h" | 28 #include "sky/engine/config.h" |
| 29 #include "sky/engine/core/dom/StyleEngine.h" | 29 #include "sky/engine/core/dom/StyleEngine.h" |
| 30 | 30 |
| 31 #include "sky/engine/core/css/CSSFontSelector.h" | 31 #include "sky/engine/core/css/CSSFontSelector.h" |
| 32 #include "sky/engine/core/css/CSSStyleSheet.h" | 32 #include "sky/engine/core/css/CSSStyleSheet.h" |
| 33 #include "sky/engine/core/css/FontFaceCache.h" | 33 #include "sky/engine/core/css/FontFaceCache.h" |
| 34 #include "sky/engine/core/css/StyleSheetContents.h" | 34 #include "sky/engine/core/css/StyleSheetContents.h" |
| 35 #include "sky/engine/core/dom/Element.h" | 35 #include "sky/engine/core/dom/Element.h" |
| 36 #include "sky/engine/core/dom/ShadowTreeStyleSheetCollection.h" | 36 #include "sky/engine/core/dom/StyleSheetCollection.h" |
| 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 38 #include "sky/engine/core/frame/Settings.h" | 38 #include "sky/engine/core/frame/Settings.h" |
| 39 #include "sky/engine/core/html/HTMLStyleElement.h" | 39 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 40 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 40 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 41 #include "sky/engine/core/page/Page.h" | 41 #include "sky/engine/core/page/Page.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 StyleEngine::StyleEngine(Document& document) | 45 StyleEngine::StyleEngine(Document& document) |
| 46 : m_document(&document) | 46 : m_document(&document) |
| 47 , m_isMaster(!document.importsController() || document.importsController()->
master() == &document) | 47 , m_isMaster(!document.importsController() || document.importsController()->
master() == &document) |
| 48 , m_documentStyleSheetCollection(DocumentStyleSheetCollection::create(docume
nt)) | 48 , m_documentStyleSheetCollection(StyleSheetCollection::create(document)) |
| 49 , m_documentScopeDirty(true) | 49 , m_documentScopeDirty(true) |
| 50 , m_ignorePendingStylesheets(false) | 50 , m_ignorePendingStylesheets(false) |
| 51 // We don't need to create CSSFontSelector for imported document or | 51 // We don't need to create CSSFontSelector for imported document or |
| 52 // HTMLTemplateElement's document, because those documents have no frame. | 52 // HTMLTemplateElement's document, because those documents have no frame. |
| 53 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) | 53 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) |
| 54 { | 54 { |
| 55 if (m_fontSelector) | 55 if (m_fontSelector) |
| 56 m_fontSelector->registerForInvalidationCallbacks(this); | 56 m_fontSelector->registerForInvalidationCallbacks(this); |
| 57 } | 57 } |
| 58 | 58 |
| 59 StyleEngine::~StyleEngine() | 59 StyleEngine::~StyleEngine() |
| 60 { | 60 { |
| 61 } | 61 } |
| 62 | 62 |
| 63 #if !ENABLE(OILPAN) | |
| 64 void StyleEngine::detachFromDocument() | 63 void StyleEngine::detachFromDocument() |
| 65 { | 64 { |
| 66 // Cleanup is performed eagerly when the StyleEngine is removed from the | 65 // Cleanup is performed eagerly when the StyleEngine is removed from the |
| 67 // document. The StyleEngine is unreachable after this, since only the | 66 // document. The StyleEngine is unreachable after this, since only the |
| 68 // document has a reference to it. | 67 // document has a reference to it. |
| 69 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | |
| 70 m_authorStyleSheets[i]->clearOwnerNode(); | |
| 71 | 68 |
| 72 if (m_fontSelector) { | 69 if (m_fontSelector) { |
| 73 m_fontSelector->clearDocument(); | 70 m_fontSelector->clearDocument(); |
| 74 m_fontSelector->unregisterForInvalidationCallbacks(this); | 71 m_fontSelector->unregisterForInvalidationCallbacks(this); |
| 75 } | 72 } |
| 76 | 73 |
| 77 // Decrement reference counts for things we could be keeping alive. | 74 // Decrement reference counts for things we could be keeping alive. |
| 78 m_fontSelector.clear(); | 75 m_fontSelector.clear(); |
| 79 m_resolver.clear(); | 76 m_resolver.clear(); |
| 80 m_styleSheetCollectionMap.clear(); | 77 m_styleSheetCollectionMap.clear(); |
| 81 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | 78 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) |
| 82 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); | 79 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); |
| 83 m_scopedStyleResolvers.clear(); | 80 m_scopedStyleResolvers.clear(); |
| 84 } | 81 } |
| 85 #endif | |
| 86 | 82 |
| 87 inline Document* StyleEngine::master() | 83 inline Document* StyleEngine::master() |
| 88 { | 84 { |
| 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 if (!import) // Document::import() can return null while executing its destr
uctor. | 88 if (!import) // Document::import() can return null while executing its destr
uctor. |
| 93 return 0; | 89 return 0; |
| 94 return import->master(); | 90 return import->master(); |
| 95 } | 91 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { | 117 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { |
| 122 treeScopes.insertBefore(followingTreeScope, treeScope); | 118 treeScopes.insertBefore(followingTreeScope, treeScope); |
| 123 return; | 119 return; |
| 124 } | 120 } |
| 125 followingTreeScope = n; | 121 followingTreeScope = n; |
| 126 } while (it != begin); | 122 } while (it != begin); |
| 127 | 123 |
| 128 treeScopes.insertBefore(followingTreeScope, treeScope); | 124 treeScopes.insertBefore(followingTreeScope, treeScope); |
| 129 } | 125 } |
| 130 | 126 |
| 131 TreeScopeStyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeSc
ope& treeScope) | 127 StyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeScope& tree
Scope) |
| 132 { | 128 { |
| 133 if (treeScope == m_document) | 129 if (treeScope == m_document) |
| 134 return documentStyleSheetCollection(); | 130 return documentStyleSheetCollection(); |
| 135 | 131 |
| 136 StyleSheetCollectionMap::AddResult result = m_styleSheetCollectionMap.add(&t
reeScope, nullptr); | 132 StyleSheetCollectionMap::AddResult result = m_styleSheetCollectionMap.add(&t
reeScope, nullptr); |
| 137 if (result.isNewEntry) | 133 if (result.isNewEntry) |
| 138 result.storedValue->value = adoptPtr(new ShadowTreeStyleSheetCollection(
toShadowRoot(treeScope))); | 134 result.storedValue->value = StyleSheetCollection::create(treeScope); |
| 139 return result.storedValue->value.get(); | 135 return result.storedValue->value.get(); |
| 140 } | 136 } |
| 141 | 137 |
| 142 TreeScopeStyleSheetCollection* StyleEngine::styleSheetCollectionFor(TreeScope& t
reeScope) | 138 StyleSheetCollection* StyleEngine::styleSheetCollectionFor(TreeScope& treeScope) |
| 143 { | 139 { |
| 144 if (treeScope == m_document) | 140 if (treeScope == m_document) |
| 145 return documentStyleSheetCollection(); | 141 return documentStyleSheetCollection(); |
| 146 | 142 |
| 147 StyleSheetCollectionMap::iterator it = m_styleSheetCollectionMap.find(&treeS
cope); | 143 StyleSheetCollectionMap::iterator it = m_styleSheetCollectionMap.find(&treeS
cope); |
| 148 if (it == m_styleSheetCollectionMap.end()) | 144 if (it == m_styleSheetCollectionMap.end()) |
| 149 return 0; | 145 return 0; |
| 150 return it->value.get(); | 146 return it->value.get(); |
| 151 } | 147 } |
| 152 | 148 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 165 markTreeScopeDirty(treeScope); | 161 markTreeScopeDirty(treeScope); |
| 166 } | 162 } |
| 167 | 163 |
| 168 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) | 164 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) |
| 169 { | 165 { |
| 170 if (!node->inDocument()) | 166 if (!node->inDocument()) |
| 171 return; | 167 return; |
| 172 | 168 |
| 173 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; | 169 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; |
| 174 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); | 170 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); |
| 175 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr
eeScope); | 171 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); |
| 176 ASSERT(collection); | 172 ASSERT(collection); |
| 177 collection->addStyleSheetCandidateNode(node, createdByParser); | 173 collection->addStyleSheetCandidateNode(node, createdByParser); |
| 178 | 174 |
| 179 markTreeScopeDirty(treeScope); | 175 markTreeScopeDirty(treeScope); |
| 180 if (treeScope != m_document) | 176 if (treeScope != m_document) |
| 181 insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); | 177 insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); |
| 182 } | 178 } |
| 183 | 179 |
| 184 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi
ngNode, TreeScope& treeScope) | 180 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi
ngNode, TreeScope& treeScope) |
| 185 { | 181 { |
| 186 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); | 182 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); |
| 187 | 183 |
| 188 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop
e); | 184 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); |
| 189 ASSERT(collection); | 185 ASSERT(collection); |
| 190 collection->removeStyleSheetCandidateNode(node, scopingNode); | 186 collection->removeStyleSheetCandidateNode(node, scopingNode); |
| 191 | 187 |
| 192 markTreeScopeDirty(treeScope); | 188 markTreeScopeDirty(treeScope); |
| 193 m_activeTreeScopes.remove(&treeScope); | 189 m_activeTreeScopes.remove(&treeScope); |
| 194 } | 190 } |
| 195 | 191 |
| 196 void StyleEngine::updateActiveStyleSheets() | 192 void StyleEngine::updateActiveStyleSheets() |
| 197 { | 193 { |
| 198 ASSERT(isMaster()); | 194 ASSERT(isMaster()); |
| 199 ASSERT(!document().inStyleRecalc()); | 195 ASSERT(!document().inStyleRecalc()); |
| 200 | 196 |
| 201 if (!document().isActive()) | 197 if (!document().isActive()) |
| 202 return; | 198 return; |
| 203 | 199 |
| 204 documentStyleSheetCollection()->updateActiveStyleSheets(this); | 200 documentStyleSheetCollection()->updateActiveStyleSheets(this); |
| 205 | 201 |
| 206 TreeScopeSet treeScopes = m_activeTreeScopes; | 202 TreeScopeSet treeScopes = m_activeTreeScopes; |
| 207 HashSet<TreeScope*> treeScopesRemoved; | 203 HashSet<TreeScope*> treeScopesRemoved; |
| 208 | 204 |
| 209 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { | 205 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { |
| 210 TreeScope* treeScope = *it; | 206 TreeScope* treeScope = *it; |
| 211 ASSERT(treeScope != m_document); | 207 ASSERT(treeScope != m_document); |
| 212 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyle
SheetCollection*>(styleSheetCollectionFor(*treeScope)); | 208 StyleSheetCollection* collection = styleSheetCollectionFor(*treeScope); |
| 213 ASSERT(collection); | 209 ASSERT(collection); |
| 214 collection->updateActiveStyleSheets(this); | 210 collection->updateActiveStyleSheets(this); |
| 215 if (!collection->hasStyleSheetCandidateNodes()) | 211 if (!collection->hasStyleSheetCandidateNodes()) |
| 216 treeScopesRemoved.add(treeScope); | 212 treeScopesRemoved.add(treeScope); |
| 217 } | 213 } |
| 218 m_activeTreeScopes.removeAll(treeScopesRemoved); | 214 m_activeTreeScopes.removeAll(treeScopesRemoved); |
| 219 | 215 |
| 220 m_dirtyTreeScopes.clear(); | 216 m_dirtyTreeScopes.clear(); |
| 221 m_documentScopeDirty = false; | 217 m_documentScopeDirty = false; |
| 222 } | 218 } |
| 223 | 219 |
| 224 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) | 220 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
| 225 { | 221 { |
| 226 if (shadowRoot->scopedStyleResolver()) | 222 if (shadowRoot->scopedStyleResolver()) |
| 227 removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); | 223 removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); |
| 228 m_styleSheetCollectionMap.remove(shadowRoot); | 224 m_styleSheetCollectionMap.remove(shadowRoot); |
| 229 } | 225 } |
| 230 | 226 |
| 231 void StyleEngine::appendActiveAuthorStyleSheets() | 227 void StyleEngine::appendActiveAuthorStyleSheets() |
| 232 { | 228 { |
| 233 ASSERT(isMaster()); | 229 ASSERT(isMaster()); |
| 234 | 230 |
| 235 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); | 231 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); |
| 236 | 232 |
| 237 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 233 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 238 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 234 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 239 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 235 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 240 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa
p.get(*it)) | 236 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) |
| 241 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); | 237 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); |
| 242 } | 238 } |
| 243 m_resolver->finishAppendAuthorStyleSheets(); | 239 m_resolver->finishAppendAuthorStyleSheets(); |
| 244 } | 240 } |
| 245 | 241 |
| 246 void StyleEngine::createResolver() | 242 void StyleEngine::createResolver() |
| 247 { | 243 { |
| 248 // It is a programming error to attempt to resolve style on a Document | 244 // It is a programming error to attempt to resolve style on a Document |
| 249 // which is not in a frame. Code which hits this should have checked | 245 // which is not in a frame. Code which hits this should have checked |
| 250 // Document::isActive() before calling into code which could get here. | 246 // Document::isActive() before calling into code which could get here. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 { | 393 { |
| 398 if (!document().isActive()) | 394 if (!document().isActive()) |
| 399 return; | 395 return; |
| 400 | 396 |
| 401 if (m_resolver) | 397 if (m_resolver) |
| 402 m_resolver->invalidateMatchedPropertiesCache(); | 398 m_resolver->invalidateMatchedPropertiesCache(); |
| 403 document().setNeedsStyleRecalc(SubtreeStyleChange); | 399 document().setNeedsStyleRecalc(SubtreeStyleChange); |
| 404 } | 400 } |
| 405 | 401 |
| 406 } | 402 } |
| OLD | NEW |