Index: Source/core/inspector/InspectorCSSAgent.cpp |
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp |
index abd9e0bc195420327f3e142ffd68fc08797f2bbe..cc23e3fd396be9f542d54a30abcc3498c984f8c7 100644 |
--- a/Source/core/inspector/InspectorCSSAgent.cpp |
+++ b/Source/core/inspector/InspectorCSSAgent.cpp |
@@ -29,15 +29,19 @@ |
#include "InspectorTypeBuilder.h" |
#include "core/css/CSSComputedStyleDeclaration.h" |
#include "core/css/CSSImportRule.h" |
+#include "core/css/CSSMediaRule.h" |
#include "core/css/CSSParser.h" |
+#include "core/css/CSSPropertySourceData.h" |
#include "core/css/CSSRule.h" |
#include "core/css/CSSRuleList.h" |
#include "core/css/CSSStyleRule.h" |
#include "core/css/CSSStyleSheet.h" |
+#include "core/css/MediaList.h" |
#include "core/css/StylePropertySet.h" |
#include "core/css/StylePropertyShorthand.h" |
#include "core/css/StyleRule.h" |
#include "core/css/StyleSheet.h" |
+#include "core/css/StyleSheetContents.h" |
#include "core/css/StyleSheetList.h" |
#include "core/css/resolver/StyleResolver.h" |
#include "core/dom/ExceptionCodePlaceholder.h" |
@@ -1175,6 +1179,93 @@ void InspectorCSSAgent::getNamedFlowCollection(ErrorString* errorString, int doc |
result = namedFlows.release(); |
} |
+PassRefPtr<TypeBuilder::CSS::CSSMedia> InspectorCSSAgent::buildMediaObject(const MediaList* media, MediaListSource mediaListSource, const String& sourceURL) |
+{ |
+ // Make certain compilers happy by initializing |source| up-front. |
+ TypeBuilder::CSS::CSSMedia::Source::Enum source = TypeBuilder::CSS::CSSMedia::Source::InlineSheet; |
+ switch (mediaListSource) { |
+ case MediaListSourceMediaRule: |
+ source = TypeBuilder::CSS::CSSMedia::Source::MediaRule; |
+ break; |
+ case MediaListSourceImportRule: |
+ source = TypeBuilder::CSS::CSSMedia::Source::ImportRule; |
+ break; |
+ case MediaListSourceLinkedSheet: |
+ source = TypeBuilder::CSS::CSSMedia::Source::LinkedSheet; |
+ break; |
+ case MediaListSourceInlineSheet: |
+ source = TypeBuilder::CSS::CSSMedia::Source::InlineSheet; |
+ break; |
+ } |
+ |
+ RefPtr<TypeBuilder::CSS::CSSMedia> mediaObject = TypeBuilder::CSS::CSSMedia::create() |
+ .setText(media->mediaText()) |
+ .setSource(source); |
+ |
+ if (!sourceURL.isEmpty()) { |
+ mediaObject->setSourceURL(sourceURL); |
+ mediaObject->setSourceLine(media->queries()->lastLine()); |
+ } |
+ return mediaObject.release(); |
+} |
+ |
+void InspectorCSSAgent::fillMediaListChain(CSSRule* rule, TypeBuilder::Array<TypeBuilder::CSS::CSSMedia>* mediaArray) |
+{ |
+ MediaList* mediaList; |
+ CSSRule* parentRule = rule; |
+ String sourceURL; |
+ while (parentRule) { |
+ CSSStyleSheet* parentStyleSheet = 0; |
+ bool isMediaRule = true; |
+ if (parentRule->type() == CSSRule::MEDIA_RULE) { |
+ CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(parentRule); |
+ mediaList = mediaRule->media(); |
+ parentStyleSheet = mediaRule->parentStyleSheet(); |
+ } else if (parentRule->type() == CSSRule::IMPORT_RULE) { |
+ CSSImportRule* importRule = static_cast<CSSImportRule*>(parentRule); |
+ mediaList = importRule->media(); |
+ parentStyleSheet = importRule->parentStyleSheet(); |
+ isMediaRule = false; |
+ } else { |
+ mediaList = 0; |
+ } |
+ |
+ if (parentStyleSheet) { |
+ sourceURL = parentStyleSheet->contents()->baseURL(); |
+ if (sourceURL.isEmpty()) |
+ sourceURL = InspectorDOMAgent::documentURLString(parentStyleSheet->ownerDocument()); |
+ } else { |
+ sourceURL = ""; |
+ } |
+ |
+ if (mediaList && mediaList->length()) |
+ mediaArray->addItem(buildMediaObject(mediaList, isMediaRule ? MediaListSourceMediaRule : MediaListSourceImportRule, sourceURL)); |
+ |
+ if (parentRule->parentRule()) { |
+ parentRule = parentRule->parentRule(); |
+ } else { |
+ CSSStyleSheet* styleSheet = parentRule->parentStyleSheet(); |
+ while (styleSheet) { |
+ mediaList = styleSheet->media(); |
+ if (mediaList && mediaList->length()) { |
+ Document* doc = styleSheet->ownerDocument(); |
+ if (doc) |
+ sourceURL = doc->url(); |
+ else if (!styleSheet->contents()->baseURL().isEmpty()) |
+ sourceURL = styleSheet->contents()->baseURL(); |
+ else |
+ sourceURL = ""; |
+ mediaArray->addItem(buildMediaObject(mediaList, styleSheet->ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL)); |
+ } |
+ parentRule = styleSheet->ownerRule(); |
+ if (parentRule) |
+ break; |
+ styleSheet = styleSheet->parentStyleSheet(); |
+ } |
+ } |
+ } |
+} |
+ |
void InspectorCSSAgent::startSelectorProfiler(ErrorString*) |
{ |
m_currentSelectorProfile = adoptPtr(new SelectorProfile()); |
@@ -1200,7 +1291,6 @@ PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro |
void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection) |
{ |
-// printf("InspectorCSSAgent::willMatchRule %s\n", rule->selectorList().selectorsText().utf8().data()); |
if (m_currentSelectorProfile) |
m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrapperForRuleInSheets(rule, styleSheetCollection)); |
} |
@@ -1232,7 +1322,7 @@ InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Elem |
return 0; |
String newStyleSheetId = String::number(m_lastStyleSheetId++); |
- RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, element, TypeBuilder::CSS::StyleSheetOrigin::Regular, this); |
yurys
2013/06/13 13:52:05
I think we should try to get rid of InspectorStyle
|
+ RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(this, newStyleSheetId, element, TypeBuilder::CSS::StyleSheetOrigin::Regular, this); |
m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); |
m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); |
return inspectorStyleSheet.get(); |
@@ -1297,7 +1387,7 @@ InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet |
if (!inspectorStyleSheet) { |
String id = String::number(m_lastStyleSheetId++); |
Document* document = styleSheet->ownerDocument(); |
- inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document), this); |
+ inspectorStyleSheet = InspectorStyleSheet::create(this, id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document), this); |
m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); |
m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet); |
if (m_creatingViaInspectorStyleSheet) |