Skip to content

Commit

Permalink
[DownloadBubble] Add accessibility labels/announcements
Browse files Browse the repository at this point in the history
Add title for the main view (full/partial) and warning announcement for
the subpage view. Also, make the back button on the subpage initially
focused.

Bug: 1323604
Change-Id: I8075086bd70ce92864d43299e6f63c9383cfa13c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3633444
Commit-Queue: Rohit Bhatia <bhatiarohit@google.com>
Reviewed-by: Min Qin <qinmin@chromium.org>
Reviewed-by: Mike Wasserman <msw@chromium.org>
Reviewed-by: Xinghui Lu <xinghuilu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002516}
  • Loading branch information
Rohit Bhatia authored and Chromium LUCI CQ committed May 12, 2022
1 parent e189327 commit c3d81c8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
Expand Down Expand Up @@ -48,16 +49,16 @@ void DownloadBubbleSecurityView::AddHeader() {
gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_RELATED_CONTROL_VERTICAL)));

auto* back_button =
back_button_ =
header->AddChildView(views::CreateVectorImageButtonWithNativeTheme(
base::BindRepeating(
&DownloadBubbleNavigationHandler::OpenPrimaryDialog,
base::Unretained(navigation_handler_)),
vector_icons::kArrowBackIcon, GetLayoutConstant(DOWNLOAD_ICON_SIZE)));
views::InstallCircleHighlightPathGenerator(back_button);
back_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
back_button->SetProperty(views::kCrossAxisAlignmentKey,
views::LayoutAlignment::kStart);
views::InstallCircleHighlightPathGenerator(back_button_);
back_button_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
back_button_->SetProperty(views::kCrossAxisAlignmentKey,
views::LayoutAlignment::kStart);

title_ = header->AddChildView(std::make_unique<views::Label>(
std::u16string(), views::style::CONTEXT_DIALOG_TITLE,
Expand Down Expand Up @@ -293,6 +294,22 @@ void DownloadBubbleSecurityView::UpdateSecurityView(
UpdateButtons();
}

void DownloadBubbleSecurityView::UpdateAccessibilityTextAndFocus() {
DownloadUIModel::BubbleUIInfo& ui_info = download_row_view_->ui_info();
// Announce that the subpage was opened to inform the user about the changes
// in the UI.
#if BUILDFLAG(IS_MAC)
GetViewAccessibility().OverrideName(ui_info.warning_summary);
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
#else
GetViewAccessibility().AnnounceText(ui_info.warning_summary);
#endif

// Focus the back button by default to ensure that focus is set when new
// content is displayed.
back_button_->RequestFocus();
}

DownloadBubbleSecurityView::DownloadBubbleSecurityView(
DownloadBubbleUIController* bubble_controller,
DownloadBubbleNavigationHandler* navigation_handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Checkbox;
class Label;
class ImageView;
class StyledLabel;
class ImageButton;
} // namespace views

class DownloadBubbleUIController;
Expand All @@ -32,8 +33,15 @@ class DownloadBubbleSecurityView : public views::View {
DownloadBubbleSecurityView& operator=(const DownloadBubbleSecurityView&) =
delete;
~DownloadBubbleSecurityView() override;

// Update the security view when a subpage is opened for a particular
// download.
void UpdateSecurityView(DownloadBubbleRowView* download_row_view);

// Update the view after it is visible, in particular asking for focus and
// announcing accessibility text.
void UpdateAccessibilityTextAndFocus();

raw_ptr<views::MdTextButton> keep_button_ = nullptr;
raw_ptr<views::MdTextButton> discard_button_ = nullptr;
raw_ptr<views::MdTextButton> bypass_deep_scan_button_ = nullptr;
Expand All @@ -48,6 +56,7 @@ class DownloadBubbleSecurityView : public views::View {
void AddIconAndText();
void UpdateButtons();
void AddButtons();

void ProcessButtonClick(DownloadCommands::Command command,
bool is_first_button);
views::MdTextButton* GetButtonForCommand(DownloadCommands::Command command);
Expand All @@ -61,6 +70,7 @@ class DownloadBubbleSecurityView : public views::View {
raw_ptr<views::Label> title_ = nullptr;
raw_ptr<views::ImageView> icon_ = nullptr;
raw_ptr<views::StyledLabel> styled_label_ = nullptr;
raw_ptr<views::ImageButton> back_button_ = nullptr;
absl::optional<base::Time> warning_time_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ void DownloadToolbarButtonView::OpenSecurityDialog(
security_view_->UpdateSecurityView(download_row_view);
primary_view_->SetVisible(false);
security_view_->SetVisible(true);
security_view_->UpdateAccessibilityTextAndFocus();
ResizeDialog();
}

Expand Down Expand Up @@ -227,6 +228,8 @@ void DownloadToolbarButtonView::CreateBubbleDialogDelegate(
std::unique_ptr<views::BubbleDialogDelegate> bubble_delegate =
std::make_unique<views::BubbleDialogDelegate>(
this, views::BubbleBorder::TOP_RIGHT);
bubble_delegate->SetTitle(
l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_HEADER_TEXT));
bubble_delegate->SetShowTitle(false);
bubble_delegate->SetShowCloseButton(false);
bubble_delegate->SetButtons(ui::DIALOG_BUTTON_NONE);
Expand Down

0 comments on commit c3d81c8

Please sign in to comment.