| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 926 |
| 995 if (startOffset > endOffset) { | 927 if (startOffset > endOffset) { |
| 996 *errorString = "Range start must not succeed its end"; | 928 *errorString = "Range start must not succeed its end"; |
| 997 return false; | 929 return false; |
| 998 } | 930 } |
| 999 sourceRange->start = startOffset; | 931 sourceRange->start = startOffset; |
| 1000 sourceRange->end = endOffset; | 932 sourceRange->end = endOffset; |
| 1001 return true; | 933 return true; |
| 1002 } | 934 } |
| 1003 | 935 |
| 1004 void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const String&
styleSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBu
ilder::CSS::CSSStyle>& result) | |
| 1005 { | |
| 1006 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt
ring, styleSheetId); | |
| 1007 if (!inspectorStyleSheet) | |
| 1008 return; | |
| 1009 SourceRange propertyRange; | |
| 1010 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &proper
tyRange)) | |
| 1011 return; | |
| 1012 unsigned ruleIndex = 0; | |
| 1013 unsigned propertyIndex = 0; | |
| 1014 bool overwrite; | |
| 1015 if (!inspectorStyleSheet->findPropertyByRange(propertyRange, &ruleIndex, &pr
opertyIndex, &overwrite)) { | |
| 1016 *errorString = "Source range didn't match any existing property source r
ange nor any property insertion point"; | |
| 1017 return; | |
| 1018 } | |
| 1019 | |
| 1020 TrackExceptionState exceptionState; | |
| 1021 bool success = m_domAgent->history()->perform(adoptRefWillBeNoop(new SetProp
ertyTextAction(inspectorStyleSheet, ruleIndex, propertyIndex, text, overwrite)),
exceptionState); | |
| 1022 if (success) | |
| 1023 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->s
tyleAt(ruleIndex)); | |
| 1024 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | |
| 1025 } | |
| 1026 | |
| 1027 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String&
styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty
peBuilder::CSS::CSSRule>& result) | 936 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String&
styleSheetId, const RefPtr<JSONObject>& range, const String& selector, RefPtr<Ty
peBuilder::CSS::CSSRule>& result) |
| 1028 { | 937 { |
| 1029 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); | 938 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); |
| 1030 if (!inspectorStyleSheet) { | 939 if (!inspectorStyleSheet) { |
| 1031 *errorString = "Stylesheet not found"; | 940 *errorString = "Stylesheet not found"; |
| 1032 return; | 941 return; |
| 1033 } | 942 } |
| 1034 SourceRange selectorRange; | 943 SourceRange selectorRange; |
| 1035 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select
orRange)) | 944 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select
orRange)) |
| 1036 return; | 945 return; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 visitor->trace(m_documentToCSSStyleSheets); | 1565 visitor->trace(m_documentToCSSStyleSheets); |
| 1657 visitor->trace(m_invalidatedDocuments); | 1566 visitor->trace(m_invalidatedDocuments); |
| 1658 visitor->trace(m_nodeToInspectorStyleSheet); | 1567 visitor->trace(m_nodeToInspectorStyleSheet); |
| 1659 visitor->trace(m_documentToViaInspectorStyleSheet); | 1568 visitor->trace(m_documentToViaInspectorStyleSheet); |
| 1660 #endif | 1569 #endif |
| 1661 visitor->trace(m_inspectorUserAgentStyleSheet); | 1570 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 1662 InspectorBaseAgent::trace(visitor); | 1571 InspectorBaseAgent::trace(visitor); |
| 1663 } | 1572 } |
| 1664 | 1573 |
| 1665 } // namespace blink | 1574 } // namespace blink |
| OLD | NEW |