Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var DeletableItem = options.DeletableItem; | 6 /** @const */ var DeletableItem = options.DeletableItem; |
| 7 /** @const */ var DeletableItemList = options.DeletableItemList; | 7 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Creates a new list item with support for inline editing. | 10 * Creates a new list item with support for inline editing. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 }, | 173 }, |
| 174 set isPlaceholder(isPlaceholder) { | 174 set isPlaceholder(isPlaceholder) { |
| 175 this.isPlaceholder_ = isPlaceholder; | 175 this.isPlaceholder_ = isPlaceholder; |
| 176 if (isPlaceholder) | 176 if (isPlaceholder) |
| 177 this.deletable = false; | 177 this.deletable = false; |
| 178 }, | 178 }, |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * The HTML element that should have focus initially when editing starts, | 181 * The HTML element that should have focus initially when editing starts, |
| 182 * if a specific element wasn't clicked. | 182 * if a specific element wasn't clicked. |
| 183 * Defaults to the first <input> element; can be overriden by subclasses if | 183 * Defaults to the first <input> element; can be overridden by subclasses if |
| 184 * a different element should be focused. | 184 * a different element should be focused. |
| 185 * @type {HTMLElement} | 185 * @type {HTMLElement} |
| 186 */ | 186 */ |
| 187 get initialFocusElement() { | 187 get initialFocusElement() { |
| 188 return this.contentElement.querySelector('input'); | 188 return this.contentElement.querySelector('input'); |
| 189 }, | 189 }, |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Whether the input in currently valid to submit. If this returns false | 192 * Whether the input in currently valid to submit. If this returns false |
| 193 * when editing would be submitted, either editing will not be ended, | 193 * when editing would be submitted, either editing will not be ended, |
| 194 * or it will be cancelled, depending on the context. | 194 * or it will be cancelled, depending on the context. |
| 195 * Can be overrided by subclasses to perform input validation. | 195 * Can be overridden by subclasses to perform input validation. |
| 196 * @type {boolean} | 196 * @type {boolean} |
| 197 */ | 197 */ |
| 198 get currentInputIsValid() { | 198 get currentInputIsValid() { |
| 199 return true; | 199 return true; |
| 200 }, | 200 }, |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * Returns true if the item has been changed by an edit. | 203 * Returns true if the item has been changed by an edit. |
| 204 * Can be overrided by subclasses to return false when nothing has changed | 204 * Can be overridden by subclasses to return false when nothing has changed |
| 205 * to avoid unnecessary commits. | 205 * to avoid unnecessary commits. |
| 206 * @type {boolean} | 206 * @type {boolean} |
| 207 */ | 207 */ |
| 208 get hasBeenEdited() { | 208 get hasBeenEdited() { |
| 209 return true; | 209 return true; |
| 210 }, | 210 }, |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * Returns a div containing an <input>, as well as static text if | 213 * Returns a div containing an <input>, as well as static text if |
| 214 * isPlaceholder is not true. | 214 * isPlaceholder is not true. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 if (!staticLabel) | 289 if (!staticLabel) |
| 290 continue; | 290 continue; |
| 291 | 291 |
| 292 if (editFields[i].tagName == 'INPUT') | 292 if (editFields[i].tagName == 'INPUT') |
| 293 staticLabel.textContent = editFields[i].value; | 293 staticLabel.textContent = editFields[i].value; |
| 294 // Add more tag types here as new createEditable* methods are added. | 294 // Add more tag types here as new createEditable* methods are added. |
| 295 } | 295 } |
| 296 }, | 296 }, |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Called a key is pressed. Handles committing and cancelling edits. | 299 * Called a key is pressed. Handles committing and canceling edits. |
|
Dan Beam
2012/08/11 01:38:02
called *when* a key is pressed
Greg Spencer (Chromium)
2012/08/13 19:20:04
Done.
| |
| 300 * @param {Event} e The key down event. | 300 * @param {Event} e The key down event. |
| 301 * @private | 301 * @private |
| 302 */ | 302 */ |
| 303 handleKeyDown_: function(e) { | 303 handleKeyDown_: function(e) { |
| 304 if (!this.editing) | 304 if (!this.editing) |
| 305 return; | 305 return; |
| 306 | 306 |
| 307 var endEdit = false; | 307 var endEdit = false; |
| 308 switch (e.keyIdentifier) { | 308 switch (e.keyIdentifier) { |
| 309 case 'U+001B': // Esc | 309 case 'U+001B': // Esc |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 return true; | 406 return true; |
| 407 }, | 407 }, |
| 408 }; | 408 }; |
| 409 | 409 |
| 410 // Export | 410 // Export |
| 411 return { | 411 return { |
| 412 InlineEditableItem: InlineEditableItem, | 412 InlineEditableItem: InlineEditableItem, |
| 413 InlineEditableItemList: InlineEditableItemList, | 413 InlineEditableItemList: InlineEditableItemList, |
| 414 }; | 414 }; |
| 415 }); | 415 }); |
| OLD | NEW |