Commit b01c6a72 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media Notification] Add metadata to AX data

Add the media metadata to the AX data so that it can
be picked up by a screen reader.

BUG=962682

Change-Id: I78a0d5c09c13450d5486c94b7d04b5fa36cce9b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610028
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Auto-Submit: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659281}
parent 92861c50
......@@ -1922,6 +1922,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_MEDIA_NOTIFICATION_ACTION_NEXT_TRACK" desc="The button to trigger media playback to go to the next track.">
Next Track
</message>
<message name="IDS_ASH_MEDIA_NOTIFICATION_ACCESSIBLE_NAME" desc="The accessible name for the media notification to control playback">
Media Controls
</message>
</messages>
</release>
</grit>
b9c783c388c0bbd76087452ce60ba00813c668e4
\ No newline at end of file
......@@ -11,8 +11,10 @@
#include "ash/strings/grit/ash_strings.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/vector_icons/vector_icons.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_list.h"
......@@ -249,6 +251,16 @@ void MediaNotificationView::UpdateCornerRadius(int top_radius,
bottom_radius);
}
void MediaNotificationView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kListItem;
node_data->AddStringAttribute(
ax::mojom::StringAttribute::kRoleDescription,
l10n_util::GetStringUTF8(IDS_ASH_MEDIA_NOTIFICATION_ACCESSIBLE_NAME));
if (!accessible_name_.empty())
node_data->SetName(accessible_name_);
}
void MediaNotificationView::OnMouseEvent(ui::MouseEvent* event) {
switch (event->type()) {
case ui::ET_MOUSE_ENTERED:
......@@ -307,14 +319,24 @@ void MediaNotificationView::UpdateWithMediaMetadata(
artist_label_->SetText(metadata.artist);
header_row_->SetSummaryText(metadata.album);
if (!metadata.title.empty())
std::vector<base::string16> text;
if (!metadata.title.empty()) {
text.push_back(metadata.title);
RecordMetadataHistogram(Metadata::kTitle);
}
if (!metadata.artist.empty())
if (!metadata.artist.empty()) {
text.push_back(metadata.artist);
RecordMetadataHistogram(Metadata::kArtist);
}
if (!metadata.album.empty())
if (!metadata.album.empty()) {
text.push_back(metadata.album);
RecordMetadataHistogram(Metadata::kAlbum);
}
accessible_name_ = base::JoinString(text, base::ASCIIToUTF16(" - "));
RecordMetadataHistogram(Metadata::kCount);
......
......@@ -74,6 +74,7 @@ class ASH_EXPORT MediaNotificationView : public message_center::MessageView,
const override;
void SetExpanded(bool expanded) override;
void UpdateCornerRadius(int top_radius, int bottom_radius) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::View:
void OnMouseEvent(ui::MouseEvent* event) override;
......@@ -126,6 +127,10 @@ class ASH_EXPORT MediaNotificationView : public message_center::MessageView,
// Set of enabled actions.
std::set<media_session::mojom::MediaSessionAction> enabled_actions_;
// Stores the text to be read by screen readers describing the notification.
// Contains the title, artist and album separated by hypens.
base::string16 accessible_name_;
// Container views directly attached to this view.
message_center::NotificationHeaderView* header_row_ = nullptr;
views::View* button_row_ = nullptr;
......
......@@ -27,6 +27,7 @@
#include "services/media_session/public/cpp/test/test_media_controller.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/message_center/message_center.h"
......@@ -179,6 +180,10 @@ class MediaNotificationViewTest : public AshTestBase {
return view_->header_row_;
}
const base::string16& accessible_name() const {
return view_->accessible_name_;
}
views::View* button_row() const { return view_->button_row_; }
views::View* title_artist_row() const { return view_->title_artist_row_; }
......@@ -608,6 +613,8 @@ TEST_F(MediaNotificationViewTest, UpdateMetadata_FromObserver) {
EXPECT_EQ(kMediaTitleArtistRowExpectedHeight, title_artist_row()->height());
EXPECT_EQ(base::ASCIIToUTF16("title2 - artist2 - album"), accessible_name());
ExpectHistogramMetadataRecorded(MediaNotificationView::Metadata::kTitle, 2);
ExpectHistogramMetadataRecorded(MediaNotificationView::Metadata::kArtist, 2);
ExpectHistogramMetadataRecorded(MediaNotificationView::Metadata::kAlbum, 1);
......@@ -899,4 +906,13 @@ TEST_F(MediaNotificationViewTest, ActionButtonRowSizeAndAlignment) {
EXPECT_GT(button_x, button->GetBoundsInScreen().x());
}
TEST_F(MediaNotificationViewTest, AccessibleNodeData) {
ui::AXNodeData data;
view()->GetAccessibleNodeData(&data);
EXPECT_TRUE(
data.HasStringAttribute(ax::mojom::StringAttribute::kRoleDescription));
EXPECT_EQ(base::ASCIIToUTF16("title - artist"), accessible_name());
}
} // namespace ash
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