Commit f5307871 authored by Gavin Williams's avatar Gavin Williams Committed by Chromium LUCI CQ

scanning: a11y: Add ARIA labels for preview area

This change adds an ARIA label for the preview area that is updated
depending on the current page:
 -In the initial state, grab the scan preview instructions from the page
 -While scanning, update the label when the page number increases
 -When the scan is completed successfully, announce scan is completed
  and the total number of pages scanned.

Bug: 1059779
Change-Id: I1fcdf2552f779737a69d95fe5971c1b98c0a6aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580846
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835882}
parent 672fbcf4
...@@ -600,6 +600,11 @@ Try tapping the mic to ask me anything. ...@@ -600,6 +600,11 @@ Try tapping the mic to ask me anything.
<message name="IDS_SCANNING_APP_OK_BUTTON_LABEL" desc="The label for the button to acknowledge and close the dialog shown when a scan job fails."> <message name="IDS_SCANNING_APP_OK_BUTTON_LABEL" desc="The label for the button to acknowledge and close the dialog shown when a scan job fails.">
Ok Ok
</message> </message>
<message name="IDS_SCANNING_APP_SCANNED_IMAGES_ARIA_LABEL" is_accessibility_with_no_ui="true" desc="The text read by the screen reader to announce a scan job is completed and the total number of pages scanned.">
{NUMBER_OF_PAGES, plural,
=1 {Scanning completed. 1 page scanned}
other {Scanning completed. {NUMBER_OF_PAGES} pages scanned}}
</message>
<!-- Diagnostics App --> <!-- Diagnostics App -->
<message name="IDS_DIAGNOSTICS_TITLE" desc="The title of the diagnostics app."> <message name="IDS_DIAGNOSTICS_TITLE" desc="The title of the diagnostics app.">
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
} }
</style> </style>
<iron-icon id="checkMarkIcon" icon="scanning:check-mark"></iron-icon> <iron-icon id="checkMarkIcon" icon="scanning:check-mark"></iron-icon>
<h1 id="title" role="alert"> <h1 id="title">
[[titleText_]] [[titleText_]]
</h1> </h1>
<div class="container"> <div class="container">
......
...@@ -44,8 +44,8 @@ Polymer({ ...@@ -44,8 +44,8 @@ Polymer({
/** @override */ /** @override */
created() { created() {
// ScanningBrowserProxy is initialized when scanning_app.js is created.
this.browserProxy_ = ScanningBrowserProxyImpl.getInstance(); this.browserProxy_ = ScanningBrowserProxyImpl.getInstance();
this.browserProxy_.initialize();
}, },
/** @private */ /** @private */
......
...@@ -75,14 +75,14 @@ ...@@ -75,14 +75,14 @@
--paper-progress-container-color: var(--google-grey-200); --paper-progress-container-color: var(--google-grey-200);
} }
</style> </style>
<div class="preview"> <div class="preview" aria-label="[[previewAriaLabel_]]">
<div id="helpOrProgress" class="preview-item" <div id="helpOrProgress" class="preview-item" hidden$="[[showScannedImages_]]"
hidden$="[[showScannedImages_]]"> aria-hidden="true">
<div id="helperText" hidden$="[[!showHelperText_]]"> <div id="helperText" hidden$="[[!showHelperText_]]">
<span inner-h-t-m-l="[[getHelperTextHtml_()]]"></span> <span inner-h-t-m-l="[[getHelperTextHtml_()]]"></span>
</div> </div>
<div id="scanProgress" hidden$="[[!showScanProgress_]]"> <div id="scanProgress" hidden$="[[!showScanProgress_]]">
<span id="progressText">[[getProgressTextString_(pageNumber)]]</span> <span id="progressText">[[progressTextString_]]</span>
<paper-progress id="scanProgressBar" value="[[progressPercent]]"> <paper-progress id="scanProgressBar" value="[[progressPercent]]">
</paper-progress> </paper-progress>
</div> </div>
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
<paper-progress id="cancelingProgressBar" indeterminate></paper-progress> <paper-progress id="cancelingProgressBar" indeterminate></paper-progress>
</div> </div>
</div> </div>
<div id="scannedImages" hidden$="[[!showScannedImages_]]"> <div id="scannedImages" hidden$="[[!showScannedImages_]]" aria-hidden="true">
<template is="dom-repeat" items="[[objectUrls]]" as="url"> <template is="dom-repeat" items="[[objectUrls]]" as="url">
<img class="preview-item scanned-image" src="[[url]]"> <img class="preview-item scanned-image" src="[[url]]">
</template> </template>
......
...@@ -7,10 +7,10 @@ import './scanning_shared_css.js'; ...@@ -7,10 +7,10 @@ import './scanning_shared_css.js';
import 'chrome://resources/polymer/v3_0/paper-progress/paper-progress.js'; import 'chrome://resources/polymer/v3_0/paper-progress/paper-progress.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js'; import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {afterNextRender, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {AppState} from './scanning_app_types.js'; import {AppState} from './scanning_app_types.js';
import {ScanningBrowserProxy, ScanningBrowserProxyImpl} from './scanning_browser_proxy.js';
/** /**
* @fileoverview * @fileoverview
...@@ -23,6 +23,9 @@ Polymer({ ...@@ -23,6 +23,9 @@ Polymer({
behaviors: [I18nBehavior], behaviors: [I18nBehavior],
/** @private {?ScanningBrowserProxy}*/
browserProxy_: null,
properties: { properties: {
/** @type {!AppState} */ /** @type {!AppState} */
appState: { appState: {
...@@ -37,7 +40,10 @@ Polymer({ ...@@ -37,7 +40,10 @@ Polymer({
objectUrls: Array, objectUrls: Array,
/** @type {number} */ /** @type {number} */
pageNumber: Number, pageNumber: {
type: Number,
observer: 'onPageNumberChange_',
},
/** @type {number} */ /** @type {number} */
progressPercent: Number, progressPercent: Number,
...@@ -65,6 +71,23 @@ Polymer({ ...@@ -65,6 +71,23 @@ Polymer({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
/** @type {string} */
progressTextString_: String,
/** @type {string} */
previewAriaLabel_: String,
},
observers: [
'setPreviewAriaLabel_(showScannedImages_, showScanProgress_,' +
' showCancelingProgress_, showHelperText_, progressTextString_)',
],
/** @override */
created() {
// ScanningBrowserProxy is initialized when scanning_app.js is created.
this.browserProxy_ = ScanningBrowserProxyImpl.getInstance();
}, },
/** /**
...@@ -77,15 +100,6 @@ Polymer({ ...@@ -77,15 +100,6 @@ Polymer({
return this.i18nAdvanced('scanPreviewHelperText', {attrs: ['id']}); return this.i18nAdvanced('scanPreviewHelperText', {attrs: ['id']});
}, },
/**
* @return {string}
* @private
*/
getProgressTextString_() {
return loadTimeData.getStringF(
'scanPreviewProgressText', this.pageNumber.toString());
},
/** @private */ /** @private */
onAppStateChange_() { onAppStateChange_() {
this.showScannedImages_ = this.showScannedImages_ =
...@@ -96,4 +110,48 @@ Polymer({ ...@@ -96,4 +110,48 @@ Polymer({
this.showHelperText_ = this.showHelperText_ =
!this.showScanProgress_ && !this.showCancelingProgress_; !this.showScanProgress_ && !this.showCancelingProgress_;
}, },
/** @private */
onPageNumberChange_() {
this.progressTextString_ =
this.i18n('scanPreviewProgressText', this.pageNumber);
},
/**
* Sets the ARIA label used by the preview area based on the app state and the
* current page showing. In the initial state, use the scan preview
* instructions from the page as the label. While scanning, update the label
* each time the page number increases. When the scan completes, announce the
* total number of pages scanned.
* @private
*/
setPreviewAriaLabel_() {
if (this.showScannedImages_) {
this.browserProxy_
.getPluralString('scannedImagesAriaLabel', this.objectUrls.length)
.then(
/* @type {string} */ (pluralString) => this.previewAriaLabel_ =
pluralString);
return;
}
if (this.showScanProgress_) {
this.previewAriaLabel_ = this.progressTextString_;
return;
}
if (this.showCancelingProgress_) {
this.previewAriaLabel_ = this.i18n('cancelingScanningText');
return;
}
if (this.showHelperText_) {
// We can't directly use the 'scanPreviewHelperText' string because it
// conatains HTML. So instead wait for the page to render then use its
// text as the ARIA label.
afterNextRender(this, () => {
this.previewAriaLabel_ = this.$.helperText.innerText;
});
}
},
}); });
...@@ -32,6 +32,7 @@ import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bun ...@@ -32,6 +32,7 @@ import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bun
import {getScanService} from './mojo_interface_provider.js'; import {getScanService} from './mojo_interface_provider.js';
import {AppState, ScannerArr} from './scanning_app_types.js'; import {AppState, ScannerArr} from './scanning_app_types.js';
import {colorModeFromString, fileTypeFromString, pageSizeFromString, tokenToString} from './scanning_app_util.js'; import {colorModeFromString, fileTypeFromString, pageSizeFromString, tokenToString} from './scanning_app_util.js';
import {ScanningBrowserProxyImpl} from './scanning_browser_proxy.js';
/** /**
* The default save directory for completed scans. * The default save directory for completed scans.
...@@ -211,6 +212,8 @@ Polymer({ ...@@ -211,6 +212,8 @@ Polymer({
created() { created() {
this.scanService_ = getScanService(); this.scanService_ = getScanService();
this.selectedFilePath = DEFAULT_SAVE_DIRECTORY; this.selectedFilePath = DEFAULT_SAVE_DIRECTORY;
ScanningBrowserProxyImpl.getInstance().initialize();
}, },
/** @override */ /** @override */
......
...@@ -109,7 +109,8 @@ void AddScanningAppStrings(content::WebUIDataSource* html_source) { ...@@ -109,7 +109,8 @@ void AddScanningAppStrings(content::WebUIDataSource* html_source) {
void AddScanningAppPluralStrings(ScanningHandler* handler) { void AddScanningAppPluralStrings(ScanningHandler* handler) {
static constexpr webui::LocalizedString kLocalizedStrings[] = { static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"fileSavedText", IDS_SCANNING_APP_FILE_SAVED_TEXT}}; {"fileSavedText", IDS_SCANNING_APP_FILE_SAVED_TEXT},
{"scannedImagesAriaLabel", IDS_SCANNING_APP_SCANNED_IMAGES_ARIA_LABEL}};
for (const auto& str : kLocalizedStrings) for (const auto& str : kLocalizedStrings)
handler->AddStringToPluralMap(str.name, str.id); handler->AddStringToPluralMap(str.name, str.id);
......
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