Commit 4f4586fd authored by Michael Checo's avatar Michael Checo Committed by Commit Bot

Printer settings: Make saved/nearby printers use FocusRowBehavior

Description:
 This change allows users to tab to the first printer in the saved
 and nearby printer lists and use the arrow keys to navigate the
 remaining printers. Users can also use the arrow keys to navigate
 through a printer entry's associated buttons/icons. Lastly, the
 printer entry row will be highlighted (blue background) if it is
 being focused.

Screenshots:
 - http://shortn/_Fqf1Nn9qjF nearby printers
 - http://shortn/_BSspETkjzV saved printers

Bug: 987422
Test: gtest_filter=OSSettingsCupsPrinterLandingPageV3Test.All
Change-Id: I68fc5fc3ff2ceec88ce81f95da5b451a6ad3beb1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399601Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Commit-Queue: Michael Checo <michaelcheco@google.com>
Cr-Commit-Position: refs/heads/master@{#809354}
parent ee4cfc5d
...@@ -131,6 +131,7 @@ js_library("cups_printers_entry") { ...@@ -131,6 +131,7 @@ js_library("cups_printers_entry") {
deps = [ deps = [
":cups_printer_types", ":cups_printer_types",
":cups_printers_browser_proxy", ":cups_printers_browser_proxy",
"//ui/webui/resources/js/cr/ui:focus_row_behavior",
] ]
} }
...@@ -311,7 +312,10 @@ js_library("cups_printers_browser_proxy.m") { ...@@ -311,7 +312,10 @@ js_library("cups_printers_browser_proxy.m") {
js_library("cups_printers_entry.m") { js_library("cups_printers_entry.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_printers_entry.m.js" ] sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_printers_entry.m.js" ]
deps = [ ":cups_printer_types.m" ] deps = [
":cups_printer_types.m",
"//ui/webui/resources/js/cr/ui:focus_row_behavior.m",
]
extra_deps = [ ":cups_printers_entry_module" ] extra_deps = [ ":cups_printers_entry_module" ]
} }
......
...@@ -28,7 +28,10 @@ ...@@ -28,7 +28,10 @@
<iron-list class="list-frame vertical-list flex-auto" id="printerEntryList" <iron-list class="list-frame vertical-list flex-auto" id="printerEntryList"
items="[[filteredPrinters_]]"> items="[[filteredPrinters_]]">
<template> <template>
<settings-cups-printers-entry printer-entry="[[item]]"> <settings-cups-printers-entry printer-entry="[[item]]"
tabindex$="[[tabIndex]]" last-focused="{{lastFocused_}}"
list-blurred="{{listBlurred_}}" focus-row-index="[[index]]"
iron-list-tab-index="[[tabIndex]]">
</settings-cups-printers-entry> </settings-cups-printers-entry>
</template> </template>
</iron-list> </iron-list>
......
...@@ -56,6 +56,18 @@ Polymer({ ...@@ -56,6 +56,18 @@ Polymer({
type: Array, type: Array,
value: () => [], value: () => [],
}, },
/**
* Used by FocusRowBehavior to track the last focused element on a row.
* @private
*/
lastFocused_: Object,
/**
* Used by FocusRowBehavior to track if the list has been blurred.
* @private
*/
listBlurred_: Boolean,
}, },
listeners: { listeners: {
......
...@@ -5,53 +5,74 @@ ...@@ -5,53 +5,74 @@
<link rel="import" href="cups_printers_browser_proxy.html"> <link rel="import" href="cups_printers_browser_proxy.html">
<link rel="import" href="../../settings_shared_css.html"> <link rel="import" href="../../settings_shared_css.html">
<link rel="import" href="chrome://resources/html/load_time_data.html"> <link rel="import" href="chrome://resources/html/load_time_data.html">
<link rel="import" href="chrome://resources/html/cr/ui/focus_row_behavior.html">
<dom-module id="settings-cups-printers-entry"> <dom-module id="settings-cups-printers-entry">
<template> <template>
<style include="settings-shared"> <style include="settings-shared">
.icon-more-vert {
background-color: none;
}
.printer-name { .printer-name {
flex: 1; flex: 1;
} }
.list-item:focus-within {
background-color: var(--google-blue-50);
outline: none;
}
</style> </style>
<div id="entry" class="list-item" focus-row-container> <div focus-row-container>
<div class="printer-name text-elide"> <div id="entry" class="list-item" focus-row-control focus-type="entry">
<span id="printerName" aria-hidden="true"> <div class="printer-name text-elide">
[[printerEntry.printerInfo.printerName]] <span id="printerName" aria-hidden="true">
</span> [[printerEntry.printerInfo.printerName]]
<div id="printerSubtext" hidden="[[!subtext]]" class="secondary" </span>
aria-hidden="true"> <div id="printerSubtext" hidden="[[!subtext]]" class="secondary"
[[subtext]] aria-hidden="true">
[[subtext]]
</div>
</div> </div>
<template is="dom-if"
if="[[isSavedPrinter_(printerEntry.printerType)]]">
<cr-icon-button id="moreActions" class="icon-more-vert"
on-click="onOpenActionMenuTap_" title="$i18n{moreActions}"
aria-labelledby="printerName" focus-row-control
focus-type="moreActions" tabindex$="[[tabindex]]">
</cr-icon-button>
</template>
<template is="dom-if"
if="[[isDiscoveredPrinter_(printerEntry.printerType)]]">
<cr-button id="setupPrinterButton"
on-click="onAddDiscoveredPrinterTap_"
aria-label$="[[getSetupButtonAria_()]]"
focus-row-control
focus-type="setupPrinterButton">
$i18n{setupPrinter}
</cr-button>
</template>
<template is="dom-if"
if="[[isAutomaticPrinter_(printerEntry.printerType)]]">
<cr-button id="automaticPrinterButton" class="save-printer-button"
on-click="onAddAutomaticPrinterTap_"
aria-label$="[[getSaveButtonAria_()]]"
focus-row-control
focus-type="automaticPrinterButton">
$i18n{savePrinter}
</cr-button>
</template>
<template is="dom-if"
if="[[isPrintServerPrinter_(printerEntry.printerType)]]">
<cr-button id="savePrinterButton"
class="save-printer-button" on-click="onAddServerPrinterTap_"
aria-label$="[[getSaveButtonAria_()]]"
focus-row-control
focus-type="savePrinterButton">
$i18n{savePrinter}
</cr-button>
</template>
</div> </div>
<template is="dom-if" if="[[isSavedPrinter_(printerEntry.printerType)]]">
<cr-icon-button id="moreActions" class="icon-more-vert"
on-click="onOpenActionMenuTap_" title="$i18n{moreActions}"
aria-labelledby="printerName">
</cr-icon-button>
</template>
<template is="dom-if"
if="[[isDiscoveredPrinter_(printerEntry.printerType)]]">
<cr-button id="setupPrinterButton"
on-click="onAddDiscoveredPrinterTap_"
aria-label$="[[getSetupButtonAria_()]]">
$i18n{setupPrinter}
</cr-button>
</template>
<template is="dom-if"
if="[[isAutomaticPrinter_(printerEntry.printerType)]]">
<cr-button class="save-printer-button"
on-click="onAddAutomaticPrinterTap_"
aria-label$="[[getSaveButtonAria_()]]">
$i18n{savePrinter}
</cr-button>
</template>
<template is="dom-if"
if="[[isPrintServerPrinter_(printerEntry.printerType)]]">
<cr-button class="save-printer-button" on-click="onAddServerPrinterTap_"
aria-label$="[[getSaveButtonAria_()]]">
$i18n{savePrinter}
</cr-button>
</template>
</div> </div>
</template> </template>
<script src="cups_printers_entry.js"></script> <script src="cups_printers_entry.js"></script>
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
Polymer({ Polymer({
is: 'settings-cups-printers-entry', is: 'settings-cups-printers-entry',
behaviors: [
cr.ui.FocusRowBehavior,
],
properties: { properties: {
/** @type {!PrinterListEntry} */ /** @type {!PrinterListEntry} */
printerEntry: Object, printerEntry: Object,
......
...@@ -63,7 +63,10 @@ ...@@ -63,7 +63,10 @@
<iron-list class="list-frame vertical-list flex-auto" id="printerEntryList" <iron-list class="list-frame vertical-list flex-auto" id="printerEntryList"
items="[[filteredPrinters_]]"> items="[[filteredPrinters_]]">
<template> <template>
<settings-cups-printers-entry printer-entry="[[item]]"> <settings-cups-printers-entry printer-entry="[[item]]"
tabindex$="[[tabIndex]]" last-focused="{{lastFocused_}}"
list-blurred="{{listBlurred_}}" focus-row-index="[[index]]"
iron-list-tab-index="[[tabIndex]]">
</settings-cups-printers-entry> </settings-cups-printers-entry>
</template> </template>
</iron-list> </iron-list>
......
...@@ -96,6 +96,18 @@ Polymer({ ...@@ -96,6 +96,18 @@ Polymer({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
/**
* Used by FocusRowBehavior to track the last focused element on a row.
* @private
*/
lastFocused_: Object,
/**
* Used by FocusRowBehavior to track if the list has been blurred.
* @private
*/
listBlurred_: Boolean,
}, },
listeners: { listeners: {
......
...@@ -18,6 +18,12 @@ ...@@ -18,6 +18,12 @@
// #import {waitAfterNextRender} from 'chrome://test/test_util.m.js'; // #import {waitAfterNextRender} from 'chrome://test/test_util.m.js';
// clang-format on // clang-format on
const arrowUpEvent = new KeyboardEvent(
'keydown', {cancelable: true, key: 'ArrowUp', keyCode: 38});
const arrowDownEvent = new KeyboardEvent(
'keydown', {cancelable: true, key: 'ArrowDown', keyCode: 40});
/** /**
* @param {!HTMLElement} printerEntry * @param {!HTMLElement} printerEntry
* @private * @private
...@@ -615,6 +621,37 @@ suite('CupsSavedPrintersTests', function() { ...@@ -615,6 +621,37 @@ suite('CupsSavedPrintersTests', function() {
}); });
}); });
test('NavigateSavedPrintersList', function() {
createCupsPrinterPage([
cups_printer_test_util.createCupsPrinterInfo('google', '4', 'id4'),
cups_printer_test_util.createCupsPrinterInfo('test1', '1', 'id1'),
cups_printer_test_util.createCupsPrinterInfo('test2', '2', 'id2'),
]);
return cupsPrintersBrowserProxy.whenCalled('getCupsPrintersList')
.then(async () => {
// Wait for saved printers to populate.
Polymer.dom.flush();
savedPrintersElement = page.$$('settings-cups-saved-printers');
assertTrue(!!savedPrintersElement);
const printerEntryList = savedPrintersElement.$$('#printerEntryList');
const printerListEntries =
cups_printer_test_util.getPrinterEntries(savedPrintersElement);
printerEntryList.focus();
printerEntryList.dispatchEvent(arrowDownEvent);
Polymer.dom.flush();
assertEquals(printerListEntries[1], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowDownEvent);
Polymer.dom.flush();
assertEquals(printerListEntries[2], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowUpEvent);
Polymer.dom.flush();
assertEquals(printerListEntries[1], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowUpEvent);
Polymer.dom.flush();
assertEquals(printerListEntries[0], getDeepActiveElement());
});
});
test('Deep link to saved printers', async () => { test('Deep link to saved printers', async () => {
loadTimeData.overrideValues({ loadTimeData.overrideValues({
isDeepLinkingEnabled: true, isDeepLinkingEnabled: true,
...@@ -1201,6 +1238,38 @@ suite('CupsNearbyPrintersTests', function() { ...@@ -1201,6 +1238,38 @@ suite('CupsNearbyPrintersTests', function() {
}); });
}); });
test('NavigateNearbyPrinterList', function() {
const discoveredPrinterList = [
cups_printer_test_util.createCupsPrinterInfo('test3', '3', 'id3'),
cups_printer_test_util.createCupsPrinterInfo('test4', '4', 'id4'),
cups_printer_test_util.createCupsPrinterInfo('test2', '2', 'id5'),
];
return test_util.flushTasks().then(() => {
nearbyPrintersElement = page.$$('settings-cups-nearby-printers');
assertTrue(!!nearbyPrintersElement);
// Simuluate finding nearby printers.
cr.webUIListenerCallback(
'on-nearby-printers-changed', [], discoveredPrinterList);
Polymer.dom.flush();
const nearbyPrinterEntries =
cups_printer_test_util.getPrinterEntries(nearbyPrintersElement);
const printerEntryList = nearbyPrintersElement.$$('#printerEntryList');
printerEntryList.focus();
printerEntryList.dispatchEvent(arrowDownEvent);
Polymer.dom.flush();
assertEquals(nearbyPrinterEntries[1], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowDownEvent);
Polymer.dom.flush();
assertEquals(nearbyPrinterEntries[2], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowUpEvent);
Polymer.dom.flush();
assertEquals(nearbyPrinterEntries[1], getDeepActiveElement());
printerEntryList.dispatchEvent(arrowUpEvent);
Polymer.dom.flush();
assertEquals(nearbyPrinterEntries[0], getDeepActiveElement());
});
});
test('addingDiscoveredPrinterIsSuccessful', function() { test('addingDiscoveredPrinterIsSuccessful', function() {
const automaticPrinterList = []; const automaticPrinterList = [];
const discoveredPrinterList = const discoveredPrinterList =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment