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

Unified Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 172593003: DevTools: [CSS] Add CSS.editRangeInStyleSheetText() to the protocol (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address vsevik comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698