Index: ash/system/tray_accessibility.cc |
diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc |
index 7ea654d5a24ac744362d5406fd322997410589c2..3c545f544dea34024afbbc83bab4fb5e48a7a7b2 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,270 @@ |
namespace ash { |
namespace internal { |
-class DefaultAccessibilityView : public ActionableView { |
+namespace { |
+const int kPaddingAroundBottomRow = 5; |
+ |
+bool IsAnyAccessibilityFeatureEnabled() { |
+ ShellDelegate* shell_delegate = Shell::GetInstance()->delegate(); |
+ return shell_delegate && |
+ (shell_delegate->IsSpokenFeedbackEnabled() || |
+ shell_delegate->IsHighContrastEnabled() || |
+ shell_delegate->GetMagnifierType() != ash::MAGNIFIER_OFF); |
+} |
+ |
+user::LoginStatus GetCurrentLoginStatus() { |
+ SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate(); |
stevenjb
2012/11/26 19:32:11
tray_delegate() is safe to call outside of destruc
yoshiki
2012/11/28 12:35:29
Done.
|
+ 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: |
+ explicit AccessibilityDetailedView(SystemTrayItem* owner, |
+ user::LoginStatus login) : |
+ TrayDetailsView(owner), |
+ spoken_feedback_view_(NULL), |
+ high_contrast_view_(NULL), |
+ screen_magnifier_view_(NULL), |
+ help_view_(NULL) { |
+ login_ = login; |
stevenjb
2012/11/26 19:32:11
login_(login)
yoshiki
2012/11/28 12:35:29
Done.
|
+ |
+ Reset(); |
+ |
+ AppendAccessibilityList(); |
+ AppendHelpEntries(); |
+ CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this); |
+ |
+ Layout(); |
+ } |
+ |
+ virtual ~AccessibilityDetailedView() { |
} |
stevenjb
2012/11/26 19:32:11
Make WS consistent with ~DefaultAccessibilityView(
yoshiki
2012/11/28 12:35:29
Done. (WS means curly brackets, right?)
|
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->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->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->GetMagnifierType() == 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; |
+ |
+ views::BoxLayout* layout = new |
+ views::BoxLayout(views::BoxLayout::kHorizontal, |
+ kPaddingAroundBottomRow, |
+ kPaddingAroundBottomRow, |
+ -1); |
stevenjb
2012/11/26 19:32:11
Comment -1 or use an appropriately named const
yoshiki
2012/11/28 12:35:29
Done. And changed network_list_detailed_view_base.
|
+ layout->set_spread_blank_space(true); |
+ views::View* bottom_row = new View(); |
stevenjb
2012/11/26 19:32:11
nit: Construct bottom_row before layout (makes the
yoshiki
2012/11/28 12:35:29
Done.
|
+ bottom_row->SetLayoutManager(layout); |
+ |
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
+ |
+ TrayPopupLabelButton* help = new TrayPopupLabelButton( |
+ this, |
+ bundle.GetLocalizedString( |
+ IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE)); |
+ bottom_row->AddChildView(help); |
+ help_view_ = help; |
+ |
+ // TODO(yoshiki): Add "Customize accessibility" button when the customize is |
+ // available. crbug.com/158281 |
+ |
+ 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); |
stevenjb
2012/11/26 19:32:11
Use owner->system_tray() instead of Shell::GetInst
yoshiki
2012/11/28 12:35:29
Done.
|
+ } 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->GetMagnifierType() == 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(); |
+ } |
stevenjb
2012/11/26 19:32:11
nit: {} unnecessary
yoshiki
2012/11/28 12:35:29
Done.
|
+ } |
+ |
+ 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, |
stevenjb
2012/11/26 19:32:11
Use a const for 10
yoshiki
2012/11/28 12:35:29
I removed this part by using TrayNotificationView.
|
+ 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(SystemTray* system_tray) |
: TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), |
default_(NULL), |
- detailed_(NULL) { |
+ detailed_(NULL), |
+ request_popup_view_(false), |
+ accessibility_previously_enabled_(IsAnyAccessibilityFeatureEnabled()), |
+ login_(GetCurrentLoginStatus()) { |
+ DCHECK(Shell::GetInstance()->delegate()); |
+ DCHECK(system_tray); |
+ |
+ // This class and related classes use Shell::system_tray() instead of the |
+ // given system_tray. They should be same. |
+ DCHECK(system_tray == Shell::GetInstance()->system_tray()); |
stevenjb
2012/11/26 19:32:11
We are planning to deprecate Shell::GetInstance()-
yoshiki
2012/11/28 12:35:29
Done.
|
+ |
+ 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(); |
+ // Always shows this on the login screen. |
+ if (login_ == user::LOGGED_IN_NONE) |
+ return true; |
+ |
+ if (delegate->ShouldAlwaysShowAccessibilityMenu() || |
+ 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(this, status); |
+ } |
return detailed_; |
} |
@@ -108,15 +300,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(enabled); |
+ tray_view()->SetVisible(GetInitialVisibility()); |
+} |
+ |
+void TrayAccessibility::OnAccessibilityModeChanged() { |
+ if (tray_view()) |
+ tray_view()->SetVisible(GetInitialVisibility()); |
- if (enabled) { |
+ bool current_accessibility_status = IsAnyAccessibilityFeatureEnabled(); |
Daniel Erat
2012/11/26 18:11:39
nit: rename to accessibility_enabled?
yoshiki
2012/11/28 12:35:29
Done.
|
+ if (!accessibility_previously_enabled_ && current_accessibility_status) { |
+ // Show popup if the accessibily status is being changed to true from false. |
Daniel Erat
2012/11/26 18:11:39
nit: accessibility
yoshiki
2012/11/28 12:35:29
Done.
|
+ request_popup_view_ = true; |
PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
} else if (detailed_) { |
detailed_->GetWidget()->Close(); |
} |
+ |
+ accessibility_previously_enabled_ = current_accessibility_status; |
} |
} // namespace internal |