2011-04-11 Pavel Podivilov <podivilov@chromium.org>
authorpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Apr 2011 13:52:32 +0000 (13:52 +0000)
committerpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Apr 2011 13:52:32 +0000 (13:52 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
        https://bugs.webkit.org/show_bug.cgi?id=58238

        * inspector/debugger/live-edit.html:
2011-04-11  Pavel Podivilov  <podivilov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
        https://bugs.webkit.org/show_bug.cgi?id=58238

        Commit/cancel editing functionality is common for all resource types, and it deals with TextViewer state.

        * inspector/front-end/SourceFrame.js:
        (WebInspector.SourceFrame):
        (WebInspector.SourceFrame.prototype.isContentEditable):
        (WebInspector.SourceFrame.prototype._createTextViewer):
        (WebInspector.SourceFrame.prototype.commitEditing.didEditContent):
        (WebInspector.SourceFrame.prototype.commitEditing):
        (WebInspector.SourceFrame.prototype.cancelEditing):
        * inspector/front-end/TextViewer.js:
        (WebInspector.TextViewer.prototype._doubleClick):
        (WebInspector.TextViewer.prototype._registerShortcuts):
        (WebInspector.TextViewer.prototype._handleKeyDown):
        (WebInspector.TextViewer.prototype._commitEditing.didCommitEditing):
        (WebInspector.TextViewer.prototype._commitEditing):
        (WebInspector.TextViewer.prototype._cancelEditing):
        (WebInspector.TextViewerDelegate.prototype.endEditing):
        (WebInspector.TextViewerDelegate.prototype.commitEditing):
        (WebInspector.TextViewerDelegate.prototype.cancelEditing):

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

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/live-edit.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/SourceFrame.js
Source/WebCore/inspector/front-end/TextViewer.js

index 1d5877a..0aeb73a 100644 (file)
@@ -1,3 +1,12 @@
+2011-04-11  Pavel Podivilov  <podivilov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
+        https://bugs.webkit.org/show_bug.cgi?id=58238
+
+        * inspector/debugger/live-edit.html:
+
 2011-04-12  Pavel Feldman  <pfeldman@google.com>
 
         Reviewed by Yury Semikhatsky.
index bf346e4..4d43cf4 100644 (file)
@@ -90,7 +90,7 @@ function test()
     function replaceInSource(sourceFrame, string, replacement, callback)
     {
         InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", callback);
-        sourceFrame._textViewer.readOnly = false;
+        sourceFrame._textViewer._mainPanel.readOnly = false;
         sourceFrame.startEditing();
         var oldRange, newRange;
         var lines = sourceFrame._textModel._lines;
@@ -106,7 +106,7 @@ function test()
             break;
         }
         sourceFrame.endEditing(oldRange, newRange);
-        sourceFrame._handleSave();
+        sourceFrame._textViewer._commitEditing();
     }
 };
 
index 063a81d..5a24fd2 100644 (file)
@@ -1,3 +1,30 @@
+2011-04-11  Pavel Podivilov  <podivilov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
+        https://bugs.webkit.org/show_bug.cgi?id=58238
+
+        Commit/cancel editing functionality is common for all resource types, and it deals with TextViewer state.
+
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame):
+        (WebInspector.SourceFrame.prototype.isContentEditable):
+        (WebInspector.SourceFrame.prototype._createTextViewer):
+        (WebInspector.SourceFrame.prototype.commitEditing.didEditContent):
+        (WebInspector.SourceFrame.prototype.commitEditing):
+        (WebInspector.SourceFrame.prototype.cancelEditing):
+        * inspector/front-end/TextViewer.js:
+        (WebInspector.TextViewer.prototype._doubleClick):
+        (WebInspector.TextViewer.prototype._registerShortcuts):
+        (WebInspector.TextViewer.prototype._handleKeyDown):
+        (WebInspector.TextViewer.prototype._commitEditing.didCommitEditing):
+        (WebInspector.TextViewer.prototype._commitEditing):
+        (WebInspector.TextViewer.prototype._cancelEditing):
+        (WebInspector.TextViewerDelegate.prototype.endEditing):
+        (WebInspector.TextViewerDelegate.prototype.commitEditing):
+        (WebInspector.TextViewerDelegate.prototype.cancelEditing):
+
 2011-04-12  Pavel Feldman  <pfeldman@google.com>
 
         Reviewed by Yury Semikhatsky.
