| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "core/inspector/InspectorStyleSheet.h" | 26 #include "core/inspector/InspectorStyleSheet.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "bindings/core/v8/ScriptRegexp.h" | 30 #include "bindings/core/v8/ScriptRegexp.h" |
| 31 #include "core/CSSPropertyNames.h" | 31 #include "core/CSSPropertyNames.h" |
| 32 #include "core/css/CSSImportRule.h" |
| 32 #include "core/css/CSSKeyframesRule.h" | 33 #include "core/css/CSSKeyframesRule.h" |
| 33 #include "core/css/CSSMediaRule.h" | 34 #include "core/css/CSSMediaRule.h" |
| 34 #include "core/css/CSSRuleList.h" | 35 #include "core/css/CSSRuleList.h" |
| 35 #include "core/css/CSSStyleRule.h" | 36 #include "core/css/CSSStyleRule.h" |
| 36 #include "core/css/CSSStyleSheet.h" | 37 #include "core/css/CSSStyleSheet.h" |
| 37 #include "core/css/CSSSupportsRule.h" | 38 #include "core/css/CSSSupportsRule.h" |
| 38 #include "core/css/StylePropertySet.h" | 39 #include "core/css/StylePropertySet.h" |
| 39 #include "core/css/StyleRule.h" | 40 #include "core/css/StyleRule.h" |
| 40 #include "core/css/StyleSheetContents.h" | 41 #include "core/css/StyleSheetContents.h" |
| 41 #include "core/css/parser/CSSParser.h" | 42 #include "core/css/parser/CSSParser.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 329 } |
| 329 | 330 |
| 330 void StyleSheetHandler::endMediaQuery() | 331 void StyleSheetHandler::endMediaQuery() |
| 331 { | 332 { |
| 332 m_currentMediaQueryData.clear(); | 333 m_currentMediaQueryData.clear(); |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool verifyRuleText(Document* document, const String& ruleText) | 336 bool verifyRuleText(Document* document, const String& ruleText) |
| 336 { | 337 { |
| 337 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 338 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 339 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea
te(strictCSSParserContext()); |
| 338 RuleSourceDataList sourceData; | 340 RuleSourceDataList sourceData; |
| 339 String text = ruleText + " div { " + bogusPropertyName + ": none; }"; | 341 String text = ruleText + " div { " + bogusPropertyName + ": none; }"; |
| 340 StyleSheetHandler handler(text, document, &sourceData); | 342 StyleSheetHandler handler(text, document, &sourceData); |
| 341 CSSParser::parseSheetForInspector(parserContextForDocument(document), text,
handler); | 343 CSSParser::parseSheetForInspector(parserContextForDocument(document), styleS
heet.get(), text, handler); |
| 342 unsigned ruleCount = sourceData.size(); | 344 unsigned ruleCount = sourceData.size(); |
| 343 | 345 |
| 344 // Exactly two rules should be parsed. | 346 // Exactly two rules should be parsed. |
| 345 if (ruleCount != 2) | 347 if (ruleCount != 2) |
| 346 return false; | 348 return false; |
| 347 | 349 |
| 348 // Added rule must be style rule. | 350 // Added rule must be style rule. |
| 349 if (!sourceData.at(0)->styleSourceData) | 351 if (!sourceData.at(0)->styleSourceData) |
| 350 return false; | 352 return false; |
| 351 | 353 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 364 } | 366 } |
| 365 | 367 |
| 366 bool verifyStyleText(Document* document, const String& text) | 368 bool verifyStyleText(Document* document, const String& text) |
| 367 { | 369 { |
| 368 return verifyRuleText(document, "div {" + text + "}"); | 370 return verifyRuleText(document, "div {" + text + "}"); |
| 369 } | 371 } |
| 370 | 372 |
| 371 bool verifySelectorText(Document* document, const String& selectorText) | 373 bool verifySelectorText(Document* document, const String& selectorText) |
| 372 { | 374 { |
| 373 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 375 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 376 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea
te(strictCSSParserContext()); |
| 374 RuleSourceDataList sourceData; | 377 RuleSourceDataList sourceData; |
| 375 String text = selectorText + " { " + bogusPropertyName + ": none; }"; | 378 String text = selectorText + " { " + bogusPropertyName + ": none; }"; |
| 376 StyleSheetHandler handler(text, document, &sourceData); | 379 StyleSheetHandler handler(text, document, &sourceData); |
| 377 CSSParser::parseSheetForInspector(parserContextForDocument(document), text,
handler); | 380 CSSParser::parseSheetForInspector(parserContextForDocument(document), styleS
heet.get(), text, handler); |
| 378 | 381 |
| 379 // Exactly one rule should be parsed. | 382 // Exactly one rule should be parsed. |
| 380 unsigned ruleCount = sourceData.size(); | 383 unsigned ruleCount = sourceData.size(); |
| 381 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style) | 384 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style) |
| 382 return false; | 385 return false; |
| 383 | 386 |
| 384 // Exactly one property should be in style rule. | 387 // Exactly one property should be in style rule. |
| 385 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; | 388 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st
yleSourceData->propertyData; |
| 386 unsigned propertyCount = propertyData.size(); | 389 unsigned propertyCount = propertyData.size(); |
| 387 if (propertyCount != 1) | 390 if (propertyCount != 1) |
| 388 return false; | 391 return false; |
| 389 | 392 |
| 390 // Check for the property name. | 393 // Check for the property name. |
| 391 if (propertyData.at(0).name != bogusPropertyName) | 394 if (propertyData.at(0).name != bogusPropertyName) |
| 392 return false; | 395 return false; |
| 393 | 396 |
| 394 return true; | 397 return true; |
| 395 } | 398 } |
| 396 | 399 |
| 397 bool verifyMediaText(Document* document, const String& mediaText) | 400 bool verifyMediaText(Document* document, const String& mediaText) |
| 398 { | 401 { |
| 399 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 402 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 403 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea
te(strictCSSParserContext()); |
| 400 RuleSourceDataList sourceData; | 404 RuleSourceDataList sourceData; |
| 401 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; | 405 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n
one; } }"; |
| 402 StyleSheetHandler handler(text, document, &sourceData); | 406 StyleSheetHandler handler(text, document, &sourceData); |
| 403 CSSParser::parseSheetForInspector(parserContextForDocument(document), text,
handler); | 407 CSSParser::parseSheetForInspector(parserContextForDocument(document), styleS
heet.get(), text, handler); |
| 404 | 408 |
| 405 // Exactly one media rule should be parsed. | 409 // Exactly one media rule should be parsed. |
| 406 unsigned ruleCount = sourceData.size(); | 410 unsigned ruleCount = sourceData.size(); |
| 407 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media) | 411 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media) |
| 408 return false; | 412 return false; |
| 409 | 413 |
| 410 // Media rule should have exactly one style rule child. | 414 // Media rule should have exactly one style rule child. |
| 411 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; | 415 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules; |
| 412 ruleCount = childSourceData.size(); | 416 ruleCount = childSourceData.size(); |
| 413 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) | 417 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 case CSSRule::SUPPORTS_RULE: | 494 case CSSRule::SUPPORTS_RULE: |
| 491 result->append(rule); | 495 result->append(rule); |
| 492 collectFlatRules(asCSSRuleList(rule), result); | 496 collectFlatRules(asCSSRuleList(rule), result); |
| 493 break; | 497 break; |
| 494 default: | 498 default: |
| 495 break; | 499 break; |
| 496 } | 500 } |
| 497 } | 501 } |
| 498 } | 502 } |
| 499 | 503 |
| 504 typedef HashMap<unsigned, unsigned, WTF::IntHash<unsigned>, WTF::UnsignedWithZer
oKeyHashTraits<unsigned>> IndexMap; |
| 505 |
| 506 void diff(const Vector<String>& listA, const Vector<String>& listB, IndexMap* aT
oB, IndexMap* bToA) |
| 507 { |
| 508 // Cut of common prefix. |
| 509 size_t startOffset = 0; |
| 510 while (startOffset < listA.size() && startOffset < listB.size()) { |
| 511 if (listA.at(startOffset) != listB.at(startOffset)) |
| 512 break; |
| 513 aToB->set(startOffset, startOffset); |
| 514 bToA->set(startOffset, startOffset); |
| 515 ++startOffset; |
| 516 } |
| 517 |
| 518 // Cut of common suffix. |
| 519 size_t endOffset = 0; |
| 520 while (endOffset < listA.size() - startOffset && endOffset < listB.size() -
startOffset) { |
| 521 size_t indexA = listA.size() - endOffset - 1; |
| 522 size_t indexB = listB.size() - endOffset - 1; |
| 523 if (listA.at(indexA) != listB.at(indexB)) |
| 524 break; |
| 525 aToB->set(indexA, indexB); |
| 526 bToA->set(indexB, indexA); |
| 527 ++endOffset; |
| 528 } |
| 529 |
| 530 int n = listA.size() - startOffset - endOffset; |
| 531 int m = listB.size() - startOffset - endOffset; |
| 532 |
| 533 // If we mapped either of arrays, we have no more work to do. |
| 534 if (n == 0 || m == 0) |
| 535 return; |
| 536 |
| 537 int** diff = new int*[n]; |
| 538 int** backtrack = new int*[n]; |
| 539 for (int i = 0; i < n; ++i) { |
| 540 diff[i] = new int[m]; |
| 541 backtrack[i] = new int[m]; |
| 542 } |
| 543 |
| 544 // Compute longest common subsequence of two cssom models. |
| 545 for (int i = 0; i < n; ++i) { |
| 546 for (int j = 0; j < m; ++j) { |
| 547 int max = 0; |
| 548 int track = 0; |
| 549 |
| 550 if (i > 0 && diff[i - 1][j] > max) { |
| 551 max = diff[i - 1][j]; |
| 552 track = 1; |
| 553 } |
| 554 |
| 555 if (j > 0 && diff[i][j - 1] > max) { |
| 556 max = diff[i][j - 1]; |
| 557 track = 2; |
| 558 } |
| 559 |
| 560 if (listA.at(i + startOffset) == listB.at(j + startOffset)) { |
| 561 int value = i > 0 && j > 0 ? diff[i - 1][j - 1] + 1 : 1; |
| 562 if (value > max) { |
| 563 max = value; |
| 564 track = 3; |
| 565 } |
| 566 } |
| 567 |
| 568 diff[i][j] = max; |
| 569 backtrack[i][j] = track; |
| 570 } |
| 571 } |
| 572 |
| 573 // Backtrack and add missing mapping. |
| 574 int i = n - 1, j = m - 1; |
| 575 while (i >= 0 && j >= 0 && backtrack[i][j]) { |
| 576 switch (backtrack[i][j]) { |
| 577 case 1: |
| 578 i -= 1; |
| 579 break; |
| 580 case 2: |
| 581 j -= 1; |
| 582 break; |
| 583 case 3: |
| 584 aToB->set(i + startOffset, j + startOffset); |
| 585 bToA->set(j + startOffset, i + startOffset); |
| 586 i -= 1; |
| 587 j -= 1; |
| 588 break; |
| 589 default: |
| 590 ASSERT_NOT_REACHED(); |
| 591 } |
| 592 } |
| 593 |
| 594 for (int i = 0; i < n; ++i) { |
| 595 delete [] diff[i]; |
| 596 delete [] backtrack[i]; |
| 597 } |
| 598 delete [] diff; |
| 599 delete [] backtrack; |
| 600 } |
| 601 |
| 500 } // namespace | 602 } // namespace |
| 501 | 603 |
| 502 namespace blink { | 604 namespace blink { |
| 503 | 605 |
| 504 enum MediaListSource { | 606 enum MediaListSource { |
| 505 MediaListSourceLinkedSheet, | 607 MediaListSourceLinkedSheet, |
| 506 MediaListSourceInlineSheet, | 608 MediaListSourceInlineSheet, |
| 507 MediaListSourceMediaRule, | 609 MediaListSourceMediaRule, |
| 508 MediaListSourceImportRule | 610 MediaListSourceImportRule |
| 509 }; | 611 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 532 : m_style(style) | 634 : m_style(style) |
| 533 , m_sourceData(sourceData) | 635 , m_sourceData(sourceData) |
| 534 , m_parentStyleSheet(parentStyleSheet) | 636 , m_parentStyleSheet(parentStyleSheet) |
| 535 { | 637 { |
| 536 ASSERT(m_style); | 638 ASSERT(m_style); |
| 537 } | 639 } |
| 538 | 640 |
| 539 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() | 641 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() |
| 540 { | 642 { |
| 541 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); | 643 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); |
| 542 if (m_parentStyleSheet && !m_parentStyleSheet->id().isEmpty()) | |
| 543 result->setStyleSheetId(m_parentStyleSheet->id()); | |
| 544 | |
| 545 if (m_sourceData) { | 644 if (m_sourceData) { |
| 645 if (m_parentStyleSheet && !m_parentStyleSheet->id().isEmpty()) |
| 646 result->setStyleSheetId(m_parentStyleSheet->id()); |
| 546 result->setRange(buildSourceRangeObject(m_sourceData->ruleBodyRange, m_p
arentStyleSheet->lineEndings())); | 647 result->setRange(buildSourceRangeObject(m_sourceData->ruleBodyRange, m_p
arentStyleSheet->lineEndings())); |
| 547 String sheetText; | 648 String sheetText; |
| 548 bool success = m_parentStyleSheet->getText(&sheetText); | 649 bool success = m_parentStyleSheet->getText(&sheetText); |
| 549 if (success) { | 650 if (success) { |
| 550 const SourceRange& bodyRange = m_sourceData->ruleBodyRange; | 651 const SourceRange& bodyRange = m_sourceData->ruleBodyRange; |
| 551 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en
d - bodyRange.start)); | 652 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en
d - bodyRange.start)); |
| 552 } | 653 } |
| 553 } | 654 } |
| 554 | 655 |
| 555 return result.release(); | 656 return result.release(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 , m_pageStyleSheet(pageStyleSheet) | 860 , m_pageStyleSheet(pageStyleSheet) |
| 760 , m_origin(origin) | 861 , m_origin(origin) |
| 761 , m_documentURL(documentURL) | 862 , m_documentURL(documentURL) |
| 762 { | 863 { |
| 763 String text; | 864 String text; |
| 764 bool success = inlineStyleSheetText(&text); | 865 bool success = inlineStyleSheetText(&text); |
| 765 if (!success) | 866 if (!success) |
| 766 success = resourceStyleSheetText(&text); | 867 success = resourceStyleSheetText(&text); |
| 767 if (success) | 868 if (success) |
| 768 innerSetText(text, false); | 869 innerSetText(text, false); |
| 769 collectFlatRules(); | 870 mapSourceDataToCSSOM(); |
| 770 } | 871 } |
| 771 | 872 |
| 772 InspectorStyleSheet::~InspectorStyleSheet() | 873 InspectorStyleSheet::~InspectorStyleSheet() |
| 773 { | 874 { |
| 774 } | 875 } |
| 775 | 876 |
| 776 DEFINE_TRACE(InspectorStyleSheet) | 877 DEFINE_TRACE(InspectorStyleSheet) |
| 777 { | 878 { |
| 778 visitor->trace(m_cssAgent); | 879 visitor->trace(m_cssAgent); |
| 779 visitor->trace(m_resourceAgent); | 880 visitor->trace(m_resourceAgent); |
| 780 visitor->trace(m_pageStyleSheet); | 881 visitor->trace(m_pageStyleSheet); |
| 781 visitor->trace(m_sourceData); | 882 visitor->trace(m_sourceData); |
| 782 visitor->trace(m_flatRules); | 883 visitor->trace(m_cssomFlatRules); |
| 884 visitor->trace(m_parsedFlatRules); |
| 783 InspectorStyleSheetBase::trace(visitor); | 885 InspectorStyleSheetBase::trace(visitor); |
| 784 } | 886 } |
| 785 | 887 |
| 786 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) | 888 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) |
| 787 { | 889 { |
| 788 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) | 890 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) |
| 789 return pageStyleSheet->contents()->baseURL().string(); | 891 return pageStyleSheet->contents()->baseURL().string(); |
| 790 return emptyString(); | 892 return emptyString(); |
| 791 } | 893 } |
| 792 | 894 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 812 { | 914 { |
| 813 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); | 915 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); |
| 814 m_pageStyleSheet->contents()->parseString(text); | 916 m_pageStyleSheet->contents()->parseString(text); |
| 815 } | 917 } |
| 816 | 918 |
| 817 if (listener()) | 919 if (listener()) |
| 818 listener()->didReparseStyleSheet(); | 920 listener()->didReparseStyleSheet(); |
| 819 onStyleSheetTextChanged(); | 921 onStyleSheetTextChanged(); |
| 820 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); | 922 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); |
| 821 | 923 |
| 822 collectFlatRules(); | 924 mapSourceDataToCSSOM(); |
| 823 return true; | 925 return true; |
| 824 } | 926 } |
| 825 | 927 |
| 826 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour
ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce
ptionState& exceptionState) | 928 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour
ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce
ptionState& exceptionState) |
| 827 { | 929 { |
| 828 if (!verifySelectorText(m_pageStyleSheet->ownerDocument(), text)) { | 930 if (!verifySelectorText(m_pageStyleSheet->ownerDocument(), text)) { |
| 829 exceptionState.throwDOMException(SyntaxError, "Selector or media text is
not valid."); | 931 exceptionState.throwDOMException(SyntaxError, "Selector or media text is
not valid."); |
| 830 return nullptr; | 932 return nullptr; |
| 831 } | 933 } |
| 832 | 934 |
| 833 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByHeaderRange(ran
ge); | 935 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByHeaderRange(ran
ge); |
| 834 if (!sourceData || !sourceData->styleSourceData) { | 936 if (!sourceData || !sourceData->styleSourceData) { |
| 835 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing source range"); | 937 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing source range"); |
| 836 return nullptr; | 938 return nullptr; |
| 837 } | 939 } |
| 838 | 940 |
| 839 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData.get()); | 941 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData); |
| 840 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::STYLE_RUL
E) { | 942 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::STYLE_RUL
E) { |
| 841 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); | 943 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); |
| 842 return nullptr; | 944 return nullptr; |
| 843 } | 945 } |
| 844 | 946 |
| 845 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu
le(rule.get()); | 947 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu
le(rule.get()); |
| 846 styleRule->setSelectorText(text); | 948 styleRule->setSelectorText(text); |
| 847 | 949 |
| 848 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); | 950 if (!replaceText(sourceData->ruleHeaderRange, text, newRange, oldText)) |
| 951 mapSourceDataToCSSOM(); |
| 849 onStyleSheetTextChanged(); | 952 onStyleSheetTextChanged(); |
| 850 | 953 |
| 851 return styleRule; | 954 return styleRule; |
| 852 } | 955 } |
| 853 | 956 |
| 854 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR
ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti
onState& exceptionState) | 957 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR
ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti
onState& exceptionState) |
| 855 { | 958 { |
| 856 if (!verifyStyleText(m_pageStyleSheet->ownerDocument(), text)) { | 959 if (!verifyStyleText(m_pageStyleSheet->ownerDocument(), text)) { |
| 857 exceptionState.throwDOMException(SyntaxError, "Style text is not valid."
); | 960 exceptionState.throwDOMException(SyntaxError, "Style text is not valid."
); |
| 858 return nullptr; | 961 return nullptr; |
| 859 } | 962 } |
| 860 | 963 |
| 861 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByBodyRange(range
); | 964 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByBodyRange(range
); |
| 862 if (!sourceData || !sourceData->styleSourceData) { | 965 if (!sourceData || !sourceData->styleSourceData) { |
| 863 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); | 966 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); |
| 864 return nullptr; | 967 return nullptr; |
| 865 } | 968 } |
| 866 | 969 |
| 867 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData.get()); | 970 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData); |
| 868 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::STYLE_RUL
E) { | 971 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::STYLE_RUL
E) { |
| 869 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); | 972 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); |
| 870 return nullptr; | 973 return nullptr; |
| 871 } | 974 } |
| 872 | 975 |
| 873 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu
le(rule.get()); | 976 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu
le(rule.get()); |
| 874 styleRule->style()->setCSSText(text, exceptionState); | 977 styleRule->style()->setCSSText(text, exceptionState); |
| 875 | 978 |
| 876 replaceText(sourceData->ruleBodyRange, text, newRange, oldText); | 979 if (!replaceText(sourceData->ruleBodyRange, text, newRange, oldText)) |
| 980 mapSourceDataToCSSOM(); |
| 877 onStyleSheetTextChanged(); | 981 onStyleSheetTextChanged(); |
| 878 | 982 |
| 879 return styleRule; | 983 return styleRule; |
| 880 } | 984 } |
| 881 | 985 |
| 882 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou
rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc
eptionState& exceptionState) | 986 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou
rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc
eptionState& exceptionState) |
| 883 { | 987 { |
| 884 if (!verifyMediaText(m_pageStyleSheet->ownerDocument(), text)) { | 988 if (!verifyMediaText(m_pageStyleSheet->ownerDocument(), text)) { |
| 885 exceptionState.throwDOMException(SyntaxError, "Selector or media text is
not valid."); | 989 exceptionState.throwDOMException(SyntaxError, "Selector or media text is
not valid."); |
| 886 return nullptr; | 990 return nullptr; |
| 887 } | 991 } |
| 888 | 992 |
| 889 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByHeaderRange(ran
ge); | 993 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByHeaderRange(ran
ge); |
| 890 if (!sourceData || !sourceData->mediaSourceData) { | 994 if (!sourceData || !sourceData->mediaSourceData) { |
| 891 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing source range"); | 995 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing source range"); |
| 892 return nullptr; | 996 return nullptr; |
| 893 } | 997 } |
| 894 | 998 |
| 895 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData.get()); | 999 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData); |
| 896 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::MEDIA_RUL
E) { | 1000 if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::MEDIA_RUL
E) { |
| 897 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); | 1001 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat
ch existing style source range"); |
| 898 return nullptr; | 1002 return nullptr; |
| 899 } | 1003 } |
| 900 | 1004 |
| 901 RefPtrWillBeRawPtr<CSSMediaRule> mediaRule = InspectorCSSAgent::asCSSMediaR
ule(rule.get()); | 1005 RefPtrWillBeRawPtr<CSSMediaRule> mediaRule = InspectorCSSAgent::asCSSMediaR
ule(rule.get()); |
| 902 mediaRule->media()->setMediaText(text); | 1006 mediaRule->media()->setMediaText(text); |
| 903 | 1007 |
| 904 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); | 1008 if (!replaceText(sourceData->ruleHeaderRange, text, newRange, oldText)) |
| 1009 mapSourceDataToCSSOM(); |
| 1010 |
| 905 onStyleSheetTextChanged(); | 1011 onStyleSheetTextChanged(); |
| 906 | 1012 |
| 907 return mediaRule; | 1013 return mediaRule; |
| 908 } | 1014 } |
| 909 | 1015 |
| 910 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleAfterSourceRange(
const SourceRange& sourceRange) | 1016 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAfterSo
urceRange(const SourceRange& sourceRange) |
| 911 { | 1017 { |
| 912 ASSERT(m_sourceData); | 1018 ASSERT(m_sourceData); |
| 913 unsigned index = 0; | 1019 unsigned index = 0; |
| 914 for (; index < m_sourceData->size(); ++index) { | 1020 for (; index < m_sourceData->size(); ++index) { |
| 915 RefPtrWillBeRawPtr<CSSRuleSourceData> sd = m_sourceData->at(index); | 1021 RefPtrWillBeRawPtr<CSSRuleSourceData> sd = m_sourceData->at(index); |
| 916 if (sd->ruleHeaderRange.start >= sourceRange.end) | 1022 if (sd->ruleHeaderRange.start >= sourceRange.end) |
| 917 break; | 1023 break; |
| 918 } | 1024 } |
| 919 return index < m_sourceData->size() ? m_sourceData->at(index) : nullptr; | 1025 return index < m_sourceData->size() ? m_sourceData->at(index) : nullptr; |
| 920 } | 1026 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 if (ruleSourceData->ruleHeaderRange.start < sourceRange.start && sourceR
ange.start < ruleSourceData->ruleBodyRange.start) { | 1075 if (ruleSourceData->ruleHeaderRange.start < sourceRange.start && sourceR
ange.start < ruleSourceData->ruleBodyRange.start) { |
| 970 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule
inside rule selector."); | 1076 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule
inside rule selector."); |
| 971 return nullptr; | 1077 return nullptr; |
| 972 } | 1078 } |
| 973 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc
eData->ruleBodyRange.end < sourceRange.start) | 1079 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc
eData->ruleBodyRange.end < sourceRange.start) |
| 974 continue; | 1080 continue; |
| 975 if (!containingRuleSourceData || containingRuleSourceData->ruleBodyRange
.length() > ruleSourceData->ruleBodyRange.length()) | 1081 if (!containingRuleSourceData || containingRuleSourceData->ruleBodyRange
.length() > ruleSourceData->ruleBodyRange.length()) |
| 976 containingRuleSourceData = ruleSourceData; | 1082 containingRuleSourceData = ruleSourceData; |
| 977 } | 1083 } |
| 978 | 1084 |
| 979 RefPtrWillBeRawPtr<CSSRuleSourceData> insertBefore = ruleAfterSourceRange(so
urceRange); | 1085 RefPtrWillBeRawPtr<CSSRuleSourceData> insertBefore = ruleSourceDataAfterSour
ceRange(sourceRange); |
| 980 RefPtrWillBeRawPtr<CSSRule> insertBeforeRule = ruleForSourceData(insertBefor
e.get()); | 1086 RefPtrWillBeRawPtr<CSSRule> insertBeforeRule = ruleForSourceData(insertBefor
e); |
| 981 | 1087 |
| 982 if (!containingRuleSourceData) | 1088 if (!containingRuleSourceData) |
| 983 return insertCSSOMRuleInStyleSheet(insertBeforeRule.get(), ruleText, exc
eptionState); | 1089 return insertCSSOMRuleInStyleSheet(insertBeforeRule.get(), ruleText, exc
eptionState); |
| 984 | 1090 |
| 985 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(containingRuleSourceDat
a.get()); | 1091 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(containingRuleSourceDat
a); |
| 986 if (!rule || rule->type() != CSSRule::MEDIA_RULE) { | 1092 if (!rule || rule->type() != CSSRule::MEDIA_RULE) { |
| 987 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n
on-media rule."); | 1093 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n
on-media rule."); |
| 988 return nullptr; | 1094 return nullptr; |
| 989 } | 1095 } |
| 990 | 1096 |
| 991 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), insertBeforeRu
le.get(), ruleText, exceptionState); | 1097 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), insertBeforeRu
le.get(), ruleText, exceptionState); |
| 992 } | 1098 } |
| 993 | 1099 |
| 994 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule
Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce
ptionState) | 1100 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule
Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce
ptionState) |
| 995 { | 1101 { |
| 996 if (location.start != location.end) { | 1102 if (location.start != location.end) { |
| 997 exceptionState.throwDOMException(NotFoundError, "Source range must be co
llapsed."); | 1103 exceptionState.throwDOMException(NotFoundError, "Source range must be co
llapsed."); |
| 998 return nullptr; | 1104 return nullptr; |
| 999 } | 1105 } |
| 1000 | 1106 |
| 1001 if (!verifyRuleText(m_pageStyleSheet->ownerDocument(), ruleText)) { | 1107 if (!verifyRuleText(m_pageStyleSheet->ownerDocument(), ruleText)) { |
| 1002 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.")
; | 1108 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.")
; |
| 1003 return nullptr; | 1109 return nullptr; |
| 1004 } | 1110 } |
| 1005 | 1111 |
| 1006 if (!m_sourceData) { | 1112 if (!m_sourceData) { |
| 1007 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); | 1113 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); |
| 1008 return nullptr; | 1114 return nullptr; |
| 1009 } | 1115 } |
| 1010 | 1116 |
| 1117 // Enforce renumber to get proper insertion anchor. |
| 1118 mapSourceDataToCSSOM(); |
| 1119 |
| 1011 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo
cation, ruleText, exceptionState); | 1120 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo
cation, ruleText, exceptionState); |
| 1012 if (exceptionState.hadException()) | 1121 if (exceptionState.hadException()) |
| 1013 return nullptr; | 1122 return nullptr; |
| 1014 | 1123 |
| 1015 replaceText(location, ruleText, addedRange, nullptr); | 1124 replaceText(location, ruleText, addedRange, nullptr); |
| 1016 collectFlatRules(); | 1125 mapSourceDataToCSSOM(); |
| 1017 | 1126 |
| 1018 onStyleSheetTextChanged(); | 1127 onStyleSheetTextChanged(); |
| 1019 return styleRule; | 1128 return styleRule; |
| 1020 } | 1129 } |
| 1021 | 1130 |
| 1022 bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e
xceptionState) | 1131 bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e
xceptionState) |
| 1023 { | 1132 { |
| 1024 if (!m_sourceData) { | 1133 if (!m_sourceData) { |
| 1025 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); | 1134 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); |
| 1026 return false; | 1135 return false; |
| 1027 } | 1136 } |
| 1028 | 1137 |
| 1029 // Find index of CSSRule that entirely belongs to the range. | 1138 // Find index of CSSRule that entirely belongs to the range. |
| 1030 RefPtrWillBeRawPtr<CSSRuleSourceData> foundData = nullptr; | 1139 RefPtrWillBeRawPtr<CSSRuleSourceData> foundData = nullptr; |
| 1031 | 1140 |
| 1032 for (size_t i = 0; i < m_sourceData->size(); ++i) { | 1141 for (size_t i = 0; i < m_sourceData->size(); ++i) { |
| 1033 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at(
i); | 1142 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at(
i); |
| 1034 unsigned ruleStart = ruleSourceData->ruleHeaderRange.start; | 1143 unsigned ruleStart = ruleSourceData->ruleHeaderRange.start; |
| 1035 unsigned ruleEnd = ruleSourceData->ruleBodyRange.end + 1; | 1144 unsigned ruleEnd = ruleSourceData->ruleBodyRange.end + 1; |
| 1036 bool startBelongs = ruleStart >= range.start && ruleStart < range.end; | 1145 bool startBelongs = ruleStart >= range.start && ruleStart < range.end; |
| 1037 bool endBelongs = ruleEnd > range.start && ruleEnd <= range.end; | 1146 bool endBelongs = ruleEnd > range.start && ruleEnd <= range.end; |
| 1038 | 1147 |
| 1039 if (startBelongs != endBelongs) | 1148 if (startBelongs != endBelongs) |
| 1040 break; | 1149 break; |
| 1041 if (!startBelongs) | 1150 if (!startBelongs) |
| 1042 continue; | 1151 continue; |
| 1043 if (!foundData || foundData->ruleBodyRange.length() > ruleSourceData->ru
leBodyRange.length()) | 1152 if (!foundData || foundData->ruleBodyRange.length() > ruleSourceData->ru
leBodyRange.length()) |
| 1044 foundData = ruleSourceData; | 1153 foundData = ruleSourceData; |
| 1045 } | 1154 } |
| 1046 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(foundData.get()); | 1155 RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(foundData); |
| 1047 if (!rule) { | 1156 if (!rule) { |
| 1048 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found in given range."); | 1157 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found in given range."); |
| 1049 return false; | 1158 return false; |
| 1050 } | 1159 } |
| 1051 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); | 1160 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); |
| 1052 if (!styleSheet) { | 1161 if (!styleSheet) { |
| 1053 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co
uld be found."); | 1162 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co
uld be found."); |
| 1054 return false; | 1163 return false; |
| 1055 } | 1164 } |
| 1056 CSSRule* parentRule = rule->parentRule(); | 1165 CSSRule* parentRule = rule->parentRule(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1071 ++index; | 1180 ++index; |
| 1072 ASSERT(index < styleSheet->length()); | 1181 ASSERT(index < styleSheet->length()); |
| 1073 styleSheet->deleteRule(index, exceptionState); | 1182 styleSheet->deleteRule(index, exceptionState); |
| 1074 } | 1183 } |
| 1075 // |rule| MAY NOT be addressed after this line! | 1184 // |rule| MAY NOT be addressed after this line! |
| 1076 | 1185 |
| 1077 if (exceptionState.hadException()) | 1186 if (exceptionState.hadException()) |
| 1078 return false; | 1187 return false; |
| 1079 | 1188 |
| 1080 replaceText(range, "", nullptr, nullptr); | 1189 replaceText(range, "", nullptr, nullptr); |
| 1081 collectFlatRules(); | 1190 mapSourceDataToCSSOM(); |
| 1082 | 1191 |
| 1083 onStyleSheetTextChanged(); | 1192 onStyleSheetTextChanged(); |
| 1084 return true; | 1193 return true; |
| 1085 } | 1194 } |
| 1086 | 1195 |
| 1087 void InspectorStyleSheet::replaceText(const SourceRange& range, const String& te
xt, SourceRange* newRange, String* oldText) | 1196 bool InspectorStyleSheet::replaceText(const SourceRange& range, const String& te
xt, SourceRange* newRange, String* oldText) |
| 1088 { | 1197 { |
| 1089 String sheetText = m_text; | 1198 String sheetText = m_text; |
| 1090 if (oldText) | 1199 if (oldText) |
| 1091 *oldText = sheetText.substring(range.start, range.length()); | 1200 *oldText = sheetText.substring(range.start, range.length()); |
| 1092 sheetText.replace(range.start, range.length(), text); | 1201 sheetText.replace(range.start, range.length(), text); |
| 1093 if (newRange) | 1202 if (newRange) |
| 1094 *newRange = SourceRange(range.start, range.start + text.length()); | 1203 *newRange = SourceRange(range.start, range.start + text.length()); |
| 1095 innerSetText(sheetText, true); | 1204 return innerSetText(sheetText, true); |
| 1096 } | 1205 } |
| 1097 | 1206 |
| 1098 void InspectorStyleSheet::innerSetText(const String& text, bool markAsLocallyMod
ified) | 1207 bool InspectorStyleSheet::innerSetText(const String& text, bool markAsLocallyMod
ified) |
| 1099 { | 1208 { |
| 1209 unsigned sizeBefore = m_sourceData ? m_sourceData->size() : 0; |
| 1210 |
| 1100 OwnPtrWillBeRawPtr<RuleSourceDataList> ruleTree = adoptPtrWillBeNoop(new Rul
eSourceDataList()); | 1211 OwnPtrWillBeRawPtr<RuleSourceDataList> ruleTree = adoptPtrWillBeNoop(new Rul
eSourceDataList()); |
| 1212 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea
te(m_pageStyleSheet->contents()->parserContext()); |
| 1101 StyleSheetHandler handler(text, m_pageStyleSheet->ownerDocument(), ruleTree.
get()); | 1213 StyleSheetHandler handler(text, m_pageStyleSheet->ownerDocument(), ruleTree.
get()); |
| 1102 CSSParser::parseSheetForInspector(parserContextForDocument(m_pageStyleSheet-
>ownerDocument()), text, handler); | 1214 CSSParser::parseSheetForInspector(m_pageStyleSheet->contents()->parserContex
t(), styleSheet.get(), text, handler); |
| 1215 RefPtrWillBeRawPtr<CSSStyleSheet> sourceDataSheet; |
| 1216 if (toCSSImportRule(m_pageStyleSheet->ownerRule())) |
| 1217 sourceDataSheet = CSSStyleSheet::create(styleSheet, toCSSImportRule(m_pa
geStyleSheet->ownerRule())); |
| 1218 else |
| 1219 sourceDataSheet = CSSStyleSheet::create(styleSheet, m_pageStyleSheet->ow
nerNode()); |
| 1220 |
| 1221 m_parsedFlatRules.clear(); |
| 1222 collectFlatRules(sourceDataSheet.get(), &m_parsedFlatRules); |
| 1223 |
| 1103 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); | 1224 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); |
| 1104 flattenSourceData(ruleTree.get(), m_sourceData.get()); | 1225 flattenSourceData(ruleTree.get(), m_sourceData.get()); |
| 1105 m_text = text; | 1226 m_text = text; |
| 1106 | 1227 |
| 1107 if (markAsLocallyModified) { | 1228 if (markAsLocallyModified) { |
| 1108 Element* element = ownerStyleElement(); | 1229 Element* element = ownerStyleElement(); |
| 1109 if (element) | 1230 if (element) |
| 1110 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), te
xt); | 1231 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), te
xt); |
| 1111 else | 1232 else |
| 1112 m_cssAgent->addEditedStyleSheet(finalURL(), text); | 1233 m_cssAgent->addEditedStyleSheet(finalURL(), text); |
| 1113 } | 1234 } |
| 1235 return sizeBefore == m_sourceData->size(); |
| 1114 } | 1236 } |
| 1115 | 1237 |
| 1116 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() | 1238 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() |
| 1117 { | 1239 { |
| 1118 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1240 CSSStyleSheet* styleSheet = pageStyleSheet(); |
| 1119 if (!styleSheet) | 1241 if (!styleSheet) |
| 1120 return nullptr; | 1242 return nullptr; |
| 1121 | 1243 |
| 1122 Document* document = styleSheet->ownerDocument(); | 1244 Document* document = styleSheet->ownerDocument(); |
| 1123 LocalFrame* frame = document ? document->frame() : nullptr; | 1245 LocalFrame* frame = document ? document->frame() : nullptr; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 | 1473 |
| 1352 for (size_t i = 0; i < m_sourceData->size(); ++i) { | 1474 for (size_t i = 0; i < m_sourceData->size(); ++i) { |
| 1353 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at(
i); | 1475 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at(
i); |
| 1354 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour
ceData->ruleBodyRange.end == sourceRange.end) { | 1476 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour
ceData->ruleBodyRange.end == sourceRange.end) { |
| 1355 return ruleSourceData; | 1477 return ruleSourceData; |
| 1356 } | 1478 } |
| 1357 } | 1479 } |
| 1358 return nullptr; | 1480 return nullptr; |
| 1359 } | 1481 } |
| 1360 | 1482 |
| 1361 RefPtrWillBeRawPtr<CSSRule> InspectorStyleSheet::ruleForSourceData(CSSRuleSource
Data* sourceData) | 1483 RefPtrWillBeRawPtr<CSSRule> InspectorStyleSheet::ruleForSourceData(RefPtrWillBeR
awPtr<CSSRuleSourceData> sourceData) |
| 1362 { | 1484 { |
| 1363 if (!m_sourceData || !sourceData) | 1485 if (!m_sourceData || !sourceData) |
| 1364 return nullptr; | 1486 return nullptr; |
| 1365 for (size_t i = 0; i < m_sourceData->size(); ++i) { | 1487 size_t index = m_sourceData->find(sourceData.get()); |
| 1366 if (m_sourceData->at(i).get() == sourceData) | 1488 if (index == kNotFound) |
| 1367 return i < m_flatRules.size() ? m_flatRules.at(i) : nullptr; | 1489 return nullptr; |
| 1368 } | 1490 IndexMap::iterator it = m_sourceDataToRule.find(index); |
| 1369 return nullptr; | 1491 if (it == m_sourceDataToRule.end()) |
| 1492 return nullptr; |
| 1493 |
| 1494 ASSERT(it->value < m_cssomFlatRules.size()); |
| 1495 |
| 1496 // Check that CSSOM did not mutate this rule. |
| 1497 RefPtrWillBeRawPtr<CSSRule> result = m_cssomFlatRules.at(it->value); |
| 1498 if (m_parsedFlatRules.at(index)->cssText() != result->cssText()) |
| 1499 return nullptr; |
| 1500 return result; |
| 1370 } | 1501 } |
| 1371 | 1502 |
| 1372 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(CSS
Rule* rule) | 1503 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(Ref
PtrWillBeRawPtr<CSSRule> rule) |
| 1373 { | 1504 { |
| 1374 if (!m_sourceData || !rule) | 1505 if (!m_sourceData || !rule) |
| 1375 return nullptr; | 1506 return nullptr; |
| 1507 size_t index = m_cssomFlatRules.find(rule.get()); |
| 1508 if (index == kNotFound) |
| 1509 return nullptr; |
| 1510 IndexMap::iterator it = m_ruleToSourceData.find(index); |
| 1511 if (it == m_ruleToSourceData.end()) |
| 1512 return nullptr; |
| 1376 | 1513 |
| 1377 size_t index = m_flatRules.find(rule); | 1514 ASSERT(it->value < m_sourceData->size()); |
| 1378 return index < m_sourceData->size() ? m_sourceData->at(index) : nullptr; | 1515 |
| 1516 // Check that CSSOM did not mutate this rule. |
| 1517 RefPtrWillBeRawPtr<CSSRule> parsedRule = m_parsedFlatRules.at(it->value); |
| 1518 if (rule->cssText() != parsedRule->cssText()) |
| 1519 return nullptr; |
| 1520 |
| 1521 return m_sourceData->at(it->value); |
| 1379 } | 1522 } |
| 1380 | 1523 |
| 1381 void InspectorStyleSheet::collectFlatRules() | 1524 void InspectorStyleSheet::mapSourceDataToCSSOM() |
| 1382 { | 1525 { |
| 1383 m_flatRules.clear(); | 1526 m_ruleToSourceData.clear(); |
| 1384 ::collectFlatRules(m_pageStyleSheet.get(), &m_flatRules); | 1527 m_sourceDataToRule.clear(); |
| 1528 |
| 1529 m_cssomFlatRules.clear(); |
| 1530 CSSRuleVector& cssomRules = m_cssomFlatRules; |
| 1531 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); |
| 1532 |
| 1533 if (!m_sourceData) |
| 1534 return; |
| 1535 |
| 1536 CSSRuleVector& parsedRules = m_parsedFlatRules; |
| 1537 |
| 1538 Vector<String> cssomRulesText = Vector<String>(); |
| 1539 Vector<String> parsedRulesText = Vector<String>(); |
| 1540 for (size_t i = 0; i < cssomRules.size(); ++i) |
| 1541 cssomRulesText.append(cssomRules.at(i)->cssText()); |
| 1542 for (size_t j = 0; j < parsedRules.size(); ++j) |
| 1543 parsedRulesText.append(parsedRules.at(j)->cssText()); |
| 1544 |
| 1545 diff(cssomRulesText, parsedRulesText, &m_ruleToSourceData, &m_sourceDataToRu
le); |
| 1385 } | 1546 } |
| 1386 | 1547 |
| 1387 const CSSRuleVector& InspectorStyleSheet::flatRules() | 1548 const CSSRuleVector& InspectorStyleSheet::flatRules() |
| 1388 { | 1549 { |
| 1389 return m_flatRules; | 1550 return m_cssomFlatRules; |
| 1390 } | 1551 } |
| 1391 | 1552 |
| 1392 bool InspectorStyleSheet::resourceStyleSheetText(String* result) | 1553 bool InspectorStyleSheet::resourceStyleSheetText(String* result) |
| 1393 { | 1554 { |
| 1394 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin ==
TypeBuilder::CSS::StyleSheetOrigin::User_agent) | 1555 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin ==
TypeBuilder::CSS::StyleSheetOrigin::User_agent) |
| 1395 return false; | 1556 return false; |
| 1396 | 1557 |
| 1397 if (!m_pageStyleSheet->ownerDocument()) | 1558 if (!m_pageStyleSheet->ownerDocument()) |
| 1398 return false; | 1559 return false; |
| 1399 | 1560 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 } | 1660 } |
| 1500 | 1661 |
| 1501 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1662 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1502 { | 1663 { |
| 1503 visitor->trace(m_element); | 1664 visitor->trace(m_element); |
| 1504 visitor->trace(m_inspectorStyle); | 1665 visitor->trace(m_inspectorStyle); |
| 1505 InspectorStyleSheetBase::trace(visitor); | 1666 InspectorStyleSheetBase::trace(visitor); |
| 1506 } | 1667 } |
| 1507 | 1668 |
| 1508 } // namespace blink | 1669 } // namespace blink |
| OLD | NEW |