Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 (HashSet<Document*>::iterator it = m_invalidatedDocuments.begin(); it != m_invalidatedDocuments.end(); ++it) { |
| 515 Document* document = *it; | |
| 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 if (m_frontend) |
| 521 m_frontend->mediaQueryResultChanged(); | 524 m_frontend->mediaQueryResultChanged(); |
| 522 } | 525 } |
| 523 | 526 |
| 524 void InspectorCSSAgent::willMutateRules() | 527 void InspectorCSSAgent::willMutateRules() |
| 525 { | 528 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 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 if (!m_invalidatedDocuments.size()) | |
| 564 return; | |
| 565 HashSet<Document*> invalidatedDocuments; | |
| 566 m_invalidatedDocuments.swap(&invalidatedDocuments); | |
|
lushnikov
2014/03/17 08:46:43
This is nifty; but why not simply clear m_invalida
pfeldman
2014/03/17 12:32:58
For re-entrance.
| |
| 567 for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != i nvalidatedDocuments.end(); ++it) | |
| 568 updateActiveStyleSheets(*it, ExistingFrontendRefresh); | |
| 569 } | |
| 570 | |
| 558 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) | 571 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) |
| 559 { | 572 { |
| 560 if (styleSheetEditInProgress()) | 573 if (styleSheetEditInProgress()) |
| 561 return; | 574 return; |
| 562 updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh); | 575 if (m_creatingViaInspectorStyleSheet) |
|
lushnikov
2014/03/17 08:37:32
I don't see where you set this to true
pfeldman
2014/03/17 12:32:58
It was there.
| |
| 576 updateActiveStyleSheets(document, ExistingFrontendRefresh); | |
| 577 else | |
| 578 m_invalidatedDocuments.add(document); | |
| 563 } | 579 } |
| 564 | 580 |
| 565 void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, S tyleSheetsUpdateType styleSheetsUpdateType) | 581 void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsU pdateType styleSheetsUpdateType) |
| 566 { | 582 { |
| 567 LocalFrame* frame = document->frame(); | |
| 568 if (!frame) | |
| 569 return; | |
| 570 Vector<CSSStyleSheet*> newSheetsVector; | 583 Vector<CSSStyleSheet*> newSheetsVector; |
| 571 collectAllDocumentStyleSheets(document, newSheetsVector); | 584 collectAllDocumentStyleSheets(document, newSheetsVector); |
| 572 updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType); | 585 setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType); |
| 573 } | 586 } |
| 574 | 587 |
| 575 void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector< CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) | 588 void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CS SStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) |
| 576 { | 589 { |
| 590 | |
| 577 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; | 591 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; |
| 578 | 592 |
| 579 HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(f rame); | 593 HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets .get(document); |
| 580 if (!frameCSSStyleSheets) { | 594 if (!documentCSSStyleSheets) { |
| 581 frameCSSStyleSheets = new HashSet<CSSStyleSheet*>(); | 595 documentCSSStyleSheets = new HashSet<CSSStyleSheet*>(); |
| 582 OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frame CSSStyleSheets); | 596 OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(do cumentCSSStyleSheets); |
| 583 m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release()); | 597 m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.relea se()); |
| 584 } | 598 } |
| 585 | 599 |
| 586 HashSet<CSSStyleSheet*> removedSheets; | 600 HashSet<CSSStyleSheet*> removedSheets; |
| 587 for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it != frameCSSStyleSheets->end(); ++it) | 601 for (HashSet<CSSStyleSheet*>::iterator it = documentCSSStyleSheets->begin(); it != documentCSSStyleSheets->end(); ++it) |
| 588 removedSheets.add(*it); | 602 removedSheets.add(*it); |
| 589 | 603 |
| 590 HashSet<CSSStyleSheet*> addedSheets; | 604 HashSet<CSSStyleSheet*> addedSheets; |
| 591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) { | 605 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) { |
| 592 CSSStyleSheet* cssStyleSheet = *it; | 606 CSSStyleSheet* cssStyleSheet = *it; |
| 593 if (removedSheets.contains(cssStyleSheet)) { | 607 if (removedSheets.contains(cssStyleSheet)) { |
| 594 removedSheets.remove(cssStyleSheet); | 608 removedSheets.remove(cssStyleSheet); |
| 595 if (isInitialFrontendLoad) | 609 if (isInitialFrontendLoad) |
| 596 addedSheets.add(cssStyleSheet); | 610 addedSheets.add(cssStyleSheet); |
| 597 } else { | 611 } else { |
| 598 addedSheets.add(cssStyleSheet); | 612 addedSheets.add(cssStyleSheet); |
| 599 } | 613 } |
| 600 } | 614 } |
| 601 | 615 |
| 602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) { | 616 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) { |
| 603 CSSStyleSheet* cssStyleSheet = *it; | 617 CSSStyleSheet* cssStyleSheet = *it; |
| 604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet); | 618 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet); |
| 605 ASSERT(inspectorStyleSheet); | 619 ASSERT(inspectorStyleSheet); |
| 606 | 620 |
| 607 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { | 621 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { |
| 608 String id = unbindStyleSheet(inspectorStyleSheet.get()); | 622 String id = unbindStyleSheet(inspectorStyleSheet.get()); |
| 609 frameCSSStyleSheets->remove(cssStyleSheet); | 623 documentCSSStyleSheets->remove(cssStyleSheet); |
| 610 if (m_frontend && !isInitialFrontendLoad) | 624 if (m_frontend && !isInitialFrontendLoad) |
| 611 m_frontend->styleSheetRemoved(id); | 625 m_frontend->styleSheetRemoved(id); |
| 612 } | 626 } |
| 613 } | 627 } |
| 614 | 628 |
| 615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) { | 629 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) { |
| 616 CSSStyleSheet* cssStyleSheet = *it; | 630 CSSStyleSheet* cssStyleSheet = *it; |
| 617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet); | 631 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet); |
| 618 if (isNew) { | 632 if (isNew) { |
| 619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); | 633 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); |
| 620 frameCSSStyleSheets->add(cssStyleSheet); | 634 documentCSSStyleSheets->add(cssStyleSheet); |
| 621 if (m_frontend) | 635 if (m_frontend) |
| 622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo()); | 636 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo()); |
| 623 } | 637 } |
| 624 } | 638 } |
| 625 | 639 |
| 626 if (frameCSSStyleSheets->isEmpty()) | 640 if (documentCSSStyleSheets->isEmpty()) |
| 627 m_frameToCSSStyleSheets.remove(frame); | 641 m_documentToCSSStyleSheets.remove(document); |
| 642 } | |
| 643 | |
| 644 void InspectorCSSAgent::documentDisposed(Document* document) | |
| 645 { | |
| 646 m_invalidatedDocuments.remove(document); | |
| 647 setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh); | |
| 628 } | 648 } |
| 629 | 649 |
| 630 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) | 650 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) |
| 631 { | 651 { |
| 632 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh); | 652 documentDisposed(frame->document()); |
| 633 } | 653 } |
| 634 | 654 |
| 635 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType) | 655 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType) |
| 636 { | 656 { |
| 637 if (m_nodeIdToForcedPseudoState.isEmpty()) | 657 if (m_nodeIdToForcedPseudoState.isEmpty()) |
| 638 return false; | 658 return false; |
| 639 | 659 |
| 640 int nodeId = m_domAgent->boundNodeId(element); | 660 int nodeId = m_domAgent->boundNodeId(element); |
| 641 if (!nodeId) | 661 if (!nodeId) |
| 642 return false; | 662 return false; |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 documentsToChange.add(element->ownerDocument()); | 1357 documentsToChange.add(element->ownerDocument()); |
| 1338 } | 1358 } |
| 1339 | 1359 |
| 1340 m_nodeIdToForcedPseudoState.clear(); | 1360 m_nodeIdToForcedPseudoState.clear(); |
| 1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) | 1361 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) |
| 1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); | 1362 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1343 } | 1363 } |
| 1344 | 1364 |
| 1345 } // namespace WebCore | 1365 } // namespace WebCore |
| 1346 | 1366 |
| OLD | NEW |