Chromium Code Reviews| 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('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 Loading... | |
| 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. | |
|
dpapad
2017/05/23 18:57:30
Out of curiosity, does crbug.com/723579 happen for
tkent
2017/05/24 01:37:17
:focus-within means just "contains a :focus elemen
| |
| 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 if (listEl.lastChild != itemEl) |
|
dpapad
2017/05/23 18:57:30
Did you mean to remove this in patch#2?
tkent
2017/05/24 01:37:17
Oops. Removed.
| |
| 344 listEl.appendChild(itemEl); | |
| 340 // Restore focus. | 345 // Restore focus. |
| 341 if (focusedEl) { | 346 if (focusedEl) { |
| 342 if (focusedEl == itemEl || focusedEl == focusedInnerEl) | 347 if (focusedEl == itemEl || focusedEl == focusedInnerEl) |
| 343 focusedEl.focus(); | 348 focusedEl.focus(); |
| 344 itemEl.classList.remove('moving'); | 349 itemEl.classList.remove('moving'); |
| 345 } | 350 } |
| 346 }, | 351 }, |
| 347 | 352 |
| 348 /** | 353 /** |
| 349 * @param {Element} listEl List element. | 354 * @param {Element} listEl List element. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 367 cr.dispatchSimpleEvent(this, | 372 cr.dispatchSimpleEvent(this, |
| 368 DestinationList.EventType.ACTION_LINK_ACTIVATED); | 373 DestinationList.EventType.ACTION_LINK_ACTIVATED); |
| 369 } | 374 } |
| 370 }; | 375 }; |
| 371 | 376 |
| 372 // Export | 377 // Export |
| 373 return { | 378 return { |
| 374 DestinationList: DestinationList | 379 DestinationList: DestinationList |
| 375 }; | 380 }; |
| 376 }); | 381 }); |
| OLD | NEW |