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

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: Address review comments. Created 4 years, 5 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..5b49381699ff80abb1a8308ca34e65d8186d9646 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 base::char16 kKeyNameDelimiter[] = {'|', '\0'};
+
} // 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:
@@ -91,9 +98,8 @@ void SubtleNotificationView::InstructionView::SetText(
RemoveAllChildViews(true);
// Parse |text|, looking for pipe-delimited segment.
- std::vector<base::string16> segments =
- base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ std::vector<base::string16> segments = base::SplitString(
+ text, 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 +188,9 @@ void SubtleNotificationView::UpdateContent(
instruction_view_->SetVisible(!instruction_text.empty());
link_->SetText(link_text);
link_->SetVisible(!link_text.empty());
Matt Giuca 2016/07/14 01:16:02 I think you have to clear accessible_name_ here, o
Patti Lor 2016/07/19 01:31:51 :O Good catch thank you! I ended up changing the w
+
+ NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
dmazzoni 2016/07/13 23:41:35 I think AX_EVENT_CHILDREN_CHANGED would be better
Patti Lor 2016/07/19 01:31:51 Done, thanks. Would you say |link_| and |instructi
tapted 2016/07/19 02:46:53 Yeah - this may depend on how we solve http://crbu
+ NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
}
// static
@@ -206,5 +215,34 @@ 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, 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.
dmazzoni 2016/07/13 23:41:35 What code removes the | delimiters?
Matt Giuca 2016/07/14 01:16:02 SetAccessibleName, just above, does this. I agree
Patti Lor 2016/07/19 01:31:51 Have removed the side effect here, and left the co
+ if (accessible_name_.empty())
+ SetAccessibleName(instruction_view_->text());
+ 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