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

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, 6 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 8d42713d9d59bbfab42d6ea49c257883f5927e4d..d7d52e4cedddd214b876c60f64e545454dc4d1ed 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[] = "|";
tapted 2016/07/11 03:46:47 hum - this should probably be a const char16 []. T
Patti Lor 2016/07/12 00:04:36 Done.
Matt Giuca 2016/07/14 01:16:02 Hmm, I don't really like this (I wrote a whole com
tapted 2016/07/14 01:48:40 my brain sees arrays and string literals as interc
Patti Lor 2016/07/19 01:31:51 Have taken Matt's suggestion to keep it as a char
+
} // namespace
// Class containing the instruction text. Contains fancy styling on the keyboard
@@ -42,13 +48,17 @@ class SubtleNotificationView::InstructionView : public views::View {
public:
// Creates an InstructionView with specific text. |text| may contain one or
// more segments delimited by a pair of pipes ('|'); each of these segments
- // will be displayed as a keyboard key. e.g., "Press |Alt|+|Q| to exit" will
+ // will be displayed as a keyboard key. e.g. "Press |Alt|+|Q| to exit" will
tapted 2016/07/11 03:46:47 (ubernit: technically, a comma should "always" com
Patti Lor 2016/07/12 00:04:36 Oops, didn't notice that! Noted for future referen
Matt Giuca 2016/07/14 01:16:02 Also I had a comma there in the first place :)
Patti Lor 2016/07/19 01:31:51 Haha, yup, that's what I meant D: Didn't copy and
// have "Alt" and "Q" rendered as keys.
InstructionView(const base::string16& text,
const gfx::FontList& font_list,
SkColor foreground_color,
SkColor background_color);
+ base::string16 accessible_name() { return accessible_name_; }
tapted 2016/07/11 03:46:47 nit: const method
Patti Lor 2016/07/12 00:04:36 Done.
+ void SetAccessibleName(const base::string16& accessible_name);
+
+ base::string16 text() { return text_; }
tapted 2016/07/11 03:46:47 nit: const
Patti Lor 2016/07/12 00:04:36 Done.
void SetText(const base::string16& text);
private:
@@ -61,6 +71,10 @@ class SubtleNotificationView::InstructionView : public views::View {
SkColor foreground_color_;
SkColor background_color_;
+ // Text to read out on displaying this notification for screenreaders, with
+ // unicode characters expanded.
+ base::string16 accessible_name_;
tapted 2016/07/11 03:46:47 If it achieves the same thing, I think it makes mo
Patti Lor 2016/07/12 00:04:36 Done.
+
base::string16 text_;
DISALLOW_COPY_AND_ASSIGN(InstructionView);
@@ -82,6 +96,12 @@ SubtleNotificationView::InstructionView::InstructionView(
SetText(text);
}
+void SubtleNotificationView::InstructionView::SetAccessibleName(
+ const base::string16& accessible_name) {
+ base::RemoveChars(accessible_name, base::ASCIIToUTF16(kKeyNameDelimiter),
+ &accessible_name_);
+}
+
void SubtleNotificationView::InstructionView::SetText(
const base::string16& text) {
// Avoid replacing the contents with the same text.
@@ -92,8 +112,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
@@ -182,6 +202,9 @@ void SubtleNotificationView::UpdateContent(
instruction_view_->SetVisible(!instruction_text.empty());
link_->SetText(link_text);
link_->SetVisible(!link_text.empty());
+
+ NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
+ NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
}
// static
@@ -206,5 +229,33 @@ 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) {
+ instruction_view_->SetAccessibleName(accessible_name);
+}
+
+void SubtleNotificationView::GetAccessibleState(ui::AXViewState* state) {
+ state->role = ui::AX_ROLE_LABEL_TEXT;
+
+ // If there is no accessible name set, fall back to the text displayed.
+ if (instruction_view_->accessible_name().empty())
tapted 2016/07/11 03:46:47 Can this happen?
Patti Lor 2016/07/12 00:04:36 Yes, currently the new backspace shortcut bubble i
tapted 2016/07/12 00:51:39 Ah. So, it's "generally" good to avoid side-effect
Matt Giuca 2016/07/14 01:16:02 This is a good point. How about we *pretend* that
Patti Lor 2016/07/19 01:31:51 A point Matt brought up in one of his other commen
+ SetAccessibleName(instruction_view_->text());
+ state->name = instruction_view_->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);
+}

Powered by Google App Engine
This is Rietveld 408576698