Commit f02f6d09 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Added A11y announcements for New Download Manager.

The strings has not beed finalized yet, and will be updated in a
separate CL.

Bug: 821188
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I28e4883e84ec07e003c6a799d7a060640ee41038
Reviewed-on: https://chromium-review.googlesource.com/959589
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542802}
parent cfeb51ad
......@@ -618,6 +618,15 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_DOWNLOAD_MANAGER_UNABLE_TO_OPEN_FILE" desc="Title of dialog displayed when the user attempts to open a downloaded file and no app on the device can open the file. [Length: 25em] [iOS only]">
Unable to Open File
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_FAILED_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibility announcement read by Voice Over when the download has failed. [Length: unlimited] [iOS only]">
Download failed
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_SUCCEEDED_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibility announcement read by Voice Over when the download has sucessfully finished. [Length: unlimited] [iOS only]">
Download successfully finished
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_REQUESTED_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibility announcement read by Voice Over when the Download Manager UI is shown to the user. [Length: unlimited] [iOS only]">
File download is available
</message>
<message name="IDS_IOS_DOWNLOAD_MANAGER_UPLOAD_TO_GOOGLE_DRIVE" desc="Button for uploading a downloaded file to Google Drive. It's displayed on the dialog presented when no app on the device can open the file. [Length: 25em] [iOS only]">
Upload to Google Drive
</message>
......
......@@ -60,6 +60,10 @@ class DownloadManagerMediator : public web::DownloadTaskObserver {
// Converts DownloadTask progress [0;100] to float progress [0.0f;1.0f].
float GetDownloadManagerProgress() const;
// Returns accessibility announcement for download state change. -1 if there
// is no announcement.
int GetDownloadManagerA11yAnnouncement() const;
// web::DownloadTaskObserver overrides:
void OnDownloadUpdated(web::DownloadTask* task) override;
void OnDownloadDestroyed(web::DownloadTask* task) override;
......
......@@ -4,6 +4,8 @@
#import "ios/chrome/browser/ui/download/download_manager_mediator.h"
#include <UIKit/UIKit.h>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/strings/sys_string_conversions.h"
......@@ -11,9 +13,11 @@
#include "base/task_scheduler/post_task.h"
#include "ios/chrome/browser/download/download_directory_util.h"
#import "ios/chrome/browser/download/google_drive_app_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/web/public/download/download_task.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_fetcher_response_writer.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -108,6 +112,12 @@ void DownloadManagerMediator::UpdateConsumer() {
[consumer_ setProgress:GetDownloadManagerProgress()];
[consumer_
setFileName:base::SysUTF16ToNSString(task_->GetSuggestedFilename())];
int a11y_announcement = GetDownloadManagerA11yAnnouncement();
if (a11y_announcement != -1) {
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,
l10n_util::GetNSString(a11y_announcement));
}
}
DownloadManagerState DownloadManagerMediator::GetDownloadManagerState() const {
......@@ -125,6 +135,20 @@ DownloadManagerState DownloadManagerMediator::GetDownloadManagerState() const {
}
}
int DownloadManagerMediator::GetDownloadManagerA11yAnnouncement() const {
switch (task_->GetState()) {
case web::DownloadTask::State::kNotStarted:
return IDS_IOS_DOWNLOAD_MANAGER_REQUESTED_ACCESSIBILITY_ANNOUNCEMENT;
case web::DownloadTask::State::kComplete:
return task_->GetErrorCode()
? IDS_IOS_DOWNLOAD_MANAGER_FAILED_ACCESSIBILITY_ANNOUNCEMENT
: IDS_IOS_DOWNLOAD_MANAGER_SUCCEEDED_ACCESSIBILITY_ANNOUNCEMENT;
case web::DownloadTask::State::kCancelled:
case web::DownloadTask::State::kInProgress:
return -1;
}
}
float DownloadManagerMediator::GetDownloadManagerProgress() const {
if (task_->GetPercentComplete() == -1)
return 0.0f;
......
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