Commit 35642255 authored by Mark Schillaci's avatar Mark Schillaci Committed by Commit Bot

Accessibility Image Descriptions Android Port, Part III - Integration 1

This CL is the third part of an effort to port the existing Desktop
feature to Android. This feature enables a user to send an image to
Google to process to generate a descriptive alt text if a website
does not provide one.

Design Doc: go/2020-q1-android-image-descriptions
Slide Deck: go/clank-imageDescriptions
Launch Bug: 1057168

Original Desktop Design Doc for reference:
go/chrome-a11y-annotations-design

This is a conservative approach, we use a separate set of profile
Prefs for this feature rather than syncing with the Desktop Prefs.
This can be updated in time as needed. We have also hidden the
entire feature behind a feature flag, so this CL is not visible
to an average user.

----------

This CL adds the following:

- Adds helper text/hint for unlabeled images
- Adds returned image description to node's inner text
- Associated strings etc for above

----------

Binary-Size: Size increase is unavoidable, it comes from adding necessary content strings and descriptions for translations.
AX-Relnotes: Adds feature to enable generating alt image descriptions, currently behind a feature flag.
Bug: 1057169
Change-Id: I6becb973045e127681136a1fe0b7171d5cbddca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317712Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarMark Schillaci <mschillaci@google.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Cr-Commit-Position: refs/heads/master@{#821324}
parent 8698e421
......@@ -91,6 +91,50 @@ void BrowserAccessibilityAndroid::OnLocationChanged() {
manager->FireLocationChanged(this);
}
base::string16
BrowserAccessibilityAndroid::GetLocalizedStringForImageAnnotationStatus(
ax::mojom::ImageAnnotationStatus status) const {
// Default to standard text, except for special case of eligible.
if (status != ax::mojom::ImageAnnotationStatus::kEligibleForAnnotation)
return BrowserAccessibility::GetLocalizedStringForImageAnnotationStatus(
status);
ContentClient* content_client = content::GetContentClient();
int message_id = 0;
switch (static_cast<ax::mojom::WritingDirection>(
GetIntAttribute(ax::mojom::IntAttribute::kTextDirection))) {
case ax::mojom::WritingDirection::kRtl:
message_id = IDS_AX_IMAGE_ELIGIBLE_FOR_ANNOTATION_ANDROID_RTL;
break;
case ax::mojom::WritingDirection::kTtb:
case ax::mojom::WritingDirection::kBtt:
case ax::mojom::WritingDirection::kNone:
case ax::mojom::WritingDirection::kLtr:
message_id = IDS_AX_IMAGE_ELIGIBLE_FOR_ANNOTATION_ANDROID_LTR;
break;
}
DCHECK(message_id);
return content_client->GetLocalizedString(message_id);
}
void BrowserAccessibilityAndroid::AppendTextToString(
base::string16 extra_text,
base::string16* string) const {
if (extra_text.empty())
return;
if (string->empty()) {
*string = extra_text;
return;
}
*string += base::string16(base::ASCIIToUTF16(", ")) + extra_text;
}
bool BrowserAccessibilityAndroid::IsCheckable() const {
return GetData().HasCheckedState();
}
......@@ -479,6 +523,31 @@ base::string16 BrowserAccessibilityAndroid::GetInnerText() const {
if (GetRole() == ax::mojom::Role::kRootWebArea)
return text;
// Append image description strings to the text.
auto status = GetData().GetImageAnnotationStatus();
switch (status) {
case ax::mojom::ImageAnnotationStatus::kEligibleForAnnotation:
case ax::mojom::ImageAnnotationStatus::kAnnotationPending:
case ax::mojom::ImageAnnotationStatus::kAnnotationEmpty:
case ax::mojom::ImageAnnotationStatus::kAnnotationAdult:
case ax::mojom::ImageAnnotationStatus::kAnnotationProcessFailed:
AppendTextToString(GetLocalizedStringForImageAnnotationStatus(status),
&text);
break;
case ax::mojom::ImageAnnotationStatus::kAnnotationSucceeded:
AppendTextToString(
GetString16Attribute(ax::mojom::StringAttribute::kImageAnnotation),
&text);
break;
case ax::mojom::ImageAnnotationStatus::kNone:
case ax::mojom::ImageAnnotationStatus::kWillNotAnnotateDueToScheme:
case ax::mojom::ImageAnnotationStatus::kIneligibleForAnnotation:
case ax::mojom::ImageAnnotationStatus::kSilentlyEligibleForAnnotation:
break;
}
// This is called from IsLeaf, so don't call PlatformChildCount
// from within this!
if (text.empty() && (HasOnlyTextChildren() ||
......@@ -756,6 +825,24 @@ base::string16 BrowserAccessibilityAndroid::GetRoleDescription() const {
return parent->GetRoleDescription();
}
// If this node is an image, check status and potentially add unlabeled role.
auto status = GetData().GetImageAnnotationStatus();
switch (status) {
case ax::mojom::ImageAnnotationStatus::kEligibleForAnnotation:
case ax::mojom::ImageAnnotationStatus::kAnnotationPending:
case ax::mojom::ImageAnnotationStatus::kAnnotationEmpty:
case ax::mojom::ImageAnnotationStatus::kAnnotationAdult:
case ax::mojom::ImageAnnotationStatus::kAnnotationProcessFailed:
return GetLocalizedRoleDescriptionForUnlabeledImage();
case ax::mojom::ImageAnnotationStatus::kAnnotationSucceeded:
case ax::mojom::ImageAnnotationStatus::kNone:
case ax::mojom::ImageAnnotationStatus::kWillNotAnnotateDueToScheme:
case ax::mojom::ImageAnnotationStatus::kIneligibleForAnnotation:
case ax::mojom::ImageAnnotationStatus::kSilentlyEligibleForAnnotation:
break;
}
int message_id = -1;
switch (GetRole()) {
case ax::mojom::Role::kAbbr:
......
......@@ -26,6 +26,8 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
// Overrides from BrowserAccessibility.
void OnDataChanged() override;
void OnLocationChanged() override;
base::string16 GetLocalizedStringForImageAnnotationStatus(
ax::mojom::ImageAnnotationStatus status) const override;
bool IsCheckable() const;
bool IsChecked() const;
......@@ -195,6 +197,9 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
static size_t CommonEndLengths(const base::string16 a,
const base::string16 b);
void AppendTextToString(base::string16 extra_text,
base::string16* string) const;
base::string16 cached_text_;
base::string16 old_value_;
base::string16 new_value_;
......
......@@ -841,6 +841,14 @@ below:
</message>
</else>
</if>
<if expr="is_android">
<message name="IDS_AX_IMAGE_ELIGIBLE_FOR_ANNOTATION_ANDROID_LTR" desc="Accessibility message spoken out loud to screen reader users on Android to inform them that they can get a description of an image by opening the 'More Options' menu on the top right. This is only for LTR languages. The 'more options' text should match TC ID 8110367050267853536">
This image isn‘t labeled. Open the More Options menu at the top right to get image descriptions.
</message>
<message name="IDS_AX_IMAGE_ELIGIBLE_FOR_ANNOTATION_ANDROID_RTL" desc="Accessibility message spoken out loud to screen reader users on Android to inform them that they can get a description of an image by opening the 'More Options' menu on the top left. This is only for RTL languages. The 'more options' text should match TC ID 8110367050267853536">
This image isn‘t labeled. Open the More Options menu at the top left to get image descriptions.
</message>
</if>
<message name="IDS_AX_IMAGE_ELIGIBLE_FOR_ANNOTATION" desc="Accessibility message spoken out loud to screen reader users to inform them that they can get a description of an image by opening the context menu.">
To get missing image descriptions, open the context menu.
</message>
......
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