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

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: 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 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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (!inspectorStyleSheet) 821 if (!inspectorStyleSheet)
822 return; 822 return;
823 823
824 inspectorStyleSheet->getText(result); 824 inspectorStyleSheet->getText(result);
825 } 825 }
826 826
827 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text) 827 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String & styleSheetId, const String& text)
828 { 828 {
829 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId); 829 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
830 if (!inspectorStyleSheet) { 830 if (!inspectorStyleSheet) {
831 *errorString = "Style sheet with id " + styleSheetId + " not found."; 831 *errorString = "Style sheet with id " + styleSheetId + " not found";
832 return; 832 return;
833 } 833 }
834 834
835 TrackExceptionState exceptionState; 835 TrackExceptionState exceptionState;
836 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState); 836 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspecto rStyleSheet, text)), exceptionState);
837 *errorString = InspectorDOMAgent::toErrorString(exceptionState); 837 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
838 } 838 }
839 839
840 static bool extractRangeComponent(ErrorString* errorString, const RefPtr<JSONObj ect>& range, const String& component, unsigned& result)
841 {
842 int parsedValue;
843 if (!range->getNumber(component, &parsedValue) || parsedValue < 0) {
844 *errorString = "range." + component + " must be a non-negative integer";
845 return false;
846 }
847 result = parsedValue;
848 return true;
849 }
850
851 void InspectorCSSAgent::editRangeInStyleSheetText(ErrorString* errorString, cons t String& styleSheetId, const RefPtr<JSONObject>& range, const String& text)
852 {
853 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , styleSheetId);
854 if (!inspectorStyleSheet) {
855 *errorString = "Stylesheet with id " + styleSheetId + " not found";
856 return;
857 }
858 unsigned startLineNumber;
859 unsigned startColumn;
860 unsigned endLineNumber;
861 unsigned endColumn;
862 if (!extractRangeComponent(errorString, range, "startLine", startLineNumber)
863 || !extractRangeComponent(errorString, range, "startColumn", startColumn )
864 || !extractRangeComponent(errorString, range, "endLine", endLineNumber)
865 || !extractRangeComponent(errorString, range, "endColumn", endColumn))
866 return;
867
868 String oldText;
869 if (!inspectorStyleSheet->getText(&oldText)) {
870 *errorString = "Failed to fetch stylesheet text";
871 return;
872 }
873
874 unsigned startOffset;
875 unsigned endOffset;
876 bool success = inspectorStyleSheet->lineNumberAndColumnToOffset(startLineNum ber, startColumn, &startOffset)
877 && inspectorStyleSheet->lineNumberAndColumnToOffset(endLineNumber, endCo lumn, &endOffset);
878 if (!success) {
879 *errorString = "Specified range is out of bounds";
880 return;
881 }
882
883 if (startOffset > endOffset) {
884 *errorString = "Range start must not succeed its end";
885 return;
886 }
887
888 oldText.replace(startOffset, endOffset - startOffset, text);
889 setStyleSheetText(errorString, styleSheetId, oldText);
890 }
891
840 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result) 892 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<J SONObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
841 { 893 {
842 InspectorCSSId compoundId(fullStyleId); 894 InspectorCSSId compoundId(fullStyleId);
843 ASSERT(!compoundId.isEmpty()); 895 ASSERT(!compoundId.isEmpty());
844 896
845 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId()); 897 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString , compoundId.styleSheetId());
846 if (!inspectorStyleSheet) 898 if (!inspectorStyleSheet)
847 return; 899 return;
848 900
849 TrackExceptionState exceptionState; 901 TrackExceptionState exceptionState;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 documentsToChange.add(element->ownerDocument()); 1372 documentsToChange.add(element->ownerDocument());
1321 } 1373 }
1322 1374
1323 m_nodeIdToForcedPseudoState.clear(); 1375 m_nodeIdToForcedPseudoState.clear();
1324 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1376 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1325 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1377 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1326 } 1378 }
1327 1379
1328 } // namespace WebCore 1380 } // namespace WebCore
1329 1381
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698