Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| index aace205763cc28cdefe344a4182cb32dc263dff9..ac2d066a09b80309efb188da51aef768362c411e 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| @@ -1319,6 +1319,23 @@ bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e |
| return true; |
| } |
| +std::unique_ptr<protocol::Array<String>> InspectorStyleSheet::collectClassNames() |
| +{ |
| + HashSet<String> uniqueNames; |
| + std::unique_ptr<protocol::Array<String>> result = protocol::Array<String>::create(); |
| + CSSRuleVector flatRules; |
| + |
| + collectFlatRules(m_pageStyleSheet.get(), &flatRules); |
| + |
| + for (size_t i = 0; i < flatRules.size(); ++i) { |
| + if (flatRules.at(i)->type() == CSSRule::kStyleRule) |
| + getClassNameFromRule(toCSSStyleRule(flatRules.at(i)), uniqueNames); |
| + } |
| + for (const String& className : uniqueNames) |
| + result->addItem(className); |
| + return result; |
| +} |
| + |
| void InspectorStyleSheet::replaceText(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText) |
| { |
| String sheetText = m_text; |
| @@ -1510,6 +1527,23 @@ std::unique_ptr<protocol::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpVa |
| return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex).valueRange); |
| } |
| +void InspectorStyleSheet::getClassNameFromRule(CSSStyleRule* rule, HashSet<String>& uniqueNames) |
| +{ |
| + const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| + if (!selectorList.isValid()) |
| + return; |
| + const CSSSelector* subSelector = selectorList.first(); |
|
lushnikov
2016/09/06 17:51:38
no need to extract from for-loop
ahmetemirercin
2016/09/07 00:02:28
Done.
|
| + for (; subSelector; subSelector = CSSSelectorList::next(*subSelector)) { |
| + const CSSSelector* simpleSelector = subSelector; |
| + while (simpleSelector) { |
| + if (simpleSelector->match() == CSSSelector::Class) { |
|
lushnikov
2016/09/06 17:51:38
nit: drop {}
ahmetemirercin
2016/09/07 00:02:28
Done.
|
| + uniqueNames.add(simpleSelector->value()); |
| + } |
| + simpleSelector = simpleSelector->tagHistory(); |
| + } |
| + } |
| +} |
| + |
| InspectorStyle* InspectorStyleSheet::inspectorStyle(CSSStyleDeclaration* style) |
| { |
| return style ? InspectorStyle::create(style, sourceDataForRule(style->parentRule()), this) : nullptr; |