Chromium Code Reviews| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 , m_ignorePendingStylesheets(false) | 94 , m_ignorePendingStylesheets(false) |
| 95 , m_didCalculateResolver(false) | 95 , m_didCalculateResolver(false) |
| 96 // We don't need to create CSSFontSelector for imported document or | 96 // We don't need to create CSSFontSelector for imported document or |
| 97 // HTMLTemplateElement's document, because those documents have no frame. | 97 // HTMLTemplateElement's document, because those documents have no frame. |
| 98 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul lptr) | 98 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul lptr) |
| 99 { | 99 { |
| 100 } | 100 } |
| 101 | 101 |
| 102 StyleEngine::~StyleEngine() | 102 StyleEngine::~StyleEngine() |
| 103 { | 103 { |
| 104 } | |
| 105 | |
| 106 void StyleEngine::detachFromDocument() | |
| 107 { | |
| 104 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) | 108 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) |
| 105 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); | 109 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); |
| 106 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | 110 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) |
| 107 m_authorStyleSheets[i]->clearOwnerNode(); | 111 m_authorStyleSheets[i]->clearOwnerNode(); |
| 108 | 112 |
| 109 if (m_fontSelector) { | 113 if (m_fontSelector) { |
| 110 m_fontSelector->clearDocument(); | 114 m_fontSelector->clearDocument(); |
| 111 if (m_resolver) | 115 if (m_resolver) |
| 112 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()) ; | 116 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()) ; |
| 113 } | 117 } |
| 118 m_fontSelector.clear(); | |
| 119 m_resolver.clear(); | |
| 120 m_styleSheetCollectionMap.clear(); | |
|
haraken
2014/03/12 11:08:21
Don't you need to clear m_document, m_dirtyTreeSco
Erik Corry
2014/03/12 11:48:57
I'm clearing the RefPtrs and the OwnPtrs so that t
| |
| 114 } | 121 } |
| 115 | 122 |
| 116 inline Document* StyleEngine::master() | 123 inline Document* StyleEngine::master() |
| 117 { | 124 { |
| 118 if (isMaster()) | 125 if (isMaster()) |
| 119 return &m_document; | 126 return &m_document; |
| 120 HTMLImport* import = m_document.import(); | 127 HTMLImport* import = m_document.import(); |
| 121 if (!import) // Document::import() can return null while executing its destr uctor. | 128 if (!import) // Document::import() can return null while executing its destr uctor. |
| 122 return 0; | 129 return 0; |
| 123 return import->master(); | 130 return import->master(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 { | 172 { |
| 166 if (treeScope == m_document) | 173 if (treeScope == m_document) |
| 167 return &m_documentStyleSheetCollection; | 174 return &m_documentStyleSheetCollection; |
| 168 | 175 |
| 169 HashMap<TreeScope*, OwnPtr<TreeScopeStyleSheetCollection> >::iterator it = m _styleSheetCollectionMap.find(&treeScope); | 176 HashMap<TreeScope*, OwnPtr<TreeScopeStyleSheetCollection> >::iterator it = m _styleSheetCollectionMap.find(&treeScope); |
| 170 if (it == m_styleSheetCollectionMap.end()) | 177 if (it == m_styleSheetCollectionMap.end()) |
| 171 return 0; | 178 return 0; |
| 172 return it->value.get(); | 179 return it->value.get(); |
| 173 } | 180 } |
| 174 | 181 |
| 175 const Vector<RefPtr<StyleSheet> >& StyleEngine::styleSheetsForStyleSheetList(Tre eScope& treeScope) | 182 const WillBeHeapVector<RefPtrWillBeMember<StyleSheet> >& StyleEngine::styleSheet sForStyleSheetList(TreeScope& treeScope) |
| 176 { | 183 { |
| 177 if (treeScope == m_document) | 184 if (treeScope == m_document) |
| 178 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 185 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
| 179 | 186 |
| 180 return ensureStyleSheetCollectionFor(treeScope)->styleSheetsForStyleSheetLis t(); | 187 return ensureStyleSheetCollectionFor(treeScope)->styleSheetsForStyleSheetLis t(); |
| 181 } | 188 } |
| 182 | 189 |
| 183 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::activeAuthorStyleSheets() con st | 190 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& StyleEngine::activeA uthorStyleSheets() const |
| 184 { | 191 { |
| 185 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); | 192 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); |
| 186 } | 193 } |
| 187 | 194 |
| 188 void StyleEngine::combineCSSFeatureFlags(const RuleFeatureSet& features) | 195 void StyleEngine::combineCSSFeatureFlags(const RuleFeatureSet& features) |
| 189 { | 196 { |
| 190 // Delay resetting the flags until after next style recalc since unapplying the style may not work without these set (this is true at least with before/afte r). | 197 // Delay resetting the flags until after next style recalc since unapplying the style may not work without these set (this is true at least with before/afte r). |
| 191 m_usesSiblingRules = m_usesSiblingRules || features.usesSiblingRules(); | 198 m_usesSiblingRules = m_usesSiblingRules || features.usesSiblingRules(); |
| 192 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules() ; | 199 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules() ; |
| 193 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma xDirectAdjacentSelectors()); | 200 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma xDirectAdjacentSelectors()); |
| 194 } | 201 } |
| 195 | 202 |
| 196 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) | 203 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) |
| 197 { | 204 { |
| 198 m_usesSiblingRules = features.usesSiblingRules(); | 205 m_usesSiblingRules = features.usesSiblingRules(); |
| 199 m_usesFirstLineRules = features.usesFirstLineRules(); | 206 m_usesFirstLineRules = features.usesFirstLineRules(); |
| 200 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); | 207 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); |
| 201 } | 208 } |
| 202 | 209 |
| 203 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedAuthorStyleSheets() c onst | 210 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& StyleEngine::injecte dAuthorStyleSheets() const |
| 204 { | 211 { |
| 205 updateInjectedStyleSheetCache(); | 212 updateInjectedStyleSheetCache(); |
| 206 return m_injectedAuthorStyleSheets; | 213 return m_injectedAuthorStyleSheets; |
| 207 } | 214 } |
| 208 | 215 |
| 209 void StyleEngine::updateInjectedStyleSheetCache() const | 216 void StyleEngine::updateInjectedStyleSheetCache() const |
| 210 { | 217 { |
| 211 if (m_injectedStyleSheetCacheValid) | 218 if (m_injectedStyleSheetCacheValid) |
| 212 return; | 219 return; |
| 213 m_injectedStyleSheetCacheValid = true; | 220 m_injectedStyleSheetCacheValid = true; |
| 214 m_injectedAuthorStyleSheets.clear(); | 221 m_injectedAuthorStyleSheets.clear(); |
| 215 | 222 |
| 216 Page* owningPage = m_document.page(); | 223 Page* owningPage = m_document.page(); |
| 217 if (!owningPage) | 224 if (!owningPage) |
| 218 return; | 225 return; |
| 219 | 226 |
| 220 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance ().entries(); | 227 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance ().entries(); |
| 221 for (unsigned i = 0; i < entries.size(); ++i) { | 228 for (unsigned i = 0; i < entries.size(); ++i) { |
| 222 const InjectedStyleSheetEntry* entry = entries[i].get(); | 229 const InjectedStyleSheetEntry* entry = entries[i].get(); |
| 223 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o wnerElement()) | 230 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o wnerElement()) |
| 224 continue; | 231 continue; |
| 225 if (!URLPatternMatcher::matchesPatterns(m_document.url(), entry->whiteli st())) | 232 if (!URLPatternMatcher::matchesPatterns(m_document.url(), entry->whiteli st())) |
| 226 continue; | 233 continue; |
| 227 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas t<Document*>(&m_document), KURL()); | 234 RefPtrWillBeRawPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInli ne(const_cast<Document*>(&m_document), KURL()); |
| 228 m_injectedAuthorStyleSheets.append(groupSheet); | 235 m_injectedAuthorStyleSheets.append(groupSheet); |
| 229 groupSheet->contents()->parseString(entry->source()); | 236 groupSheet->contents()->parseString(entry->source()); |
| 230 } | 237 } |
| 231 } | 238 } |
| 232 | 239 |
| 233 void StyleEngine::invalidateInjectedStyleSheetCache() | 240 void StyleEngine::invalidateInjectedStyleSheetCache() |
| 234 { | 241 { |
| 235 m_injectedStyleSheetCacheValid = false; | 242 m_injectedStyleSheetCacheValid = false; |
| 236 markDocumentDirty(); | 243 markDocumentDirty(); |
| 237 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio n::updateActiveStyleSheets | 244 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio n::updateActiveStyleSheets |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 void StyleEngine::clearMediaQueryRuleSetStyleSheets() | 366 void StyleEngine::clearMediaQueryRuleSetStyleSheets() |
| 360 { | 367 { |
| 361 m_documentStyleSheetCollection.clearMediaQueryRuleSetStyleSheets(); | 368 m_documentStyleSheetCollection.clearMediaQueryRuleSetStyleSheets(); |
| 362 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes); | 369 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes); |
| 363 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes); | 370 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes); |
| 364 } | 371 } |
| 365 | 372 |
| 366 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector) | 373 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector) |
| 367 { | 374 { |
| 368 ASSERT(!isMaster()); | 375 ASSERT(!isMaster()); |
| 369 Vector<RefPtr<StyleSheet> > sheetsForList; | 376 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > sheetsForList; |
| 370 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist); | 377 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist); |
| 371 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); | 378 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); |
| 372 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); | 379 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); |
| 373 } | 380 } |
| 374 | 381 |
| 375 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) | 382 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
| 376 { | 383 { |
| 377 ASSERT(isMaster()); | 384 ASSERT(isMaster()); |
| 378 ASSERT(!m_document.inStyleRecalc()); | 385 ASSERT(!m_document.inStyleRecalc()); |
| 379 | 386 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 404 | 411 |
| 405 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document); | 412 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document); |
| 406 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); | 413 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); |
| 407 | 414 |
| 408 m_dirtyTreeScopes.clear(); | 415 m_dirtyTreeScopes.clear(); |
| 409 m_documentScopeDirty = false; | 416 m_documentScopeDirty = false; |
| 410 | 417 |
| 411 return requiresFullStyleRecalc; | 418 return requiresFullStyleRecalc; |
| 412 } | 419 } |
| 413 | 420 |
| 414 const Vector<RefPtr<StyleSheet> > StyleEngine::activeStyleSheetsForInspector() c onst | 421 const WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > StyleEngine::activeStyle SheetsForInspector() const |
| 415 { | 422 { |
| 416 if (m_activeTreeScopes.isEmpty()) | 423 if (m_activeTreeScopes.isEmpty()) |
| 417 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 424 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
| 418 | 425 |
| 419 Vector<RefPtr<StyleSheet> > activeStyleSheets; | 426 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > activeStyleSheets; |
| 420 | 427 |
| 421 activeStyleSheets.appendVector(m_documentStyleSheetCollection.styleSheetsFor StyleSheetList()); | 428 activeStyleSheets.appendVector(m_documentStyleSheetCollection.styleSheetsFor StyleSheetList()); |
| 422 | 429 |
| 423 TreeScopeSet::const_iterator begin = m_activeTreeScopes.begin(); | 430 TreeScopeSet::const_iterator begin = m_activeTreeScopes.begin(); |
| 424 TreeScopeSet::const_iterator end = m_activeTreeScopes.end(); | 431 TreeScopeSet::const_iterator end = m_activeTreeScopes.end(); |
| 425 for (TreeScopeSet::const_iterator it = begin; it != end; ++it) { | 432 for (TreeScopeSet::const_iterator it = begin; it != end; ++it) { |
| 426 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(*it)) | 433 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(*it)) |
| 427 activeStyleSheets.appendVector(collection->styleSheetsForStyleSheetL ist()); | 434 activeStyleSheets.appendVector(collection->styleSheetsForStyleSheetL ist()); |
| 428 } | 435 } |
| 429 | 436 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 void StyleEngine::removeSheet(StyleSheetContents* contents) | 628 void StyleEngine::removeSheet(StyleSheetContents* contents) |
| 622 { | 629 { |
| 623 WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>: :iterator it = sheetToTextCache().find(contents); | 630 WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>: :iterator it = sheetToTextCache().find(contents); |
| 624 if (it == sheetToTextCache().end()) | 631 if (it == sheetToTextCache().end()) |
| 625 return; | 632 return; |
| 626 | 633 |
| 627 textToSheetCache().remove(it->value); | 634 textToSheetCache().remove(it->value); |
| 628 sheetToTextCache().remove(contents); | 635 sheetToTextCache().remove(contents); |
| 629 } | 636 } |
| 630 | 637 |
| 638 void StyleEngine::trace(Visitor* visitor) | |
| 639 { | |
| 640 m_injectedAuthorStyleSheets.trace(visitor); | |
|
haraken
2014/03/12 11:08:21
visitor->trace(m_injectedAuthorStyleSheets)
Erik Corry
2014/03/12 11:48:57
Done.
| |
| 641 m_authorStyleSheets.trace(visitor); | |
|
haraken
2014/03/12 11:08:21
visitor->trace(m_authorStyleSheets);
Erik Corry
2014/03/12 11:48:57
Done.
| |
| 631 } | 642 } |
| 643 | |
| 644 } | |
| OLD | NEW |