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