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

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

Issue 2468973003: Improve updateOriginsEliding_ performance. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 */ 177 */
178 updateOriginsEliding_: function(list) { 178 updateOriginsEliding_: function(list) {
179 var entries = list.getElementsByClassName('deletable-item'); 179 var entries = list.getElementsByClassName('deletable-item');
180 if (entries.length == 0) 180 if (entries.length == 0)
181 return; 181 return;
182 var entry = entries[0]; 182 var entry = entries[0];
183 var computedStyle = window.getComputedStyle(entry.urlDiv); 183 var computedStyle = window.getComputedStyle(entry.urlDiv);
184 var columnWidth = entry.urlDiv.offsetWidth - 184 var columnWidth = entry.urlDiv.offsetWidth -
185 parseInt(computedStyle.webkitMarginStart, 10) - 185 parseInt(computedStyle.webkitMarginStart, 10) -
186 parseInt(computedStyle.webkitPaddingStart, 10); 186 parseInt(computedStyle.webkitPaddingStart, 10);
187
188 // We use a canvas context to compute text widths. This canvas is not
189 // part of the DOM and thus avoids layout thrashing when updating the
190 // contained text.
191 var canvas = document.createElement('canvas');
192 var ctx = canvas.getContext('2d');
193 ctx.font = computedStyle.font;
194
187 for (var i = 0; i < entries.length; ++i) { 195 for (var i = 0; i < entries.length; ++i) {
188 entry = entries[i]; 196 entry = entries[i];
189 // For android://com.example, elide from the right. 197 // For android://com.example, elide from the right.
190 if (!entry.isClickable) 198 if (!entry.isClickable)
191 continue; 199 continue;
192 var cellWidth = columnWidth; 200 var cellWidth = columnWidth;
193 if (entry.androidUriSuffix) 201 if (entry.androidUriSuffix)
194 cellWidth -= entry.androidUriSuffix.offsetWidth; 202 cellWidth -= entry.androidUriSuffix.offsetWidth;
195 var urlLink = entry.urlLink; 203 var urlLink = entry.urlLink;
196 if (cellWidth <= 0) { 204 if (cellWidth <= 0) {
197 console.error('cellWidth <= 0. Skip origins eliding for ' + 205 console.error('cellWidth <= 0. Skip origins eliding for ' +
198 urlLink.textContent); 206 urlLink.textContent);
199 continue; 207 continue;
200 } 208 }
201 if (urlLink.offsetWidth <= cellWidth) 209
210 var textContent = urlLink.textContent;
211 if (ctx.measureText(textContent).width <= cellWidth)
202 continue; 212 continue;
203 urlLink.textContent = '…' + urlLink.textContent.substring(1); 213
204 while (urlLink.offsetWidth > cellWidth) 214 textContent = '…' + textContent.substring(1);
205 urlLink.textContent = '…' + urlLink.textContent.substring(2); 215 while (ctx.measureText(textContent).width > cellWidth)
216 textContent = '…' + textContent.substring(2);
217
218 // Write the elided origin back to the DOM.
219 urlLink.textContent = textContent;
206 } 220 }
207 }, 221 },
208 222
209 /** 223 /**
210 * Updates the data model for the saved passwords list with the values from 224 * Updates the data model for the saved passwords list with the values from
211 * |entries|. 225 * |entries|.
212 * @param {!Array} entries The list of saved password data. 226 * @param {!Array} entries The list of saved password data.
213 */ 227 */
214 setSavedPasswordsList_: function(entries) { 228 setSavedPasswordsList_: function(entries) {
215 if (this.lastQuery_) { 229 if (this.lastQuery_) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 'showImportExportButton', 334 'showImportExportButton',
321 'showPassword', 335 'showPassword',
322 ]); 336 ]);
323 337
324 // Export 338 // Export
325 return { 339 return {
326 PasswordManager: PasswordManager 340 PasswordManager: PasswordManager
327 }; 341 };
328 342
329 }); 343 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698