Chromium Code Reviews| Index: Source/core/inspector/InspectorCSSAgent.cpp |
| diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp |
| index f146150de1e71098d9b7aff332e93885baf0c223..ecfa26ee44081dd68d1255cdc9a8aec900565eaa 100644 |
| --- a/Source/core/inspector/InspectorCSSAgent.cpp |
| +++ b/Source/core/inspector/InspectorCSSAgent.cpp |
| @@ -290,10 +290,16 @@ private: |
| class InspectorCSSAgent::SetRuleSelectorOrMediaAction final : public InspectorCSSAgent::StyleSheetAction { |
| WTF_MAKE_NONCOPYABLE(SetRuleSelectorOrMediaAction); |
| public: |
| - SetRuleSelectorOrMediaAction(bool isMedia, InspectorStyleSheet* styleSheet, const SourceRange& range, const String& text) |
| + enum Type { |
| + SetRuleSelector, |
| + SetStyleText, |
| + SetMediaRuleText |
| + }; |
| + |
| + SetRuleSelectorOrMediaAction(Type type, InspectorStyleSheet* styleSheet, const SourceRange& range, const String& text) |
|
lushnikov
2015/06/17 13:55:10
SetModelTextAction?
pfeldman
2015/06/18 13:01:55
Done.
|
| : InspectorCSSAgent::StyleSheetAction("SetRuleSelectorOrMediaAction") |
| , m_styleSheet(styleSheet) |
| - , m_isMedia(isMedia) |
| + , m_type(type) |
| , m_range(range) |
| , m_text(text) |
| , m_cssRule(nullptr) |
| @@ -307,17 +313,33 @@ public: |
| virtual bool undo(ExceptionState& exceptionState) override |
| { |
| - if (m_isMedia) |
| + switch (m_type) { |
| + case SetRuleSelector: |
| + return m_styleSheet->setRuleSelector(m_newRange, m_oldText, nullptr, nullptr, exceptionState); |
| + case SetStyleText: |
| + return m_styleSheet->setStyleText(m_newRange, m_oldText, nullptr, nullptr, exceptionState); |
| + case SetMediaRuleText: |
| return m_styleSheet->setMediaRuleText(m_newRange, m_oldText, nullptr, nullptr, exceptionState); |
| - return m_styleSheet->setRuleSelector(m_newRange, m_oldText, nullptr, nullptr, exceptionState); |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| } |
| virtual bool redo(ExceptionState& exceptionState) override |
| { |
| - if (m_isMedia) |
| - m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRange, &m_oldText, exceptionState); |
| - else |
| + switch (m_type) { |
| + case SetRuleSelector: |
| m_cssRule = m_styleSheet->setRuleSelector(m_range, m_text, &m_newRange, &m_oldText, exceptionState); |
| + break; |
| + case SetStyleText: |
| + m_cssRule = m_styleSheet->setStyleText(m_range, m_text, &m_newRange, &m_oldText, exceptionState); |
| + break; |
| + case SetMediaRuleText: |
| + m_cssRule = m_styleSheet->setMediaRuleText(m_range, m_text, &m_newRange, &m_oldText, exceptionState); |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| return m_cssRule; |
| } |
| @@ -337,7 +359,7 @@ public: |
| private: |
| RefPtrWillBeMember<InspectorStyleSheet> m_styleSheet; |
| - bool m_isMedia; |
| + Type m_type; |
| SourceRange m_range; |
| String m_text; |
| String m_oldText; |
| @@ -966,7 +988,28 @@ void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String& |
| return; |
| TrackExceptionState exceptionState; |
| - RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop(new SetRuleSelectorOrMediaAction(false, inspectorStyleSheet, selectorRange, selector)); |
| + RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop(new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetRuleSelector, inspectorStyleSheet, selectorRange, selector)); |
| + bool success = m_domAgent->history()->perform(action, exceptionState); |
| + if (success) { |
| + RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRule(action->takeRule().get()); |
| + result = inspectorStyleSheet->buildObjectForRule(rule.get(), buildMediaListChain(rule.get())); |
| + } |
| + *errorString = InspectorDOMAgent::toErrorString(exceptionState); |
| +} |
| + |
| +void InspectorCSSAgent::setStyleText(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuilder::CSS::CSSRule>& result) |
| +{ |
| + InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(errorString, styleSheetId); |
|
lushnikov
2015/06/17 13:55:10
you want inspectorStyleSheetBase here
pfeldman
2015/06/18 13:01:55
Not really, plugged in differently.
|
| + if (!inspectorStyleSheet) { |
| + *errorString = "Stylesheet not found"; |
| + return; |
| + } |
| + SourceRange selectorRange; |
| + if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &selectorRange)) |
| + return; |
| + |
| + TrackExceptionState exceptionState; |
| + RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop(new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetStyleText, inspectorStyleSheet, selectorRange, text)); |
| bool success = m_domAgent->history()->perform(action, exceptionState); |
| if (success) { |
| RefPtrWillBeRawPtr<CSSStyleRule> rule = InspectorCSSAgent::asCSSStyleRule(action->takeRule().get()); |
| @@ -987,7 +1030,7 @@ void InspectorCSSAgent::setMediaText(ErrorString* errorString, const String& sty |
| return; |
| TrackExceptionState exceptionState; |
| - RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop(new SetRuleSelectorOrMediaAction(true, inspectorStyleSheet, textRange, text)); |
| + RefPtrWillBeRawPtr<SetRuleSelectorOrMediaAction> action = adoptRefWillBeNoop(new SetRuleSelectorOrMediaAction(SetRuleSelectorOrMediaAction::SetMediaRuleText, inspectorStyleSheet, textRange, text)); |
| bool success = m_domAgent->history()->perform(action, exceptionState); |
| if (success) { |
| RefPtrWillBeRawPtr<CSSMediaRule> rule = InspectorCSSAgent::asCSSMediaRule(action->takeRule().get()); |