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_nodeToInspectorStyleSheet.clear(); | 439 m_nodeToInspectorStyleSheet.clear(); |
440 m_documentToViaInspectorStyleSheet.clear(); | 440 m_documentToViaInspectorStyleSheet.clear(); |
441 resetNonPersistentData(); | 441 resetNonPersistentData(); |
442 } | 442 } |
443 | 443 |
444 void InspectorCSSAgent::resetNonPersistentData() | 444 void InspectorCSSAgent::resetNonPersistentData() |
445 { | 445 { |
446 resetPseudoStates(); | 446 resetPseudoStates(); |
447 } | 447 } |
448 | 448 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 483 |
484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) | 484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) |
485 { | 485 { |
486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { | 486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { |
487 // We were disabled while fetching resources. | 487 // We were disabled while fetching resources. |
488 return; | 488 return; |
489 } | 489 } |
490 | 490 |
491 m_instrumentingAgents->setInspectorCSSAgent(this); | 491 m_instrumentingAgents->setInspectorCSSAgent(this); |
492 Vector<Document*> documents = m_domAgent->documents(); | 492 Vector<Document*> documents = m_domAgent->documents(); |
493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) { | 493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) |
494 Document* document = *it; | 494 updateActiveStyleSheets(*it, InitialFrontendLoad); |
495 updateActiveStyleSheetsForDocument(document, InitialFrontendLoad); | |
496 } | |
497 | 495 |
498 if (callback) | 496 if (callback) |
499 callback->sendSuccess(); | 497 callback->sendSuccess(); |
500 } | 498 } |
501 | 499 |
502 void InspectorCSSAgent::disable(ErrorString*) | 500 void InspectorCSSAgent::disable(ErrorString*) |
503 { | 501 { |
504 m_instrumentingAgents->setInspectorCSSAgent(0); | 502 m_instrumentingAgents->setInspectorCSSAgent(0); |
505 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); | 503 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); |
506 } | 504 } |
507 | 505 |
508 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) | 506 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) |
509 { | 507 { |
510 if (loader->frame() == frame->page()->mainFrame()) { | 508 if (loader->frame() == frame->page()->mainFrame()) { |
511 reset(); | 509 reset(); |
512 return; | 510 return; |
513 } | 511 } |
514 | 512 |
515 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); | 513 for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin();
it != m_documentToCSSStyleSheets.end(); ++it) { |
| 514 Document* document = it->key; |
| 515 if (!document->frame() || document->frame() == frame) |
| 516 documentDisposed(document); |
| 517 } |
516 } | 518 } |
517 | 519 |
518 void InspectorCSSAgent::mediaQueryResultChanged() | 520 void InspectorCSSAgent::mediaQueryResultChanged() |
519 { | 521 { |
520 if (m_frontend) | 522 if (m_frontend) |
521 m_frontend->mediaQueryResultChanged(); | 523 m_frontend->mediaQueryResultChanged(); |
522 } | 524 } |
523 | 525 |
524 void InspectorCSSAgent::willMutateRules() | 526 void InspectorCSSAgent::willMutateRules() |
525 { | 527 { |
(...skipping 26 matching lines...) Expand all Loading... |
552 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; | 554 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; |
553 if (owner) | 555 if (owner) |
554 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl
eUpdate); | 556 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl
eUpdate); |
555 } | 557 } |
556 } | 558 } |
557 | 559 |
558 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) | 560 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) |
559 { | 561 { |
560 if (styleSheetEditInProgress()) | 562 if (styleSheetEditInProgress()) |
561 return; | 563 return; |
562 updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh); | 564 updateActiveStyleSheets(document, ExistingFrontendRefresh); |
563 } | 565 } |
564 | 566 |
565 void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, S
tyleSheetsUpdateType styleSheetsUpdateType) | 567 void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsU
pdateType styleSheetsUpdateType) |
566 { | 568 { |
567 LocalFrame* frame = document->frame(); | |
568 if (!frame) | |
569 return; | |
570 Vector<CSSStyleSheet*> newSheetsVector; | 569 Vector<CSSStyleSheet*> newSheetsVector; |
571 collectAllDocumentStyleSheets(document, newSheetsVector); | 570 collectAllDocumentStyleSheets(document, newSheetsVector); |
572 updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType); | 571 setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType); |
573 } | 572 } |
574 | 573 |
575 void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) | 574 void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CS
SStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) |
576 { | 575 { |
577 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; | 576 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; |
578 | 577 |
579 HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(f
rame); | 578 HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets
.get(document); |
580 if (!frameCSSStyleSheets) { | 579 if (!documentCSSStyleSheets) { |
581 frameCSSStyleSheets = new HashSet<CSSStyleSheet*>(); | 580 documentCSSStyleSheets = new HashSet<CSSStyleSheet*>(); |
582 OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frame
CSSStyleSheets); | 581 OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(do
cumentCSSStyleSheets); |
583 m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release()); | 582 m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.relea
se()); |
584 } | 583 } |
585 | 584 |
586 HashSet<CSSStyleSheet*> removedSheets; | 585 HashSet<CSSStyleSheet*> removedSheets; |
587 for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it
!= frameCSSStyleSheets->end(); ++it) | 586 for (HashSet<CSSStyleSheet*>::iterator it = documentCSSStyleSheets->begin();
it != documentCSSStyleSheets->end(); ++it) |
588 removedSheets.add(*it); | 587 removedSheets.add(*it); |
589 | 588 |
590 HashSet<CSSStyleSheet*> addedSheets; | 589 HashSet<CSSStyleSheet*> addedSheets; |
591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it
!= allSheetsVector.end(); ++it) { | 590 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it
!= allSheetsVector.end(); ++it) { |
592 CSSStyleSheet* cssStyleSheet = *it; | 591 CSSStyleSheet* cssStyleSheet = *it; |
593 if (removedSheets.contains(cssStyleSheet)) { | 592 if (removedSheets.contains(cssStyleSheet)) { |
594 removedSheets.remove(cssStyleSheet); | 593 removedSheets.remove(cssStyleSheet); |
595 if (isInitialFrontendLoad) | 594 if (isInitialFrontendLoad) |
596 addedSheets.add(cssStyleSheet); | 595 addedSheets.add(cssStyleSheet); |
597 } else { | 596 } else { |
598 addedSheets.add(cssStyleSheet); | 597 addedSheets.add(cssStyleSheet); |
599 } | 598 } |
600 } | 599 } |
601 | 600 |
602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem
ovedSheets.end(); ++it) { | 601 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem
ovedSheets.end(); ++it) { |
603 CSSStyleSheet* cssStyleSheet = *it; | 602 CSSStyleSheet* cssStyleSheet = *it; |
604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe
ctorStyleSheet.get(cssStyleSheet); | 603 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe
ctorStyleSheet.get(cssStyleSheet); |
605 ASSERT(inspectorStyleSheet); | 604 ASSERT(inspectorStyleSheet); |
606 | 605 |
607 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { | 606 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { |
608 String id = unbindStyleSheet(inspectorStyleSheet.get()); | 607 String id = unbindStyleSheet(inspectorStyleSheet.get()); |
609 frameCSSStyleSheets->remove(cssStyleSheet); | 608 documentCSSStyleSheets->remove(cssStyleSheet); |
610 if (m_frontend && !isInitialFrontendLoad) | 609 if (m_frontend && !isInitialFrontendLoad) |
611 m_frontend->styleSheetRemoved(id); | 610 m_frontend->styleSheetRemoved(id); |
612 } | 611 } |
613 } | 612 } |
614 | 613 |
615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added
Sheets.end(); ++it) { | 614 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added
Sheets.end(); ++it) { |
616 CSSStyleSheet* cssStyleSheet = *it; | 615 CSSStyleSheet* cssStyleSheet = *it; |
617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh
eet.contains(cssStyleSheet); | 616 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh
eet.contains(cssStyleSheet); |
618 if (isNew) { | 617 if (isNew) { |
619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); | 618 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); |
620 frameCSSStyleSheets->add(cssStyleSheet); | 619 documentCSSStyleSheets->add(cssStyleSheet); |
621 if (m_frontend) | 620 if (m_frontend) |
622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh
eetInfo()); | 621 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh
eetInfo()); |
623 } | 622 } |
624 } | 623 } |
625 | 624 |
626 if (frameCSSStyleSheets->isEmpty()) | 625 if (documentCSSStyleSheets->isEmpty()) |
627 m_frameToCSSStyleSheets.remove(frame); | 626 m_documentToCSSStyleSheets.remove(document); |
| 627 } |
| 628 |
| 629 void InspectorCSSAgent::documentDisposed(Document* document) |
| 630 { |
| 631 setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); |
628 } | 632 } |
629 | 633 |
630 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) | 634 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) |
631 { | 635 { |
632 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); | 636 documentDisposed(frame->document()); |
633 } | 637 } |
634 | 638 |
635 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) | 639 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) |
636 { | 640 { |
637 if (m_nodeIdToForcedPseudoState.isEmpty()) | 641 if (m_nodeIdToForcedPseudoState.isEmpty()) |
638 return false; | 642 return false; |
639 | 643 |
640 int nodeId = m_domAgent->boundNodeId(element); | 644 int nodeId = m_domAgent->boundNodeId(element); |
641 if (!nodeId) | 645 if (!nodeId) |
642 return false; | 646 return false; |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 documentsToChange.add(element->ownerDocument()); | 1341 documentsToChange.add(element->ownerDocument()); |
1338 } | 1342 } |
1339 | 1343 |
1340 m_nodeIdToForcedPseudoState.clear(); | 1344 m_nodeIdToForcedPseudoState.clear(); |
1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) | 1345 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) |
1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); | 1346 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); |
1343 } | 1347 } |
1344 | 1348 |
1345 } // namespace WebCore | 1349 } // namespace WebCore |
1346 | 1350 |
OLD | NEW |