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

Side by Side Diff: ash/system/tray_accessibility.cc

Issue 11415025: A11y: Introduce High Contrast Mode and Screen Magnifier to ubar tray. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/tray_accessibility.h" 5 #include "ash/system/tray_accessibility.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 8 #include "ash/shell_delegate.h"
9 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 11 #include "ash/system/tray/tray_constants.h"
12 #include "ash/system/tray/tray_details_view.h"
13 #include "ash/system/tray/tray_item_more.h"
10 #include "ash/system/tray/tray_views.h" 14 #include "ash/system/tray/tray_views.h"
11 #include "grit/ash_resources.h" 15 #include "grit/ash_resources.h"
12 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
13 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
15 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h" 21 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
19 23
20 namespace ash { 24 namespace ash {
21 namespace internal { 25 namespace internal {
22 26
23 class DefaultAccessibilityView : public ActionableView { 27 namespace {
28
29 bool IsAnyAccessibilityFeatureEnabled() {
30 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
31 return shell_delegate &&
32 (shell_delegate->IsSpokenFeedbackEnabled() ||
33 shell_delegate->IsHighContrastEnabled() ||
34 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.
35 }
36
37 user::LoginStatus GetCurrentLoginStatus() {
38 SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate();
39 return tray_delegate ?
40 tray_delegate->GetUserLoginStatus() :
41 user::LOGGED_IN_NONE;
42 }
43
44 } // namespace
45
46 namespace tray {
47
48 class DefaultAccessibilityView : public TrayItemMore {
24 public: 49 public:
25 DefaultAccessibilityView() { 50 explicit DefaultAccessibilityView(SystemTrayItem* owner)
51 : TrayItemMore(owner, true) {
26 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 52 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
27 kTrayPopupPaddingHorizontal, 53 kTrayPopupPaddingHorizontal,
28 0, 54 0,
29 kTrayPopupPaddingBetweenItems)); 55 kTrayPopupPaddingBetweenItems));
30 56
31 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 57 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
32 FixedSizedImageView* image = 58 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK).
33 new FixedSizedImageView(0, kTrayPopupItemHeight); 59 ToImageSkia());
60 string16 label = bundle.GetLocalizedString(
61 IDS_ASH_STATUS_TRAY_ACCESSIBILITY);
62 SetLabel(label);
63 SetAccessibleName(label);
64 }
65
66 virtual ~DefaultAccessibilityView() {}
67
68 private:
69
70 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
71 };
72
73 class AccessibilityDetailedView : public TrayDetailsView,
74 public ViewClickListener,
75 public views::ButtonListener,
76 public ShellObserver {
77 public:
78 AccessibilityDetailedView(user::LoginStatus login) :
79 spoken_feedback_view_(NULL),
80 high_contrast_view_(NULL),
81 screen_magnifier_view_(NULL),
82 help_view_(NULL) {
83 login_ = login;
84
85 Reset();
86
87 AppendAccessibilityList();
88 AppendHelpEntries();
89 CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this);
90
91 Layout();
92 }
93
94 virtual ~AccessibilityDetailedView() {
95 }
96
97 private:
98 // Add the accessibility feature list.
99 void AppendAccessibilityList() {
100 CreateScrollableList();
101 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
102
103 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
104 bool spoken_feedback_enabled =
105 shell_delegate && shell_delegate->IsSpokenFeedbackEnabled();
106 spoken_feedback_view_ = AddScrollListItem(
107 bundle.GetLocalizedString(
108 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK),
109 spoken_feedback_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
110 spoken_feedback_enabled);
111 bool high_contrast_mode_enabled =
112 shell_delegate && shell_delegate->IsHighContrastEnabled();
113 high_contrast_view_ = AddScrollListItem(
114 bundle.GetLocalizedString(
115 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE),
116 high_contrast_mode_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
117 high_contrast_mode_enabled);
118 bool screen_magnifier_enabled =
119 shell_delegate &&
120 shell_delegate->GetScreenMagnifierType() == ash::MAGNIFIER_FULL;
121 screen_magnifier_view_ = AddScrollListItem(
122 bundle.GetLocalizedString(
123 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER),
124 screen_magnifier_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
125 screen_magnifier_enabled);
126 }
127
128 // Add help entries.
129 void AppendHelpEntries() {
130 // Currently the help page requires a browser window.
131 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286
132 if (login_ == user::LOGGED_IN_NONE ||
133 login_ == user::LOGGED_IN_LOCKED)
134 return;
135
136 TrayPopupTextButtonContainer* bottom_row =
137 new TrayPopupTextButtonContainer;
138
139 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
140
141 TrayPopupTextButton* help = new TrayPopupTextButton(
142 this,
143 bundle.GetLocalizedString(
144 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE));
145 bottom_row->AddTextButton(help);
146 help_view_ = help;
147 AddChildView(bottom_row);
148 }
149
150 HoverHighlightView* AddScrollListItem(const string16& text,
151 gfx::Font::FontStyle style,
152 bool checked) {
153 HoverHighlightView* container = new HoverHighlightView(this);
154 container->set_fixed_height(kTrayPopupItemHeight);
155 container->AddCheckableLabel(text, style, checked);
156 scroll_content()->AddChildView(container);
157 return container;
158 }
159
160 // Overridden from ViewClickListener.
161 virtual void ClickedOn(views::View* sender) OVERRIDE {
162 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
163 if (sender == footer()->content()) {
164 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
165 } else if (sender == spoken_feedback_view_) {
166 shell_delegate->ToggleSpokenFeedback();
167 } else if (sender == high_contrast_view_) {
168 shell_delegate->ToggleHighContrast();
169 } else if (sender == screen_magnifier_view_) {
170 bool screen_magnifier_enabled =
171 shell_delegate->GetScreenMagnifierType() == ash::MAGNIFIER_FULL;
172 shell_delegate->SetScreenMagnifier(
173 screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL);
174 }
175 }
176
177 // Overridden from ButtonListener.
178 virtual void ButtonPressed(views::Button* sender,
179 const ui::Event& event) OVERRIDE {
180 SystemTrayDelegate* tray_delegate = Shell::GetInstance()->tray_delegate();
181 if (sender == help_view_) {
182 tray_delegate->ShowAccessibilityHelp();
183 }
184 }
185
186 views::View* spoken_feedback_view_;
187 views::View* high_contrast_view_;
188 views::View* screen_magnifier_view_;;
189 views::View* help_view_;
190 user::LoginStatus login_;
191
192 DISALLOW_COPY_AND_ASSIGN(AccessibilityDetailedView);
193 };
194
195 class AccessibilityPopupView : public views::View {
196 public:
197 AccessibilityPopupView() {
198 SetLayoutManager(
199 new views::BoxLayout(views::BoxLayout::kHorizontal,
200 kTrayPopupPaddingHorizontal,
201 10,
202 kTrayPopupPaddingBetweenItems));
203
204 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
205 views::ImageView* image = new views::ImageView;
34 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). 206 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK).
35 ToImageSkia()); 207 ToImageSkia());
36
37 AddChildView(image); 208 AddChildView(image);
38 string16 label = bundle.GetLocalizedString( 209
39 IDS_ASH_STATUS_TRAY_DISABLE_SPOKEN_FEEDBACK); 210 AddChildView(new views::Label(bundle.GetLocalizedString(
40 AddChildView(new views::Label(label)); 211 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE)));
41 SetAccessibleName(label); 212
42 }
43
44 virtual ~DefaultAccessibilityView() {}
45
46 protected:
47 // Overridden from ActionableView.
48 virtual bool PerformAction(const ui::Event& event) OVERRIDE {
49 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
50 Shell::GetInstance()->delegate()->ToggleSpokenFeedback();
51 GetWidget()->Close();
52 return true;
53 } 213 }
54 214
55 private: 215 private:
56 216 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView);
57 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
58 }; 217 };
59 218
219 } // namespace tray
220
221
60 TrayAccessibility::TrayAccessibility() 222 TrayAccessibility::TrayAccessibility()
61 : TrayImageItem(IDR_AURA_UBER_TRAY_ACCESSIBILITY), 223 : TrayImageItem(IDR_AURA_UBER_TRAY_ACCESSIBILITY),
62 default_(NULL), 224 default_(NULL),
63 detailed_(NULL) { 225 detailed_(NULL),
64 } 226 request_popup_view_(false),
65 227 previous_accessibility_status_(IsAnyAccessibilityFeatureEnabled()),
66 TrayAccessibility::~TrayAccessibility() {} 228 login_(GetCurrentLoginStatus()) {
229 Shell::GetInstance()->AddShellObserver(this);
230 }
231
232 TrayAccessibility::~TrayAccessibility() {
233 Shell::GetInstance()->RemoveShellObserver(this);
234 }
67 235
68 bool TrayAccessibility::GetInitialVisibility() { 236 bool TrayAccessibility::GetInitialVisibility() {
69 return Shell::GetInstance()->delegate() && 237 ShellDelegate* delegate = Shell::GetInstance()->delegate();
70 Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled(); 238 if (!delegate)
239 return false;
240
241 // Always shows this on the login screen.
242 if (login_ == user::LOGGED_IN_NONE)
243 return true;
244
245 if (delegate->AlwaysShowAccessibilityMenu() ||
246 IsAnyAccessibilityFeatureEnabled()) {
247 return true;
248 }
249
250 return false;
71 } 251 }
72 252
73 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { 253 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) {
74 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) 254 CHECK(default_ == NULL);
255
256 login_ = status;
257
258 if (!GetInitialVisibility())
75 return NULL; 259 return NULL;
76 260
77 CHECK(default_ == NULL); 261 CHECK(default_ == NULL);
78 default_ = new DefaultAccessibilityView(); 262 default_ = new tray::DefaultAccessibilityView(this);
79 263
80 return default_; 264 return default_;
81 } 265 }
82 266
83 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { 267 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) {
84 CHECK(detailed_ == NULL); 268 CHECK(detailed_ == NULL);
85 detailed_ = new views::View; 269
86 270 login_ = status;
87 detailed_->SetLayoutManager(new 271
88 views::BoxLayout(views::BoxLayout::kHorizontal, 272 if (request_popup_view_) {
89 kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); 273 detailed_ = new tray::AccessibilityPopupView();
90 274 request_popup_view_ = false;
91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 275 } else {
92 views::ImageView* image = new views::ImageView; 276 detailed_ = new tray::AccessibilityDetailedView(status);
93 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). 277 }
94 ToImageSkia());
95
96 detailed_->AddChildView(image);
97 detailed_->AddChildView(new views::Label(bundle.GetLocalizedString(
98 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE)));
99 278
100 return detailed_; 279 return detailed_;
101 } 280 }
102 281
103 void TrayAccessibility::DestroyDefaultView() { 282 void TrayAccessibility::DestroyDefaultView() {
104 default_ = NULL; 283 default_ = NULL;
105 } 284 }
106 285
107 void TrayAccessibility::DestroyDetailedView() { 286 void TrayAccessibility::DestroyDetailedView() {
108 detailed_ = NULL; 287 detailed_ = NULL;
109 } 288 }
110 289
111 void TrayAccessibility::OnAccessibilityModeChanged(bool enabled) { 290 void TrayAccessibility::OnLoginStateChanged(user::LoginStatus status) {
291 login_ = status;
292
112 if (tray_view()) 293 if (tray_view())
113 tray_view()->SetVisible(enabled); 294 tray_view()->SetVisible(GetInitialVisibility());
295 }
114 296
115 if (enabled) { 297 void TrayAccessibility::OnAccessibilityModeChanged() {
298 if (tray_view())
299 tray_view()->SetVisible(GetInitialVisibility());
300
301 bool current_accessibility_status = IsAnyAccessibilityFeatureEnabled();
302 if (!previous_accessibility_status_ && current_accessibility_status) {
303 // Show popup if the accessibily status is being changed to true from false.
304 request_popup_view_ = true;
116 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 305 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
117 } else if (detailed_) { 306 } else if (detailed_) {
118 detailed_->GetWidget()->Close(); 307 detailed_->GetWidget()->Close();
119 } 308 }
309
310 previous_accessibility_status_ = current_accessibility_status;
120 } 311 }
121 312
122 } // namespace internal 313 } // namespace internal
123 } // namespace ash 314 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698