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

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

Issue 20091002: DevTools: Clean up InspectorStyleSheet, InspectorCSSAgent, and InspectorResourceAgent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 7 years, 4 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
« no previous file with comments | « no previous file | Source/core/inspector/InspectorResourceAgent.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 }; 134 };
135 135
136 class StyleSheetAppender { 136 class StyleSheetAppender {
137 public: 137 public:
138 StyleSheetAppender(CSSStyleSheetToInspectorStyleSheet& cssStyleSheetToInspec torStyleSheet, Vector<CSSStyleSheet*>& result) 138 StyleSheetAppender(CSSStyleSheetToInspectorStyleSheet& cssStyleSheetToInspec torStyleSheet, Vector<CSSStyleSheet*>& result)
139 : m_cssStyleSheetToInspectorStyleSheet(cssStyleSheetToInspectorStyleShee t) 139 : m_cssStyleSheetToInspectorStyleSheet(cssStyleSheetToInspectorStyleShee t)
140 , m_result(result) { } 140 , m_result(result) { }
141 141
142 void run(CSSStyleSheet* styleSheet) 142 void run(CSSStyleSheet* styleSheet)
143 { 143 {
144 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(static_cast<CSSStyleSheet*>(styleSheet)); 144 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(styleSheet);
145 // Avoid creating m_childRuleCSSOMWrappers in the stylesheet if it is in the process of re-parsing. 145 // Avoid creating m_childRuleCSSOMWrappers in the stylesheet if it is in the process of re-parsing.
146 // Otherwise m_childRuleCSSOMWrappers size will be initialized only for a part of rules, resulting in an ASSERT failure in CSSStyleSheet::item(). 146 // Otherwise m_childRuleCSSOMWrappers size will be initialized only for a part of rules, resulting in an ASSERT failure in CSSStyleSheet::item().
147 // Instead, wait for the RuleMutationScope destruction and handle the co mplete CSSStyleSheet. 147 // Instead, wait for the RuleMutationScope destruction and handle the co mplete CSSStyleSheet.
148 if (inspectorStyleSheet && inspectorStyleSheet->isReparsing()) 148 if (inspectorStyleSheet && inspectorStyleSheet->isReparsing())
149 return; 149 return;
150 m_result.append(styleSheet); 150 m_result.append(styleSheet);
151 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { 151 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
152 CSSRule* rule = styleSheet->item(i); 152 CSSRule* rule = styleSheet->item(i);
153 if (rule->type() == CSSRule::IMPORT_RULE) { 153 if (rule->type() == CSSRule::IMPORT_RULE) {
154 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>( rule)->styleSheet(); 154 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>( rule)->styleSheet();
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 resetPseudoStates(); 905 resetPseudoStates();
906 } 906 }
907 907
908 void InspectorCSSAgent::enable(ErrorString*) 908 void InspectorCSSAgent::enable(ErrorString*)
909 { 909 {
910 m_state->setBoolean(CSSAgentState::cssAgentEnabled, true); 910 m_state->setBoolean(CSSAgentState::cssAgentEnabled, true);
911 m_instrumentingAgents->setInspectorCSSAgent(this); 911 m_instrumentingAgents->setInspectorCSSAgent(this);
912 912
913 if (!m_frontend) 913 if (!m_frontend)
914 return; 914 return;
915 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > styleInfo s = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create();
916 Vector<InspectorStyleSheet*> styleSheets; 915 Vector<InspectorStyleSheet*> styleSheets;
917 collectAllStyleSheets(styleSheets); 916 collectAllStyleSheets(styleSheets);
918 for (size_t i = 0; i < styleSheets.size(); ++i) 917 for (size_t i = 0; i < styleSheets.size(); ++i)
919 m_frontend->styleSheetAdded(styleSheets.at(i)->buildObjectForStyleSheetI nfo()); 918 m_frontend->styleSheetAdded(styleSheets.at(i)->buildObjectForStyleSheetI nfo());
920 } 919 }
921 920
922 void InspectorCSSAgent::disable(ErrorString*) 921 void InspectorCSSAgent::disable(ErrorString*)
923 { 922 {
924 m_instrumentingAgents->setInspectorCSSAgent(0); 923 m_instrumentingAgents->setInspectorCSSAgent(0);
925 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); 924 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1025
1027 HashSet<CSSStyleSheet*> addedSheets; 1026 HashSet<CSSStyleSheet*> addedSheets;
1028 for (size_t i = 0; i < newSheetsVector.size(); ++i) { 1027 for (size_t i = 0; i < newSheetsVector.size(); ++i) {
1029 CSSStyleSheet* newCSSSheet = newSheetsVector.at(i); 1028 CSSStyleSheet* newCSSSheet = newSheetsVector.at(i);
1030 if (removedSheets.contains(newCSSSheet)) 1029 if (removedSheets.contains(newCSSSheet))
1031 removedSheets.remove(newCSSSheet); 1030 removedSheets.remove(newCSSSheet);
1032 else 1031 else
1033 addedSheets.add(newCSSSheet); 1032 addedSheets.add(newCSSSheet);
1034 } 1033 }
1035 1034
1036 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::StyleSheetId> > removedIds = Typ eBuilder::Array<TypeBuilder::CSS::StyleSheetId>::create();
1037 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) { 1035 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) {
1038 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(*it); 1036 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(*it);
1039 ASSERT(inspectorStyleSheet); 1037 ASSERT(inspectorStyleSheet);
1040 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { 1038 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) {
1041 String id = unbindStyleSheet(inspectorStyleSheet.get()); 1039 String id = unbindStyleSheet(inspectorStyleSheet.get());
1042 if (m_frontend) 1040 if (m_frontend)
1043 m_frontend->styleSheetRemoved(id); 1041 m_frontend->styleSheetRemoved(id);
1044 } 1042 }
1045 } 1043 }
1046 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > addedHead ers = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create(); 1044
1047 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) { 1045 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) {
1048 if (!m_cssStyleSheetToInspectorStyleSheet.contains(*it)) { 1046 if (!m_cssStyleSheetToInspectorStyleSheet.contains(*it)) {
1049 InspectorStyleSheet* newStyleSheet = bindStyleSheet(static_cast<CSSS tyleSheet*>(*it)); 1047 InspectorStyleSheet* newStyleSheet = bindStyleSheet(static_cast<CSSS tyleSheet*>(*it));
1050 if (m_frontend) 1048 if (m_frontend)
1051 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo()); 1049 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo());
1052 } 1050 }
1053 } 1051 }
1054 } 1052 }
1055 1053
1056 void InspectorCSSAgent::frameDetachedFromParent(Frame* frame) 1054 void InspectorCSSAgent::frameDetachedFromParent(Frame* frame)
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 if (parentStyleSheet && mediaListSource != MediaListSourceLinkedSheet) { 1392 if (parentStyleSheet && mediaListSource != MediaListSourceLinkedSheet) {
1395 if (InspectorStyleSheet* inspectorStyleSheet = m_cssStyleSheetToInspecto rStyleSheet.get(parentStyleSheet)) 1393 if (InspectorStyleSheet* inspectorStyleSheet = m_cssStyleSheetToInspecto rStyleSheet.get(parentStyleSheet))
1396 mediaObject->setParentStyleSheetId(inspectorStyleSheet->id()); 1394 mediaObject->setParentStyleSheetId(inspectorStyleSheet->id());
1397 } 1395 }
1398 if (!sourceURL.isEmpty()) { 1396 if (!sourceURL.isEmpty()) {
1399 mediaObject->setSourceURL(sourceURL); 1397 mediaObject->setSourceURL(sourceURL);
1400 1398
1401 CSSRule* parentRule = media->parentRule(); 1399 CSSRule* parentRule = media->parentRule();
1402 if (!parentRule) 1400 if (!parentRule)
1403 return mediaObject.release(); 1401 return mediaObject.release();
1404 InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(const_cast<CSS StyleSheet*>(parentRule->parentStyleSheet())); 1402 InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(parentRule->pa rentStyleSheet());
1405 RefPtr<TypeBuilder::CSS::SourceRange> mediaRange = inspectorStyleSheet-> ruleHeaderSourceRange(parentRule); 1403 RefPtr<TypeBuilder::CSS::SourceRange> mediaRange = inspectorStyleSheet-> ruleHeaderSourceRange(parentRule);
1406 if (mediaRange) 1404 if (mediaRange)
1407 mediaObject->setRange(mediaRange); 1405 mediaObject->setRange(mediaRange);
1408 } 1406 }
1409 return mediaObject.release(); 1407 return mediaObject.release();
1410 } 1408 }
1411 1409
1412 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> > InspectorCSSAgent::b uildMediaListChain(CSSRule* rule) 1410 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> > InspectorCSSAgent::b uildMediaListChain(CSSRule* rule)
1413 { 1411 {
1414 if (!rule) 1412 if (!rule)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 1515
1518 void InspectorCSSAgent::didProcessRule() 1516 void InspectorCSSAgent::didProcessRule()
1519 { 1517 {
1520 if (m_currentSelectorProfile) 1518 if (m_currentSelectorProfile)
1521 m_currentSelectorProfile->commitSelectorTime(); 1519 m_currentSelectorProfile->commitSelectorTime();
1522 } 1520 }
1523 1521
1524 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element) 1522 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element)
1525 { 1523 {
1526 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); 1524 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement);
1527 if (it == m_nodeToInspectorStyleSheet.end()) { 1525 if (it != m_nodeToInspectorStyleSheet.end())
1528 CSSStyleDeclaration* style = element->isStyledElement() ? element->style () : 0; 1526 return it->value.get();
1529 if (!style)
1530 return 0;
1531 1527
1532 String newStyleSheetId = String::number(m_lastStyleSheetId++); 1528 CSSStyleDeclaration* style = element->isStyledElement() ? element->style() : 0;
1533 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = Inspecto rStyleSheetForInlineStyle::create(m_pageAgent, newStyleSheetId, element, TypeBui lder::CSS::StyleSheetOrigin::Regular, this); 1529 if (!style)
1534 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); 1530 return 0;
1535 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
1536 return inspectorStyleSheet.get();
1537 }
1538 1531
1539 return it->value.get(); 1532 String newStyleSheetId = String::number(m_lastStyleSheetId++);
1533 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorSty leSheetForInlineStyle::create(m_pageAgent, newStyleSheetId, element, TypeBuilder ::CSS::StyleSheetOrigin::Regular, this);
1534 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet);
1535 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
1536 return inspectorStyleSheet.get();
1540 } 1537 }
1541 1538
1542 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) 1539 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId)
1543 { 1540 {
1544 Node* node = m_domAgent->nodeForId(nodeId); 1541 Node* node = m_domAgent->nodeForId(nodeId);
1545 if (!node) { 1542 if (!node) {
1546 *errorString = "No node with given id found"; 1543 *errorString = "No node with given id found";
1547 return 0; 1544 return 0;
1548 } 1545 }
1549 if (node->nodeType() != Node::ELEMENT_NODE) { 1546 if (!node->isElementNode()) {
1550 *errorString = "Not an element node"; 1547 *errorString = "Not an element node";
1551 return 0; 1548 return 0;
1552 } 1549 }
1553 return toElement(node); 1550 return toElement(node);
1554 } 1551 }
1555 1552
1556 int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document) 1553 int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document)
1557 { 1554 {
1558 int documentNodeId = m_domAgent->boundNodeId(document); 1555 int documentNodeId = m_domAgent->boundNodeId(document);
1559 if (!documentNodeId || !m_namedFlowCollectionsRequested.contains(documentNod eId)) 1556 if (!documentNodeId || !m_namedFlowCollectionsRequested.contains(documentNod eId))
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 documentsToChange.add(element->ownerDocument()); 1878 documentsToChange.add(element->ownerDocument());
1882 } 1879 }
1883 1880
1884 m_nodeIdToForcedPseudoState.clear(); 1881 m_nodeIdToForcedPseudoState.clear();
1885 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1882 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1886 (*it)->setNeedsStyleRecalc(); 1883 (*it)->setNeedsStyleRecalc();
1887 } 1884 }
1888 1885
1889 } // namespace WebCore 1886 } // namespace WebCore
1890 1887
OLDNEW
« no previous file with comments | « no previous file | Source/core/inspector/InspectorResourceAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698