Commit 951705f5 authored by Katie D's avatar Katie D Committed by Commit Bot

Adds UMA histograms to better understand image alt usage for a11y.

This logs image minimum dimension and dimension ratio for all images
loaded when a screen reader is enabled. For more info see go/gchro.

Bug: 905419
Change-Id: I75402356c4cf5e64211e37d928634b7b4754fc2b
Reviewed-on: https://chromium-review.googlesource.com/c/1336001
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608922}
parent c852d472
......@@ -11,6 +11,7 @@
#include "base/containers/queue.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -436,6 +437,9 @@ void RenderAccessibilityImpl::SendPendingAccessibilityEvents() {
// If there's a layout complete message, we need to send location changes.
bool had_layout_complete_messages = false;
// If there's a load complete message, we need to send image metrics.
bool had_load_complete_messages = false;
ScopedFreezeBlinkAXTreeSource freeze(&tree_source_);
// Loop over each event and generate an updated event message.
......@@ -444,6 +448,9 @@ void RenderAccessibilityImpl::SendPendingAccessibilityEvents() {
if (event.event_type == ax::mojom::Event::kLayoutComplete)
had_layout_complete_messages = true;
if (event.event_type == ax::mojom::Event::kLoadComplete)
had_load_complete_messages = true;
auto obj = WebAXObject::FromWebDocumentByID(document, event.id);
// Make sure the object still exists.
......@@ -519,6 +526,9 @@ void RenderAccessibilityImpl::SendPendingAccessibilityEvents() {
bundle.updates.push_back(update);
if (had_load_complete_messages)
RecordImageMetrics(&update);
VLOG(1) << "Accessibility tree update:\n" << update.ToString();
}
......@@ -899,4 +909,49 @@ void RenderAccessibilityImpl::ScrollPlugin(int id_to_make_visible) {
WebRect(bounds.x(), bounds.y(), bounds.width(), bounds.height()));
}
void RenderAccessibilityImpl::RecordImageMetrics(AXContentTreeUpdate* update) {
if (!render_frame_->accessibility_mode().has_mode(ui::AXMode::kScreenReader))
return;
float scale_factor = render_frame_->GetRenderView()->GetDeviceScaleFactor();
for (size_t i = 0; i < update->nodes.size(); ++i) {
ui::AXNodeData& node_data = update->nodes[i];
if (node_data.role != ax::mojom::Role::kImage)
continue;
// Convert to DIPs based on screen scale factor.
int width = node_data.relative_bounds.bounds.width() / scale_factor;
int height = node_data.relative_bounds.bounds.height() / scale_factor;
if (width == 0 || height == 0)
continue;
// We log the min size in a histogram with a max of 10000, so set a ceiling
// of 10000 on min_size.
int min_size = std::min(std::min(width, height), 10000);
int max_size = std::max(width, height);
// The ratio is always the smaller divided by the larger so as not to go
// over 100%.
int ratio = min_size * 100.0 / max_size;
const std::string name =
node_data.GetStringAttribute(ax::mojom::StringAttribute::kName);
bool explicitly_empty = node_data.GetNameFrom() ==
ax::mojom::NameFrom::kAttributeExplicitlyEmpty;
if (!name.empty()) {
UMA_HISTOGRAM_PERCENTAGE(
"Accessibility.ScreenReader.Image.SizeRatio.Labeled", ratio);
UMA_HISTOGRAM_COUNTS_10000(
"Accessibility.ScreenReader.Image.MinSize.Labeled", min_size);
} else if (explicitly_empty) {
UMA_HISTOGRAM_PERCENTAGE(
"Accessibility.ScreenReader.Image.SizeRatio.ExplicitlyUnlabeled",
ratio);
UMA_HISTOGRAM_COUNTS_10000(
"Accessibility.ScreenReader.Image.MinSize.ExplicitlyUnlabeled",
min_size);
} else {
UMA_HISTOGRAM_PERCENTAGE(
"Accessibility.ScreenReader.Image.SizeRatio.Unlabeled", ratio);
UMA_HISTOGRAM_COUNTS_10000(
"Accessibility.ScreenReader.Image.MinSize.Unlabeled", min_size);
}
}
}
} // namespace content
......@@ -137,6 +137,7 @@ class CONTENT_EXPORT RenderAccessibilityImpl
void ScrollPlugin(int id_to_make_visible);
ax::mojom::EventFrom GetEventFrom();
void ScheduleSendAccessibilityEventsIfNeeded();
void RecordImageMetrics(AXContentTreeUpdate* update);
// The RenderFrameImpl that owns us.
RenderFrameImpl* render_frame_;
......
......@@ -403,6 +403,34 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="Accessibility.ScreenReader.Image.MinSize" units="px"
expires_after="2019-04-01">
<!-- Name completed by histogram_suffixes
name="AccessibilityScreenReaderImage" -->
<owner>katie@chromium.org</owner>
<owner>dmazzoni@chromium.org</owner>
<summary>
For every image on a page with screen reader accessibility mode enabled,
this histogram will be used to understand minimum dimension of the image,
i.e. either the width or height in px.
</summary>
</histogram>
<histogram name="Accessibility.ScreenReader.Image.SizeRatio" units="%"
expires_after="2019-04-01">
<!-- Name completed by histogram_suffixes
name="AccessibilityScreenReaderImage" -->
<owner>katie@chromium.org</owner>
<owner>dmazzoni@chromium.org</owner>
<summary>
For every image on a page with screen reader accessibility mode enabled,
this histogram will be used to understand the size ratio of the image. This
is the smaller dimension divided by the larger dimension.
</summary>
</histogram>
<histogram name="Accessibility.State" enum="BooleanEnabled">
<obsolete>
Deprecated 12/2016 in Issue 672205 with the addition of
......@@ -125641,6 +125669,15 @@ uploading your change for review.
<histogram_suffixes_list>
<histogram_suffixes name="AccessibilityScreenReaderImage" separator=".">
<suffix base="true" name="ExplicitlyUnlabeled"
label="explicitly unlabeled image"/>
<suffix base="true" name="Labeled" label="labeled image"/>
<suffix name="Unlabeled" label="unlabeled image"/>
<affected-histogram name="Accessibility.ScreenReader.Image.MinSize"/>
<affected-histogram name="Accessibility.ScreenReader.Image.SizeRatio"/>
</histogram_suffixes>
<histogram_suffixes name="AccessorySheetType" separator=".">
<suffix name="Passwords" label="Password suggestions and generation."/>
<affected-histogram name="KeyboardAccessory.AccessorySheetSuggestionCount"/>
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