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 11 matching lines...) Expand all Loading... | |
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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1168 | 1172 |
1169 Vector<RefPtr<NamedFlow> > namedFlowsVector = document->namedFlows()->namedF lows(); | 1173 Vector<RefPtr<NamedFlow> > namedFlowsVector = document->namedFlows()->namedF lows(); |
1170 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> > namedFlows = TypeBu ilder::Array<TypeBuilder::CSS::NamedFlow>::create(); | 1174 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> > namedFlows = TypeBu ilder::Array<TypeBuilder::CSS::NamedFlow>::create(); |
1171 | 1175 |
1172 for (Vector<RefPtr<NamedFlow> >::iterator it = namedFlowsVector.begin(); it != namedFlowsVector.end(); ++it) | 1176 for (Vector<RefPtr<NamedFlow> >::iterator it = namedFlowsVector.begin(); it != namedFlowsVector.end(); ++it) |
1173 namedFlows->addItem(buildObjectForNamedFlow(errorString, it->get(), docu mentNodeId)); | 1177 namedFlows->addItem(buildObjectForNamedFlow(errorString, it->get(), docu mentNodeId)); |
1174 | 1178 |
1175 result = namedFlows.release(); | 1179 result = namedFlows.release(); |
1176 } | 1180 } |
1177 | 1181 |
1182 PassRefPtr<TypeBuilder::CSS::CSSMedia> InspectorCSSAgent::buildMediaObject(const MediaList* media, MediaListSource mediaListSource, const String& sourceURL) | |
1183 { | |
1184 // Make certain compilers happy by initializing |source| up-front. | |
1185 TypeBuilder::CSS::CSSMedia::Source::Enum source = TypeBuilder::CSS::CSSMedia ::Source::InlineSheet; | |
1186 switch (mediaListSource) { | |
1187 case MediaListSourceMediaRule: | |
1188 source = TypeBuilder::CSS::CSSMedia::Source::MediaRule; | |
1189 break; | |
1190 case MediaListSourceImportRule: | |
1191 source = TypeBuilder::CSS::CSSMedia::Source::ImportRule; | |
1192 break; | |
1193 case MediaListSourceLinkedSheet: | |
1194 source = TypeBuilder::CSS::CSSMedia::Source::LinkedSheet; | |
1195 break; | |
1196 case MediaListSourceInlineSheet: | |
1197 source = TypeBuilder::CSS::CSSMedia::Source::InlineSheet; | |
1198 break; | |
1199 } | |
1200 | |
1201 RefPtr<TypeBuilder::CSS::CSSMedia> mediaObject = TypeBuilder::CSS::CSSMedia: :create() | |
1202 .setText(media->mediaText()) | |
1203 .setSource(source); | |
1204 | |
1205 if (!sourceURL.isEmpty()) { | |
1206 mediaObject->setSourceURL(sourceURL); | |
1207 mediaObject->setSourceLine(media->queries()->lastLine()); | |
1208 } | |
1209 return mediaObject.release(); | |
1210 } | |
1211 | |
1212 void InspectorCSSAgent::fillMediaListChain(CSSRule* rule, TypeBuilder::Array<Typ eBuilder::CSS::CSSMedia>* mediaArray) | |
1213 { | |
1214 MediaList* mediaList; | |
1215 CSSRule* parentRule = rule; | |
1216 String sourceURL; | |
1217 while (parentRule) { | |
1218 CSSStyleSheet* parentStyleSheet = 0; | |
1219 bool isMediaRule = true; | |
1220 if (parentRule->type() == CSSRule::MEDIA_RULE) { | |
1221 CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(parentRule); | |
1222 mediaList = mediaRule->media(); | |
1223 parentStyleSheet = mediaRule->parentStyleSheet(); | |
1224 } else if (parentRule->type() == CSSRule::IMPORT_RULE) { | |
1225 CSSImportRule* importRule = static_cast<CSSImportRule*>(parentRule); | |
1226 mediaList = importRule->media(); | |
1227 parentStyleSheet = importRule->parentStyleSheet(); | |
1228 isMediaRule = false; | |
1229 } else { | |
1230 mediaList = 0; | |
1231 } | |
1232 | |
1233 if (parentStyleSheet) { | |
1234 sourceURL = parentStyleSheet->contents()->baseURL(); | |
1235 if (sourceURL.isEmpty()) | |
1236 sourceURL = InspectorDOMAgent::documentURLString(parentStyleShee t->ownerDocument()); | |
1237 } else { | |
1238 sourceURL = ""; | |
1239 } | |
1240 | |
1241 if (mediaList && mediaList->length()) | |
1242 mediaArray->addItem(buildMediaObject(mediaList, isMediaRule ? MediaL istSourceMediaRule : MediaListSourceImportRule, sourceURL)); | |
1243 | |
1244 if (parentRule->parentRule()) { | |
1245 parentRule = parentRule->parentRule(); | |
1246 } else { | |
1247 CSSStyleSheet* styleSheet = parentRule->parentStyleSheet(); | |
1248 while (styleSheet) { | |
1249 mediaList = styleSheet->media(); | |
1250 if (mediaList && mediaList->length()) { | |
1251 Document* doc = styleSheet->ownerDocument(); | |
1252 if (doc) | |
1253 sourceURL = doc->url(); | |
1254 else if (!styleSheet->contents()->baseURL().isEmpty()) | |
1255 sourceURL = styleSheet->contents()->baseURL(); | |
1256 else | |
1257 sourceURL = ""; | |
1258 mediaArray->addItem(buildMediaObject(mediaList, styleSheet-> ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL )); | |
1259 } | |
1260 parentRule = styleSheet->ownerRule(); | |
1261 if (parentRule) | |
1262 break; | |
1263 styleSheet = styleSheet->parentStyleSheet(); | |
1264 } | |
1265 } | |
1266 } | |
1267 } | |
1268 | |
1178 void InspectorCSSAgent::startSelectorProfiler(ErrorString*) | 1269 void InspectorCSSAgent::startSelectorProfiler(ErrorString*) |
1179 { | 1270 { |
1180 m_currentSelectorProfile = adoptPtr(new SelectorProfile()); | 1271 m_currentSelectorProfile = adoptPtr(new SelectorProfile()); |
1181 m_state->setBoolean(CSSAgentState::isSelectorProfiling, true); | 1272 m_state->setBoolean(CSSAgentState::isSelectorProfiling, true); |
1182 } | 1273 } |
1183 | 1274 |
1184 void InspectorCSSAgent::stopSelectorProfiler(ErrorString* errorString, RefPtr<Ty peBuilder::CSS::SelectorProfile>& result) | 1275 void InspectorCSSAgent::stopSelectorProfiler(ErrorString* errorString, RefPtr<Ty peBuilder::CSS::SelectorProfile>& result) |
1185 { | 1276 { |
1186 result = stopSelectorProfilerImpl(errorString, true); | 1277 result = stopSelectorProfilerImpl(errorString, true); |
1187 } | 1278 } |
1188 | 1279 |
1189 PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro filerImpl(ErrorString*, bool needProfile) | 1280 PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro filerImpl(ErrorString*, bool needProfile) |
1190 { | 1281 { |
1191 if (!m_state->getBoolean(CSSAgentState::isSelectorProfiling)) | 1282 if (!m_state->getBoolean(CSSAgentState::isSelectorProfiling)) |
1192 return 0; | 1283 return 0; |
1193 m_state->setBoolean(CSSAgentState::isSelectorProfiling, false); | 1284 m_state->setBoolean(CSSAgentState::isSelectorProfiling, false); |
1194 RefPtr<TypeBuilder::CSS::SelectorProfile> result; | 1285 RefPtr<TypeBuilder::CSS::SelectorProfile> result; |
1195 if (m_frontend && needProfile) | 1286 if (m_frontend && needProfile) |
1196 result = m_currentSelectorProfile->toInspectorObject(); | 1287 result = m_currentSelectorProfile->toInspectorObject(); |
1197 m_currentSelectorProfile.clear(); | 1288 m_currentSelectorProfile.clear(); |
1198 return result.release(); | 1289 return result.release(); |
1199 } | 1290 } |
1200 | 1291 |
1201 void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& i nspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection) | 1292 void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& i nspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection) |
1202 { | 1293 { |
1203 // printf("InspectorCSSAgent::willMatchRule %s\n", rule->selectorList().selec torsText().utf8().data()); | |
1204 if (m_currentSelectorProfile) | 1294 if (m_currentSelectorProfile) |
1205 m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrappe rForRuleInSheets(rule, styleSheetCollection)); | 1295 m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrappe rForRuleInSheets(rule, styleSheetCollection)); |
1206 } | 1296 } |
1207 | 1297 |
1208 void InspectorCSSAgent::didMatchRule(bool matched) | 1298 void InspectorCSSAgent::didMatchRule(bool matched) |
1209 { | 1299 { |
1210 if (m_currentSelectorProfile) | 1300 if (m_currentSelectorProfile) |
1211 m_currentSelectorProfile->commitSelector(matched); | 1301 m_currentSelectorProfile->commitSelector(matched); |
1212 } | 1302 } |
1213 | 1303 |
(...skipping 11 matching lines...) Expand all Loading... | |
1225 | 1315 |
1226 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element) | 1316 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem ent* element) |
1227 { | 1317 { |
1228 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); | 1318 NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(el ement); |
1229 if (it == m_nodeToInspectorStyleSheet.end()) { | 1319 if (it == m_nodeToInspectorStyleSheet.end()) { |
1230 CSSStyleDeclaration* style = element->isStyledElement() ? element->style () : 0; | 1320 CSSStyleDeclaration* style = element->isStyledElement() ? element->style () : 0; |
1231 if (!style) | 1321 if (!style) |
1232 return 0; | 1322 return 0; |
1233 | 1323 |
1234 String newStyleSheetId = String::number(m_lastStyleSheetId++); | 1324 String newStyleSheetId = String::number(m_lastStyleSheetId++); |
1235 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = Inspecto rStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, elem ent, TypeBuilder::CSS::StyleSheetOrigin::Regular, this); | 1325 RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = Inspecto rStyleSheetForInlineStyle::create(this, newStyleSheetId, element, TypeBuilder::C SS::StyleSheetOrigin::Regular, this); |
yurys
2013/06/13 13:52:05
I think we should try to get rid of InspectorStyle
| |
1236 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); | 1326 m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); |
1237 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); | 1327 m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); |
1238 return inspectorStyleSheet.get(); | 1328 return inspectorStyleSheet.get(); |
1239 } | 1329 } |
1240 | 1330 |
1241 return it->value.get(); | 1331 return it->value.get(); |
1242 } | 1332 } |
1243 | 1333 |
1244 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) | 1334 Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) |
1245 { | 1335 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 } | 1380 } |
1291 } | 1381 } |
1292 } | 1382 } |
1293 | 1383 |
1294 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet ) | 1384 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet ) |
1295 { | 1385 { |
1296 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector StyleSheet.get(styleSheet); | 1386 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector StyleSheet.get(styleSheet); |
1297 if (!inspectorStyleSheet) { | 1387 if (!inspectorStyleSheet) { |
1298 String id = String::number(m_lastStyleSheetId++); | 1388 String id = String::number(m_lastStyleSheetId++); |
1299 Document* document = styleSheet->ownerDocument(); | 1389 Document* document = styleSheet->ownerDocument(); |
1300 inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent( ), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::docume ntURLString(document), this); | 1390 inspectorStyleSheet = InspectorStyleSheet::create(this, id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(documen t), this); |
1301 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); | 1391 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); |
1302 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet ); | 1392 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet ); |
1303 if (m_creatingViaInspectorStyleSheet) | 1393 if (m_creatingViaInspectorStyleSheet) |
1304 m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet); | 1394 m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet); |
1305 } | 1395 } |
1306 return inspectorStyleSheet.get(); | 1396 return inspectorStyleSheet.get(); |
1307 } | 1397 } |
1308 | 1398 |
1309 String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSh eet) | 1399 String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSh eet) |
1310 { | 1400 { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1567 documentsToChange.add(element->ownerDocument()); | 1657 documentsToChange.add(element->ownerDocument()); |
1568 } | 1658 } |
1569 | 1659 |
1570 m_nodeIdToForcedPseudoState.clear(); | 1660 m_nodeIdToForcedPseudoState.clear(); |
1571 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) | 1661 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) |
1572 (*it)->styleResolverChanged(RecalcStyleImmediately); | 1662 (*it)->styleResolverChanged(RecalcStyleImmediately); |
1573 } | 1663 } |
1574 | 1664 |
1575 } // namespace WebCore | 1665 } // namespace WebCore |
1576 | 1666 |
OLD | NEW |