| 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/ElementTraversal.h" |
| 36 #include "sky/engine/core/dom/StyleSheetCollection.h" | 37 #include "sky/engine/core/dom/StyleSheetCollection.h" |
| 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 38 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 38 #include "sky/engine/core/frame/Settings.h" | 39 #include "sky/engine/core/frame/Settings.h" |
| 39 #include "sky/engine/core/html/HTMLStyleElement.h" | 40 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 40 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 41 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 41 #include "sky/engine/core/page/Page.h" | 42 #include "sky/engine/core/page/Page.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 StyleEngine::StyleEngine(Document& document) | 46 StyleEngine::StyleEngine(Document& document) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 66 | 67 |
| 67 if (m_fontSelector) { | 68 if (m_fontSelector) { |
| 68 m_fontSelector->clearDocument(); | 69 m_fontSelector->clearDocument(); |
| 69 m_fontSelector->unregisterForInvalidationCallbacks(this); | 70 m_fontSelector->unregisterForInvalidationCallbacks(this); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Decrement reference counts for things we could be keeping alive. | 73 // Decrement reference counts for things we could be keeping alive. |
| 73 m_fontSelector.clear(); | 74 m_fontSelector.clear(); |
| 74 m_resolver.clear(); | 75 m_resolver.clear(); |
| 75 m_styleSheetCollectionMap.clear(); | 76 m_styleSheetCollectionMap.clear(); |
| 76 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | |
| 77 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); | |
| 78 m_scopedStyleResolvers.clear(); | |
| 79 } | 77 } |
| 80 | 78 |
| 81 const Vector<RefPtr<CSSStyleSheet>>& StyleEngine::activeAuthorStyleSheetsFor(Tre
eScope& treeScope) | 79 const Vector<RefPtr<CSSStyleSheet>>& StyleEngine::activeAuthorStyleSheetsFor(Tre
eScope& treeScope) |
| 82 { | 80 { |
| 83 if (treeScope == m_document) | 81 if (treeScope == m_document) |
| 84 return documentStyleSheetCollection()->activeAuthorStyleSheets(); | 82 return documentStyleSheetCollection()->activeAuthorStyleSheets(); |
| 85 return ensureStyleSheetCollectionFor(treeScope)->activeAuthorStyleSheets(); | 83 return ensureStyleSheetCollectionFor(treeScope)->activeAuthorStyleSheets(); |
| 86 } | 84 } |
| 87 | 85 |
| 88 StyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeScope& tree
Scope) | 86 StyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeScope& tree
Scope) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (!collection->hasStyleSheetCandidateNodes()) | 169 if (!collection->hasStyleSheetCandidateNodes()) |
| 172 treeScopesRemoved.add(treeScope); | 170 treeScopesRemoved.add(treeScope); |
| 173 } | 171 } |
| 174 m_activeTreeScopes.removeAll(treeScopesRemoved); | 172 m_activeTreeScopes.removeAll(treeScopesRemoved); |
| 175 | 173 |
| 176 m_dirtyTreeScopes.clear(); | 174 m_dirtyTreeScopes.clear(); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) | 177 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
| 180 { | 178 { |
| 181 if (shadowRoot->scopedStyleResolver()) | |
| 182 removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); | |
| 183 m_styleSheetCollectionMap.remove(shadowRoot); | 179 m_styleSheetCollectionMap.remove(shadowRoot); |
| 184 } | 180 } |
| 185 | 181 |
| 186 void StyleEngine::appendActiveAuthorStyleSheets() | 182 void StyleEngine::appendActiveAuthorStyleSheets() |
| 187 { | 183 { |
| 188 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); | 184 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); |
| 189 | 185 |
| 190 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 186 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 191 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 187 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 192 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 188 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 193 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) | 189 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) |
| 194 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); | 190 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); |
| 195 } | 191 } |
| 196 m_resolver->finishAppendAuthorStyleSheets(); | 192 m_resolver->finishAppendAuthorStyleSheets(); |
| 197 } | 193 } |
| 198 | 194 |
| 199 void StyleEngine::createResolver() | 195 void StyleEngine::createResolver() |
| 200 { | 196 { |
| 201 // It is a programming error to attempt to resolve style on a Document | 197 // It is a programming error to attempt to resolve style on a Document |
| 202 // which is not in a frame. Code which hits this should have checked | 198 // which is not in a frame. Code which hits this should have checked |
| 203 // Document::isActive() before calling into code which could get here. | 199 // Document::isActive() before calling into code which could get here. |
| 204 | 200 |
| 205 ASSERT(m_document->frame()); | 201 ASSERT(m_document->frame()); |
| 206 | 202 |
| 207 m_resolver = adoptPtr(new StyleResolver(*m_document)); | 203 m_resolver = adoptPtr(new StyleResolver(*m_document)); |
| 208 addScopedStyleResolver(&m_document->ensureScopedStyleResolver()); | |
| 209 | 204 |
| 210 appendActiveAuthorStyleSheets(); | 205 appendActiveAuthorStyleSheets(); |
| 211 } | 206 } |
| 212 | 207 |
| 213 void StyleEngine::clearResolver() | 208 void StyleEngine::clearResolver() |
| 214 { | 209 { |
| 215 ASSERT(!m_document->inStyleRecalc()); | 210 ASSERT(!m_document->inStyleRecalc()); |
| 216 | |
| 217 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | |
| 218 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); | |
| 219 m_scopedStyleResolvers.clear(); | |
| 220 m_resolver.clear(); | 211 m_resolver.clear(); |
| 221 } | 212 } |
| 222 | 213 |
| 223 unsigned StyleEngine::resolverAccessCount() const | 214 unsigned StyleEngine::resolverAccessCount() const |
| 224 { | 215 { |
| 225 return m_resolver ? m_resolver->accessCount() : 0; | 216 return m_resolver ? m_resolver->accessCount() : 0; |
| 226 } | 217 } |
| 227 | 218 |
| 228 void StyleEngine::didDetach() | 219 void StyleEngine::didDetach() |
| 229 { | 220 { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 void StyleEngine::removeSheet(StyleSheetContents* contents) | 301 void StyleEngine::removeSheet(StyleSheetContents* contents) |
| 311 { | 302 { |
| 312 HashMap<RawPtr<StyleSheetContents>, AtomicString>::iterator it = m_sheetToTe
xtCache.find(contents); | 303 HashMap<RawPtr<StyleSheetContents>, AtomicString>::iterator it = m_sheetToTe
xtCache.find(contents); |
| 313 if (it == m_sheetToTextCache.end()) | 304 if (it == m_sheetToTextCache.end()) |
| 314 return; | 305 return; |
| 315 | 306 |
| 316 m_textToSheetCache.remove(it->value); | 307 m_textToSheetCache.remove(it->value); |
| 317 m_sheetToTextCache.remove(contents); | 308 m_sheetToTextCache.remove(contents); |
| 318 } | 309 } |
| 319 | 310 |
| 311 // TODO(esprehn): This walks the entire document to collect features, instead |
| 312 // we should store features per scope and get rid of the global set. |
| 313 static void collectFeatures(TreeScope& scope, RuleFeatureSet& features, HashSet<
const StyleSheetContents*> visitedSharedStyleSheetContents) |
| 314 { |
| 315 scope.scopedStyleResolver().collectFeaturesTo(features, visitedSharedStyleSh
eetContents); |
| 316 for (Element* element = ElementTraversal::firstWithin(scope.rootNode()); ele
ment; element = ElementTraversal::next(*element, &scope.rootNode())) { |
| 317 if (ShadowRoot* root = element->shadowRoot()) |
| 318 collectFeatures(*root, features, visitedSharedStyleSheetContents); |
| 319 } |
| 320 } |
| 321 |
| 320 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const | 322 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const |
| 321 { | 323 { |
| 322 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; | 324 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; |
| 323 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | 325 collectFeatures(*m_document, features, visitedSharedStyleSheetContents); |
| 324 (*it)->collectFeaturesTo(features, visitedSharedStyleSheetContents); | |
| 325 } | 326 } |
| 326 | 327 |
| 327 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) | 328 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) |
| 328 { | 329 { |
| 329 if (m_resolver) | 330 if (m_resolver) |
| 330 m_resolver->invalidateMatchedPropertiesCache(); | 331 m_resolver->invalidateMatchedPropertiesCache(); |
| 331 m_document->setNeedsStyleRecalc(SubtreeStyleChange); | 332 m_document->setNeedsStyleRecalc(SubtreeStyleChange); |
| 332 } | 333 } |
| 333 | 334 |
| 334 } | 335 } |
| OLD | NEW |