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

Side by Side Diff: chrome/browser/resources/options/inline_editable_list.js

Issue 7004058: Commit inline editable list changes when window loses focus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
OLDNEW
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
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
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.eventTracker.add(window, 'blur', this.handleWindowBlur_.bind(this));
345 this.addEventListener('DOMNodeRemovedFromDocument',
Rick Byers 2011/05/25 03:04:15 The use of EventTracker here looks right and neces
346 this.handleNodeRemoved_);
342 }, 347 },
343 348
344 /** 349 /**
345 * Called when the list hierarchy as a whole loses or gains focus; starts 350 * Called when the list hierarchy as a whole loses or gains focus; starts
346 * or ends editing for the lead item if necessary. 351 * or ends editing for the lead item if necessary.
347 * @param {Event} e The change event. 352 * @param {Event} e The change event.
348 * @private 353 * @private
349 */ 354 */
350 handleListFocusChange_: function(e) { 355 handleListFocusChange_: function(e) {
351 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex); 356 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex);
352 if (leadItem) { 357 if (leadItem) {
353 if (e.newValue) 358 if (e.newValue)
354 leadItem.updateEditState(); 359 leadItem.updateEditState();
355 else 360 else
356 leadItem.editing = false; 361 leadItem.editing = false;
357 } 362 }
358 }, 363 },
364
365 /**
366 * Handles blur events on window. When the user switches tabs or
367 * otherwise defocuses window, we treat that as a commit (same as if they
368 * clicked away within the page).
369 * @param {Event} e The blur event.
370 * @private
371 */
372 handleWindowBlur_: function(e) {
373 var focusElement = this.ownerDocument.activeElement;
374 if (this.contains(focusElement))
375 focusElement.blur();
stuartmorgan 2011/05/23 16:54:49 I'm afraid this will be confusing/unexpected for u
376 },
377
378 /**
379 * Handles DOMNodeRemovedFromDocument event. This is the closest thing to
380 * a destructor that we have. Disconnect from window events so |this|
381 * doesn't stick around (and leak).
382 * @param {Event} e The node removed event.
383 * @private
384 */
385 handleNodeRemoved_: function(e) {
386 this.eventTracker.removeAll();
387 },
359 }; 388 };
360 389
361 // Export 390 // Export
362 return { 391 return {
363 InlineEditableItem: InlineEditableItem, 392 InlineEditableItem: InlineEditableItem,
364 InlineEditableItemList: InlineEditableItemList, 393 InlineEditableItemList: InlineEditableItemList,
365 }; 394 };
366 }); 395 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698