Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp

Issue 2296323002: DevTools: Add features to collect classnames from Stylesheets and DOM (Closed)
Patch Set: DevTools: Add features to collect classnames from Stylesheets and DOM Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..dd0b4392c2301dd64147370a36df3095d1becccb 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);
dgozman 2016/09/09 01:57:56 Why don't we use m_parsedFlatRules?
ahmetemirercin 2016/09/09 10:07:55 Done.
+
+ 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,22 @@ std::unique_ptr<protocol::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpVa
return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex).valueRange);
}
+void InspectorStyleSheet::getClassNameFromRule(CSSStyleRule* rule, HashSet<String>& uniqueNames)
dgozman 2016/09/09 01:57:56 This doesn't have to be an instance function, let'
ahmetemirercin 2016/09/09 10:07:55 Done.
+{
+ 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();
+ }
+ }
+}
+
InspectorStyle* InspectorStyleSheet::inspectorStyle(CSSStyleDeclaration* style)
{
return style ? InspectorStyle::create(style, sourceDataForRule(style->parentRule()), this) : nullptr;

Powered by Google App Engine
This is Rietveld 408576698