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

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

Issue 1181213007: DevTools: introduce CSS.setStyleText, we'll migrate setPropertyText to it later. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: win fixed Created 5 years, 6 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
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | Source/devtools/protocol.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> data = CSSMediaQuerySourceData:: create(); 325 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> data = CSSMediaQuerySourceData:: create();
326 m_currentMediaQueryData = data; 326 m_currentMediaQueryData = data;
327 m_currentRuleDataStack.last()->mediaSourceData->queryData.append(data); 327 m_currentRuleDataStack.last()->mediaSourceData->queryData.append(data);
328 } 328 }
329 329
330 void StyleSheetHandler::endMediaQuery() 330 void StyleSheetHandler::endMediaQuery()
331 { 331 {
332 m_currentMediaQueryData.clear(); 332 m_currentMediaQueryData.clear();
333 } 333 }
334 334
335 bool verifyRuleText(Document* document, const String& ruleText)
336 {
337 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
338 RuleSourceDataList sourceData;
339 String text = ruleText + " div { " + bogusPropertyName + ": none; }";
340 StyleSheetHandler handler(text, document, &sourceData);
341 CSSParser::parseSheetForInspector(parserContextForDocument(document), text, handler);
342 unsigned ruleCount = sourceData.size();
343
344 // Exactly two rules should be parsed.
345 if (ruleCount != 2)
346 return false;
347
348 // Added rule must be style rule.
349 if (!sourceData.at(0)->styleSourceData)
350 return false;
351
352 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(1)->st yleSourceData->propertyData;
353 unsigned propertyCount = propertyData.size();
354
355 // Exactly one property should be in rule.
356 if (propertyCount != 1)
357 return false;
358
359 // Check for the property name.
360 if (propertyData.at(0).name != bogusPropertyName)
361 return false;
362
363 return true;
364 }
365
366 bool verifyStyleText(Document* document, const String& text)
367 {
368 return verifyRuleText(document, "div {" + text + "}");
369 }
370
371 bool verifySelectorText(Document* document, const String& selectorText)
372 {
373 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
374 RuleSourceDataList sourceData;
375 String text = selectorText + " { " + bogusPropertyName + ": none; }";
376 StyleSheetHandler handler(text, document, &sourceData);
377 CSSParser::parseSheetForInspector(parserContextForDocument(document), text, handler);
378
379 // Exactly one rule should be parsed.
380 unsigned ruleCount = sourceData.size();
381 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style)
382 return false;
383
384 // Exactly one property should be in style rule.
385 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st yleSourceData->propertyData;
386 unsigned propertyCount = propertyData.size();
387 if (propertyCount != 1)
388 return false;
389
390 // Check for the property name.
391 if (propertyData.at(0).name != bogusPropertyName)
392 return false;
393
394 return true;
395 }
396
397 bool verifyMediaText(Document* document, const String& mediaText)
398 {
399 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
400 RuleSourceDataList sourceData;
401 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n one; } }";
402 StyleSheetHandler handler(text, document, &sourceData);
403 CSSParser::parseSheetForInspector(parserContextForDocument(document), text, handler);
404
405 // Exactly one media rule should be parsed.
406 unsigned ruleCount = sourceData.size();
407 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media)
408 return false;
409
410 // Media rule should have exactly one style rule child.
411 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules;
412 ruleCount = childSourceData.size();
413 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData)
414 return false;
415
416 // Exactly one property should be in style rule.
417 WillBeHeapVector<CSSPropertySourceData>& propertyData = childSourceData.at(0 )->styleSourceData->propertyData;
418 unsigned propertyCount = propertyData.size();
419 if (propertyCount != 1)
420 return false;
421
422 // Check for the property name.
423 if (propertyData.at(0).name != bogusPropertyName)
424 return false;
425
426 return true;
427 }
428
335 } // namespace 429 } // namespace
336 430
337 class ParsedStyleSheet : public NoBaseWillBeGarbageCollectedFinalized<ParsedStyl eSheet> { 431 class ParsedStyleSheet : public NoBaseWillBeGarbageCollectedFinalized<ParsedStyl eSheet> {
338 public: 432 public:
339 static PassOwnPtrWillBeRawPtr<ParsedStyleSheet> create(CSSStyleSheet* pageSt yleSheet) 433 static PassOwnPtrWillBeRawPtr<ParsedStyleSheet> create(CSSStyleSheet* pageSt yleSheet)
340 { 434 {
341 return adoptPtrWillBeNoop(new ParsedStyleSheet(pageStyleSheet)); 435 return adoptPtrWillBeNoop(new ParsedStyleSheet(pageStyleSheet));
342 } 436 }
343 437
344 const String& text() const { ASSERT(m_hasText); return m_text; } 438 const String& text() const { ASSERT(m_hasText); return m_text; }
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 m_pageStyleSheet->contents()->parseString(text); 1094 m_pageStyleSheet->contents()->parseString(text);
1001 } 1095 }
1002 1096
1003 if (listener()) 1097 if (listener())
1004 listener()->didReparseStyleSheet(); 1098 listener()->didReparseStyleSheet();
1005 onStyleSheetTextChanged(); 1099 onStyleSheetTextChanged();
1006 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); 1100 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate);
1007 return true; 1101 return true;
1008 } 1102 }
1009 1103
1010 CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, con st String& text, SourceRange* newRange, String* oldText, ExceptionState& excepti onState) 1104 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce ptionState& exceptionState)
1011 { 1105 {
1012 if (!verifySelectorText(text)) { 1106 if (!verifySelectorText(ownerDocument(), text)) {
1013 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); 1107 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1014 return nullptr; 1108 return nullptr;
1015 } 1109 }
1016 1110
1017 CSSRule* rule = nullptr; 1111 CSSRule* rule = nullptr;
1018 CSSRuleSourceData* sourceData = nullptr; 1112 CSSRuleSourceData* sourceData = nullptr;
1019 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) { 1113 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) {
1020 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); 1114 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range");
1021 return nullptr; 1115 return nullptr;
1022 } 1116 }
1023 1117
1024 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule); 1118 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleR ule(rule);
1025 styleRule->setSelectorText(text); 1119 styleRule->setSelectorText(text);
1026 1120
1027 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); 1121 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1028 onStyleSheetTextChanged(); 1122 onStyleSheetTextChanged();
1029 1123
1030 return styleRule; 1124 return styleRule;
1031 } 1125 }
1032 1126
1033 CSSMediaRule* InspectorStyleSheet::setMediaRuleText(const SourceRange& range, co nst String& text, SourceRange* newRange, String* oldText, ExceptionState& except ionState) 1127 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti onState& exceptionState)
1034 { 1128 {
1035 if (!verifyMediaText(text)) { 1129 if (!verifyStyleText(ownerDocument(), text)) {
1130 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." );
1131 return nullptr;
1132 }
1133
1134 CSSRule* rule = nullptr;
1135 CSSRuleSourceData* sourceData = nullptr;
1136 if (!findRuleByBodyRange(range, &rule, &sourceData) || !sourceData->styleSou rceData || rule->type() != CSSRule::STYLE_RULE) {
1137 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing style source range");
1138 return nullptr;
1139 }
1140
1141 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu le(rule);
1142 styleRule->style()->setCSSText(text, exceptionState);
1143
1144 replaceText(sourceData->ruleBodyRange, text, newRange, oldText);
1145 onStyleSheetTextChanged();
1146
1147 return styleRule;
1148 }
1149
1150 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc eptionState& exceptionState)
1151 {
1152 if (!verifyMediaText(ownerDocument(), text)) {
1036 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); 1153 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1037 return nullptr; 1154 return nullptr;
1038 } 1155 }
1039 1156
1040 CSSRule* rule = nullptr; 1157 CSSRule* rule = nullptr;
1041 CSSRuleSourceData* sourceData = nullptr; 1158 CSSRuleSourceData* sourceData = nullptr;
1042 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) { 1159 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) {
1043 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); 1160 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range");
1044 return nullptr; 1161 return nullptr;
1045 } 1162 }
1046 1163
1047 CSSMediaRule* mediaRule = InspectorCSSAgent::asCSSMediaRule(rule); 1164 RefPtrWillBeRawPtr<CSSMediaRule> mediaRule = InspectorCSSAgent::asCSSMediaR ule(rule);
1048 mediaRule->media()->setMediaText(text); 1165 mediaRule->media()->setMediaText(text);
1049 1166
1050 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); 1167 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1051 onStyleSheetTextChanged(); 1168 onStyleSheetTextChanged();
1052 1169
1053 return mediaRule; 1170 return mediaRule;
1054 } 1171 }
1055 1172
1056 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) 1173 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange)
1057 { 1174 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 return insertCSSOMRuleInStyleSheet(sourceRange, ruleText, exceptionState ); 1233 return insertCSSOMRuleInStyleSheet(sourceRange, ruleText, exceptionState );
1117 1234
1118 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(containingRuleIndex); 1235 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(containingRuleIndex);
1119 if (rule->type() != CSSRule::MEDIA_RULE) { 1236 if (rule->type() != CSSRule::MEDIA_RULE) {
1120 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n on-media rule."); 1237 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n on-media rule.");
1121 return nullptr; 1238 return nullptr;
1122 } 1239 }
1123 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState); 1240 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState);
1124 } 1241 }
1125 1242
1126 bool InspectorStyleSheet::verifyRuleText(const String& ruleText) 1243 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce ptionState)
1127 {
1128 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
1129 RuleSourceDataList sourceData;
1130 String text = ruleText + " div { " + bogusPropertyName + ": none; }";
1131 StyleSheetHandler handler(text, ownerDocument(), &sourceData);
1132 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()), text, handler);
1133 unsigned ruleCount = sourceData.size();
1134
1135 // Exactly two rules should be parsed.
1136 if (ruleCount != 2)
1137 return false;
1138
1139 // Added rule must be style rule.
1140 if (!sourceData.at(0)->styleSourceData)
1141 return false;
1142
1143 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(1)->st yleSourceData->propertyData;
1144 unsigned propertyCount = propertyData.size();
1145
1146 // Exactly one property should be in rule.
1147 if (propertyCount != 1)
1148 return false;
1149
1150 // Check for the property name.
1151 if (propertyData.at(0).name != bogusPropertyName)
1152 return false;
1153
1154 return true;
1155 }
1156
1157 bool InspectorStyleSheet::verifySelectorText(const String& selectorText)
1158 {
1159 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
1160 RuleSourceDataList sourceData;
1161 String text = selectorText + " { " + bogusPropertyName + ": none; }";
1162 StyleSheetHandler handler(text, ownerDocument(), &sourceData);
1163 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()), text, handler);
1164
1165 // Exactly one rule should be parsed.
1166 unsigned ruleCount = sourceData.size();
1167 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Style)
1168 return false;
1169
1170 // Exactly one property should be in style rule.
1171 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(0)->st yleSourceData->propertyData;
1172 unsigned propertyCount = propertyData.size();
1173 if (propertyCount != 1)
1174 return false;
1175
1176 // Check for the property name.
1177 if (propertyData.at(0).name != bogusPropertyName)
1178 return false;
1179
1180 return true;
1181 }
1182
1183 bool InspectorStyleSheet::verifyMediaText(const String& mediaText)
1184 {
1185 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
1186 RuleSourceDataList sourceData;
1187 String text = "@media " + mediaText + " { div { " + bogusPropertyName + ": n one; } }";
1188 StyleSheetHandler handler(text, ownerDocument(), &sourceData);
1189 CSSParser::parseSheetForInspector(parserContextForDocument(ownerDocument()), text, handler);
1190
1191 // Exactly one media rule should be parsed.
1192 unsigned ruleCount = sourceData.size();
1193 if (ruleCount != 1 || sourceData.at(0)->type != StyleRule::Media)
1194 return false;
1195
1196 // Media rule should have exactly one style rule child.
1197 RuleSourceDataList& childSourceData = sourceData.at(0)->childRules;
1198 ruleCount = childSourceData.size();
1199 if (ruleCount != 1 || !childSourceData.at(0)->styleSourceData)
1200 return false;
1201
1202 // Exactly one property should be in style rule.
1203 WillBeHeapVector<CSSPropertySourceData>& propertyData = childSourceData.at(0 )->styleSourceData->propertyData;
1204 unsigned propertyCount = propertyData.size();
1205 if (propertyCount != 1)
1206 return false;
1207
1208 // Check for the property name.
1209 if (propertyData.at(0).name != bogusPropertyName)
1210 return false;
1211
1212 return true;
1213 }
1214
1215 CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceR ange& location, SourceRange* addedRange, ExceptionState& exceptionState)
1216 { 1244 {
1217 if (location.start != location.end) { 1245 if (location.start != location.end) {
1218 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); 1246 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed.");
1219 return nullptr; 1247 return nullptr;
1220 } 1248 }
1221 1249
1222 if (!verifyRuleText(ruleText)) { 1250 if (!verifyRuleText(ownerDocument(), ruleText)) {
1223 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; 1251 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ;
1224 return nullptr; 1252 return nullptr;
1225 } 1253 }
1226 1254
1227 if (!ensureParsedDataReady()) { 1255 if (!ensureParsedDataReady()) {
1228 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t."); 1256 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t.");
1229 return nullptr; 1257 return nullptr;
1230 } 1258 }
1231 ensureFlatRules(); 1259 ensureFlatRules();
1232 1260
1233 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState); 1261 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo cation, ruleText, exceptionState);
1234 if (exceptionState.hadException()) 1262 if (exceptionState.hadException())
1235 return nullptr; 1263 return nullptr;
1236 1264
1237 replaceText(location, ruleText, addedRange, nullptr); 1265 replaceText(location, ruleText, addedRange, nullptr);
1238 m_flatRules.clear(); 1266 m_flatRules.clear();
1239 1267
1240 onStyleSheetTextChanged(); 1268 onStyleSheetTextChanged();
1241 return styleRule; 1269 return styleRule;
1242 } 1270 }
1243 1271
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 *pRule = m_flatRules.at(i).get(); 1635 *pRule = m_flatRules.at(i).get();
1608 if (!(*pRule)->parentStyleSheet()) 1636 if (!(*pRule)->parentStyleSheet())
1609 return false; 1637 return false;
1610 *pSourceData = ruleSourceData.get(); 1638 *pSourceData = ruleSourceData.get();
1611 return true; 1639 return true;
1612 } 1640 }
1613 } 1641 }
1614 return false; 1642 return false;
1615 } 1643 }
1616 1644
1645 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData)
1646 {
1647 if (!ensureParsedDataReady())
1648 return false;
1649 ensureFlatRules();
1650
1651 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) {
1652 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1653 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) {
1654 *pRule = m_flatRules.at(i).get();
1655 if (!(*pRule)->parentStyleSheet())
1656 return false;
1657 *pSourceData = ruleSourceData.get();
1658 return true;
1659 }
1660 }
1661 return false;
1662 }
1663
1617 const CSSRuleVector& InspectorStyleSheet::flatRules() 1664 const CSSRuleVector& InspectorStyleSheet::flatRules()
1618 { 1665 {
1619 ensureFlatRules(); 1666 ensureFlatRules();
1620 return m_flatRules; 1667 return m_flatRules;
1621 } 1668 }
1622 1669
1623 Document* InspectorStyleSheet::ownerDocument() const 1670 Document* InspectorStyleSheet::ownerDocument() const
1624 { 1671 {
1625 return m_pageStyleSheet->ownerDocument(); 1672 return m_pageStyleSheet->ownerDocument();
1626 } 1673 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() 1852 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute()
1806 { 1853 {
1807 m_isStyleTextValid = false; 1854 m_isStyleTextValid = false;
1808 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) 1855 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle())
1809 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this); 1856 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this);
1810 m_ruleSourceData.clear(); 1857 m_ruleSourceData.clear();
1811 } 1858 }
1812 1859
1813 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) 1860 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState)
1814 { 1861 {
1862 if (!verifyStyleText(ownerDocument(), text)) {
1863 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." );
1864 return false;
1865 }
1866
1815 bool success = setStyleText(0, text); 1867 bool success = setStyleText(0, text);
1816 if (!success) 1868 if (!success)
1817 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); 1869 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id.");
1818 return success; 1870 return success;
1819 } 1871 }
1820 1872
1821 bool InspectorStyleSheetForInlineStyle::getText(String* result) const 1873 bool InspectorStyleSheetForInlineStyle::getText(String* result) const
1822 { 1874 {
1823 if (!m_isStyleTextValid) { 1875 if (!m_isStyleTextValid) {
1824 m_styleText = elementStyleText(); 1876 m_styleText = elementStyleText();
1825 m_isStyleTextValid = true; 1877 m_isStyleTextValid = true;
1826 } 1878 }
1827 *result = m_styleText; 1879 *result = m_styleText;
1828 return true; 1880 return true;
1829 } 1881 }
1830 1882
1831 bool InspectorStyleSheetForInlineStyle::setStyleText(unsigned ruleIndex, const S tring& text) 1883 bool InspectorStyleSheetForInlineStyle::setStyleText(unsigned ruleIndex, const S tring& text)
1832 { 1884 {
1833 CSSStyleDeclaration* style = styleAt(ruleIndex);
1834 if (!style)
1835 return false;
1836 ASSERT_UNUSED(style, style == inlineStyle());
1837 TrackExceptionState exceptionState; 1885 TrackExceptionState exceptionState;
1838
1839 { 1886 {
1840 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); 1887 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument());
1841 m_element->setAttribute("style", AtomicString(text), exceptionState); 1888 m_element->setAttribute("style", AtomicString(text), exceptionState);
1842 } 1889 }
1843 if (!exceptionState.hadException()) { 1890 if (!exceptionState.hadException()) {
1844 m_styleText = text; 1891 m_styleText = text;
1845 m_isStyleTextValid = true; 1892 m_isStyleTextValid = true;
1846 m_ruleSourceData.clear(); 1893 m_ruleSourceData.clear();
1847 onStyleSheetTextChanged(); 1894 onStyleSheetTextChanged();
1848 } 1895 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 1961
1915 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1962 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1916 { 1963 {
1917 visitor->trace(m_element); 1964 visitor->trace(m_element);
1918 visitor->trace(m_ruleSourceData); 1965 visitor->trace(m_ruleSourceData);
1919 visitor->trace(m_inspectorStyle); 1966 visitor->trace(m_inspectorStyle);
1920 InspectorStyleSheetBase::trace(visitor); 1967 InspectorStyleSheetBase::trace(visitor);
1921 } 1968 }
1922 1969
1923 } // namespace blink 1970 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | Source/devtools/protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698