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

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

Issue 211193006: DevTools: [CSS] use setStyleText as undo action for setPropertyText (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add testcase 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 , m_styleSheet(styleSheet) 222 , m_styleSheet(styleSheet)
223 , m_cssId(cssId) 223 , m_cssId(cssId)
224 , m_propertyIndex(propertyIndex) 224 , m_propertyIndex(propertyIndex)
225 , m_text(text) 225 , m_text(text)
226 , m_overwrite(overwrite) 226 , m_overwrite(overwrite)
227 { 227 {
228 } 228 }
229 229
230 virtual String toString() OVERRIDE 230 virtual String toString() OVERRIDE
231 { 231 {
232 return mergeId() + ": " + m_oldText + " -> " + m_text; 232 return mergeId() + ": " + m_oldStyleText + " -> " + m_text;
233 } 233 }
234 234
235 virtual bool perform(ExceptionState& exceptionState) OVERRIDE 235 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
236 { 236 {
237 return redo(exceptionState); 237 return redo(exceptionState);
238 } 238 }
239 239
240 virtual bool undo(ExceptionState& exceptionState) OVERRIDE 240 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
241 { 241 {
242 String placeholder; 242 String placeholder;
243 return m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwri te ? m_oldText : "", true, &placeholder, exceptionState); 243 return m_styleSheet->setStyleText(m_cssId, m_oldStyleText);
244 } 244 }
245 245
246 virtual bool redo(ExceptionState& exceptionState) OVERRIDE 246 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
247 { 247 {
248 String oldText; 248 if (!m_styleSheet->getStyleText(m_cssId, &m_oldStyleText))
249 bool result = m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_ text, m_overwrite, &oldText, exceptionState); 249 return false;
250 m_oldText = oldText.stripWhiteSpace(); 250 bool result = m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_ text, m_overwrite, exceptionState);
251 return result; 251 return result;
252 } 252 }
253 253
254 virtual String mergeId() OVERRIDE 254 virtual String mergeId() OVERRIDE
255 { 255 {
256 return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf 8().data(), m_propertyIndex, m_overwrite ? "true" : "false"); 256 return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf 8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
257 } 257 }
258 258
259 virtual void merge(PassOwnPtr<Action> action) OVERRIDE 259 virtual void merge(PassOwnPtr<Action> action) OVERRIDE
260 { 260 {
261 ASSERT(action->mergeId() == mergeId()); 261 ASSERT(action->mergeId() == mergeId());
262 262
263 SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(actio n.get()); 263 SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(actio n.get());
264 m_text = other->m_text; 264 m_text = other->m_text;
265 } 265 }
266 266
267 private: 267 private:
268 RefPtr<InspectorStyleSheetBase> m_styleSheet; 268 RefPtr<InspectorStyleSheetBase> m_styleSheet;
269 InspectorCSSId m_cssId; 269 InspectorCSSId m_cssId;
270 unsigned m_propertyIndex; 270 unsigned m_propertyIndex;
271 String m_text; 271 String m_text;
272 String m_oldText; 272 String m_oldStyleText;
273 bool m_overwrite; 273 bool m_overwrite;
274 }; 274 };
275 275
276 class InspectorCSSAgent::SetRuleSelectorAction FINAL : public InspectorCSSAgent: :StyleSheetAction { 276 class InspectorCSSAgent::SetRuleSelectorAction FINAL : public InspectorCSSAgent: :StyleSheetAction {
277 WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction); 277 WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction);
278 public: 278 public:
279 SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector) 279 SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector)
280 : InspectorCSSAgent::StyleSheetAction("SetRuleSelector") 280 : InspectorCSSAgent::StyleSheetAction("SetRuleSelector")
281 , m_styleSheet(styleSheet) 281 , m_styleSheet(styleSheet)
282 , m_cssId(cssId) 282 , m_cssId(cssId)
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 documentsToChange.add(element->ownerDocument()); 1352 documentsToChange.add(element->ownerDocument());
1353 } 1353 }
1354 1354
1355 m_nodeIdToForcedPseudoState.clear(); 1355 m_nodeIdToForcedPseudoState.clear();
1356 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1356 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1357 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1357 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1358 } 1358 }
1359 1359
1360 } // namespace WebCore 1360 } // namespace WebCore
1361 1361
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698