Changeset 83585 in webkit
- Timestamp:
- Apr 12, 2011 6:52:32 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r83584 r83585 1 2011-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 1 10 2011-04-12 Pavel Feldman <pfeldman@google.com> 2 11 -
trunk/LayoutTests/inspector/debugger/live-edit.html
r83294 r83585 91 91 { 92 92 InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", callback); 93 sourceFrame._textViewer. readOnly = false;93 sourceFrame._textViewer._mainPanel.readOnly = false; 94 94 sourceFrame.startEditing(); 95 95 var oldRange, newRange; … … 107 107 } 108 108 sourceFrame.endEditing(oldRange, newRange); 109 sourceFrame._ handleSave();109 sourceFrame._textViewer._commitEditing(); 110 110 } 111 111 }; -
trunk/Source/WebCore/ChangeLog
r83584 r83585 1 2011-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 1 28 2011-04-12 Pavel Feldman <pfeldman@google.com> 2 29 -
trunk/Source/WebCore/inspector/front-end/SourceFrame.js
r83577 r83585 50 50 51 51 this._breakpoints = {}; 52 53 this._registerShortcuts();54 52 } 55 53 … … 237 235 isContentEditable: function() 238 236 { 239 return this._delegate.canEditScriptSource() && !this._editScriptSourceInProgress;237 return this._delegate.canEditScriptSource(); 240 238 }, 241 239 … … 305 303 element.addEventListener("scroll", this._scroll.bind(this), true); 306 304 } 307 element.addEventListener("keydown", this._handleKeyDown.bind(this), false);308 305 309 306 this._textViewer.beginUpdates(); … … 872 869 }, 873 870 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 { 898 873 if (!this._viewerState) { 899 874 // No editing was actually done. 900 this._textViewer.readOnly = true;901 875 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) 913 881 { 914 this._editScriptSourceInProgress = false;915 916 882 if (error) { 917 this._viewerState = originalViewerState;918 this._textViewer.readOnly = false;919 this._delegate.setScriptSourceIsBeingEdited(true);920 883 WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error); 921 884 WebInspector.showConsole(); 885 callback(error); 922 886 return; 923 887 } … … 929 893 } 930 894 931 for (var lineNumber in originalViewerState.breakpoints)895 for (var lineNumber in this._viewerState.breakpoints) 932 896 this._delegate.removeBreakpoint(Number(lineNumber)); 933 897 … … 936 900 this._delegate.setBreakpoint(Number(lineNumber), breakpoint.condition, breakpoint.enabled); 937 901 } 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)); 942 909 }, 943 910 … … 947 914 }, 948 915 949 _handleRevertEditing: function() 950 { 951 if (this._textViewer.readOnly) 952 return false; 953 916 cancelEditing: function() 917 { 954 918 this._restoreViewerState(); 955 this._textViewer.readOnly = true;956 919 this._delegate.setScriptSourceIsBeingEdited(false); 957 return true;958 920 } 959 921 } -
trunk/Source/WebCore/inspector/front-end/TextViewer.js
r83288 r83585 55 55 56 56 this.element.addEventListener("dblclick", this._doubleClick.bind(this), true); 57 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false); 58 59 this._registerShortcuts(); 57 60 } 58 61 … … 61 64 { 62 65 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;73 66 }, 74 67 … … 227 220 _doubleClick: function(event) 228 221 { 229 if (!this._ delegate.isContentEditable())222 if (!this._mainPanel.readOnly || this._commitEditingInProgress) 230 223 return; 231 224 … … 234 227 return; // Do not trigger editing from line numbers. 235 228 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; 240 281 } 241 282 } … … 259 300 260 301 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() 261 312 { 262 313 // Should be implemented by subclasses.
Note: See TracChangeset
for help on using the changeset viewer.