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..7d2abfae6fe96c9e5ec90ea1c07725d2f81c3e7b 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| @@ -133,6 +133,22 @@ String findMagicComment(const String& content, const String& name) |
| return match; |
| } |
| +void getClassNamesFromRule(CSSStyleRule* rule, HashSet<String>& uniqueNames) |
| +{ |
| + const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| + if (!selectorList.isValid()) |
| + return; |
| + |
| + for (const CSSSelector* subSelector = selectorList.first(); subSelector; subSelector = CSSSelectorList::next(*subSelector)) { |
| + const CSSSelector* simpleSelector = subSelector; |
| + while (simpleSelector) { |
| + if (simpleSelector->match() == CSSSelector::Class) |
| + uniqueNames.add(simpleSelector->value()); |
| + simpleSelector = simpleSelector->tagHistory(); |
| + } |
| + } |
| +} |
| + |
| class StyleSheetHandler final : public CSSParserObserver { |
| public: |
| StyleSheetHandler(const String& parsedText, Document* document, RuleSourceDataList* result) |
| @@ -1319,6 +1335,20 @@ 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(); |
| + |
| + for (size_t i = 0; i < m_parsedFlatRules.size(); ++i) { |
|
lushnikov
2016/09/09 18:21:35
oh, m_parsedFlatRules, nice! I had a memory of the
|
| + if (m_parsedFlatRules.at(i)->type() == CSSRule::kStyleRule) |
| + getClassNamesFromRule(toCSSStyleRule(m_parsedFlatRules.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; |