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

Side by Side Diff: Source/core/inspector/InspectorStyleSheet.cpp

Issue 172593003: DevTools: [CSS] Add CSS.editRangeInStyleSheetText() to the protocol (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix glitch Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 WTF_MAKE_FAST_ALLOCATED; 360 WTF_MAKE_FAST_ALLOCATED;
361 public: 361 public:
362 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet); 362 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet);
363 363
364 const String& text() const { ASSERT(m_hasText); return m_text; } 364 const String& text() const { ASSERT(m_hasText); return m_text; }
365 void setText(const String&); 365 void setText(const String&);
366 bool hasText() const { return m_hasText; } 366 bool hasText() const { return m_hasText; }
367 bool ensureSourceData(); 367 bool ensureSourceData();
368 bool hasSourceData() const { return m_sourceData; } 368 bool hasSourceData() const { return m_sourceData; }
369 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; 369 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const;
370 size_t size() const { return m_sourceData->size(); }
370 371
371 private: 372 private:
372 void flattenSourceData(RuleSourceDataList*); 373 void flattenSourceData(RuleSourceDataList*);
373 void setSourceData(PassOwnPtr<RuleSourceDataList>); 374 void setSourceData(PassOwnPtr<RuleSourceDataList>);
374 375
375 String m_text; 376 String m_text;
376 bool m_hasText; 377 bool m_hasText;
377 OwnPtr<RuleSourceDataList> m_sourceData; 378 OwnPtr<RuleSourceDataList> m_sourceData;
378 RefPtr<CSSStyleSheet> m_pageStyleSheet; 379 RefPtr<CSSStyleSheet> m_pageStyleSheet;
379 }; 380 };
380 381
381 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet) 382 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet)
382 : m_hasText(false) 383 : m_hasText(false)
383 , m_pageStyleSheet(pageStyleSheet) 384 , m_pageStyleSheet(pageStyleSheet)
384 { 385 {
385 } 386 }
386 387
387 void ParsedStyleSheet::setText(const String& text) 388 void ParsedStyleSheet::setText(const String& text)
388 { 389 {
389 m_hasText = true; 390 m_hasText = true;
390 m_text = text; 391 m_text = text.isNull() ? "" : text;
391 setSourceData(nullptr); 392 setSourceData(nullptr);
392 } 393 }
393 394
394 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) 395 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList)
395 { 396 {
396 for (size_t i = 0; i < dataList->size(); ++i) { 397 for (size_t i = 0; i < dataList->size(); ++i) {
397 RefPtr<CSSRuleSourceData>& data = dataList->at(i); 398 RefPtr<CSSRuleSourceData>& data = dataList->at(i);
398 if (data->type == CSSRuleSourceData::STYLE_RULE) { 399 if (data->type == CSSRuleSourceData::STYLE_RULE) {
399 m_sourceData->append(data); 400 m_sourceData->append(data);
400 } else if (data->type == CSSRuleSourceData::IMPORT_RULE) { 401 } else if (data->type == CSSRuleSourceData::IMPORT_RULE) {
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 return false; 925 return false;
925 if (!m_parsedStyleSheet) 926 if (!m_parsedStyleSheet)
926 return false; 927 return false;
927 928
928 m_parsedStyleSheet->setText(text); 929 m_parsedStyleSheet->setText(text);
929 m_flatRules.clear(); 930 m_flatRules.clear();
930 931
931 return true; 932 return true;
932 } 933 }
933 934
935 static SourceRange ruleSourceRange(const CSSRuleSourceData* ruleSourceData)
936 {
937 return SourceRange(ruleSourceData->ruleHeaderRange.start, ruleSourceData->ru leBodyRange.end);
938 }
939
940 static bool isSubRange(const SourceRange& ownerRange, const SourceRange& subRang e)
941 {
942 return ownerRange.start <= subRange.start && subRange.end <= ownerRange.end;
943 }
944
945 static bool verifyEditLocalizedToRule(const ParsedStyleSheet* originalData, cons t ParsedStyleSheet* modifiedData, const unsigned ruleIndex, ExceptionState& exce ptionState)
vsevik 2014/03/13 10:44:51 This method does something different from what its
946 {
947 if (originalData->size() != modifiedData->size()) {
948 exceptionState.throwDOMException(NotFoundError, "Edit should not damage rules.");
949 return false;
950 }
951
952 int sourceRangeDelta = originalData->text().length() - modifiedData->text(). length();
953 for (size_t i = ruleIndex + 1; i < originalData->size(); ++i) {
954 SourceRange originalRuleRange = ruleSourceRange(originalData->ruleSource DataAt(i).get());
955 SourceRange modifiedRuleRange = ruleSourceRange(modifiedData->ruleSource DataAt(i).get());
956 if (originalRuleRange.start != modifiedRuleRange.start + sourceRangeDelt a
957 || originalRuleRange.end != modifiedRuleRange.end + sourceRangeDelta ) {
958 exceptionState.throwDOMException(NotFoundError, "Edit should not dam age rules.");
959 return false;
960 }
961 }
962 return true;
963 }
964
965 static void countPropertiesDelta(const CSSStyleSourceData* originalStyle, const CSSStyleSourceData* modifiedStyle, size_t* firstChangedIndex, size_t* addedCount , size_t* removedCount)
966 {
967 const Vector<CSSPropertySourceData>& originalPropertyData = originalStyle->p ropertyData;
968 const Vector<CSSPropertySourceData>& modifiedPropertyData = modifiedStyle->p ropertyData;
969 int originalSize = originalPropertyData.size();
970 int modifiedSize = modifiedPropertyData.size();
971 int minSize = std::min(originalSize, modifiedSize);
972 int leadingCongruent = 0;
973 while (leadingCongruent < minSize) {
974 if (originalPropertyData.at(leadingCongruent).hash() != modifiedProperty Data.at(leadingCongruent).hash())
975 break;
976 ++leadingCongruent;
977 }
978 int trailingCongruent = 0;
979 while (trailingCongruent < minSize) {
980 if (originalPropertyData.at(originalSize - trailingCongruent - 1).hash() != modifiedPropertyData.at(modifiedSize - trailingCongruent - 1).hash())
981 break;
982 ++trailingCongruent;
983 }
984 *firstChangedIndex = leadingCongruent;
985 *addedCount = std::max(modifiedSize - leadingCongruent - trailingCongruent, 0);
986 *removedCount = std::max(originalSize - leadingCongruent - trailingCongruent , 0);
987 }
988
989 bool InspectorStyleSheet::handleSelectorEditScope(const CSSRuleSourceData* origi nalData, const CSSRuleSourceData* modifiedData, const String& modifiedText, cons t unsigned ruleIndex, EditRangeResult* editRangeResult, ExceptionState& exceptio nState)
990 {
991 size_t firstChangedIndex;
992 size_t addedCount;
993 size_t removedCount;
994 countPropertiesDelta(originalData->styleSourceData.get(), modifiedData->styl eSourceData.get(), &firstChangedIndex, &addedCount, &removedCount);
995 if (addedCount || removedCount) {
996 exceptionState.throwDOMException(NotFoundError, "Rule selector edit shou ld not damage rule properties.");
997 return false;
998 }
999 const String selectorText = modifiedText.substring(modifiedData->ruleHeaderR ange.start, modifiedData->ruleHeaderRange.length());
1000 if (!setRuleSelector(InspectorCSSId(id(), ruleIndex), selectorText, exceptio nState))
1001 return false;
1002 editRangeResult->rule = ruleForId(InspectorCSSId(id(), ruleIndex));
1003 return true;
1004 }
1005
1006 bool InspectorStyleSheet::handlePropertyScope(const CSSStyleSourceData* original Data, const CSSStyleSourceData* modifiedData, const unsigned ruleIndex, const Pr opertyScopeEditType editType, EditRangeResult* editRangeResult, ExceptionState& exceptionState)
1007 {
1008 size_t firstChangedIndex;
1009 size_t addedCount;
1010 size_t removedCount;
1011 countPropertiesDelta(originalData, modifiedData, &firstChangedIndex, &addedC ount, &removedCount);
1012 if (!addedCount && !removedCount) {
1013 editRangeResult->style = styleForId(InspectorCSSId(id(), ruleIndex));
1014 return true;
1015 }
1016 if (editType == EditExistingProperty && removedCount != 1) {
1017 exceptionState.throwDOMException(NotFoundError, "Rule property edit shou ld not damage more then one property.");
1018 return false;
1019 }
1020 if (editType == AppendNewProperty && removedCount) {
1021 exceptionState.throwDOMException(NotFoundError, "Rule property insertion should not damage any properties.");
1022 return false;
1023 }
1024 StringBuilder newPropertyText;
1025 for (size_t i = firstChangedIndex; i < firstChangedIndex + addedCount; ++i)
1026 newPropertyText.append(modifiedData->propertyData.at(i).toString());
1027 String placeholder;
1028 if (!setPropertyText(InspectorCSSId(id(), ruleIndex), firstChangedIndex, new PropertyText.toString(), editType == EditExistingProperty, &placeholder, excepti onState))
1029 return false;
1030 editRangeResult->style = styleForId(InspectorCSSId(id(), ruleIndex));
1031 return true;
1032 }
1033
1034 bool InspectorStyleSheet::handleStyleSheetEditScope(const ParsedStyleSheet* orig inalData, const ParsedStyleSheet* modifiedData, EditRangeResult* editRangeResult , ExceptionState& exceptionState)
1035 {
1036 size_t originalSize = originalData->size();
1037 size_t modifiedSize = modifiedData->size();
1038 if (modifiedSize - originalSize != 1) {
1039 exceptionState.throwDOMException(NotFoundError, "Editing in stylesheet s cope should insert a single rule.");
1040 return false;
1041 }
1042 size_t minSize = std::min(originalSize, modifiedSize);
vsevik 2014/03/13 10:44:51 size_t minSize = originalSize; So let's remove it.
1043 size_t leadingCongruent = 0;
1044 while (leadingCongruent < minSize) {
vsevik 2014/03/13 10:44:51 Can we use text for this instead?
1045 SourceRange originalRuleRange = ruleSourceRange(originalData->ruleSource DataAt(leadingCongruent).get());
1046 SourceRange modifiedRuleRange = ruleSourceRange(modifiedData->ruleSource DataAt(leadingCongruent).get());
1047 if (originalRuleRange.start != modifiedRuleRange.start || originalRuleRa nge.end != modifiedRuleRange.end)
1048 break;
1049 ++leadingCongruent;
1050 }
1051
1052 int sourceRangeDelta = originalData->text().length() - modifiedData->text(). length();
1053 size_t trailingCongruent = 0;
1054 while (trailingCongruent < minSize) {
1055 SourceRange originalRuleRange = ruleSourceRange(originalData->ruleSource DataAt(originalSize - trailingCongruent - 1).get());
1056 SourceRange modifiedRuleRange = ruleSourceRange(modifiedData->ruleSource DataAt(modifiedSize - trailingCongruent - 1).get());
1057 if (originalRuleRange.start != modifiedRuleRange.start + sourceRangeDelt a || originalRuleRange.end != modifiedRuleRange.end + sourceRangeDelta)
1058 break;
1059 ++trailingCongruent;
1060 }
1061 if (leadingCongruent + trailingCongruent != originalSize) {
1062 exceptionState.throwDOMException(NotFoundError, "Rules should not damage with edit in stylesheet scope.");
1063 return false;
1064 }
1065 setText(modifiedData->text(), ASSERT_NO_EXCEPTION);
1066 reparseStyleSheet(modifiedData->text());
1067 editRangeResult->rule = ruleForId(InspectorCSSId(id(), leadingCongruent));
1068 return true;
1069 }
1070
1071 bool InspectorStyleSheet::editRange(const String& text, unsigned startOffset, un signed endOffset, EditRangeResult* editRangeResult, ExceptionState& exceptionSta te)
1072 {
1073 String modifiedText;
1074 if (!getText(&modifiedText)) {
1075 exceptionState.throwDOMException(NotFoundError, "Stylesheet text could n ot be fetched.");
1076 return false;
1077 }
1078 modifiedText.replace(startOffset, endOffset - startOffset, text);
1079 OwnPtr<ParsedStyleSheet> editedParsedData = adoptPtr(new ParsedStyleSheet(m_ pageStyleSheet.get()));
1080 editedParsedData->setText(modifiedText);
1081 if (!m_parsedStyleSheet->ensureSourceData()) {
1082 exceptionState.throwDOMException(NotFoundError, "Original text could not be parsed.");
1083 return false;
1084 }
1085 if (!editedParsedData->ensureSourceData()) {
1086 exceptionState.throwDOMException(NotFoundError, "Edited text could not b e parsed.");
1087 return false;
1088 }
1089 if (m_parsedStyleSheet->size() - editedParsedData->size())
1090 return handleStyleSheetEditScope(m_parsedStyleSheet, editedParsedData.ge t(), editRangeResult, exceptionState);
1091
1092 SourceRange editRange = SourceRange(startOffset, endOffset);
1093 for (size_t i = 0; i < m_parsedStyleSheet->size(); ++i) {
1094 RefPtr<CSSRuleSourceData> ruleData = m_parsedStyleSheet->ruleSourceDataA t(i);
1095 if (!ruleData->styleSourceData)
1096 continue;
vsevik 2014/03/13 10:44:51 if (!editRange intersects with rule range) con
1097 if (isSubRange(ruleData->ruleHeaderRange, editRange)) {
1098 return verifyEditLocalizedToRule(m_parsedStyleSheet, editedParsedDat a.get(), i, exceptionState)
1099 && handleSelectorEditScope(m_parsedStyleSheet->ruleSourceDataAt( i).get(), editedParsedData->ruleSourceDataAt(i).get(), modifiedText, i, editRang eResult, exceptionState);
1100 }
1101 Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData- >propertyData;
1102 const CSSStyleSourceData* originalStyleData = m_parsedStyleSheet->ruleSo urceDataAt(i)->styleSourceData.get();
1103 const CSSStyleSourceData* modifiedStyleData = editedParsedData->ruleSour ceDataAt(i)->styleSourceData.get();
1104 if (editRange.length()) {
1105 for (size_t j = 0; j < propertyData.size(); ++j) {
1106 CSSPropertySourceData& property = propertyData.at(j);
1107 SourceRange globalPropertyRange = SourceRange(ruleData->ruleBody Range.start + property.range.start, ruleData->ruleBodyRange.start + property.ran ge.end);
1108 if (isSubRange(globalPropertyRange, editRange)) {
1109 return verifyEditLocalizedToRule(m_parsedStyleSheet, editedP arsedData.get(), i, exceptionState)
1110 && handlePropertyScope(originalStyleData, modifiedStyleD ata, i, EditExistingProperty, editRangeResult, exceptionState);
1111 }
1112 }
1113 } else if (isSubRange(ruleData->ruleBodyRange, editRange)) {
1114 return verifyEditLocalizedToRule(m_parsedStyleSheet, editedParsedDat a.get(), i, exceptionState)
1115 && handlePropertyScope(originalStyleData, modifiedStyleData, i, AppendNewProperty, editRangeResult, exceptionState);
1116 }
1117 }
1118 return handleStyleSheetEditScope(m_parsedStyleSheet, editedParsedData.get(), editRangeResult, exceptionState);
vsevik 2014/03/13 10:44:51 return false;
1119 }
1120
934 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) 1121 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState)
935 { 1122 {
936 CSSStyleRule* rule = ruleForId(id); 1123 CSSStyleRule* rule = ruleForId(id);
937 if (!rule) { 1124 if (!rule) {
938 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1125 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
939 return ""; 1126 return "";
940 } 1127 }
941 return rule->selectorText(); 1128 return rule->selectorText();
942 } 1129 }
943 1130
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 return m_pageStyleSheet->ownerDocument(); 1556 return m_pageStyleSheet->ownerDocument();
1370 } 1557 }
1371 1558
1372 PassRefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDec laration* style) const 1559 PassRefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDec laration* style) const
1373 { 1560 {
1374 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style)); 1561 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style));
1375 } 1562 }
1376 1563
1377 PassOwnPtr<Vector<unsigned> > InspectorStyleSheet::lineEndings() const 1564 PassOwnPtr<Vector<unsigned> > InspectorStyleSheet::lineEndings() const
1378 { 1565 {
1379 if (!m_parsedStyleSheet->hasText()) 1566 if (!ensureText())
1380 return PassOwnPtr<Vector<unsigned> >(); 1567 return PassOwnPtr<Vector<unsigned> >();
1381 return WTF::lineEndings(m_parsedStyleSheet->text()); 1568 return WTF::lineEndings(m_parsedStyleSheet->text());
1382 } 1569 }
1383 1570
1384 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c onst 1571 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c onst
1385 { 1572 {
1386 ensureFlatRules(); 1573 ensureFlatRules();
1387 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { 1574 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
1388 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); 1575 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get());
1389 if (styleRule && styleRule->style() == pageStyle) 1576 if (styleRule && styleRule->style() == pageStyle)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); 1666 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText);
1480 *result = text; 1667 *result = text;
1481 return true; 1668 return true;
1482 } 1669 }
1483 1670
1484 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const 1671 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const
1485 { 1672 {
1486 return ruleOrStyleId(rule->style()); 1673 return ruleOrStyleId(rule->style());
1487 } 1674 }
1488 1675
1676 bool InspectorStyleSheet::lineNumberAndColumnToOffset(unsigned lineNumber, unsig ned columnNumber, unsigned* offset) const
1677 {
1678 OwnPtr<Vector<unsigned> > endings = lineEndings();
1679 if (lineNumber >= endings->size())
1680 return false;
1681 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin gs->at(lineNumber - 1) - 1 : endings->at(0);
1682 if (columnNumber > charactersInLine)
1683 return false;
1684 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu mber::fromZeroBasedInt(columnNumber));
1685 *offset = position.toOffsetPosition(*endings).zeroBasedInt();
1686 return true;
1687 }
1688
1489 bool InspectorStyleSheet::originalStyleSheetText(String* result) const 1689 bool InspectorStyleSheet::originalStyleSheetText(String* result) const
1490 { 1690 {
1491 bool success = inlineStyleSheetText(result); 1691 bool success = inlineStyleSheetText(result);
1492 if (!success) 1692 if (!success)
1493 success = resourceStyleSheetText(result); 1693 success = resourceStyleSheetText(result);
1494 return success; 1694 return success;
1495 } 1695 }
1496 1696
1497 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const 1697 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const
1498 { 1698 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 } 1753 }
1554 1754
1555 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) 1755 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState)
1556 { 1756 {
1557 bool success = setStyleText(inlineStyle(), text); 1757 bool success = setStyleText(inlineStyle(), text);
1558 if (!success) 1758 if (!success)
1559 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); 1759 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id.");
1560 return success; 1760 return success;
1561 } 1761 }
1562 1762
1763 static PassRefPtr<CSSRuleSourceData> parseStyleDeclaration(Document& document, c onst String& text)
1764 {
1765 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate();
1766 RuleSourceDataList ruleSourceDataResult;
1767 StyleSheetHandler handler(text, &document, document.elementSheet().contents( ), &ruleSourceDataResult);
1768 createCSSParser(&document)->parseDeclaration(tempDeclaration.get(), text, &h andler, document.elementSheet().contents());
1769 return ruleSourceDataResult.first().release();
1770 }
1771
1772 bool InspectorStyleSheetForInlineStyle::editRange(const String& text, unsigned s tartOffset, unsigned endOffset, EditRangeResult* editRangeResult, ExceptionState & exceptionState)
1773 {
1774 String modifiedText;
1775 if (!getText(&modifiedText)) {
1776 exceptionState.throwDOMException(NotFoundError, "Inline style attribute text could not be fetched.");
1777 return false;
1778 }
1779 modifiedText.replace(startOffset, endOffset - startOffset, text);
1780
1781 RefPtr<CSSRuleSourceData> originalRuleData = getStyleAttributeData();
1782 RefPtr<CSSRuleSourceData> modifiedRuleData = parseStyleDeclaration(m_element ->document(), modifiedText);
1783
1784 CSSStyleSourceData* originalStyleData = originalRuleData->styleSourceData.ge t();
1785 CSSStyleSourceData* modifiedStyleData = modifiedRuleData->styleSourceData.ge t();
1786
1787 SourceRange editRange = SourceRange(startOffset, endOffset);
1788
1789 Vector<CSSPropertySourceData>& propertyData = originalStyleData->propertyDat a;
1790 if (editRange.length()) {
1791 for (size_t j = 0; j < propertyData.size(); ++j) {
1792 CSSPropertySourceData& property = propertyData.at(j);
1793 if (isSubRange(property.range, editRange))
1794 return handlePropertyScope(originalStyleData, modifiedStyleData, 0, EditExistingProperty, editRangeResult, exceptionState);
1795 }
1796 exceptionState.throwDOMException(NotFoundError, "Specified edit range do es not belong to any property.");
1797 return false;
1798 }
1799 return handlePropertyScope(originalStyleData, modifiedStyleData, 0, AppendNe wProperty, editRangeResult, exceptionState);
1800 }
1801
1563 bool InspectorStyleSheetForInlineStyle::getText(String* result) const 1802 bool InspectorStyleSheetForInlineStyle::getText(String* result) const
1564 { 1803 {
1565 if (!m_isStyleTextValid) { 1804 if (!m_isStyleTextValid) {
1566 m_styleText = elementStyleText(); 1805 m_styleText = elementStyleText();
1567 m_isStyleTextValid = true; 1806 m_isStyleTextValid = true;
1568 } 1807 }
1808 if (m_styleText.isNull())
1809 m_styleText = "";
1569 *result = m_styleText; 1810 *result = m_styleText;
1570 return true; 1811 return true;
1571 } 1812 }
1572 1813
1573 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text) 1814 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text)
1574 { 1815 {
1575 ASSERT_UNUSED(style, style == inlineStyle()); 1816 ASSERT_UNUSED(style, style == inlineStyle());
1576 TrackExceptionState exceptionState; 1817 TrackExceptionState exceptionState;
1577 1818
1578 { 1819 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const 1875 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const
1635 { 1876 {
1636 return m_element->getAttribute("style").string(); 1877 return m_element->getAttribute("style").string();
1637 } 1878 }
1638 1879
1639 PassRefPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::getStyleAttribu teData() const 1880 PassRefPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::getStyleAttribu teData() const
1640 { 1881 {
1641 if (!m_element->isStyledElement()) 1882 if (!m_element->isStyledElement())
1642 return nullptr; 1883 return nullptr;
1643 1884
1644 if (m_styleText.isEmpty()) { 1885 if (m_styleText.isEmpty()) {
vsevik 2014/03/13 10:44:51 This is not needed anymore.
1645 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour ceData::STYLE_RULE); 1886 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour ceData::STYLE_RULE);
1646 result->ruleBodyRange.start = 0; 1887 result->ruleBodyRange.start = 0;
1647 result->ruleBodyRange.end = 0; 1888 result->ruleBodyRange.end = 0;
1648 return result.release(); 1889 return result.release();
1649 } 1890 }
1650 1891
1651 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate(); 1892 return parseStyleDeclaration(m_element->document(), m_styleText);
1652 RuleSourceDataList ruleSourceDataResult;
1653 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult);
1654 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge t(), m_styleText, &handler, m_element->document().elementSheet().contents());
1655 return ruleSourceDataResult.first().release();
1656 } 1893 }
1657 1894
1658 } // namespace WebCore 1895 } // namespace WebCore
1659 1896
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698