| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 */ | 7 */ |
| 8 WebInspector.InplaceEditor = function() | 8 WebInspector.InplaceEditor = function() |
| 9 { | 9 { |
| 10 } | 10 }; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @typedef {{cancel: function(), commit: function(), setWidth: function(number)
}} | 13 * @typedef {{cancel: function(), commit: function(), setWidth: function(number)
}} |
| 14 */ | 14 */ |
| 15 WebInspector.InplaceEditor.Controller; | 15 WebInspector.InplaceEditor.Controller; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @param {!Element} element | 18 * @param {!Element} element |
| 19 * @param {!WebInspector.InplaceEditor.Config=} config | 19 * @param {!WebInspector.InplaceEditor.Config=} config |
| 20 * @return {?WebInspector.InplaceEditor.Controller} | 20 * @return {?WebInspector.InplaceEditor.Controller} |
| 21 */ | 21 */ |
| 22 WebInspector.InplaceEditor.startEditing = function(element, config) | 22 WebInspector.InplaceEditor.startEditing = function(element, config) |
| 23 { | 23 { |
| 24 if (!WebInspector.InplaceEditor._defaultInstance) | 24 if (!WebInspector.InplaceEditor._defaultInstance) |
| 25 WebInspector.InplaceEditor._defaultInstance = new WebInspector.InplaceEd
itor(); | 25 WebInspector.InplaceEditor._defaultInstance = new WebInspector.InplaceEd
itor(); |
| 26 return WebInspector.InplaceEditor._defaultInstance.startEditing(element, con
fig); | 26 return WebInspector.InplaceEditor._defaultInstance.startEditing(element, con
fig); |
| 27 } | 27 }; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @param {!Element} element | 30 * @param {!Element} element |
| 31 * @param {!WebInspector.InplaceEditor.Config=} config | 31 * @param {!WebInspector.InplaceEditor.Config=} config |
| 32 * @return {!Promise.<!WebInspector.InplaceEditor.Controller>} | 32 * @return {!Promise.<!WebInspector.InplaceEditor.Controller>} |
| 33 */ | 33 */ |
| 34 WebInspector.InplaceEditor.startMultilineEditing = function(element, config) | 34 WebInspector.InplaceEditor.startMultilineEditing = function(element, config) |
| 35 { | 35 { |
| 36 return self.runtime.extension(WebInspector.InplaceEditor).instance().then(st
artEditing); | 36 return self.runtime.extension(WebInspector.InplaceEditor).instance().then(st
artEditing); |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * @param {!Object} inplaceEditor | 39 * @param {!Object} inplaceEditor |
| 40 * @return {!WebInspector.InplaceEditor.Controller|!Promise.<!WebInspector.I
nplaceEditor.Controller>} | 40 * @return {!WebInspector.InplaceEditor.Controller|!Promise.<!WebInspector.I
nplaceEditor.Controller>} |
| 41 */ | 41 */ |
| 42 function startEditing(inplaceEditor) | 42 function startEditing(inplaceEditor) |
| 43 { | 43 { |
| 44 var controller = /** @type {!WebInspector.InplaceEditor} */ (inplaceEdit
or).startEditing(element, config); | 44 var controller = /** @type {!WebInspector.InplaceEditor} */ (inplaceEdit
or).startEditing(element, config); |
| 45 if (!controller) | 45 if (!controller) |
| 46 return Promise.reject(new Error("Editing is already in progress")); | 46 return Promise.reject(new Error("Editing is already in progress")); |
| 47 return controller; | 47 return controller; |
| 48 } | 48 } |
| 49 } | 49 }; |
| 50 | 50 |
| 51 WebInspector.InplaceEditor.prototype = { | 51 WebInspector.InplaceEditor.prototype = { |
| 52 /** | 52 /** |
| 53 * @return {string} | 53 * @return {string} |
| 54 */ | 54 */ |
| 55 editorContent: function(editingContext) { | 55 editorContent: function(editingContext) { |
| 56 var element = editingContext.element; | 56 var element = editingContext.element; |
| 57 if (element.tagName === "INPUT" && element.type === "text") | 57 if (element.tagName === "INPUT" && element.type === "text") |
| 58 return element.value; | 58 return element.value; |
| 59 | 59 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 element.addEventListener("paste", pasteEventListener, true); | 229 element.addEventListener("paste", pasteEventListener, true); |
| 230 | 230 |
| 231 var handle = { | 231 var handle = { |
| 232 cancel: editingCancelled.bind(element), | 232 cancel: editingCancelled.bind(element), |
| 233 commit: editingCommitted.bind(element), | 233 commit: editingCommitted.bind(element), |
| 234 setWidth: function() {} | 234 setWidth: function() {} |
| 235 }; | 235 }; |
| 236 this.augmentEditingHandle(editingContext, handle); | 236 this.augmentEditingHandle(editingContext, handle); |
| 237 return handle; | 237 return handle; |
| 238 } | 238 } |
| 239 } | 239 }; |
| 240 | 240 |
| 241 /** | 241 /** |
| 242 * @constructor | 242 * @constructor |
| 243 * @param {function(!Element,string,string,T,string)} commitHandler | 243 * @param {function(!Element,string,string,T,string)} commitHandler |
| 244 * @param {function(!Element,T)} cancelHandler | 244 * @param {function(!Element,T)} cancelHandler |
| 245 * @param {T=} context | 245 * @param {T=} context |
| 246 * @param {function(!Element,!Event):boolean=} blurHandler | 246 * @param {function(!Element,!Event):boolean=} blurHandler |
| 247 * @template T | 247 * @template T |
| 248 */ | 248 */ |
| 249 WebInspector.InplaceEditor.Config = function(commitHandler, cancelHandler, conte
xt, blurHandler) | 249 WebInspector.InplaceEditor.Config = function(commitHandler, cancelHandler, conte
xt, blurHandler) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * @type {boolean|undefined} | 262 * @type {boolean|undefined} |
| 263 */ | 263 */ |
| 264 this.multiline; | 264 this.multiline; |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @type {function(!Event):string|undefined} | 267 * @type {function(!Event):string|undefined} |
| 268 */ | 268 */ |
| 269 this.postKeydownFinishHandler; | 269 this.postKeydownFinishHandler; |
| 270 } | 270 }; |
| 271 | 271 |
| 272 WebInspector.InplaceEditor.Config.prototype = { | 272 WebInspector.InplaceEditor.Config.prototype = { |
| 273 setPasteHandler: function(pasteHandler) | 273 setPasteHandler: function(pasteHandler) |
| 274 { | 274 { |
| 275 this.pasteHandler = pasteHandler; | 275 this.pasteHandler = pasteHandler; |
| 276 }, | 276 }, |
| 277 | 277 |
| 278 /** | 278 /** |
| 279 * @param {string} initialValue | 279 * @param {string} initialValue |
| 280 * @param {!Object} mode | 280 * @param {!Object} mode |
| (...skipping 11 matching lines...) Expand all Loading... |
| 292 this.smartIndent = smartIndent; | 292 this.smartIndent = smartIndent; |
| 293 }, | 293 }, |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * @param {function(!Event):string} postKeydownFinishHandler | 296 * @param {function(!Event):string} postKeydownFinishHandler |
| 297 */ | 297 */ |
| 298 setPostKeydownFinishHandler: function(postKeydownFinishHandler) | 298 setPostKeydownFinishHandler: function(postKeydownFinishHandler) |
| 299 { | 299 { |
| 300 this.postKeydownFinishHandler = postKeydownFinishHandler; | 300 this.postKeydownFinishHandler = postKeydownFinishHandler; |
| 301 } | 301 } |
| 302 } | 302 }; |
| OLD | NEW |