Commit 6a353124 authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[Autofill Views] Expanding a11y data

This CL adds the disambiguation information and the credit card network
icon to the accessible data, when these fields are present.

Change-Id: I198e0af4d058290f4a572d2534aec2bbd56beda3
Bug: 847586

TBR=avi@chromium.org

Change-Id: I198e0af4d058290f4a572d2534aec2bbd56beda3
Reviewed-on: https://chromium-review.googlesource.com/1077335
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarRachel Blum <groby@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566608}
parent 605ff0e7
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/autofill/autofill_popup_view.h" #include "chrome/browser/ui/autofill/autofill_popup_view.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "components/autofill/core/browser/suggestion.h" #include "components/autofill/core/browser/suggestion.h"
#include "components/autofill/core/common/autofill_util.h" #include "components/autofill/core/common/autofill_util.h"
#include "components/grit/components_scaled_resources.h" #include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
...@@ -46,27 +48,34 @@ const size_t kSeparatorHeight = 1; ...@@ -46,27 +48,34 @@ const size_t kSeparatorHeight = 1;
const int kSmallerFontSizeDelta = -1; const int kSmallerFontSizeDelta = -1;
#endif #endif
// Used in the IDS_ space as a placeholder for resources that don't exist.
constexpr int kResourceNotFoundId = 0;
const struct { const struct {
const char* name; const char* name;
int id; int icon_id;
int accessible_string_id;
} kDataResources[] = { } kDataResources[] = {
{autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX}, {autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX,
{autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS}, IDS_AUTOFILL_CC_AMEX},
{autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER}, {autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS, IDS_AUTOFILL_CC_DINERS},
{autofill::kEloCard, IDR_AUTOFILL_CC_ELO}, {autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER,
{autofill::kGenericCard, IDR_AUTOFILL_CC_GENERIC}, IDS_AUTOFILL_CC_DISCOVER},
{autofill::kJCBCard, IDR_AUTOFILL_CC_JCB}, {autofill::kEloCard, IDR_AUTOFILL_CC_ELO, IDS_AUTOFILL_CC_ELO},
{autofill::kMasterCard, IDR_AUTOFILL_CC_MASTERCARD}, {autofill::kGenericCard, IDR_AUTOFILL_CC_GENERIC, kResourceNotFoundId},
{autofill::kMirCard, IDR_AUTOFILL_CC_MIR}, {autofill::kJCBCard, IDR_AUTOFILL_CC_JCB, IDS_AUTOFILL_CC_JCB},
{autofill::kUnionPay, IDR_AUTOFILL_CC_UNIONPAY}, {autofill::kMasterCard, IDR_AUTOFILL_CC_MASTERCARD,
{autofill::kVisaCard, IDR_AUTOFILL_CC_VISA}, IDS_AUTOFILL_CC_MASTERCARD},
{"googlePay", IDR_AUTOFILL_GOOGLE_PAY}, {autofill::kMirCard, IDR_AUTOFILL_CC_MIR, IDS_AUTOFILL_CC_MIR},
{autofill::kUnionPay, IDR_AUTOFILL_CC_UNIONPAY, IDS_AUTOFILL_CC_UNION_PAY},
{autofill::kVisaCard, IDR_AUTOFILL_CC_VISA, IDS_AUTOFILL_CC_VISA},
{"googlePay", IDR_AUTOFILL_GOOGLE_PAY, kResourceNotFoundId},
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
{"httpWarning", IDR_AUTOFILL_HTTP_WARNING}, {"httpWarning", IDR_AUTOFILL_HTTP_WARNING, kResourceNotFoundId},
{"httpsInvalid", IDR_AUTOFILL_HTTPS_INVALID_WARNING}, {"httpsInvalid", IDR_AUTOFILL_HTTPS_INVALID_WARNING, kResourceNotFoundId},
{"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW}, {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW, kResourceNotFoundId},
{"settings", IDR_AUTOFILL_SETTINGS}, {"settings", IDR_AUTOFILL_SETTINGS, kResourceNotFoundId},
{"create", IDR_AUTOFILL_CREATE}, {"create", IDR_AUTOFILL_CREATE, kResourceNotFoundId},
#endif #endif
}; };
...@@ -218,7 +227,7 @@ gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { ...@@ -218,7 +227,7 @@ gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const {
// For other suggestion entries, get icon from PNG files. // For other suggestion entries, get icon from PNG files.
int icon_id = GetIconResourceID(icon_str); int icon_id = GetIconResourceID(icon_str);
DCHECK_NE(-1, icon_id); DCHECK_NE(kResourceNotFoundId, icon_id);
return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id);
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
...@@ -253,10 +262,10 @@ gfx::Rect AutofillPopupLayoutModel::GetRowBounds(size_t index) const { ...@@ -253,10 +262,10 @@ gfx::Rect AutofillPopupLayoutModel::GetRowBounds(size_t index) const {
int AutofillPopupLayoutModel::GetIconResourceID( int AutofillPopupLayoutModel::GetIconResourceID(
const base::string16& resource_name) const { const base::string16& resource_name) const {
int result = -1; int result = kResourceNotFoundId;
for (size_t i = 0; i < arraysize(kDataResources); ++i) { for (size_t i = 0; i < base::size(kDataResources); ++i) {
if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) { if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) {
result = kDataResources[i].id; result = kDataResources[i].icon_id;
break; break;
} }
} }
...@@ -264,6 +273,17 @@ int AutofillPopupLayoutModel::GetIconResourceID( ...@@ -264,6 +273,17 @@ int AutofillPopupLayoutModel::GetIconResourceID(
return result; return result;
} }
int AutofillPopupLayoutModel::GetIconAccessibleNameResourceId(
const base::string16& resource_name) const {
for (size_t i = 0; i < base::size(kDataResources); ++i) {
// TODO(crbug.com/850597): Remove UTF conversion once AutofillSuggestion
// no longer stores the resource name as a string16.
if (resource_name == base::ASCIIToUTF16(kDataResources[i].name))
return kDataResources[i].accessible_string_id;
}
return kResourceNotFoundId;
}
const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const {
return gfx::ToEnclosingRect(delegate_->element_bounds()); return gfx::ToEnclosingRect(delegate_->element_bounds());
} }
......
...@@ -86,9 +86,17 @@ class AutofillPopupLayoutModel { ...@@ -86,9 +86,17 @@ class AutofillPopupLayoutModel {
// the top left of the popup. // the top left of the popup.
gfx::Rect GetRowBounds(size_t index) const; gfx::Rect GetRowBounds(size_t index) const;
// Gets the resource value for the given resource, returning -1 if the // Gets the resource value for the given resource, returning 0 if the
// resource isn't recognized. // resource isn't recognized.
int GetIconResourceID(const base::string16& resource_name) const; int GetIconResourceID(const base::string16& resource_name) const;
// Returns the string id for an accessible name which should be used to
// describe the given resource. Returns 0 if the resource isn't recognized;
// note that this doesn't necessarily mean anything went wrong, as some valid
// resources are intentionally omitted for screen readers.
int GetIconAccessibleNameResourceId(
const base::string16& resource_name) const;
bool is_credit_card_popup() const { return is_credit_card_popup_; } bool is_credit_card_popup() const { return is_credit_card_popup_; }
private: private:
......
...@@ -32,7 +32,7 @@ constexpr int maxTouchBarItems = 3; ...@@ -32,7 +32,7 @@ constexpr int maxTouchBarItems = 3;
// Returns the credit card image. // Returns the credit card image.
NSImage* GetCreditCardTouchBarImage(int iconId) { NSImage* GetCreditCardTouchBarImage(int iconId) {
if (iconId == -1) if (iconId < 1)
return nil; return nil;
// If it's a generic card image, use the vector icon instead. // If it's a generic card image, use the vector icon instead.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_platform_node.h" #include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
...@@ -71,7 +72,20 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -71,7 +72,20 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override { void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
node_data->SetName(controller_->GetSuggestionAt(line_number_).value); auto suggestion = controller_->GetSuggestionAt(line_number_);
std::vector<base::string16> text;
text.push_back(suggestion.value);
text.push_back(suggestion.label);
base::string16 icon_description;
if (!suggestion.icon.empty()) {
const int id =
controller_->layout_model().GetIconAccessibleNameResourceId(
suggestion.icon);
if (id > 0)
text.push_back(l10n_util::GetStringUTF16(id));
}
node_data->SetName(base::JoinString(text, base::ASCIIToUTF16(" ")));
// Options are selectable. // Options are selectable.
node_data->role = ax::mojom::Role::kMenuItem; node_data->role = ax::mojom::Role::kMenuItem;
......
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