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

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 201363002: DevTools: defer styles delta calculation to until the end of the task. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void InspectorCSSAgent::restore() 428 void InspectorCSSAgent::restore()
429 { 429 {
430 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled)) 430 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled))
431 wasEnabled(nullptr); 431 wasEnabled(nullptr);
432 } 432 }
433 433
434 void InspectorCSSAgent::reset() 434 void InspectorCSSAgent::reset()
435 { 435 {
436 m_idToInspectorStyleSheet.clear(); 436 m_idToInspectorStyleSheet.clear();
437 m_cssStyleSheetToInspectorStyleSheet.clear(); 437 m_cssStyleSheetToInspectorStyleSheet.clear();
438 m_frameToCSSStyleSheets.clear(); 438 m_documentToCSSStyleSheets.clear();
439 m_invalidatedDocuments.clear();
439 m_nodeToInspectorStyleSheet.clear(); 440 m_nodeToInspectorStyleSheet.clear();
440 m_documentToViaInspectorStyleSheet.clear(); 441 m_documentToViaInspectorStyleSheet.clear();
441 resetNonPersistentData(); 442 resetNonPersistentData();
442 } 443 }
443 444
444 void InspectorCSSAgent::resetNonPersistentData() 445 void InspectorCSSAgent::resetNonPersistentData()
445 { 446 {
446 resetPseudoStates(); 447 resetPseudoStates();
447 } 448 }
448 449
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 484
484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) 485 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
485 { 486 {
486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { 487 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) {
487 // We were disabled while fetching resources. 488 // We were disabled while fetching resources.
488 return; 489 return;
489 } 490 }
490 491
491 m_instrumentingAgents->setInspectorCSSAgent(this); 492 m_instrumentingAgents->setInspectorCSSAgent(this);
492 Vector<Document*> documents = m_domAgent->documents(); 493 Vector<Document*> documents = m_domAgent->documents();
493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end (); ++it) { 494 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end (); ++it)
494 Document* document = *it; 495 updateActiveStyleSheets(*it, InitialFrontendLoad);
495 updateActiveStyleSheetsForDocument(document, InitialFrontendLoad);
496 }
497 496
498 if (callback) 497 if (callback)
499 callback->sendSuccess(); 498 callback->sendSuccess();
500 } 499 }
501 500
502 void InspectorCSSAgent::disable(ErrorString*) 501 void InspectorCSSAgent::disable(ErrorString*)
503 { 502 {
504 m_instrumentingAgents->setInspectorCSSAgent(0); 503 m_instrumentingAgents->setInspectorCSSAgent(0);
505 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); 504 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false);
506 } 505 }
507 506
508 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) 507 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader)
509 { 508 {
510 if (loader->frame() == frame->page()->mainFrame()) { 509 if (loader->frame() == frame->page()->mainFrame()) {
511 reset(); 510 reset();
512 return; 511 return;
513 } 512 }
514 513
515 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh); 514 for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin(); it != m_documentToCSSStyleSheets.end(); ++it) {
515 Document* document = it->key;
516 if (!document->frame() || document->frame() == frame)
517 documentDisposed(document);
518 }
516 } 519 }
517 520
518 void InspectorCSSAgent::mediaQueryResultChanged() 521 void InspectorCSSAgent::mediaQueryResultChanged()
519 { 522 {
520 if (m_frontend) 523 validateFrontendStylesheets();
521 m_frontend->mediaQueryResultChanged(); 524 m_frontend->mediaQueryResultChanged();
522 } 525 }
523 526
524 void InspectorCSSAgent::willMutateRules() 527 void InspectorCSSAgent::willMutateRules()
525 { 528 {
526 ++m_styleSheetsPendingMutation; 529 ++m_styleSheetsPendingMutation;
527 } 530 }
528 531
529 void InspectorCSSAgent::didMutateRules(CSSStyleSheet* styleSheet) 532 void InspectorCSSAgent::didMutateRules(CSSStyleSheet* styleSheet)
530 { 533 {
531 --m_styleSheetsPendingMutation; 534 --m_styleSheetsPendingMutation;
(...skipping 16 matching lines...) Expand all
548 ASSERT(m_styleDeclarationPendingMutation); 551 ASSERT(m_styleDeclarationPendingMutation);
549 m_styleDeclarationPendingMutation = false; 552 m_styleDeclarationPendingMutation = false;
550 if (!styleSheetEditInProgress() && !isInlineStyle) { 553 if (!styleSheetEditInProgress() && !isInlineStyle) {
551 CSSStyleSheet* parentSheet = style->parentStyleSheet(); 554 CSSStyleSheet* parentSheet = style->parentStyleSheet();
552 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; 555 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0;
553 if (owner) 556 if (owner)
554 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl eUpdate); 557 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl eUpdate);
555 } 558 }
556 } 559 }
557 560
561 void InspectorCSSAgent::didProcessTask()
562 {
563 validateFrontendStylesheets();
564 }
565
558 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) 566 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
559 { 567 {
560 if (styleSheetEditInProgress()) 568 if (styleSheetEditInProgress())
561 return; 569 return;
562 updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh); 570 m_invalidatedDocuments.add(document);
571 if (m_creatingViaInspectorStyleSheet)
572 validateFrontendStylesheets();
563 } 573 }
564 574
565 void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, S tyleSheetsUpdateType styleSheetsUpdateType) 575 void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsU pdateType styleSheetsUpdateType)
566 { 576 {
567 LocalFrame* frame = document->frame();
568 if (!frame)
569 return;
570 Vector<CSSStyleSheet*> newSheetsVector; 577 Vector<CSSStyleSheet*> newSheetsVector;
571 collectAllDocumentStyleSheets(document, newSheetsVector); 578 collectAllDocumentStyleSheets(document, newSheetsVector);
572 updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType); 579 setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType);
573 } 580 }
574 581
575 void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector< CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) 582 void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CS SStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
576 { 583 {
577 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; 584 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad;
578 585
579 HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(f rame); 586 HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets .get(document);
580 if (!frameCSSStyleSheets) { 587 if (!documentCSSStyleSheets) {
581 frameCSSStyleSheets = new HashSet<CSSStyleSheet*>(); 588 documentCSSStyleSheets = new HashSet<CSSStyleSheet*>();
582 OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frame CSSStyleSheets); 589 OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(do cumentCSSStyleSheets);
583 m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release()); 590 m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.relea se());
584 } 591 }
585 592
586 HashSet<CSSStyleSheet*> removedSheets; 593 HashSet<CSSStyleSheet*> removedSheets;
587 for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it != frameCSSStyleSheets->end(); ++it) 594 for (HashSet<CSSStyleSheet*>::iterator it = documentCSSStyleSheets->begin(); it != documentCSSStyleSheets->end(); ++it)
588 removedSheets.add(*it); 595 removedSheets.add(*it);
589 596
590 HashSet<CSSStyleSheet*> addedSheets; 597 HashSet<CSSStyleSheet*> addedSheets;
591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) { 598 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) {
592 CSSStyleSheet* cssStyleSheet = *it; 599 CSSStyleSheet* cssStyleSheet = *it;
593 if (removedSheets.contains(cssStyleSheet)) { 600 if (removedSheets.contains(cssStyleSheet)) {
594 removedSheets.remove(cssStyleSheet); 601 removedSheets.remove(cssStyleSheet);
595 if (isInitialFrontendLoad) 602 if (isInitialFrontendLoad)
596 addedSheets.add(cssStyleSheet); 603 addedSheets.add(cssStyleSheet);
597 } else { 604 } else {
598 addedSheets.add(cssStyleSheet); 605 addedSheets.add(cssStyleSheet);
599 } 606 }
600 } 607 }
601 608
602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) { 609 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) {
603 CSSStyleSheet* cssStyleSheet = *it; 610 CSSStyleSheet* cssStyleSheet = *it;
604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet); 611 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet);
605 ASSERT(inspectorStyleSheet); 612 ASSERT(inspectorStyleSheet);
606 613
607 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { 614 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) {
608 String id = unbindStyleSheet(inspectorStyleSheet.get()); 615 String id = unbindStyleSheet(inspectorStyleSheet.get());
609 frameCSSStyleSheets->remove(cssStyleSheet); 616 documentCSSStyleSheets->remove(cssStyleSheet);
610 if (m_frontend && !isInitialFrontendLoad) 617 if (m_frontend && !isInitialFrontendLoad)
611 m_frontend->styleSheetRemoved(id); 618 m_frontend->styleSheetRemoved(id);
612 } 619 }
613 } 620 }
614 621
615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) { 622 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) {
616 CSSStyleSheet* cssStyleSheet = *it; 623 CSSStyleSheet* cssStyleSheet = *it;
617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet); 624 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet);
618 if (isNew) { 625 if (isNew) {
619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); 626 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet);
620 frameCSSStyleSheets->add(cssStyleSheet); 627 documentCSSStyleSheets->add(cssStyleSheet);
621 if (m_frontend) 628 if (m_frontend)
622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo()); 629 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo());
623 } 630 }
624 } 631 }
625 632
626 if (frameCSSStyleSheets->isEmpty()) 633 if (documentCSSStyleSheets->isEmpty())
627 m_frameToCSSStyleSheets.remove(frame); 634 m_documentToCSSStyleSheets.remove(document);
635 }
636
637 void InspectorCSSAgent::validateFrontendStylesheets()
638 {
639 if (!m_invalidatedDocuments.size())
640 return;
641 HashSet<Document*> invalidatedDocuments;
642 m_invalidatedDocuments.swap(&invalidatedDocuments);
643 for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != i nvalidatedDocuments.end(); ++it)
644 updateActiveStyleSheets(*it, ExistingFrontendRefresh);
645 }
646
647 void InspectorCSSAgent::documentDisposed(Document* document)
648 {
649 m_invalidatedDocuments.remove(document);
650 setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh);
628 } 651 }
629 652
630 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) 653 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame)
631 { 654 {
632 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh); 655 documentDisposed(frame->document());
633 } 656 }
634 657
635 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType) 658 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType)
636 { 659 {
637 if (m_nodeIdToForcedPseudoState.isEmpty()) 660 if (m_nodeIdToForcedPseudoState.isEmpty())
638 return false; 661 return false;
639 662
640 int nodeId = m_domAgent->boundNodeId(element); 663 int nodeId = m_domAgent->boundNodeId(element);
641 if (!nodeId) 664 if (!nodeId)
642 return false; 665 return false;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 *errorString = "Frame does not have a document"; 908 *errorString = "Frame does not have a document";
886 return; 909 return;
887 } 910 }
888 911
889 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(document, true); 912 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(document, true);
890 if (!inspectorStyleSheet) { 913 if (!inspectorStyleSheet) {
891 *errorString = "No target stylesheet found"; 914 *errorString = "No target stylesheet found";
892 return; 915 return;
893 } 916 }
894 917
918 updateActiveStyleSheets(document, ExistingFrontendRefresh);
919
895 *outStyleSheetId = inspectorStyleSheet->id(); 920 *outStyleSheetId = inspectorStyleSheet->id();
896 } 921 }
897 922
898 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) 923 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result)
899 { 924 {
900 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 925 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
901 if (!inspectorStyleSheet) 926 if (!inspectorStyleSheet)
902 return; 927 return;
903 928
904 TrackExceptionState exceptionState; 929 TrackExceptionState exceptionState;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 1330
1306 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); 1331 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement);
1307 if (it == m_nodeToInspectorStyleSheet.end()) 1332 if (it == m_nodeToInspectorStyleSheet.end())
1308 return; 1333 return;
1309 1334
1310 it->value->didModifyElementAttribute(); 1335 it->value->didModifyElementAttribute();
1311 } 1336 }
1312 1337
1313 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet) 1338 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet)
1314 { 1339 {
1315 if (m_frontend) 1340 validateFrontendStylesheets();
1316 m_frontend->styleSheetChanged(styleSheet->id()); 1341 m_frontend->styleSheetChanged(styleSheet->id());
1317 } 1342 }
1318 1343
1319 void InspectorCSSAgent::willReparseStyleSheet() 1344 void InspectorCSSAgent::willReparseStyleSheet()
1320 { 1345 {
1321 ASSERT(!m_isSettingStyleSheetText); 1346 ASSERT(!m_isSettingStyleSheetText);
1322 m_isSettingStyleSheetText = true; 1347 m_isSettingStyleSheetText = true;
1323 } 1348 }
1324 1349
1325 void InspectorCSSAgent::didReparseStyleSheet() 1350 void InspectorCSSAgent::didReparseStyleSheet()
1326 { 1351 {
(...skipping 10 matching lines...) Expand all
1337 documentsToChange.add(element->ownerDocument()); 1362 documentsToChange.add(element->ownerDocument());
1338 } 1363 }
1339 1364
1340 m_nodeIdToForcedPseudoState.clear(); 1365 m_nodeIdToForcedPseudoState.clear();
1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1366 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1367 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1343 } 1368 }
1344 1369
1345 } // namespace WebCore 1370 } // namespace WebCore
1346 1371
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698