index bd7e04d..ae4efeb 100644 (file)
@@ -49,8 +49,6 @@ WebInspector.SourceFrame = function(delegate, url)
     this._messageBubbles = {};
 
     this._breakpoints = {};
-
-    this._registerShortcuts();
 }
 
 WebInspector.SourceFrame.Events = {
@@ -236,7 +234,7 @@ WebInspector.SourceFrame.prototype = {
 
     isContentEditable: function()
     {
-        return this._delegate.canEditScriptSource() && !this._editScriptSourceInProgress;
+        return this._delegate.canEditScriptSource();
     },
 
     startEditing: function()
@@ -304,7 +302,6 @@ WebInspector.SourceFrame.prototype = {
             element.addEventListener("mousemove", this._mouseMove.bind(this), true);
             element.addEventListener("scroll", this._scroll.bind(this), true);
         }
-        element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
 
         this._textViewer.beginUpdates();
 
@@ -871,54 +868,21 @@ WebInspector.SourceFrame.prototype = {
         this._textViewer.resize();
     },
 
-    _registerShortcuts: function()
-    {
-        this._shortcuts = {};
-        var handleSaveCallback = this._handleSave.bind(this);
-        this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = handleSaveCallback;
-        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Enter.code, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = handleSaveCallback;
-        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Esc.code)] = this._handleRevertEditing.bind(this);
-    },
-
-    _handleKeyDown: function(e)
+    commitEditing: function(callback)
     {
-        var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
-        var handler = this._shortcuts[shortcutKey];
-        if (handler && handler.call(this)) {
-            e.preventDefault();
-            e.stopPropagation();
-        }
-    },
-
-    _handleSave: function()
-    {
-        if (this._textViewer.readOnly || !this.isContentEditable())
-            return false;
-
         if (!this._viewerState) {
             // No editing was actually done.
-            this._textViewer.readOnly = true;
             this._delegate.setScriptSourceIsBeingEdited(false);
-            return true;
+            callback();
+            return;
         }
 
-        var originalViewerState = this._viewerState;
-        var newSource = this._textModel.text;
-
-        delete this._viewerState;
-        this._textViewer.readOnly = true;
-        this._delegate.setScriptSourceIsBeingEdited(false);
-
-        function didEditScriptSource(error)
+        function didEditContent(error)
         {
-            this._editScriptSourceInProgress = false;
-
             if (error) {
-                this._viewerState = originalViewerState;
-                this._textViewer.readOnly = false;
-                this._delegate.setScriptSourceIsBeingEdited(true);
                 WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
                 WebInspector.showConsole();
+                callback(error);
                 return;
             }
 
@@ -928,17 +892,20 @@ WebInspector.SourceFrame.prototype = {
                 this.removeBreakpoint(Number(lineNumber));
             }
 
-            for (var lineNumber in originalViewerState.breakpoints)
+            for (var lineNumber in this._viewerState.breakpoints)
                 this._delegate.removeBreakpoint(Number(lineNumber));
 
             for (var lineNumber in newBreakpoints) {
                 var breakpoint = newBreakpoints[lineNumber];
                 this._delegate.setBreakpoint(Number(lineNumber), breakpoint.condition, breakpoint.enabled);
             }
+
+            delete this._viewerState;
+            this._delegate.setScriptSourceIsBeingEdited(false);
+
+            callback();
         }
-        this._editContent(newSource, didEditScriptSource.bind(this));
-        this._editScriptSourceInProgress = true;
-        return true;
+        this._editContent(this._textModel.text, didEditContent.bind(this));
     },
 
     _editContent: function(newContent, callback)
