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

Side by Side 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: fix glitch Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 SetStyleSheetTextAction* other = static_cast<SetStyleSheetTextAction*>(a ction.get()); 218 SetStyleSheetTextAction* other = static_cast<SetStyleSheetTextAction*>(a ction.get());
219 m_text = other->m_text; 219 m_text = other->m_text;
220 } 220 }
221 221
222 private: 222 private:
223 String m_text; 223 String m_text;
224 String m_oldText; 224 String m_oldText;
225 }; 225 };
226 226
227 class InspectorCSSAgent::EditRangeInStyleSheetTextAction FINAL : public Inspecto rCSSAgent::StyleSheetAction {
228 WTF_MAKE_NONCOPYABLE(EditRangeInStyleSheetTextAction);
229 public:
230 EditRangeInStyleSheetTextAction(InspectorStyleSheet* styleSheet, const Strin g& text, unsigned rangeStart, unsigned rangeEnd)
231 : InspectorCSSAgent::StyleSheetAction("EditRangeInStyleSheetTextAction", styleSheet)
232 , m_text(text)
233 , m_rangeStart(rangeStart)
234 , m_rangeEnd(rangeEnd)
235 , m_externalEditRangeResult(0)
236 {
237 }
238
239 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
240 {
241 return redo(exceptionState);
242 }
243
244 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
245 {
246 if (m_styleSheet->setText(m_oldText, exceptionState)) {
247 m_styleSheet->reparseStyleSheet(m_oldText);
248 return true;
249 }
250 return false;
251 }
252
253 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
254 {
255 if (!m_styleSheet->getText(&m_oldText))
256 return false;
257 InspectorStyleSheet::EditRangeResult placeholder;
258 InspectorStyleSheet::EditRangeResult* editRangeResult = m_externalEditRa ngeResult ? m_externalEditRangeResult : &placeholder;
259 m_externalEditRangeResult = 0;
260 return m_styleSheet->editRange(m_text, m_rangeStart, m_rangeEnd, editRan geResult, exceptionState);
261 }
262
263 virtual String mergeId() OVERRIDE
264 {
265 return String::format("EditRangeInStyleSheetTextAction %s:%u:%u", m_styl eSheet->id().utf8().data(), m_rangeStart, m_rangeEnd);
266 }
267
268 virtual void merge(PassOwnPtr<Action> action) OVERRIDE
269 {
270 ASSERT(action->mergeId() == mergeId());
271
272 EditRangeInStyleSheetTextAction* other = static_cast<EditRangeInStyleShe etTextAction*>(action.get());
273 m_text = other->m_text;
274 }
275
276 void setExternalEditRangeResult(InspectorStyleSheet::EditRangeResult* editRa ngeResult)
277 {
278 m_externalEditRangeResult = editRangeResult;
279 }
280
281 private:
282 String m_text;
283 unsigned m_rangeStart;
284 unsigned m_rangeEnd;
285 String m_oldText;
286 InspectorStyleSheet::EditRangeResult* m_externalEditRangeResult;
287 };
288
227 class InspectorCSSAgent::SetPropertyTextAction FINAL : public InspectorCSSAgent: :StyleSheetAction { 289 class InspectorCSSAgent::SetPropertyTextAction FINAL : public InspectorCSSAgent: :StyleSheetAction {
228 WTF_MAKE_NONCOPYABLE(SetPropertyTextAction); 290 WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
229 public: 291 public:
230 SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite) 292 SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
231 : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet) 293 : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet)
232 , m_cssId(cssId) 294 , m_cssId(cssId)
233 , m_propertyIndex(propertyIndex) 295 , m_propertyIndex(propertyIndex)
234 , m_text(text) 296 , m_text(text)
235 , m_overwrite(overwrite) 297 , m_overwrite(overwrite)
236 { 298 {
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (!inspectorStyleSheet) 883 if (!inspectorStyleSheet)
822 return; 884 return;
823 885
824 inspectorStyleSheet->getText(result); 886 inspectorStyleSheet->getText(result);
825 } 887 }
826 888
827 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text) 889 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text)
828 { 890 {
829 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 891 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
830 if (!inspectorStyleSheet) { 892 if (!inspectorStyleSheet) {
831 *errorString = "Style sheet with id " + styleSheetId + " not found."; 893 *errorString = "Style sheet with id " + styleSheetId + " not found";
832 return; 894 return;
833 } 895 }
834 896
835 TrackExceptionState exceptionState; 897 TrackExceptionState exceptionState;
836 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState); 898 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState);
837 *errorString = InspectorDOMAgent::toErrorString(exceptionState); 899 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
838 } 900 }
839 901
902 static bool extractRangeComponent(ErrorString* errorString, const RefPtr<JSONObj ect>& range, const String& component, unsigned& result)
903 {
904 int parsedValue;
905 if (!range->getNumber(component, &parsedValue) || parsedValue < 0) {
906 *errorString = "range." + component + " must be a non-negative integer";
907 return false;
908 }
909 result = parsedValue;
910 return true;
911 }
912
913 void InspectorCSSAgent::editRangeInStyleSheetText(ErrorString* errorString, cons t String& styleSheetId, const RefPtr<JSONObject>& range, const String& text, Ref Ptr<TypeBuilder::CSS::CSSRule>& rule, RefPtr<TypeBuilder::CSS::CSSStyle>& style)
914 {
915 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
916 if (!inspectorStyleSheet) {
917 *errorString = "Stylesheet with id " + styleSheetId + " not found";
918 return;
919 }
920 unsigned startLineNumber;
921 unsigned startColumn;
922 unsigned endLineNumber;
923 unsigned endColumn;
924 if (!extractRangeComponent(errorString, range, "startLine", startLineNumber)
925 || !extractRangeComponent(errorString, range, "startColumn", startColumn )
926 || !extractRangeComponent(errorString, range, "endLine", endLineNumber)
927 || !extractRangeComponent(errorString, range, "endColumn", endColumn))
928 return;
929
930 unsigned startOffset;
931 unsigned endOffset;
932 bool success = inspectorStyleSheet->lineNumberAndColumnToOffset(startLineNum ber, startColumn, &startOffset)
933 && inspectorStyleSheet->lineNumberAndColumnToOffset(endLineNumber, endCo lumn, &endOffset);
934 if (!success) {
935 *errorString = "Specified range is out of bounds";
936 return;
937 }
938
939 if (startOffset > endOffset) {
940 *errorString = "Range start must not succeed its end";
941 return;
942 }
943
944 TrackExceptionState exceptionState;
945 OwnPtr<EditRangeInStyleSheetTextAction> editAction = adoptPtr(new EditRangeI nStyleSheetTextAction(inspectorStyleSheet, text, startOffset, endOffset));
946 InspectorStyleSheet::EditRangeResult editRangeResult;
947 editAction->setExternalEditRangeResult(&editRangeResult);
vsevik 2014/03/13 10:44:51 Wouldn't it be simpler to add an actionResult gett
948 if (!m_domAgent->history()->perform(editAction.release(), exceptionState)) {
949 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
950 return;
951 }
952 if (editRangeResult.rule) {
953 rule = inspectorStyleSheet->buildObjectForRule(editRangeResult.rule.get( ), buildMediaListChain(editRangeResult.rule.get()));
954 } else if (editRangeResult.style) {
955 style = inspectorStyleSheet->buildObjectForStyle(editRangeResult.style.g et());
956 }
957 }
958
840 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result) 959 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
841 { 960 {
842 InspectorCSSId compoundId(fullStyleId); 961 InspectorCSSId compoundId(fullStyleId);
843 ASSERT(!compoundId.isEmpty()); 962 ASSERT(!compoundId.isEmpty());
844 963
845 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId()); 964 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId());
846 if (!inspectorStyleSheet) 965 if (!inspectorStyleSheet)
847 return; 966 return;
848 967
849 TrackExceptionState exceptionState; 968 TrackExceptionState exceptionState;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 documentsToChange.add(element->ownerDocument()); 1456 documentsToChange.add(element->ownerDocument());
1338 } 1457 }
1339 1458
1340 m_nodeIdToForcedPseudoState.clear(); 1459 m_nodeIdToForcedPseudoState.clear();
1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1460 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1461 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1343 } 1462 }
1344 1463
1345 } // namespace WebCore 1464 } // namespace WebCore
1346 1465
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698