OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 * @param {!cr.ui.List} list The list to toggle visilibility for. | 158 * @param {!cr.ui.List} list The list to toggle visilibility for. |
159 */ | 159 */ |
160 updateListVisibility_: function(list) { | 160 updateListVisibility_: function(list) { |
161 var empty = list.dataModel.length == 0; | 161 var empty = list.dataModel.length == 0; |
162 var listPlaceHolderID = list.id + '-empty-placeholder'; | 162 var listPlaceHolderID = list.id + '-empty-placeholder'; |
163 list.hidden = empty; | 163 list.hidden = empty; |
164 $(listPlaceHolderID).hidden = !empty; | 164 $(listPlaceHolderID).hidden = !empty; |
165 }, | 165 }, |
166 | 166 |
167 /** | 167 /** |
168 * Updates eliding of origins. If there is no enough space to show the full | |
169 * origin, the origin is elided from the left with ellipsis. | |
170 * @param {!cr.ui.List} list The list to update eliding. | |
171 */ | |
172 updateOriginsEliding_: function(list) { | |
173 var entries = list.getElementsByClassName('deletable-item'); | |
174 if (entries.length == 0) | |
175 return; | |
176 var entry = entries[0]; | |
177 var columnWidth = entry.urlDiv.offsetWidth - | |
178 parseInt(window.getComputedStyle(entry.urlDiv).webkitMarginStart) - | |
179 parseInt(window.getComputedStyle(entry.urlDiv).webkitPaddingStart); | |
Evan Stade
2016/03/21 21:59:02
nit: store getComputedStyle in a var?
kolos1
2016/03/22 19:10:24
Done.
| |
180 for (var i = 0; i < entries.length; ++i) { | |
181 var urlLink = entries[i].urlLink; | |
182 if (urlLink.offsetWidth <= columnWidth) | |
183 continue; | |
184 urlLink.textContent = '…' + urlLink.textContent.substring(1); | |
185 while (urlLink.offsetWidth > columnWidth) | |
186 urlLink.textContent = '…' + urlLink.textContent.substring(2); | |
Evan Stade
2016/03/21 21:59:02
I kinda liked the idea of skipping ahead to the ne
kolos1
2016/03/22 19:10:24
I asked UI team about this. They recommend to show
| |
187 } | |
188 }, | |
189 | |
190 /** | |
168 * Updates the data model for the saved passwords list with the values from | 191 * Updates the data model for the saved passwords list with the values from |
169 * |entries|. | 192 * |entries|. |
170 * @param {!Array} entries The list of saved password data. | 193 * @param {!Array} entries The list of saved password data. |
171 */ | 194 */ |
172 setSavedPasswordsList_: function(entries) { | 195 setSavedPasswordsList_: function(entries) { |
173 if (this.lastQuery_) { | 196 if (this.lastQuery_) { |
174 // Implement password searching here in javascript, rather than in C++. | 197 // Implement password searching here in javascript, rather than in C++. |
175 // The number of saved passwords shouldn't be too big for us to handle. | 198 // The number of saved passwords shouldn't be too big for us to handle. |
176 var query = this.lastQuery_; | 199 var query = this.lastQuery_; |
177 var filter = function(entry, index, list) { | 200 var filter = function(entry, index, list) { |
178 // Search both shown URL and username. | 201 // Search both shown URL and username. |
179 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; | 202 var shownUrl = entry[options.passwordManager.SHOWN_URL_FIELD]; |
180 var username = entry[options.passwordManager.USERNAME_FIELD]; | 203 var username = entry[options.passwordManager.USERNAME_FIELD]; |
181 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 204 if (shownUrl.toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
182 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 205 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
183 // Keep the original index so we can delete correctly. See also | 206 // Keep the original index so we can delete correctly. See also |
184 // deleteItemAtIndex() in password_manager_list.js that uses this. | 207 // deleteItemAtIndex() in password_manager_list.js that uses this. |
185 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; | 208 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; |
186 return true; | 209 return true; |
187 } | 210 } |
188 return false; | 211 return false; |
189 }; | 212 }; |
190 entries = entries.filter(filter); | 213 entries = entries.filter(filter); |
191 } | 214 } |
192 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 215 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
216 this.updateOriginsEliding_(this.savedPasswordsList_); | |
193 this.updateListVisibility_(this.savedPasswordsList_); | 217 this.updateListVisibility_(this.savedPasswordsList_); |
194 }, | 218 }, |
195 | 219 |
196 /** | 220 /** |
197 * Updates the data model for the password exceptions list with the values | 221 * Updates the data model for the password exceptions list with the values |
198 * from |entries|. | 222 * from |entries|. |
199 * @param {!Array} entries The list of password exception data. | 223 * @param {!Array} entries The list of password exception data. |
200 */ | 224 */ |
201 setPasswordExceptionsList_: function(entries) { | 225 setPasswordExceptionsList_: function(entries) { |
202 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 226 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); |
227 this.updateOriginsEliding_(this.passwordExceptionsList_); | |
203 this.updateListVisibility_(this.passwordExceptionsList_); | 228 this.updateListVisibility_(this.passwordExceptionsList_); |
204 }, | 229 }, |
205 | 230 |
206 /** | 231 /** |
207 * Reveals the password for a saved password entry. This is called by the | 232 * Reveals the password for a saved password entry. This is called by the |
208 * backend after it has authenticated the user. | 233 * backend after it has authenticated the user. |
209 * @param {number} index The original index of the entry in the model. | 234 * @param {number} index The original index of the entry in the model. |
210 * @param {string} password The saved password. | 235 * @param {string} password The saved password. |
211 */ | 236 */ |
212 showPassword_: function(index, password) { | 237 showPassword_: function(index, password) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 'setPasswordExceptionsList', | 283 'setPasswordExceptionsList', |
259 'showPassword' | 284 'showPassword' |
260 ]); | 285 ]); |
261 | 286 |
262 // Export | 287 // Export |
263 return { | 288 return { |
264 PasswordManager: PasswordManager | 289 PasswordManager: PasswordManager |
265 }; | 290 }; |
266 | 291 |
267 }); | 292 }); |
OLD | NEW |