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

Unified Diff: Source/core/inspector/LayoutEditor.cpp

Issue 1308383007: Devtools [LayoutEditor]: Show medias for the rules with the same selectors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@affected2
Patch Set: Rebase Created 5 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: Source/core/inspector/LayoutEditor.cpp
diff --git a/Source/core/inspector/LayoutEditor.cpp b/Source/core/inspector/LayoutEditor.cpp
index baf5c57795fc2d77a71f6e1db6670ccf00ba1492..25436dfb84399b523879286ca3d570fd0ad49501 100644
--- a/Source/core/inspector/LayoutEditor.cpp
+++ b/Source/core/inspector/LayoutEditor.cpp
@@ -6,7 +6,10 @@
#include "core/inspector/LayoutEditor.h"
#include "core/css/CSSComputedStyleDeclaration.h"
+#include "core/css/CSSImportRule.h"
+#include "core/css/CSSMediaRule.h"
#include "core/css/CSSRuleList.h"
+#include "core/css/MediaList.h"
#include "core/dom/NodeComputedStyle.h"
#include "core/dom/StaticNodeList.h"
#include "core/frame/FrameView.h"
@@ -396,6 +399,21 @@ String LayoutEditor::currentSelectorInfo()
if (!ownerDocument->isActive() || m_currentRuleIndex == -1)
return object->toJSONString();
+ if (m_currentRuleIndex != -1) {
+ bool hasSameSelectors = false;
+ for (size_t i = 0; i < m_matchedRules.size(); i++)
+ hasSameSelectors |= i != static_cast<unsigned>(m_currentRuleIndex) && m_matchedRules[i]->selectorText() == currentSelectorText;
dgozman 2015/09/02 22:06:26 if (i != ....) ...
sergeyv 2015/09/02 23:58:34 Done.
+
+ if (hasSameSelectors) {
+ OwnPtr<Vector<String>> medias = buildMediaListChain(m_matchedRules[m_currentRuleIndex].get());
+ RefPtr<JSONArray> mediasJSONArray = JSONArray::create();
+ for (size_t i = 0; i < medias->size(); ++i)
+ mediasJSONArray->pushString(medias->at(i));
+
+ object->setArray("medias", mediasJSONArray.release());
+ }
+ }
+
TrackExceptionState exceptionState;
RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelectorAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exceptionState);
@@ -418,4 +436,48 @@ String LayoutEditor::currentSelectorInfo()
return m_cachedSelectorsInfo.get(m_currentRuleIndex);
}
+void LayoutEditor::collectMediaQueriesFromRule(CSSRule* rule, Vector<String>& mediaArray)
+{
+ MediaList* mediaList;
+ if (rule->type() == CSSRule::MEDIA_RULE) {
+ CSSMediaRule* mediaRule = toCSSMediaRule(rule);
+ mediaList = mediaRule->media();
+ } else if (rule->type() == CSSRule::IMPORT_RULE) {
+ CSSImportRule* importRule = toCSSImportRule(rule);
+ mediaList = importRule->media();
+ } else {
+ mediaList = nullptr;
+ }
+
+ if (mediaList && mediaList->length())
+ mediaArray.append(mediaList->mediaText());
+}
+
+PassOwnPtr<Vector<String>> LayoutEditor::buildMediaListChain(CSSRule* rule)
dgozman 2015/09/02 22:06:25 Move to namespace.
dgozman 2015/09/02 22:06:26 Let's follow the pattern of (..., Vector<String>&)
sergeyv 2015/09/02 23:58:34 Done.
sergeyv 2015/09/02 23:58:34 Done.
+{
+ if (!rule)
+ return nullptr;
+ CSSRule* parentRule = rule;
+ OwnPtr<Vector<String>> result = adoptPtr(new Vector<String>());
+ while (parentRule) {
dgozman 2015/09/02 22:06:25 s/parentRule/rule
sergeyv 2015/09/02 23:58:34 Done.
+ collectMediaQueriesFromRule(parentRule, *result.get());
+ if (parentRule->parentRule()) {
+ parentRule = parentRule->parentRule();
+ } else {
+ CSSStyleSheet* styleSheet = parentRule->parentStyleSheet();
+ while (styleSheet) {
dgozman 2015/09/02 22:06:25 TODO: should be able to replace cycle by one itera
sergeyv 2015/09/02 23:58:34 Done.
+ MediaList* mediaList = styleSheet->media();
+ if (mediaList && mediaList->length())
+ result->append(mediaList->mediaText());
+
+ parentRule = styleSheet->ownerRule();
+ if (parentRule)
+ break;
+ styleSheet = styleSheet->parentStyleSheet();
+ }
+ }
+ }
+ return result.release();
+}
+
} // namespace blink
« Source/core/inspector/InspectorOverlayPage.html ('K') | « Source/core/inspector/LayoutEditor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698