Web Inspector: explicitly mark undoable state from the front-end.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 15:38:42 +0000 (15:38 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 15:38:42 +0000 (15:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78716

Reviewed by Vsevolod Vlasov.

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::toggleProperty):
(WebCore::InspectorCSSAgent::setRuleSelector):
(WebCore::InspectorCSSAgent::addRule):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::setAttributeValue):
(WebCore::InspectorDOMAgent::setAttributesAsText):
(WebCore::InspectorDOMAgent::removeAttribute):
(WebCore::InspectorDOMAgent::removeNode):
(WebCore::InspectorDOMAgent::setNodeName):
(WebCore::InspectorDOMAgent::setOuterHTML):
(WebCore::InspectorDOMAgent::setNodeValue):
(WebCore::InspectorDOMAgent::moveTo):
* inspector/InspectorHistory.cpp:
(WebCore::InspectorHistory::redo):
* inspector/InspectorHistory.h:
(InspectorHistory):
* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSStyleModel.prototype.setRuleSelector.callback):
(WebInspector.CSSStyleModel.prototype.setRuleSelector):
(WebInspector.CSSStyleModel.prototype.addRule.callback):
(WebInspector.CSSStyleModel.prototype.addRule):
(WebInspector.CSSStyleModel.prototype.setStyleSheetText):
(WebInspector.CSSProperty.prototype.setText.callback):
(WebInspector.CSSProperty.prototype.setText):
(WebInspector.CSSProperty.prototype.setDisabled.callback):
(WebInspector.CSSProperty.prototype.setDisabled):
(WebInspector.CSSStyleSheet.prototype.setText):
* inspector/front-end/DOMAgent.js:
(WebInspector.DOMAgent.prototype._markRevision):
(WebInspector.DOMAgent.prototype.get markUndoableState):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorHistory.cpp
Source/WebCore/inspector/InspectorHistory.h
Source/WebCore/inspector/front-end/CSSStyleModel.js
Source/WebCore/inspector/front-end/DOMAgent.js

index 947f597..4306cbc 100644 (file)
@@ -1,5 +1,44 @@
 2012-02-15  Pavel Feldman  <pfeldman@google.com>
 
+        Web Inspector: explicitly mark undoable state from the front-end.
+        https://bugs.webkit.org/show_bug.cgi?id=78716
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::toggleProperty):
+        (WebCore::InspectorCSSAgent::setRuleSelector):
+        (WebCore::InspectorCSSAgent::addRule):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::setAttributeValue):
+        (WebCore::InspectorDOMAgent::setAttributesAsText):
+        (WebCore::InspectorDOMAgent::removeAttribute):
+        (WebCore::InspectorDOMAgent::removeNode):
+        (WebCore::InspectorDOMAgent::setNodeName):
+        (WebCore::InspectorDOMAgent::setOuterHTML):
+        (WebCore::InspectorDOMAgent::setNodeValue):
+        (WebCore::InspectorDOMAgent::moveTo):
+        * inspector/InspectorHistory.cpp:
+        (WebCore::InspectorHistory::redo):
+        * inspector/InspectorHistory.h:
+        (InspectorHistory):
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel.prototype.setRuleSelector.callback):
+        (WebInspector.CSSStyleModel.prototype.setRuleSelector):
+        (WebInspector.CSSStyleModel.prototype.addRule.callback):
+        (WebInspector.CSSStyleModel.prototype.addRule):
+        (WebInspector.CSSStyleModel.prototype.setStyleSheetText):
+        (WebInspector.CSSProperty.prototype.setText.callback):
+        (WebInspector.CSSProperty.prototype.setText):
+        (WebInspector.CSSProperty.prototype.setDisabled.callback):
+        (WebInspector.CSSProperty.prototype.setDisabled):
+        (WebInspector.CSSStyleSheet.prototype.setText):
+        * inspector/front-end/DOMAgent.js:
+        (WebInspector.DOMAgent.prototype._markRevision):
+        (WebInspector.DOMAgent.prototype.get markUndoableState):
+
+2012-02-15  Pavel Feldman  <pfeldman@google.com>
+
         Web Inspector: revert 'modification of DOM upon single click for selected nodes'.
         https://bugs.webkit.org/show_bug.cgi?id=78717
 
