Chromium Code Reviews| Index: chrome/browser/resources/options/inline_editable_list.js |
| diff --git a/chrome/browser/resources/options/inline_editable_list.js b/chrome/browser/resources/options/inline_editable_list.js |
| index 1c94a8d200b0ddd512a895a21852ded314c8874d..6097bab80b620dce46305de970ceb5484c949628 100644 |
| --- a/chrome/browser/resources/options/inline_editable_list.js |
| +++ b/chrome/browser/resources/options/inline_editable_list.js |
| @@ -72,8 +72,8 @@ cr.define('options', function() { |
| DeletableItem.prototype.decorate.call(this); |
| this.editFields_ = []; |
| - this.addEventListener('mousedown', this.handleMouseDown_.bind(this)); |
| - this.addEventListener('keydown', this.handleKeyDown_.bind(this)); |
| + this.addEventListener('mousedown', this.handleMouseDown_); |
| + this.addEventListener('keydown', this.handleKeyDown_); |
| this.addEventListener('leadChange', this.handleLeadChange_); |
| }, |
| @@ -339,6 +339,14 @@ cr.define('options', function() { |
| this.setAttribute('inlineeditable', ''); |
| this.addEventListener('hasElementFocusChange', |
| this.handleListFocusChange_); |
| + |
| + this.eventTracker = new EventTracker(); |
| + this.addEventListener('DOMNodeInsertedIntoDocument', |
| + this.handleNodeInserted_); |
| + if (document.documentElement.contains(this)) |
| + this.handleNodeInserted_(); |
| + this.addEventListener('DOMNodeRemovedFromDocument', |
| + this.handleNodeRemoved_); |
| }, |
| /** |
| @@ -356,6 +364,45 @@ cr.define('options', function() { |
| leadItem.editing = false; |
| } |
| }, |
| + |
| + /** |
| + * Handles blur events on window. When the user switches tabs or |
| + * otherwise defocuses window, we treat that as a commit (same as if they |
| + * clicked away within the page). |
| + * @param {Event} e The blur event. |
| + * @private |
| + */ |
| + handleWindowBlur_: function(e) { |
| + var focusElement = this.ownerDocument.activeElement; |
| + if (this.contains(focusElement)) |
| + focusElement.blur(); |
| + }, |
| + |
| + /** |
| + * Handles DOMNodeInsertedIntoDocument event. Connect to the blur event on |
| + * window (see above). This could be done in decorate(), but instead it's |
| + * here so as to mirror the remove call. |
| + * @param {Event} e The node inserted event. |
| + * @private |
| + */ |
| + handleNodeInserted_: function(e) { |
| + if (e && e.target == this) { |
|
Rick Byers
2011/05/25 18:17:23
You call above with u undefined so that will be a
|
| + this.eventTracker.add(window, 'blur', |
| + this.handleWindowBlur_.bind(this)); |
| + } |
| + }, |
| + |
| + /** |
| + * Handles DOMNodeRemovedFromDocument event. This is the closest thing to |
| + * a destructor that we have. Disconnect from window events so |this| |
| + * doesn't stick around (and leak). |
| + * @param {Event} e The node removed event. |
| + * @private |
| + */ |
| + handleNodeRemoved_: function(e) { |
| + if (e.target == this) |
| + this.eventTracker.removeAll(); |
| + }, |
| }; |
| // Export |