@@ -946,15 +913,10 @@ WebInspector.SourceFrame.prototype = {
         this._delegate.editScriptSource(newContent, callback);
     },
 
-    _handleRevertEditing: function()
+    cancelEditing: function()
     {
-        if (this._textViewer.readOnly)
-            return false;
-
         this._restoreViewerState();
-        this._textViewer.readOnly = true;
         this._delegate.setScriptSourceIsBeingEdited(false);
-        return true;
     }
 }
 
index 743c263..8f4fa4f 100644 (file)
@@ -54,6 +54,9 @@ WebInspector.TextViewer = function(textModel, platform, url, delegate)
     }.bind(this), false);
 
     this.element.addEventListener("dblclick", this._doubleClick.bind(this), true);
+    this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
+
+    this._registerShortcuts();
 }
 
 WebInspector.TextViewer.prototype = {
@@ -62,16 +65,6 @@ WebInspector.TextViewer.prototype = {
         this._mainPanel.mimeType = mimeType;
     },
 
-    set readOnly(readOnly)
-    {
-        this._mainPanel.readOnly = readOnly;
-    },
-
-    get readOnly()
-    {
-        return this._mainPanel.readOnly;
-    },
-
     get textModel()
     {
         return this._textModel;
@@ -226,17 +219,65 @@ WebInspector.TextViewer.prototype = {
 
     _doubleClick: function(event)
     {
-        if (!this._delegate.isContentEditable())
+        if (!this._mainPanel.readOnly || this._commitEditingInProgress)
             return;
 
         var lineRow = event.target.enclosingNodeOrSelfWithClass("webkit-line-content");
         if (!lineRow)
             return;  // Do not trigger editing from line numbers.
 
-        if (this.readOnly) {
-            this.readOnly = false;
-            window.getSelection().collapseToStart();
+        if (!this._delegate.isContentEditable())
+            return;
+
+        this._mainPanel.readOnly = false;
+        window.getSelection().collapseToStart();
+    },
+
+    _registerShortcuts: function()
+    {
+        this._shortcuts = {};
+        var commitEditing = this._commitEditing.bind(this);
+        var cancelEditing = this._cancelEditing.bind(this);
+        this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = commitEditing;
+        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Enter.code, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = commitEditing;
+        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Esc.code)] = cancelEditing;
+    },
+
+    _handleKeyDown: function(e)
+    {
+        var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
+        var handler = this._shortcuts[shortcutKey];
+        if (handler && handler.call(this)) {
+            e.preventDefault();
+            e.stopPropagation();
         }
+    },
+
+    _commitEditing: function()
+    {
+        if (this._mainPanel.readOnly)
+            return false;
+
+        this._mainPanel.readOnly = true;
+        function didCommitEditing(error)
+        {
+            this._commitEditingInProgress = false;
+            if (error)
+                this._mainPanel.readOnly = false;
+        }
+        this._commitEditingInProgress = true;
+        this._delegate.commitEditing(didCommitEditing.bind(this));
+        return true;
+    },
+
+    _cancelEditing: function()
+    {
+        if (this._mainPanel.readOnly)
+            return false;
+
+        this._mainPanel.readOnly = true;
+        this._delegate.cancelEditing();
+        return true;
     }
 }
 
@@ -260,6 +301,16 @@ WebInspector.TextViewerDelegate.prototype = {
     endEditing: function(oldRange, newRange)
     {
         // Should be implemented by subclasses.
+    },
+
+    commitEditing: function()
+    {
+        // Should be implemented by subclasses.
+    },
+
+    cancelEditing: function()
+    {
+        // Should be implemented by subclasses.
     }
 }