| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 m_domAgent->setDOMListener(0); | 424 m_domAgent->setDOMListener(0); |
| 425 m_domAgent = 0; | 425 m_domAgent = 0; |
| 426 } | 426 } |
| 427 | 427 |
| 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::flushPendingFrontendMessages() |
| 435 { |
| 436 if (!m_invalidatedDocuments.size()) |
| 437 return; |
| 438 HashSet<Document*> invalidatedDocuments; |
| 439 m_invalidatedDocuments.swap(&invalidatedDocuments); |
| 440 for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != i
nvalidatedDocuments.end(); ++it) |
| 441 updateActiveStyleSheets(*it, ExistingFrontendRefresh); |
| 442 } |
| 443 |
| 434 void InspectorCSSAgent::reset() | 444 void InspectorCSSAgent::reset() |
| 435 { | 445 { |
| 436 m_idToInspectorStyleSheet.clear(); | 446 m_idToInspectorStyleSheet.clear(); |
| 437 m_cssStyleSheetToInspectorStyleSheet.clear(); | 447 m_cssStyleSheetToInspectorStyleSheet.clear(); |
| 438 m_frameToCSSStyleSheets.clear(); | 448 m_documentToCSSStyleSheets.clear(); |
| 449 m_invalidatedDocuments.clear(); |
| 439 m_nodeToInspectorStyleSheet.clear(); | 450 m_nodeToInspectorStyleSheet.clear(); |
| 440 m_documentToViaInspectorStyleSheet.clear(); | 451 m_documentToViaInspectorStyleSheet.clear(); |
| 441 resetNonPersistentData(); | 452 resetNonPersistentData(); |
| 442 } | 453 } |
| 443 | 454 |
| 444 void InspectorCSSAgent::resetNonPersistentData() | 455 void InspectorCSSAgent::resetNonPersistentData() |
| 445 { | 456 { |
| 446 resetPseudoStates(); | 457 resetPseudoStates(); |
| 447 } | 458 } |
| 448 | 459 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 494 |
| 484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) | 495 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) |
| 485 { | 496 { |
| 486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { | 497 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { |
| 487 // We were disabled while fetching resources. | 498 // We were disabled while fetching resources. |
| 488 return; | 499 return; |
| 489 } | 500 } |
| 490 | 501 |
| 491 m_instrumentingAgents->setInspectorCSSAgent(this); | 502 m_instrumentingAgents->setInspectorCSSAgent(this); |
| 492 Vector<Document*> documents = m_domAgent->documents(); | 503 Vector<Document*> documents = m_domAgent->documents(); |
| 493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) { | 504 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) |
| 494 Document* document = *it; | 505 updateActiveStyleSheets(*it, InitialFrontendLoad); |
| 495 updateActiveStyleSheetsForDocument(document, InitialFrontendLoad); | |
| 496 } | |
| 497 | 506 |
| 498 if (callback) | 507 if (callback) |
| 499 callback->sendSuccess(); | 508 callback->sendSuccess(); |
| 500 } | 509 } |
| 501 | 510 |
| 502 void InspectorCSSAgent::disable(ErrorString*) | 511 void InspectorCSSAgent::disable(ErrorString*) |
| 503 { | 512 { |
| 504 m_instrumentingAgents->setInspectorCSSAgent(0); | 513 m_instrumentingAgents->setInspectorCSSAgent(0); |
| 505 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); | 514 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); |
| 506 } | 515 } |
| 507 | 516 |
| 508 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) | 517 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) |
| 509 { | 518 { |
| 510 if (loader->frame() == frame->page()->mainFrame()) { | 519 if (loader->frame() == frame->page()->mainFrame()) { |
| 511 reset(); | 520 reset(); |
| 512 return; | 521 return; |
| 513 } | 522 } |
| 514 | 523 |
| 515 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); | 524 Vector<Document*> toDispose; |
| 525 for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin();
it != m_documentToCSSStyleSheets.end(); ++it) { |
| 526 Document* document = it->key; |
| 527 if (!document->frame() || document->frame() == frame) |
| 528 toDispose.append(document); |
| 529 } |
| 530 for (Vector<Document*>::iterator it = toDispose.begin(); it != toDispose.end
(); ++it) |
| 531 documentDetached(*it); |
| 516 } | 532 } |
| 517 | 533 |
| 518 void InspectorCSSAgent::mediaQueryResultChanged() | 534 void InspectorCSSAgent::mediaQueryResultChanged() |
| 519 { | 535 { |
| 520 if (m_frontend) | 536 flushPendingFrontendMessages(); |
| 521 m_frontend->mediaQueryResultChanged(); | 537 m_frontend->mediaQueryResultChanged(); |
| 522 } | 538 } |
| 523 | 539 |
| 524 void InspectorCSSAgent::willMutateRules() | 540 void InspectorCSSAgent::willMutateRules() |
| 525 { | 541 { |
| 526 ++m_styleSheetsPendingMutation; | 542 ++m_styleSheetsPendingMutation; |
| 527 } | 543 } |
| 528 | 544 |
| 529 void InspectorCSSAgent::didMutateRules(CSSStyleSheet* styleSheet) | 545 void InspectorCSSAgent::didMutateRules(CSSStyleSheet* styleSheet) |
| 530 { | 546 { |
| 531 --m_styleSheetsPendingMutation; | 547 --m_styleSheetsPendingMutation; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 552 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; | 568 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; |
| 553 if (owner) | 569 if (owner) |
| 554 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl
eUpdate); | 570 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl
eUpdate); |
| 555 } | 571 } |
| 556 } | 572 } |
| 557 | 573 |
| 558 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) | 574 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) |
| 559 { | 575 { |
| 560 if (styleSheetEditInProgress()) | 576 if (styleSheetEditInProgress()) |
| 561 return; | 577 return; |
| 562 updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh); | 578 m_invalidatedDocuments.add(document); |
| 579 if (m_creatingViaInspectorStyleSheet) |
| 580 flushPendingFrontendMessages(); |
| 563 } | 581 } |
| 564 | 582 |
| 565 void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, S
tyleSheetsUpdateType styleSheetsUpdateType) | 583 void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsU
pdateType styleSheetsUpdateType) |
| 566 { | 584 { |
| 567 LocalFrame* frame = document->frame(); | |
| 568 if (!frame) | |
| 569 return; | |
| 570 Vector<CSSStyleSheet*> newSheetsVector; | 585 Vector<CSSStyleSheet*> newSheetsVector; |
| 571 collectAllDocumentStyleSheets(document, newSheetsVector); | 586 collectAllDocumentStyleSheets(document, newSheetsVector); |
| 572 updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType); | 587 setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType); |
| 573 } | 588 } |
| 574 | 589 |
| 575 void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) | 590 void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CS
SStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) |
| 576 { | 591 { |
| 577 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; | 592 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; |
| 578 | 593 |
| 579 HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(f
rame); | 594 HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets
.get(document); |
| 580 if (!frameCSSStyleSheets) { | 595 if (!documentCSSStyleSheets) { |
| 581 frameCSSStyleSheets = new HashSet<CSSStyleSheet*>(); | 596 documentCSSStyleSheets = new HashSet<CSSStyleSheet*>(); |
| 582 OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frame
CSSStyleSheets); | 597 OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(do
cumentCSSStyleSheets); |
| 583 m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release()); | 598 m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.relea
se()); |
| 584 } | 599 } |
| 585 | 600 |
| 586 HashSet<CSSStyleSheet*> removedSheets; | 601 HashSet<CSSStyleSheet*> removedSheets(*documentCSSStyleSheets); |
| 587 for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it
!= frameCSSStyleSheets->end(); ++it) | |
| 588 removedSheets.add(*it); | |
| 589 | 602 |
| 590 HashSet<CSSStyleSheet*> addedSheets; | 603 HashSet<CSSStyleSheet*> addedSheets; |
| 591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it
!= allSheetsVector.end(); ++it) { | 604 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it
!= allSheetsVector.end(); ++it) { |
| 592 CSSStyleSheet* cssStyleSheet = *it; | 605 CSSStyleSheet* cssStyleSheet = *it; |
| 593 if (removedSheets.contains(cssStyleSheet)) { | 606 if (removedSheets.contains(cssStyleSheet)) { |
| 594 removedSheets.remove(cssStyleSheet); | 607 removedSheets.remove(cssStyleSheet); |
| 595 if (isInitialFrontendLoad) | 608 if (isInitialFrontendLoad) |
| 596 addedSheets.add(cssStyleSheet); | 609 addedSheets.add(cssStyleSheet); |
| 597 } else { | 610 } else { |
| 598 addedSheets.add(cssStyleSheet); | 611 addedSheets.add(cssStyleSheet); |
| 599 } | 612 } |
| 600 } | 613 } |
| 601 | 614 |
| 602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem
ovedSheets.end(); ++it) { | 615 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem
ovedSheets.end(); ++it) { |
| 603 CSSStyleSheet* cssStyleSheet = *it; | 616 CSSStyleSheet* cssStyleSheet = *it; |
| 604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe
ctorStyleSheet.get(cssStyleSheet); | 617 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe
ctorStyleSheet.get(cssStyleSheet); |
| 605 ASSERT(inspectorStyleSheet); | 618 ASSERT(inspectorStyleSheet); |
| 606 | 619 |
| 620 documentCSSStyleSheets->remove(cssStyleSheet); |
| 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); | |
| 610 if (m_frontend && !isInitialFrontendLoad) | 623 if (m_frontend && !isInitialFrontendLoad) |
| 611 m_frontend->styleSheetRemoved(id); | 624 m_frontend->styleSheetRemoved(id); |
| 612 } | 625 } |
| 613 } | 626 } |
| 614 | 627 |
| 615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added
Sheets.end(); ++it) { | 628 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added
Sheets.end(); ++it) { |
| 616 CSSStyleSheet* cssStyleSheet = *it; | 629 CSSStyleSheet* cssStyleSheet = *it; |
| 617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh
eet.contains(cssStyleSheet); | 630 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh
eet.contains(cssStyleSheet); |
| 618 if (isNew) { | 631 if (isNew) { |
| 619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); | 632 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); |
| 620 frameCSSStyleSheets->add(cssStyleSheet); | 633 documentCSSStyleSheets->add(cssStyleSheet); |
| 621 if (m_frontend) | 634 if (m_frontend) |
| 622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh
eetInfo()); | 635 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh
eetInfo()); |
| 623 } | 636 } |
| 624 } | 637 } |
| 625 | 638 |
| 626 if (frameCSSStyleSheets->isEmpty()) | 639 if (documentCSSStyleSheets->isEmpty()) |
| 627 m_frameToCSSStyleSheets.remove(frame); | 640 m_documentToCSSStyleSheets.remove(document); |
| 641 } |
| 642 |
| 643 void InspectorCSSAgent::documentDetached(Document* document) |
| 644 { |
| 645 m_invalidatedDocuments.remove(document); |
| 646 setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); |
| 628 } | 647 } |
| 629 | 648 |
| 630 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) | 649 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) |
| 631 { | 650 { |
| 632 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef
resh); | 651 documentDetached(frame->document()); |
| 633 } | 652 } |
| 634 | 653 |
| 635 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) | 654 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) |
| 636 { | 655 { |
| 637 if (m_nodeIdToForcedPseudoState.isEmpty()) | 656 if (m_nodeIdToForcedPseudoState.isEmpty()) |
| 638 return false; | 657 return false; |
| 639 | 658 |
| 640 int nodeId = m_domAgent->boundNodeId(element); | 659 int nodeId = m_domAgent->boundNodeId(element); |
| 641 if (!nodeId) | 660 if (!nodeId) |
| 642 return false; | 661 return false; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 *errorString = "Frame does not have a document"; | 904 *errorString = "Frame does not have a document"; |
| 886 return; | 905 return; |
| 887 } | 906 } |
| 888 | 907 |
| 889 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(document,
true); | 908 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(document,
true); |
| 890 if (!inspectorStyleSheet) { | 909 if (!inspectorStyleSheet) { |
| 891 *errorString = "No target stylesheet found"; | 910 *errorString = "No target stylesheet found"; |
| 892 return; | 911 return; |
| 893 } | 912 } |
| 894 | 913 |
| 914 updateActiveStyleSheets(document, ExistingFrontendRefresh); |
| 915 |
| 895 *outStyleSheetId = inspectorStyleSheet->id(); | 916 *outStyleSheetId = inspectorStyleSheet->id(); |
| 896 } | 917 } |
| 897 | 918 |
| 898 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe
etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) | 919 void InspectorCSSAgent::addRule(ErrorString* errorString, const String& styleShe
etId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) |
| 899 { | 920 { |
| 900 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString
, styleSheetId); | 921 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString
, styleSheetId); |
| 901 if (!inspectorStyleSheet) | 922 if (!inspectorStyleSheet) |
| 902 return; | 923 return; |
| 903 | 924 |
| 904 TrackExceptionState exceptionState; | 925 TrackExceptionState exceptionState; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 | 1326 |
| 1306 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el
ement); | 1327 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el
ement); |
| 1307 if (it == m_nodeToInspectorStyleSheet.end()) | 1328 if (it == m_nodeToInspectorStyleSheet.end()) |
| 1308 return; | 1329 return; |
| 1309 | 1330 |
| 1310 it->value->didModifyElementAttribute(); | 1331 it->value->didModifyElementAttribute(); |
| 1311 } | 1332 } |
| 1312 | 1333 |
| 1313 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet) | 1334 void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet) |
| 1314 { | 1335 { |
| 1315 if (m_frontend) | 1336 flushPendingFrontendMessages(); |
| 1316 m_frontend->styleSheetChanged(styleSheet->id()); | 1337 m_frontend->styleSheetChanged(styleSheet->id()); |
| 1317 } | 1338 } |
| 1318 | 1339 |
| 1319 void InspectorCSSAgent::willReparseStyleSheet() | 1340 void InspectorCSSAgent::willReparseStyleSheet() |
| 1320 { | 1341 { |
| 1321 ASSERT(!m_isSettingStyleSheetText); | 1342 ASSERT(!m_isSettingStyleSheetText); |
| 1322 m_isSettingStyleSheetText = true; | 1343 m_isSettingStyleSheetText = true; |
| 1323 } | 1344 } |
| 1324 | 1345 |
| 1325 void InspectorCSSAgent::didReparseStyleSheet() | 1346 void InspectorCSSAgent::didReparseStyleSheet() |
| 1326 { | 1347 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1337 documentsToChange.add(element->ownerDocument()); | 1358 documentsToChange.add(element->ownerDocument()); |
| 1338 } | 1359 } |
| 1339 | 1360 |
| 1340 m_nodeIdToForcedPseudoState.clear(); | 1361 m_nodeIdToForcedPseudoState.clear(); |
| 1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) | 1362 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) |
| 1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); | 1363 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1343 } | 1364 } |
| 1344 | 1365 |
| 1345 } // namespace WebCore | 1366 } // namespace WebCore |
| 1346 | 1367 |
| OLD | NEW |