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

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 1187193005: DevTools: migrate from CSS.setPropertyText to CSS.setStyleText (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: all tests passing Created 5 years, 6 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 visitor->trace(m_styleSheet); 207 visitor->trace(m_styleSheet);
208 InspectorCSSAgent::StyleSheetAction::trace(visitor); 208 InspectorCSSAgent::StyleSheetAction::trace(visitor);
209 } 209 }
210 210
211 private: 211 private:
212 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet; 212 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet;
213 String m_text; 213 String m_text;
214 String m_oldText; 214 String m_oldText;
215 }; 215 };
216 216
217 class InspectorCSSAgent::SetPropertyTextAction final : public InspectorCSSAgent: :StyleSheetAction {
218 WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
219 public:
220 SetPropertyTextAction(InspectorStyleSheetBase* styleSheet, unsigned ruleInde x, unsigned propertyIndex, const String& text, bool overwrite)
221 : InspectorCSSAgent::StyleSheetAction("SetPropertyText")
222 , m_styleSheet(styleSheet)
223 , m_ruleIndex(ruleIndex)
224 , m_propertyIndex(propertyIndex)
225 , m_text(text)
226 , m_overwrite(overwrite)
227 {
228 }
229
230 virtual String toString() override
231 {
232 return mergeId() + ": " + m_oldStyleText + " -> " + m_text;
233 }
234
235 virtual bool perform(ExceptionState& exceptionState) override
236 {
237 return redo(exceptionState);
238 }
239
240 virtual bool undo(ExceptionState& exceptionState) override
241 {
242 String placeholder;
243 return m_styleSheet->setStyleText(m_ruleIndex, m_oldStyleText);
244 }
245
246 virtual bool redo(ExceptionState& exceptionState) override
247 {
248 if (!m_styleSheet->getStyleText(m_ruleIndex, &m_oldStyleText))
249 return false;
250 bool result = m_styleSheet->setPropertyText(m_ruleIndex, m_propertyIndex , m_text, m_overwrite, exceptionState);
251 m_styleSheet->getStyleText(m_ruleIndex, &m_newStyleText);
252 return result;
253 }
254
255 virtual String mergeId() override
256 {
257 return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf 8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
258 }
259
260 virtual void merge(PassRefPtrWillBeRawPtr<Action> action) override
261 {
262 ASSERT(action->mergeId() == mergeId());
263
264 SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(actio n.get());
265 m_text = other->m_text;
266 m_newStyleText = other->m_newStyleText;
267 }
268
269 virtual bool isNoop() override
270 {
271 return m_newStyleText == m_oldStyleText;
272 }
273
274 DEFINE_INLINE_VIRTUAL_TRACE()
275 {
276 visitor->trace(m_styleSheet);
277 InspectorCSSAgent::StyleSheetAction::trace(visitor);
278 }
279
280 private:
281 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet;
282 unsigned m_ruleIndex;
283 unsigned m_propertyIndex;
284 String m_text;
285 String m_oldStyleText;
286 String m_newStyleText;
287 bool m_overwrite;
288 };
289
290 class InspectorCSSAgent::ModifyRuleAction final : public InspectorCSSAgent::Styl eSheetAction { 217 class InspectorCSSAgent::ModifyRuleAction final : public InspectorCSSAgent::Styl eSheetAction {
291 WTF_MAKE_NONCOPYABLE(ModifyRuleAction); 218 WTF_MAKE_NONCOPYABLE(ModifyRuleAction);
292 public: 219 public:
293 enum Type { 220 enum Type {
294 SetRuleSelector, 221 SetRuleSelector,
295 SetStyleText, 222 SetStyleText,
296 SetMediaRuleText 223 SetMediaRuleText
297 }; 224 };
298 225
299 ModifyRuleAction(Type type, InspectorStyleSheet* styleSheet, const SourceRan ge& range, const String& text) 226 ModifyRuleAction(Type type, InspectorStyleSheet* styleSheet, const SourceRan ge& range, const String& text)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 visitor->trace(m_styleSheet); 283 visitor->trace(m_styleSheet);
357 visitor->trace(m_cssRule); 284 visitor->trace(m_cssRule);
358 InspectorCSSAgent::StyleSheetAction::trace(visitor); 285 InspectorCSSAgent::StyleSheetAction::trace(visitor);
359 } 286 }
360 287
361 virtual String mergeId() override 288 virtual String mergeId() override
362 { 289 {
363 return String::format("ModifyRuleAction:%d %s:%d", m_type, m_styleSheet- >id().utf8().data(), m_oldRange.start); 290 return String::format("ModifyRuleAction:%d %s:%d", m_type, m_styleSheet- >id().utf8().data(), m_oldRange.start);
364 } 291 }
365 292
293 virtual bool isNoop() override
294 {
295 return m_oldText == m_newText;
296 }
297
366 virtual void merge(PassRefPtrWillBeRawPtr<Action> action) override 298 virtual void merge(PassRefPtrWillBeRawPtr<Action> action) override
367 { 299 {
368 ASSERT(action->mergeId() == mergeId()); 300 ASSERT(action->mergeId() == mergeId());
369 301
370 ModifyRuleAction* other = static_cast<ModifyRuleAction*>(action.get()); 302 ModifyRuleAction* other = static_cast<ModifyRuleAction*>(action.get());
371 m_newText = other->m_newText; 303 m_newText = other->m_newText;
372 m_newRange = other->m_newRange; 304 m_newRange = other->m_newRange;
373 } 305 }
374 306
375 private: 307 private:
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 946
1015 if (startOffset > endOffset) { 947 if (startOffset > endOffset) {
1016 *errorString = "Range start must not succeed its end"; 948 *errorString = "Range start must not succeed its end";
1017 return false; 949 return false;
1018 } 950 }
1019 sourceRange->start = startOffset; 951 sourceRange->start = startOffset;
1020 sourceRange->end = endOffset; 952 sourceRange->end = endOffset;
1021 return true; 953 return true;
1022 } 954 }
1023 955
1024 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBu ilder::CSS::CSSStyle>& result)
1025 {
1026 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt ring, styleSheetId);
1027 if (!inspectorStyleSheet)
1028 return;
1029 SourceRange propertyRange;
1030 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &proper tyRange))
1031 return;
1032 unsigned ruleIndex = 0;
1033 unsigned propertyIndex = 0;
1034 bool overwrite;
1035 if (!inspectorStyleSheet->findPropertyByRange(propertyRange, &ruleIndex, &pr opertyIndex, &overwrite)) {
1036 *errorString = "Source range didn't match any existing property source r ange nor any property insertion point";
1037 return;
1038 }
1039
1040 TrackExceptionState exceptionState;
1041 bool success = m_domAgent->history()->perform(adoptRefWillBeNoop(new SetProp ertyTextAction(inspectorStyleSheet, ruleIndex, propertyIndex, text, overwrite)), exceptionState);
1042 if (success)
1043 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->s tyleAt(ruleIndex));
1044 *errorString = InspectorDOMAgent::toErrorString(exceptionState);
1045 }
1046
1047 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty peBuilder::CSS::CSSRule>& result) 956 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty peBuilder::CSS::CSSRule>& result)
1048 { 957 {
1049 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); 958 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId);
1050 if (!inspectorStyleSheet) { 959 if (!inspectorStyleSheet) {
1051 *errorString = "Stylesheet not found"; 960 *errorString = "Stylesheet not found";
1052 return; 961 return;
1053 } 962 }
1054 SourceRange selectorRange; 963 SourceRange selectorRange;
1055 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) 964 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange))
1056 return; 965 return;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 visitor->trace(m_documentToCSSStyleSheets); 1585 visitor->trace(m_documentToCSSStyleSheets);
1677 visitor->trace(m_invalidatedDocuments); 1586 visitor->trace(m_invalidatedDocuments);
1678 visitor->trace(m_nodeToInspectorStyleSheet); 1587 visitor->trace(m_nodeToInspectorStyleSheet);
1679 visitor->trace(m_documentToViaInspectorStyleSheet); 1588 visitor->trace(m_documentToViaInspectorStyleSheet);
1680 #endif 1589 #endif
1681 visitor->trace(m_inspectorUserAgentStyleSheet); 1590 visitor->trace(m_inspectorUserAgentStyleSheet);
1682 InspectorBaseAgent::trace(visitor); 1591 InspectorBaseAgent::trace(visitor);
1683 } 1592 }
1684 1593
1685 } // namespace blink 1594 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698