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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 489 |
490 namespace blink { | 490 namespace blink { |
491 | 491 |
492 enum MediaListSource { | 492 enum MediaListSource { |
493 MediaListSourceLinkedSheet, | 493 MediaListSourceLinkedSheet, |
494 MediaListSourceInlineSheet, | 494 MediaListSourceInlineSheet, |
495 MediaListSourceMediaRule, | 495 MediaListSourceMediaRule, |
496 MediaListSourceImportRule | 496 MediaListSourceImportRule |
497 }; | 497 }; |
498 | 498 |
499 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So
urceRange& range, Vector<unsigned>* lineEndings) | 499 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So
urceRange& range, const LineEndings* lineEndings) |
500 { | 500 { |
501 if (!lineEndings) | 501 if (!lineEndings) |
502 return nullptr; | 502 return nullptr; |
503 TextPosition start = TextPosition::fromOffsetAndLineEndings(range.start, *li
neEndings); | 503 TextPosition start = TextPosition::fromOffsetAndLineEndings(range.start, *li
neEndings); |
504 TextPosition end = TextPosition::fromOffsetAndLineEndings(range.end, *lineEn
dings); | 504 TextPosition end = TextPosition::fromOffsetAndLineEndings(range.end, *lineEn
dings); |
505 | 505 |
506 RefPtr<TypeBuilder::CSS::SourceRange> result = TypeBuilder::CSS::SourceRange
::create() | 506 RefPtr<TypeBuilder::CSS::SourceRange> result = TypeBuilder::CSS::SourceRange
::create() |
507 .setStartLine(start.m_line.zeroBasedInt()) | 507 .setStartLine(start.m_line.zeroBasedInt()) |
508 .setStartColumn(start.m_column.zeroBasedInt()) | 508 .setStartColumn(start.m_column.zeroBasedInt()) |
509 .setEndLine(end.m_line.zeroBasedInt()) | 509 .setEndLine(end.m_line.zeroBasedInt()) |
(...skipping 30 matching lines...) Expand all Loading... |
540 } | 540 } |
541 | 541 |
542 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con
st | 542 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con
st |
543 { | 543 { |
544 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); | 544 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); |
545 if (!m_styleId.isEmpty()) | 545 if (!m_styleId.isEmpty()) |
546 result->setStyleSheetId(m_styleId.styleSheetId()); | 546 result->setStyleSheetId(m_styleId.styleSheetId()); |
547 | 547 |
548 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 548 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
549 if (sourceData) | 549 if (sourceData) |
550 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par
entStyleSheet->lineEndings().get())); | 550 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par
entStyleSheet->lineEndings())); |
551 | 551 |
552 return result.release(); | 552 return result.release(); |
553 } | 553 } |
554 | 554 |
555 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp
ectorStyle::buildArrayForComputedStyle() const | 555 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp
ectorStyle::buildArrayForComputedStyle() const |
556 { | 556 { |
557 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu
lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); | 557 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu
lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); |
558 WillBeHeapVector<InspectorStyleProperty> properties; | 558 WillBeHeapVector<InspectorStyleProperty> properties; |
559 populateAllProperties(properties); | 559 populateAllProperties(properties); |
560 | 560 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 continue; | 687 continue; |
688 result.append(InspectorStyleProperty(CSSPropertySourceData(name, value,
!m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), fals
e)); | 688 result.append(InspectorStyleProperty(CSSPropertySourceData(name, value,
!m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), fals
e)); |
689 } | 689 } |
690 } | 690 } |
691 | 691 |
692 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st | 692 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st |
693 { | 693 { |
694 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); | 694 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); |
695 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); | 695 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); |
696 HashSet<String> foundShorthands; | 696 HashSet<String> foundShorthands; |
697 OwnPtr<Vector<unsigned> > lineEndings(m_parentStyleSheet ? m_parentStyleShee
t->lineEndings() : PassOwnPtr<Vector<unsigned> >()); | |
698 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 697 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
699 | 698 |
700 WillBeHeapVector<InspectorStyleProperty> properties; | 699 WillBeHeapVector<InspectorStyleProperty> properties; |
701 populateAllProperties(properties); | 700 populateAllProperties(properties); |
702 | 701 |
703 for (WillBeHeapVector<InspectorStyleProperty>::iterator it = properties.begi
n(), itEnd = properties.end(); it != itEnd; ++it) { | 702 for (WillBeHeapVector<InspectorStyleProperty>::iterator it = properties.begi
n(), itEnd = properties.end(); it != itEnd; ++it) { |
704 const CSSPropertySourceData& propertyEntry = it->sourceData; | 703 const CSSPropertySourceData& propertyEntry = it->sourceData; |
705 const String& name = propertyEntry.name; | 704 const String& name = propertyEntry.name; |
706 | 705 |
707 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() | 706 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() |
708 .setName(name) | 707 .setName(name) |
709 .setValue(propertyEntry.value); | 708 .setValue(propertyEntry.value); |
710 propertiesObject->addItem(property); | 709 propertiesObject->addItem(property); |
711 | 710 |
712 // Default "parsedOk" == true. | 711 // Default "parsedOk" == true. |
713 if (!propertyEntry.parsedOk) | 712 if (!propertyEntry.parsedOk) |
714 property->setParsedOk(false); | 713 property->setParsedOk(false); |
715 if (it->hasRawText()) | 714 if (it->hasRawText()) |
716 property->setText(it->rawText); | 715 property->setText(it->rawText); |
717 | 716 |
718 if (propertyEntry.important) | 717 if (propertyEntry.important) |
719 property->setImportant(true); | 718 property->setImportant(true); |
720 if (it->hasSource) { | 719 if (it->hasSource) { |
721 property->setRange(buildSourceRangeObject(propertyEntry.range, lineE
ndings.get())); | 720 property->setRange(buildSourceRangeObject(propertyEntry.range, m_par
entStyleSheet ? m_parentStyleSheet->lineEndings() : nullptr)); |
722 if (!propertyEntry.disabled) { | 721 if (!propertyEntry.disabled) { |
723 ASSERT_UNUSED(sourceData, sourceData); | 722 ASSERT_UNUSED(sourceData, sourceData); |
724 property->setImplicit(false); | 723 property->setImplicit(false); |
725 } | 724 } |
726 property->setDisabled(propertyEntry.disabled); | 725 property->setDisabled(propertyEntry.disabled); |
727 } else if (!propertyEntry.disabled) { | 726 } else if (!propertyEntry.disabled) { |
728 bool implicit = m_style->isPropertyImplicit(name); | 727 bool implicit = m_style->isPropertyImplicit(name); |
729 // Default "implicit" == false. | 728 // Default "implicit" == false. |
730 if (implicit) | 729 if (implicit) |
731 property->setImplicit(true); | 730 property->setImplicit(true); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 851 |
853 void InspectorStyle::trace(Visitor* visitor) | 852 void InspectorStyle::trace(Visitor* visitor) |
854 { | 853 { |
855 visitor->trace(m_style); | 854 visitor->trace(m_style); |
856 visitor->trace(m_parentStyleSheet); | 855 visitor->trace(m_parentStyleSheet); |
857 } | 856 } |
858 | 857 |
859 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis
tener) | 858 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis
tener) |
860 : m_id(id) | 859 : m_id(id) |
861 , m_listener(listener) | 860 , m_listener(listener) |
| 861 , m_lineEndings(adoptPtr(new LineEndings())) |
862 { | 862 { |
863 } | 863 } |
864 | 864 |
865 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned
propertyIndex, const String& text, bool overwrite, ExceptionState& exceptionSta
te) | 865 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned
propertyIndex, const String& text, bool overwrite, ExceptionState& exceptionSta
te) |
866 { | 866 { |
867 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); | 867 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); |
868 if (!inspectorStyle) { | 868 if (!inspectorStyle) { |
869 exceptionState.throwDOMException(NotFoundError, "No property could be fo
und for the given ID."); | 869 exceptionState.throwDOMException(NotFoundError, "No property could be fo
und for the given ID."); |
870 return false; | 870 return false; |
871 } | 871 } |
872 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep
tionState); | 872 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep
tionState); |
873 } | 873 } |
874 | 874 |
875 bool InspectorStyleSheetBase::getStyleText(const InspectorCSSId& id, String* tex
t) | 875 bool InspectorStyleSheetBase::getStyleText(const InspectorCSSId& id, String* tex
t) |
876 { | 876 { |
877 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); | 877 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); |
878 if (!inspectorStyle) | 878 if (!inspectorStyle) |
879 return false; | 879 return false; |
880 return inspectorStyle->styleText(text); | 880 return inspectorStyle->styleText(text); |
881 } | 881 } |
882 | 882 |
883 void InspectorStyleSheetBase::fireStyleSheetChanged() | 883 void InspectorStyleSheetBase::onStyleSheetTextChanged() |
884 { | 884 { |
| 885 m_lineEndings = adoptPtrWillBeNoop(new LineEndings()); |
885 if (listener()) | 886 if (listener()) |
886 listener()->styleSheetChanged(this); | 887 listener()->styleSheetChanged(this); |
887 } | 888 } |
888 | 889 |
889 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) | 890 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) |
890 { | 891 { |
891 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 892 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
892 if (ensureParsedDataReady()) | 893 if (ensureParsedDataReady()) |
893 sourceData = ruleSourceDataAt(styleId(style).ordinal()); | 894 sourceData = ruleSourceDataAt(styleId(style).ordinal()); |
894 | 895 |
(...skipping 13 matching lines...) Expand all Loading... |
908 bool success = getText(&sheetText); | 909 bool success = getText(&sheetText); |
909 if (success) { | 910 if (success) { |
910 const SourceRange& bodyRange = sourceData->ruleBodyRange; | 911 const SourceRange& bodyRange = sourceData->ruleBodyRange; |
911 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en
d - bodyRange.start)); | 912 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en
d - bodyRange.start)); |
912 } | 913 } |
913 } | 914 } |
914 | 915 |
915 return result.release(); | 916 return result.release(); |
916 } | 917 } |
917 | 918 |
918 PassOwnPtr<Vector<unsigned> > InspectorStyleSheetBase::lineEndings() | 919 const LineEndings* InspectorStyleSheetBase::lineEndings() |
919 { | 920 { |
| 921 if (m_lineEndings->size() > 0) |
| 922 return m_lineEndings.get(); |
920 String text; | 923 String text; |
921 if (!getText(&text)) | 924 if (getText(&text)) |
922 return PassOwnPtr<Vector<unsigned> >(); | 925 m_lineEndings = WTF::lineEndings(text); |
923 return WTF::lineEndings(text); | 926 return m_lineEndings.get(); |
924 } | 927 } |
925 | 928 |
926 bool InspectorStyleSheetBase::lineNumberAndColumnToOffset(unsigned lineNumber, u
nsigned columnNumber, unsigned* offset) | 929 bool InspectorStyleSheetBase::lineNumberAndColumnToOffset(unsigned lineNumber, u
nsigned columnNumber, unsigned* offset) |
927 { | 930 { |
928 OwnPtr<Vector<unsigned> > endings = lineEndings(); | 931 const LineEndings* endings = lineEndings(); |
929 if (lineNumber >= endings->size()) | 932 if (lineNumber >= endings->size()) |
930 return false; | 933 return false; |
931 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin
gs->at(lineNumber - 1) - 1 : endings->at(0); | 934 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin
gs->at(lineNumber - 1) - 1 : endings->at(0); |
932 if (columnNumber > charactersInLine) | 935 if (columnNumber > charactersInLine) |
933 return false; | 936 return false; |
934 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu
mber::fromZeroBasedInt(columnNumber)); | 937 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu
mber::fromZeroBasedInt(columnNumber)); |
935 *offset = position.toOffset(*endings).zeroBasedInt(); | 938 *offset = position.toOffset(*endings).zeroBasedInt(); |
936 return true; | 939 return true; |
937 } | 940 } |
938 | 941 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 m_pageStyleSheet->contents()->clearRules(); | 1033 m_pageStyleSheet->contents()->clearRules(); |
1031 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); | 1034 m_pageStyleSheet->clearChildRuleCSSOMWrappers(); |
1032 } | 1035 } |
1033 { | 1036 { |
1034 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); | 1037 CSSStyleSheet::RuleMutationScope mutationScope(m_pageStyleSheet.get()); |
1035 m_pageStyleSheet->contents()->parseString(text); | 1038 m_pageStyleSheet->contents()->parseString(text); |
1036 } | 1039 } |
1037 | 1040 |
1038 if (listener()) | 1041 if (listener()) |
1039 listener()->didReparseStyleSheet(); | 1042 listener()->didReparseStyleSheet(); |
1040 fireStyleSheetChanged(); | 1043 onStyleSheetTextChanged(); |
1041 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); | 1044 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); |
1042 return true; | 1045 return true; |
1043 } | 1046 } |
1044 | 1047 |
1045 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat
e& exceptionState) | 1048 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat
e& exceptionState) |
1046 { | 1049 { |
1047 CSSStyleRule* rule = ruleForId(id); | 1050 CSSStyleRule* rule = ruleForId(id); |
1048 if (!rule) { | 1051 if (!rule) { |
1049 exceptionState.throwDOMException(NotFoundError, "No rule was found for t
he given ID."); | 1052 exceptionState.throwDOMException(NotFoundError, "No rule was found for t
he given ID."); |
1050 return ""; | 1053 return ""; |
(...skipping 17 matching lines...) Expand all Loading... |
1068 rule->setSelectorText(selector); | 1071 rule->setSelectorText(selector); |
1069 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin
al()); | 1072 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin
al()); |
1070 if (!sourceData) { | 1073 if (!sourceData) { |
1071 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec
tor + "' could not be set."); | 1074 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec
tor + "' could not be set."); |
1072 return false; | 1075 return false; |
1073 } | 1076 } |
1074 | 1077 |
1075 String sheetText = m_parsedStyleSheet->text(); | 1078 String sheetText = m_parsedStyleSheet->text(); |
1076 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); | 1079 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); |
1077 updateText(sheetText); | 1080 updateText(sheetText); |
1078 fireStyleSheetChanged(); | 1081 onStyleSheetTextChanged(); |
1079 return true; | 1082 return true; |
1080 } | 1083 } |
1081 | 1084 |
1082 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM
ediaRule, const SourceRange& sourceRange) | 1085 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM
ediaRule, const SourceRange& sourceRange) |
1083 { | 1086 { |
1084 unsigned index = 0; | 1087 unsigned index = 0; |
1085 for (size_t i = 0; i < m_flatRules.size(); ++i) { | 1088 for (size_t i = 0; i < m_flatRules.size(); ++i) { |
1086 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i); | 1089 RefPtrWillBeRawPtr<CSSRule> rule = m_flatRules.at(i); |
1087 if (rule->parentRule() != parentMediaRule) | 1090 if (rule->parentRule() != parentMediaRule) |
1088 continue; | 1091 continue; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 return 0; | 1207 return 0; |
1205 } | 1208 } |
1206 | 1209 |
1207 ensureFlatRules(); | 1210 ensureFlatRules(); |
1208 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e
xceptionState); | 1211 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e
xceptionState); |
1209 if (exceptionState.hadException()) | 1212 if (exceptionState.hadException()) |
1210 return 0; | 1213 return 0; |
1211 | 1214 |
1212 text.insert(ruleText, location.start); | 1215 text.insert(ruleText, location.start); |
1213 | 1216 |
1214 m_parsedStyleSheet->setText(text); | 1217 updateText(text); |
1215 m_flatRules.clear(); | 1218 m_flatRules.clear(); |
1216 | 1219 |
1217 fireStyleSheetChanged(); | 1220 onStyleSheetTextChanged(); |
1218 return styleRule; | 1221 return styleRule; |
1219 } | 1222 } |
1220 | 1223 |
1221 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, const String& old
Text, ExceptionState& exceptionState) | 1224 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, const String& old
Text, ExceptionState& exceptionState) |
1222 { | 1225 { |
1223 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); | 1226 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); |
1224 if (!rule) { | 1227 if (!rule) { |
1225 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); | 1228 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); |
1226 return false; | 1229 return false; |
1227 } | 1230 } |
(...skipping 26 matching lines...) Expand all Loading... |
1254 while (index < styleSheet->length() && styleSheet->item(index) != rule) | 1257 while (index < styleSheet->length() && styleSheet->item(index) != rule) |
1255 ++index; | 1258 ++index; |
1256 ASSERT(index < styleSheet->length()); | 1259 ASSERT(index < styleSheet->length()); |
1257 styleSheet->deleteRule(index, exceptionState); | 1260 styleSheet->deleteRule(index, exceptionState); |
1258 } | 1261 } |
1259 // |rule| MAY NOT be addressed after this line! | 1262 // |rule| MAY NOT be addressed after this line! |
1260 | 1263 |
1261 if (exceptionState.hadException()) | 1264 if (exceptionState.hadException()) |
1262 return false; | 1265 return false; |
1263 | 1266 |
1264 m_parsedStyleSheet->setText(oldText); | 1267 updateText(oldText); |
1265 m_flatRules.clear(); | 1268 m_flatRules.clear(); |
1266 fireStyleSheetChanged(); | 1269 onStyleSheetTextChanged(); |
1267 return true; | 1270 return true; |
1268 } | 1271 } |
1269 | 1272 |
1270 void InspectorStyleSheet::updateText(const String& newText) | 1273 void InspectorStyleSheet::updateText(const String& newText) |
1271 { | 1274 { |
1272 Element* element = ownerStyleElement(); | 1275 Element* element = ownerStyleElement(); |
1273 if (!element) | 1276 if (!element) |
1274 m_pageAgent->addEditedResourceContent(finalURL(), newText); | 1277 m_pageAgent->addEditedResourceContent(finalURL(), newText); |
1275 m_parsedStyleSheet->setText(newText); | 1278 m_parsedStyleSheet->setText(newText); |
1276 } | 1279 } |
1277 | 1280 |
1278 | |
1279 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const | 1281 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const |
1280 { | 1282 { |
1281 ASSERT(!id.isEmpty()); | 1283 ASSERT(!id.isEmpty()); |
1282 ensureFlatRules(); | 1284 ensureFlatRules(); |
1283 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size()
? 0 : m_flatRules.at(id.ordinal()).get()); | 1285 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size()
? 0 : m_flatRules.at(id.ordinal()).get()); |
1284 } | 1286 } |
1285 | 1287 |
1286 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() const | 1288 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() const |
1287 { | 1289 { |
1288 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1290 CSSStyleSheet* styleSheet = pageStyleSheet(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 String selector = sheetText.substring(range.start, range.length()); | 1324 String selector = sheetText.substring(range.start, range.length()); |
1323 | 1325 |
1324 // We don't want to see any comments in the selector components, only th
e meaningful parts. | 1326 // We don't want to see any comments in the selector components, only th
e meaningful parts. |
1325 int matchLength; | 1327 int matchLength; |
1326 int offset = 0; | 1328 int offset = 0; |
1327 while ((offset = comment.match(selector, offset, &matchLength)) >= 0) | 1329 while ((offset = comment.match(selector, offset, &matchLength)) >= 0) |
1328 selector.replace(offset, matchLength, ""); | 1330 selector.replace(offset, matchLength, ""); |
1329 | 1331 |
1330 RefPtr<TypeBuilder::CSS::Selector> simpleSelector = TypeBuilder::CSS::Se
lector::create() | 1332 RefPtr<TypeBuilder::CSS::Selector> simpleSelector = TypeBuilder::CSS::Se
lector::create() |
1331 .setValue(selector.stripWhiteSpace()); | 1333 .setValue(selector.stripWhiteSpace()); |
1332 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings().get
())); | 1334 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); |
1333 result->addItem(simpleSelector.release()); | 1335 result->addItem(simpleSelector.release()); |
1334 } | 1336 } |
1335 return result.release(); | 1337 return result.release(); |
1336 } | 1338 } |
1337 | 1339 |
1338 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe
lectorList(CSSStyleRule* rule) | 1340 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe
lectorList(CSSStyleRule* rule) |
1339 { | 1341 { |
1340 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 1342 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
1341 if (ensureParsedDataReady()) | 1343 if (ensureParsedDataReady()) |
1342 sourceData = ruleSourceDataAt(styleId(rule->style()).ordinal()); | 1344 sourceData = ruleSourceDataAt(styleId(rule->style()).ordinal()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 return nullptr; | 1413 return nullptr; |
1412 | 1414 |
1413 ensureFlatRules(); | 1415 ensureFlatRules(); |
1414 size_t index = m_flatRules.find(rule); | 1416 size_t index = m_flatRules.find(rule); |
1415 // FIXME(lusnikov): m_flatRules are not always aligned with the m_parsedStyl
eSheet rule source | 1417 // FIXME(lusnikov): m_flatRules are not always aligned with the m_parsedStyl
eSheet rule source |
1416 // datas due to the CSSOM operations that add/remove rules without changing
source. | 1418 // datas due to the CSSOM operations that add/remove rules without changing
source. |
1417 // This is a design issue. See crbug.com/178410 | 1419 // This is a design issue. See crbug.com/178410 |
1418 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) | 1420 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) |
1419 return nullptr; | 1421 return nullptr; |
1420 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS
ourceDataAt(static_cast<unsigned>(index)); | 1422 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS
ourceDataAt(static_cast<unsigned>(index)); |
1421 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get
()); | 1423 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings()); |
1422 } | 1424 } |
1423 | 1425 |
1424 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpValu
eSourceRange(const CSSRule* rule, size_t mediaQueryIndex, size_t mediaQueryExpIn
dex) | 1426 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::mediaQueryExpValu
eSourceRange(const CSSRule* rule, size_t mediaQueryIndex, size_t mediaQueryExpIn
dex) |
1425 { | 1427 { |
1426 if (!ensureParsedDataReady()) | 1428 if (!ensureParsedDataReady()) |
1427 return nullptr; | 1429 return nullptr; |
1428 ensureFlatRules(); | 1430 ensureFlatRules(); |
1429 size_t index = m_flatRules.find(rule); | 1431 size_t index = m_flatRules.find(rule); |
1430 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) | 1432 if (index == kNotFound || index >= m_parsedStyleSheet->ruleCount()) |
1431 return nullptr; | 1433 return nullptr; |
1432 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS
ourceDataAt(static_cast<unsigned>(index)); | 1434 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS
ourceDataAt(static_cast<unsigned>(index)); |
1433 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour
ceData->queryData.size()) | 1435 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour
ceData->queryData.size()) |
1434 return nullptr; | 1436 return nullptr; |
1435 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med
iaSourceData->queryData.at(mediaQueryIndex); | 1437 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med
iaSourceData->queryData.at(mediaQueryIndex); |
1436 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) | 1438 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) |
1437 return nullptr; | 1439 return nullptr; |
1438 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex)
.valueRange, lineEndings().get()); | 1440 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex)
.valueRange, lineEndings()); |
1439 } | 1441 } |
1440 | 1442 |
1441 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(
const InspectorCSSId& id) | 1443 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(
const InspectorCSSId& id) |
1442 { | 1444 { |
1443 CSSStyleDeclaration* style = styleForId(id); | 1445 CSSStyleDeclaration* style = styleForId(id); |
1444 if (!style) | 1446 if (!style) |
1445 return nullptr; | 1447 return nullptr; |
1446 | 1448 |
1447 return InspectorStyle::create(id, style, this); | 1449 return InspectorStyle::create(id, style, this); |
1448 } | 1450 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 | 1648 |
1647 String patchedStyleSheetText; | 1649 String patchedStyleSheetText; |
1648 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee
tText); | 1650 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee
tText); |
1649 if (!success) | 1651 if (!success) |
1650 return false; | 1652 return false; |
1651 | 1653 |
1652 TrackExceptionState exceptionState; | 1654 TrackExceptionState exceptionState; |
1653 style->setCSSText(text, exceptionState); | 1655 style->setCSSText(text, exceptionState); |
1654 if (!exceptionState.hadException()) { | 1656 if (!exceptionState.hadException()) { |
1655 updateText(patchedStyleSheetText); | 1657 updateText(patchedStyleSheetText); |
1656 fireStyleSheetChanged(); | 1658 onStyleSheetTextChanged(); |
1657 } | 1659 } |
1658 | 1660 |
1659 return !exceptionState.hadException(); | 1661 return !exceptionState.hadException(); |
1660 } | 1662 } |
1661 | 1663 |
1662 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) | 1664 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) |
1663 { | 1665 { |
1664 if (!style) | 1666 if (!style) |
1665 return false; | 1667 return false; |
1666 if (!ensureParsedDataReady()) | 1668 if (!ensureParsedDataReady()) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle->
cssStyle()) | 1754 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle->
cssStyle()) |
1753 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin
eStyle(), this); | 1755 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin
eStyle(), this); |
1754 m_ruleSourceData.clear(); | 1756 m_ruleSourceData.clear(); |
1755 } | 1757 } |
1756 | 1758 |
1757 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta
te& exceptionState) | 1759 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta
te& exceptionState) |
1758 { | 1760 { |
1759 bool success = setStyleText(InspectorCSSId(id(), 0), text); | 1761 bool success = setStyleText(InspectorCSSId(id(), 0), text); |
1760 if (!success) | 1762 if (!success) |
1761 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval
id."); | 1763 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval
id."); |
1762 else | |
1763 fireStyleSheetChanged(); | |
1764 return success; | 1764 return success; |
1765 } | 1765 } |
1766 | 1766 |
1767 bool InspectorStyleSheetForInlineStyle::getText(String* result) const | 1767 bool InspectorStyleSheetForInlineStyle::getText(String* result) const |
1768 { | 1768 { |
1769 if (!m_isStyleTextValid) { | 1769 if (!m_isStyleTextValid) { |
1770 m_styleText = elementStyleText(); | 1770 m_styleText = elementStyleText(); |
1771 m_isStyleTextValid = true; | 1771 m_isStyleTextValid = true; |
1772 } | 1772 } |
1773 *result = m_styleText; | 1773 *result = m_styleText; |
1774 return true; | 1774 return true; |
1775 } | 1775 } |
1776 | 1776 |
1777 bool InspectorStyleSheetForInlineStyle::setStyleText(const InspectorCSSId& id, c
onst String& text) | 1777 bool InspectorStyleSheetForInlineStyle::setStyleText(const InspectorCSSId& id, c
onst String& text) |
1778 { | 1778 { |
1779 CSSStyleDeclaration* style = styleForId(id); | 1779 CSSStyleDeclaration* style = styleForId(id); |
1780 if (!style) | 1780 if (!style) |
1781 return false; | 1781 return false; |
1782 ASSERT_UNUSED(style, style == inlineStyle()); | 1782 ASSERT_UNUSED(style, style == inlineStyle()); |
1783 TrackExceptionState exceptionState; | 1783 TrackExceptionState exceptionState; |
1784 | 1784 |
1785 { | 1785 { |
1786 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own
erDocument()); | 1786 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own
erDocument()); |
1787 m_element->setAttribute("style", AtomicString(text), exceptionState); | 1787 m_element->setAttribute("style", AtomicString(text), exceptionState); |
1788 } | 1788 } |
1789 if (!exceptionState.hadException()) { | 1789 if (!exceptionState.hadException()) { |
1790 m_styleText = text; | 1790 m_styleText = text; |
1791 m_isStyleTextValid = true; | 1791 m_isStyleTextValid = true; |
1792 m_ruleSourceData.clear(); | 1792 m_ruleSourceData.clear(); |
1793 fireStyleSheetChanged(); | 1793 onStyleSheetTextChanged(); |
1794 } | 1794 } |
1795 return !exceptionState.hadException(); | 1795 return !exceptionState.hadException(); |
1796 } | 1796 } |
1797 | 1797 |
1798 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const | 1798 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const |
1799 { | 1799 { |
1800 return &m_element->document(); | 1800 return &m_element->document(); |
1801 } | 1801 } |
1802 | 1802 |
1803 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() | 1803 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 void InspectorStyleSheetForInlineStyle::trace(Visitor* visitor) | 1862 void InspectorStyleSheetForInlineStyle::trace(Visitor* visitor) |
1863 { | 1863 { |
1864 visitor->trace(m_element); | 1864 visitor->trace(m_element); |
1865 visitor->trace(m_ruleSourceData); | 1865 visitor->trace(m_ruleSourceData); |
1866 visitor->trace(m_inspectorStyle); | 1866 visitor->trace(m_inspectorStyle); |
1867 InspectorStyleSheetBase::trace(visitor); | 1867 InspectorStyleSheetBase::trace(visitor); |
1868 } | 1868 } |
1869 | 1869 |
1870 } // namespace blink | 1870 } // namespace blink |
1871 | 1871 |
OLD | NEW |