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

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: 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 8512f7f46f3fc47e5d83c3c26ca8551779f63815..be10abd8e2b90cc5a5e21ca5a0d8f5e101e4f914 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -72,6 +72,7 @@
#include "wtf/CurrentTime.h"
#include "wtf/text/CString.h"
#include "wtf/text/StringConcatenate.h"
+#include "wtf/text/TextPosition.h"
apavlov 2014/02/20 09:58:14 This should not be here
lushnikov 2014/02/20 14:17:04 Done.
namespace CSSAgentState {
static const char cssAgentEnabled[] = "cssAgentEnabled";
@@ -837,6 +838,48 @@ void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String
*errorString = InspectorDOMAgent::toErrorString(exceptionState);
}
+void InspectorCSSAgent::replaceRangeInStyleSheetText(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text)
apavlov 2014/02/20 09:58:14 Is this going to be an undoable operation, like th
pfeldman 2014/02/20 11:29:05 editRangeInStyleSheetText?
lushnikov 2014/02/20 14:17:04 This is essentially a wrapper around setStyleSheet
lushnikov 2014/02/20 14:17:04 Done.
+{
+ InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
+ if (!inspectorStyleSheet) {
+ *errorString = "Style sheet with id " + styleSheetId + " not found.";
apavlov 2014/02/20 09:58:14 We have a convention to never place periods at the
lushnikov 2014/02/20 14:17:04 Done.
+ return;
+ }
+ int startLineNumber;
+ int startColumn;
+ int endLineNumber;
+ int endColumn;
+ if (!range->getNumber("startLine", &startLineNumber)) {
+ *errorString = "range.startLine is not an integer value.";
+ return;
+ }
+ if (!range->getNumber("startColumn", &startColumn)) {
+ *errorString = "range.startColumn is not an integer value.";
+ return;
+ }
+ if (!range->getNumber("endLine", &endLineNumber)) {
+ *errorString = "range.endLine is not an integer value.";
+ return;
+ }
+ if (!range->getNumber("endColumn", &endColumn)) {
+ *errorString = "range.endColumn is not an integer value.";
+ return;
+ }
+ String oldText;
+ if (!inspectorStyleSheet->getText(&oldText)) {
+ *errorString = "Failed to fetch stylesheet text.";
+ return;
+ }
+
+ TextPosition startPosition(OrdinalNumber::fromZeroBasedInt(startLineNumber), OrdinalNumber::fromZeroBasedInt(startColumn));
apavlov 2014/02/20 09:58:14 This code doesn't seem to belong to ICSSAgent (for
lushnikov 2014/02/20 14:17:04 InspectorStyleSheet soaked all the logic in its li
+ TextPosition endPosition(OrdinalNumber::fromZeroBasedInt(endLineNumber), OrdinalNumber::fromZeroBasedInt(endColumn));
+ OwnPtr<Vector<unsigned> > lineEndings = inspectorStyleSheet->lineEndings();
+ int startOffset = startPosition.toOffsetPosition(*lineEndings.get()).zeroBasedInt();
apavlov 2014/02/20 09:58:14 You don't need .get() here, just (*lineEndings)
lushnikov 2014/02/20 14:17:04 Done.
+ int endOffset = endPosition.toOffsetPosition(*lineEndings.get()).zeroBasedInt();
apavlov 2014/02/20 09:58:14 ditto
lushnikov 2014/02/20 14:17:04 Done.
+ 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