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

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

Issue 16745003: DevTools: Move CSS.CSSMedia construction into InspectorCSSAgent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Get rid of the ISS->ICSSAgent dependency Created 7 years, 6 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 | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorStyleSheet.h » ('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 11 matching lines...) Expand all
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/inspector/InspectorCSSAgent.h" 26 #include "core/inspector/InspectorCSSAgent.h"
27 27
28 #include "CSSPropertyNames.h" 28 #include "CSSPropertyNames.h"
29 #include "InspectorTypeBuilder.h" 29 #include "InspectorTypeBuilder.h"
30 #include "core/css/CSSComputedStyleDeclaration.h" 30 #include "core/css/CSSComputedStyleDeclaration.h"
31 #include "core/css/CSSImportRule.h" 31 #include "core/css/CSSImportRule.h"
32 #include "core/css/CSSMediaRule.h"
32 #include "core/css/CSSParser.h" 33 #include "core/css/CSSParser.h"
34 #include "core/css/CSSPropertySourceData.h"
33 #include "core/css/CSSRule.h" 35 #include "core/css/CSSRule.h"
34 #include "core/css/CSSRuleList.h" 36 #include "core/css/CSSRuleList.h"
35 #include "core/css/CSSStyleRule.h" 37 #include "core/css/CSSStyleRule.h"
36 #include "core/css/CSSStyleSheet.h" 38 #include "core/css/CSSStyleSheet.h"
39 #include "core/css/MediaList.h"
37 #include "core/css/StylePropertySet.h" 40 #include "core/css/StylePropertySet.h"
38 #include "core/css/StylePropertyShorthand.h" 41 #include "core/css/StylePropertyShorthand.h"
39 #include "core/css/StyleRule.h" 42 #include "core/css/StyleRule.h"
40 #include "core/css/StyleSheet.h" 43 #include "core/css/StyleSheet.h"
44 #include "core/css/StyleSheetContents.h"
41 #include "core/css/StyleSheetList.h" 45 #include "core/css/StyleSheetList.h"
42 #include "core/css/resolver/StyleResolver.h" 46 #include "core/css/resolver/StyleResolver.h"
43 #include "core/dom/ExceptionCodePlaceholder.h" 47 #include "core/dom/ExceptionCodePlaceholder.h"
44 #include "core/dom/NamedFlow.h" 48 #include "core/dom/NamedFlow.h"
45 #include "core/dom/NamedFlowCollection.h" 49 #include "core/dom/NamedFlowCollection.h"
46 #include "core/dom/Node.h" 50 #include "core/dom/Node.h"
47 #include "core/dom/NodeList.h" 51 #include "core/dom/NodeList.h"
48 #include "core/html/HTMLHeadElement.h" 52 #include "core/html/HTMLHeadElement.h"
49 #include "core/inspector/ContentSearchUtils.h" 53 #include "core/inspector/ContentSearchUtils.h"
50 #include "core/inspector/InspectorDOMAgent.h" 54 #include "core/inspector/InspectorDOMAgent.h"
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 for (size_t i = 0; i < styleSheets.size(); ++i) 997 for (size_t i = 0; i < styleSheets.size(); ++i)
994 styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo()); 998 styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo());
995 } 999 }
996 1000
997 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) 1001 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject)
998 { 1002 {
999 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 1003 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
1000 if (!inspectorStyleSheet) 1004 if (!inspectorStyleSheet)
1001 return; 1005 return;
1002 1006
1003 styleSheetObject = inspectorStyleSheet->buildObjectForStyleSheet(); 1007 Document* doc = inspectorStyleSheet->pageStyleSheet() ? inspectorStyleSheet- >pageStyleSheet()->ownerDocument() : 0;
1008 if (!doc || !doc->styleResolver())
1009 return;
1010
1011 RefPtr<TypeBuilder::CSS::CSSStyleSheetBody> result = TypeBuilder::CSS::CSSSt yleSheetBody::create()
1012 .setStyleSheetId(styleSheetId)
1013 .setRules(buildArrayForRuleList(inspectorStyleSheet->pageStyleSheet()->r ules().get(), doc->styleResolver()));
1014
1015 bool success = inspectorStyleSheet->fillObjectForStyleSheet(result);
1016 if (success)
1017 styleSheetObject = result;
1004 } 1018 }
1005 1019
1006 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result) 1020 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result)
1007 { 1021 {
1008 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 1022 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
1009 if (!inspectorStyleSheet) 1023 if (!inspectorStyleSheet)
1010 return; 1024 return;
1011 1025
1012 inspectorStyleSheet->getText(result); 1026 inspectorStyleSheet->getText(result);
1013 } 1027 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 InspectorCSSId compoundId(fullRuleId); 1090 InspectorCSSId compoundId(fullRuleId);
1077 ASSERT(!compoundId.isEmpty()); 1091 ASSERT(!compoundId.isEmpty());
1078 1092
1079 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId()); 1093 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId());
1080 if (!inspectorStyleSheet) 1094 if (!inspectorStyleSheet)
1081 return; 1095 return;
1082 1096
1083 ExceptionCode ec = 0; 1097 ExceptionCode ec = 0;
1084 bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAc tion(inspectorStyleSheet, compoundId, selector)), ec); 1098 bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAc tion(inspectorStyleSheet, compoundId, selector)), ec);
1085 1099
1086 if (success) 1100 if (success) {
1087 result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ru leForId(compoundId)); 1101 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(compoundId);
1102 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListCha in(rule));
1103 }
1088 *errorString = InspectorDOMAgent::toErrorString(ec); 1104 *errorString = InspectorDOMAgent::toErrorString(ec);
1089 } 1105 }
1090 1106
1091 void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeI d, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) 1107 void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeI d, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result)
1092 { 1108 {
1093 Node* node = m_domAgent->assertNode(errorString, contextNodeId); 1109 Node* node = m_domAgent->assertNode(errorString, contextNodeId);
1094 if (!node) 1110 if (!node)
1095 return; 1111 return;
1096 1112
1097 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->docu ment(), true); 1113 InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->docu ment(), true);
1098 if (!inspectorStyleSheet) { 1114 if (!inspectorStyleSheet) {
1099 *errorString = "No target stylesheet found"; 1115 *errorString = "No target stylesheet found";
1100 return; 1116 return;
1101 } 1117 }
1102 1118
1103 ExceptionCode ec = 0; 1119 ExceptionCode ec = 0;
1104 OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleShee t, selector)); 1120 OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleShee t, selector));
1105 AddRuleAction* rawAction = action.get(); 1121 AddRuleAction* rawAction = action.get();
1106 bool success = m_domAgent->history()->perform(action.release(), ec); 1122 bool success = m_domAgent->history()->perform(action.release(), ec);
1107 if (!success) { 1123 if (!success) {
1108 *errorString = InspectorDOMAgent::toErrorString(ec); 1124 *errorString = InspectorDOMAgent::toErrorString(ec);
1109 return; 1125 return;
1110 } 1126 }
1111 1127
1112 InspectorCSSId ruleId = rawAction->newRuleId(); 1128 InspectorCSSId ruleId = rawAction->newRuleId();
1113 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId); 1129 CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId);
1114 result = inspectorStyleSheet->buildObjectForRule(rule); 1130 result = inspectorStyleSheet->buildObjectForRule(rule, buildMediaListChain(r ule));
1115 } 1131 }
1116 1132
1117 void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<TypeBuild er::Array<TypeBuilder::CSS::CSSPropertyInfo> >& cssProperties) 1133 void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<TypeBuild er::Array<TypeBuilder::CSS::CSSPropertyInfo> >& cssProperties)
1118 { 1134 {
1119 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo> > properties = TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo>::create(); 1135 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo> > properties = TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo>::create();
1120 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) { 1136 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
1121 CSSPropertyID id = convertToCSSPropertyID(i); 1137 CSSPropertyID id = convertToCSSPropertyID(i);
1122 RefPtr<TypeBuilder::CSS::CSSPropertyInfo> property = TypeBuilder::CSS::C SSPropertyInfo::create() 1138 RefPtr<TypeBuilder::CSS::CSSPropertyInfo> property = TypeBuilder::CSS::C SSPropertyInfo::create()
1123 .setName(getPropertyNameString(id)); 1139 .setName(getPropertyNameString(id));
1124 1140
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 1184
1169 Vector<RefPtr<NamedFlow> > namedFlowsVector = document->namedFlows()->namedF lows(); 1185 Vector<RefPtr<NamedFlow> > namedFlowsVector = document->namedFlows()->namedF lows();
1170 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> > namedFlows = TypeBu ilder::Array<TypeBuilder::CSS::NamedFlow>::create(); 1186 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> > namedFlows = TypeBu ilder::Array<TypeBuilder::CSS::NamedFlow>::create();
1171 1187
1172 for (Vector<RefPtr<NamedFlow> >::iterator it = namedFlowsVector.begin(); it != namedFlowsVector.end(); ++it) 1188 for (Vector<RefPtr<NamedFlow> >::iterator it = namedFlowsVector.begin(); it != namedFlowsVector.end(); ++it)
1173 namedFlows->addItem(buildObjectForNamedFlow(errorString, it->get(), docu mentNodeId)); 1189 namedFlows->addItem(buildObjectForNamedFlow(errorString, it->get(), docu mentNodeId));
1174 1190
1175 result = namedFlows.release(); 1191 result = namedFlows.release();
1176 } 1192 }
1177 1193
1194 PassRefPtr<TypeBuilder::CSS::CSSMedia> InspectorCSSAgent::buildMediaObject(const MediaList* media, MediaListSource mediaListSource, const String& sourceURL)
1195 {
1196 // Make certain compilers happy by initializing |source| up-front.
1197 TypeBuilder::CSS::CSSMedia::Source::Enum source = TypeBuilder::CSS::CSSMedia ::Source::InlineSheet;
1198 switch (mediaListSource) {
1199 case MediaListSourceMediaRule:
1200 source = TypeBuilder::CSS::CSSMedia::Source::MediaRule;
1201 break;
1202 case MediaListSourceImportRule:
1203 source = TypeBuilder::CSS::CSSMedia::Source::ImportRule;
1204 break;
1205 case MediaListSourceLinkedSheet:
1206 source = TypeBuilder::CSS::CSSMedia::Source::LinkedSheet;
1207 break;
1208 case MediaListSourceInlineSheet:
1209 source = TypeBuilder::CSS::CSSMedia::Source::InlineSheet;
1210 break;
1211 }
1212
1213 RefPtr<TypeBuilder::CSS::CSSMedia> mediaObject = TypeBuilder::CSS::CSSMedia: :create()
1214 .setText(media->mediaText())
1215 .setSource(source);
1216
1217 if (!sourceURL.isEmpty()) {
1218 mediaObject->setSourceURL(sourceURL);
1219 mediaObject->setSourceLine(media->queries()->lastLine());
1220 }
1221 return mediaObject.release();
1222 }
1223
1224 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> > InspectorCSSAgent::b uildMediaListChain(CSSRule* rule)
1225 {
1226 if (!rule)
1227 return 0;
1228 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> > mediaArray = TypeBui lder::Array<TypeBuilder::CSS::CSSMedia>::create();
1229 bool hasItems = false;
1230 MediaList* mediaList;
1231 CSSRule* parentRule = rule;
1232 String sourceURL;
1233 while (parentRule) {
1234 CSSStyleSheet* parentStyleSheet = 0;
1235 bool isMediaRule = true;
1236 if (parentRule->type() == CSSRule::MEDIA_RULE) {
1237 CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(parentRule);
1238 mediaList = mediaRule->media();
1239 parentStyleSheet = mediaRule->parentStyleSheet();
1240 } else if (parentRule->type() == CSSRule::IMPORT_RULE) {
1241 CSSImportRule* importRule = static_cast<CSSImportRule*>(parentRule);
1242 mediaList = importRule->media();
1243 parentStyleSheet = importRule->parentStyleSheet();
1244 isMediaRule = false;
1245 } else {
1246 mediaList = 0;
1247 }
1248
1249 if (parentStyleSheet) {
1250 sourceURL = parentStyleSheet->contents()->baseURL();
1251 if (sourceURL.isEmpty())
1252 sourceURL = InspectorDOMAgent::documentURLString(parentStyleShee t->ownerDocument());
1253 } else {
1254 sourceURL = "";
1255 }
1256
1257 if (mediaList && mediaList->length()) {
1258 mediaArray->addItem(buildMediaObject(mediaList, isMediaRule ? MediaL istSourceMediaRule : MediaListSourceImportRule, sourceURL));
1259 hasItems = true;
1260 }
1261
1262 if (parentRule->parentRule()) {
1263 parentRule = parentRule->parentRule();
1264 } else {
1265 CSSStyleSheet* styleSheet = parentRule->parentStyleSheet();
1266 while (styleSheet) {
1267 mediaList = styleSheet->media();
1268 if (mediaList && mediaList->length()) {
1269 Document* doc = styleSheet->ownerDocument();
1270 if (doc)
1271 sourceURL = doc->url();
1272 else if (!styleSheet->contents()->baseURL().isEmpty())
1273 sourceURL = styleSheet->contents()->baseURL();
1274 else
1275 sourceURL = "";
1276 mediaArray->addItem(buildMediaObject(mediaList, styleSheet-> ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL ));
1277 hasItems = true;
1278 }
1279 parentRule = styleSheet->ownerRule();
1280 if (parentRule)
1281 break;
1282 styleSheet = styleSheet->parentStyleSheet();
1283 }
1284 }
1285 }
1286 return hasItems ? mediaArray : 0;
1287 }
1288
1178 void InspectorCSSAgent::startSelectorProfiler(ErrorString*) 1289 void InspectorCSSAgent::startSelectorProfiler(ErrorString*)
1179 { 1290 {
1180 m_currentSelectorProfile = adoptPtr(new SelectorProfile()); 1291 m_currentSelectorProfile = adoptPtr(new SelectorProfile());
1181 m_state->setBoolean(CSSAgentState::isSelectorProfiling, true); 1292 m_state->setBoolean(CSSAgentState::isSelectorProfiling, true);
1182 } 1293 }
1183 1294
1184 void InspectorCSSAgent::stopSelectorProfiler(ErrorString* errorString, RefPtr<Ty peBuilder::CSS::SelectorProfile>& result) 1295 void InspectorCSSAgent::stopSelectorProfiler(ErrorString* errorString, RefPtr<Ty peBuilder::CSS::SelectorProfile>& result)
1185 { 1296 {
1186 result = stopSelectorProfilerImpl(errorString, true); 1297 result = stopSelectorProfilerImpl(errorString, true);
1187 } 1298 }
1188 1299
1189 PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro filerImpl(ErrorString*, bool needProfile) 1300 PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro filerImpl(ErrorString*, bool needProfile)
1190 { 1301 {
1191 if (!m_state->getBoolean(CSSAgentState::isSelectorProfiling)) 1302 if (!m_state->getBoolean(CSSAgentState::isSelectorProfiling))
1192 return 0; 1303 return 0;
1193 m_state->setBoolean(CSSAgentState::isSelectorProfiling, false); 1304 m_state->setBoolean(CSSAgentState::isSelectorProfiling, false);
1194 RefPtr<TypeBuilder::CSS::SelectorProfile> result; 1305 RefPtr<TypeBuilder::CSS::SelectorProfile> result;
1195 if (m_frontend && needProfile) 1306 if (m_frontend && needProfile)
1196 result = m_currentSelectorProfile->toInspectorObject(); 1307 result = m_currentSelectorProfile->toInspectorObject();
1197 m_currentSelectorProfile.clear(); 1308 m_currentSelectorProfile.clear();
1198 return result.release(); 1309 return result.release();
1199 } 1310 }
1200 1311
1201 void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& i nspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection) 1312 void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& i nspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection)
1202 { 1313 {
1203 // printf("InspectorCSSAgent::willMatchRule %s\n", rule->selectorList().selec torsText().utf8().data());
1204 if (m_currentSelectorProfile) 1314 if (m_currentSelectorProfile)
1205 m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrappe rForRuleInSheets(rule, styleSheetCollection)); 1315 m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrappe rForRuleInSheets(rule, styleSheetCollection));
1206 } 1316 }
1207 1317
1208 void InspectorCSSAgent::didMatchRule(bool matched) 1318 void InspectorCSSAgent::didMatchRule(bool matched)
1209 { 1319 {
1210 if (m_currentSelectorProfile) 1320 if (m_currentSelectorProfile)
1211 m_currentSelectorProfile->commitSelector(matched); 1321 m_currentSelectorProfile->commitSelector(matched);
1212 } 1322 }
1213 1323
(...skipping 11 matching lines...) Expand all
1225 1335
1226 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element) 1336 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element)
1227 { 1337 {
1228 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); 1338 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement);
1229 if (it == m_nodeToInspectorStyleSheet.end()) { 1339 if (it == m_nodeToInspectorStyleSheet.end()) {
1230 CSSStyleDeclaration* style = element->isStyledElement() ? element->style () : 0; 1340 CSSStyleDeclaration* style = element->isStyledElement() ? element->style () : 0;
1231 if (!style) 1341 if (!style)
1232 return 0; 1342 return 0;
1233 1343
1234 String newStyleSheetId = String::number(m_lastStyleSheetId++); 1344 String newStyleSheetId = String::number(m_lastStyleSheetId++);
1235 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = Inspecto rStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, elem ent, TypeBuilder::CSS::StyleSheetOrigin::Regular, this); 1345 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = Inspecto rStyleSheetForInlineStyle::create(m_pageAgent, newStyleSheetId, element, TypeBui lder::CSS::StyleSheetOrigin::Regular, this);
1236 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); 1346 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet);
1237 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); 1347 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
1238 return inspectorStyleSheet.get(); 1348 return inspectorStyleSheet.get();
1239 } 1349 }
1240 1350
1241 return it->value.get(); 1351 return it->value.get();
1242 } 1352 }
1243 1353
1244 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) 1354 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId)
1245 { 1355 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 } 1400 }
1291 } 1401 }
1292 } 1402 }
1293 1403
1294 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet ) 1404 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet )
1295 { 1405 {
1296 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector StyleSheet.get(styleSheet); 1406 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector StyleSheet.get(styleSheet);
1297 if (!inspectorStyleSheet) { 1407 if (!inspectorStyleSheet) {
1298 String id = String::number(m_lastStyleSheetId++); 1408 String id = String::number(m_lastStyleSheetId++);
1299 Document* document = styleSheet->ownerDocument(); 1409 Document* document = styleSheet->ownerDocument();
1300 inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent( ), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::docume ntURLString(document), this); 1410 inspectorStyleSheet = InspectorStyleSheet::create(m_pageAgent, id, style Sheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString( document), this);
1301 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); 1411 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
1302 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet ); 1412 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet );
1303 if (m_creatingViaInspectorStyleSheet) 1413 if (m_creatingViaInspectorStyleSheet)
1304 m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet); 1414 m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet);
1305 } 1415 }
1306 return inspectorStyleSheet.get(); 1416 return inspectorStyleSheet.get();
1307 } 1417 }
1308 1418
1309 String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSh eet) 1419 String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSh eet)
1310 { 1420 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 return 0; 1500 return 0;
1391 1501
1392 // CSSRules returned by StyleResolver::styleRulesForElement lack parent poin ters since that infomation is not cheaply available. 1502 // CSSRules returned by StyleResolver::styleRulesForElement lack parent poin ters since that infomation is not cheaply available.
1393 // Since the inspector wants to walk the parent chain, we construct the full wrappers here. 1503 // Since the inspector wants to walk the parent chain, we construct the full wrappers here.
1394 // FIXME: This could be factored better. StyleResolver::styleRulesForElement should return a StyleRule vector, not a CSSRuleList. 1504 // FIXME: This could be factored better. StyleResolver::styleRulesForElement should return a StyleRule vector, not a CSSRuleList.
1395 if (!rule->parentStyleSheet()) { 1505 if (!rule->parentStyleSheet()) {
1396 rule = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets (rule->styleRule(), styleResolver->document()->styleSheetCollection()); 1506 rule = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets (rule->styleRule(), styleResolver->document()->styleSheetCollection());
1397 if (!rule) 1507 if (!rule)
1398 return 0; 1508 return 0;
1399 } 1509 }
1400 return bindStyleSheet(rule->parentStyleSheet())->buildObjectForRule(rule); 1510 return bindStyleSheet(rule->parentStyleSheet())->buildObjectForRule(rule, bu ildMediaListChain(rule));
1401 } 1511 }
1402 1512
1403 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::bu ildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver) 1513 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::bu ildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver)
1404 { 1514 {
1405 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder: :Array<TypeBuilder::CSS::CSSRule>::create(); 1515 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder: :Array<TypeBuilder::CSS::CSSRule>::create();
1406 if (!ruleList) 1516 if (!ruleList)
1407 return result.release(); 1517 return result.release();
1408 1518
1409 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { 1519 RefPtr<CSSRuleList> refRuleList = ruleList;
1410 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); 1520 CSSStyleRuleVector rules;
1411 RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule, styleResolver); 1521 InspectorStyleSheet::collectFlatRules(refRuleList, &rules);
1412 if (!ruleObject) 1522
1413 continue; 1523 for (unsigned i = 0, size = rules.size(); i < size; ++i)
1414 result->addItem(ruleObject); 1524 result->addItem(buildObjectForRule(rules.at(i).get(), styleResolver));
1415 } 1525
1416 return result.release(); 1526 return result.release();
1417 } 1527 }
1418 1528
1419 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver , Element* element) 1529 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent:: buildArrayForMatchedRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver , Element* element)
1420 { 1530 {
1421 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create(); 1531 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilde r::Array<TypeBuilder::CSS::RuleMatch>::create();
1422 if (!ruleList) 1532 if (!ruleList)
1423 return result.release(); 1533 return result.release();
1424 1534
1425 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { 1535 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 documentsToChange.add(element->ownerDocument()); 1677 documentsToChange.add(element->ownerDocument());
1568 } 1678 }
1569 1679
1570 m_nodeIdToForcedPseudoState.clear(); 1680 m_nodeIdToForcedPseudoState.clear();
1571 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1681 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1572 (*it)->styleResolverChanged(RecalcStyleImmediately); 1682 (*it)->styleResolverChanged(RecalcStyleImmediately);
1573 } 1683 }
1574 1684
1575 } // namespace WebCore 1685 } // namespace WebCore
1576 1686
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorStyleSheet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698