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

Unified Diff: chrome/browser/resources/options/inline_editable_list.js

Issue 819193003: Fix list focus after tab key in chrome://settings/autofillEditAddress page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests. Created 5 years, 11 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 05c63eac45d43b8571cd33228386b05ebea4be12..cff2a84a506327c31cb4203038d78c855e5e4c2c 100644
--- a/chrome/browser/resources/options/inline_editable_list.js
+++ b/chrome/browser/resources/options/inline_editable_list.js
@@ -85,7 +85,8 @@ cr.define('options', function() {
/** @override */
selectionChanged: function() {
- this.updateEditState();
+ if (!this.parentNode.eventsDisabled)
+ this.updateEditState();
},
/**
@@ -578,6 +579,13 @@ cr.define('options', function() {
__proto__: DeletableItemList.prototype,
/**
+ * Event handling is disabled if > 0.
+ * @type {number}
+ * @private
+ */
+ eventsDisabledCount_: 0,
+
+ /**
* Focuses the input element of the placeholder if true.
* @type {boolean}
* @private
@@ -596,12 +604,27 @@ cr.define('options', function() {
},
/**
+ * Whether events are disabled.
+ * Used to modify the list without triggering a bunch of unnecessary events.
+ * @type {boolean}
+ */
+ get eventsDisabled() {
+ return this.eventsDisabledCount_ > 0;
+ },
+ set eventsDisabled(disabled) {
+ this.eventsDisabledCount_ += disabled ? 1 : -1;
+ },
+
+ /**
* Called when the list hierarchy as a whole loses or gains focus; starts
* or ends editing for the lead item if necessary.
* @param {Event} e The change event.
* @private
*/
handleListFocusChange_: function(e) {
+ if (this.eventsDisabled)
+ return;
+
bondd 2015/01/15 03:04:02 This wasn't necessary.
var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex);
if (leadItem) {
if (e.newValue) {
@@ -626,6 +649,9 @@ cr.define('options', function() {
/** @override */
handleLeadChange: function(e) {
+ if (this.eventsDisabled)
+ return;
+
DeletableItemList.prototype.handleLeadChange.call(this, e);
var focusedColumnIndex = -1;
@@ -665,6 +691,38 @@ cr.define('options', function() {
},
/**
+ * Set the selected index without changing the focused element on the page.
+ * Used to change the selected index when the list doesn't have focus (and
+ * doesn't want to take focus).
+ */
+ setSelectedIndexWithoutFocusing: function(index) {
+ this.eventsDisabled = true;
+ // Remove focusability from old item.
+ var oldItem = this.getListItemByIndex(this.selectionModel.leadIndex) ||
+ this.getInitialFocusableItem();
+ if (oldItem) {
+ oldItem.setEditableValuesFocusable(false);
+ oldItem.setStaticValuesFocusable(false);
+ oldItem.setCloseButtonFocusable(false);
+ oldItem.lead = false;
+ }
+
+ this.selectionModel.selectedIndex = index;
+ // Add focusability to new item.
+ var newItem = this.getListItemByIndex(index);
+ if (newItem) {
+ if (newItem.isPlaceholder)
+ newItem.setEditableValuesFocusable(true);
+ else
+ newItem.setStaticValuesFocusable(true);
+
+ newItem.setCloseButtonFocusable(true);
+ newItem.lead = true;
+ }
+ this.eventsDisabled = false;
+ },
+
+ /**
* Focus the placeholder's first input field.
* Should only be called immediately after the list has been repopulated.
*/

Powered by Google App Engine
This is Rietveld 408576698