| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 private: | 280 private: |
| 281 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet; | 281 RefPtrWillBeMember<InspectorStyleSheetBase> m_styleSheet; |
| 282 unsigned m_ruleIndex; | 282 unsigned m_ruleIndex; |
| 283 unsigned m_propertyIndex; | 283 unsigned m_propertyIndex; |
| 284 String m_text; | 284 String m_text; |
| 285 String m_oldStyleText; | 285 String m_oldStyleText; |
| 286 String m_newStyleText; | 286 String m_newStyleText; |
| 287 bool m_overwrite; | 287 bool m_overwrite; |
| 288 }; | 288 }; |
| 289 | 289 |
| 290 class InspectorCSSAgent::SetRuleSelectorOrMediaAction final : public InspectorCS
SAgent::StyleSheetAction { | 290 class InspectorCSSAgent::ModifyRuleAction final : public InspectorCSSAgent::Styl
eSheetAction { |
| 291 WTF_MAKE_NONCOPYABLE(SetRuleSelectorOrMediaAction); | 291 WTF_MAKE_NONCOPYABLE(ModifyRuleAction); |
| 292 public: | 292 public: |
| 293 SetRuleSelectorOrMediaAction(bool isMedia, InspectorStyleSheet* styleSheet,
const SourceRange& range, const String& text) | 293 enum Type { |
| 294 : InspectorCSSAgent::StyleSheetAction("SetRuleSelectorOrMediaAction") | 294 SetRuleSelector, |
| 295 SetStyleText, |
| 296 SetMediaRuleText |
| 297 }; |
| 298 |
| 299 ModifyRuleAction(Type type, InspectorStyleSheet* styleSheet, const SourceRan
ge& range, const String& text) |
| 300 : InspectorCSSAgent::StyleSheetAction("ModifyRuleAction") |
| 295 , m_styleSheet(styleSheet) | 301 , m_styleSheet(styleSheet) |
| 296 , m_isMedia(isMedia) | 302 , m_type(type) |
| 297 , m_range(range) | 303 , m_newText(text) |
| 298 , m_text(text) | 304 , m_oldRange(range) |
| 299 , m_cssRule(nullptr) | 305 , m_cssRule(nullptr) |
| 300 { | 306 { |
| 301 } | 307 } |
| 302 | 308 |
| 303 virtual bool perform(ExceptionState& exceptionState) override | 309 virtual bool perform(ExceptionState& exceptionState) override |
| 304 { | 310 { |
| 305 return redo(exceptionState); | 311 return redo(exceptionState); |
| 306 } | 312 } |
| 307 | 313 |
| 308 virtual bool undo(ExceptionState& exceptionState) override | 314 virtual bool undo(ExceptionState& exceptionState) override |
| 309 { | 315 { |
| 310 if (m_isMedia) | 316 switch (m_type) { |
| 317 case SetRuleSelector: |
| 318 return m_styleSheet->setRuleSelector(m_newRange, m_oldText, nullptr,
nullptr, exceptionState); |
| 319 case SetStyleText: |
| 320 return m_styleSheet->setStyleText(m_newRange, m_oldText, nullptr, nu
llptr, exceptionState); |
| 321 case SetMediaRuleText: |
| 311 return m_styleSheet->setMediaRuleText(m_newRange, m_oldText, nullptr
, nullptr, exceptionState); | 322 return m_styleSheet->setMediaRuleText(m_newRange, m_oldText, nullptr
, nullptr, exceptionState); |
| 312 return m_styleSheet->setRuleSelector(m_newRange, m_oldText, nullptr, nul
lptr, exceptionState); | 323 default: |
| 324 ASSERT_NOT_REACHED(); |
| 325 } |
| 313 } | 326 } |
| 314 | 327 |
| 315 virtual bool redo(ExceptionState& exceptionState) override | 328 virtual bool redo(ExceptionState& exceptionState) override |
| 316 { | 329 { |
| 317 if (m_isMedia) | 330 switch (m_type) { |
| 318 m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRa
nge, &m_oldText, exceptionState); | 331 case SetRuleSelector: |
| 319 else | 332 m_cssRule = m_styleSheet->setRuleSelector(m_oldRange, m_newText, &m_
newRange, &m_oldText, exceptionState); |
| 320 m_cssRule = m_styleSheet->setRuleSelector(m_range, m_text, &m_newRan
ge, &m_oldText, exceptionState); | 333 break; |
| 334 case SetStyleText: |
| 335 m_cssRule = m_styleSheet->setStyleText(m_oldRange, m_newText, &m_new
Range, &m_oldText, exceptionState); |
| 336 break; |
| 337 case SetMediaRuleText: |
| 338 m_cssRule = m_styleSheet->setMediaRuleText(m_oldRange, m_newText, &m
_newRange, &m_oldText, exceptionState); |
| 339 break; |
| 340 default: |
| 341 ASSERT_NOT_REACHED(); |
| 342 } |
| 321 return m_cssRule; | 343 return m_cssRule; |
| 322 } | 344 } |
| 323 | 345 |
| 324 RefPtrWillBeRawPtr<CSSRule> takeRule() | 346 RefPtrWillBeRawPtr<CSSRule> takeRule() |
| 325 { | 347 { |
| 326 RefPtrWillBeRawPtr<CSSRule> result = m_cssRule; | 348 RefPtrWillBeRawPtr<CSSRule> result = m_cssRule; |
| 327 m_cssRule = nullptr; | 349 m_cssRule = nullptr; |
| 328 return result; | 350 return result; |
| 329 } | 351 } |
| 330 | 352 |
| 331 DEFINE_INLINE_VIRTUAL_TRACE() | 353 DEFINE_INLINE_VIRTUAL_TRACE() |
| 332 { | 354 { |
| 333 visitor->trace(m_styleSheet); | 355 visitor->trace(m_styleSheet); |
| 334 visitor->trace(m_cssRule); | 356 visitor->trace(m_cssRule); |
| 335 InspectorCSSAgent::StyleSheetAction::trace(visitor); | 357 InspectorCSSAgent::StyleSheetAction::trace(visitor); |
| 336 } | 358 } |
| 337 | 359 |
| 360 virtual String mergeId() override |
| 361 { |
| 362 return String::format("ModifyRuleAction:%d %s:%d", m_type, m_styleSheet-
>id().utf8().data(), m_oldRange.start); |
| 363 } |
| 364 |
| 365 virtual void merge(PassRefPtrWillBeRawPtr<Action> action) override |
| 366 { |
| 367 ASSERT(action->mergeId() == mergeId()); |
| 368 |
| 369 ModifyRuleAction* other = static_cast<ModifyRuleAction*>(action.get()); |
| 370 m_newText = other->m_newText; |
| 371 m_newRange = other->m_newRange; |
| 372 } |
| 373 |
| 338 private: | 374 private: |
| 339 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 375 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
| 340 bool m_isMedia; | 376 Type m_type; |
| 341 SourceRange m_range; | 377 String m_oldText; |
| 378 String m_newText; |
| 379 SourceRange m_oldRange; |
| 380 SourceRange m_newRange; |
| 381 RefPtrWillBeMember<CSSRule> m_cssRule; |
| 382 }; |
| 383 |
| 384 class InspectorCSSAgent::SetElementStyleAction final : public InspectorCSSAgent:
:StyleSheetAction { |
| 385 WTF_MAKE_NONCOPYABLE(SetElementStyleAction); |
| 386 public: |
| 387 SetElementStyleAction(InspectorStyleSheetForInlineStyle* styleSheet, const S
tring& text) |
| 388 : InspectorCSSAgent::StyleSheetAction("SetElementStyleAction") |
| 389 , m_styleSheet(styleSheet) |
| 390 , m_text(text) |
| 391 { |
| 392 } |
| 393 |
| 394 virtual bool perform(ExceptionState& exceptionState) override |
| 395 { |
| 396 return redo(exceptionState); |
| 397 } |
| 398 |
| 399 virtual bool undo(ExceptionState& exceptionState) override |
| 400 { |
| 401 return m_styleSheet->setText(m_oldText, exceptionState); |
| 402 } |
| 403 |
| 404 virtual bool redo(ExceptionState& exceptionState) override |
| 405 { |
| 406 if (!m_styleSheet->getText(&m_oldText)) |
| 407 return false; |
| 408 return m_styleSheet->setText(m_text, exceptionState); |
| 409 return true; |
| 410 } |
| 411 |
| 412 DEFINE_INLINE_VIRTUAL_TRACE() |
| 413 { |
| 414 visitor->trace(m_styleSheet); |
| 415 InspectorCSSAgent::StyleSheetAction::trace(visitor); |
| 416 } |
| 417 |
| 418 virtual String mergeId() override |
| 419 { |
| 420 return String::format("SetElementStyleAction:%s", m_styleSheet->id().utf
8().data()); |
| 421 } |
| 422 |
| 423 virtual void merge(PassRefPtrWillBeRawPtr<Action> action) override |
| 424 { |
| 425 ASSERT(action->mergeId() == mergeId()); |
| 426 |
| 427 SetElementStyleAction* other = static_cast<SetElementStyleAction*>(actio
n.get()); |
| 428 m_text = other->m_text; |
| 429 } |
| 430 |
| 431 private: |
| 432 RefPtrWillBeMember<InspectorStyleSheetForInlineStyle> m_styleSheet; |
| 342 String m_text; | 433 String m_text; |
| 343 String m_oldText; | 434 String m_oldText; |
| 344 SourceRange m_newRange; | |
| 345 RefPtrWillBeMember<CSSRule> m_cssRule; | |
| 346 }; | 435 }; |
| 347 | 436 |
| 348 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh
eetAction { | 437 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh
eetAction { |
| 349 WTF_MAKE_NONCOPYABLE(AddRuleAction); | 438 WTF_MAKE_NONCOPYABLE(AddRuleAction); |
| 350 public: | 439 public: |
| 351 AddRuleAction(InspectorStyleSheet* styleSheet, const String& ruleText, const
SourceRange& location) | 440 AddRuleAction(InspectorStyleSheet* styleSheet, const String& ruleText, const
SourceRange& location) |
| 352 : InspectorCSSAgent::StyleSheetAction("AddRule") | 441 : InspectorCSSAgent::StyleSheetAction("AddRule") |
| 353 , m_styleSheet(styleSheet) | 442 , m_styleSheet(styleSheet) |
| 354 , m_ruleText(ruleText) | 443 , m_ruleText(ruleText) |
| 355 , m_location(location) | 444 , m_location(location) |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); | 1048 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); |
| 960 if (!inspectorStyleSheet) { | 1049 if (!inspectorStyleSheet) { |
| 961 *errorString = "Stylesheet not found"; | 1050 *errorString = "Stylesheet not found"; |
| 962 return; | 1051 return; |
| 963 } | 1052 } |
| 964 SourceRange selectorRange; | 1053 SourceRange selectorRange; |
| 965 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select
orRange)) | 1054 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select
orRange)) |
| 966 return; | 1055 return; |
| 967 | 1056 |
| 968 TrackExceptionState exceptionState; | 1057 TrackExceptionState exceptionState; |
| 969 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop
(new SetRuleSelectorOrMediaAction(false, inspectorStyleSheet, selectorRange, sel
ector)); | 1058 RefPtrWillBeRawPtr<ModifyRuleAction> action = adoptRefWillBeNoop(new ModifyR
uleAction(ModifyRuleAction::SetRuleSelector, inspectorStyleSheet, selectorRange,
selector)); |
| 970 bool success = m_domAgent->history()->perform(action, exceptionState); | 1059 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 971 if (success) { | 1060 if (success) { |
| 972 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRul
e(action->takeRule().get()); | 1061 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRul
e(action->takeRule().get()); |
| 973 result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaL
istChain(rule.get())); | 1062 result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaL
istChain(rule.get())); |
| 974 } | 1063 } |
| 975 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 1064 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 976 } | 1065 } |
| 977 | 1066 |
| 1067 void InspectorCSSAgent::setStyleText(ErrorString* errorString, const String& sty
leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild
er::CSS::CSSStyle>& result) |
| 1068 { |
| 1069 InspectorStyleSheetBase* inspectorStyleSheet = assertStyleSheetForId(errorSt
ring, styleSheetId); |
| 1070 if (!inspectorStyleSheet) { |
| 1071 *errorString = "Stylesheet not found"; |
| 1072 return; |
| 1073 } |
| 1074 SourceRange selectorRange; |
| 1075 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select
orRange)) |
| 1076 return; |
| 1077 |
| 1078 TrackExceptionState exceptionState; |
| 1079 if (inspectorStyleSheet->isInlineStyle()) { |
| 1080 InspectorStyleSheetForInlineStyle* inlineStyleSheet = static_cast<Inspec
torStyleSheetForInlineStyle*>(inspectorStyleSheet); |
| 1081 RefPtrWillBeRawPtr<SetElementStyleAction> action = adoptRefWillBeNoop(ne
w SetElementStyleAction(inlineStyleSheet, text)); |
| 1082 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 1083 if (success) |
| 1084 result = inspectorStyleSheet->buildObjectForStyle(inlineStyleSheet->
inlineStyle()); |
| 1085 } else { |
| 1086 RefPtrWillBeRawPtr<ModifyRuleAction> action = adoptRefWillBeNoop(new Mod
ifyRuleAction(ModifyRuleAction::SetStyleText, static_cast<InspectorStyleSheet*>(
inspectorStyleSheet), selectorRange, text)); |
| 1087 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 1088 if (success) { |
| 1089 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyl
eRule(action->takeRule().get()); |
| 1090 result = inspectorStyleSheet->buildObjectForStyle(rule->style()); |
| 1091 } |
| 1092 } |
| 1093 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1094 } |
| 1095 |
| 978 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty
leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild
er::CSS::CSSMedia>& result) | 1096 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty
leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild
er::CSS::CSSMedia>& result) |
| 979 { | 1097 { |
| 980 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); | 1098 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er
rorString, styleSheetId); |
| 981 if (!inspectorStyleSheet) { | 1099 if (!inspectorStyleSheet) { |
| 982 *errorString = "Stylesheet not found"; | 1100 *errorString = "Stylesheet not found"; |
| 983 return; | 1101 return; |
| 984 } | 1102 } |
| 985 SourceRange textRange; | 1103 SourceRange textRange; |
| 986 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa
nge)) | 1104 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa
nge)) |
| 987 return; | 1105 return; |
| 988 | 1106 |
| 989 TrackExceptionState exceptionState; | 1107 TrackExceptionState exceptionState; |
| 990 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop
(new SetRuleSelectorOrMediaAction(true, inspectorStyleSheet, textRange, text)); | 1108 RefPtrWillBeRawPtr<ModifyRuleAction> action = adoptRefWillBeNoop(new ModifyR
uleAction(ModifyRuleAction::SetMediaRuleText, inspectorStyleSheet, textRange, te
xt)); |
| 991 bool success = m_domAgent->history()->perform(action, exceptionState); | 1109 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 992 if (success) { | 1110 if (success) { |
| 993 RefPtrWillBeRawPtr<CSSMediaRule> rule = InspectorCSSAgent::asCSSMediaRul
e(action->takeRule().get()); | 1111 RefPtrWillBeRawPtr<CSSMediaRule> rule = InspectorCSSAgent::asCSSMediaRul
e(action->takeRule().get()); |
| 994 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); | 1112 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); |
| 995 if (sourceURL.isEmpty()) | 1113 if (sourceURL.isEmpty()) |
| 996 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh
eet()->ownerDocument()); | 1114 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh
eet()->ownerDocument()); |
| 997 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc
eURL, rule->parentStyleSheet()); | 1115 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc
eURL, rule->parentStyleSheet()); |
| 998 } | 1116 } |
| 999 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 1117 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1000 } | 1118 } |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 visitor->trace(m_documentToCSSStyleSheets); | 1675 visitor->trace(m_documentToCSSStyleSheets); |
| 1558 visitor->trace(m_invalidatedDocuments); | 1676 visitor->trace(m_invalidatedDocuments); |
| 1559 visitor->trace(m_nodeToInspectorStyleSheet); | 1677 visitor->trace(m_nodeToInspectorStyleSheet); |
| 1560 visitor->trace(m_documentToViaInspectorStyleSheet); | 1678 visitor->trace(m_documentToViaInspectorStyleSheet); |
| 1561 #endif | 1679 #endif |
| 1562 visitor->trace(m_inspectorUserAgentStyleSheet); | 1680 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 1563 InspectorBaseAgent::trace(visitor); | 1681 InspectorBaseAgent::trace(visitor); |
| 1564 } | 1682 } |
| 1565 | 1683 |
| 1566 } // namespace blink | 1684 } // namespace blink |
| 1567 | |
| OLD | NEW |