Chromium Code Reviews| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::SetRuleSelectorOrMediaAction final : public InspectorCS SAgent::StyleSheetAction { |
| 291 WTF_MAKE_NONCOPYABLE(SetRuleSelectorOrMediaAction); | 291 WTF_MAKE_NONCOPYABLE(SetRuleSelectorOrMediaAction); |
| 292 public: | 292 public: |
| 293 SetRuleSelectorOrMediaAction(bool isMedia, InspectorStyleSheet* styleSheet, const SourceRange& range, const String& text) | 293 enum Type { |
| 294 SetRuleSelector, | |
| 295 SetStyleText, | |
| 296 SetMediaRuleText | |
| 297 }; | |
| 298 | |
| 299 SetRuleSelectorOrMediaAction(Type type, InspectorStyleSheet* styleSheet, con st SourceRange& range, const String& text) | |
|
lushnikov
2015/06/17 13:55:10
SetModelTextAction?
pfeldman
2015/06/18 13:01:55
Done.
| |
| 294 : InspectorCSSAgent::StyleSheetAction("SetRuleSelectorOrMediaAction") | 300 : InspectorCSSAgent::StyleSheetAction("SetRuleSelectorOrMediaAction") |
| 295 , m_styleSheet(styleSheet) | 301 , m_styleSheet(styleSheet) |
| 296 , m_isMedia(isMedia) | 302 , m_type(type) |
| 297 , m_range(range) | 303 , m_range(range) |
| 298 , m_text(text) | 304 , m_text(text) |
| 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) { |
| 331 case SetRuleSelector: | |
| 332 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_range, m_text, &m_newRange, &m_oldText, exceptionState); | |
| 336 break; | |
| 337 case SetMediaRuleText: | |
| 318 m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRa nge, &m_oldText, exceptionState); | 338 m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRa nge, &m_oldText, exceptionState); |
| 319 else | 339 break; |
| 320 m_cssRule = m_styleSheet->setRuleSelector(m_range, m_text, &m_newRan ge, &m_oldText, exceptionState); | 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 |
| 338 private: | 360 private: |
| 339 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; | 361 RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
| 340 bool m_isMedia; | 362 Type m_type; |
| 341 SourceRange m_range; | 363 SourceRange m_range; |
| 342 String m_text; | 364 String m_text; |
| 343 String m_oldText; | 365 String m_oldText; |
| 344 SourceRange m_newRange; | 366 SourceRange m_newRange; |
| 345 RefPtrWillBeMember<CSSRule> m_cssRule; | 367 RefPtrWillBeMember<CSSRule> m_cssRule; |
| 346 }; | 368 }; |
| 347 | 369 |
| 348 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh eetAction { | 370 class InspectorCSSAgent::AddRuleAction final : public InspectorCSSAgent::StyleSh eetAction { |
| 349 WTF_MAKE_NONCOPYABLE(AddRuleAction); | 371 WTF_MAKE_NONCOPYABLE(AddRuleAction); |
| 350 public: | 372 public: |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); | 981 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); |
| 960 if (!inspectorStyleSheet) { | 982 if (!inspectorStyleSheet) { |
| 961 *errorString = "Stylesheet not found"; | 983 *errorString = "Stylesheet not found"; |
| 962 return; | 984 return; |
| 963 } | 985 } |
| 964 SourceRange selectorRange; | 986 SourceRange selectorRange; |
| 965 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) | 987 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) |
| 966 return; | 988 return; |
| 967 | 989 |
| 968 TrackExceptionState exceptionState; | 990 TrackExceptionState exceptionState; |
| 969 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(false, inspectorStyleSheet, selectorRange, sel ector)); | 991 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetRuleSelector, inspectorStyleSheet, selectorRange, selector)); |
| 970 bool success = m_domAgent->history()->perform(action, exceptionState); | 992 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 971 if (success) { | 993 if (success) { |
| 972 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRul e(action->takeRule().get()); | 994 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRul e(action->takeRule().get()); |
| 995 result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaL istChain(rule.get())); | |
| 996 } | |
| 997 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | |
| 998 } | |
| 999 | |
| 1000 void InspectorCSSAgent::setStyleText(ErrorString* errorString, const String& sty leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild er::CSS::CSSRule>& result) | |
| 1001 { | |
| 1002 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); | |
|
lushnikov
2015/06/17 13:55:10
you want inspectorStyleSheetBase here
pfeldman
2015/06/18 13:01:55
Not really, plugged in differently.
| |
| 1003 if (!inspectorStyleSheet) { | |
| 1004 *errorString = "Stylesheet not found"; | |
| 1005 return; | |
| 1006 } | |
| 1007 SourceRange selectorRange; | |
| 1008 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &select orRange)) | |
| 1009 return; | |
| 1010 | |
| 1011 TrackExceptionState exceptionState; | |
| 1012 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetStyleText, in spectorStyleSheet, selectorRange, text)); | |
| 1013 bool success = m_domAgent->history()->perform(action, exceptionState); | |
| 1014 if (success) { | |
| 1015 RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRul e(action->takeRule().get()); | |
| 973 result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaL istChain(rule.get())); | 1016 result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaL istChain(rule.get())); |
| 974 } | 1017 } |
| 975 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 1018 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 976 } | 1019 } |
| 977 | 1020 |
| 978 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild er::CSS::CSSMedia>& result) | 1021 void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty leSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuild er::CSS::CSSMedia>& result) |
| 979 { | 1022 { |
| 980 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); | 1023 InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(er rorString, styleSheetId); |
| 981 if (!inspectorStyleSheet) { | 1024 if (!inspectorStyleSheet) { |
| 982 *errorString = "Stylesheet not found"; | 1025 *errorString = "Stylesheet not found"; |
| 983 return; | 1026 return; |
| 984 } | 1027 } |
| 985 SourceRange textRange; | 1028 SourceRange textRange; |
| 986 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa nge)) | 1029 if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &textRa nge)) |
| 987 return; | 1030 return; |
| 988 | 1031 |
| 989 TrackExceptionState exceptionState; | 1032 TrackExceptionState exceptionState; |
| 990 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(true, inspectorStyleSheet, textRange, text)); | 1033 RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop (new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetMediaRuleText , inspectorStyleSheet, textRange, text)); |
| 991 bool success = m_domAgent->history()->perform(action, exceptionState); | 1034 bool success = m_domAgent->history()->perform(action, exceptionState); |
| 992 if (success) { | 1035 if (success) { |
| 993 RefPtrWillBeRawPtr<CSSMediaRule> rule = InspectorCSSAgent::asCSSMediaRul e(action->takeRule().get()); | 1036 RefPtrWillBeRawPtr<CSSMediaRule> rule = InspectorCSSAgent::asCSSMediaRul e(action->takeRule().get()); |
| 994 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); | 1037 String sourceURL = rule->parentStyleSheet()->contents()->baseURL(); |
| 995 if (sourceURL.isEmpty()) | 1038 if (sourceURL.isEmpty()) |
| 996 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh eet()->ownerDocument()); | 1039 sourceURL = InspectorDOMAgent::documentURLString(rule->parentStyleSh eet()->ownerDocument()); |
| 997 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc eURL, rule->parentStyleSheet()); | 1040 result = buildMediaObject(rule->media(), MediaListSourceMediaRule, sourc eURL, rule->parentStyleSheet()); |
| 998 } | 1041 } |
| 999 *errorString = InspectorDOMAgent::toErrorString(exceptionState); | 1042 *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| 1000 } | 1043 } |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1558 visitor->trace(m_invalidatedDocuments); | 1601 visitor->trace(m_invalidatedDocuments); |
| 1559 visitor->trace(m_nodeToInspectorStyleSheet); | 1602 visitor->trace(m_nodeToInspectorStyleSheet); |
| 1560 visitor->trace(m_documentToViaInspectorStyleSheet); | 1603 visitor->trace(m_documentToViaInspectorStyleSheet); |
| 1561 #endif | 1604 #endif |
| 1562 visitor->trace(m_inspectorUserAgentStyleSheet); | 1605 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 1563 InspectorBaseAgent::trace(visitor); | 1606 InspectorBaseAgent::trace(visitor); |
| 1564 } | 1607 } |
| 1565 | 1608 |
| 1566 } // namespace blink | 1609 } // namespace blink |
| 1567 | 1610 |
| OLD | NEW |