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