index 54ca9a2..1f4f713 100644 (file)
@@ -711,7 +711,6 @@ void InspectorCSSAgent::toggleProperty(ErrorString* errorString, const RefPtr<In
     if (success)
         result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     *errorString = InspectorDOMAgent::toErrorString(ec);
-    m_domAgent->history()->markUndoableState();
 }
 
 void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const RefPtr<InspectorObject>& fullRuleId, const String& selector, RefPtr<InspectorObject>& result)
@@ -731,7 +730,6 @@ void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const RefPtr<I
 
     if (success)
         result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId));
-    m_domAgent->history()->markUndoableState();
 }
 
 void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeId, const String& selector, RefPtr<InspectorObject>& result)
@@ -758,7 +756,6 @@ void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeI
     InspectorCSSId ruleId = rawAction->newRuleId();
     CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId);
     result = inspectorStyleSheet->buildObjectForRule(rule);
-    m_domAgent->history()->markUndoableState();
 }
 
 void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<InspectorArray>& cssProperties)
index 5eb3ee9..6ea68a5 100644 (file)
@@ -538,7 +538,6 @@ void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, int elementI
         return;
 
     m_domEditor->setAttribute(element, name, value, errorString);
-    m_history->markUndoableState();
 }
 
 void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elementId, const String& text, const String* const name)
@@ -569,7 +568,6 @@ void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elemen
     Element* childElement = toElement(child);
     if (!childElement->hasAttributes() && name) {
         m_domEditor->removeAttribute(element, *name, errorString);
-        m_history->markUndoableState();
         return;
     }
 
@@ -585,8 +583,6 @@ void InspectorDOMAgent::setAttributesAsText(ErrorString* errorString, int elemen
 
     if (!foundOriginalAttribute && name && !name->stripWhiteSpace().isEmpty())
         m_domEditor->removeAttribute(element, *name, errorString);
-
-    m_history->markUndoableState();
 }
 
 void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId, const String& name)
@@ -596,7 +592,6 @@ void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId,
         return;
 
     m_domEditor->removeAttribute(element, name, errorString);
-    m_history->markUndoableState();
 }
 
 void InspectorDOMAgent::removeNode(ErrorString* errorString, int nodeId)
@@ -612,7 +607,6 @@ void InspectorDOMAgent::removeNode(ErrorString* errorString, int nodeId)
     }
 
     m_domEditor->removeChild(parentNode, node, errorString);
-    m_history->markUndoableState();
 }
 
 void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const String& tagName, int* newId)
@@ -644,7 +638,6 @@ void InspectorDOMAgent::setNodeName(ErrorString* errorString, int nodeId, const
         return;
     if (!m_domEditor->removeChild(parent, oldNode, errorString))
         return;
-    m_history->markUndoableState();
 
     *newId = pushNodePathToFrontend(newElem.get());
     if (m_childrenRequested.contains(nodeId))
@@ -681,7 +674,6 @@ void InspectorDOMAgent::setOuterHTML(ErrorString* errorString, int nodeId, const
     Node* newNode = 0;
     if (!m_domEditor->setOuterHTML(node, outerHTML, &newNode, errorString))
         return;
-    m_history->markUndoableState();
 
     if (!newNode) {
         // The only child node has been deleted.
@@ -707,7 +699,6 @@ void InspectorDOMAgent::setNodeValue(ErrorString* errorString, int nodeId, const
     }
 
     m_domEditor->replaceWholeText(toText(node), value, errorString);
-    m_history->markUndoableState();
 }
 
 void InspectorDOMAgent::getEventListenersForNode(ErrorString*, int nodeId, RefPtr<InspectorArray>& listenersArray)
@@ -1067,7 +1058,6 @@ void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE
 
     if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString))
         return;
-    m_history->markUndoableState();
 
     *newNodeId = pushNodePathToFrontend(node);
 }
