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/CSSRuleList.h" | 9 #include "core/css/CSSRuleList.h" |
10 #include "core/dom/NodeComputedStyle.h" | 10 #include "core/dom/NodeComputedStyle.h" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 { | 308 { |
309 ErrorString errorString; | 309 ErrorString errorString; |
310 if (commitChanges) | 310 if (commitChanges) |
311 m_domAgent->markUndoableState(&errorString); | 311 m_domAgent->markUndoableState(&errorString); |
312 else if (m_isDirty) | 312 else if (m_isDirty) |
313 m_domAgent->undo(&errorString); | 313 m_domAgent->undo(&errorString); |
314 | 314 |
315 m_element.clear(); | 315 m_element.clear(); |
316 m_isDirty = false; | 316 m_isDirty = false; |
317 m_matchedRules.clear(); | 317 m_matchedRules.clear(); |
318 m_cachedSelectorsInfo.clear(); | |
319 m_currentRuleIndex = -1; | 318 m_currentRuleIndex = -1; |
320 } | 319 } |
321 | 320 |
322 void LayoutEditor::initializeCSSRules() | 321 void LayoutEditor::initializeCSSRules() |
323 { | 322 { |
324 if (!m_element) | 323 if (!m_element) |
325 return; | 324 return; |
326 | 325 |
327 Document* ownerDocument = m_element->ownerDocument(); | 326 Document* ownerDocument = m_element->ownerDocument(); |
328 // A non-active document has no styles. | 327 // A non-active document has no styles. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 return; | 377 return; |
379 | 378 |
380 m_currentRuleIndex--; | 379 m_currentRuleIndex--; |
381 } | 380 } |
382 | 381 |
383 String LayoutEditor::currentSelectorInfo() | 382 String LayoutEditor::currentSelectorInfo() |
384 { | 383 { |
385 if (!m_element) | 384 if (!m_element) |
386 return String(); | 385 return String(); |
387 | 386 |
388 if (m_cachedSelectorsInfo.contains(m_currentRuleIndex)) | |
389 return m_cachedSelectorsInfo.get(m_currentRuleIndex); | |
390 | |
391 RefPtr<JSONObject> object = JSONObject::create(); | 387 RefPtr<JSONObject> object = JSONObject::create(); |
392 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m
atchedRules[m_currentRuleIndex]->selectorText(); | 388 String currentSelectorText = m_currentRuleIndex == -1 ? "inline style" : m_m
atchedRules[m_currentRuleIndex]->selectorText(); |
393 object->setString("selector", currentSelectorText); | 389 object->setString("selector", currentSelectorText); |
394 | 390 |
395 Document* ownerDocument = m_element->ownerDocument(); | 391 Document* ownerDocument = m_element->ownerDocument(); |
396 if (!ownerDocument->isActive() || m_currentRuleIndex == -1) | 392 if (!ownerDocument->isActive() || m_currentRuleIndex == -1) |
397 return object->toJSONString(); | 393 return object->toJSONString(); |
398 | 394 |
399 TrackExceptionState exceptionState; | 395 TrackExceptionState exceptionState; |
400 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto
rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception
State); | 396 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelecto
rAll(AtomicString(m_matchedRules[m_currentRuleIndex]->selectorText()), exception
State); |
401 | 397 |
402 if (!elements || exceptionState.hadException()) | 398 if (!elements || exceptionState.hadException()) |
403 return object->toJSONString(); | 399 return object->toJSONString(); |
404 | 400 |
405 RefPtr<JSONArray> highlights = JSONArray::create(); | 401 RefPtr<JSONArray> highlights = JSONArray::create(); |
406 InspectorHighlightConfig config = affectedNodesHighlightConfig(); | 402 InspectorHighlightConfig config = affectedNodesHighlightConfig(); |
407 for (unsigned i = 0; i < elements->length(); ++i) { | 403 for (unsigned i = 0; i < elements->length(); ++i) { |
408 Element* element = elements->item(i); | 404 Element* element = elements->item(i); |
409 if (element == m_element) | 405 if (element == m_element) |
410 continue; | 406 continue; |
411 | 407 |
412 InspectorHighlight highlight(element, config, false); | 408 InspectorHighlight highlight(element, config, false); |
413 highlights->pushObject(highlight.asJSONObject()); | 409 highlights->pushObject(highlight.asJSONObject()); |
414 } | 410 } |
415 | 411 |
416 object->setArray("nodes", highlights.release()); | 412 object->setArray("nodes", highlights.release()); |
417 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString()); | 413 return object->toJSONString(); |
418 return m_cachedSelectorsInfo.get(m_currentRuleIndex); | |
419 } | 414 } |
420 | 415 |
421 } // namespace blink | 416 } // namespace blink |
OLD | NEW |