Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: Source/devtools/front_end/ui/InplaceEditor.js

Issue 658483004: DevTools: fix DOM multiline editing, extract multiline editor API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/elements/ElementsTreeOutline.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) }}
14 */
15 WebInspector.InplaceEditor.Controller;
16
17 /**
13 * @param {!Element} element 18 * @param {!Element} element
14 * @param {!WebInspector.InplaceEditor.Config=} config 19 * @param {!WebInspector.InplaceEditor.Config=} config
15 * @return {?{cancel: function(), commit: function(), setWidth: function(number) }} 20 * @return {?WebInspector.InplaceEditor.Controller}
16 */ 21 */
17 WebInspector.InplaceEditor.startEditing = function(element, config) 22 WebInspector.InplaceEditor.startEditing = function(element, config)
18 { 23 {
19 if (!WebInspector.InplaceEditor._defaultInstance) 24 if (!WebInspector.InplaceEditor._defaultInstance)
20 WebInspector.InplaceEditor._defaultInstance = new WebInspector.InplaceEd itor(); 25 WebInspector.InplaceEditor._defaultInstance = new WebInspector.InplaceEd itor();
21 return WebInspector.InplaceEditor._defaultInstance.startEditing(element, con fig); 26 return WebInspector.InplaceEditor._defaultInstance.startEditing(element, con fig);
22 } 27 }
23 28
29 /**
30 * @param {!Element} element
31 * @param {!WebInspector.InplaceEditor.Config=} config
32 * @return {!Promise.<!WebInspector.InplaceEditor.Controller>}
33 */
34 WebInspector.InplaceEditor.startMultilineEditing = function(element, config)
35 {
36 return self.runtime.instancePromise(WebInspector.InplaceEditor).then(startEd iting);
37
38 /**
39 * @param {!Object} inplaceEditor
40 * @return {!WebInspector.InplaceEditor.Controller|!Promise.<!WebInspector.I nplaceEditor.Controller>}
41 */
42 function startEditing(inplaceEditor)
43 {
44 var controller = /** @type {!WebInspector.InplaceEditor} */ (inplaceEdit or).startEditing(element, config);
45 if (!controller)
46 return Promise.rejectWithError("Editing is already in progress");
47 return controller;
48 }
49 }
50
24 WebInspector.InplaceEditor.prototype = { 51 WebInspector.InplaceEditor.prototype = {
25 /** 52 /**
26 * @return {string} 53 * @return {string}
27 */ 54 */
28 editorContent: function(editingContext) { 55 editorContent: function(editingContext) {
29 var element = editingContext.element; 56 var element = editingContext.element;
30 if (element.tagName === "INPUT" && element.type === "text") 57 if (element.tagName === "INPUT" && element.type === "text")
31 return element.value; 58 return element.value;
32 59
33 return element.textContent; 60 return element.textContent;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 element.textContent = editingContext.oldText; 94 element.textContent = editingContext.oldText;
68 }, 95 },
69 96
70 augmentEditingHandle: function(editingContext, handle) 97 augmentEditingHandle: function(editingContext, handle)
71 { 98 {
72 }, 99 },
73 100
74 /** 101 /**
75 * @param {!Element} element 102 * @param {!Element} element
76 * @param {!WebInspector.InplaceEditor.Config=} config 103 * @param {!WebInspector.InplaceEditor.Config=} config
77 * @return {?{cancel: function(), commit: function()}} 104 * @return {?WebInspector.InplaceEditor.Controller}
78 */ 105 */
79 startEditing: function(element, config) 106 startEditing: function(element, config)
80 { 107 {
81 if (!WebInspector.markBeingEdited(element, true)) 108 if (!WebInspector.markBeingEdited(element, true))
82 return null; 109 return null;
83 110
84 config = config || new WebInspector.InplaceEditor.Config(function() {}, function() {}); 111 config = config || new WebInspector.InplaceEditor.Config(function() {}, function() {});
85 var editingContext = { element: element, config: config }; 112 var editingContext = { element: element, config: config };
86 var committedCallback = config.commitHandler; 113 var committedCallback = config.commitHandler;
87 var cancelledCallback = config.cancelHandler; 114 var cancelledCallback = config.cancelHandler;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 handleEditingResult(result, event); 210 handleEditingResult(result, event);
184 } 211 }
185 212
186 element.addEventListener("blur", blurEventListener, isMultiline); 213 element.addEventListener("blur", blurEventListener, isMultiline);
187 element.addEventListener("keydown", keyDownEventListener, true); 214 element.addEventListener("keydown", keyDownEventListener, true);
188 if (pasteCallback) 215 if (pasteCallback)
189 element.addEventListener("paste", pasteEventListener, true); 216 element.addEventListener("paste", pasteEventListener, true);
190 217
191 var handle = { 218 var handle = {
192 cancel: editingCancelled.bind(element), 219 cancel: editingCancelled.bind(element),
193 commit: editingCommitted.bind(element) 220 commit: editingCommitted.bind(element),
221 setWidth: function() {}
194 }; 222 };
195 this.augmentEditingHandle(editingContext, handle); 223 this.augmentEditingHandle(editingContext, handle);
196 return handle; 224 return handle;
197 } 225 }
198 } 226 }
199 227
200 /** 228 /**
201 * @constructor 229 * @constructor
202 * @param {function(!Element,string,string,T,string)} commitHandler 230 * @param {function(!Element,string,string,T,string)} commitHandler
203 * @param {function(!Element,T)} cancelHandler 231 * @param {function(!Element,T)} cancelHandler
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 267
240 /** 268 /**
241 * @param {string} initialValue 269 * @param {string} initialValue
242 * @param {!Object} mode 270 * @param {!Object} mode
243 * @param {string} theme 271 * @param {string} theme
244 * @param {boolean=} lineWrapping 272 * @param {boolean=} lineWrapping
245 * @param {boolean=} smartIndent 273 * @param {boolean=} smartIndent
246 */ 274 */
247 setMultilineOptions: function(initialValue, mode, theme, lineWrapping, smart Indent) 275 setMultilineOptions: function(initialValue, mode, theme, lineWrapping, smart Indent)
248 { 276 {
277 this.multiline = true;
249 this.initialValue = initialValue; 278 this.initialValue = initialValue;
250 this.mode = mode; 279 this.mode = mode;
251 this.theme = theme; 280 this.theme = theme;
252 this.lineWrapping = lineWrapping; 281 this.lineWrapping = lineWrapping;
253 this.smartIndent = smartIndent; 282 this.smartIndent = smartIndent;
254 }, 283 },
255 284
256 setCustomFinishHandler: function(customFinishHandler) 285 setCustomFinishHandler: function(customFinishHandler)
257 { 286 {
258 this.customFinishHandler = customFinishHandler; 287 this.customFinishHandler = customFinishHandler;
259 } 288 }
260 } 289 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/elements/ElementsTreeOutline.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698