index f9db5c6..393cba5 100644 (file)
@@ -134,7 +134,7 @@ bool InspectorHistory::redo(ExceptionCode& ec)
     while (m_afterLastActionIndex < m_history.size()) {
         Action* action = m_history[m_afterLastActionIndex].get();
         if (!action->redo(ec)) {
-            m_history.resize(m_afterLastActionIndex);
+            m_history.clear();
             return false;
         }
         ++m_afterLastActionIndex;
index b047ceb..037344b 100644 (file)
@@ -78,7 +78,6 @@ public:
     void reset();
 
 private:
-    void dump();
     Vector<OwnPtr<Action> > m_history;
     size_t m_afterLastActionIndex;
 };
index fe16ffa..ecdbfd3 100644 (file)
@@ -191,6 +191,7 @@ WebInspector.CSSStyleModel.prototype = {
             if (error)
                 failureCallback();
             else {
+                WebInspector.domAgent.markUndoableState();
                 var ownerDocumentId = this._ownerDocumentId(nodeId);
                 if (ownerDocumentId)
                     WebInspector.domAgent.querySelectorAll(ownerDocumentId, newSelector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
@@ -235,6 +236,7 @@ WebInspector.CSSStyleModel.prototype = {
                 // Invalid syntax for a selector
                 failureCallback();
             } else {
+                WebInspector.domAgent.markUndoableState();
                 var ownerDocumentId = this._ownerDocumentId(nodeId);
                 if (ownerDocumentId)
                     WebInspector.domAgent.querySelectorAll(ownerDocumentId, selector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
@@ -284,13 +286,14 @@ WebInspector.CSSStyleModel.prototype = {
         function callback(error)
         {
             this._pendingCommandsMajorState.pop();
+            if (!error && majorChange)
+                WebInspector.domAgent.markUndoableState();
+            
             if (!error && userCallback)
                 userCallback(error);
         }
         this._pendingCommandsMajorState.push(majorChange);
         CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this));
-        if (majorChange)
-            DOMAgent.markUndoableState();
     },
 
     _undoRedoRequested: function()
@@ -629,6 +632,8 @@ WebInspector.CSSProperty.prototype = {
         {
             WebInspector.cssModel._pendingCommandsMajorState.pop();
             if (!error) {
+                if (majorChange)
+                    WebInspector.domAgent.markUndoableState();
                 this.text = propertyText;
                 var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload);
                 var newProperty = style.allProperties[this.index];
@@ -652,8 +657,6 @@ WebInspector.CSSProperty.prototype = {
         // An index past all the properties adds a new property to the style.
         WebInspector.cssModel._pendingCommandsMajorState.push(majorChange);
         CSSAgent.setPropertyText(this.ownerStyle.id, this.index, propertyText, this.index < this.ownerStyle.pastLastSourcePropertyIndex(), callback.bind(this));
-        if (majorChange)
-            DOMAgent.markUndoableState();
     },
 
     setValue: function(newValue, majorChange, userCallback)
@@ -677,6 +680,7 @@ WebInspector.CSSProperty.prototype = {
                     userCallback(null);
                 return;
             }
+            WebInspector.domAgent.markUndoableState();
             if (userCallback) {
                 var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload);
                 userCallback(style);
@@ -760,6 +764,9 @@ WebInspector.CSSStyleSheet.prototype = {
     {
         function callback(error)
         {
+            if (!error)
+                WebInspector.domAgent.markUndoableState();
+
             WebInspector.cssModel._pendingCommandsMajorState.pop();
             if (userCallback)
                 userCallback(error);
index ef708c4..d686fa7 100644 (file)
@@ -1117,6 +1117,9 @@ WebInspector.DOMAgent.prototype = {
     {
         function wrapperFunction(error)
         {
+            if (!error)
+                this.markUndoableState();
+
             if (callback)
                 callback.apply(this, arguments);
             if (error || !WebInspector.experimentsSettings.freeFlowDOMEditing.isEnabled())
@@ -1163,6 +1166,11 @@ WebInspector.DOMAgent.prototype = {
         DOMAgent.setTouchEmulationEnabled(WebInspector.settings.emulateTouchEvents.get());
     },
 
+    markUndoableState: function()
+    {
+        DOMAgent.markUndoableState();
+    },
+
     /**
      * @param {function(?Protocol.Error)=} callback
      */