| 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 { |
| 108 // Cleanup is performed eagerly when the StyleEngine is removed from the |
| 109 // document. The StyleEngine is unreachable after this, since only the |
| 110 // document has a reference to it. |
| 104 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) | 111 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) |
| 105 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); | 112 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); |
| 106 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | 113 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) |
| 107 m_authorStyleSheets[i]->clearOwnerNode(); | 114 m_authorStyleSheets[i]->clearOwnerNode(); |
| 108 | 115 |
| 109 if (m_fontSelector) { | 116 if (m_fontSelector) { |
| 110 m_fontSelector->clearDocument(); | 117 m_fontSelector->clearDocument(); |
| 111 if (m_resolver) | 118 if (m_resolver) |
| 112 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get())
; | 119 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get())
; |
| 113 } | 120 } |
| 121 |
| 122 // Decrement reference counts for things we could be keeping alive. |
| 123 m_fontSelector.clear(); |
| 124 m_resolver.clear(); |
| 125 m_styleSheetCollectionMap.clear(); |
| 114 } | 126 } |
| 115 | 127 |
| 116 inline Document* StyleEngine::master() | 128 inline Document* StyleEngine::master() |
| 117 { | 129 { |
| 118 if (isMaster()) | 130 if (isMaster()) |
| 119 return &m_document; | 131 return &m_document; |
| 120 HTMLImport* import = m_document.import(); | 132 HTMLImport* import = m_document.import(); |
| 121 if (!import) // Document::import() can return null while executing its destr
uctor. | 133 if (!import) // Document::import() can return null while executing its destr
uctor. |
| 122 return 0; | 134 return 0; |
| 123 return import->master(); | 135 return import->master(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 { | 177 { |
| 166 if (treeScope == m_document) | 178 if (treeScope == m_document) |
| 167 return &m_documentStyleSheetCollection; | 179 return &m_documentStyleSheetCollection; |
| 168 | 180 |
| 169 HashMap<TreeScope*, OwnPtr<TreeScopeStyleSheetCollection> >::iterator it = m
_styleSheetCollectionMap.find(&treeScope); | 181 HashMap<TreeScope*, OwnPtr<TreeScopeStyleSheetCollection> >::iterator it = m
_styleSheetCollectionMap.find(&treeScope); |
| 170 if (it == m_styleSheetCollectionMap.end()) | 182 if (it == m_styleSheetCollectionMap.end()) |
| 171 return 0; | 183 return 0; |
| 172 return it->value.get(); | 184 return it->value.get(); |
| 173 } | 185 } |
| 174 | 186 |
| 175 const Vector<RefPtr<StyleSheet> >& StyleEngine::styleSheetsForStyleSheetList(Tre
eScope& treeScope) | 187 const WillBeHeapVector<RefPtrWillBeMember<StyleSheet> >& StyleEngine::styleSheet
sForStyleSheetList(TreeScope& treeScope) |
| 176 { | 188 { |
| 177 if (treeScope == m_document) | 189 if (treeScope == m_document) |
| 178 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 190 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
| 179 | 191 |
| 180 return ensureStyleSheetCollectionFor(treeScope)->styleSheetsForStyleSheetLis
t(); | 192 return ensureStyleSheetCollectionFor(treeScope)->styleSheetsForStyleSheetLis
t(); |
| 181 } | 193 } |
| 182 | 194 |
| 183 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::activeAuthorStyleSheets() con
st | 195 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& StyleEngine::activeA
uthorStyleSheets() const |
| 184 { | 196 { |
| 185 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); | 197 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); |
| 186 } | 198 } |
| 187 | 199 |
| 188 void StyleEngine::combineCSSFeatureFlags(const RuleFeatureSet& features) | 200 void StyleEngine::combineCSSFeatureFlags(const RuleFeatureSet& features) |
| 189 { | 201 { |
| 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). | 202 // 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(); | 203 m_usesSiblingRules = m_usesSiblingRules || features.usesSiblingRules(); |
| 192 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules()
; | 204 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules()
; |
| 193 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma
xDirectAdjacentSelectors()); | 205 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma
xDirectAdjacentSelectors()); |
| 194 } | 206 } |
| 195 | 207 |
| 196 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) | 208 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) |
| 197 { | 209 { |
| 198 m_usesSiblingRules = features.usesSiblingRules(); | 210 m_usesSiblingRules = features.usesSiblingRules(); |
| 199 m_usesFirstLineRules = features.usesFirstLineRules(); | 211 m_usesFirstLineRules = features.usesFirstLineRules(); |
| 200 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); | 212 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); |
| 201 } | 213 } |
| 202 | 214 |
| 203 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedAuthorStyleSheets() c
onst | 215 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& StyleEngine::injecte
dAuthorStyleSheets() const |
| 204 { | 216 { |
| 205 updateInjectedStyleSheetCache(); | 217 updateInjectedStyleSheetCache(); |
| 206 return m_injectedAuthorStyleSheets; | 218 return m_injectedAuthorStyleSheets; |
| 207 } | 219 } |
| 208 | 220 |
| 209 void StyleEngine::updateInjectedStyleSheetCache() const | 221 void StyleEngine::updateInjectedStyleSheetCache() const |
| 210 { | 222 { |
| 211 if (m_injectedStyleSheetCacheValid) | 223 if (m_injectedStyleSheetCacheValid) |
| 212 return; | 224 return; |
| 213 m_injectedStyleSheetCacheValid = true; | 225 m_injectedStyleSheetCacheValid = true; |
| 214 m_injectedAuthorStyleSheets.clear(); | 226 m_injectedAuthorStyleSheets.clear(); |
| 215 | 227 |
| 216 Page* owningPage = m_document.page(); | 228 Page* owningPage = m_document.page(); |
| 217 if (!owningPage) | 229 if (!owningPage) |
| 218 return; | 230 return; |
| 219 | 231 |
| 220 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance
().entries(); | 232 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance
().entries(); |
| 221 for (unsigned i = 0; i < entries.size(); ++i) { | 233 for (unsigned i = 0; i < entries.size(); ++i) { |
| 222 const InjectedStyleSheetEntry* entry = entries[i].get(); | 234 const InjectedStyleSheetEntry* entry = entries[i].get(); |
| 223 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o
wnerElement()) | 235 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o
wnerElement()) |
| 224 continue; | 236 continue; |
| 225 if (!URLPatternMatcher::matchesPatterns(m_document.url(), entry->whiteli
st())) | 237 if (!URLPatternMatcher::matchesPatterns(m_document.url(), entry->whiteli
st())) |
| 226 continue; | 238 continue; |
| 227 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas
t<Document*>(&m_document), KURL()); | 239 RefPtrWillBeRawPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInli
ne(const_cast<Document*>(&m_document), KURL()); |
| 228 m_injectedAuthorStyleSheets.append(groupSheet); | 240 m_injectedAuthorStyleSheets.append(groupSheet); |
| 229 groupSheet->contents()->parseString(entry->source()); | 241 groupSheet->contents()->parseString(entry->source()); |
| 230 } | 242 } |
| 231 } | 243 } |
| 232 | 244 |
| 233 void StyleEngine::invalidateInjectedStyleSheetCache() | 245 void StyleEngine::invalidateInjectedStyleSheetCache() |
| 234 { | 246 { |
| 235 m_injectedStyleSheetCacheValid = false; | 247 m_injectedStyleSheetCacheValid = false; |
| 236 markDocumentDirty(); | 248 markDocumentDirty(); |
| 237 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets | 249 // 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() | 371 void StyleEngine::clearMediaQueryRuleSetStyleSheets() |
| 360 { | 372 { |
| 361 m_documentStyleSheetCollection.clearMediaQueryRuleSetStyleSheets(); | 373 m_documentStyleSheetCollection.clearMediaQueryRuleSetStyleSheets(); |
| 362 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes); | 374 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes); |
| 363 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes); | 375 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes); |
| 364 } | 376 } |
| 365 | 377 |
| 366 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC
ollector) | 378 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC
ollector) |
| 367 { | 379 { |
| 368 ASSERT(!isMaster()); | 380 ASSERT(!isMaster()); |
| 369 Vector<RefPtr<StyleSheet> > sheetsForList; | 381 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > sheetsForList; |
| 370 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL
ist); | 382 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL
ist); |
| 371 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); | 383 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); |
| 372 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); | 384 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); |
| 373 } | 385 } |
| 374 | 386 |
| 375 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) | 387 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
| 376 { | 388 { |
| 377 ASSERT(isMaster()); | 389 ASSERT(isMaster()); |
| 378 ASSERT(!m_document.inStyleRecalc()); | 390 ASSERT(!m_document.inStyleRecalc()); |
| 379 | 391 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 404 | 416 |
| 405 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document); | 417 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document); |
| 406 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); | 418 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); |
| 407 | 419 |
| 408 m_dirtyTreeScopes.clear(); | 420 m_dirtyTreeScopes.clear(); |
| 409 m_documentScopeDirty = false; | 421 m_documentScopeDirty = false; |
| 410 | 422 |
| 411 return requiresFullStyleRecalc; | 423 return requiresFullStyleRecalc; |
| 412 } | 424 } |
| 413 | 425 |
| 414 const Vector<RefPtr<StyleSheet> > StyleEngine::activeStyleSheetsForInspector() c
onst | 426 const WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > StyleEngine::activeStyle
SheetsForInspector() const |
| 415 { | 427 { |
| 416 if (m_activeTreeScopes.isEmpty()) | 428 if (m_activeTreeScopes.isEmpty()) |
| 417 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 429 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
| 418 | 430 |
| 419 Vector<RefPtr<StyleSheet> > activeStyleSheets; | 431 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > activeStyleSheets; |
| 420 | 432 |
| 421 activeStyleSheets.appendVector(m_documentStyleSheetCollection.styleSheetsFor
StyleSheetList()); | 433 activeStyleSheets.appendVector(m_documentStyleSheetCollection.styleSheetsFor
StyleSheetList()); |
| 422 | 434 |
| 423 TreeScopeSet::const_iterator begin = m_activeTreeScopes.begin(); | 435 TreeScopeSet::const_iterator begin = m_activeTreeScopes.begin(); |
| 424 TreeScopeSet::const_iterator end = m_activeTreeScopes.end(); | 436 TreeScopeSet::const_iterator end = m_activeTreeScopes.end(); |
| 425 for (TreeScopeSet::const_iterator it = begin; it != end; ++it) { | 437 for (TreeScopeSet::const_iterator it = begin; it != end; ++it) { |
| 426 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa
p.get(*it)) | 438 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa
p.get(*it)) |
| 427 activeStyleSheets.appendVector(collection->styleSheetsForStyleSheetL
ist()); | 439 activeStyleSheets.appendVector(collection->styleSheetsForStyleSheetL
ist()); |
| 428 } | 440 } |
| 429 | 441 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 void StyleEngine::removeSheet(StyleSheetContents* contents) | 633 void StyleEngine::removeSheet(StyleSheetContents* contents) |
| 622 { | 634 { |
| 623 WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>:
:iterator it = sheetToTextCache().find(contents); | 635 WillBeHeapHashMap<RawPtrWillBeWeakMember<StyleSheetContents>, AtomicString>:
:iterator it = sheetToTextCache().find(contents); |
| 624 if (it == sheetToTextCache().end()) | 636 if (it == sheetToTextCache().end()) |
| 625 return; | 637 return; |
| 626 | 638 |
| 627 textToSheetCache().remove(it->value); | 639 textToSheetCache().remove(it->value); |
| 628 sheetToTextCache().remove(contents); | 640 sheetToTextCache().remove(contents); |
| 629 } | 641 } |
| 630 | 642 |
| 643 void StyleEngine::trace(Visitor* visitor) |
| 644 { |
| 645 visitor->trace(m_injectedAuthorStyleSheets); |
| 646 visitor->trace(m_authorStyleSheets); |
| 631 } | 647 } |
| 648 |
| 649 } |
| OLD | NEW |