Skip to content

Commit

Permalink
Add accessibility data to URL Handling intent picker dialog for scree…
Browse files Browse the repository at this point in the history
…n readers

The URL Handling intent picker dialog shows a list of options. Add a11y
info that indicates the current option position out of the total count -
"1 of 2" for example.

Before & after screenshots with Accessibility Insights for Windows:
https://imgur.com/a/jCpRbHI

VoiceOver: https://imgur.com/a/bsG4SOP


Bug: 1072058, 1209222
Change-Id: Id24faa061323732cfe76dec742b32c1af188760e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2970726
Commit-Queue: Mandy Chen <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Reviewed-by: Dominick Ng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#894019}
  • Loading branch information
chruxin authored and Chromium LUCI CQ committed Jun 18, 2021
1 parent a50b9e0 commit 2a98528
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
3 changes: 3 additions & 0 deletions chrome/app/url_handler_intent_picker_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
<message name="IDS_URL_HANDLER_INTENT_PICKER_APP_ORIGIN_LABEL" desc="Label for the url origin of each item in the web app list in the URL handler intent picker dialog">
Publisher: <ph name="APP_ORIGIN">$1<ex>example.com</ex></ph>
</message>
<message name="IDS_URL_HANDLER_INTENT_PICKER_OPTION_N_OF_M" desc="Text for screenreaders describing the current option's position in the list of options in the URL handler intent picker dialog.">
<ph name="BUTTON_ACCESSIBLE_TEXT">$1<ex>Chromium</ex></ph>, <ph name="OPTION_POSITION">$2<ex>1</ex></ph> of <ph name="NUM_OPTIONS">$3<ex>2</ex></ph>
</message>
</grit-part>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b1ef41586f33eee7d5d96a3230454c1b2969d556
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/button.h"
#include "url/gurl.h"

WebAppUrlHandlerHoverButton::WebAppUrlHandlerHoverButton(
size_t total_buttons,
views::Button::PressedCallback callback,
const web_app::UrlHandlerLaunchParams& url_handler_launch_params,
web_app::WebAppProvider* provider,
Expand All @@ -31,15 +33,28 @@ WebAppUrlHandlerHoverButton::WebAppUrlHandlerHoverButton(
display_name,
app_start_url),
url_handler_launch_params_(url_handler_launch_params),
is_app_(true) {}
is_app_(true),
total_buttons_(total_buttons) {}

WebAppUrlHandlerHoverButton::WebAppUrlHandlerHoverButton(
size_t total_buttons,
views::Button::PressedCallback callback)
: WebAppHoverButton(
std::move(callback),
*(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_PRODUCT_LOGO_32)),
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
is_app_(false) {}
is_app_(false),
total_buttons_(total_buttons) {}

WebAppUrlHandlerHoverButton::~WebAppUrlHandlerHoverButton() = default;

void WebAppUrlHandlerHoverButton::GetAccessibleNodeData(
ui::AXNodeData* node_data) {
WebAppHoverButton::GetAccessibleNodeData(node_data);

node_data->SetName(l10n_util::GetStringFUTF16(
IDS_URL_HANDLER_INTENT_PICKER_OPTION_N_OF_M, GetAccessibleName(),
base::NumberToString16(tag() + 1),
base::NumberToString16(total_buttons_)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WebAppUrlHandlerHoverButton : public WebAppHoverButton {
// +-------------------------------------------------------------------+
//
WebAppUrlHandlerHoverButton(
size_t buttons_count,
views::Button::PressedCallback callback,
const web_app::UrlHandlerLaunchParams& url_handler_launch_params,
web_app::WebAppProvider* provider,
Expand All @@ -45,7 +46,8 @@ class WebAppUrlHandlerHoverButton : public WebAppHoverButton {
// | | |
// +-------------------------------------------------------------------+
//
explicit WebAppUrlHandlerHoverButton(views::Button::PressedCallback callback);
explicit WebAppUrlHandlerHoverButton(size_t buttons_count,
views::Button::PressedCallback callback);
WebAppUrlHandlerHoverButton(const WebAppUrlHandlerHoverButton&) = delete;
WebAppUrlHandlerHoverButton& operator=(const WebAppUrlHandlerHoverButton&) =
delete;
Expand All @@ -57,11 +59,16 @@ class WebAppUrlHandlerHoverButton : public WebAppHoverButton {

bool is_app() const { return is_app_; }

// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;

private:
const web_app::UrlHandlerLaunchParams url_handler_launch_params_;
// True if the current WebAppUrlHandlerHoverButton is for an app, false if
// it's for the browser.
const bool is_app_;
// Total number of buttons. Used for accessibility.
size_t total_buttons_;
};

#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_WEB_APP_URL_HANDLER_HOVER_BUTTON_H_
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ void WebAppUrlHandlerIntentPickerView::Initialize() {
views::BoxLayout::Orientation::kVertical));

web_app::WebAppProvider* provider;
// Reserve size+1 for the browser entry.
hover_buttons_.reserve(launch_params_list_.size() + 1);
// size+1 for the browser entry.
size_t total_buttons = launch_params_list_.size() + 1;
hover_buttons_.reserve(total_buttons);
// Create a WebAppUrlHandlerHoverButton to open the link in browser and
// list it as the first choice.
auto app_button =
std::make_unique<WebAppUrlHandlerHoverButton>(base::BindRepeating(
&WebAppUrlHandlerIntentPickerView::SetSelectedAppIndex,
base::Unretained(this), 0));
auto app_button = std::make_unique<WebAppUrlHandlerHoverButton>(
total_buttons, base::BindRepeating(
&WebAppUrlHandlerIntentPickerView::SetSelectedAppIndex,
base::Unretained(this), 0));
app_button->set_tag(0);
hover_buttons_.push_back(app_button.get());
scrollable_view->AddChildViewAt(std::move(app_button), 0);
Expand All @@ -231,6 +232,7 @@ void WebAppUrlHandlerIntentPickerView::Initialize() {
// TODO(crbug.com/1072058): Make sure the UI is reasonable when
// |app_title| is long.
auto app_button = std::make_unique<WebAppUrlHandlerHoverButton>(
total_buttons,
base::BindRepeating(
&WebAppUrlHandlerIntentPickerView::SetSelectedAppIndex,
base::Unretained(this), button_index),
Expand Down

0 comments on commit 2a98528

Please sign in to comment.