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..d78f00a3cc7d386900d38f58024d6020109e268a 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| @@ -1319,6 +1319,32 @@ 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(); |
| + const CSSRuleList* ruleList = pageStyleSheet()->rules(); |
| + for (unsigned i = ruleList ? ruleList->length() : 0; i > 0; --i) { |
|
lushnikov
2016/09/01 20:50:36
Let's reuse collectFlatRules(). It will free you f
ahmetemirercin
2016/09/01 21:47:58
I specially didn't used it since "collectFlatRules
lushnikov
2016/09/01 22:04:24
I see.
Performance-wise, it should not be any mea
ahmetemirercin
2016/09/02 19:59:54
Done.
|
| + CSSRule* rule = ruleList->item(i - 1); |
| + if (rule->type() == CSSRule::kStyleRule) { |
| + getClassNameFromRule(rule, uniqueNames); |
| + } else { |
| + CSSRuleList* cssRuleList = nullptr; |
| + if (rule->type() == CSSRule::kMediaRule) |
| + cssRuleList = toCSSMediaRule(rule)->cssRules(); |
| + else if (rule->type() == CSSRule::kSupportsRule) |
| + cssRuleList = toCSSSupportsRule(rule)->cssRules(); |
| + for (unsigned j = cssRuleList ? cssRuleList->length() : 0; j > 0; --j) { |
| + CSSRule* childRule = cssRuleList->item(j - 1); |
| + getClassNameFromRule(childRule, 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 +1536,23 @@ std::unique_ptr<protocol::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpVa |
| return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex).valueRange); |
| } |
| +void InspectorStyleSheet::getClassNameFromRule(CSSRule* rule, HashSet<String>& uniqueNames) |
|
lushnikov
2016/09/01 20:50:36
let's have CSSStyleRule here
ahmetemirercin
2016/09/02 19:59:54
Done.
|
| +{ |
| + const CSSSelectorList& selectorList = toCSSStyleRule(rule)->styleRule()->selectorList(); |
| + if (!selectorList.isValid()) |
| + return; |
| + const CSSSelector* subSelector = selectorList.first(); |
| + for (; subSelector; subSelector = CSSSelectorList::next(*subSelector)) { |
| + const CSSSelector* simpleSelector = subSelector; |
| + while (simpleSelector) { |
| + if (simpleSelector->match() == CSSSelector::Class) { |
| + uniqueNames.add(simpleSelector->value()); |
| + } |
| + simpleSelector = simpleSelector->tagHistory(); |
| + } |
| + } |
| +} |
| + |
| InspectorStyle* InspectorStyleSheet::inspectorStyle(CSSStyleDeclaration* style) |
| { |
| return style ? InspectorStyle::create(style, sourceDataForRule(style->parentRule()), this) : nullptr; |