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

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

Issue 14604003: When there are no more stylesheets schedule the recalc async (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Refactor based on review Created 7 years, 7 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 | Annotate | Revision Log
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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 344 }
345 345
346 if (rel.contains("alternate") && title.isEmpty()) 346 if (rel.contains("alternate") && title.isEmpty())
347 sheet = 0; 347 sheet = 0;
348 } 348 }
349 if (sheet) 349 if (sheet)
350 sheets.append(sheet); 350 sheets.append(sheet);
351 } 351 }
352 } 352 }
353 353
354 void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag , const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolverUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc) 354 DocumentStyleSheetCollection::UpdateAction DocumentStyleSheetCollection::analyze StyleSheetChange(StyleResolverUpdateMode updateMode, const Vector<RefPtr<CSSStyl eSheet> >& newStylesheets, bool& requiresFullStyleRecalc)
355 { 355 {
356 styleResolverUpdateType = Reconstruct; 356 // FIXME: Updating the active loading sheet state shouldn't be in this metho d.
357 requiresFullStyleRecalc = true; 357
358
359 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done. 358 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done.
360 bool hasActiveLoadingStylesheet = false; 359 bool hasActiveLoadingStylesheet = false;
361 unsigned newStylesheetCount = newStylesheets.size(); 360 unsigned newStylesheetCount = newStylesheets.size();
362 for (unsigned i = 0; i < newStylesheetCount; ++i) { 361 for (unsigned i = 0; i < newStylesheetCount; ++i) {
363 if (newStylesheets[i]->isLoading()) 362 if (newStylesheets[i]->isLoading())
364 hasActiveLoadingStylesheet = true; 363 hasActiveLoadingStylesheet = true;
365 } 364 }
366 if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) { 365 if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) {
367 m_hadActiveLoadingStylesheet = false; 366 m_hadActiveLoadingStylesheet = false;
368 return; 367 return Reconstruct;
369 } 368 }
370 m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet; 369 m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet;
371 370
372 if (updateFlag != OptimizedUpdate) 371 if (updateMode != OptimizedStyleUpdate)
373 return; 372 return Reconstruct;
374 if (!m_document->styleResolverIfExists()) 373 if (!m_document->styleResolverIfExists())
375 return; 374 return Reconstruct;
376 375
377 // Find out which stylesheets are new. 376 // Find out which stylesheets are new.
378 unsigned oldStylesheetCount = m_activeAuthorStyleSheets.size(); 377 unsigned oldStylesheetCount = m_activeAuthorStyleSheets.size();
379 if (newStylesheetCount < oldStylesheetCount) 378 if (newStylesheetCount < oldStylesheetCount)
380 return; 379 return Reconstruct;
381 Vector<StyleSheetContents*> addedSheets; 380 Vector<StyleSheetContents*> addedSheets;
382 unsigned newIndex = 0; 381 unsigned newIndex = 0;
383 for (unsigned oldIndex = 0; oldIndex < oldStylesheetCount; ++oldIndex) { 382 for (unsigned oldIndex = 0; oldIndex < oldStylesheetCount; ++oldIndex) {
384 if (newIndex >= newStylesheetCount) 383 if (newIndex >= newStylesheetCount)
385 return; 384 return Reconstruct;
386 while (m_activeAuthorStyleSheets[oldIndex] != newStylesheets[newIndex]) { 385 while (m_activeAuthorStyleSheets[oldIndex] != newStylesheets[newIndex]) {
387 addedSheets.append(newStylesheets[newIndex]->contents()); 386 addedSheets.append(newStylesheets[newIndex]->contents());
388 ++newIndex; 387 ++newIndex;
389 if (newIndex == newStylesheetCount) 388 if (newIndex == newStylesheetCount)
390 return; 389 return Reconstruct;
391 } 390 }
392 ++newIndex; 391 ++newIndex;
393 } 392 }
394 bool hasInsertions = !addedSheets.isEmpty(); 393 bool hasInsertions = !addedSheets.isEmpty();
395 while (newIndex < newStylesheetCount) { 394 while (newIndex < newStylesheetCount) {
396 addedSheets.append(newStylesheets[newIndex]->contents()); 395 addedSheets.append(newStylesheets[newIndex]->contents());
397 ++newIndex; 396 ++newIndex;
398 } 397 }
398
399 // If we don't have a body yet it's unlikely there's enough nodes to warrant
400 // doing analysis. If there's place holder styles we do a full recalc to tur n
401 // them into real styles.
402 //
403 // FIXME: It's not clear why analysis isn't safe for placeholder styles.
404 if (m_document->body() && !m_document->hasNodesWithPlaceholderStyle()) {
405 StyleInvalidationAnalysis invalidationAnalysis(addedSheets);
406 if (!invalidationAnalysis.dirtiesAllStyle()) {
407 invalidationAnalysis.invalidateStyle(m_document);
408 requiresFullStyleRecalc = false;
409 }
410 }
411
399 // If all new sheets were added at the end of the list we can just add them to existing StyleResolver. 412 // If all new sheets were added at the end of the list we can just add them to existing StyleResolver.
400 // If there were insertions we need to re-add all the stylesheets so rules a re ordered correctly. 413 // If there were insertions we need to re-add all the stylesheets so rules a re ordered correctly.
401 styleResolverUpdateType = hasInsertions ? Reset : Additive; 414 return hasInsertions ? Reset : Append;
402
403 // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs.
404 if (!m_document->body() || m_document->hasNodesWithPlaceholderStyle())
405 return;
406 StyleInvalidationAnalysis invalidationAnalysis(addedSheets);
407 if (invalidationAnalysis.dirtiesAllStyle())
408 return;
409 invalidationAnalysis.invalidateStyle(m_document);
410 requiresFullStyleRecalc = false;
411 } 415 }
412 416
413 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) 417 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
414 { 418 {
415 for (unsigned i = 0; i < sheets.size(); ++i) { 419 for (unsigned i = 0; i < sheets.size(); ++i) {
416 if (sheets[i]->contents()->usesRemUnits()) 420 if (sheets[i]->contents()->usesRemUnits())
417 return true; 421 return true;
418 } 422 }
419 return false; 423 return false;
420 } 424 }
(...skipping 10 matching lines...) Expand all
431 } 435 }
432 436
433 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document) 437 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document)
434 { 438 {
435 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame(); 439 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame();
436 if (!seamlessParentIFrame) 440 if (!seamlessParentIFrame)
437 return; 441 return;
438 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets()); 442 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets());
439 } 443 }
440 444
441 bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag ) 445 bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo de updateMode)
442 { 446 {
443 if (m_document->inStyleRecalc()) { 447 if (m_document->inStyleRecalc()) {
444 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc. 448 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc.
445 // https://bugs.webkit.org/show_bug.cgi?id=54344 449 // https://bugs.webkit.org/show_bug.cgi?id=54344
446 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc). 450 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc).
447 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; 451 m_needsUpdateActiveStylesheetsOnStyleRecalc = true;
448 m_document->scheduleForcedStyleRecalc(); 452 m_document->scheduleForcedStyleRecalc();
449 return false; 453 return false;
454 }
450 455
451 }
452 if (!m_document->renderer() || !m_document->attached()) 456 if (!m_document->renderer() || !m_document->attached())
453 return false; 457 return false;
454 458
455 Vector<RefPtr<StyleSheet> > activeStyleSheets; 459 Vector<RefPtr<StyleSheet> > activeStyleSheets;
456 collectActiveStyleSheets(activeStyleSheets); 460 collectActiveStyleSheets(activeStyleSheets);
457 461
458 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets; 462 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
459 activeCSSStyleSheets.append(injectedAuthorStyleSheets()); 463 activeCSSStyleSheets.append(injectedAuthorStyleSheets());
460 activeCSSStyleSheets.append(documentAuthorStyleSheets()); 464 activeCSSStyleSheets.append(documentAuthorStyleSheets());
461 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent); 465 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent);
462 filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets); 466 filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
463 467
464 StyleResolverUpdateType styleResolverUpdateType; 468 bool requiresFullStyleRecalc = true;
465 bool requiresFullStyleRecalc; 469 UpdateAction action = analyzeStyleSheetChange(updateMode, activeCSSStyleShee ts, requiresFullStyleRecalc);
466 analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdat eType, requiresFullStyleRecalc);
467 470
468 if (styleResolverUpdateType == Reconstruct) 471 switch (action) {
472 case Reconstruct:
469 m_document->clearStyleResolver(); 473 m_document->clearStyleResolver();
470 else { 474 break;
471 StyleResolver* styleResolver = m_document->styleResolver(); 475 case Reset:
472 if (styleResolverUpdateType == Reset) { 476 m_document->styleResolver()->ruleSets().resetAuthorStyle();
473 styleResolver->ruleSets().resetAuthorStyle(); 477 m_document->styleResolver()->appendAuthorStyleSheets(0, activeCSSStyleSh eets);
474 styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
475 } else {
476 ASSERT(styleResolverUpdateType == Additive);
477 styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.siz e(), activeCSSStyleSheets);
478 }
479 resetCSSFeatureFlags(); 478 resetCSSFeatureFlags();
479 break;
480 case Append:
481 m_document->styleResolver()->appendAuthorStyleSheets(m_activeAuthorStyle Sheets.size(), activeCSSStyleSheets);
482 resetCSSFeatureFlags();
483 break;
480 } 484 }
485
481 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets); 486 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
482 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSh eets); 487 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSh eets);
483 m_styleSheetsForStyleSheetList.swap(activeStyleSheets); 488 m_styleSheetsForStyleSheetList.swap(activeStyleSheets);
484 489
485 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); 490 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
486 m_needsUpdateActiveStylesheetsOnStyleRecalc = false; 491 m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
487 492
488 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate(); 493 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
489 494
490 return requiresFullStyleRecalc; 495 return requiresFullStyleRecalc;
491 } 496 }
492 497
493 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const 498 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const
494 { 499 {
495 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); 500 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
496 info.addMember(m_pageUserSheet, "pageUserSheet"); 501 info.addMember(m_pageUserSheet, "pageUserSheet");
497 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets"); 502 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets");
498 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets"); 503 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets");
499 info.addMember(m_userStyleSheets, "userStyleSheets"); 504 info.addMember(m_userStyleSheets, "userStyleSheets");
500 info.addMember(m_authorStyleSheets, "authorStyleSheets"); 505 info.addMember(m_authorStyleSheets, "authorStyleSheets");
501 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets"); 506 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets");
502 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList "); 507 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList ");
503 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes"); 508 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes");
504 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName"); 509 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName");
505 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName"); 510 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName");
506 info.addMember(m_document, "document"); 511 info.addMember(m_document, "document");
507 } 512 }
508 513
509 } 514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698