Chromium Code Reviews| Index: ash/system/tray_accessibility.cc |
| diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc |
| index 7b7a3be9457193802436c86164e326205bca91a5..b8566c76ba03c88f991e26882030dfc80795fa0b 100644 |
| --- a/ash/system/tray_accessibility.cc |
| +++ b/ash/system/tray_accessibility.cc |
| @@ -6,7 +6,11 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_delegate.h" |
| +#include "ash/system/tray/system_tray.h" |
| +#include "ash/system/tray/system_tray_delegate.h" |
| #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_views.h" |
| #include "grit/ash_resources.h" |
| #include "grit/ash_strings.h" |
| @@ -20,82 +24,257 @@ |
| namespace ash { |
| namespace internal { |
| -class DefaultAccessibilityView : public ActionableView { |
| +namespace { |
| + |
| +bool IsAnyAccessibilityFeatureEnabled() { |
| + ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); |
| + return shell_delegate && |
| + (shell_delegate->IsSpokenFeedbackEnabled() || |
| + shell_delegate->IsHighContrastEnabled() || |
| + shell_delegate->GetScreenMagnifierType() == ash::MAGNIFIER_FULL); |
|
Zachary Kuznia
2012/11/21 08:07:12
!= ash::MAGNIFIER_NONE
yoshiki
2012/11/21 14:48:04
Done.
|
| +} |
| + |
| +user::LoginStatus GetCurrentLoginStatus() { |
| + SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate(); |
| + return tray_delegate ? |
| + tray_delegate->GetUserLoginStatus() : |
| + user::LOGGED_IN_NONE; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace tray { |
| + |
| +class DefaultAccessibilityView : public TrayItemMore { |
| public: |
| - DefaultAccessibilityView() { |
| + explicit DefaultAccessibilityView(SystemTrayItem* owner) |
| + : TrayItemMore(owner, true) { |
| SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| kTrayPopupPaddingHorizontal, |
| 0, |
| kTrayPopupPaddingBetweenItems)); |
| ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| - FixedSizedImageView* image = |
| - new FixedSizedImageView(0, kTrayPopupItemHeight); |
| - image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| + SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| ToImageSkia()); |
| - |
| - AddChildView(image); |
| string16 label = bundle.GetLocalizedString( |
| - IDS_ASH_STATUS_TRAY_DISABLE_SPOKEN_FEEDBACK); |
| - AddChildView(new views::Label(label)); |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY); |
| + SetLabel(label); |
| SetAccessibleName(label); |
| } |
| virtual ~DefaultAccessibilityView() {} |
| - protected: |
| - // Overridden from ActionableView. |
| - virtual bool PerformAction(const ui::Event& event) OVERRIDE { |
| - if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) |
| - Shell::GetInstance()->delegate()->ToggleSpokenFeedback(); |
| - GetWidget()->Close(); |
| - return true; |
| + private: |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); |
| +}; |
| + |
| +class AccessibilityDetailedView : public TrayDetailsView, |
| + public ViewClickListener, |
| + public views::ButtonListener, |
| + public ShellObserver { |
| + public: |
| + AccessibilityDetailedView(user::LoginStatus login) : |
| + spoken_feedback_view_(NULL), |
| + high_contrast_view_(NULL), |
| + screen_magnifier_view_(NULL), |
| + help_view_(NULL) { |
| + login_ = login; |
| + |
| + Reset(); |
| + |
| + AppendAccessibilityList(); |
| + AppendHelpEntries(); |
| + CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this); |
| + |
| + Layout(); |
| + } |
| + |
| + virtual ~AccessibilityDetailedView() { |
| } |
| private: |
| + // Add the accessibility feature list. |
| + void AppendAccessibilityList() { |
| + CreateScrollableList(); |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| - DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); |
| + ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); |
| + bool spoken_feedback_enabled = |
| + shell_delegate && shell_delegate->IsSpokenFeedbackEnabled(); |
| + spoken_feedback_view_ = AddScrollListItem( |
| + bundle.GetLocalizedString( |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK), |
| + spoken_feedback_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, |
| + spoken_feedback_enabled); |
| + bool high_contrast_mode_enabled = |
| + shell_delegate && shell_delegate->IsHighContrastEnabled(); |
| + high_contrast_view_ = AddScrollListItem( |
| + bundle.GetLocalizedString( |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), |
| + high_contrast_mode_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, |
| + high_contrast_mode_enabled); |
| + bool screen_magnifier_enabled = |
| + shell_delegate && |
| + shell_delegate->GetScreenMagnifierType() == ash::MAGNIFIER_FULL; |
| + screen_magnifier_view_ = AddScrollListItem( |
| + bundle.GetLocalizedString( |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), |
| + screen_magnifier_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL, |
| + screen_magnifier_enabled); |
| + } |
| + |
| + // Add help entries. |
| + void AppendHelpEntries() { |
| + // Currently the help page requires a browser window. |
| + // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286 |
| + if (login_ == user::LOGGED_IN_NONE || |
| + login_ == user::LOGGED_IN_LOCKED) |
| + return; |
| + |
| + TrayPopupTextButtonContainer* bottom_row = |
| + new TrayPopupTextButtonContainer; |
| + |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + |
| + TrayPopupTextButton* help = new TrayPopupTextButton( |
| + this, |
| + bundle.GetLocalizedString( |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE)); |
| + bottom_row->AddTextButton(help); |
| + help_view_ = help; |
| + AddChildView(bottom_row); |
| + } |
| + |
| + HoverHighlightView* AddScrollListItem(const string16& text, |
| + gfx::Font::FontStyle style, |
| + bool checked) { |
| + HoverHighlightView* container = new HoverHighlightView(this); |
| + container->set_fixed_height(kTrayPopupItemHeight); |
| + container->AddCheckableLabel(text, style, checked); |
| + scroll_content()->AddChildView(container); |
| + return container; |
| + } |
| + |
| + // Overridden from ViewClickListener. |
| + virtual void ClickedOn(views::View* sender) OVERRIDE { |
| + ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); |
| + if (sender == footer()->content()) { |
| + Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| + } else if (sender == spoken_feedback_view_) { |
| + shell_delegate->ToggleSpokenFeedback(); |
| + } else if (sender == high_contrast_view_) { |
| + shell_delegate->ToggleHighContrast(); |
| + } else if (sender == screen_magnifier_view_) { |
| + bool screen_magnifier_enabled = |
| + shell_delegate->GetScreenMagnifierType() == ash::MAGNIFIER_FULL; |
| + shell_delegate->SetScreenMagnifier( |
| + screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL); |
| + } |
| + } |
| + |
| + // Overridden from ButtonListener. |
| + virtual void ButtonPressed(views::Button* sender, |
| + const ui::Event& event) OVERRIDE { |
| + SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate(); |
| + if (sender == help_view_) { |
| + tray_delegate->ShowAccessibilityHelp(); |
| + } |
| + } |
| + |
| + views::View* spoken_feedback_view_; |
| + views::View* high_contrast_view_; |
| + views::View* screen_magnifier_view_;; |
| + views::View* help_view_; |
| + user::LoginStatus login_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AccessibilityDetailedView); |
| +}; |
| + |
| +class AccessibilityPopupView : public views::View { |
| + public: |
| + AccessibilityPopupView() { |
| + SetLayoutManager( |
| + new views::BoxLayout(views::BoxLayout::kHorizontal, |
| + kTrayPopupPaddingHorizontal, |
| + 10, |
| + kTrayPopupPaddingBetweenItems)); |
| + |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + views::ImageView* image = new views::ImageView; |
| + image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| + ToImageSkia()); |
| + AddChildView(image); |
| + |
| + AddChildView(new views::Label(bundle.GetLocalizedString( |
| + IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE))); |
| + |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); |
| }; |
| +} // namespace tray |
| + |
| + |
| TrayAccessibility::TrayAccessibility() |
| : TrayImageItem(IDR_AURA_UBER_TRAY_ACCESSIBILITY), |
| default_(NULL), |
| - detailed_(NULL) { |
| + detailed_(NULL), |
| + request_popup_view_(false), |
| + previous_accessibility_status_(IsAnyAccessibilityFeatureEnabled()), |
| + login_(GetCurrentLoginStatus()) { |
| + Shell::GetInstance()->AddShellObserver(this); |
| } |
| -TrayAccessibility::~TrayAccessibility() {} |
| +TrayAccessibility::~TrayAccessibility() { |
| + Shell::GetInstance()->RemoveShellObserver(this); |
| +} |
| bool TrayAccessibility::GetInitialVisibility() { |
| - return Shell::GetInstance()->delegate() && |
| - Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled(); |
| + ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| + if (!delegate) |
| + return false; |
| + |
| + // Always shows this on the login screen. |
| + if (login_ == user::LOGGED_IN_NONE) |
| + return true; |
| + |
| + if (delegate->AlwaysShowAccessibilityMenu() || |
| + IsAnyAccessibilityFeatureEnabled()) { |
| + return true; |
| + } |
| + |
| + return false; |
| } |
| views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { |
| - if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) |
| + CHECK(default_ == NULL); |
| + |
| + login_ = status; |
| + |
| + if (!GetInitialVisibility()) |
| return NULL; |
| CHECK(default_ == NULL); |
| - default_ = new DefaultAccessibilityView(); |
| + default_ = new tray::DefaultAccessibilityView(this); |
| return default_; |
| } |
| views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { |
| CHECK(detailed_ == NULL); |
| - detailed_ = new views::View; |
| - |
| - detailed_->SetLayoutManager(new |
| - views::BoxLayout(views::BoxLayout::kHorizontal, |
| - kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); |
| - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| - views::ImageView* image = new views::ImageView; |
| - image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). |
| - ToImageSkia()); |
| + login_ = status; |
| - detailed_->AddChildView(image); |
| - detailed_->AddChildView(new views::Label(bundle.GetLocalizedString( |
| - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE))); |
| + if (request_popup_view_) { |
| + detailed_ = new tray::AccessibilityPopupView(); |
| + request_popup_view_ = false; |
| + } else { |
| + detailed_ = new tray::AccessibilityDetailedView(status); |
| + } |
| return detailed_; |
| } |
| @@ -108,15 +287,27 @@ void TrayAccessibility::DestroyDetailedView() { |
| detailed_ = NULL; |
| } |
| -void TrayAccessibility::OnAccessibilityModeChanged(bool enabled) { |
| +void TrayAccessibility::OnLoginStateChanged(user::LoginStatus status) { |
| + login_ = status; |
| + |
| + if (tray_view()) |
| + tray_view()->SetVisible(GetInitialVisibility()); |
| +} |
| + |
| +void TrayAccessibility::OnAccessibilityModeChanged() { |
| if (tray_view()) |
| - tray_view()->SetVisible(enabled); |
| + tray_view()->SetVisible(GetInitialVisibility()); |
| - if (enabled) { |
| + bool current_accessibility_status = IsAnyAccessibilityFeatureEnabled(); |
| + if (!previous_accessibility_status_ && current_accessibility_status) { |
| + // Show popup if the accessibily status is being changed to true from false. |
| + request_popup_view_ = true; |
| PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| } else if (detailed_) { |
| detailed_->GetWidget()->Close(); |
| } |
| + |
| + previous_accessibility_status_ = current_accessibility_status; |
| } |
| } // namespace internal |