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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/inspector/InspectorOverlayPage.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/inspector/LayoutEditor.h" 6 #include "core/inspector/LayoutEditor.h"
7 7
8 #include "core/css/CSSComputedStyleDeclaration.h" 8 #include "core/css/CSSComputedStyleDeclaration.h"
9 #include "core/css/CSSImportRule.h"
10 #include "core/css/CSSMediaRule.h"
9 #include "core/css/CSSRuleList.h" 11 #include "core/css/CSSRuleList.h"
12 #include "core/css/MediaList.h"
10 #include "core/dom/NodeComputedStyle.h" 13 #include "core/dom/NodeComputedStyle.h"
11 #include "core/dom/StaticNodeList.h" 14 #include "core/dom/StaticNodeList.h"
12 #include "core/frame/FrameView.h" 15 #include "core/frame/FrameView.h"
13 #include "core/inspector/InspectorCSSAgent.h" 16 #include "core/inspector/InspectorCSSAgent.h"
14 #include "core/inspector/InspectorDOMAgent.h" 17 #include "core/inspector/InspectorDOMAgent.h"
15 #include "core/inspector/InspectorHighlight.h" 18 #include "core/inspector/InspectorHighlight.h"
16 #include "core/layout/LayoutBox.h" 19 #include "core/layout/LayoutBox.h"
17 #include "core/layout/LayoutInline.h" 20 #include "core/layout/LayoutInline.h"
18 #include "core/layout/LayoutObject.h" 21 #include "core/layout/LayoutObject.h"
19 #include "core/style/ComputedStyle.h" 22 #include "core/style/ComputedStyle.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 InspectorHighlightConfig affectedNodesHighlightConfig() 153 InspectorHighlightConfig affectedNodesHighlightConfig()
151 { 154 {
152 // TODO: find a better color 155 // TODO: find a better color
153 InspectorHighlightConfig config; 156 InspectorHighlightConfig config;
154 config.content = Color(95, 127, 162, 100); 157 config.content = Color(95, 127, 162, 100);
155 config.padding = Color(95, 127, 162, 100); 158 config.padding = Color(95, 127, 162, 100);
156 config.margin = Color(95, 127, 162, 100); 159 config.margin = Color(95, 127, 162, 100);
157 return config; 160 return config;
158 } 161 }
159 162
163 void collectMediaQueriesFromRule(CSSRule* rule, Vector<String>& mediaArray)
164 {
165 MediaList* mediaList;
166 if (rule->type() == CSSRule::MEDIA_RULE) {
167 CSSMediaRule* mediaRule = toCSSMediaRule(rule);
168 mediaList = mediaRule->media();
169 } else if (rule->type() == CSSRule::IMPORT_RULE) {
170 CSSImportRule* importRule = toCSSImportRule(rule);
171 mediaList = importRule->media();
172 } else {
173 mediaList = nullptr;
174 }
175
176 if (mediaList && mediaList->length())
177 mediaArray.append(mediaList->mediaText());
178 }
179
180 void buildMediaListChain(CSSRule* rule, Vector<String>& mediaArray)
181 {
182 while (rule) {
183 collectMediaQueriesFromRule(rule, mediaArray);
184 if (rule->parentRule()) {
185 rule = rule->parentRule();
186 } else {
187 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
188 // TODO: should be able to replace cycle by one iteration of it.
189 while (styleSheet) {
190 MediaList* mediaList = styleSheet->media();
191 if (mediaList && mediaList->length())
192 mediaArray.append(mediaList->mediaText());
193
194 rule = styleSheet->ownerRule();
195 if (rule)
196 break;
197 styleSheet = styleSheet->parentStyleSheet();
198 }
199 }
200 }
201 }
202
160 } // namespace 203 } // namespace
161 204
162 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent, InspectorDOMAgent* domAg ent) 205 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent, InspectorDOMAgent* domAg ent)
163 : m_element(nullptr) 206 : m_element(nullptr)
164 , m_cssAgent(cssAgent) 207 , m_cssAgent(cssAgent)
165 , m_domAgent(domAgent) 208 , m_domAgent(domAgent)
166 , m_changingProperty(CSSPropertyInvalid) 209 , m_changingProperty(CSSPropertyInvalid)
167 , m_propertyInitialValue(0) 210 , m_propertyInitialValue(0)
168 , m_isDirty(false) 211 , m_isDirty(false)
212 , m_currentRuleIndex(-1)
169 { 213 {
170 } 214 }
171 215
172 DEFINE_TRACE(LayoutEditor) 216 DEFINE_TRACE(LayoutEditor)
173 { 217 {
174 visitor->trace(m_element); 218 visitor->trace(m_element);
175 visitor->trace(m_cssAgent); 219 visitor->trace(m_cssAgent);
176 visitor->trace(m_domAgent); 220 visitor->trace(m_domAgent);
177 visitor->trace(m_matchedRules); 221 visitor->trace(m_matchedRules);
178 } 222 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return m_cachedSelectorsInfo.get(m_currentRuleIndex); 433 return m_cachedSelectorsInfo.get(m_currentRuleIndex);
390 434
391 RefPtr<JSONObject> object = JSONObject::create(); 435 RefPtr<JSONObject> object = JSONObject::create();
392 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m atchedRules[m_currentRuleIndex]->selectorText(); 436 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m atchedRules[m_currentRuleIndex]->selectorText();
393 object->setString("selector", currentSelectorText); 437 object->setString("selector", currentSelectorText);
394 438
395 Document* ownerDocument = m_element->ownerDocument(); 439 Document* ownerDocument = m_element->ownerDocument();
396 if (!ownerDocument->isActive() || m_currentRuleIndex == -1) 440 if (!ownerDocument->isActive() || m_currentRuleIndex == -1)
397 return object->toJSONString(); 441 return object->toJSONString();
398 442
443 if (m_currentRuleIndex != -1) {
444 bool hasSameSelectors = false;
445 for (size_t i = 0; i < m_matchedRules.size(); i++) {
446 if (i != static_cast<unsigned>(m_currentRuleIndex) && m_matchedRules [i]->selectorText() == currentSelectorText) {
447 hasSameSelectors = true;
448 break;
449 }
450 }
451
452 if (hasSameSelectors) {
453 Vector<String> medias;
454 buildMediaListChain(m_matchedRules[m_currentRuleIndex].get(), medias );
455 RefPtr<JSONArray> mediasJSONArray = JSONArray::create();
456 for (size_t i = 0; i < medias.size(); ++i)
457 mediasJSONArray->pushString(medias[i]);
458
459 object->setArray("medias", mediasJSONArray.release());
460 }
461 }
462
399 TrackExceptionState exceptionState; 463 TrackExceptionState exceptionState;
400 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception State); 464 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception State);
401 465
402 if (!elements || exceptionState.hadException()) 466 if (!elements || exceptionState.hadException())
403 return object->toJSONString(); 467 return object->toJSONString();
404 468
405 RefPtr<JSONArray> highlights = JSONArray::create(); 469 RefPtr<JSONArray> highlights = JSONArray::create();
406 InspectorHighlightConfig config = affectedNodesHighlightConfig(); 470 InspectorHighlightConfig config = affectedNodesHighlightConfig();
407 for (unsigned i = 0; i < elements->length(); ++i) { 471 for (unsigned i = 0; i < elements->length(); ++i) {
408 Element* element = elements->item(i); 472 Element* element = elements->item(i);
409 if (element == m_element) 473 if (element == m_element)
410 continue; 474 continue;
411 475
412 InspectorHighlight highlight(element, config, false); 476 InspectorHighlight highlight(element, config, false);
413 highlights->pushObject(highlight.asJSONObject()); 477 highlights->pushObject(highlight.asJSONObject());
414 } 478 }
415 479
416 object->setArray("nodes", highlights.release()); 480 object->setArray("nodes", highlights.release());
417 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString()); 481 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString());
418 return m_cachedSelectorsInfo.get(m_currentRuleIndex); 482 return m_cachedSelectorsInfo.get(m_currentRuleIndex);
419 } 483 }
420 484
421 } // namespace blink 485 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorOverlayPage.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698