Chromium Code Reviews| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 if (propertyCount != 1) | 419 if (propertyCount != 1) |
| 420 return false; | 420 return false; |
| 421 | 421 |
| 422 // Check for the property name. | 422 // Check for the property name. |
| 423 if (propertyData.at(0).name != bogusPropertyName) | 423 if (propertyData.at(0).name != bogusPropertyName) |
| 424 return false; | 424 return false; |
| 425 | 425 |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace | 429 void flattenSourceData(RuleSourceDataList* dataList, RuleSourceDataList* result) |
| 430 | |
| 431 class ParsedStyleSheet : public NoBaseWillBeGarbageCollectedFinalized<ParsedStyl eSheet> { | |
| 432 public: | |
| 433 static PassOwnPtrWillBeRawPtr<ParsedStyleSheet> create(Document* document) | |
| 434 { | |
| 435 return adoptPtrWillBeNoop(new ParsedStyleSheet(document)); | |
| 436 } | |
| 437 | |
| 438 const String& text() { ASSERT(m_hasText); return m_text; } | |
| 439 void setText(const String&); | |
| 440 bool hasText() { return m_hasText; } | |
| 441 bool ensureSourceData(); | |
| 442 bool hasSourceData() { return m_sourceData; } | |
| 443 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ruleSourceDataAt(unsigned); | |
| 444 unsigned ruleCount() { return m_sourceData->size(); } | |
| 445 | |
| 446 DECLARE_TRACE(); | |
| 447 | |
| 448 private: | |
| 449 explicit ParsedStyleSheet(Document*); | |
| 450 | |
| 451 void flattenSourceData(RuleSourceDataList*); | |
| 452 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>); | |
| 453 | |
| 454 String m_text; | |
| 455 bool m_hasText; | |
| 456 OwnPtrWillBeMember<RuleSourceDataList> m_sourceData; | |
| 457 RefPtrWillBeMember<Document> m_document; | |
| 458 }; | |
| 459 | |
| 460 ParsedStyleSheet::ParsedStyleSheet(Document* document) | |
| 461 : m_hasText(false) | |
| 462 , m_document(document) | |
| 463 { | |
| 464 } | |
| 465 | |
| 466 void ParsedStyleSheet::setText(const String& text) | |
| 467 { | |
| 468 m_hasText = true; | |
| 469 m_text = text; | |
| 470 setSourceData(nullptr); | |
| 471 } | |
| 472 | |
| 473 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) | |
| 474 { | 430 { |
| 475 for (size_t i = 0; i < dataList->size(); ++i) { | 431 for (size_t i = 0; i < dataList->size(); ++i) { |
| 476 RefPtrWillBeMember<CSSRuleSourceData>& data = dataList->at(i); | 432 RefPtrWillBeMember<CSSRuleSourceData>& data = dataList->at(i); |
| 477 | 433 |
| 478 // The m_sourceData->append()'ed types should be exactly the same as in collectFlatRules(). | 434 // The result->append()'ed types should be exactly the same as in collec tFlatRules(). |
| 479 switch (data->type) { | 435 switch (data->type) { |
| 480 case StyleRule::Style: | 436 case StyleRule::Style: |
| 481 case StyleRule::Import: | 437 case StyleRule::Import: |
| 482 case StyleRule::Page: | 438 case StyleRule::Page: |
| 483 case StyleRule::FontFace: | 439 case StyleRule::FontFace: |
| 484 case StyleRule::Viewport: | 440 case StyleRule::Viewport: |
| 485 case StyleRule::Keyframes: | 441 case StyleRule::Keyframes: |
| 486 m_sourceData->append(data); | 442 result->append(data); |
| 487 break; | 443 break; |
| 488 case StyleRule::Media: | 444 case StyleRule::Media: |
| 489 case StyleRule::Supports: | 445 case StyleRule::Supports: |
| 490 m_sourceData->append(data); | 446 result->append(data); |
| 491 flattenSourceData(&data->childRules); | 447 flattenSourceData(&data->childRules, result); |
| 492 break; | 448 break; |
| 493 default: | 449 default: |
| 494 break; | 450 break; |
| 495 } | 451 } |
| 496 } | 452 } |
| 497 } | 453 } |
| 498 | 454 |
| 499 bool ParsedStyleSheet::ensureSourceData() | 455 } // namespace |
| 500 { | |
| 501 if (hasSourceData()) | |
| 502 return true; | |
| 503 | |
| 504 if (!hasText()) | |
| 505 return false; | |
| 506 | |
| 507 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS ourceDataList()); | |
| 508 StyleSheetHandler handler(text(), m_document.get(), result.get()); | |
| 509 CSSParser::parseSheetForInspector(parserContextForDocument(m_document.get()) , text(), handler); | |
| 510 setSourceData(result.release()); | |
| 511 return hasSourceData(); | |
| 512 } | |
| 513 | |
| 514 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList> sourceData) | |
| 515 { | |
| 516 if (!sourceData) { | |
| 517 m_sourceData.clear(); | |
| 518 return; | |
| 519 } | |
| 520 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); | |
| 521 | |
| 522 // FIXME: This is a temporary solution to retain the original flat sourceDat a structure | |
| 523 // containing only style rules, even though BisonCSSParser now provides the full rule source data tree. | |
| 524 // Normally, we should just assign m_sourceData = sourceData; | |
| 525 flattenSourceData(sourceData.get()); | |
| 526 } | |
| 527 | |
| 528 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDat aAt(unsigned index) | |
| 529 { | |
| 530 if (!hasSourceData() || index >= m_sourceData->size()) | |
| 531 return nullptr; | |
| 532 | |
| 533 return m_sourceData->at(index); | |
| 534 } | |
| 535 | |
| 536 DEFINE_TRACE(ParsedStyleSheet) | |
| 537 { | |
| 538 visitor->trace(m_sourceData); | |
| 539 visitor->trace(m_document); | |
| 540 } | |
| 541 | 456 |
| 542 namespace blink { | 457 namespace blink { |
| 543 | 458 |
| 544 enum MediaListSource { | 459 enum MediaListSource { |
| 545 MediaListSourceLinkedSheet, | 460 MediaListSourceLinkedSheet, |
| 546 MediaListSourceInlineSheet, | 461 MediaListSourceInlineSheet, |
| 547 MediaListSourceMediaRule, | 462 MediaListSourceMediaRule, |
| 548 MediaListSourceImportRule | 463 MediaListSourceImportRule |
| 549 }; | 464 }; |
| 550 | 465 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 } | 723 } |
| 809 | 724 |
| 810 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent) | 725 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent) |
| 811 : InspectorStyleSheetBase(id, cssAgent) | 726 : InspectorStyleSheetBase(id, cssAgent) |
| 812 , m_cssAgent(cssAgent) | 727 , m_cssAgent(cssAgent) |
| 813 , m_resourceAgent(resourceAgent) | 728 , m_resourceAgent(resourceAgent) |
| 814 , m_pageStyleSheet(pageStyleSheet) | 729 , m_pageStyleSheet(pageStyleSheet) |
| 815 , m_origin(origin) | 730 , m_origin(origin) |
| 816 , m_documentURL(documentURL) | 731 , m_documentURL(documentURL) |
| 817 { | 732 { |
| 818 m_parsedStyleSheet = ParsedStyleSheet::create(m_pageStyleSheet->ownerDocumen t()); | 733 String text; |
| 734 bool success = inlineStyleSheetText(&text); | |
| 735 if (!success) | |
| 736 success = resourceStyleSheetText(&text); | |
| 737 if (success) | |
| 738 innerSetText(text, false); | |
| 819 } | 739 } |
| 820 | 740 |
| 821 InspectorStyleSheet::~InspectorStyleSheet() | 741 InspectorStyleSheet::~InspectorStyleSheet() |
| 822 { | 742 { |
| 823 } | 743 } |
| 824 | 744 |
| 825 DEFINE_TRACE(InspectorStyleSheet) | 745 DEFINE_TRACE(InspectorStyleSheet) |
| 826 { | 746 { |
| 827 visitor->trace(m_cssAgent); | 747 visitor->trace(m_cssAgent); |
| 828 visitor->trace(m_resourceAgent); | 748 visitor->trace(m_resourceAgent); |
| 829 visitor->trace(m_pageStyleSheet); | 749 visitor->trace(m_pageStyleSheet); |
| 830 visitor->trace(m_parsedStyleSheet); | 750 visitor->trace(m_sourceData); |
| 831 visitor->trace(m_flatRules); | 751 visitor->trace(m_flatRules); |
| 832 InspectorStyleSheetBase::trace(visitor); | 752 InspectorStyleSheetBase::trace(visitor); |
| 833 } | 753 } |
| 834 | 754 |
| 835 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) | 755 static String styleSheetURL(CSSStyleSheet* pageStyleSheet) |
| 836 { | 756 { |
| 837 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) | 757 if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty()) |
| 838 return pageStyleSheet->contents()->baseURL().string(); | 758 return pageStyleSheet->contents()->baseURL().string(); |
| 839 return emptyString(); | 759 return emptyString(); |
| 840 } | 760 } |
| 841 | 761 |
| 842 String InspectorStyleSheet::finalURL() | 762 String InspectorStyleSheet::finalURL() |
| 843 { | 763 { |
| 844 String url = styleSheetURL(m_pageStyleSheet.get()); | 764 String url = styleSheetURL(m_pageStyleSheet.get()); |
| 845 return url.isEmpty() ? m_documentURL : url; | 765 return url.isEmpty() ? m_documentURL : url; |
| 846 } | 766 } |
| 847 | 767 |
| 848 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) | 768 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) |
| 849 { | 769 { |
| 850 innerSetText(text); | 770 innerSetText(text, true); |
| 851 m_flatRules.clear(); | 771 m_flatRules.clear(); |
| 852 | 772 |
| 853 if (listener()) | 773 if (listener()) |
| 854 listener()->willReparseStyleSheet(); | 774 listener()->willReparseStyleSheet(); |
| 855 | 775 |
| 856 { | 776 { |
| 857 // Have a separate scope for clearRules() (bug 95324). | 777 // Have a separate scope for clearRules() (bug 95324). |
| 858 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); | 778 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); |
| 859 m_pageStyleSheet->contents()->clearRules(); | 779 m_pageStyleSheet->contents()->clearRules(); |
| 860 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); | 780 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 mediaRule->media()->setMediaText(text); | 855 mediaRule->media()->setMediaText(text); |
| 936 | 856 |
| 937 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); | 857 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); |
| 938 onStyleSheetTextChanged(); | 858 onStyleSheetTextChanged(); |
| 939 | 859 |
| 940 return mediaRule; | 860 return mediaRule; |
| 941 } | 861 } |
| 942 | 862 |
| 943 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) | 863 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) |
| 944 { | 864 { |
| 865 ASSERT(m_sourceData); | |
| 945 unsigned index = 0; | 866 unsigned index = 0; |
| 946 for (size_t i = 0; i < m_flatRules.size(); ++i) { | 867 for (size_t i = 0; i < m_flatRules.size() && i < m_sourceData->size(); ++i) { |
| 947 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i); | 868 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i); |
| 948 if (rule->parentRule() != parentMediaRule) | 869 if (rule->parentRule() != parentMediaRule) |
| 949 continue; | 870 continue; |
| 950 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); | 871 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at( i); |
| 951 if (ruleSourceData->ruleBodyRange.end < sourceRange.start) | 872 if (ruleSourceData->ruleBodyRange.end < sourceRange.start) |
| 952 ++index; | 873 ++index; |
| 953 } | 874 } |
| 954 return index; | 875 return index; |
| 955 } | 876 } |
| 956 | 877 |
| 957 CSSStyleRule* InspectorStyleSheet::insertCSSOMRuleInStyleSheet(const SourceRange & sourceRange, const String& ruleText, ExceptionState& exceptionState) | 878 CSSStyleRule* InspectorStyleSheet::insertCSSOMRuleInStyleSheet(const SourceRange & sourceRange, const String& ruleText, ExceptionState& exceptionState) |
| 958 { | 879 { |
| 959 unsigned index = ruleIndexBySourceRange(nullptr, sourceRange); | 880 unsigned index = ruleIndexBySourceRange(nullptr, sourceRange); |
| 960 m_pageStyleSheet->insertRule(ruleText, index, exceptionState); | 881 m_pageStyleSheet->insertRule(ruleText, index, exceptionState); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 977 if (!styleRule) { | 898 if (!styleRule) { |
| 978 mediaRule->deleteRule(index, ASSERT_NO_EXCEPTION); | 899 mediaRule->deleteRule(index, ASSERT_NO_EXCEPTION); |
| 979 exceptionState.throwDOMException(SyntaxError, "The rule '" + ruleText + "' could not be added in media rule."); | 900 exceptionState.throwDOMException(SyntaxError, "The rule '" + ruleText + "' could not be added in media rule."); |
| 980 return nullptr; | 901 return nullptr; |
| 981 } | 902 } |
| 982 return styleRule; | 903 return styleRule; |
| 983 } | 904 } |
| 984 | 905 |
| 985 CSSStyleRule* InspectorStyleSheet::insertCSSOMRuleBySourceRange(const SourceRang e& sourceRange, const String& ruleText, ExceptionState& exceptionState) | 906 CSSStyleRule* InspectorStyleSheet::insertCSSOMRuleBySourceRange(const SourceRang e& sourceRange, const String& ruleText, ExceptionState& exceptionState) |
| 986 { | 907 { |
| 908 ASSERT(m_sourceData); | |
| 909 | |
| 987 int containingRuleIndex = -1; | 910 int containingRuleIndex = -1; |
| 988 unsigned containingRuleLength = 0; | 911 unsigned containingRuleLength = 0; |
| 989 for (size_t i = 0; i < m_parsedStyleSheet->ruleCount(); ++i) { | 912 for (size_t i = 0; i < m_sourceData->size(); ++i) { |
| 990 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); | 913 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at( i); |
| 991 if (ruleSourceData->ruleHeaderRange.start < sourceRange.start && sourceR ange.start < ruleSourceData->ruleBodyRange.start) { | 914 if (ruleSourceData->ruleHeaderRange.start < sourceRange.start && sourceR ange.start < ruleSourceData->ruleBodyRange.start) { |
| 992 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule inside rule selector."); | 915 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule inside rule selector."); |
| 993 return nullptr; | 916 return nullptr; |
| 994 } | 917 } |
| 995 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc eData->ruleBodyRange.end < sourceRange.start) | 918 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc eData->ruleBodyRange.end < sourceRange.start) |
| 996 continue; | 919 continue; |
| 997 if (containingRuleIndex == -1 || containingRuleLength > ruleSourceData-> ruleBodyRange.length()) { | 920 if (containingRuleIndex == -1 || containingRuleLength > ruleSourceData-> ruleBodyRange.length()) { |
| 998 containingRuleIndex = i; | 921 containingRuleIndex = i; |
| 999 containingRuleLength = ruleSourceData->ruleBodyRange.length(); | 922 containingRuleLength = ruleSourceData->ruleBodyRange.length(); |
| 1000 } | 923 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1015 if (location.start != location.end) { | 938 if (location.start != location.end) { |
| 1016 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); | 939 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); |
| 1017 return nullptr; | 940 return nullptr; |
| 1018 } | 941 } |
| 1019 | 942 |
| 1020 if (!verifyRuleText(m_pageStyleSheet->ownerDocument(), ruleText)) { | 943 if (!verifyRuleText(m_pageStyleSheet->ownerDocument(), ruleText)) { |
| 1021 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; | 944 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; |
| 1022 return nullptr; | 945 return nullptr; |
| 1023 } | 946 } |
| 1024 | 947 |
| 1025 if (!ensureParsedDataReady()) { | 948 if (!m_sourceData) { |
| 1026 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t."); | 949 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); |
| 1027 return nullptr; | 950 return nullptr; |
| 1028 } | 951 } |
| 1029 ensureFlatRules(); | 952 ensureFlatRules(); |
| 1030 | 953 |
| 1031 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo cation, ruleText, exceptionState); | 954 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo cation, ruleText, exceptionState); |
| 1032 if (exceptionState.hadException()) | 955 if (exceptionState.hadException()) |
| 1033 return nullptr; | 956 return nullptr; |
| 1034 | 957 |
| 1035 replaceText(location, ruleText, addedRange, nullptr); | 958 replaceText(location, ruleText, addedRange, nullptr); |
| 1036 m_flatRules.clear(); | 959 m_flatRules.clear(); |
| 1037 | 960 |
| 1038 onStyleSheetTextChanged(); | 961 onStyleSheetTextChanged(); |
| 1039 return styleRule; | 962 return styleRule; |
| 1040 } | 963 } |
| 1041 | 964 |
| 1042 bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e xceptionState) | 965 bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e xceptionState) |
| 1043 { | 966 { |
| 967 if (!m_sourceData) { | |
| 968 exceptionState.throwDOMException(NotFoundError, "Style is read-only."); | |
| 969 return false; | |
| 970 } | |
| 971 | |
| 1044 // Find index of CSSRule that entirely belongs to the range. | 972 // Find index of CSSRule that entirely belongs to the range. |
| 1045 RefPtrWillBeRawPtr<CSSRule> rule = nullptr; | 973 RefPtrWillBeRawPtr<CSSRule> rule = nullptr; |
| 1046 unsigned containingRuleLength = 0; | 974 unsigned containingRuleLength = 0; |
| 1047 | 975 |
| 1048 for (size_t i = 0; i < m_flatRules.size() && i < m_parsedStyleSheet->ruleCou nt(); ++i) { | 976 for (size_t i = 0; i < m_flatRules.size() && i < m_sourceData->size(); ++i) { |
| 1049 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); | 977 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at( i); |
| 1050 unsigned ruleStart = ruleSourceData->ruleHeaderRange.start; | 978 unsigned ruleStart = ruleSourceData->ruleHeaderRange.start; |
| 1051 unsigned ruleEnd = ruleSourceData->ruleBodyRange.end + 1; | 979 unsigned ruleEnd = ruleSourceData->ruleBodyRange.end + 1; |
| 1052 bool startBelongs = ruleStart >= range.start && ruleStart < range.end; | 980 bool startBelongs = ruleStart >= range.start && ruleStart < range.end; |
| 1053 bool endBelongs = ruleEnd > range.start && ruleEnd <= range.end; | 981 bool endBelongs = ruleEnd > range.start && ruleEnd <= range.end; |
| 1054 | 982 |
| 1055 if (startBelongs != endBelongs) | 983 if (startBelongs != endBelongs) |
| 1056 break; | 984 break; |
| 1057 if (!startBelongs) | 985 if (!startBelongs) |
| 1058 continue; | 986 continue; |
| 1059 if (!rule || containingRuleLength > ruleSourceData->ruleBodyRange.length ()) { | 987 if (!rule || containingRuleLength > ruleSourceData->ruleBodyRange.length ()) { |
| 1060 containingRuleLength = ruleSourceData->ruleBodyRange.length(); | 988 containingRuleLength = ruleSourceData->ruleBodyRange.length(); |
| 1061 rule = m_flatRules.at(i).get(); | 989 rule = m_flatRules.at(i).get(); |
| 1062 } | 990 } |
| 1063 } | 991 } |
| 1064 if (!rule) { | 992 if (!rule) { |
| 1065 exceptionState.throwDOMException(NotFoundError, "No style rule could be found in given range."); | 993 exceptionState.throwDOMException(NotFoundError, "No style rule could be found in given range."); |
| 1066 return false; | 994 return false; |
| 1067 } | 995 } |
| 1068 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); | 996 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); |
| 1069 if (!styleSheet || !ensureParsedDataReady()) { | 997 if (!styleSheet) { |
| 1070 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); | 998 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); |
| 1071 return false; | 999 return false; |
| 1072 } | 1000 } |
| 1073 CSSRule* parentRule = rule->parentRule(); | 1001 CSSRule* parentRule = rule->parentRule(); |
| 1074 if (parentRule) { | 1002 if (parentRule) { |
| 1075 if (parentRule->type() != CSSRule::MEDIA_RULE) { | 1003 if (parentRule->type() != CSSRule::MEDIA_RULE) { |
| 1076 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule."); | 1004 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule."); |
| 1077 return false; | 1005 return false; |
| 1078 } | 1006 } |
| 1079 CSSMediaRule* parentMediaRule = toCSSMediaRule(parentRule); | 1007 CSSMediaRule* parentMediaRule = toCSSMediaRule(parentRule); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1095 return false; | 1023 return false; |
| 1096 | 1024 |
| 1097 replaceText(range, "", nullptr, nullptr); | 1025 replaceText(range, "", nullptr, nullptr); |
| 1098 m_flatRules.clear(); | 1026 m_flatRules.clear(); |
| 1099 onStyleSheetTextChanged(); | 1027 onStyleSheetTextChanged(); |
| 1100 return true; | 1028 return true; |
| 1101 } | 1029 } |
| 1102 | 1030 |
| 1103 void InspectorStyleSheet::replaceText(const SourceRange& range, const String& te xt, SourceRange* newRange, String* oldText) | 1031 void InspectorStyleSheet::replaceText(const SourceRange& range, const String& te xt, SourceRange* newRange, String* oldText) |
| 1104 { | 1032 { |
| 1105 String sheetText = m_parsedStyleSheet->text(); | 1033 String sheetText = m_text; |
|
lushnikov
2015/06/23 17:58:44
you can avoid this cloning
| |
| 1106 if (oldText) | 1034 if (oldText) |
| 1107 *oldText = sheetText.substring(range.start, range.length()); | 1035 *oldText = sheetText.substring(range.start, range.length()); |
| 1108 sheetText.replace(range.start, range.length(), text); | 1036 sheetText.replace(range.start, range.length(), text); |
| 1109 if (newRange) | 1037 if (newRange) |
| 1110 *newRange = SourceRange(range.start, range.start + text.length()); | 1038 *newRange = SourceRange(range.start, range.start + text.length()); |
| 1111 innerSetText(sheetText); | 1039 innerSetText(sheetText, true); |
| 1112 } | 1040 } |
| 1113 | 1041 |
| 1114 void InspectorStyleSheet::innerSetText(const String& newText) | 1042 void InspectorStyleSheet::innerSetText(const String& text, bool markAsLocallyMod ified) |
| 1115 { | 1043 { |
| 1116 Element* element = ownerStyleElement(); | 1044 OwnPtrWillBeRawPtr<RuleSourceDataList> ruleTree = adoptPtrWillBeNoop(new Rul eSourceDataList()); |
| 1117 if (element) | 1045 StyleSheetHandler handler(text, m_pageStyleSheet->ownerDocument(), ruleTree. get()); |
| 1118 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); | 1046 CSSParser::parseSheetForInspector(parserContextForDocument(m_pageStyleSheet- >ownerDocument()), text, handler); |
| 1119 else | 1047 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); |
| 1120 m_cssAgent->addEditedStyleSheet(finalURL(), newText); | 1048 flattenSourceData(ruleTree.get(), m_sourceData.get()); |
| 1121 m_parsedStyleSheet->setText(newText); | 1049 m_text = text; |
| 1050 | |
| 1051 if (markAsLocallyModified) { | |
| 1052 Element* element = ownerStyleElement(); | |
| 1053 if (element) | |
| 1054 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), te xt); | |
| 1055 else | |
| 1056 m_cssAgent->addEditedStyleSheet(finalURL(), text); | |
| 1057 } | |
| 1122 } | 1058 } |
| 1123 | 1059 |
| 1124 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() | 1060 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() |
| 1125 { | 1061 { |
| 1126 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1062 CSSStyleSheet* styleSheet = pageStyleSheet(); |
| 1127 if (!styleSheet) | 1063 if (!styleSheet) |
| 1128 return nullptr; | 1064 return nullptr; |
| 1129 | 1065 |
| 1130 Document* document = styleSheet->ownerDocument(); | 1066 Document* document = styleSheet->ownerDocument(); |
| 1131 LocalFrame* frame = document ? document->frame() : nullptr; | 1067 LocalFrame* frame = document ? document->frame() : nullptr; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); | 1109 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); |
| 1174 result->addItem(simpleSelector.release()); | 1110 result->addItem(simpleSelector.release()); |
| 1175 } | 1111 } |
| 1176 return result.release(); | 1112 return result.release(); |
| 1177 } | 1113 } |
| 1178 | 1114 |
| 1179 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) | 1115 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) |
| 1180 { | 1116 { |
| 1181 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 1117 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1182 unsigned ruleIndex = indexOf(rule->style()); | 1118 unsigned ruleIndex = indexOf(rule->style()); |
| 1183 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) { | 1119 if (ruleIndex != UINT_MAX && m_sourceData && ruleIndex < m_sourceData->size( )) |
| 1184 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | 1120 sourceData = m_sourceData->at(ruleIndex); |
| 1185 } | |
| 1186 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; | 1121 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; |
| 1187 | 1122 |
| 1188 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). | 1123 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). |
| 1189 String selectorText = rule->selectorText(); | 1124 String selectorText = rule->selectorText(); |
| 1190 | 1125 |
| 1191 if (sourceData) | 1126 if (sourceData) |
| 1192 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); | 1127 selectors = selectorsFromSource(sourceData.get(), m_text); |
| 1193 else { | 1128 else { |
| 1194 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); | 1129 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); |
| 1195 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); | 1130 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| 1196 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) | 1131 for (const CSSSelector* selector = selectorList.first(); selector; selec tor = CSSSelectorList::next(*selector)) |
| 1197 selectors->addItem(TypeBuilder::CSS::Selector::create().setValue(sel ector->selectorText()).release()); | 1132 selectors->addItem(TypeBuilder::CSS::Selector::create().setValue(sel ector->selectorText()).release()); |
| 1198 } | 1133 } |
| 1199 RefPtr<TypeBuilder::CSS::SelectorList> result = TypeBuilder::CSS::SelectorLi st::create() | 1134 RefPtr<TypeBuilder::CSS::SelectorList> result = TypeBuilder::CSS::SelectorLi st::create() |
| 1200 .setSelectors(selectors) | 1135 .setSelectors(selectors) |
| 1201 .setText(selectorText) | 1136 .setText(selectorText) |
| 1202 .release(); | 1137 .release(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1225 } | 1160 } |
| 1226 | 1161 |
| 1227 if (mediaStack) | 1162 if (mediaStack) |
| 1228 result->setMedia(mediaStack); | 1163 result->setMedia(mediaStack); |
| 1229 | 1164 |
| 1230 return result.release(); | 1165 return result.release(); |
| 1231 } | 1166 } |
| 1232 | 1167 |
| 1233 bool InspectorStyleSheet::getText(String* result) | 1168 bool InspectorStyleSheet::getText(String* result) |
| 1234 { | 1169 { |
| 1235 if (!ensureText()) | 1170 if (m_sourceData) { |
| 1236 return false; | 1171 *result = m_text; |
| 1237 *result = m_parsedStyleSheet->text(); | 1172 return true; |
| 1238 return true; | 1173 } |
| 1174 return false; | |
| 1239 } | 1175 } |
| 1240 | 1176 |
| 1241 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) | 1177 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) |
| 1242 { | 1178 { |
| 1243 if (!ensureParsedDataReady()) | 1179 if (!m_sourceData) |
| 1244 return nullptr; | 1180 return nullptr; |
| 1245 | 1181 |
| 1246 ensureFlatRules(); | 1182 ensureFlatRules(); |
| 1247 size_t index = m_flatRules.find(rule); | 1183 size_t index = m_flatRules.find(rule); |
| 1248 // FIXME(lusnikov): m_flatRules are not always aligned with the m_parsedStyl eSheet rule source | 1184 // FIXME(lusnikov): m_flatRules are not always aligned with the m_sourceData rule source |
| 1249 // datas due to the CSSOM operations that add/remove rules without changing source. | 1185 // datas due to the CSSOM operations that add/remove rules without changing source. |
| 1250 // This is a design issue. See crbug.com/178410 | 1186 // This is a design issue. See crbug.com/178410 |
| 1251 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) | 1187 if (index == kNotFound || index >= m_sourceData->size()) |
| 1252 return nullptr; | 1188 return nullptr; |
| 1253 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); | 1189 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_sourceData->at(static_c ast<unsigned>(index)); |
| 1254 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings()); | 1190 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings()); |
| 1255 } | 1191 } |
| 1256 | 1192 |
| 1257 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpValu eSourceRange(const CSSRule* rule, size_t mediaQueryIndex, size_t mediaQueryExpIn dex) | 1193 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpValu eSourceRange(const CSSRule* rule, size_t mediaQueryIndex, size_t mediaQueryExpIn dex) |
| 1258 { | 1194 { |
| 1259 if (!ensureParsedDataReady()) | 1195 if (!m_sourceData) |
| 1260 return nullptr; | 1196 return nullptr; |
| 1261 ensureFlatRules(); | 1197 ensureFlatRules(); |
| 1262 size_t index = m_flatRules.find(rule); | 1198 size_t index = m_flatRules.find(rule); |
| 1263 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) | 1199 if (index == kNotFound || index >= m_sourceData->size()) |
| 1264 return nullptr; | 1200 return nullptr; |
| 1265 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); | 1201 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_sourceData->at(static_c ast<unsigned>(index)); |
| 1266 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) | 1202 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) |
| 1267 return nullptr; | 1203 return nullptr; |
| 1268 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); | 1204 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); |
| 1269 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) | 1205 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) |
| 1270 return nullptr; | 1206 return nullptr; |
| 1271 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); | 1207 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); |
| 1272 } | 1208 } |
| 1273 | 1209 |
| 1274 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyle(RefPt rWillBeRawPtr<CSSStyleDeclaration> style) | 1210 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyle(RefPt rWillBeRawPtr<CSSStyleDeclaration> style) |
| 1275 { | 1211 { |
| 1276 if (!style) | 1212 if (!style) |
| 1277 return nullptr; | 1213 return nullptr; |
| 1278 | 1214 |
| 1279 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 1215 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1280 unsigned ruleIndex = indexOf(style.get()); | 1216 unsigned ruleIndex = indexOf(style.get()); |
| 1281 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | 1217 if (ruleIndex != UINT_MAX && m_sourceData && ruleIndex < m_sourceData->size( )) |
| 1282 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | 1218 sourceData = m_sourceData->at(ruleIndex); |
| 1283 | 1219 |
| 1284 if (ruleIndex == UINT_MAX) { | 1220 if (ruleIndex == UINT_MAX) { |
| 1285 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. | 1221 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. |
| 1286 // See InspectorCSSAgent::buildObjectForRule for details. | 1222 // See InspectorCSSAgent::buildObjectForRule for details. |
| 1287 return InspectorStyle::create(style, nullptr, this); | 1223 return InspectorStyle::create(style, nullptr, this); |
| 1288 } | 1224 } |
| 1289 | 1225 |
| 1290 return InspectorStyle::create(style, sourceData, this); | 1226 return InspectorStyle::create(style, sourceData, this); |
| 1291 } | 1227 } |
| 1292 | 1228 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { | 1307 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { |
| 1372 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); | 1308 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); |
| 1373 if (styleRule && styleRule->style() == style) | 1309 if (styleRule && styleRule->style() == style) |
| 1374 return i; | 1310 return i; |
| 1375 } | 1311 } |
| 1376 return UINT_MAX; | 1312 return UINT_MAX; |
| 1377 } | 1313 } |
| 1378 | 1314 |
| 1379 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) | 1315 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) |
| 1380 { | 1316 { |
| 1381 if (!ensureParsedDataReady()) | 1317 if (!m_sourceData) |
| 1382 return false; | 1318 return false; |
| 1383 ensureFlatRules(); | 1319 ensureFlatRules(); |
| 1384 | 1320 |
| 1385 for (size_t i = 0; i < m_parsedStyleSheet->ruleCount() && i < m_flatRules.si ze(); ++i) { | 1321 for (size_t i = 0; i < m_sourceData->size() && i < m_flatRules.size(); ++i) { |
| 1386 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); | 1322 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at( i); |
| 1387 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { | 1323 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { |
| 1388 *pRule = m_flatRules.at(i).get(); | 1324 *pRule = m_flatRules.at(i).get(); |
| 1389 if (!(*pRule)->parentStyleSheet()) | 1325 if (!(*pRule)->parentStyleSheet()) |
| 1390 return false; | 1326 return false; |
| 1391 *pSourceData = ruleSourceData.get(); | 1327 *pSourceData = ruleSourceData.get(); |
| 1392 return true; | 1328 return true; |
| 1393 } | 1329 } |
| 1394 } | 1330 } |
| 1395 return false; | 1331 return false; |
| 1396 } | 1332 } |
| 1397 | 1333 |
| 1398 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) | 1334 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) |
| 1399 { | 1335 { |
| 1400 if (!ensureParsedDataReady()) | 1336 if (!m_sourceData) |
| 1401 return false; | 1337 return false; |
| 1402 ensureFlatRules(); | 1338 ensureFlatRules(); |
| 1403 | 1339 |
| 1404 for (size_t i = 0; i < m_parsedStyleSheet->ruleCount() && i < m_flatRules.si ze(); ++i) { | 1340 for (size_t i = 0; i < m_sourceData->size() && i < m_flatRules.size(); ++i) { |
| 1405 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); | 1341 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_sourceData->at( i); |
| 1406 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { | 1342 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { |
| 1407 *pRule = m_flatRules.at(i).get(); | 1343 *pRule = m_flatRules.at(i).get(); |
| 1408 if (!(*pRule)->parentStyleSheet()) | 1344 if (!(*pRule)->parentStyleSheet()) |
| 1409 return false; | 1345 return false; |
| 1410 *pSourceData = ruleSourceData.get(); | 1346 *pSourceData = ruleSourceData.get(); |
| 1411 return true; | 1347 return true; |
| 1412 } | 1348 } |
| 1413 } | 1349 } |
| 1414 return false; | 1350 return false; |
| 1415 } | 1351 } |
| 1416 | 1352 |
| 1417 const CSSRuleVector& InspectorStyleSheet::flatRules() | 1353 const CSSRuleVector& InspectorStyleSheet::flatRules() |
| 1418 { | 1354 { |
| 1419 ensureFlatRules(); | 1355 ensureFlatRules(); |
| 1420 return m_flatRules; | 1356 return m_flatRules; |
| 1421 } | 1357 } |
| 1422 | 1358 |
| 1423 bool InspectorStyleSheet::ensureParsedDataReady() | |
| 1424 { | |
| 1425 return ensureText() && m_parsedStyleSheet->ensureSourceData(); | |
| 1426 } | |
| 1427 | |
| 1428 bool InspectorStyleSheet::ensureText() | |
| 1429 { | |
| 1430 if (m_parsedStyleSheet->hasText()) | |
| 1431 return true; | |
| 1432 | |
| 1433 String text; | |
| 1434 bool success = originalStyleSheetText(&text); | |
| 1435 if (success) | |
| 1436 m_parsedStyleSheet->setText(text); | |
| 1437 // No need to clear m_flatRules here - it's empty. | |
| 1438 | |
| 1439 return success; | |
| 1440 } | |
| 1441 | |
| 1442 template <typename RuleList> | 1359 template <typename RuleList> |
| 1443 static void collectFlatRules(RuleList ruleList, CSSRuleVector* result) | 1360 static void collectFlatRules(RuleList ruleList, CSSRuleVector* result) |
| 1444 { | 1361 { |
| 1445 if (!ruleList) | 1362 if (!ruleList) |
| 1446 return; | 1363 return; |
| 1447 | 1364 |
| 1448 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { | 1365 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
| 1449 CSSRule* rule = ruleList->item(i); | 1366 CSSRule* rule = ruleList->item(i); |
| 1450 | 1367 |
| 1451 // The result->append()'ed types should be exactly the same as in Parsed StyleSheet::flattenSourceData(). | 1368 // The result->append()'ed types should be exactly the same as in flatte nSourceData(). |
| 1452 switch (rule->type()) { | 1369 switch (rule->type()) { |
| 1453 case CSSRule::STYLE_RULE: | 1370 case CSSRule::STYLE_RULE: |
| 1454 case CSSRule::IMPORT_RULE: | 1371 case CSSRule::IMPORT_RULE: |
| 1455 case CSSRule::CHARSET_RULE: | 1372 case CSSRule::CHARSET_RULE: |
| 1456 case CSSRule::PAGE_RULE: | 1373 case CSSRule::PAGE_RULE: |
| 1457 case CSSRule::FONT_FACE_RULE: | 1374 case CSSRule::FONT_FACE_RULE: |
| 1458 case CSSRule::VIEWPORT_RULE: | 1375 case CSSRule::VIEWPORT_RULE: |
| 1459 case CSSRule::KEYFRAMES_RULE: | 1376 case CSSRule::KEYFRAMES_RULE: |
| 1460 result->append(rule); | 1377 result->append(rule); |
| 1461 break; | 1378 break; |
| 1462 case CSSRule::MEDIA_RULE: | 1379 case CSSRule::MEDIA_RULE: |
| 1463 case CSSRule::SUPPORTS_RULE: | 1380 case CSSRule::SUPPORTS_RULE: |
| 1464 result->append(rule); | 1381 result->append(rule); |
| 1465 collectFlatRules(asCSSRuleList(rule), result); | 1382 collectFlatRules(asCSSRuleList(rule), result); |
| 1466 break; | 1383 break; |
| 1467 default: | 1384 default: |
| 1468 break; | 1385 break; |
| 1469 } | 1386 } |
| 1470 } | 1387 } |
| 1471 } | 1388 } |
| 1472 | 1389 |
| 1473 void InspectorStyleSheet::ensureFlatRules() | 1390 void InspectorStyleSheet::ensureFlatRules() |
| 1474 { | 1391 { |
| 1475 // We are fine with redoing this for empty stylesheets as this will run fast . | 1392 // We are fine with redoing this for empty stylesheets as this will run fast . |
| 1476 if (m_flatRules.isEmpty()) | 1393 if (m_flatRules.isEmpty()) |
| 1477 collectFlatRules(pageStyleSheet(), &m_flatRules); | 1394 collectFlatRules(pageStyleSheet(), &m_flatRules); |
| 1478 } | 1395 } |
| 1479 | 1396 |
| 1480 bool InspectorStyleSheet::originalStyleSheetText(String* result) | |
| 1481 { | |
| 1482 bool success = inlineStyleSheetText(result); | |
| 1483 if (!success) | |
| 1484 success = resourceStyleSheetText(result); | |
| 1485 return success; | |
| 1486 } | |
| 1487 | |
| 1488 bool InspectorStyleSheet::resourceStyleSheetText(String* result) | 1397 bool InspectorStyleSheet::resourceStyleSheetText(String* result) |
| 1489 { | 1398 { |
| 1490 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin == TypeBuilder::CSS::StyleSheetOrigin::User_agent) | 1399 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin == TypeBuilder::CSS::StyleSheetOrigin::User_agent) |
| 1491 return false; | 1400 return false; |
| 1492 | 1401 |
| 1493 if (!m_pageStyleSheet->ownerDocument()) | 1402 if (!m_pageStyleSheet->ownerDocument()) |
| 1494 return false; | 1403 return false; |
| 1495 | 1404 |
| 1496 KURL url(ParsedURLString, m_pageStyleSheet->href()); | 1405 KURL url(ParsedURLString, m_pageStyleSheet->href()); |
| 1497 if (m_cssAgent->getEditedStyleSheet(url, result)) | 1406 if (m_cssAgent->getEditedStyleSheet(url, result)) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 } | 1504 } |
| 1596 | 1505 |
| 1597 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1506 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1598 { | 1507 { |
| 1599 visitor->trace(m_element); | 1508 visitor->trace(m_element); |
| 1600 visitor->trace(m_inspectorStyle); | 1509 visitor->trace(m_inspectorStyle); |
| 1601 InspectorStyleSheetBase::trace(visitor); | 1510 InspectorStyleSheetBase::trace(visitor); |
| 1602 } | 1511 } |
| 1603 | 1512 |
| 1604 } // namespace blink | 1513 } // namespace blink |
| OLD | NEW |