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

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

Issue 1162533005: Stop sorting StyleEngine::m_activeTreeScopes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 inline Document* StyleEngine::master() 106 inline Document* StyleEngine::master()
107 { 107 {
108 if (isMaster()) 108 if (isMaster())
109 return m_document; 109 return m_document;
110 HTMLImportsController* import = document().importsController(); 110 HTMLImportsController* import = document().importsController();
111 if (!import) // Document::import() can return null while executing its destr uctor. 111 if (!import) // Document::import() can return null while executing its destr uctor.
112 return 0; 112 return 0;
113 return import->master(); 113 return import->master();
114 } 114 }
115 115
116 void StyleEngine::OrderedTreeScopeSet::insert(TreeScope* treeScope)
117 {
118 if (m_treeScopes.isEmpty()) {
119 m_treeScopes.append(treeScope);
120 m_hash.add(treeScope);
121 return;
122 }
123 if (m_hash.contains(treeScope))
124 return;
125
126 int end = m_treeScopes.size() - 1;
127 int start = 0;
128 int position = 0;
129 unsigned result = 0;
130
131 while (start <= end) {
132 position = (start + end) / 2;
133 result = m_treeScopes[position]->comparePosition(*treeScope);
134
135 if (result & Node::DOCUMENT_POSITION_PRECEDING) {
136 end = position - 1;
137 } else {
138 ASSERT(result & Node::DOCUMENT_POSITION_FOLLOWING);
139 start = position + 1;
140 }
141 }
142
143 if (result & Node::DOCUMENT_POSITION_FOLLOWING) {
144 ++position;
145 ASSERT(static_cast<size_t>(position) == m_treeScopes.size() || (m_treeSc opes[position]->comparePosition(*treeScope) & Node::DOCUMENT_POSITION_PRECEDING) );
146 }
147 m_treeScopes.insert(position, treeScope);
148 m_hash.add(treeScope);
149
150 #if ENABLE(ASSERT)
151 // Check whether m_treeScopes is sorted in document order or not.
152 for (unsigned i = 0; i < m_treeScopes.size() - 1; ++i) {
153 unsigned result = m_treeScopes[i]->comparePosition(*m_treeScopes[i + 1]) ;
154 ASSERT(result & Node::DOCUMENT_POSITION_FOLLOWING);
155 }
156 #endif
157 }
158
159 void StyleEngine::OrderedTreeScopeSet::remove(TreeScope* treeScope)
160 {
161 if (!m_hash.contains(treeScope))
162 return;
163 size_t position = m_treeScopes.find(treeScope);
164 m_treeScopes.remove(position);
165 m_hash.remove(treeScope);
166 }
167
168 DEFINE_TRACE(StyleEngine::OrderedTreeScopeSet)
169 {
170 #if ENABLE(OILPAN)
171 visitor->trace(m_treeScopes);
172 visitor->trace(m_hash);
173 #endif
174 }
175
176 TreeScopeStyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeSc ope& treeScope) 116 TreeScopeStyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeSc ope& treeScope)
177 { 117 {
178 if (treeScope == m_document) 118 if (treeScope == m_document)
179 return documentStyleSheetCollection(); 119 return documentStyleSheetCollection();
180 120
181 StyleSheetCollectionMap::AddResult result = m_styleSheetCollectionMap.add(&t reeScope, nullptr); 121 StyleSheetCollectionMap::AddResult result = m_styleSheetCollectionMap.add(&t reeScope, nullptr);
182 if (result.isNewEntry) 122 if (result.isNewEntry)
183 result.storedValue->value = adoptPtrWillBeNoop(new ShadowTreeStyleSheetC ollection(toShadowRoot(treeScope))); 123 result.storedValue->value = adoptPtrWillBeNoop(new ShadowTreeStyleSheetC ollection(toShadowRoot(treeScope)));
184 return result.storedValue->value.get(); 124 return result.storedValue->value.get();
185 } 125 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 219
280 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt; 220 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt;
281 ASSERT(isStyleElement(*node) || treeScope == m_document); 221 ASSERT(isStyleElement(*node) || treeScope == m_document);
282 ASSERT(!isXSLStyleSheet(*node)); 222 ASSERT(!isXSLStyleSheet(*node));
283 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope); 223 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope);
284 ASSERT(collection); 224 ASSERT(collection);
285 collection->addStyleSheetCandidateNode(node, createdByParser); 225 collection->addStyleSheetCandidateNode(node, createdByParser);
286 226
287 markTreeScopeDirty(treeScope); 227 markTreeScopeDirty(treeScope);
288 if (treeScope != m_document) 228 if (treeScope != m_document)
289 m_activeTreeScopes.insert(&treeScope); 229 m_activeTreeScopes.add(&treeScope);
290 } 230 }
291 231
292 void StyleEngine::removeStyleSheetCandidateNode(Node* node) 232 void StyleEngine::removeStyleSheetCandidateNode(Node* node)
293 { 233 {
294 removeStyleSheetCandidateNode(node, *m_document); 234 removeStyleSheetCandidateNode(node, *m_document);
295 } 235 }
296 236
297 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope ) 237 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope )
298 { 238 {
299 ASSERT(isStyleElement(*node) || treeScope == m_document); 239 ASSERT(isStyleElement(*node) || treeScope == m_document);
(...skipping 22 matching lines...) Expand all
322 bool StyleEngine::shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMo de updateMode) const 262 bool StyleEngine::shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMo de updateMode) const
323 { 263 {
324 return m_documentScopeDirty || updateMode == FullStyleUpdate; 264 return m_documentScopeDirty || updateMode == FullStyleUpdate;
325 } 265 }
326 266
327 bool StyleEngine::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdate Mode updateMode) const 267 bool StyleEngine::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdate Mode updateMode) const
328 { 268 {
329 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; 269 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate;
330 } 270 }
331 271
332 void StyleEngine::clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScop eSet::iterator begin, UnorderedTreeScopeSet::iterator end) 272 void StyleEngine::clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScop eSet& treeScopes)
333 { 273 {
334 for (UnorderedTreeScopeSet::iterator it = begin; it != end; ++it) { 274 for (TreeScope* treeScope : treeScopes) {
335 TreeScope& treeScope = **it;
336 ASSERT(treeScope != m_document); 275 ASSERT(treeScope != m_document);
337 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyle SheetCollection*>(styleSheetCollectionFor(treeScope)); 276 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyle SheetCollection*>(styleSheetCollectionFor(*treeScope));
338 ASSERT(collection); 277 ASSERT(collection);
339 collection->clearMediaQueryRuleSetStyleSheets(); 278 collection->clearMediaQueryRuleSetStyleSheets();
340 } 279 }
341 } 280 }
342 281
343 void StyleEngine::clearMediaQueryRuleSetStyleSheets() 282 void StyleEngine::clearMediaQueryRuleSetStyleSheets()
344 { 283 {
345 documentStyleSheetCollection()->clearMediaQueryRuleSetStyleSheets(); 284 documentStyleSheetCollection()->clearMediaQueryRuleSetStyleSheets();
346 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes.beginUnorder ed(), m_activeTreeScopes.endUnordered()); 285 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes);
347 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes.begin(), m_di rtyTreeScopes.end()); 286 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_dirtyTreeScopes);
348 } 287 }
349 288
350 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector) 289 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector)
351 { 290 {
352 ASSERT(!isMaster()); 291 ASSERT(!isMaster());
353 WillBeHeapVector<RefPtrWillBeMember<StyleSheet>> sheetsForList; 292 WillBeHeapVector<RefPtrWillBeMember<StyleSheet>> sheetsForList;
354 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist); 293 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist);
355 documentStyleSheetCollection()->collectStyleSheets(*this, subcollector); 294 documentStyleSheetCollection()->collectStyleSheets(*this, subcollector);
356 documentStyleSheetCollection()->swapSheetsForSheetList(sheetsForList); 295 documentStyleSheetCollection()->swapSheetsForSheetList(sheetsForList);
357 } 296 }
(...skipping 20 matching lines...) Expand all
378 if (!document().isActive()) 317 if (!document().isActive())
379 return; 318 return;
380 319
381 if (shouldUpdateDocumentStyleSheetCollection(updateMode)) 320 if (shouldUpdateDocumentStyleSheetCollection(updateMode))
382 documentStyleSheetCollection()->updateActiveStyleSheets(*this, updateMod e); 321 documentStyleSheetCollection()->updateActiveStyleSheets(*this, updateMod e);
383 322
384 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { 323 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) {
385 UnorderedTreeScopeSet treeScopesRemoved; 324 UnorderedTreeScopeSet treeScopesRemoved;
386 325
387 if (updateMode == FullStyleUpdate) { 326 if (updateMode == FullStyleUpdate) {
388 for (unsigned i = 0; i < m_activeTreeScopes.size(); ++i) 327 for (TreeScope* treeScope : m_activeTreeScopes)
389 updateActiveStyleSheetsInShadow(updateMode, m_activeTreeScopes[i ], treeScopesRemoved); 328 updateActiveStyleSheetsInShadow(updateMode, treeScope, treeScope sRemoved);
390 } else { 329 } else {
391 for (UnorderedTreeScopeSet::iterator it = m_dirtyTreeScopes.begin(); it != m_dirtyTreeScopes.end(); ++it) { 330 for (TreeScope* treeScope : m_dirtyTreeScopes)
392 updateActiveStyleSheetsInShadow(updateMode, *it, treeScopesRemov ed); 331 updateActiveStyleSheetsInShadow(updateMode, treeScope, treeScope sRemoved);
393 }
394 } 332 }
395 for (UnorderedTreeScopeSet::iterator it = treeScopesRemoved.begin(); it != treeScopesRemoved.end(); ++it) 333 for (TreeScope* treeScope : treeScopesRemoved)
396 m_activeTreeScopes.remove(*it); 334 m_activeTreeScopes.remove(treeScope);
397 } 335 }
398 336
399 InspectorInstrumentation::activeStyleSheetsUpdated(m_document); 337 InspectorInstrumentation::activeStyleSheetsUpdated(m_document);
400 m_usesRemUnits = documentStyleSheetCollection()->usesRemUnits(); 338 m_usesRemUnits = documentStyleSheetCollection()->usesRemUnits();
401 339
402 m_dirtyTreeScopes.clear(); 340 m_dirtyTreeScopes.clear();
403 m_documentScopeDirty = false; 341 m_documentScopeDirty = false;
404 } 342 }
405 343
406 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> StyleEngine::activeSty leSheetsForInspector() const 344 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> StyleEngine::activeSty leSheetsForInspector() const
407 { 345 {
408 if (m_activeTreeScopes.isEmpty()) 346 if (m_activeTreeScopes.isEmpty())
409 return documentStyleSheetCollection()->activeAuthorStyleSheets(); 347 return documentStyleSheetCollection()->activeAuthorStyleSheets();
410 348
411 WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> activeStyleSheets; 349 WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> activeStyleSheets;
412 350
413 activeStyleSheets.appendVector(documentStyleSheetCollection()->activeAuthorS tyleSheets()); 351 activeStyleSheets.appendVector(documentStyleSheetCollection()->activeAuthorS tyleSheets());
414 for (unsigned i = 0; i < m_activeTreeScopes.size(); ++i) { 352 for (TreeScope* treeScope : m_activeTreeScopes) {
415 TreeScope* treeScope = const_cast<TreeScope*>(m_activeTreeScopes[i]);
416 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(treeScope)) 353 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(treeScope))
417 activeStyleSheets.appendVector(collection->activeAuthorStyleSheets() ); 354 activeStyleSheets.appendVector(collection->activeAuthorStyleSheets() );
418 } 355 }
419 356
420 // FIXME: Inspector needs a vector which has all active stylesheets. 357 // FIXME: Inspector needs a vector which has all active stylesheets.
421 // However, creating such a large vector might cause performance regression. 358 // However, creating such a large vector might cause performance regression.
422 // Need to implement some smarter solution. 359 // Need to implement some smarter solution.
423 return activeStyleSheets; 360 return activeStyleSheets;
424 } 361 }
425 362
(...skipping 15 matching lines...) Expand all
441 m_styleSheetCollectionMap.remove(shadowRoot); 378 m_styleSheetCollectionMap.remove(shadowRoot);
442 m_activeTreeScopes.remove(shadowRoot); 379 m_activeTreeScopes.remove(shadowRoot);
443 m_dirtyTreeScopes.remove(shadowRoot); 380 m_dirtyTreeScopes.remove(shadowRoot);
444 } 381 }
445 382
446 void StyleEngine::appendActiveAuthorStyleSheets() 383 void StyleEngine::appendActiveAuthorStyleSheets()
447 { 384 {
448 ASSERT(isMaster()); 385 ASSERT(isMaster());
449 386
450 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets()); 387 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets());
451 for (unsigned i = 0; i < m_activeTreeScopes.size(); ++i) { 388 for (TreeScope* treeScope : m_activeTreeScopes) {
452 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(m_activeTreeScopes[i])) 389 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(treeScope))
453 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets()); 390 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets());
454 } 391 }
455 m_resolver->finishAppendAuthorStyleSheets(); 392 m_resolver->finishAppendAuthorStyleSheets();
456 } 393 }
457 394
458 void StyleEngine::createResolver() 395 void StyleEngine::createResolver()
459 { 396 {
460 // It is a programming error to attempt to resolve style on a Document 397 // It is a programming error to attempt to resolve style on a Document
461 // which is not in a frame. Code which hits this should have checked 398 // which is not in a frame. Code which hits this should have checked
462 // Document::isActive() before calling into code which could get here. 399 // Document::isActive() before calling into code which could get here.
(...skipping 14 matching lines...) Expand all
477 ASSERT(isMaster() || !m_resolver); 414 ASSERT(isMaster() || !m_resolver);
478 415
479 document().clearScopedStyleResolver(); 416 document().clearScopedStyleResolver();
480 // StyleEngine::shadowRootRemovedFromDocument removes not-in-document 417 // StyleEngine::shadowRootRemovedFromDocument removes not-in-document
481 // treescopes from activeTreeScopes. StyleEngine::didRemoveShadowRoot 418 // treescopes from activeTreeScopes. StyleEngine::didRemoveShadowRoot
482 // removes treescopes which are being destroyed from activeTreeScopes. 419 // removes treescopes which are being destroyed from activeTreeScopes.
483 // So we need to clearScopedStyleResolver for treescopes which have been 420 // So we need to clearScopedStyleResolver for treescopes which have been
484 // just removed from document. If document is destroyed before invoking 421 // just removed from document. If document is destroyed before invoking
485 // updateActiveStyleSheets, the treescope has a scopedStyleResolver which 422 // updateActiveStyleSheets, the treescope has a scopedStyleResolver which
486 // has destroyed StyleSheetContents. 423 // has destroyed StyleSheetContents.
487 for (UnorderedTreeScopeSet::iterator it = m_activeTreeScopes.beginUnordered( ); it != m_activeTreeScopes.endUnordered(); ++it) 424 for (TreeScope* treeScope : m_activeTreeScopes)
488 (*it)->clearScopedStyleResolver(); 425 treeScope->clearScopedStyleResolver();
489 426
490 m_resolver.clear(); 427 m_resolver.clear();
491 } 428 }
492 429
493 void StyleEngine::clearMasterResolver() 430 void StyleEngine::clearMasterResolver()
494 { 431 {
495 if (Document* master = this->master()) 432 if (Document* master = this->master())
496 master->styleEngine().clearResolver(); 433 master->styleEngine().clearResolver();
497 } 434 }
498 435
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 579
643 m_textToSheetCache.remove(it->value); 580 m_textToSheetCache.remove(it->value);
644 m_sheetToTextCache.remove(contents); 581 m_sheetToTextCache.remove(contents);
645 } 582 }
646 583
647 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const 584 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
648 { 585 {
649 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; 586 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents;
650 if (document().scopedStyleResolver()) 587 if (document().scopedStyleResolver())
651 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents); 588 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents);
652 for (unsigned i = 0; i < m_activeTreeScopes.size(); ++i) { 589 for (TreeScope* treeScope : m_activeTreeScopes) {
653 TreeScope* treeScope = const_cast<TreeScope*>(m_activeTreeScopes[i]);
654 // When creating StyleResolver, dirty treescopes might not be processed. 590 // When creating StyleResolver, dirty treescopes might not be processed.
655 // So some active treescopes might not have a scoped style resolver. 591 // So some active treescopes might not have a scoped style resolver.
656 // In this case, we should skip collectFeatures for the treescopes witho ut 592 // In this case, we should skip collectFeatures for the treescopes witho ut
657 // scoped style resolvers. When invoking updateActiveStyleSheets, 593 // scoped style resolvers. When invoking updateActiveStyleSheets,
658 // the treescope's features will be processed. 594 // the treescope's features will be processed.
659 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) 595 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver())
660 resolver->collectFeaturesTo(features, visitedSharedStyleSheetContent s); 596 resolver->collectFeaturesTo(features, visitedSharedStyleSheetContent s);
661 } 597 }
662 } 598 }
663 599
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 visitor->trace(m_dirtyTreeScopes); 717 visitor->trace(m_dirtyTreeScopes);
782 visitor->trace(m_activeTreeScopes); 718 visitor->trace(m_activeTreeScopes);
783 visitor->trace(m_fontSelector); 719 visitor->trace(m_fontSelector);
784 visitor->trace(m_textToSheetCache); 720 visitor->trace(m_textToSheetCache);
785 visitor->trace(m_sheetToTextCache); 721 visitor->trace(m_sheetToTextCache);
786 #endif 722 #endif
787 CSSFontSelectorClient::trace(visitor); 723 CSSFontSelectorClient::trace(visitor);
788 } 724 }
789 725
790 } 726 }
OLDNEW
« no previous file with comments | « Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698