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

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

Issue 7903001: Improve Tab-key navigation for editing Autofill addresses and credit cards. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 this.addEventListener('keydown', this.handleKeyDown_); 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 the input element receives focus. Selects this item in the
87 * list selection model.
88 * @private
89 */
90 handleFocus_: function() {
91 var list = this.parentNode;
92 var index = list.getIndexOfListItem(this);
93 list.selectionModel.selectedIndex = index;
94 list.selectionModel.anchorIndex = index;
95 },
Ilya Sherman 2011/09/15 04:10:39 This was moved to deletable_item_list.js.
96
97 /**
98 * Called when this element gains or loses 'lead' status. Updates editing 86 * Called when this element gains or loses 'lead' status. Updates editing
99 * mode accordingly. 87 * mode accordingly.
100 * @private 88 * @private
101 */ 89 */
102 handleLeadChange_: function() { 90 handleLeadChange_: function() {
103 this.updateEditState(); 91 this.updateEditState();
104 }, 92 },
105 93
106 /** 94 /**
107 * Updates the edit state based on the current selected and lead states. 95 * Updates the edit state based on the current selected and lead states.
108 */ 96 */
109 updateEditState: function() { 97 updateEditState: function() {
110 if (this.editable) 98 if (this.editable)
111 this.editing = this.selected && this.lead; 99 this.editing = this.selected && this.lead;
112 }, 100 },
113 101
114 /** 102 /**
115 * Whether the user is currently editing the list item. 103 * Whether the user is currently editing the list item.
116 * @type {boolean} 104 * @type {boolean}
117 */ 105 */
118 get editing() { 106 get editing() {
119 return this.hasAttribute('editing'); 107 return this.hasAttribute('editing');
120 }, 108 },
121 set editing(editing) { 109 set editing(editing) {
122 if (this.editing == editing) 110 if (this.editing == editing)
123 return; 111 return;
124 112
125 if (editing) 113 if (editing) {
126 this.setAttribute('editing', ''); 114 this.setAttribute('editing', '');
127 else
128 this.removeAttribute('editing');
Ilya Sherman 2011/09/15 04:10:39 This if/else got merged with the if/else below.
James Hawkins 2011/09/15 19:28:02 This block was intentionally kept separate from be
Ilya Sherman 2011/09/15 20:39:01 Ok, restored, though I find the second block harde
129
130 if (editing) {
131 this.editCancelled_ = false; 115 this.editCancelled_ = false;
132 116
133 cr.dispatchSimpleEvent(this, 'edit', true); 117 cr.dispatchSimpleEvent(this, 'edit', true);
134 118
135 var focusElement = this.editClickTarget_ || this.initialFocusElement; 119 var focusElement = this.editClickTarget_ || this.initialFocusElement;
136 this.editClickTarget_ = null; 120 this.editClickTarget_ = null;
137 121
138 // When this is called in response to the selectedChange event, 122 // When this is called in response to the selectedChange event,
139 // the list grabs focus immediately afterwards. Thus we must delay 123 // the list grabs focus immediately afterwards. Thus we must delay
140 // our focus grab. 124 // our focus grab.
141 var self = this; 125 var self = this;
142 if (focusElement) { 126 if (focusElement) {
143 window.setTimeout(function() { 127 window.setTimeout(function() {
144 // Make sure we are still in edit mode by the time we execute. 128 // Make sure we are still in edit mode by the time we execute.
145 if (self.editing && self.focusPlaceholder) { 129 if (self.editing) {
Ilya Sherman 2011/09/15 04:10:39 List items don't have a 'focusPlaceholder' propert
James Hawkins 2011/09/15 19:28:02 But InlineEditableLists do...
Ilya Sherman 2011/09/15 20:39:01 InlineEditableItemLists have this property. Inlin
146 focusElement.focus(); 130 focusElement.focus();
147 focusElement.select(); 131 focusElement.select();
148 } 132 }
149 }, 50); 133 }, 50);
150 } 134 }
151 } else { 135 } else {
136 this.removeAttribute('editing');
152 if (!this.editCancelled_ && this.hasBeenEdited && 137 if (!this.editCancelled_ && this.hasBeenEdited &&
153 this.currentInputIsValid) { 138 this.currentInputIsValid) {
154 if (this.isPlaceholder) 139 if (this.isPlaceholder)
155 this.parentNode.focusPlaceholder = true; 140 this.parentNode.focusPlaceholder = true;
156 141
157 this.updateStaticValues_(); 142 this.updateStaticValues_();
158 cr.dispatchSimpleEvent(this, 'commitedit', true); 143 cr.dispatchSimpleEvent(this, 'commitedit', true);
159 } else { 144 } else {
160 this.resetEditableValues_(); 145 this.resetEditableValues_();
161 cr.dispatchSimpleEvent(this, 'canceledit', true); 146 cr.dispatchSimpleEvent(this, 'canceledit', true);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return true; 402 return true;
418 }, 403 },
419 }; 404 };
420 405
421 // Export 406 // Export
422 return { 407 return {
423 InlineEditableItem: InlineEditableItem, 408 InlineEditableItem: InlineEditableItem,
424 InlineEditableItemList: InlineEditableItemList, 409 InlineEditableItemList: InlineEditableItemList,
425 }; 410 };
426 }); 411 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698