| Index: Source/core/inspector/InspectorCSSAgent.cpp
|
| diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
|
| index 29b4c5baefbcabef4ccf1ae5b91a5ba973dd1df9..726fbd98cb74d08a5e24f5bafe952298ad8086fb 100644
|
| --- a/Source/core/inspector/InspectorCSSAgent.cpp
|
| +++ b/Source/core/inspector/InspectorCSSAgent.cpp
|
| @@ -828,7 +828,7 @@ void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String
|
| {
|
| InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
|
| if (!inspectorStyleSheet) {
|
| - *errorString = "Style sheet with id " + styleSheetId + " not found.";
|
| + *errorString = "Style sheet with id " + styleSheetId + " not found";
|
| return;
|
| }
|
|
|
| @@ -837,6 +837,58 @@ void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String
|
| *errorString = InspectorDOMAgent::toErrorString(exceptionState);
|
| }
|
|
|
| +static bool extractRangeComponent(ErrorString* errorString, const RefPtr<JSONObject>& range, const String& component, unsigned& result)
|
| +{
|
| + int parsedValue;
|
| + if (!range->getNumber(component, &parsedValue) || parsedValue < 0) {
|
| + *errorString = "range." + component + " must be a non-negative integer";
|
| + return false;
|
| + }
|
| + result = parsedValue;
|
| + return true;
|
| +}
|
| +
|
| +void InspectorCSSAgent::editRangeInStyleSheetText(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text)
|
| +{
|
| + InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
|
| + if (!inspectorStyleSheet) {
|
| + *errorString = "Stylesheet with id " + styleSheetId + " not found";
|
| + return;
|
| + }
|
| + unsigned startLineNumber;
|
| + unsigned startColumn;
|
| + unsigned endLineNumber;
|
| + unsigned endColumn;
|
| + if (!extractRangeComponent(errorString, range, "startLine", startLineNumber)
|
| + || !extractRangeComponent(errorString, range, "startColumn", startColumn)
|
| + || !extractRangeComponent(errorString, range, "endLine", endLineNumber)
|
| + || !extractRangeComponent(errorString, range, "endColumn", endColumn))
|
| + return;
|
| +
|
| + String oldText;
|
| + if (!inspectorStyleSheet->getText(&oldText)) {
|
| + *errorString = "Failed to fetch stylesheet text";
|
| + return;
|
| + }
|
| +
|
| + unsigned startOffset;
|
| + unsigned endOffset;
|
| + bool success = inspectorStyleSheet->lineNumberAndColumnToOffset(startLineNumber, startColumn, &startOffset)
|
| + && inspectorStyleSheet->lineNumberAndColumnToOffset(endLineNumber, endColumn, &endOffset);
|
| + if (!success) {
|
| + *errorString = "Specified range is out of bounds";
|
| + return;
|
| + }
|
| +
|
| + if (startOffset > endOffset) {
|
| + *errorString = "Range start must not succeed its end";
|
| + return;
|
| + }
|
| +
|
| + oldText.replace(startOffset, endOffset - startOffset, text);
|
| + setStyleSheetText(errorString, styleSheetId, oldText);
|
| +}
|
| +
|
| void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<JSONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
|
| {
|
| InspectorCSSId compoundId(fullStyleId);
|
|
|