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

Unified 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 side-by-side diff with in-line comments
Download patch
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..b955fbfaed5383cc368a62db281559042cb2086c 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,11 @@ cr.define('options', function() {
this.setAttribute('inlineeditable', '');
this.addEventListener('hasElementFocusChange',
this.handleListFocusChange_);
+
+ this.eventTracker = new EventTracker();
+ this.eventTracker.add(window, 'blur', this.handleWindowBlur_.bind(this));
+ this.addEventListener('DOMNodeRemovedFromDocument',
Rick Byers 2011/05/25 03:04:15 The use of EventTracker here looks right and neces
+ this.handleNodeRemoved_);
},
/**
@@ -356,6 +361,30 @@ 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();
stuartmorgan 2011/05/23 16:54:49 I'm afraid this will be confusing/unexpected for u
+ },
+
+ /**
+ * 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) {
+ this.eventTracker.removeAll();
+ },
};
// Export

Powered by Google App Engine
This is Rietveld 408576698