Changeset 83585 in webkit


Ignore:
Timestamp:
Apr 12, 2011 6:52:32 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

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-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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r83584 r83585  
     12011-04-11  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
     6        https://bugs.webkit.org/show_bug.cgi?id=58238
     7
     8        * inspector/debugger/live-edit.html:
     9
    1102011-04-12  Pavel Feldman  <pfeldman@google.com>
    211
  • trunk/LayoutTests/inspector/debugger/live-edit.html

    r83294 r83585  
    9191    {
    9292        InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", callback);
    93         sourceFrame._textViewer.readOnly = false;
     93        sourceFrame._textViewer._mainPanel.readOnly = false;
    9494        sourceFrame.startEditing();
    9595        var oldRange, newRange;
     
    107107        }
    108108        sourceFrame.endEditing(oldRange, newRange);
    109         sourceFrame._handleSave();
     109        sourceFrame._textViewer._commitEditing();
    110110    }
    111111};
  • trunk/Source/WebCore/ChangeLog

    r83584 r83585  
     12011-04-11  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: move shortcut handlers from SourceFrame to TextViewer.
     6        https://bugs.webkit.org/show_bug.cgi?id=58238
     7
     8        Commit/cancel editing functionality is common for all resource types, and it deals with TextViewer state.
     9
     10        * inspector/front-end/SourceFrame.js:
     11        (WebInspector.SourceFrame):
     12        (WebInspector.SourceFrame.prototype.isContentEditable):
     13        (WebInspector.SourceFrame.prototype._createTextViewer):
     14        (WebInspector.SourceFrame.prototype.commitEditing.didEditContent):
     15        (WebInspector.SourceFrame.prototype.commitEditing):
     16        (WebInspector.SourceFrame.prototype.cancelEditing):
     17        * inspector/front-end/TextViewer.js:
     18        (WebInspector.TextViewer.prototype._doubleClick):
     19        (WebInspector.TextViewer.prototype._registerShortcuts):
     20        (WebInspector.TextViewer.prototype._handleKeyDown):
     21        (WebInspector.TextViewer.prototype._commitEditing.didCommitEditing):
     22        (WebInspector.TextViewer.prototype._commitEditing):
     23        (WebInspector.TextViewer.prototype._cancelEditing):
     24        (WebInspector.TextViewerDelegate.prototype.endEditing):
     25        (WebInspector.TextViewerDelegate.prototype.commitEditing):
     26        (WebInspector.TextViewerDelegate.prototype.cancelEditing):
     27
    1282011-04-12  Pavel Feldman  <pfeldman@google.com>
    229
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r83577 r83585  
    5050
    5151    this._breakpoints = {};
    52 
    53     this._registerShortcuts();
    5452}
    5553
     
    237235    isContentEditable: function()
    238236    {
    239         return this._delegate.canEditScriptSource() && !this._editScriptSourceInProgress;
     237        return this._delegate.canEditScriptSource();
    240238    },
    241239
     
    305303            element.addEventListener("scroll", this._scroll.bind(this), true);
    306304        }
    307         element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
    308305
    309306        this._textViewer.beginUpdates();
     
    872869    },
    873870
    874     _registerShortcuts: function()
    875     {
    876         this._shortcuts = {};
    877         var handleSaveCallback = this._handleSave.bind(this);
    878         this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = handleSaveCallback;
    879         this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Enter.code, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = handleSaveCallback;
    880         this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Esc.code)] = this._handleRevertEditing.bind(this);
    881     },
    882 
    883     _handleKeyDown: function(e)
    884     {
    885         var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
    886         var handler = this._shortcuts[shortcutKey];
    887         if (handler && handler.call(this)) {
    888             e.preventDefault();
    889             e.stopPropagation();
    890         }
    891     },
    892 
    893     _handleSave: function()
    894     {
    895         if (this._textViewer.readOnly || !this.isContentEditable())
    896             return false;
    897 
     871    commitEditing: function(callback)
     872    {
    898873        if (!this._viewerState) {
    899874            // No editing was actually done.
    900             this._textViewer.readOnly = true;
    901875            this._delegate.setScriptSourceIsBeingEdited(false);
    902             return true;
    903         }
    904 
    905         var originalViewerState = this._viewerState;
    906         var newSource = this._textModel.text;
    907 
    908         delete this._viewerState;
    909         this._textViewer.readOnly = true;
    910         this._delegate.setScriptSourceIsBeingEdited(false);
    911 
    912         function didEditScriptSource(error)
     876            callback();
     877            return;
     878        }
     879
     880        function didEditContent(error)
    913881        {
    914             this._editScriptSourceInProgress = false;
    915 
    916882            if (error) {
    917                 this._viewerState = originalViewerState;
    918                 this._textViewer.readOnly = false;
    919                 this._delegate.setScriptSourceIsBeingEdited(true);
    920883                WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
    921884                WebInspector.showConsole();
     885                callback(error);
    922886                return;
    923887            }
     
    929893            }
    930894
    931             for (var lineNumber in originalViewerState.breakpoints)
     895            for (var lineNumber in this._viewerState.breakpoints)
    932896                this._delegate.removeBreakpoint(Number(lineNumber));
    933897
     
    936900                this._delegate.setBreakpoint(Number(lineNumber), breakpoint.condition, breakpoint.enabled);
    937901            }
    938         }
    939         this._editContent(newSource, didEditScriptSource.bind(this));
    940         this._editScriptSourceInProgress = true;
    941         return true;
     902
     903            delete this._viewerState;
     904            this._delegate.setScriptSourceIsBeingEdited(false);
     905
     906            callback();
     907        }
     908        this._editContent(this._textModel.text, didEditContent.bind(this));
    942909    },
    943910
     
    947914    },
    948915
    949     _handleRevertEditing: function()
    950     {
    951         if (this._textViewer.readOnly)
    952             return false;
    953 
     916    cancelEditing: function()
     917    {
    954918        this._restoreViewerState();
    955         this._textViewer.readOnly = true;
    956919        this._delegate.setScriptSourceIsBeingEdited(false);
    957         return true;
    958920    }
    959921}
  • trunk/Source/WebCore/inspector/front-end/TextViewer.js

    r83288 r83585  
    5555
    5656    this.element.addEventListener("dblclick", this._doubleClick.bind(this), true);
     57    this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
     58
     59    this._registerShortcuts();
    5760}
    5861
     
    6164    {
    6265        this._mainPanel.mimeType = mimeType;
    63     },
    64 
    65     set readOnly(readOnly)
    66     {
    67         this._mainPanel.readOnly = readOnly;
    68     },
    69 
    70     get readOnly()
    71     {
    72         return this._mainPanel.readOnly;
    7366    },
    7467
     
    227220    _doubleClick: function(event)
    228221    {
    229         if (!this._delegate.isContentEditable())
     222        if (!this._mainPanel.readOnly || this._commitEditingInProgress)
    230223            return;
    231224
     
    234227            return;  // Do not trigger editing from line numbers.
    235228
    236         if (this.readOnly) {
    237             this.readOnly = false;
    238             window.getSelection().collapseToStart();
    239         }
     229        if (!this._delegate.isContentEditable())
     230            return;
     231
     232        this._mainPanel.readOnly = false;
     233        window.getSelection().collapseToStart();
     234    },
     235
     236    _registerShortcuts: function()
     237    {
     238        this._shortcuts = {};
     239        var commitEditing = this._commitEditing.bind(this);
     240        var cancelEditing = this._cancelEditing.bind(this);
     241        this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = commitEditing;
     242        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Enter.code, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = commitEditing;
     243        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Esc.code)] = cancelEditing;
     244    },
     245
     246    _handleKeyDown: function(e)
     247    {
     248        var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
     249        var handler = this._shortcuts[shortcutKey];
     250        if (handler && handler.call(this)) {
     251            e.preventDefault();
     252            e.stopPropagation();
     253        }
     254    },
     255
     256    _commitEditing: function()
     257    {
     258        if (this._mainPanel.readOnly)
     259            return false;
     260
     261        this._mainPanel.readOnly = true;
     262        function didCommitEditing(error)
     263        {
     264            this._commitEditingInProgress = false;
     265            if (error)
     266                this._mainPanel.readOnly = false;
     267        }
     268        this._commitEditingInProgress = true;
     269        this._delegate.commitEditing(didCommitEditing.bind(this));
     270        return true;
     271    },
     272
     273    _cancelEditing: function()
     274    {
     275        if (this._mainPanel.readOnly)
     276            return false;
     277
     278        this._mainPanel.readOnly = true;
     279        this._delegate.cancelEditing();
     280        return true;
    240281    }
    241282}
     
    259300
    260301    endEditing: function(oldRange, newRange)
     302    {
     303        // Should be implemented by subclasses.
     304    },
     305
     306    commitEditing: function()
     307    {
     308        // Should be implemented by subclasses.
     309    },
     310
     311    cancelEditing: function()
    261312    {
    262313        // Should be implemented by subclasses.
Note: See TracChangeset for help on using the changeset viewer.