OLD | NEW |
---|---|
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 return m_cachedSelectorsInfo.get(m_currentRuleIndex); | 392 return m_cachedSelectorsInfo.get(m_currentRuleIndex); |
390 | 393 |
391 RefPtr<JSONObject> object = JSONObject::create(); | 394 RefPtr<JSONObject> object = JSONObject::create(); |
392 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m atchedRules[m_currentRuleIndex]->selectorText(); | 395 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m atchedRules[m_currentRuleIndex]->selectorText(); |
393 object->setString("selector", currentSelectorText); | 396 object->setString("selector", currentSelectorText); |
394 | 397 |
395 Document* ownerDocument = m_element->ownerDocument(); | 398 Document* ownerDocument = m_element->ownerDocument(); |
396 if (!ownerDocument->isActive() || m_currentRuleIndex == -1) | 399 if (!ownerDocument->isActive() || m_currentRuleIndex == -1) |
397 return object->toJSONString(); | 400 return object->toJSONString(); |
398 | 401 |
402 if (m_currentRuleIndex != -1) { | |
403 bool hasSameSelectors = false; | |
404 for (size_t i = 0; i < m_matchedRules.size(); i++) | |
405 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.
| |
406 | |
407 if (hasSameSelectors) { | |
408 OwnPtr<Vector<String>> medias = buildMediaListChain(m_matchedRules[m _currentRuleIndex].get()); | |
409 RefPtr<JSONArray> mediasJSONArray = JSONArray::create(); | |
410 for (size_t i = 0; i < medias->size(); ++i) | |
411 mediasJSONArray->pushString(medias->at(i)); | |
412 | |
413 object->setArray("medias", mediasJSONArray.release()); | |
414 } | |
415 } | |
416 | |
399 TrackExceptionState exceptionState; | 417 TrackExceptionState exceptionState; |
400 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception State); | 418 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception State); |
401 | 419 |
402 if (!elements || exceptionState.hadException()) | 420 if (!elements || exceptionState.hadException()) |
403 return object->toJSONString(); | 421 return object->toJSONString(); |
404 | 422 |
405 RefPtr<JSONArray> highlights = JSONArray::create(); | 423 RefPtr<JSONArray> highlights = JSONArray::create(); |
406 InspectorHighlightConfig config = affectedNodesHighlightConfig(); | 424 InspectorHighlightConfig config = affectedNodesHighlightConfig(); |
407 for (unsigned i = 0; i < elements->length(); ++i) { | 425 for (unsigned i = 0; i < elements->length(); ++i) { |
408 Element* element = elements->item(i); | 426 Element* element = elements->item(i); |
409 if (element == m_element) | 427 if (element == m_element) |
410 continue; | 428 continue; |
411 | 429 |
412 InspectorHighlight highlight(element, config, false); | 430 InspectorHighlight highlight(element, config, false); |
413 highlights->pushObject(highlight.asJSONObject()); | 431 highlights->pushObject(highlight.asJSONObject()); |
414 } | 432 } |
415 | 433 |
416 object->setArray("nodes", highlights.release()); | 434 object->setArray("nodes", highlights.release()); |
417 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString()); | 435 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString()); |
418 return m_cachedSelectorsInfo.get(m_currentRuleIndex); | 436 return m_cachedSelectorsInfo.get(m_currentRuleIndex); |
419 } | 437 } |
420 | 438 |
439 void LayoutEditor::collectMediaQueriesFromRule(CSSRule* rule, Vector<String>& me diaArray) | |
440 { | |
441 MediaList* mediaList; | |
442 if (rule->type() == CSSRule::MEDIA_RULE) { | |
443 CSSMediaRule* mediaRule = toCSSMediaRule(rule); | |
444 mediaList = mediaRule->media(); | |
445 } else if (rule->type() == CSSRule::IMPORT_RULE) { | |
446 CSSImportRule* importRule = toCSSImportRule(rule); | |
447 mediaList = importRule->media(); | |
448 } else { | |
449 mediaList = nullptr; | |
450 } | |
451 | |
452 if (mediaList && mediaList->length()) | |
453 mediaArray.append(mediaList->mediaText()); | |
454 } | |
455 | |
456 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.
| |
457 { | |
458 if (!rule) | |
459 return nullptr; | |
460 CSSRule* parentRule = rule; | |
461 OwnPtr<Vector<String>> result = adoptPtr(new Vector<String>()); | |
462 while (parentRule) { | |
dgozman
2015/09/02 22:06:25
s/parentRule/rule
sergeyv
2015/09/02 23:58:34
Done.
| |
463 collectMediaQueriesFromRule(parentRule, *result.get()); | |
464 if (parentRule->parentRule()) { | |
465 parentRule = parentRule->parentRule(); | |
466 } else { | |
467 CSSStyleSheet* styleSheet = parentRule->parentStyleSheet(); | |
468 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.
| |
469 MediaList* mediaList = styleSheet->media(); | |
470 if (mediaList && mediaList->length()) | |
471 result->append(mediaList->mediaText()); | |
472 | |
473 parentRule = styleSheet->ownerRule(); | |
474 if (parentRule) | |
475 break; | |
476 styleSheet = styleSheet->parentStyleSheet(); | |
477 } | |
478 } | |
479 } | |
480 return result.release(); | |
481 } | |
482 | |
421 } // namespace blink | 483 } // namespace blink |
OLD | NEW |