Commit 46978aa9 authored by Sara Kato's avatar Sara Kato Committed by Commit Bot

Stop empty notification events from being sent

Follow up to crrev/c/2341231. This change will stop a11y alert events
that do not have a name (thus no new meaningful information) from being
sent.

With this change, empty "Alert" events will not be sent to a11y side.

being sent.

Test: manual, follow bug steps and ensure one announcement event is
Bug: b:162993006
Change-Id: If6fcf75f6e9df24013a0569b57844447eaab912e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2374924
Commit-Queue: Sara Kato <sarakato@chromium.org>
Auto-Submit: Sara Kato <sarakato@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804696}
parent 959d531e
......@@ -64,8 +64,17 @@ void MessagePopupView::UpdateContents(const Notification& notification) {
.should_make_spoken_feedback_for_popup_updates) {
ui::AXNodeData new_data;
message_view_->GetAccessibleNodeData(&new_data);
if (old_data.GetStringAttribute(ax::mojom::StringAttribute::kName) !=
new_data.GetStringAttribute(ax::mojom::StringAttribute::kName))
const std::string& new_name =
new_data.GetStringAttribute(ax::mojom::StringAttribute::kName);
const std::string& old_name =
old_data.GetStringAttribute(ax::mojom::StringAttribute::kName);
if (new_name.empty()) {
new_data.SetNameFrom(ax::mojom::NameFrom::kAttributeExplicitlyEmpty);
return;
}
if (old_name != new_name)
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
}
}
......
......@@ -44,9 +44,17 @@ base::string16 CreateAccessibleName(const Notification& notification) {
return notification.accessible_name();
// Fall back to a text constructed from the notification.
std::vector<base::string16> accessible_lines = {
notification.title(), notification.message(),
notification.context_message()};
// Add non-empty elements.
std::vector<base::string16> accessible_lines;
if (!notification.title().empty())
accessible_lines.push_back(notification.title());
if (!notification.message().empty())
accessible_lines.push_back(notification.message());
if (!notification.context_message().empty())
accessible_lines.push_back(notification.context_message());
std::vector<NotificationItem> items = notification.items();
for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") +
......@@ -203,6 +211,10 @@ void MessageView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->AddStringAttribute(
ax::mojom::StringAttribute::kRoleDescription,
l10n_util::GetStringUTF8(IDS_MESSAGE_NOTIFICATION_ACCESSIBLE_NAME));
if (accessible_name_.empty())
node_data->SetNameFrom(ax::mojom::NameFrom::kAttributeExplicitlyEmpty);
node_data->SetName(accessible_name_);
}
......
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