| 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 14 matching lines...) Expand all Loading... |
| 25 * Boston, MA 02110-1301, USA. | 25 * Boston, MA 02110-1301, USA. |
| 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/Document.h" |
| 35 #include "sky/engine/core/dom/Element.h" | 36 #include "sky/engine/core/dom/Element.h" |
| 36 #include "sky/engine/core/dom/ElementTraversal.h" | 37 #include "sky/engine/core/dom/ElementTraversal.h" |
| 37 #include "sky/engine/core/dom/StyleSheetCollection.h" | 38 #include "sky/engine/core/dom/StyleSheetCollection.h" |
| 38 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 39 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 39 #include "sky/engine/core/frame/Settings.h" | 40 #include "sky/engine/core/frame/Settings.h" |
| 40 #include "sky/engine/core/html/HTMLStyleElement.h" | 41 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 41 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 42 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 42 #include "sky/engine/core/page/Page.h" | 43 #include "sky/engine/core/page/Page.h" |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 StyleEngine::StyleEngine(Document& document) | 47 StyleEngine::StyleEngine(Document& document) |
| 47 : m_document(&document) | 48 : m_document(&document) |
| 48 , m_documentStyleSheetCollection(StyleSheetCollection::create(document)) | |
| 49 , m_ignorePendingStylesheets(false) | 49 , m_ignorePendingStylesheets(false) |
| 50 // We don't need to create CSSFontSelector for imported document or | 50 // We don't need to create CSSFontSelector for imported document or |
| 51 // HTMLTemplateElement's document, because those documents have no frame. | 51 // HTMLTemplateElement's document, because those documents have no frame. |
| 52 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) | 52 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) |
| 53 { | 53 { |
| 54 if (m_fontSelector) | 54 if (m_fontSelector) |
| 55 m_fontSelector->registerForInvalidationCallbacks(this); | 55 m_fontSelector->registerForInvalidationCallbacks(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 StyleEngine::~StyleEngine() | 58 StyleEngine::~StyleEngine() |
| 59 { | 59 { |
| 60 } | 60 } |
| 61 | 61 |
| 62 void StyleEngine::detachFromDocument() | 62 void StyleEngine::detachFromDocument() |
| 63 { | 63 { |
| 64 // Cleanup is performed eagerly when the StyleEngine is removed from the | 64 // Cleanup is performed eagerly when the StyleEngine is removed from the |
| 65 // document. The StyleEngine is unreachable after this, since only the | 65 // document. The StyleEngine is unreachable after this, since only the |
| 66 // document has a reference to it. | 66 // document has a reference to it. |
| 67 | 67 |
| 68 if (m_fontSelector) { | 68 if (m_fontSelector) { |
| 69 m_fontSelector->clearDocument(); | 69 m_fontSelector->clearDocument(); |
| 70 m_fontSelector->unregisterForInvalidationCallbacks(this); | 70 m_fontSelector->unregisterForInvalidationCallbacks(this); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Decrement reference counts for things we could be keeping alive. | 73 // Decrement reference counts for things we could be keeping alive. |
| 74 m_fontSelector.clear(); | 74 m_fontSelector.clear(); |
| 75 m_resolver.clear(); | 75 m_resolver.clear(); |
| 76 m_styleSheetCollectionMap.clear(); | |
| 77 } | |
| 78 | |
| 79 const Vector<RefPtr<CSSStyleSheet>>& StyleEngine::activeAuthorStyleSheetsFor(Tre
eScope& treeScope) | |
| 80 { | |
| 81 if (treeScope == m_document) | |
| 82 return documentStyleSheetCollection()->activeAuthorStyleSheets(); | |
| 83 return ensureStyleSheetCollectionFor(treeScope)->activeAuthorStyleSheets(); | |
| 84 } | |
| 85 | |
| 86 StyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeScope& tree
Scope) | |
| 87 { | |
| 88 if (treeScope == m_document) | |
| 89 return documentStyleSheetCollection(); | |
| 90 | |
| 91 StyleSheetCollectionMap::AddResult result = m_styleSheetCollectionMap.add(&t
reeScope, nullptr); | |
| 92 if (result.isNewEntry) | |
| 93 result.storedValue->value = StyleSheetCollection::create(treeScope); | |
| 94 return result.storedValue->value.get(); | |
| 95 } | |
| 96 | |
| 97 StyleSheetCollection* StyleEngine::styleSheetCollectionFor(TreeScope& treeScope) | |
| 98 { | |
| 99 if (treeScope == m_document) | |
| 100 return documentStyleSheetCollection(); | |
| 101 | |
| 102 StyleSheetCollectionMap::iterator it = m_styleSheetCollectionMap.find(&treeS
cope); | |
| 103 if (it == m_styleSheetCollectionMap.end()) | |
| 104 return 0; | |
| 105 return it->value.get(); | |
| 106 } | 76 } |
| 107 | 77 |
| 108 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) | 78 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) |
| 109 { | 79 { |
| 110 if (!node->inDocument()) | 80 if (!node->inDocument()) |
| 111 return; | 81 return; |
| 112 | 82 |
| 113 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; | 83 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; |
| 114 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); | 84 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); |
| 115 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); | 85 StyleSheetCollection& collection = treeScope.styleSheets(); |
| 116 ASSERT(collection); | 86 collection.addStyleSheetCandidateNode(node, createdByParser); |
| 117 collection->addStyleSheetCandidateNode(node, createdByParser); | |
| 118 | 87 |
| 119 if (treeScope != m_document) | 88 if (treeScope != m_document) |
| 120 m_activeTreeScopes.add(&treeScope); | 89 m_activeTreeScopes.add(&treeScope); |
| 121 } | 90 } |
| 122 | 91 |
| 123 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi
ngNode, TreeScope& treeScope) | 92 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi
ngNode, TreeScope& treeScope) |
| 124 { | 93 { |
| 125 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); | 94 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); |
| 126 | 95 |
| 127 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); | 96 StyleSheetCollection& collection = treeScope.styleSheets(); |
| 128 ASSERT(collection); | 97 collection.removeStyleSheetCandidateNode(node, scopingNode); |
| 129 collection->removeStyleSheetCandidateNode(node, scopingNode); | |
| 130 | 98 |
| 131 m_activeTreeScopes.remove(&treeScope); | 99 m_activeTreeScopes.remove(&treeScope); |
| 132 } | 100 } |
| 133 | 101 |
| 134 void StyleEngine::updateActiveStyleSheets() | 102 void StyleEngine::updateActiveStyleSheets() |
| 135 { | 103 { |
| 136 ASSERT(!m_document->inStyleRecalc()); | 104 ASSERT(!m_document->inStyleRecalc()); |
| 137 | 105 |
| 138 if (!m_document->isActive()) | 106 if (!m_document->isActive()) |
| 139 return; | 107 return; |
| 140 | 108 |
| 141 documentStyleSheetCollection()->updateActiveStyleSheets(this); | 109 // TODO(esprehn): Remove special case for document. |
| 110 m_document->styleSheets().updateActiveStyleSheets(this); |
| 142 | 111 |
| 143 TreeScopeSet treeScopes = m_activeTreeScopes; | 112 TreeScopeSet treeScopes = m_activeTreeScopes; |
| 144 HashSet<TreeScope*> treeScopesRemoved; | 113 HashSet<TreeScope*> treeScopesRemoved; |
| 145 | 114 |
| 146 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { | 115 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { |
| 147 TreeScope* treeScope = *it; | 116 TreeScope* treeScope = *it; |
| 148 ASSERT(treeScope != m_document); | 117 ASSERT(treeScope != m_document); |
| 149 StyleSheetCollection* collection = styleSheetCollectionFor(*treeScope); | 118 StyleSheetCollection& collection = treeScope->styleSheets(); |
| 150 ASSERT(collection); | 119 collection.updateActiveStyleSheets(this); |
| 151 collection->updateActiveStyleSheets(this); | 120 if (!collection.hasStyleSheetCandidateNodes()) |
| 152 if (!collection->hasStyleSheetCandidateNodes()) | |
| 153 treeScopesRemoved.add(treeScope); | 121 treeScopesRemoved.add(treeScope); |
| 154 } | 122 } |
| 155 m_activeTreeScopes.removeAll(treeScopesRemoved); | 123 m_activeTreeScopes.removeAll(treeScopesRemoved); |
| 156 } | 124 } |
| 157 | 125 |
| 158 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) | |
| 159 { | |
| 160 m_styleSheetCollectionMap.remove(shadowRoot); | |
| 161 } | |
| 162 | |
| 163 void StyleEngine::appendActiveAuthorStyleSheets() | 126 void StyleEngine::appendActiveAuthorStyleSheets() |
| 164 { | 127 { |
| 165 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); | 128 // TODO(esprehn): Remove special case for document. |
| 129 m_resolver->appendAuthorStyleSheets(m_document->styleSheets().activeAuthorSt
yleSheets()); |
| 166 | 130 |
| 167 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 131 for (TreeScope* treeScope : m_activeTreeScopes) |
| 168 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 132 m_resolver->appendAuthorStyleSheets(treeScope->styleSheets().activeAutho
rStyleSheets()); |
| 169 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 133 |
| 170 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) | |
| 171 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); | |
| 172 } | |
| 173 m_resolver->finishAppendAuthorStyleSheets(); | 134 m_resolver->finishAppendAuthorStyleSheets(); |
| 174 } | 135 } |
| 175 | 136 |
| 176 void StyleEngine::createResolver() | 137 void StyleEngine::createResolver() |
| 177 { | 138 { |
| 178 // It is a programming error to attempt to resolve style on a Document | 139 // It is a programming error to attempt to resolve style on a Document |
| 179 // which is not in a frame. Code which hits this should have checked | 140 // which is not in a frame. Code which hits this should have checked |
| 180 // Document::isActive() before calling into code which could get here. | 141 // Document::isActive() before calling into code which could get here. |
| 181 | 142 |
| 182 ASSERT(m_document->frame()); | 143 ASSERT(m_document->frame()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 260 } |
| 300 | 261 |
| 301 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) | 262 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) |
| 302 { | 263 { |
| 303 if (m_resolver) | 264 if (m_resolver) |
| 304 m_resolver->invalidateMatchedPropertiesCache(); | 265 m_resolver->invalidateMatchedPropertiesCache(); |
| 305 m_document->setNeedsStyleRecalc(SubtreeStyleChange); | 266 m_document->setNeedsStyleRecalc(SubtreeStyleChange); |
| 306 } | 267 } |
| 307 | 268 |
| 308 } | 269 } |
| OLD | NEW |