Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1201)

Unified Diff: chrome/browser/ui/views/subtle_notification_view.cc

Issue 2010493005: a11y/Mac: Add screenreader support for SubtleNotificationView announcements. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/subtle_notification_view.cc
diff --git a/chrome/browser/ui/views/subtle_notification_view.cc b/chrome/browser/ui/views/subtle_notification_view.cc
index e922234e53cf93c417d23dd03f0c75e90bb06556..a7ba5c4ef5932989f99b3bda48057cf4167911ee 100644
--- a/chrome/browser/ui/views/subtle_notification_view.cc
+++ b/chrome/browser/ui/views/subtle_notification_view.cc
@@ -7,8 +7,10 @@
#include <memory>
#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/accessibility/ax_view_state.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font_list.h"
#include "ui/views/bubble/bubble_border.h"
@@ -16,6 +18,7 @@
#include "ui/views/controls/link.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
+#include "ui/views/widget/widget_observer.h"
namespace {
@@ -34,6 +37,9 @@ const int kKeyNameBorderPx = 1;
const int kKeyNameCornerRadius = 2;
const int kKeyNamePaddingPx = 5;
+// Delimiter indicating there should be a segment displayed as a keyboard key.
+const char kKeyNameDelimiter[] = "|";
+
} // namespace
// Class containing the instruction text. Contains fancy styling on the keyboard
@@ -49,6 +55,7 @@ class SubtleNotificationView::InstructionView : public views::View {
SkColor foreground_color,
SkColor background_color);
+ base::string16 text() const { return text_; }
void SetText(const base::string16& text);
private:
@@ -92,8 +99,8 @@ void SubtleNotificationView::InstructionView::SetText(
// Parse |text|, looking for pipe-delimited segment.
std::vector<base::string16> segments =
- base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ base::SplitString(text, base::ASCIIToUTF16(kKeyNameDelimiter),
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// SplitString() returns empty strings for zero-length segments, so given an
// even number of pipes, there should always be an odd number of segments.
// The exception is if |text| is entirely empty, in which case the returned
@@ -183,6 +190,9 @@ void SubtleNotificationView::UpdateContent(
link_->SetText(link_text);
link_->SetVisible(!link_text.empty());
Layout();
+
+ NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, true);
+ NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
}
// static
@@ -207,5 +217,40 @@ views::Widget* SubtleNotificationView::CreatePopupWidget(
// animation. Remove it.
popup->GetRootView()->SetLayoutManager(nullptr);
+ // Allow accessibility events to be sent when the view is shown.
+ popup->AddObserver(view);
+
return popup;
}
+
+void SubtleNotificationView::SetAccessibleName(
+ const base::string16& accessible_name) {
+ base::RemoveChars(accessible_name, base::ASCIIToUTF16(kKeyNameDelimiter),
+ &accessible_name_);
+}
+
+void SubtleNotificationView::GetAccessibleState(ui::AXViewState* state) {
+ state->role = ui::AX_ROLE_LABEL_TEXT;
+
+ // If there is no accessible name set, use the displayed text, but ensure the
+ // '|' delimiters are removed.
+ if (accessible_name_.empty()) {
+ base::string16 accessible_name;
+ base::RemoveChars(instruction_view_->text(),
+ base::ASCIIToUTF16(kKeyNameDelimiter), &accessible_name);
+ state->name = accessible_name;
+ } else {
+ state->name = accessible_name_;
+ }
+}
+
+void SubtleNotificationView::OnWidgetClosing(views::Widget* widget) {
+ if (widget && widget == GetWidget())
+ widget->RemoveObserver(this);
+}
+
+void SubtleNotificationView::OnWidgetVisibilityChanged(views::Widget* widget,
+ bool visible) {
+ if (visible)
+ NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
+}
« no previous file with comments | « chrome/browser/ui/views/subtle_notification_view.h ('k') | ui/accessibility/platform/ax_platform_node_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698