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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 bool success = getText(&sheetText); | 881 bool success = getText(&sheetText); |
| 882 if (success) { | 882 if (success) { |
| 883 const SourceRange& bodyRange = sourceData->ruleBodyRange; | 883 const SourceRange& bodyRange = sourceData->ruleBodyRange; |
| 884 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); | 884 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 | 887 |
| 888 return result.release(); | 888 return result.release(); |
| 889 } | 889 } |
| 890 | 890 |
| 891 PassOwnPtr<Vector<unsigned> > InspectorStyleSheetBase::lineEndings() | |
| 892 { | |
| 893 String text; | |
| 894 if (!getText(&text)) | |
| 895 return PassOwnPtr<Vector<unsigned> >(); | |
| 896 return WTF::lineEndings(text); | |
| 897 } | |
| 898 | |
| 891 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, PassRefPtr<C SSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, c onst String& documentURL, Listener* listener) | 899 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, PassRefPtr<C SSStyleSheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, c onst String& documentURL, Listener* listener) |
| 892 { | 900 { |
| 893 return adoptRef(new InspectorStyleSheet(pageAgent, resourceAgent, id, pageSt yleSheet, origin, documentURL, listener)); | 901 return adoptRef(new InspectorStyleSheet(pageAgent, resourceAgent, id, pageSt yleSheet, origin, documentURL, listener)); |
| 894 } | 902 } |
| 895 | 903 |
| 896 InspectorStyleSheet::InspectorStyleSheet(InspectorPageAgent* pageAgent, Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtr<CSSStyleSheet> pageS tyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const String& docume ntURL, Listener* listener) | 904 InspectorStyleSheet::InspectorStyleSheet(InspectorPageAgent* pageAgent, Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtr<CSSStyleSheet> pageS tyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const String& docume ntURL, Listener* listener) |
| 897 : InspectorStyleSheetBase(id, listener) | 905 : InspectorStyleSheetBase(id, listener) |
| 898 , m_pageAgent(pageAgent) | 906 , m_pageAgent(pageAgent) |
| 899 , m_resourceAgent(resourceAgent) | 907 , m_resourceAgent(resourceAgent) |
| 900 , m_pageStyleSheet(pageStyleSheet) | 908 , m_pageStyleSheet(pageStyleSheet) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 914 return pageStyleSheet->contents()->baseURL().string(); | 922 return pageStyleSheet->contents()->baseURL().string(); |
| 915 return emptyString(); | 923 return emptyString(); |
| 916 } | 924 } |
| 917 | 925 |
| 918 String InspectorStyleSheet::finalURL() const | 926 String InspectorStyleSheet::finalURL() const |
| 919 { | 927 { |
| 920 String url = styleSheetURL(m_pageStyleSheet.get()); | 928 String url = styleSheetURL(m_pageStyleSheet.get()); |
| 921 return url.isEmpty() ? m_documentURL : url; | 929 return url.isEmpty() ? m_documentURL : url; |
| 922 } | 930 } |
| 923 | 931 |
| 924 void InspectorStyleSheet::reparseStyleSheet(const String& text) | 932 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) |
| 925 { | 933 { |
| 934 m_parsedStyleSheet->setText(text); | |
| 935 m_flatRules.clear(); | |
| 936 | |
| 926 if (listener()) | 937 if (listener()) |
| 927 listener()->willReparseStyleSheet(); | 938 listener()->willReparseStyleSheet(); |
| 928 | 939 |
| 929 { | 940 { |
| 930 // Have a separate scope for clearRules() (bug 95324). | 941 // Have a separate scope for clearRules() (bug 95324). |
| 931 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); | 942 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); |
| 932 m_pageStyleSheet->contents()->clearRules(); | 943 m_pageStyleSheet->contents()->clearRules(); |
| 933 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); | 944 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); |
| 934 } | 945 } |
| 935 { | 946 { |
| 936 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); | 947 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); |
| 937 m_pageStyleSheet->contents()->parseString(text); | 948 m_pageStyleSheet->contents()->parseString(text); |
| 938 } | 949 } |
| 939 | 950 |
| 940 if (listener()) | 951 if (listener()) |
| 941 listener()->didReparseStyleSheet(); | 952 listener()->didReparseStyleSheet(); |
| 942 fireStyleSheetChanged(); | 953 fireStyleSheetChanged(); |
| 943 m_pageStyleSheet->ownerDocument()->styleResolverChanged(RecalcStyleImmediate ly, FullStyleUpdate); | 954 m_pageStyleSheet->ownerDocument()->styleResolverChanged(RecalcStyleImmediate ly, FullStyleUpdate); |
| 944 } | |
| 945 | |
| 946 bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS tate) | |
| 947 { | |
| 948 m_parsedStyleSheet->setText(text); | |
| 949 m_flatRules.clear(); | |
| 950 | |
| 951 return true; | 955 return true; |
| 952 } | 956 } |
| 953 | 957 |
| 954 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) | 958 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) |
| 955 { | 959 { |
| 956 CSSStyleRule* rule = ruleForId(id); | 960 CSSStyleRule* rule = ruleForId(id); |
| 957 if (!rule) { | 961 if (!rule) { |
| 958 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); | 962 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); |
| 959 return ""; | 963 return ""; |
| 960 } | 964 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1026 m_pageStyleSheet->deleteRule(lastRuleIndex, ASSERT_NO_EXCEPTION); | 1030 m_pageStyleSheet->deleteRule(lastRuleIndex, ASSERT_NO_EXCEPTION); |
| 1027 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto r + "' could not be added."); | 1031 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto r + "' could not be added."); |
| 1028 return 0; | 1032 return 0; |
| 1029 } | 1033 } |
| 1030 | 1034 |
| 1031 if (!styleSheetText.isEmpty()) | 1035 if (!styleSheetText.isEmpty()) |
| 1032 styleSheetText.append('\n'); | 1036 styleSheetText.append('\n'); |
| 1033 | 1037 |
| 1034 styleSheetText.append(selector); | 1038 styleSheetText.append(selector); |
| 1035 styleSheetText.appendLiteral(" {}"); | 1039 styleSheetText.appendLiteral(" {}"); |
| 1036 // Using setText() as this operation changes the style sheet rule set. | 1040 m_parsedStyleSheet->setText(styleSheetText.toString()); |
| 1037 setText(styleSheetText.toString(), ASSERT_NO_EXCEPTION); | 1041 m_flatRules.clear(); |
| 1038 | 1042 |
| 1039 fireStyleSheetChanged(); | 1043 fireStyleSheetChanged(); |
| 1040 | 1044 |
| 1041 return styleRule; | 1045 return styleRule; |
| 1042 } | 1046 } |
| 1043 | 1047 |
| 1044 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionState& e xceptionState) | 1048 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionState& e xceptionState) |
| 1045 { | 1049 { |
| 1046 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); | 1050 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); |
| 1047 if (!rule) { | 1051 if (!rule) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1061 } | 1065 } |
| 1062 | 1066 |
| 1063 styleSheet->deleteRule(id.ordinal(), exceptionState); | 1067 styleSheet->deleteRule(id.ordinal(), exceptionState); |
| 1064 // |rule| MAY NOT be addressed after this line! | 1068 // |rule| MAY NOT be addressed after this line! |
| 1065 | 1069 |
| 1066 if (exceptionState.hadException()) | 1070 if (exceptionState.hadException()) |
| 1067 return false; | 1071 return false; |
| 1068 | 1072 |
| 1069 String sheetText = m_parsedStyleSheet->text(); | 1073 String sheetText = m_parsedStyleSheet->text(); |
| 1070 sheetText.remove(sourceData->ruleHeaderRange.start, sourceData->ruleBodyRang e.end - sourceData->ruleHeaderRange.start + 1); | 1074 sheetText.remove(sourceData->ruleHeaderRange.start, sourceData->ruleBodyRang e.end - sourceData->ruleHeaderRange.start + 1); |
| 1071 setText(sheetText, ASSERT_NO_EXCEPTION); | 1075 m_parsedStyleSheet->setText(sheetText); |
| 1076 m_flatRules.clear(); | |
| 1072 fireStyleSheetChanged(); | 1077 fireStyleSheetChanged(); |
| 1073 return true; | 1078 return true; |
| 1074 } | 1079 } |
| 1075 | 1080 |
| 1076 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const | 1081 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const |
| 1077 { | 1082 { |
| 1078 ASSERT(!id.isEmpty()); | 1083 ASSERT(!id.isEmpty()); |
| 1079 ensureFlatRules(); | 1084 ensureFlatRules(); |
| 1080 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size() ? 0 : m_flatRules.at(id.ordinal()).get()); | 1085 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size() ? 0 : m_flatRules.at(id.ordinal()).get()); |
| 1081 } | 1086 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1102 | 1107 |
| 1103 if (hasSourceURL()) | 1108 if (hasSourceURL()) |
| 1104 result->setHasSourceURL(true); | 1109 result->setHasSourceURL(true); |
| 1105 | 1110 |
| 1106 String sourceMapURLValue = sourceMapURL(); | 1111 String sourceMapURLValue = sourceMapURL(); |
| 1107 if (!sourceMapURLValue.isEmpty()) | 1112 if (!sourceMapURLValue.isEmpty()) |
| 1108 result->setSourceMapURL(sourceMapURLValue); | 1113 result->setSourceMapURL(sourceMapURLValue); |
| 1109 return result.release(); | 1114 return result.release(); |
| 1110 } | 1115 } |
| 1111 | 1116 |
| 1112 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > InspectorStyleSheet: :selectorsFromSource(const CSSRuleSourceData* sourceData, const String& sheetTex t) const | 1117 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > InspectorStyleSheet: :selectorsFromSource(const CSSRuleSourceData* sourceData, const String& sheetTex t) |
| 1113 { | 1118 { |
| 1114 ScriptRegexp comment("/\\*[^]*?\\*/", TextCaseSensitive, MultilineEnabled); | 1119 ScriptRegexp comment("/\\*[^]*?\\*/", TextCaseSensitive, MultilineEnabled); |
| 1115 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > result = TypeBuilder ::Array<TypeBuilder::CSS::Selector>::create(); | 1120 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > result = TypeBuilder ::Array<TypeBuilder::CSS::Selector>::create(); |
| 1116 const SelectorRangeList& ranges = sourceData->selectorRanges; | 1121 const SelectorRangeList& ranges = sourceData->selectorRanges; |
| 1117 for (size_t i = 0, size = ranges.size(); i < size; ++i) { | 1122 for (size_t i = 0, size = ranges.size(); i < size; ++i) { |
| 1118 const SourceRange& range = ranges.at(i); | 1123 const SourceRange& range = ranges.at(i); |
| 1119 String selector = sheetText.substring(range.start, range.length()); | 1124 String selector = sheetText.substring(range.start, range.length()); |
| 1120 | 1125 |
| 1121 // We don't want to see any comments in the selector components, only th e meaningful parts. | 1126 // We don't want to see any comments in the selector components, only th e meaningful parts. |
| 1122 int matchLength; | 1127 int matchLength; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 return 0; | 1209 return 0; |
| 1205 | 1210 |
| 1206 return rule->style(); | 1211 return rule->style(); |
| 1207 } | 1212 } |
| 1208 | 1213 |
| 1209 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) | 1214 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) |
| 1210 { | 1215 { |
| 1211 if (!ensureParsedDataReady()) | 1216 if (!ensureParsedDataReady()) |
| 1212 return nullptr; | 1217 return nullptr; |
| 1213 | 1218 |
| 1214 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt( ruleIndexByRule(rule)); | 1219 ensureFlatRules(); |
| 1215 if (!sourceData) | 1220 size_t index = m_flatRules.find(rule); |
| 1221 if (index == kNotFound) | |
| 1216 return nullptr; | 1222 return nullptr; |
| 1223 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt( static_cast<unsigned>(index)); | |
| 1217 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get ()); | 1224 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get ()); |
| 1218 } | 1225 } |
| 1219 | 1226 |
| 1220 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec torCSSId& id) | 1227 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec torCSSId& id) |
| 1221 { | 1228 { |
| 1222 CSSStyleDeclaration* style = styleForId(id); | 1229 CSSStyleDeclaration* style = styleForId(id); |
| 1223 if (!style) | 1230 if (!style) |
| 1224 return nullptr; | 1231 return nullptr; |
| 1225 | 1232 |
| 1226 return InspectorStyle::create(id, style, this); | 1233 return InspectorStyle::create(id, style, this); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1294 bool deprecated; | 1301 bool deprecated; |
| 1295 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated); | 1302 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated); |
| 1296 if (!commentValue.isEmpty()) { | 1303 if (!commentValue.isEmpty()) { |
| 1297 // FIXME: add deprecated console message here. | 1304 // FIXME: add deprecated console message here. |
| 1298 return commentValue; | 1305 return commentValue; |
| 1299 } | 1306 } |
| 1300 } | 1307 } |
| 1301 return m_pageAgent->resourceSourceMapURL(finalURL()); | 1308 return m_pageAgent->resourceSourceMapURL(finalURL()); |
| 1302 } | 1309 } |
| 1303 | 1310 |
| 1304 InspectorCSSId InspectorStyleSheet::ruleIdByStyle(CSSStyleDeclaration* style) co nst | 1311 InspectorCSSId InspectorStyleSheet::styleId(CSSStyleDeclaration* style) const |
| 1305 { | 1312 { |
| 1306 unsigned index = ruleIndexByStyle(style); | 1313 unsigned index = ruleIndexByStyle(style); |
| 1307 if (index != UINT_MAX) | 1314 if (index != UINT_MAX) |
| 1308 return InspectorCSSId(id(), index); | 1315 return InspectorCSSId(id(), index); |
| 1309 return InspectorCSSId(); | 1316 return InspectorCSSId(); |
| 1310 } | 1317 } |
| 1311 | 1318 |
| 1312 Document* InspectorStyleSheet::ownerDocument() const | 1319 Document* InspectorStyleSheet::ownerDocument() const |
| 1313 { | 1320 { |
| 1314 return m_pageStyleSheet->ownerDocument(); | 1321 return m_pageStyleSheet->ownerDocument(); |
| 1315 } | 1322 } |
| 1316 | 1323 |
| 1317 PassRefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDec laration* style) const | 1324 PassRefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDec laration* style) const |
| 1318 { | 1325 { |
| 1319 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style)); | 1326 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style)); |
| 1320 } | 1327 } |
| 1321 | 1328 |
| 1322 PassOwnPtr<Vector<unsigned> > InspectorStyleSheet::lineEndings() const | |
| 1323 { | |
| 1324 if (!m_parsedStyleSheet->hasText()) | |
| 1325 return PassOwnPtr<Vector<unsigned> >(); | |
| 1326 return WTF::lineEndings(m_parsedStyleSheet->text()); | |
| 1327 } | |
| 1328 | |
| 1329 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c onst | 1329 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c onst |
| 1330 { | 1330 { |
| 1331 ensureFlatRules(); | 1331 ensureFlatRules(); |
| 1332 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { | 1332 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { |
| 1333 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); | 1333 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get()); |
| 1334 if (styleRule && styleRule->style() == pageStyle) | 1334 if (styleRule && styleRule->style() == pageStyle) |
| 1335 return i; | 1335 return i; |
| 1336 } | 1336 } |
| 1337 return UINT_MAX; | 1337 return UINT_MAX; |
| 1338 } | 1338 } |
| 1339 | 1339 |
| 1340 unsigned InspectorStyleSheet::ruleIndexByRule(const CSSRule* rule) const | |
| 1341 { | |
| 1342 ensureFlatRules(); | |
| 1343 size_t index = m_flatRules.find(rule); | |
| 1344 return index == kNotFound ? UINT_MAX : static_cast<unsigned>(index); | |
| 1345 } | |
| 1346 | |
| 1347 bool InspectorStyleSheet::checkPageStyleSheet(ExceptionState& exceptionState) co nst | |
| 1348 { | |
| 1349 if (!m_pageStyleSheet) { | |
| 1350 exceptionState.throwDOMException(NotSupportedError, "No stylesheet is av ailable."); | |
| 1351 return false; | |
| 1352 } | |
| 1353 return true; | |
| 1354 } | |
| 1355 | |
| 1356 bool InspectorStyleSheet::ensureParsedDataReady() | 1340 bool InspectorStyleSheet::ensureParsedDataReady() |
| 1357 { | 1341 { |
| 1358 return ensureText() && m_parsedStyleSheet->ensureSourceData(); | 1342 return ensureText() && m_parsedStyleSheet->ensureSourceData(); |
| 1359 } | 1343 } |
| 1360 | 1344 |
| 1361 bool InspectorStyleSheet::ensureText() const | 1345 bool InspectorStyleSheet::ensureText() const |
| 1362 { | 1346 { |
| 1363 if (m_parsedStyleSheet->hasText()) | 1347 if (m_parsedStyleSheet->hasText()) |
| 1364 return true; | 1348 return true; |
| 1365 | 1349 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1408 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text) | 1392 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text) |
| 1409 { | 1393 { |
| 1410 if (!ensureParsedDataReady()) | 1394 if (!ensureParsedDataReady()) |
| 1411 return false; | 1395 return false; |
| 1412 | 1396 |
| 1413 String patchedStyleSheetText; | 1397 String patchedStyleSheetText; |
| 1414 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); | 1398 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); |
| 1415 if (!success) | 1399 if (!success) |
| 1416 return false; | 1400 return false; |
| 1417 | 1401 |
| 1418 InspectorCSSId id = ruleIdByStyle(style); | 1402 InspectorCSSId id = styleId(style); |
| 1419 if (id.isEmpty()) | 1403 if (id.isEmpty()) |
| 1420 return false; | 1404 return false; |
| 1421 | 1405 |
| 1422 TrackExceptionState exceptionState; | 1406 TrackExceptionState exceptionState; |
| 1423 style->setCSSText(text, exceptionState); | 1407 style->setCSSText(text, exceptionState); |
| 1424 if (!exceptionState.hadException()) | 1408 if (!exceptionState.hadException()) |
| 1425 m_parsedStyleSheet->setText(patchedStyleSheetText); | 1409 m_parsedStyleSheet->setText(patchedStyleSheetText); |
| 1426 | 1410 |
| 1427 return !exceptionState.hadException(); | 1411 return !exceptionState.hadException(); |
| 1428 } | 1412 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1443 String text = m_parsedStyleSheet->text(); | 1427 String text = m_parsedStyleSheet->text(); |
| 1444 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive | 1428 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive |
| 1445 | 1429 |
| 1446 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); | 1430 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); |
| 1447 *result = text; | 1431 *result = text; |
| 1448 return true; | 1432 return true; |
| 1449 } | 1433 } |
| 1450 | 1434 |
| 1451 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const | 1435 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const |
| 1452 { | 1436 { |
| 1453 return ruleIdByStyle(rule->style()); | 1437 return styleId(rule->style()); |
| 1454 } | 1438 } |
| 1455 | 1439 |
| 1456 bool InspectorStyleSheet::originalStyleSheetText(String* result) const | 1440 bool InspectorStyleSheet::originalStyleSheetText(String* result) const |
| 1457 { | 1441 { |
| 1458 bool success = inlineStyleSheetText(result); | 1442 bool success = inlineStyleSheetText(result); |
| 1459 if (!success) | 1443 if (!success) |
| 1460 success = resourceStyleSheetText(result); | 1444 success = resourceStyleSheetText(result); |
| 1461 return success; | 1445 return success; |
| 1462 } | 1446 } |
| 1463 | 1447 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1504 } | 1488 } |
| 1505 | 1489 |
| 1506 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() | 1490 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() |
| 1507 { | 1491 { |
| 1508 m_isStyleTextValid = false; | 1492 m_isStyleTextValid = false; |
| 1509 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) | 1493 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) |
| 1510 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin eStyle(), this); | 1494 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin eStyle(), this); |
| 1511 m_ruleSourceData.clear(); | 1495 m_ruleSourceData.clear(); |
| 1512 } | 1496 } |
| 1513 | 1497 |
| 1514 void InspectorStyleSheetForInlineStyle::reparseStyleSheet(const String& text) | |
| 1515 { | |
| 1516 fireStyleSheetChanged(); | |
| 1517 } | |
| 1518 | |
| 1519 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) | 1498 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) |
| 1520 { | 1499 { |
| 1521 bool success = setStyleText(inlineStyle(), text); | 1500 bool success = setStyleText(inlineStyle(), text); |
| 1522 if (!success) | 1501 if (!success) |
| 1523 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); | 1502 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); |
|
vsevik
2014/03/19 08:26:53
This could be moved out to agent.
lushnikov
2014/03/19 08:57:37
Discussed offline, decided to leave it as-is
| |
| 1503 else | |
| 1504 fireStyleSheetChanged(); | |
| 1524 return success; | 1505 return success; |
| 1525 } | 1506 } |
| 1526 | 1507 |
| 1527 bool InspectorStyleSheetForInlineStyle::getText(String* result) const | 1508 bool InspectorStyleSheetForInlineStyle::getText(String* result) const |
| 1528 { | 1509 { |
| 1529 if (!m_isStyleTextValid) { | 1510 if (!m_isStyleTextValid) { |
| 1530 m_styleText = elementStyleText(); | 1511 m_styleText = elementStyleText(); |
| 1531 m_isStyleTextValid = true; | 1512 m_isStyleTextValid = true; |
| 1532 } | 1513 } |
| 1533 *result = m_styleText; | 1514 *result = m_styleText; |
| 1534 return true; | 1515 return true; |
| 1535 } | 1516 } |
| 1536 | 1517 |
| 1537 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text) | 1518 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text) |
| 1538 { | 1519 { |
| 1539 ASSERT_UNUSED(style, style == inlineStyle()); | 1520 ASSERT_UNUSED(style, style == inlineStyle()); |
| 1540 TrackExceptionState exceptionState; | 1521 TrackExceptionState exceptionState; |
| 1541 | 1522 |
| 1542 { | 1523 { |
| 1543 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); | 1524 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); |
| 1544 m_element->setAttribute("style", AtomicString(text), exceptionState); | 1525 m_element->setAttribute("style", AtomicString(text), exceptionState); |
| 1545 } | 1526 } |
| 1546 | 1527 |
| 1547 m_styleText = text; | 1528 m_styleText = text; |
| 1548 m_isStyleTextValid = true; | 1529 m_isStyleTextValid = true; |
| 1549 m_ruleSourceData.clear(); | 1530 m_ruleSourceData.clear(); |
| 1550 return !exceptionState.hadException(); | 1531 return !exceptionState.hadException(); |
| 1551 } | 1532 } |
| 1552 | 1533 |
| 1553 PassOwnPtr<Vector<unsigned> > InspectorStyleSheetForInlineStyle::lineEndings() c onst | |
| 1554 { | |
| 1555 return WTF::lineEndings(elementStyleText()); | |
| 1556 } | |
| 1557 | |
| 1558 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const | 1534 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const |
| 1559 { | 1535 { |
| 1560 return &m_element->document(); | 1536 return &m_element->document(); |
| 1561 } | 1537 } |
| 1562 | 1538 |
| 1563 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() | 1539 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() |
| 1564 { | 1540 { |
| 1565 // The "style" property value can get changed indirectly, e.g. via element.s tyle.borderWidth = "2px". | 1541 // The "style" property value can get changed indirectly, e.g. via element.s tyle.borderWidth = "2px". |
| 1566 const String& currentStyleText = elementStyleText(); | 1542 const String& currentStyleText = elementStyleText(); |
| 1567 if (m_styleText != currentStyleText) { | 1543 if (m_styleText != currentStyleText) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1614 | 1590 |
| 1615 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate(); | 1591 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate(); |
| 1616 RuleSourceDataList ruleSourceDataResult; | 1592 RuleSourceDataList ruleSourceDataResult; |
| 1617 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult); | 1593 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult); |
| 1618 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge t(), m_styleText, &handler, m_element->document().elementSheet().contents()); | 1594 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge t(), m_styleText, &handler, m_element->document().elementSheet().contents()); |
| 1619 return ruleSourceDataResult.first().release(); | 1595 return ruleSourceDataResult.first().release(); |
| 1620 } | 1596 } |
| 1621 | 1597 |
| 1622 } // namespace WebCore | 1598 } // namespace WebCore |
| 1623 | 1599 |
| OLD | NEW |