Chromium Code Reviews| Index: ash/system/tray_accessibility.cc |
| diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc |
| index 854e81cc5ed592d6101cbfa023b5219bf0a2c25a..e219e67875e8c353fb3b5b2279397d7de4779b8e 100644 |
| --- a/ash/system/tray_accessibility.cc |
| +++ b/ash/system/tray_accessibility.cc |
| @@ -12,6 +12,7 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_port.h" |
| #include "ash/strings/grit/ash_strings.h" |
| +#include "ash/system/system_notifier.h" |
| #include "ash/system/tray/hover_highlight_view.h" |
| #include "ash/system/tray/system_tray.h" |
| #include "ash/system/tray/system_tray_controller.h" |
| @@ -19,23 +20,16 @@ |
| #include "ash/system/tray/tray_constants.h" |
| #include "ash/system/tray/tray_details_view.h" |
| #include "ash/system/tray/tray_item_more.h" |
| -#include "ash/system/tray/tray_popup_item_style.h" |
| #include "ash/system/tray/tray_popup_utils.h" |
| #include "ash/system/tray/tri_view.h" |
| -#include "base/strings/utf_string_conversions.h" |
| #include "ui/base/l10n/l10n_util.h" |
| -#include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/gfx/paint_vector_icon.h" |
| +#include "ui/gfx/vector_icon_types.h" |
| +#include "ui/message_center/message_center.h" |
| #include "ui/native_theme/native_theme.h" |
| #include "ui/resources/grit/ui_resources.h" |
| -#include "ui/views/background.h" |
| -#include "ui/views/controls/button/custom_button.h" |
| -#include "ui/views/controls/image_view.h" |
| -#include "ui/views/controls/label.h" |
| #include "ui/views/controls/separator.h" |
| -#include "ui/views/layout/box_layout.h" |
| -#include "ui/views/layout/grid_layout.h" |
| #include "ui/views/widget/widget.h" |
| namespace ash { |
| @@ -94,6 +88,22 @@ LoginStatus GetCurrentLoginStatus() { |
| return Shell::Get()->session_controller()->login_status(); |
| } |
| +// Returns notification icon based on the enabled accessibility state. |
| +const gfx::VectorIcon& GetNotificationIcon(uint32_t enabled_accessibility) { |
| + if (enabled_accessibility & A11Y_BRAILLE_DISPLAY_CONNECTED && |
| + enabled_accessibility & A11Y_SPOKEN_FEEDBACK) { |
| + return ash::kSystemMenuAccessibilityIcon; |
| + } else { |
| + if (enabled_accessibility & A11Y_BRAILLE_DISPLAY_CONNECTED) { |
|
tdanderson
2017/05/08 21:55:27
nit: no {}'s in this inner block since everything
yiyix
2017/05/15 22:55:15
Done.
|
| + return ash::kSystemMenuAccessibilityBrailleIcon; |
| + } else if (enabled_accessibility & A11Y_SPOKEN_FEEDBACK) { |
| + return ash::kSystemMenuAccessibilityChromevoxIcon; |
| + } else { |
| + return gfx::kNoneIcon; |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| namespace tray { |
| @@ -125,84 +135,6 @@ class DefaultAccessibilityView : public TrayItemMore { |
| }; |
| //////////////////////////////////////////////////////////////////////////////// |
| -// ash::tray::AccessibilityPopupView |
| - |
| -AccessibilityPopupView::AccessibilityPopupView(uint32_t enabled_state_bits) |
| - : label_(CreateLabel(enabled_state_bits)) {} |
| - |
| -void AccessibilityPopupView::Init() { |
| - set_background(views::Background::CreateThemedSolidBackground( |
| - this, ui::NativeTheme::kColorId_BubbleBackground)); |
| - |
| - views::GridLayout* layout = new views::GridLayout(this); |
| - SetLayoutManager(layout); |
| - |
| - views::ImageView* close_button = new views::ImageView(); |
| - close_button->SetImage( |
| - ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); |
| - close_button->SetHorizontalAlignment(views::ImageView::CENTER); |
| - close_button->SetVerticalAlignment(views::ImageView::CENTER); |
| - |
| - views::ImageView* icon = new views::ImageView; |
| - icon->SetImage( |
| - gfx::CreateVectorIcon(kSystemMenuAccessibilityIcon, kMenuIconColor)); |
| - |
| - views::ColumnSet* columns = layout->AddColumnSet(0); |
| - |
| - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); |
| - |
| - // Icon |
| - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| - 0, /* resize percent */ |
| - views::GridLayout::FIXED, kNotificationIconWidth, |
| - kNotificationIconWidth); |
| - |
| - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); |
| - |
| - // Contents |
| - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| - 100, /* resize percent */ |
| - views::GridLayout::FIXED, kTrayNotificationContentsWidth, |
| - kTrayNotificationContentsWidth); |
| - |
| - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); |
| - |
| - // Close button |
| - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, |
| - 0, /* resize percent */ |
| - views::GridLayout::FIXED, kNotificationButtonWidth, |
| - kNotificationButtonWidth); |
| - |
| - // Layout rows |
| - layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| - layout->StartRow(0, 0); |
| - layout->AddView(icon); |
| - layout->AddView(label_); |
| - layout->AddView(close_button); |
| - layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| -} |
| - |
| -views::Label* AccessibilityPopupView::CreateLabel(uint32_t enabled_state_bits) { |
| - DCHECK((enabled_state_bits & |
| - (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED)) != 0); |
| - base::string16 text; |
| - if (enabled_state_bits & A11Y_BRAILLE_DISPLAY_CONNECTED) { |
| - text.append(l10n_util::GetStringUTF16( |
| - IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED_BUBBLE)); |
| - } |
| - if (enabled_state_bits & A11Y_SPOKEN_FEEDBACK) { |
| - if (!text.empty()) |
| - text.append(base::ASCIIToUTF16(" ")); |
| - text.append(l10n_util::GetStringUTF16( |
| - IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE)); |
| - } |
| - views::Label* label = new views::Label(text); |
| - label->SetMultiLine(true); |
| - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - return label; |
| -} |
| - |
| -//////////////////////////////////////////////////////////////////////////////// |
| // ash::tray::AccessibilityDetailedView |
| AccessibilityDetailedView::AccessibilityDetailedView(SystemTrayItem* owner) |
| @@ -411,14 +343,14 @@ void AccessibilityDetailedView::ShowHelp() { |
| //////////////////////////////////////////////////////////////////////////////// |
| // ash::TrayAccessibility |
| +const char kNotificationId[] = "chrome://settings/accessibility"; |
| + |
| TrayAccessibility::TrayAccessibility(SystemTray* system_tray) |
| : TrayImageItem(system_tray, |
| kSystemTrayAccessibilityIcon, |
| UMA_ACCESSIBILITY), |
| default_(NULL), |
| - detailed_popup_(NULL), |
| detailed_menu_(NULL), |
| - request_popup_view_state_(A11Y_NONE), |
| tray_icon_visible_(false), |
| login_(GetCurrentLoginStatus()), |
| previous_accessibility_state_(GetAccessibilityState()), |
| @@ -469,21 +401,12 @@ views::View* TrayAccessibility::CreateDefaultView(LoginStatus status) { |
| } |
| views::View* TrayAccessibility::CreateDetailedView(LoginStatus status) { |
| - CHECK(detailed_popup_ == NULL); |
| CHECK(detailed_menu_ == NULL); |
| - if (request_popup_view_state_) { |
| - detailed_popup_ = |
| - new tray::AccessibilityPopupView(request_popup_view_state_); |
| - detailed_popup_->Init(); |
| - request_popup_view_state_ = A11Y_NONE; |
| - return detailed_popup_; |
| - } else { |
| - ShellPort::Get()->RecordUserMetricsAction( |
| - ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY); |
| - detailed_menu_ = CreateDetailedMenu(); |
| - return detailed_menu_; |
| - } |
| + ShellPort::Get()->RecordUserMetricsAction( |
| + ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY); |
|
tdanderson
2017/05/08 21:55:27
Can you please fix the pre-existing typo in this e
yiyix
2017/05/15 22:55:15
I missed it. Make sense. Corrected.
|
| + detailed_menu_ = CreateDetailedMenu(); |
| + return detailed_menu_; |
| } |
| void TrayAccessibility::DestroyDefaultView() { |
| @@ -491,7 +414,6 @@ void TrayAccessibility::DestroyDefaultView() { |
| } |
| void TrayAccessibility::DestroyDetailedView() { |
| - detailed_popup_ = NULL; |
| detailed_menu_ = NULL; |
| } |
| @@ -516,20 +438,66 @@ void TrayAccessibility::OnAccessibilityModeChanged( |
| // return early if there's no change in the state that we keep track of. |
| if (accessibility_state == previous_accessibility_state_) |
| return; |
| + |
| + if (detailed_menu_) |
| + detailed_menu_->GetWidget()->Close(); |
| + |
| + message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, |
| + false /* by_user */); |
| + |
| // Contains bits for spoken feedback and braille display connected currently |
| // being enabled. |
| uint32_t being_enabled = |
| (accessibility_state & ~previous_accessibility_state_) & |
| (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED); |
| - if ((notify == A11Y_NOTIFICATION_SHOW) && being_enabled != A11Y_NONE) { |
| - // Shows popup if |notify| is true and the spoken feedback is being enabled. |
| - request_popup_view_state_ = being_enabled; |
| - ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| + // Shows notification if |notify| is true and the spoken feedback is being |
| + // enabled or the braille is connected, which is laid out like: |
|
tdanderson
2017/05/08 21:55:27
nit: "or if a braille device is connected"
yiyix
2017/05/15 22:55:15
Done.
|
| + // -----------------x- |
|
tdanderson
2017/05/08 21:55:27
nit: no need for lines 455-6 any more since we're
yiyix
2017/05/15 22:55:15
Done.
|
| + // | icon contents | |
| + // ------------------- |
| + if ((notify == A11Y_NOTIFICATION_SHOW) && being_enabled && |
|
tdanderson
2017/05/08 21:55:27
nit: innermost () not needed
yiyix
2017/05/15 22:55:15
Done.
|
| + being_enabled != A11Y_NONE) { |
| + message_center::MessageCenter* message_center = |
| + message_center::MessageCenter::Get(); |
| + if (!message_center) |
| + return; |
| + |
| + std::unique_ptr<message_center::Notification> notification; |
| + |
| + base::string16 text; |
| + base::string16 title; |
| + if (being_enabled & A11Y_BRAILLE_DISPLAY_CONNECTED && |
| + being_enabled & A11Y_SPOKEN_FEEDBACK) { |
| + text.append(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_BRAILLE_ENABLED)); |
| + title.append(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_BRAILLE_ENABLED_TITLE)); |
| + } else { |
| + if (being_enabled & A11Y_BRAILLE_DISPLAY_CONNECTED) { |
| + text.append(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED)); |
| + } else { |
| + title.append(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TITLE)); |
| + text.append(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED)); |
| + } |
| + } |
| + |
| + notification = base::MakeUnique<message_center::Notification>( |
| + message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, title, text, |
| + gfx::Image(gfx::CreateVectorIcon(GetNotificationIcon(being_enabled), |
| + ash::kMenuIconSize, |
| + ash::kMenuIconColor)), |
| + base::string16(), GURL(), |
| + message_center::NotifierId(message_center::NotifierId::APPLICATION, |
| + system_notifier::kNotifierAccessibility), |
| + message_center::RichNotificationData(), nullptr); |
| + message_center->AddNotification(std::move(notification)); |
| + |
| } else { |
| - if (detailed_popup_) |
| - detailed_popup_->GetWidget()->Close(); |
| - if (detailed_menu_) |
| - detailed_menu_->GetWidget()->Close(); |
| + message_center::MessageCenter::Get()->RemoveNotification( |
| + kNotificationId, false /* by_user */); |
| } |
| previous_accessibility_state_ = accessibility_state; |