Chromium Code Reviews| 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..6d1e632ced8cc5df2dc492f85c3b4dced5e2a916 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); |
| + const base::string16 text() { return text_; } |
|
tapted
2016/07/12 00:51:39
`const` needs to come after the () (`const` on ret
Patti Lor
2016/07/19 01:31:51
Done, sorry for the misunderstanding!
|
| 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()); |
| + |
| + NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| + NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| } |
| // static |
| @@ -206,5 +215,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) { |
| + 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, fall back to the text displayed. |
| + 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); |
| +} |