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

Side by Side Diff: chrome/browser/resources/print_preview/search/destination_list.js

Issue 2896463004: Print Preview: Mac: Do not blur focused item while opening the hamburger menu. (Closed)
Patch Set: Actually remove a hack for appendChild() Created 3 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 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Component that displays a list of destinations with a heading, action link, 9 * Component that displays a list of destinations with a heading, action link,
10 * and "Show All..." button. An event is dispatched when the action link is 10 * and "Show All..." button. An event is dispatched when the action link is
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 visibleListItems[destinations[i].id] = null; 299 visibleListItems[destinations[i].id] = null;
300 // Update visibility for all existing list items. 300 // Update visibility for all existing list items.
301 this.listItems_.forEach(function(item) { 301 this.listItems_.forEach(function(item) {
302 var isVisible = visibleListItems.hasOwnProperty(item.destination.id); 302 var isVisible = visibleListItems.hasOwnProperty(item.destination.id);
303 setIsVisible(item.getElement(), isVisible); 303 setIsVisible(item.getElement(), isVisible);
304 if (isVisible) 304 if (isVisible)
305 visibleListItems[item.destination.id] = item; 305 visibleListItems[item.destination.id] = item;
306 }); 306 });
307 // Update the existing items, add the new ones (preserve the focused one). 307 // Update the existing items, add the new ones (preserve the focused one).
308 var listEl = this.getChildElement('.destination-list > ul'); 308 var listEl = this.getChildElement('.destination-list > ul');
309 var focusedEl = listEl.querySelector(':focus'); 309 // We need to use activeElement instead of :focus selector, which doesn't
310 // work in an inactive page. See crbug.com/723579.
311 var focusedEl = listEl.contains(document.activeElement) ?
312 document.activeElement : null;
310 for (var i = 0; i < numItems; i++) { 313 for (var i = 0; i < numItems; i++) {
311 var destination = assert(destinations[i]); 314 var destination = assert(destinations[i]);
312 var listItem = visibleListItems[destination.id]; 315 var listItem = visibleListItems[destination.id];
313 if (listItem) { 316 if (listItem) {
314 // Destination ID is the same, but it can be registered to a different 317 // Destination ID is the same, but it can be registered to a different
315 // user account, hence passing it to the item update. 318 // user account, hence passing it to the item update.
316 this.updateListItem_(listEl, listItem, focusedEl, destination); 319 this.updateListItem_(listEl, listItem, focusedEl, destination);
317 } else { 320 } else {
318 this.renderListItem_(listEl, destination); 321 this.renderListItem_(listEl, destination);
319 } 322 }
320 } 323 }
321 }, 324 },
322 325
323 /** 326 /**
324 * @param {Element} listEl List element. 327 * @param {Element} listEl List element.
325 * @param {!print_preview.DestinationListItem} listItem List item to update. 328 * @param {!print_preview.DestinationListItem} listItem List item to update.
326 * @param {Element} focusedEl Currently focused element within the listEl. 329 * @param {Element} focusedEl Currently focused element within the listEl.
327 * @param {!print_preview.Destination} destination Destination to render. 330 * @param {!print_preview.Destination} destination Destination to render.
328 * @private 331 * @private
329 */ 332 */
330 updateListItem_: function(listEl, listItem, focusedEl, destination) { 333 updateListItem_: function(listEl, listItem, focusedEl, destination) {
331 listItem.update(destination, this.query_); 334 listItem.update(destination, this.query_);
332 335
333 var itemEl = listItem.getElement(); 336 var itemEl = listItem.getElement();
334 // Preserve focused inner element, if there's one. 337 // Preserve focused inner element, if there's one.
335 var focusedInnerEl = focusedEl ? itemEl.querySelector(':focus') : null; 338 var focusedInnerEl = focusedEl && itemEl.contains(focusedEl) ?
339 focusedEl : null;
336 if (focusedEl) 340 if (focusedEl)
337 itemEl.classList.add('moving'); 341 itemEl.classList.add('moving');
338 // Move it to the end of the list. 342 // Move it to the end of the list.
339 listEl.appendChild(itemEl); 343 listEl.appendChild(itemEl);
340 // Restore focus. 344 // Restore focus.
341 if (focusedEl) { 345 if (focusedEl) {
342 if (focusedEl == itemEl || focusedEl == focusedInnerEl) 346 if (focusedEl == itemEl || focusedEl == focusedInnerEl)
343 focusedEl.focus(); 347 focusedEl.focus();
344 itemEl.classList.remove('moving'); 348 itemEl.classList.remove('moving');
345 } 349 }
(...skipping 21 matching lines...) Expand all
367 cr.dispatchSimpleEvent(this, 371 cr.dispatchSimpleEvent(this,
368 DestinationList.EventType.ACTION_LINK_ACTIVATED); 372 DestinationList.EventType.ACTION_LINK_ACTIVATED);
369 } 373 }
370 }; 374 };
371 375
372 // Export 376 // Export
373 return { 377 return {
374 DestinationList: DestinationList 378 DestinationList: DestinationList
375 }; 379 };
376 }); 380 });
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