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

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

Issue 1854423002: ASSERT -> {DCHECK|DCHECK_XX}, ENABLE(ASSERT) -> DCHECK_IS_ON() in dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark svg/as-image/svg-nested.html crash on win Created 4 years, 8 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
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 156
157 void StyleEngine::addPendingSheet() 157 void StyleEngine::addPendingSheet()
158 { 158 {
159 m_pendingStylesheets++; 159 m_pendingStylesheets++;
160 } 160 }
161 161
162 // This method is called whenever a top-level stylesheet has finished loading. 162 // This method is called whenever a top-level stylesheet has finished loading.
163 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode) 163 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode)
164 { 164 {
165 ASSERT(styleSheetCandidateNode); 165 DCHECK(styleSheetCandidateNode);
166 TreeScope* treeScope = isStyleElement(*styleSheetCandidateNode) ? &styleShee tCandidateNode->treeScope() : m_document.get(); 166 TreeScope* treeScope = isStyleElement(*styleSheetCandidateNode) ? &styleShee tCandidateNode->treeScope() : m_document.get();
167 if (styleSheetCandidateNode->inShadowIncludingDocument()) 167 if (styleSheetCandidateNode->inShadowIncludingDocument())
168 markTreeScopeDirty(*treeScope); 168 markTreeScopeDirty(*treeScope);
169 169
170 // Make sure we knew this sheet was pending, and that our count isn't out of sync. 170 // Make sure we knew this sheet was pending, and that our count isn't out of sync.
171 ASSERT(m_pendingStylesheets > 0); 171 DCHECK_GT(m_pendingStylesheets, 0);
172 172
173 m_pendingStylesheets--; 173 m_pendingStylesheets--;
174 if (m_pendingStylesheets) 174 if (m_pendingStylesheets)
175 return; 175 return;
176 176
177 document().didRemoveAllPendingStylesheet(); 177 document().didRemoveAllPendingStylesheet();
178 } 178 }
179 179
180 void StyleEngine::setNeedsActiveStyleUpdate(StyleSheet* sheet, StyleResolverUpda teMode updateMode) 180 void StyleEngine::setNeedsActiveStyleUpdate(StyleSheet* sheet, StyleResolverUpda teMode updateMode)
181 { 181 {
182 // resolverChanged() is called for inactive non-master documents because 182 // resolverChanged() is called for inactive non-master documents because
183 // import documents are inactive documents. resolverChanged() for imports 183 // import documents are inactive documents. resolverChanged() for imports
184 // will call resolverChanged() for the master document and update the active 184 // will call resolverChanged() for the master document and update the active
185 // stylesheets including the ones from the import. 185 // stylesheets including the ones from the import.
186 if (!document().isActive() && isMaster()) 186 if (!document().isActive() && isMaster())
187 return; 187 return;
188 188
189 if (sheet && document().isActive()) { 189 if (sheet && document().isActive()) {
190 Node* node = sheet->ownerNode(); 190 Node* node = sheet->ownerNode();
191 if (node && node->inShadowIncludingDocument()) { 191 if (node && node->inShadowIncludingDocument()) {
192 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : * m_document; 192 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : * m_document;
193 ASSERT(isStyleElement(*node) || node->treeScope() == m_document); 193 DCHECK(isStyleElement(*node) || node->treeScope() == m_document);
194 markTreeScopeDirty(treeScope); 194 markTreeScopeDirty(treeScope);
195 } 195 }
196 } 196 }
197 197
198 resolverChanged(updateMode); 198 resolverChanged(updateMode);
199 } 199 }
200 200
201 void StyleEngine::addStyleSheetCandidateNode(Node* node) 201 void StyleEngine::addStyleSheetCandidateNode(Node* node)
202 { 202 {
203 if (!node->inShadowIncludingDocument() || document().isDetached()) 203 if (!node->inShadowIncludingDocument() || document().isDetached())
204 return; 204 return;
205 205
206 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt; 206 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt;
207 ASSERT(isStyleElement(*node) || treeScope == m_document); 207 DCHECK(isStyleElement(*node) || treeScope == m_document);
208 ASSERT(!isXSLStyleSheet(*node)); 208 DCHECK(!isXSLStyleSheet(*node));
209 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope); 209 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope);
210 ASSERT(collection); 210 DCHECK(collection);
211 collection->addStyleSheetCandidateNode(node); 211 collection->addStyleSheetCandidateNode(node);
212 212
213 markTreeScopeDirty(treeScope); 213 markTreeScopeDirty(treeScope);
214 if (treeScope != m_document) 214 if (treeScope != m_document)
215 m_activeTreeScopes.add(&treeScope); 215 m_activeTreeScopes.add(&treeScope);
216 } 216 }
217 217
218 void StyleEngine::removeStyleSheetCandidateNode(Node* node) 218 void StyleEngine::removeStyleSheetCandidateNode(Node* node)
219 { 219 {
220 removeStyleSheetCandidateNode(node, *m_document); 220 removeStyleSheetCandidateNode(node, *m_document);
221 } 221 }
222 222
223 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope ) 223 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope )
224 { 224 {
225 ASSERT(isStyleElement(*node) || treeScope == m_document); 225 DCHECK(isStyleElement(*node) || treeScope == m_document);
226 ASSERT(!isXSLStyleSheet(*node)); 226 DCHECK(!isXSLStyleSheet(*node));
227 227
228 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e); 228 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e);
229 // After detaching document, collection could be null. In the case, 229 // After detaching document, collection could be null. In the case,
230 // we should not update anything. Instead, just return. 230 // we should not update anything. Instead, just return.
231 if (!collection) 231 if (!collection)
232 return; 232 return;
233 collection->removeStyleSheetCandidateNode(node); 233 collection->removeStyleSheetCandidateNode(node);
234 234
235 markTreeScopeDirty(treeScope); 235 markTreeScopeDirty(treeScope);
236 } 236 }
237 237
238 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node) 238 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node)
239 { 239 {
240 if (!node->inShadowIncludingDocument()) 240 if (!node->inShadowIncludingDocument())
241 return; 241 return;
242 242
243 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt; 243 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt;
244 ASSERT(isStyleElement(*node) || treeScope == m_document); 244 DCHECK(isStyleElement(*node) || treeScope == m_document);
245 markTreeScopeDirty(treeScope); 245 markTreeScopeDirty(treeScope);
246 resolverChanged(FullStyleUpdate); 246 resolverChanged(FullStyleUpdate);
247 } 247 }
248 248
249 void StyleEngine::watchedSelectorsChanged() 249 void StyleEngine::watchedSelectorsChanged()
250 { 250 {
251 if (m_resolver) { 251 if (m_resolver) {
252 m_resolver->initWatchedSelectorRules(); 252 m_resolver->initWatchedSelectorRules();
253 m_resolver->resetRuleFeatures(); 253 m_resolver->resetRuleFeatures();
254 } 254 }
255 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci ng::create(StyleChangeReason::DeclarativeContent)); 255 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci ng::create(StyleChangeReason::DeclarativeContent));
256 } 256 }
257 257
258 bool StyleEngine::shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMo de updateMode) const 258 bool StyleEngine::shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMo de updateMode) const
259 { 259 {
260 return m_documentScopeDirty || updateMode == FullStyleUpdate; 260 return m_documentScopeDirty || updateMode == FullStyleUpdate;
261 } 261 }
262 262
263 bool StyleEngine::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdate Mode updateMode) const 263 bool StyleEngine::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdate Mode updateMode) const
264 { 264 {
265 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; 265 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate;
266 } 266 }
267 267
268 void StyleEngine::clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScop eSet& treeScopes) 268 void StyleEngine::clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScop eSet& treeScopes)
269 { 269 {
270 for (TreeScope* treeScope : treeScopes) { 270 for (TreeScope* treeScope : treeScopes) {
271 ASSERT(treeScope != m_document); 271 DCHECK(treeScope != m_document);
272 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyle SheetCollection*>(styleSheetCollectionFor(*treeScope)); 272 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyle SheetCollection*>(styleSheetCollectionFor(*treeScope));
273 ASSERT(collection); 273 DCHECK(collection);
274 collection->clearMediaQueryRuleSetStyleSheets(); 274 collection->clearMediaQueryRuleSetStyleSheets();
275 } 275 }
276 } 276 }
277 277
278 void StyleEngine::clearMediaQueryRuleSetStyleSheets() 278 void StyleEngine::clearMediaQueryRuleSetStyleSheets()
279 { 279 {
280 resolverChanged(FullStyleUpdate); 280 resolverChanged(FullStyleUpdate);
281 documentStyleSheetCollection()->clearMediaQueryRuleSetStyleSheets(); 281 documentStyleSheetCollection()->clearMediaQueryRuleSetStyleSheets();
282 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes); 282 clearMediaQueryRuleSetOnTreeScopeStyleSheets(m_activeTreeScopes);
283 } 283 }
284 284
285 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector) 285 void StyleEngine::updateStyleSheetsInImport(DocumentStyleSheetCollector& parentC ollector)
286 { 286 {
287 ASSERT(!isMaster()); 287 DCHECK(!isMaster());
288 HeapVector<Member<StyleSheet>> sheetsForList; 288 HeapVector<Member<StyleSheet>> sheetsForList;
289 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist); 289 ImportedDocumentStyleSheetCollector subcollector(parentCollector, sheetsForL ist);
290 documentStyleSheetCollection()->collectStyleSheets(*this, subcollector); 290 documentStyleSheetCollection()->collectStyleSheets(*this, subcollector);
291 documentStyleSheetCollection()->swapSheetsForSheetList(sheetsForList); 291 documentStyleSheetCollection()->swapSheetsForSheetList(sheetsForList);
292 } 292 }
293 293
294 void StyleEngine::updateActiveStyleSheetsInShadow(StyleResolverUpdateMode update Mode, TreeScope* treeScope, UnorderedTreeScopeSet& treeScopesRemoved) 294 void StyleEngine::updateActiveStyleSheetsInShadow(StyleResolverUpdateMode update Mode, TreeScope* treeScope, UnorderedTreeScopeSet& treeScopesRemoved)
295 { 295 {
296 ASSERT(treeScope != m_document); 296 DCHECK_NE(treeScope, m_document);
297 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyleShee tCollection*>(styleSheetCollectionFor(*treeScope)); 297 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyleShee tCollection*>(styleSheetCollectionFor(*treeScope));
298 ASSERT(collection); 298 DCHECK(collection);
299 collection->updateActiveStyleSheets(*this, updateMode); 299 collection->updateActiveStyleSheets(*this, updateMode);
300 if (!collection->hasStyleSheetCandidateNodes()) { 300 if (!collection->hasStyleSheetCandidateNodes()) {
301 treeScopesRemoved.add(treeScope); 301 treeScopesRemoved.add(treeScope);
302 // When removing TreeScope from ActiveTreeScopes, 302 // When removing TreeScope from ActiveTreeScopes,
303 // its resolver should be destroyed by invoking resetAuthorStyle. 303 // its resolver should be destroyed by invoking resetAuthorStyle.
304 ASSERT(!treeScope->scopedStyleResolver()); 304 DCHECK(!treeScope->scopedStyleResolver());
305 } 305 }
306 } 306 }
307 307
308 void StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) 308 void StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode)
309 { 309 {
310 ASSERT(isMaster()); 310 DCHECK(isMaster());
311 ASSERT(!document().inStyleRecalc()); 311 DCHECK(!document().inStyleRecalc());
312 312
313 if (!document().isActive()) 313 if (!document().isActive())
314 return; 314 return;
315 315
316 TRACE_EVENT0("blink,blink_style", "StyleEngine::updateActiveStyleSheets"); 316 TRACE_EVENT0("blink,blink_style", "StyleEngine::updateActiveStyleSheets");
317 317
318 if (shouldUpdateDocumentStyleSheetCollection(updateMode)) 318 if (shouldUpdateDocumentStyleSheetCollection(updateMode))
319 documentStyleSheetCollection()->updateActiveStyleSheets(*this, updateMod e); 319 documentStyleSheetCollection()->updateActiveStyleSheets(*this, updateMod e);
320 320
321 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { 321 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 if (TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor( *shadowRoot)) 372 if (TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor( *shadowRoot))
373 styleResolver->removePendingAuthorStyleSheets(collection->activeAuth orStyleSheets()); 373 styleResolver->removePendingAuthorStyleSheets(collection->activeAuth orStyleSheets());
374 } 374 }
375 m_styleSheetCollectionMap.remove(shadowRoot); 375 m_styleSheetCollectionMap.remove(shadowRoot);
376 m_activeTreeScopes.remove(shadowRoot); 376 m_activeTreeScopes.remove(shadowRoot);
377 m_dirtyTreeScopes.remove(shadowRoot); 377 m_dirtyTreeScopes.remove(shadowRoot);
378 } 378 }
379 379
380 void StyleEngine::appendActiveAuthorStyleSheets() 380 void StyleEngine::appendActiveAuthorStyleSheets()
381 { 381 {
382 ASSERT(isMaster()); 382 DCHECK(isMaster());
383 383
384 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets()); 384 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu thorStyleSheets());
385 for (TreeScope* treeScope : m_activeTreeScopes) { 385 for (TreeScope* treeScope : m_activeTreeScopes) {
386 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(treeScope)) 386 if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMa p.get(treeScope))
387 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets()); 387 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe ets());
388 } 388 }
389 m_resolver->finishAppendAuthorStyleSheets(); 389 m_resolver->finishAppendAuthorStyleSheets();
390 } 390 }
391 391
392 void StyleEngine::createResolver() 392 void StyleEngine::createResolver()
393 { 393 {
394 TRACE_EVENT1("blink", "StyleEngine::createResolver", "frame", document().fra me()); 394 TRACE_EVENT1("blink", "StyleEngine::createResolver", "frame", document().fra me());
395 // It is a programming error to attempt to resolve style on a Document 395 // It is a programming error to attempt to resolve style on a Document
396 // which is not in a frame. Code which hits this should have checked 396 // which is not in a frame. Code which hits this should have checked
397 // Document::isActive() before calling into code which could get here. 397 // Document::isActive() before calling into code which could get here.
398 398
399 ASSERT(document().frame()); 399 DCHECK(document().frame());
400 400
401 m_resolver = StyleResolver::create(*m_document); 401 m_resolver = StyleResolver::create(*m_document);
402 402
403 // A scoped style resolver for document will be created during 403 // A scoped style resolver for document will be created during
404 // appendActiveAuthorStyleSheets if needed. 404 // appendActiveAuthorStyleSheets if needed.
405 appendActiveAuthorStyleSheets(); 405 appendActiveAuthorStyleSheets();
406 } 406 }
407 407
408 void StyleEngine::clearResolver() 408 void StyleEngine::clearResolver()
409 { 409 {
410 ASSERT(!document().inStyleRecalc()); 410 DCHECK(!document().inStyleRecalc());
411 ASSERT(isMaster() || !m_resolver); 411 DCHECK(isMaster() || !m_resolver);
412 412
413 document().clearScopedStyleResolver(); 413 document().clearScopedStyleResolver();
414 // StyleEngine::shadowRootRemovedFromDocument removes not-in-document 414 // StyleEngine::shadowRootRemovedFromDocument removes not-in-document
415 // treescopes from activeTreeScopes. StyleEngine::didRemoveShadowRoot 415 // treescopes from activeTreeScopes. StyleEngine::didRemoveShadowRoot
416 // removes treescopes which are being destroyed from activeTreeScopes. 416 // removes treescopes which are being destroyed from activeTreeScopes.
417 // So we need to clearScopedStyleResolver for treescopes which have been 417 // So we need to clearScopedStyleResolver for treescopes which have been
418 // just removed from document. If document is destroyed before invoking 418 // just removed from document. If document is destroyed before invoking
419 // updateActiveStyleSheets, the treescope has a scopedStyleResolver which 419 // updateActiveStyleSheets, the treescope has a scopedStyleResolver which
420 // has destroyed StyleSheetContents. 420 // has destroyed StyleSheetContents.
421 for (TreeScope* treeScope : m_activeTreeScopes) 421 for (TreeScope* treeScope : m_activeTreeScopes)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (m_fontSelector) 468 if (m_fontSelector)
469 m_fontSelector->fontFaceCache()->clearCSSConnected(); 469 m_fontSelector->fontFaceCache()->clearCSSConnected();
470 if (m_resolver) 470 if (m_resolver)
471 m_resolver->invalidateMatchedPropertiesCache(); 471 m_resolver->invalidateMatchedPropertiesCache();
472 } 472 }
473 473
474 void StyleEngine::updateGenericFontFamilySettings() 474 void StyleEngine::updateGenericFontFamilySettings()
475 { 475 {
476 // FIXME: we should not update generic font family settings when 476 // FIXME: we should not update generic font family settings when
477 // document is inactive. 477 // document is inactive.
478 ASSERT(document().isActive()); 478 DCHECK(document().isActive());
479 479
480 if (!m_fontSelector) 480 if (!m_fontSelector)
481 return; 481 return;
482 482
483 m_fontSelector->updateGenericFontFamilySettings(*m_document); 483 m_fontSelector->updateGenericFontFamilySettings(*m_document);
484 if (m_resolver) 484 if (m_resolver)
485 m_resolver->invalidateMatchedPropertiesCache(); 485 m_resolver->invalidateMatchedPropertiesCache();
486 FontCache::fontCache()->invalidateShapeCache(); 486 FontCache::fontCache()->invalidateShapeCache();
487 } 487 }
488 488
489 void StyleEngine::removeFontFaceRules(const HeapVector<Member<const StyleRuleFon tFace>>& fontFaceRules) 489 void StyleEngine::removeFontFaceRules(const HeapVector<Member<const StyleRuleFon tFace>>& fontFaceRules)
490 { 490 {
491 if (!m_fontSelector) 491 if (!m_fontSelector)
492 return; 492 return;
493 493
494 FontFaceCache* cache = m_fontSelector->fontFaceCache(); 494 FontFaceCache* cache = m_fontSelector->fontFaceCache();
495 for (unsigned i = 0; i < fontFaceRules.size(); ++i) 495 for (unsigned i = 0; i < fontFaceRules.size(); ++i)
496 cache->remove(fontFaceRules[i]); 496 cache->remove(fontFaceRules[i]);
497 if (m_resolver) 497 if (m_resolver)
498 m_resolver->invalidateMatchedPropertiesCache(); 498 m_resolver->invalidateMatchedPropertiesCache();
499 } 499 }
500 500
501 void StyleEngine::markTreeScopeDirty(TreeScope& scope) 501 void StyleEngine::markTreeScopeDirty(TreeScope& scope)
502 { 502 {
503 if (scope == m_document) { 503 if (scope == m_document) {
504 markDocumentDirty(); 504 markDocumentDirty();
505 return; 505 return;
506 } 506 }
507 507
508 ASSERT(m_styleSheetCollectionMap.contains(&scope)); 508 DCHECK(m_styleSheetCollectionMap.contains(&scope));
509 m_dirtyTreeScopes.add(&scope); 509 m_dirtyTreeScopes.add(&scope);
510 } 510 }
511 511
512 void StyleEngine::markDocumentDirty() 512 void StyleEngine::markDocumentDirty()
513 { 513 {
514 m_documentScopeDirty = true; 514 m_documentScopeDirty = true;
515 if (document().importLoader()) 515 if (document().importLoader())
516 document().importsController()->master()->styleEngine().markDocumentDirt y(); 516 document().importsController()->master()->styleEngine().markDocumentDirt y();
517 } 517 }
518 518
519 static bool isCacheableForStyleElement(const StyleSheetContents& contents) 519 static bool isCacheableForStyleElement(const StyleSheetContents& contents)
520 { 520 {
521 // FIXME: Support copying import rules. 521 // FIXME: Support copying import rules.
522 if (!contents.importRules().isEmpty()) 522 if (!contents.importRules().isEmpty())
523 return false; 523 return false;
524 // Until import rules are supported in cached sheets it's not possible for l oading to fail. 524 // Until import rules are supported in cached sheets it's not possible for l oading to fail.
525 ASSERT(!contents.didLoadErrorOccur()); 525 DCHECK(!contents.didLoadErrorOccur());
526 // It is not the original sheet anymore. 526 // It is not the original sheet anymore.
527 if (contents.isMutable()) 527 if (contents.isMutable())
528 return false; 528 return false;
529 if (!contents.hasSyntacticallyValidCSSHeader()) 529 if (!contents.hasSyntacticallyValidCSSHeader())
530 return false; 530 return false;
531 return true; 531 return true;
532 } 532 }
533 533
534 RawPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, T extPosition startPosition) 534 RawPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, T extPosition startPosition)
535 { 535 {
536 RawPtr<CSSStyleSheet> styleSheet = nullptr; 536 RawPtr<CSSStyleSheet> styleSheet = nullptr;
537 537
538 e->document().styleEngine().addPendingSheet(); 538 e->document().styleEngine().addPendingSheet();
539 539
540 AtomicString textContent(text); 540 AtomicString textContent(text);
541 541
542 HeapHashMap<AtomicString, Member<StyleSheetContents>>::AddResult result = m_ textToSheetCache.add(textContent, nullptr); 542 HeapHashMap<AtomicString, Member<StyleSheetContents>>::AddResult result = m_ textToSheetCache.add(textContent, nullptr);
543 if (result.isNewEntry || !result.storedValue->value) { 543 if (result.isNewEntry || !result.storedValue->value) {
544 styleSheet = StyleEngine::parseSheet(e, text, startPosition); 544 styleSheet = StyleEngine::parseSheet(e, text, startPosition);
545 if (result.isNewEntry && isCacheableForStyleElement(*styleSheet->content s())) { 545 if (result.isNewEntry && isCacheableForStyleElement(*styleSheet->content s())) {
546 result.storedValue->value = styleSheet->contents(); 546 result.storedValue->value = styleSheet->contents();
547 m_sheetToTextCache.add(styleSheet->contents(), textContent); 547 m_sheetToTextCache.add(styleSheet->contents(), textContent);
548 } 548 }
549 } else { 549 } else {
550 StyleSheetContents* contents = result.storedValue->value; 550 StyleSheetContents* contents = result.storedValue->value;
551 ASSERT(contents); 551 DCHECK(contents);
552 ASSERT(isCacheableForStyleElement(*contents)); 552 DCHECK(isCacheableForStyleElement(*contents));
553 ASSERT(contents->singleOwnerDocument() == e->document()); 553 DCHECK_EQ(contents->singleOwnerDocument(), e->document());
554 styleSheet = CSSStyleSheet::createInline(contents, e, startPosition); 554 styleSheet = CSSStyleSheet::createInline(contents, e, startPosition);
555 } 555 }
556 556
557 ASSERT(styleSheet); 557 DCHECK(styleSheet);
558 styleSheet->setTitle(e->title()); 558 styleSheet->setTitle(e->title());
559 return styleSheet; 559 return styleSheet;
560 } 560 }
561 561
562 RawPtr<CSSStyleSheet> StyleEngine::parseSheet(Element* e, const String& text, Te xtPosition startPosition) 562 RawPtr<CSSStyleSheet> StyleEngine::parseSheet(Element* e, const String& text, Te xtPosition startPosition)
563 { 563 {
564 RawPtr<CSSStyleSheet> styleSheet = nullptr; 564 RawPtr<CSSStyleSheet> styleSheet = nullptr;
565 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().characterSet()); 565 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().characterSet());
566 styleSheet->contents()->parseStringAtPosition(text, startPosition); 566 styleSheet->contents()->parseStringAtPosition(text, startPosition);
567 return styleSheet; 567 return styleSheet;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 return; 728 return;
729 } 729 }
730 if (!m_styleResolverStats) 730 if (!m_styleResolverStats)
731 m_styleResolverStats = StyleResolverStats::create(); 731 m_styleResolverStats = StyleResolverStats::create();
732 else 732 else
733 m_styleResolverStats->reset(); 733 m_styleResolverStats->reset();
734 } 734 }
735 735
736 void StyleEngine::setShadowCascadeOrder(ShadowCascadeOrder order) 736 void StyleEngine::setShadowCascadeOrder(ShadowCascadeOrder order)
737 { 737 {
738 ASSERT(order != ShadowCascadeOrder::ShadowCascadeNone); 738 DCHECK_NE(order, ShadowCascadeOrder::ShadowCascadeNone);
739 739
740 if (order == m_shadowCascadeOrder) 740 if (order == m_shadowCascadeOrder)
741 return; 741 return;
742 742
743 if (order == ShadowCascadeOrder::ShadowCascadeV0) 743 if (order == ShadowCascadeOrder::ShadowCascadeV0)
744 m_mayContainV0Shadow = true; 744 m_mayContainV0Shadow = true;
745 745
746 // For V0 -> V1 upgrade, we need style recalculation for the whole document. 746 // For V0 -> V1 upgrade, we need style recalculation for the whole document.
747 if (m_shadowCascadeOrder == ShadowCascadeOrder::ShadowCascadeV0 && order == ShadowCascadeOrder::ShadowCascadeV1) 747 if (m_shadowCascadeOrder == ShadowCascadeOrder::ShadowCascadeV0 && order == ShadowCascadeOrder::ShadowCascadeV1)
748 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::Shadow)); 748 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::Shadow));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 visitor->trace(m_styleInvalidator); 802 visitor->trace(m_styleInvalidator);
803 visitor->trace(m_dirtyTreeScopes); 803 visitor->trace(m_dirtyTreeScopes);
804 visitor->trace(m_activeTreeScopes); 804 visitor->trace(m_activeTreeScopes);
805 visitor->trace(m_fontSelector); 805 visitor->trace(m_fontSelector);
806 visitor->trace(m_textToSheetCache); 806 visitor->trace(m_textToSheetCache);
807 visitor->trace(m_sheetToTextCache); 807 visitor->trace(m_sheetToTextCache);
808 CSSFontSelectorClient::trace(visitor); 808 CSSFontSelectorClient::trace(visitor);
809 } 809 }
810 810
811 } // namespace blink 811 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleElement.cpp ('k') | third_party/WebKit/Source/core/dom/StyleSheetCandidate.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698