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

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

Issue 1179323003: DevTools: do not use range indices outside of InspectorStyleSheet. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments addressed 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') | no next file » | 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 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 976 }
977 977
978 String InspectorStyleSheet::finalURL() const 978 String InspectorStyleSheet::finalURL() const
979 { 979 {
980 String url = styleSheetURL(m_pageStyleSheet.get()); 980 String url = styleSheetURL(m_pageStyleSheet.get());
981 return url.isEmpty() ? m_documentURL : url; 981 return url.isEmpty() ? m_documentURL : url;
982 } 982 }
983 983
984 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) 984 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate)
985 { 985 {
986 updateText(text); 986 innerSetText(text);
987 m_flatRules.clear(); 987 m_flatRules.clear();
988 988
989 if (listener()) 989 if (listener())
990 listener()->willReparseStyleSheet(); 990 listener()->willReparseStyleSheet();
991 991
992 { 992 {
993 // Have a separate scope for clearRules() (bug 95324). 993 // Have a separate scope for clearRules() (bug 95324).
994 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); 994 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get());
995 m_pageStyleSheet->contents()->clearRules(); 995 m_pageStyleSheet->contents()->clearRules();
996 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); 996 m_pageStyleSheet->clearChildRuleCSSOMWrappers();
997 } 997 }
998 { 998 {
999 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); 999 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get());
1000 m_pageStyleSheet->contents()->parseString(text); 1000 m_pageStyleSheet->contents()->parseString(text);
1001 } 1001 }
1002 1002
1003 if (listener()) 1003 if (listener())
1004 listener()->didReparseStyleSheet(); 1004 listener()->didReparseStyleSheet();
1005 onStyleSheetTextChanged(); 1005 onStyleSheetTextChanged();
1006 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); 1006 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate);
1007 return true; 1007 return true;
1008 } 1008 }
1009 1009
1010 String InspectorStyleSheet::ruleSelector(unsigned ruleIndex, ExceptionState& exc eptionState) 1010 CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, con st String& text, SourceRange* newRange, String* oldText, ExceptionState& excepti onState)
1011 { 1011 {
1012 CSSStyleRule* rule = ruleAt(ruleIndex); 1012 if (!verifySelectorText(text)) {
1013 if (!rule) { 1013 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1014 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1014 return nullptr;
1015 return "";
1016 } 1015 }
1017 return rule->selectorText(); 1016
1017 CSSRule* rule = nullptr;
1018 CSSRuleSourceData* sourceData = nullptr;
1019 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");
1021 return nullptr;
1022 }
1023
1024 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
1025 styleRule->setSelectorText(text);
1026
1027 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1028 onStyleSheetTextChanged();
1029
1030 return styleRule;
1018 } 1031 }
1019 1032
1020 bool InspectorStyleSheet::setRuleSelector(unsigned ruleIndex, const String& sele ctor, ExceptionState& exceptionState) 1033 CSSMediaRule* InspectorStyleSheet::setMediaRuleText(const SourceRange& range, co nst String& text, SourceRange* newRange, String* oldText, ExceptionState& except ionState)
1021 { 1034 {
1022 CSSStyleRule* rule = ruleAt(ruleIndex); 1035 if (!verifyMediaText(text)) {
1023 if (!rule) { 1036 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1024 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1037 return nullptr;
1025 return false;
1026 }
1027 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1028 if (!styleSheet || !ensureParsedDataReady()) {
1029 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector.");
1030 return false;
1031 } 1038 }
1032 1039
1033 if (!verifySelectorText(selector)) { 1040 CSSRule* rule = nullptr;
1034 exceptionState.throwDOMException(SyntaxError, "Selector text is not vali d."); 1041 CSSRuleSourceData* sourceData = nullptr;
1035 return false; 1042 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");
1044 return nullptr;
1036 } 1045 }
1037 1046
1038 rule->setSelectorText(selector); 1047 CSSMediaRule* mediaRule = InspectorCSSAgent::asCSSMediaRule(rule);
1039 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x); 1048 mediaRule->media()->setMediaText(text);
1040 ASSERT(sourceData);
1041 1049
1042 String sheetText = m_parsedStyleSheet->text(); 1050 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1043 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), selector);
1044 updateText(sheetText);
1045 onStyleSheetTextChanged(); 1051 onStyleSheetTextChanged();
1046 return true;
1047 }
1048 1052
1049 String InspectorStyleSheet::mediaRuleText(unsigned ruleIndex, ExceptionState& ex ceptionState) 1053 return mediaRule;
1050 {
1051 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1052 if (!rule) {
1053 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1054 return "";
1055 }
1056 return rule->media()->mediaText();
1057 }
1058
1059 bool InspectorStyleSheet::setMediaRuleText(unsigned ruleIndex, const String& tex t, ExceptionState& exceptionState)
1060 {
1061 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1062 if (!rule) {
1063 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1064 return false;
1065 }
1066 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1067 if (!styleSheet || !ensureParsedDataReady()) {
1068 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the media text.");
1069 return false;
1070 }
1071 if (!verifyMediaText(text)) {
1072 exceptionState.throwDOMException(SyntaxError, "Media text is not valid." );
1073 return false;
1074 }
1075
1076 rule->media()->setMediaText(text);
1077 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1078 ASSERT(sourceData && sourceData->mediaSourceData);
1079
1080 String sheetText = m_parsedStyleSheet->text();
1081 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), text);
1082 updateText(sheetText);
1083 onStyleSheetTextChanged();
1084 return true;
1085 } 1054 }
1086 1055
1087 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) 1056 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange)
1088 { 1057 {
1089 unsigned index = 0; 1058 unsigned index = 0;
1090 for (size_t i = 0; i < m_flatRules.size(); ++i) { 1059 for (size_t i = 0; i < m_flatRules.size(); ++i) {
1091 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i); 1060 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i);
1092 if (rule->parentRule() != parentMediaRule) 1061 if (rule->parentRule() != parentMediaRule)
1093 continue; 1062 continue;
1094 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); 1063 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 } 1107 }
1139 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc eData->ruleBodyRange.end < sourceRange.start) 1108 if (sourceRange.start < ruleSourceData->ruleBodyRange.start || ruleSourc eData->ruleBodyRange.end < sourceRange.start)
1140 continue; 1109 continue;
1141 if (containingRuleIndex == -1 || containingRuleLength > ruleSourceData-> ruleBodyRange.length()) { 1110 if (containingRuleIndex == -1 || containingRuleLength > ruleSourceData-> ruleBodyRange.length()) {
1142 containingRuleIndex = i; 1111 containingRuleIndex = i;
1143 containingRuleLength = ruleSourceData->ruleBodyRange.length(); 1112 containingRuleLength = ruleSourceData->ruleBodyRange.length();
1144 } 1113 }
1145 } 1114 }
1146 if (containingRuleIndex == -1) 1115 if (containingRuleIndex == -1)
1147 return insertCSSOMRuleInStyleSheet(sourceRange, ruleText, exceptionState ); 1116 return insertCSSOMRuleInStyleSheet(sourceRange, ruleText, exceptionState );
1117
1148 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(containingRuleIndex); 1118 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(containingRuleIndex);
1149 if (rule->type() != CSSRule::MEDIA_RULE) { 1119 if (rule->type() != CSSRule::MEDIA_RULE) {
1150 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n on-media rule."); 1120 exceptionState.throwDOMException(NotFoundError, "Cannot insert rule in n on-media rule.");
1151 return nullptr; 1121 return nullptr;
1152 } 1122 }
1153 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState); 1123 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState);
1154 } 1124 }
1155 1125
1156 bool InspectorStyleSheet::verifyRuleText(const String& ruleText) 1126 bool InspectorStyleSheet::verifyRuleText(const String& ruleText)
1157 { 1127 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 if (propertyCount != 1) 1205 if (propertyCount != 1)
1236 return false; 1206 return false;
1237 1207
1238 // Check for the property name. 1208 // Check for the property name.
1239 if (propertyData.at(0).name != bogusPropertyName) 1209 if (propertyData.at(0).name != bogusPropertyName)
1240 return false; 1210 return false;
1241 1211
1242 return true; 1212 return true;
1243 } 1213 }
1244 1214
1245 CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceR ange& location, ExceptionState& exceptionState) 1215 CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceR ange& location, SourceRange* addedRange, ExceptionState& exceptionState)
1246 { 1216 {
1247 if (!ensureParsedDataReady()) {
1248 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t.");
1249 return nullptr;
1250 }
1251
1252 if (location.start != location.end) { 1217 if (location.start != location.end) {
1253 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); 1218 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed.");
1254 return nullptr; 1219 return nullptr;
1255 } 1220 }
1256 1221
1257 if (!verifyRuleText(ruleText)) { 1222 if (!verifyRuleText(ruleText)) {
1258 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; 1223 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ;
1259 return nullptr; 1224 return nullptr;
1260 } 1225 }
1261 1226
1262 String text; 1227 if (!ensureParsedDataReady()) {
1263 bool success = getText(&text); 1228 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t.");
1264 if (!success) {
1265 exceptionState.throwDOMException(NotFoundError, "The rule '" + ruleText + "' could not be added.");
1266 return nullptr; 1229 return nullptr;
1267 } 1230 }
1231 ensureFlatRules();
1268 1232
1269 ensureFlatRules();
1270 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState); 1233 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState);
1271 if (exceptionState.hadException()) 1234 if (exceptionState.hadException())
1272 return nullptr; 1235 return nullptr;
1273 1236
1274 text.insert(ruleText, location.start); 1237 replaceText(location, ruleText, addedRange, nullptr);
1275
1276 updateText(text);
1277 m_flatRules.clear(); 1238 m_flatRules.clear();
1278 1239
1279 onStyleSheetTextChanged(); 1240 onStyleSheetTextChanged();
1280 return styleRule; 1241 return styleRule;
1281 } 1242 }
1282 1243
1283 bool InspectorStyleSheet::deleteRule(unsigned ruleIndex, const String& oldText, ExceptionState& exceptionState) 1244 bool InspectorStyleSheet::deleteRule(const SourceRange& range, ExceptionState& e xceptionState)
1284 { 1245 {
1285 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleAt(ruleIndex); 1246 // Find index of CSSRule that entirely belongs to the range.
1247 RefPtrWillBeRawPtr<CSSRule> rule = nullptr;
1248 unsigned containingRuleLength = 0;
1249
1250 for (size_t i = 0; i < m_flatRules.size() && i < m_parsedStyleSheet->ruleCou nt(); ++i) {
1251 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i);
1252 unsigned ruleStart = ruleSourceData->ruleHeaderRange.start;
1253 unsigned ruleEnd = ruleSourceData->ruleBodyRange.end + 1;
1254 bool startBelongs = ruleStart >= range.start && ruleStart < range.end;
1255 bool endBelongs = ruleEnd > range.start && ruleEnd <= range.end;
1256
1257 if (startBelongs != endBelongs)
1258 break;
1259 if (!startBelongs)
1260 continue;
1261 if (!rule || containingRuleLength > ruleSourceData->ruleBodyRange.length ()) {
1262 containingRuleLength = ruleSourceData->ruleBodyRange.length();
1263 rule = m_flatRules.at(i).get();
1264 }
1265 }
1286 if (!rule) { 1266 if (!rule) {
1287 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1267 exceptionState.throwDOMException(NotFoundError, "No style rule could be found in given range.");
1288 return false; 1268 return false;
1289 } 1269 }
1290 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1270 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1291 if (!styleSheet || !ensureParsedDataReady()) { 1271 if (!styleSheet || !ensureParsedDataReady()) {
1292 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); 1272 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found.");
1293 return false; 1273 return false;
1294 } 1274 }
1295
1296 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1297 if (!sourceData) {
1298 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1299 return false;
1300 }
1301
1302 CSSRule* parentRule = rule->parentRule(); 1275 CSSRule* parentRule = rule->parentRule();
1303 if (parentRule) { 1276 if (parentRule) {
1304 if (parentRule->type() != CSSRule::MEDIA_RULE) { 1277 if (parentRule->type() != CSSRule::MEDIA_RULE) {
1305 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule."); 1278 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule.");
1306 return false; 1279 return false;
1307 } 1280 }
1308 CSSMediaRule* parentMediaRule = toCSSMediaRule(parentRule); 1281 CSSMediaRule* parentMediaRule = toCSSMediaRule(parentRule);
1309 size_t index = 0; 1282 size_t index = 0;
1310 while (index < parentMediaRule->length() && parentMediaRule->item(index) != rule) 1283 while (index < parentMediaRule->length() && parentMediaRule->item(index) != rule)
1311 ++index; 1284 ++index;
1312 ASSERT(index < parentMediaRule->length()); 1285 ASSERT(index < parentMediaRule->length());
1313 parentMediaRule->deleteRule(index, exceptionState); 1286 parentMediaRule->deleteRule(index, exceptionState);
1314 } else { 1287 } else {
1315 size_t index = 0; 1288 size_t index = 0;
1316 while (index < styleSheet->length() && styleSheet->item(index) != rule) 1289 while (index < styleSheet->length() && styleSheet->item(index) != rule)
1317 ++index; 1290 ++index;
1318 ASSERT(index < styleSheet->length()); 1291 ASSERT(index < styleSheet->length());
1319 styleSheet->deleteRule(index, exceptionState); 1292 styleSheet->deleteRule(index, exceptionState);
1320 } 1293 }
1321 // |rule| MAY NOT be addressed after this line! 1294 // |rule| MAY NOT be addressed after this line!
1322 1295
1323 if (exceptionState.hadException()) 1296 if (exceptionState.hadException())
1324 return false; 1297 return false;
1325 1298
1326 updateText(oldText); 1299 replaceText(range, "", nullptr, nullptr);
1327 m_flatRules.clear(); 1300 m_flatRules.clear();
1328 onStyleSheetTextChanged(); 1301 onStyleSheetTextChanged();
1329 return true; 1302 return true;
1330 } 1303 }
1331 1304
1332 void InspectorStyleSheet::updateText(const String& newText) 1305 void InspectorStyleSheet::replaceText(const SourceRange& range, const String& te xt, SourceRange* newRange, String* oldText)
1306 {
1307 String sheetText = m_parsedStyleSheet->text();
1308 if (oldText)
1309 *oldText = sheetText.substring(range.start, range.length());
1310 sheetText.replace(range.start, range.length(), text);
1311 if (newRange)
1312 *newRange = SourceRange(range.start, range.start + text.length());
1313 innerSetText(sheetText);
1314 }
1315
1316 void InspectorStyleSheet::innerSetText(const String& newText)
1333 { 1317 {
1334 Element* element = ownerStyleElement(); 1318 Element* element = ownerStyleElement();
1335 if (element) 1319 if (element)
1336 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); 1320 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t);
1337 else 1321 else
1338 m_cssAgent->addEditedStyleSheet(finalURL(), newText); 1322 m_cssAgent->addEditedStyleSheet(finalURL(), newText);
1339 m_parsedStyleSheet->setText(newText); 1323 m_parsedStyleSheet->setText(newText);
1340 } 1324 }
1341 1325
1342 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const 1326 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 { 1588 {
1605 ensureFlatRules(); 1589 ensureFlatRules();
1606 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { 1590 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
1607 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); 1591 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get());
1608 if (styleRule && styleRule->style() == style) 1592 if (styleRule && styleRule->style() == style)
1609 return i; 1593 return i;
1610 } 1594 }
1611 return UINT_MAX; 1595 return UINT_MAX;
1612 } 1596 }
1613 1597
1614 bool InspectorStyleSheet::findRuleBySelectorRange(const SourceRange& sourceRange , unsigned* ruleIndex) 1598 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData)
1615 { 1599 {
1616 if (!ensureParsedDataReady()) 1600 if (!ensureParsedDataReady())
1617 return false; 1601 return false;
1618 for (size_t i = 0; i < ruleCount(); ++i) { 1602 ensureFlatRules();
1603
1604 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) {
1619 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 1605 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1620 if (!ruleSourceData->styleSourceData)
1621 continue;
1622 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { 1606 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1623 *ruleIndex = i; 1607 *pRule = m_flatRules.at(i).get();
1608 if (!(*pRule)->parentStyleSheet())
1609 return false;
1610 *pSourceData = ruleSourceData.get();
1624 return true; 1611 return true;
1625 } 1612 }
1626 } 1613 }
1627 return false;
1628 }
1629
1630 bool InspectorStyleSheet::findMediaRuleByRange(const SourceRange& sourceRange, u nsigned* ruleIndex)
1631 {
1632 if (!ensureParsedDataReady())
1633 return false;
1634 for (size_t i = 0; i < ruleCount(); ++i) {
1635 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1636 if (!ruleSourceData->mediaSourceData)
1637 continue;
1638 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1639 *ruleIndex = i;
1640 return true;
1641 }
1642 }
1643 return false; 1614 return false;
1644 } 1615 }
1645 1616
1646 const CSSRuleVector& InspectorStyleSheet::flatRules() 1617 const CSSRuleVector& InspectorStyleSheet::flatRules()
1647 { 1618 {
1648 ensureFlatRules(); 1619 ensureFlatRules();
1649 return m_flatRules; 1620 return m_flatRules;
1650 } 1621 }
1651 1622
1652 Document* InspectorStyleSheet::ownerDocument() const 1623 Document* InspectorStyleSheet::ownerDocument() const
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 return false; 1697 return false;
1727 1698
1728 String patchedStyleSheetText; 1699 String patchedStyleSheetText;
1729 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); 1700 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText);
1730 if (!success) 1701 if (!success)
1731 return false; 1702 return false;
1732 1703
1733 TrackExceptionState exceptionState; 1704 TrackExceptionState exceptionState;
1734 style->setCSSText(text, exceptionState); 1705 style->setCSSText(text, exceptionState);
1735 if (!exceptionState.hadException()) { 1706 if (!exceptionState.hadException()) {
1736 updateText(patchedStyleSheetText); 1707 innerSetText(patchedStyleSheetText);
1737 onStyleSheetTextChanged(); 1708 onStyleSheetTextChanged();
1738 } 1709 }
1739 1710
1740 return !exceptionState.hadException(); 1711 return !exceptionState.hadException();
1741 } 1712 }
1742 1713
1743 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result) 1714 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result)
1744 { 1715 {
1745 if (!style) 1716 if (!style)
1746 return false; 1717 return false;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 1914
1944 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1915 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1945 { 1916 {
1946 visitor->trace(m_element); 1917 visitor->trace(m_element);
1947 visitor->trace(m_ruleSourceData); 1918 visitor->trace(m_ruleSourceData);
1948 visitor->trace(m_inspectorStyle); 1919 visitor->trace(m_inspectorStyle);
1949 InspectorStyleSheetBase::trace(visitor); 1920 InspectorStyleSheetBase::trace(visitor);
1950 } 1921 }
1951 1922
1952 } // namespace blink 1923 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698