| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 m_fontSelector.clear(); | 99 m_fontSelector.clear(); |
| 100 m_resolver.clear(); | 100 m_resolver.clear(); |
| 101 m_styleSheetCollectionMap.clear(); | 101 m_styleSheetCollectionMap.clear(); |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 inline Document* StyleEngine::master() | 105 inline Document* StyleEngine::master() |
| 106 { | 106 { |
| 107 if (isMaster()) | 107 if (isMaster()) |
| 108 return m_document; | 108 return m_document; |
| 109 HTMLImportsController* import = m_document->importsController(); | 109 HTMLImportsController* import = document().importsController(); |
| 110 if (!import) // Document::import() can return null while executing its destr
uctor. | 110 if (!import) // Document::import() can return null while executing its destr
uctor. |
| 111 return 0; | 111 return 0; |
| 112 return import->master(); | 112 return import->master(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) | 115 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) |
| 116 { | 116 { |
| 117 if (treeScopes.isEmpty()) { | 117 if (treeScopes.isEmpty()) { |
| 118 treeScopes.add(treeScope); | 118 treeScopes.add(treeScope); |
| 119 return; | 119 return; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return m_injectedAuthorStyleSheets; | 195 return m_injectedAuthorStyleSheets; |
| 196 } | 196 } |
| 197 | 197 |
| 198 void StyleEngine::updateInjectedStyleSheetCache() const | 198 void StyleEngine::updateInjectedStyleSheetCache() const |
| 199 { | 199 { |
| 200 if (m_injectedStyleSheetCacheValid) | 200 if (m_injectedStyleSheetCacheValid) |
| 201 return; | 201 return; |
| 202 m_injectedStyleSheetCacheValid = true; | 202 m_injectedStyleSheetCacheValid = true; |
| 203 m_injectedAuthorStyleSheets.clear(); | 203 m_injectedAuthorStyleSheets.clear(); |
| 204 | 204 |
| 205 Page* owningPage = m_document->page(); | 205 Page* owningPage = document().page(); |
| 206 if (!owningPage) | 206 if (!owningPage) |
| 207 return; | 207 return; |
| 208 | 208 |
| 209 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance
().entries(); | 209 const InjectedStyleSheetEntryVector& entries = InjectedStyleSheets::instance
().entries(); |
| 210 for (unsigned i = 0; i < entries.size(); ++i) { | 210 for (unsigned i = 0; i < entries.size(); ++i) { |
| 211 const InjectedStyleSheetEntry* entry = entries[i].get(); | 211 const InjectedStyleSheetEntry* entry = entries[i].get(); |
| 212 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && m_document->
ownerElement()) | 212 if (entry->injectedFrames() == InjectStyleInTopFrameOnly && document().o
wnerElement()) |
| 213 continue; | 213 continue; |
| 214 if (!URLPatternMatcher::matchesPatterns(m_document->url(), entry->whitel
ist())) | 214 if (!URLPatternMatcher::matchesPatterns(document().url(), entry->whiteli
st())) |
| 215 continue; | 215 continue; |
| 216 RefPtrWillBeRawPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInli
ne(m_document, KURL()); | 216 RefPtrWillBeRawPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInli
ne(m_document, KURL()); |
| 217 m_injectedAuthorStyleSheets.append(groupSheet); | 217 m_injectedAuthorStyleSheets.append(groupSheet); |
| 218 groupSheet->contents()->parseString(entry->source()); | 218 groupSheet->contents()->parseString(entry->source()); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 void StyleEngine::invalidateInjectedStyleSheetCache() | 222 void StyleEngine::invalidateInjectedStyleSheetCache() |
| 223 { | 223 { |
| 224 m_injectedStyleSheetCacheValid = false; | 224 m_injectedStyleSheetCacheValid = false; |
| 225 markDocumentDirty(); | 225 markDocumentDirty(); |
| 226 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets | 226 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets |
| 227 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). | 227 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). |
| 228 m_document->styleResolverChanged(RecalcStyleDeferred); | 228 document().styleResolverChanged(RecalcStyleDeferred); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void StyleEngine::addAuthorSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> auth
orSheet) | 231 void StyleEngine::addAuthorSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> auth
orSheet) |
| 232 { | 232 { |
| 233 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document)); | 233 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document)); |
| 234 m_document->addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImm
ediately); | 234 document().addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); |
| 235 markDocumentDirty(); | 235 markDocumentDirty(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void StyleEngine::addPendingSheet() | 238 void StyleEngine::addPendingSheet() |
| 239 { | 239 { |
| 240 m_pendingStylesheets++; | 240 m_pendingStylesheets++; |
| 241 } | 241 } |
| 242 | 242 |
| 243 // This method is called whenever a top-level stylesheet has finished loading. | 243 // This method is called whenever a top-level stylesheet has finished loading. |
| 244 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, RemovePendin
gSheetNotificationType notification) | 244 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, RemovePendin
gSheetNotificationType notification) |
| 245 { | 245 { |
| 246 ASSERT(styleSheetCandidateNode); | 246 ASSERT(styleSheetCandidateNode); |
| 247 TreeScope* treeScope = isHTMLStyleElement(*styleSheetCandidateNode) ? &style
SheetCandidateNode->treeScope() : m_document.get(); | 247 TreeScope* treeScope = isHTMLStyleElement(*styleSheetCandidateNode) ? &style
SheetCandidateNode->treeScope() : m_document.get(); |
| 248 markTreeScopeDirty(*treeScope); | 248 markTreeScopeDirty(*treeScope); |
| 249 | 249 |
| 250 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. | 250 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. |
| 251 ASSERT(m_pendingStylesheets > 0); | 251 ASSERT(m_pendingStylesheets > 0); |
| 252 | 252 |
| 253 m_pendingStylesheets--; | 253 m_pendingStylesheets--; |
| 254 if (m_pendingStylesheets) | 254 if (m_pendingStylesheets) |
| 255 return; | 255 return; |
| 256 | 256 |
| 257 if (notification == RemovePendingSheetNotifyLater) { | 257 if (notification == RemovePendingSheetNotifyLater) { |
| 258 m_document->setNeedsNotifyRemoveAllPendingStylesheet(); | 258 document().setNeedsNotifyRemoveAllPendingStylesheet(); |
| 259 return; | 259 return; |
| 260 } | 260 } |
| 261 | 261 |
| 262 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know | 262 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know |
| 263 // what's new. We should track that to tell the style system what changed. | 263 // what's new. We should track that to tell the style system what changed. |
| 264 m_document->didRemoveAllPendingStylesheet(); | 264 document().didRemoveAllPendingStylesheet(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void StyleEngine::modifiedStyleSheet(StyleSheet* sheet) | 267 void StyleEngine::modifiedStyleSheet(StyleSheet* sheet) |
| 268 { | 268 { |
| 269 if (!sheet) | 269 if (!sheet) |
| 270 return; | 270 return; |
| 271 | 271 |
| 272 Node* node = sheet->ownerNode(); | 272 Node* node = sheet->ownerNode(); |
| 273 if (!node || !node->inDocument()) | 273 if (!node || !node->inDocument()) |
| 274 return; | 274 return; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 ASSERT(!isMaster()); | 351 ASSERT(!isMaster()); |
| 352 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > sheetsForList; | 352 WillBeHeapVector<RefPtrWillBeMember<StyleSheet> > sheetsForList; |
| 353 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL
ist); | 353 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL
ist); |
| 354 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); | 354 m_documentStyleSheetCollection.collectStyleSheets(this, subcollector); |
| 355 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); | 355 m_documentStyleSheetCollection.swapSheetsForSheetList(sheetsForList); |
| 356 } | 356 } |
| 357 | 357 |
| 358 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) | 358 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
| 359 { | 359 { |
| 360 ASSERT(isMaster()); | 360 ASSERT(isMaster()); |
| 361 ASSERT(!m_document->inStyleRecalc()); | 361 ASSERT(!document().inStyleRecalc()); |
| 362 | 362 |
| 363 if (!m_document->isActive()) | 363 if (!document().isActive()) |
| 364 return false; | 364 return false; |
| 365 | 365 |
| 366 bool requiresFullStyleRecalc = false; | 366 bool requiresFullStyleRecalc = false; |
| 367 if (m_documentScopeDirty || updateMode == FullStyleUpdate) | 367 if (m_documentScopeDirty || updateMode == FullStyleUpdate) |
| 368 requiresFullStyleRecalc = m_documentStyleSheetCollection.updateActiveSty
leSheets(this, updateMode); | 368 requiresFullStyleRecalc = m_documentStyleSheetCollection.updateActiveSty
leSheets(this, updateMode); |
| 369 | 369 |
| 370 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { | 370 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { |
| 371 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc
opes : m_dirtyTreeScopes; | 371 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc
opes : m_dirtyTreeScopes; |
| 372 HashSet<TreeScope*> treeScopesRemoved; | 372 HashSet<TreeScope*> treeScopesRemoved; |
| 373 | 373 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 m_resolver->finishAppendAuthorStyleSheets(); | 437 m_resolver->finishAppendAuthorStyleSheets(); |
| 438 m_resolver->setBuildScopedStyleTreeInDocumentOrder(false); | 438 m_resolver->setBuildScopedStyleTreeInDocumentOrder(false); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void StyleEngine::createResolver() | 441 void StyleEngine::createResolver() |
| 442 { | 442 { |
| 443 // It is a programming error to attempt to resolve style on a Document | 443 // It is a programming error to attempt to resolve style on a Document |
| 444 // which is not in a frame. Code which hits this should have checked | 444 // which is not in a frame. Code which hits this should have checked |
| 445 // Document::isActive() before calling into code which could get here. | 445 // Document::isActive() before calling into code which could get here. |
| 446 | 446 |
| 447 ASSERT(m_document->frame()); | 447 ASSERT(document().frame()); |
| 448 ASSERT(m_fontSelector); | 448 ASSERT(m_fontSelector); |
| 449 | 449 |
| 450 m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document)); | 450 m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document)); |
| 451 appendActiveAuthorStyleSheets(); | 451 appendActiveAuthorStyleSheets(); |
| 452 m_fontSelector->registerForInvalidationCallbacks(m_resolver.get()); | 452 m_fontSelector->registerForInvalidationCallbacks(m_resolver.get()); |
| 453 combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet()); | 453 combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet()); |
| 454 } | 454 } |
| 455 | 455 |
| 456 void StyleEngine::clearResolver() | 456 void StyleEngine::clearResolver() |
| 457 { | 457 { |
| 458 ASSERT(!m_document->inStyleRecalc()); | 458 ASSERT(!document().inStyleRecalc()); |
| 459 ASSERT(isMaster() || !m_resolver); | 459 ASSERT(isMaster() || !m_resolver); |
| 460 ASSERT(m_fontSelector || !m_resolver); | 460 ASSERT(m_fontSelector || !m_resolver); |
| 461 if (m_resolver) { | 461 if (m_resolver) { |
| 462 m_document->updateStyleInvalidationIfNeeded(); | 462 document().updateStyleInvalidationIfNeeded(); |
| 463 #if !ENABLE(OILPAN) | 463 #if !ENABLE(OILPAN) |
| 464 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()); | 464 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()); |
| 465 #endif | 465 #endif |
| 466 } | 466 } |
| 467 m_resolver.clear(); | 467 m_resolver.clear(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void StyleEngine::clearMasterResolver() | 470 void StyleEngine::clearMasterResolver() |
| 471 { | 471 { |
| 472 if (Document* master = this->master()) | 472 if (Document* master = this->master()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 493 StyleResolverChange change; | 493 StyleResolverChange change; |
| 494 | 494 |
| 495 if (!isMaster()) { | 495 if (!isMaster()) { |
| 496 if (Document* master = this->master()) | 496 if (Document* master = this->master()) |
| 497 master->styleResolverChanged(time, mode); | 497 master->styleResolverChanged(time, mode); |
| 498 return change; | 498 return change; |
| 499 } | 499 } |
| 500 | 500 |
| 501 // Don't bother updating, since we haven't loaded all our style info yet | 501 // Don't bother updating, since we haven't loaded all our style info yet |
| 502 // and haven't calculated the style selector for the first time. | 502 // and haven't calculated the style selector for the first time. |
| 503 if (!m_document->isActive() || shouldClearResolver()) { | 503 if (!document().isActive() || shouldClearResolver()) { |
| 504 clearResolver(); | 504 clearResolver(); |
| 505 return change; | 505 return change; |
| 506 } | 506 } |
| 507 | 507 |
| 508 m_didCalculateResolver = true; | 508 m_didCalculateResolver = true; |
| 509 if (m_document->didLayoutWithPendingStylesheets() && !hasPendingSheets()) | 509 if (document().didLayoutWithPendingStylesheets() && !hasPendingSheets()) |
| 510 change.setNeedsRepaint(); | 510 change.setNeedsRepaint(); |
| 511 | 511 |
| 512 if (updateActiveStyleSheets(mode)) | 512 if (updateActiveStyleSheets(mode)) |
| 513 change.setNeedsStyleRecalc(); | 513 change.setNeedsStyleRecalc(); |
| 514 | 514 |
| 515 return change; | 515 return change; |
| 516 } | 516 } |
| 517 | 517 |
| 518 void StyleEngine::clearFontCache() | 518 void StyleEngine::clearFontCache() |
| 519 { | 519 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 markDocumentDirty(); | 552 markDocumentDirty(); |
| 553 return; | 553 return; |
| 554 } | 554 } |
| 555 | 555 |
| 556 m_dirtyTreeScopes.add(&scope); | 556 m_dirtyTreeScopes.add(&scope); |
| 557 } | 557 } |
| 558 | 558 |
| 559 void StyleEngine::markDocumentDirty() | 559 void StyleEngine::markDocumentDirty() |
| 560 { | 560 { |
| 561 m_documentScopeDirty = true; | 561 m_documentScopeDirty = true; |
| 562 if (m_document->importLoader()) | 562 if (document().importLoader()) |
| 563 m_document->importsController()->master()->styleEngine()->markDocumentDi
rty(); | 563 document().importsController()->master()->styleEngine()->markDocumentDir
ty(); |
| 564 } | 564 } |
| 565 | 565 |
| 566 static bool isCacheableForStyleElement(const StyleSheetContents& contents) | 566 static bool isCacheableForStyleElement(const StyleSheetContents& contents) |
| 567 { | 567 { |
| 568 // FIXME: Support copying import rules. | 568 // FIXME: Support copying import rules. |
| 569 if (!contents.importRules().isEmpty()) | 569 if (!contents.importRules().isEmpty()) |
| 570 return false; | 570 return false; |
| 571 // Until import rules are supported in cached sheets it's not possible for l
oading to fail. | 571 // Until import rules are supported in cached sheets it's not possible for l
oading to fail. |
| 572 ASSERT(!contents.didLoadErrorOccur()); | 572 ASSERT(!contents.didLoadErrorOccur()); |
| 573 // It is not the original sheet anymore. | 573 // It is not the original sheet anymore. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 visitor->trace(m_authorStyleSheets); | 636 visitor->trace(m_authorStyleSheets); |
| 637 visitor->trace(m_documentStyleSheetCollection); | 637 visitor->trace(m_documentStyleSheetCollection); |
| 638 visitor->trace(m_styleSheetCollectionMap); | 638 visitor->trace(m_styleSheetCollectionMap); |
| 639 visitor->trace(m_resolver); | 639 visitor->trace(m_resolver); |
| 640 visitor->trace(m_fontSelector); | 640 visitor->trace(m_fontSelector); |
| 641 visitor->trace(m_textToSheetCache); | 641 visitor->trace(m_textToSheetCache); |
| 642 visitor->trace(m_sheetToTextCache); | 642 visitor->trace(m_sheetToTextCache); |
| 643 } | 643 } |
| 644 | 644 |
| 645 } | 645 } |
| OLD | NEW |