Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 DeletableItem = options.DeletableItem; | 6 const DeletableItem = options.DeletableItem; |
| 7 const DeletableItemList = options.DeletableItemList; | 7 const 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 * @type {HTMLElement} | 65 * @type {HTMLElement} |
| 66 * @private | 66 * @private |
| 67 */ | 67 */ |
| 68 editClickTarget_: null, | 68 editClickTarget_: null, |
| 69 | 69 |
| 70 /** @inheritDoc */ | 70 /** @inheritDoc */ |
| 71 decorate: function() { | 71 decorate: function() { |
| 72 DeletableItem.prototype.decorate.call(this); | 72 DeletableItem.prototype.decorate.call(this); |
| 73 | 73 |
| 74 this.editFields_ = []; | 74 this.editFields_ = []; |
| 75 this.addEventListener('mousedown', this.handleMouseDown_.bind(this)); | 75 this.addEventListener('mousedown', this.handleMouseDown_); |
| 76 this.addEventListener('keydown', this.handleKeyDown_.bind(this)); | 76 this.addEventListener('keydown', this.handleKeyDown_); |
| 77 this.addEventListener('leadChange', this.handleLeadChange_); | 77 this.addEventListener('leadChange', this.handleLeadChange_); |
| 78 }, | 78 }, |
| 79 | 79 |
| 80 /** @inheritDoc */ | 80 /** @inheritDoc */ |
| 81 selectionChanged: function() { | 81 selectionChanged: function() { |
| 82 this.updateEditState(); | 82 this.updateEditState(); |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * Called when this element gains or loses 'lead' status. Updates editing | 86 * Called when this element gains or loses 'lead' status. Updates editing |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 | 332 |
| 333 InlineEditableItemList.prototype = { | 333 InlineEditableItemList.prototype = { |
| 334 __proto__: DeletableItemList.prototype, | 334 __proto__: DeletableItemList.prototype, |
| 335 | 335 |
| 336 /** @inheritDoc */ | 336 /** @inheritDoc */ |
| 337 decorate: function() { | 337 decorate: function() { |
| 338 DeletableItemList.prototype.decorate.call(this); | 338 DeletableItemList.prototype.decorate.call(this); |
| 339 this.setAttribute('inlineeditable', ''); | 339 this.setAttribute('inlineeditable', ''); |
| 340 this.addEventListener('hasElementFocusChange', | 340 this.addEventListener('hasElementFocusChange', |
| 341 this.handleListFocusChange_); | 341 this.handleListFocusChange_); |
| 342 | |
| 343 this.eventTracker = new EventTracker(); | |
| 344 this.addEventListener('DOMNodeInsertedIntoDocument', | |
| 345 this.handleNodeInserted_); | |
| 346 if (document.documentElement.contains(this)) | |
| 347 this.handleNodeInserted_(); | |
| 348 this.addEventListener('DOMNodeRemovedFromDocument', | |
| 349 this.handleNodeRemoved_); | |
| 342 }, | 350 }, |
| 343 | 351 |
| 344 /** | 352 /** |
| 345 * Called when the list hierarchy as a whole loses or gains focus; starts | 353 * Called when the list hierarchy as a whole loses or gains focus; starts |
| 346 * or ends editing for the lead item if necessary. | 354 * or ends editing for the lead item if necessary. |
| 347 * @param {Event} e The change event. | 355 * @param {Event} e The change event. |
| 348 * @private | 356 * @private |
| 349 */ | 357 */ |
| 350 handleListFocusChange_: function(e) { | 358 handleListFocusChange_: function(e) { |
| 351 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex); | 359 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex); |
| 352 if (leadItem) { | 360 if (leadItem) { |
| 353 if (e.newValue) | 361 if (e.newValue) |
| 354 leadItem.updateEditState(); | 362 leadItem.updateEditState(); |
| 355 else | 363 else |
| 356 leadItem.editing = false; | 364 leadItem.editing = false; |
| 357 } | 365 } |
| 358 }, | 366 }, |
| 367 | |
| 368 /** | |
| 369 * Handles blur events on window. When the user switches tabs or | |
| 370 * otherwise defocuses window, we treat that as a commit (same as if they | |
| 371 * clicked away within the page). | |
| 372 * @param {Event} e The blur event. | |
| 373 * @private | |
| 374 */ | |
| 375 handleWindowBlur_: function(e) { | |
| 376 var focusElement = this.ownerDocument.activeElement; | |
| 377 if (this.contains(focusElement)) | |
| 378 focusElement.blur(); | |
| 379 }, | |
| 380 | |
| 381 /** | |
| 382 * Handles DOMNodeInsertedIntoDocument event. Connect to the blur event on | |
| 383 * window (see above). This could be done in decorate(), but instead it's | |
| 384 * here so as to mirror the remove call. | |
| 385 * @param {Event} e The node inserted event. | |
| 386 * @private | |
| 387 */ | |
| 388 handleNodeInserted_: function(e) { | |
| 389 if (e && e.target == this) { | |
|
Rick Byers
2011/05/25 18:17:23
You call above with u undefined so that will be a
| |
| 390 this.eventTracker.add(window, 'blur', | |
| 391 this.handleWindowBlur_.bind(this)); | |
| 392 } | |
| 393 }, | |
| 394 | |
| 395 /** | |
| 396 * Handles DOMNodeRemovedFromDocument event. This is the closest thing to | |
| 397 * a destructor that we have. Disconnect from window events so |this| | |
| 398 * doesn't stick around (and leak). | |
| 399 * @param {Event} e The node removed event. | |
| 400 * @private | |
| 401 */ | |
| 402 handleNodeRemoved_: function(e) { | |
| 403 if (e.target == this) | |
| 404 this.eventTracker.removeAll(); | |
| 405 }, | |
| 359 }; | 406 }; |
| 360 | 407 |
| 361 // Export | 408 // Export |
| 362 return { | 409 return { |
| 363 InlineEditableItem: InlineEditableItem, | 410 InlineEditableItem: InlineEditableItem, |
| 364 InlineEditableItemList: InlineEditableItemList, | 411 InlineEditableItemList: InlineEditableItemList, |
| 365 }; | 412 }; |
| 366 }); | 413 }); |
| OLD | NEW |