Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: Source/core/dom/StyleEngine.cpp

Issue 751593002: Removed add/removeScopedStyleResolver from StyleEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed inspector/elements/edit-dom-actions.html Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 if (m_fontSelector) { 97 if (m_fontSelector) {
98 m_fontSelector->clearDocument(); 98 m_fontSelector->clearDocument();
99 m_fontSelector->unregisterForInvalidationCallbacks(this); 99 m_fontSelector->unregisterForInvalidationCallbacks(this);
100 } 100 }
101 101
102 // Decrement reference counts for things we could be keeping alive. 102 // Decrement reference counts for things we could be keeping alive.
103 m_fontSelector.clear(); 103 m_fontSelector.clear();
104 m_resolver.clear(); 104 m_resolver.clear();
105 m_styleSheetCollectionMap.clear(); 105 m_styleSheetCollectionMap.clear();
106 for (const auto& resolver : m_scopedStyleResolvers) 106 m_activeTreeScopes.clear();
107 const_cast<TreeScope&>(resolver->treeScope()).clearScopedStyleResolver() ;
108 m_scopedStyleResolvers.clear();
109 } 107 }
110 #endif 108 #endif
111 109
112 inline Document* StyleEngine::master() 110 inline Document* StyleEngine::master()
113 { 111 {
114 if (isMaster()) 112 if (isMaster())
115 return m_document; 113 return m_document;
116 HTMLImportsController* import = document().importsController(); 114 HTMLImportsController* import = document().importsController();
117 if (!import) // Document::import() can return null while executing its destr uctor. 115 if (!import) // Document::import() can return null while executing its destr uctor.
118 return 0; 116 return 0;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope ) 310 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope )
313 { 311 {
314 ASSERT(isStyleElement(*node) || treeScope == m_document); 312 ASSERT(isStyleElement(*node) || treeScope == m_document);
315 ASSERT(!isXSLStyleSheet(*node)); 313 ASSERT(!isXSLStyleSheet(*node));
316 314
317 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e); 315 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e);
318 ASSERT(collection); 316 ASSERT(collection);
319 collection->removeStyleSheetCandidateNode(node); 317 collection->removeStyleSheetCandidateNode(node);
320 318
321 markTreeScopeDirty(treeScope); 319 markTreeScopeDirty(treeScope);
322 m_activeTreeScopes.remove(&treeScope);
323 } 320 }
324 321
325 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node) 322 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node)
326 { 323 {
327 if (!node->inDocument()) 324 if (!node->inDocument())
328 return; 325 return;
329 326
330 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt; 327 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt;
331 ASSERT(isStyleElement(*node) || treeScope == m_document); 328 ASSERT(isStyleElement(*node) || treeScope == m_document);
332 markTreeScopeDirty(treeScope); 329 markTreeScopeDirty(treeScope);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { 386 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) {
390 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc opes : m_dirtyTreeScopes; 387 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc opes : m_dirtyTreeScopes;
391 HashSet<TreeScope*> treeScopesRemoved; 388 HashSet<TreeScope*> treeScopesRemoved;
392 389
393 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.en d(); ++it) { 390 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.en d(); ++it) {
394 TreeScope* treeScope = *it; 391 TreeScope* treeScope = *it;
395 ASSERT(treeScope != m_document); 392 ASSERT(treeScope != m_document);
396 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeS tyleSheetCollection*>(styleSheetCollectionFor(*treeScope)); 393 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeS tyleSheetCollection*>(styleSheetCollectionFor(*treeScope));
397 ASSERT(collection); 394 ASSERT(collection);
398 collection->updateActiveStyleSheets(this, updateMode); 395 collection->updateActiveStyleSheets(this, updateMode);
399 if (!collection->hasStyleSheetCandidateNodes()) 396 if (!collection->hasStyleSheetCandidateNodes()) {
400 treeScopesRemoved.add(treeScope); 397 treeScopesRemoved.add(treeScope);
398 // When removing TreeScope from ActiveTreeScopes,
399 // its resolver should be destroyed by invoking resetAuthorStyle .
400 ASSERT(!treeScope->scopedStyleResolver());
401 }
401 } 402 }
402 m_activeTreeScopes.removeAll(treeScopesRemoved); 403 m_activeTreeScopes.removeAll(treeScopesRemoved);
403 } 404 }
404 405
405 InspectorInstrumentation::activeStyleSheetsUpdated(m_document); 406 InspectorInstrumentation::activeStyleSheetsUpdated(m_document);
406 m_usesRemUnits = documentStyleSheetCollection()->usesRemUnits(); 407 m_usesRemUnits = documentStyleSheetCollection()->usesRemUnits();
407 408
408 m_dirtyTreeScopes.clear(); 409 m_dirtyTreeScopes.clear();
409 m_documentScopeDirty = false; 410 m_documentScopeDirty = false;
410 } 411 }
(...skipping 15 matching lines...) Expand all
426 } 427 }
427 428
428 // FIXME: Inspector needs a vector which has all active stylesheets. 429 // FIXME: Inspector needs a vector which has all active stylesheets.
429 // However, creating such a large vector might cause performance regression. 430 // However, creating such a large vector might cause performance regression.
430 // Need to implement some smarter solution. 431 // Need to implement some smarter solution.
431 return activeStyleSheets; 432 return activeStyleSheets;
432 } 433 }
433 434
434 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) 435 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot)
435 { 436 {
436 if (shadowRoot->scopedStyleResolver())
437 removeScopedStyleResolver(shadowRoot->scopedStyleResolver());
438 m_styleSheetCollectionMap.remove(shadowRoot); 437 m_styleSheetCollectionMap.remove(shadowRoot);
439 } 438 }
440 439
441 void StyleEngine::appendActiveAuthorStyleSheets() 440 void StyleEngine::appendActiveAuthorStyleSheets()
442 { 441 {
443 ASSERT(isMaster()); 442 ASSERT(isMaster());
444 443
445 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets()); 444 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets());
446 445
447 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); 446 TreeScopeSet::iterator begin = m_activeTreeScopes.begin();
448 TreeScopeSet::iterator end = m_activeTreeScopes.end(); 447 TreeScopeSet::iterator end = m_activeTreeScopes.end();
449 for (TreeScopeSet::iterator it = begin; it != end; ++it) { 448 for (TreeScopeSet::iterator it = begin; it != end; ++it) {
450 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(*it)) 449 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(*it))
451 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets()); 450 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets());
452 } 451 }
453 m_resolver->finishAppendAuthorStyleSheets(); 452 m_resolver->finishAppendAuthorStyleSheets();
454 } 453 }
455 454
456 void StyleEngine::createResolver() 455 void StyleEngine::createResolver()
457 { 456 {
458 // It is a programming error to attempt to resolve style on a Document 457 // It is a programming error to attempt to resolve style on a Document
459 // which is not in a frame. Code which hits this should have checked 458 // which is not in a frame. Code which hits this should have checked
460 // Document::isActive() before calling into code which could get here. 459 // Document::isActive() before calling into code which could get here.
461 460
462 ASSERT(document().frame()); 461 ASSERT(document().frame());
463 462
464 m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document)); 463 m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document));
465 addScopedStyleResolver(&m_document->ensureScopedStyleResolver());
466 464
465 // A scoped style resolver for document will be created during
466 // appendActiveAuthorStyleSheets if needed.
467 appendActiveAuthorStyleSheets(); 467 appendActiveAuthorStyleSheets();
468 combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet()); 468 combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet());
469 } 469 }
470 470
471 void StyleEngine::clearResolver() 471 void StyleEngine::clearResolver()
472 { 472 {
473 ASSERT(!document().inStyleRecalc()); 473 ASSERT(!document().inStyleRecalc());
474 ASSERT(isMaster() || !m_resolver); 474 ASSERT(isMaster() || !m_resolver);
475 475
476 for (const auto& resolver: m_scopedStyleResolvers) 476 document().clearScopedStyleResolver();
477 const_cast<TreeScope&>(resolver->treeScope()).clearScopedStyleResolver() ; 477 // clearResolver might be invoked while destryoing document. In this case,
478 m_scopedStyleResolvers.clear(); 478 // treescopes in m_activeTreeScopes might have already been destoryed,
479 // because m_activeTreeScopes are updated in updateActiveStyleSheets, not
480 // in removeStyleSheetCandidateNode. So we should not invoke
481 // treeScope->clearScopedStyleResolver when document is not active.
482 if (document().isActive()) {
483 for (auto& treeScope: m_activeTreeScopes)
484 treeScope->clearScopedStyleResolver();
485 }
479 486
480 if (m_resolver) 487 if (m_resolver)
481 document().updateStyleInvalidationIfNeeded(); 488 document().updateStyleInvalidationIfNeeded();
482 m_resolver.clear(); 489 m_resolver.clear();
483 } 490 }
484 491
485 void StyleEngine::clearMasterResolver() 492 void StyleEngine::clearMasterResolver()
486 { 493 {
487 if (Document* master = this->master()) 494 if (Document* master = this->master())
488 master->styleEngine()->clearResolver(); 495 master->styleEngine()->clearResolver();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 if (it == m_sheetToTextCache.end()) 642 if (it == m_sheetToTextCache.end())
636 return; 643 return;
637 644
638 m_textToSheetCache.remove(it->value); 645 m_textToSheetCache.remove(it->value);
639 m_sheetToTextCache.remove(contents); 646 m_sheetToTextCache.remove(contents);
640 } 647 }
641 648
642 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const 649 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
643 { 650 {
644 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; 651 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents;
645 for (const auto& resolver : m_scopedStyleResolvers) 652 if (document().scopedStyleResolver())
646 resolver->collectFeaturesTo(features, visitedSharedStyleSheetContents); 653 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents);
654 for (auto& treeScope: m_activeTreeScopes) {
655 ASSERT(treeScope->scopedStyleResolver());
656 treeScope->scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents);
657 }
647 } 658 }
648 659
649 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) 660 void StyleEngine::fontsNeedUpdate(CSSFontSelector*)
650 { 661 {
651 if (!document().isActive()) 662 if (!document().isActive())
652 return; 663 return;
653 664
654 if (m_resolver) 665 if (m_resolver)
655 m_resolver->invalidateMatchedPropertiesCache(); 666 m_resolver->invalidateMatchedPropertiesCache();
656 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci ng::create(StyleChangeReason::Fonts)); 667 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci ng::create(StyleChangeReason::Fonts));
657 } 668 }
658 669
659 void StyleEngine::trace(Visitor* visitor) 670 void StyleEngine::trace(Visitor* visitor)
660 { 671 {
661 #if ENABLE(OILPAN) 672 #if ENABLE(OILPAN)
662 visitor->trace(m_document); 673 visitor->trace(m_document);
663 visitor->trace(m_injectedAuthorStyleSheets); 674 visitor->trace(m_injectedAuthorStyleSheets);
664 visitor->trace(m_authorStyleSheets); 675 visitor->trace(m_authorStyleSheets);
665 visitor->trace(m_documentStyleSheetCollection); 676 visitor->trace(m_documentStyleSheetCollection);
666 visitor->trace(m_styleSheetCollectionMap); 677 visitor->trace(m_styleSheetCollectionMap);
667 visitor->trace(m_scopedStyleResolvers);
668 visitor->trace(m_resolver); 678 visitor->trace(m_resolver);
669 visitor->trace(m_fontSelector); 679 visitor->trace(m_fontSelector);
670 visitor->trace(m_textToSheetCache); 680 visitor->trace(m_textToSheetCache);
671 visitor->trace(m_sheetToTextCache); 681 visitor->trace(m_sheetToTextCache);
672 #endif 682 #endif
673 CSSFontSelectorClient::trace(visitor); 683 CSSFontSelectorClient::trace(visitor);
674 } 684 }
675 685
676 } 686 }
OLDNEW
« Source/core/css/resolver/StyleResolver.cpp ('K') | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698