Skip to content

Commit

Permalink
Add contextualization strings to accessibility image labels.
Browse files Browse the repository at this point in the history
When adding automated descriptions to images in the accessibility
tree, add a contextualization string, "Appears to be:" for a
caption, or "Appears to say:" for OCR, to clearly distinguish
to the user.

Only OCR is completely hooked up, the full label is blocked on
one more change landing first.

(Note: these strings have already been reviewed by Shimi.)

Bug: 905419

Change-Id: Ib39ad7ff8cb43019809dad26f0c9cd32d6f9007a
Reviewed-on: https://chromium-review.googlesource.com/c/1480351
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634531}
  • Loading branch information
minorninth authored and Commit Bot committed Feb 22, 2019
1 parent 4a611be commit 67f02ae
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 6 deletions.
6 changes: 6 additions & 0 deletions chrome/common/chrome_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ base::string16 ChromeContentClient::GetLocalizedString(int message_id) const {
return l10n_util::GetStringUTF16(message_id);
}

base::string16 ChromeContentClient::GetLocalizedString(
int message_id,
const base::string16& replacement) const {
return l10n_util::GetStringFUTF16(message_id, replacement);
}

base::StringPiece ChromeContentClient::GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const {
Expand Down
3 changes: 3 additions & 0 deletions chrome/common/chrome_content_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class ChromeContentClient : public content::ContentClient {

void AddAdditionalSchemes(Schemes* schemes) override;
base::string16 GetLocalizedString(int message_id) const override;
base::string16 GetLocalizedString(
int message_id,
const base::string16& replacement) const override;
base::StringPiece GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const override;
Expand Down
1 change: 1 addition & 0 deletions content/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include_rules = [
# directories in content/ so we disallow all of them.
"-content",
"+content/app/resources/grit/content_resources.h",
"+content/app/strings/grit", # For generated headers
"+content/common",
"+content/grit",
"+content/public/common",
Expand Down
6 changes: 6 additions & 0 deletions content/app/strings/content_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ below:
<message name="IDS_AX_IMAGE_ANNOTATION_PROCESS_FAILED" desc="Accessibility message spoken out loud to screen reader users that the browser was not able to get a description for an image.">
Unable to get a description.
</message>
<message name="IDS_AX_IMAGE_ANNOTATION_OCR_CONTEXT" desc="Accessibility message spoken out loud to screen reader users when reading text that was automatically extracted from an image, for an example the word 'stop' could be extracted from a photo of a stop sign. Because automatic text extraction sometimes contains errors it is important that the language used indicates some uncertainty - it may say 'stop' or it appears to say 'stop', not it definitely says 'stop'.">
Appears to say: <ph name="OCR_TEXT">$1<ex>Stop</ex></ph>
</message>
<message name="IDS_AX_IMAGE_ANNOTATION_DESCRIPTION_CONTEXT" desc="Accessibility message spoken out loud to screen reader users when reading a computer-generated description of an image, for example a photo of the president at a press conference might be described as 'A person at a podium'. Because automatic image description is sometimes incorrect, it is important that the langauge used indicates some uncertainty - it may be a person, it appears to be a person, not it definitely is a person.">
Appears to be: <ph name="DESCRIPTION">$1<ex>A person at a podium</ex></ph>
</message>

<message name="IDS_AX_AM_PM_FIELD_TEXT" desc="Accessible description of the AM/PM field in a date/time control">
AM/PM
Expand Down
1 change: 0 additions & 1 deletion content/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ include_rules = [
"+components/viz",
"+components/cbor",

"+content/app/strings/grit", # For generated headers
"+content/public/app",
"+content/public/browser",
"+device/base/synchronization",
Expand Down
1 change: 0 additions & 1 deletion content/child/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ include_rules = [
"+components/webcrypto",
"+components/services/font/public",

"+content/app/strings/grit", # For generated headers
"+content/public/child",
"+services/device/public/cpp/device_features.h",
"+services/device/public/cpp/power_monitor",
Expand Down
6 changes: 6 additions & 0 deletions content/public/common/content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ base::string16 ContentClient::GetLocalizedString(int message_id) const {
return base::string16();
}

base::string16 ContentClient::GetLocalizedString(
int message_id,
const base::string16& replacement) const {
return base::string16();
}

base::StringPiece ContentClient::GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const {
Expand Down
6 changes: 6 additions & 0 deletions content/public/common/content_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class CONTENT_EXPORT ContentClient {
// Returns a string resource given its id.
virtual base::string16 GetLocalizedString(int message_id) const;

// Returns a string resource given its id and replace $1 with the given
// replacement.
virtual base::string16 GetLocalizedString(
int message_id,
const base::string16& replacement) const;

// Return the contents of a resource in a StringPiece given the resource id.
virtual base::StringPiece GetDataResource(
int resource_id,
Expand Down
1 change: 1 addition & 0 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ target(link_target_type, "renderer") {
"//components/viz/common",
"//components/viz/service",
"//content:resources",
"//content/app/strings:strings_grit",
"//content/child",
"//content/common",
"//content/common:buildflags",
Expand Down
17 changes: 14 additions & 3 deletions content/renderer/accessibility/ax_image_annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "base/base64.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "content/app/strings/grit/content_strings.h"
#include "content/public/common/content_client.h"
#include "content/renderer/render_frame_impl.h"
#include "crypto/sha2.h"
#include "third_party/blink/public/web/web_ax_object.h"
Expand Down Expand Up @@ -177,9 +181,16 @@ void AXImageAnnotator::OnImageAnnotated(
DLOG(WARNING) << "Unrecognized image annotation result.";
return;
}
// TODO(nektar): Add message to explain that the annotation is a best guess,
// e.g. "appears to be".
image_annotations_.at(image.AxID()).set_annotation(result->get_ocr_text());

if (result->get_ocr_text().empty())
return;

auto contextualized_string = GetContentClient()->GetLocalizedString(
IDS_AX_IMAGE_ANNOTATION_OCR_CONTEXT,
base::UTF8ToUTF16(result->get_ocr_text()));

image_annotations_.at(image.AxID())
.set_annotation(base::UTF16ToUTF8(contextualized_string));
render_accessibility_->MarkWebAXObjectDirty(image, false /* subtree */);
}

Expand Down
7 changes: 7 additions & 0 deletions content/renderer/accessibility/blink_ax_tree_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,15 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
if (image_annotator_->HasAnnotationInCache(src)) {
dst->AddStringAttribute(ax::mojom::StringAttribute::kImageAnnotation,
image_annotator_->GetImageAnnotation(src));
dst->SetImageAnnotationStatus(
ax::mojom::ImageAnnotationStatus::kAnnotationSucceeded);
} else if (image_annotator_->HasImageInCache(src)) {
dst->SetImageAnnotationStatus(
ax::mojom::ImageAnnotationStatus::kAnnotationPending);
} else if (!image_annotator_->HasImageInCache(src)) {
image_annotator_->OnImageAdded(src);
dst->SetImageAnnotationStatus(
ax::mojom::ImageAnnotationStatus::kAnnotationPending);
}
}

Expand Down
1 change: 0 additions & 1 deletion content/shell/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ include_rules = [

# The content_shell is the canonical sample embedder, so it only uses
# content's public API.
"+content/app/strings/grit", # For generated headers
"+content/public",

"+services/network/ignore_errors_cert_verifier.h",
Expand Down

0 comments on commit 67f02ae

Please sign in to comment.