Index: Source/core/inspector/InspectorStyleSheet.cpp |
diff --git a/Source/core/inspector/InspectorStyleSheet.cpp b/Source/core/inspector/InspectorStyleSheet.cpp |
index d03a828e158d1b137a078635ecc7ca552b14debf..c01e71fcbfbaf679f351388c21d1d41dadb055e8 100644 |
--- a/Source/core/inspector/InspectorStyleSheet.cpp |
+++ b/Source/core/inspector/InspectorStyleSheet.cpp |
@@ -453,36 +453,6 @@ static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So |
return result.release(); |
} |
-static PassRefPtr<TypeBuilder::CSS::CSSMedia> 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(); |
-} |
- |
static PassRefPtr<CSSRuleList> asCSSRuleList(CSSStyleSheet* styleSheet) |
{ |
if (!styleSheet) |
@@ -519,61 +489,6 @@ static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule) |
return 0; |
} |
-static void fillMediaListChain(CSSRule* rule, 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(); |
- } |
- } |
- } |
-} |
- |
PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet) |
{ |
return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); |
@@ -1038,6 +953,25 @@ String InspectorStyleSheet::styleSheetURL(CSSStyleSheet* pageStyleSheet) |
return emptyString(); |
} |
+// static |
+void InspectorStyleSheet::collectFlatRules(PassRefPtr<CSSRuleList> ruleList, CSSStyleRuleVector* result) |
+{ |
+ if (!ruleList) |
+ return; |
+ |
+ for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
+ CSSRule* rule = ruleList->item(i); |
+ CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule); |
+ if (styleRule) { |
+ result->append(styleRule); |
+ } else { |
+ RefPtr<CSSRuleList> childRuleList = asCSSRuleList(rule); |
+ if (childRuleList) |
+ collectFlatRules(childRuleList, result); |
+ } |
+ } |
+} |
+ |
InspectorStyleSheet::InspectorStyleSheet(InspectorPageAgent* pageAgent, const String& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, Listener* listener) |
: m_pageAgent(pageAgent) |
, m_id(id) |
@@ -1231,24 +1165,19 @@ CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const |
} |
-PassRefPtr<TypeBuilder::CSS::CSSStyleSheetBody> InspectorStyleSheet::buildObjectForStyleSheet() |
+bool InspectorStyleSheet::fillObjectForStyleSheet(PassRefPtr<TypeBuilder::CSS::CSSStyleSheetBody> prpResult) |
{ |
CSSStyleSheet* styleSheet = pageStyleSheet(); |
if (!styleSheet) |
- return 0; |
- |
- RefPtr<CSSRuleList> cssRuleList = asCSSRuleList(styleSheet); |
+ return false; |
- RefPtr<TypeBuilder::CSS::CSSStyleSheetBody> result = TypeBuilder::CSS::CSSStyleSheetBody::create() |
- .setStyleSheetId(id()) |
- .setRules(buildArrayForRuleList(cssRuleList.get())); |
+ RefPtr<TypeBuilder::CSS::CSSStyleSheetBody> result = prpResult; |
String styleSheetText; |
bool success = getText(&styleSheetText); |
if (success) |
result->setText(styleSheetText); |
- |
- return result.release(); |
+ return success; |
} |
PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObjectForStyleSheetInfo() const |
@@ -1327,7 +1256,7 @@ PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe |
return result.release(); |
} |
-PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRule(CSSStyleRule* rule) |
+PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRule(CSSStyleRule* rule, PassRefPtr<Array<TypeBuilder::CSS::CSSMedia> > mediaStack) |
{ |
CSSStyleSheet* styleSheet = pageStyleSheet(); |
if (!styleSheet) |
@@ -1350,9 +1279,8 @@ PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRule(CS |
RefPtr<Array<TypeBuilder::CSS::CSSMedia> > mediaArray = Array<TypeBuilder::CSS::CSSMedia>::create(); |
- fillMediaListChain(rule, mediaArray.get()); |
- if (mediaArray->length()) |
- result->setMedia(mediaArray.release()); |
+ if (mediaStack) |
+ result->setMedia(mediaStack); |
return result.release(); |
} |
@@ -1742,40 +1670,6 @@ bool InspectorStyleSheet::inlineStyleSheetText(String* result) const |
return true; |
} |
-PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorStyleSheet::buildArrayForRuleList(CSSRuleList* ruleList) |
-{ |
- RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder::Array<TypeBuilder::CSS::CSSRule>::create(); |
- if (!ruleList) |
- return result.release(); |
- |
- RefPtr<CSSRuleList> refRuleList = ruleList; |
- CSSStyleRuleVector rules; |
- collectFlatRules(refRuleList, &rules); |
- |
- for (unsigned i = 0, size = rules.size(); i < size; ++i) |
- result->addItem(buildObjectForRule(rules.at(i).get())); |
- |
- return result.release(); |
-} |
- |
-void InspectorStyleSheet::collectFlatRules(PassRefPtr<CSSRuleList> ruleList, CSSStyleRuleVector* result) |
-{ |
- if (!ruleList) |
- return; |
- |
- for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
- CSSRule* rule = ruleList->item(i); |
- CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule); |
- if (styleRule) |
- result->append(styleRule); |
- else { |
- RefPtr<CSSRuleList> childRuleList = asCSSRuleList(rule); |
- if (childRuleList) |
- collectFlatRules(childRuleList, result); |
- } |
- } |
-} |
- |
PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle::create(InspectorPageAgent* pageAgent, const String& id, PassRefPtr<Element> element, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, Listener* listener) |
{ |
return adoptRef(new InspectorStyleSheetForInlineStyle(pageAgent, id, element, origin, listener)); |