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

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

Issue 11519036: A11y: Add a browser test of TrayAccessibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test failure on win_rel Created 8 years 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 | Annotate | Revision Log
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" 9 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 SetAccessibleName(label); 70 SetAccessibleName(label);
71 } 71 }
72 72
73 virtual ~DefaultAccessibilityView() { 73 virtual ~DefaultAccessibilityView() {
74 } 74 }
75 75
76 private: 76 private:
77 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); 77 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
78 }; 78 };
79 79
80 class AccessibilityDetailedView : public TrayDetailsView,
81 public ViewClickListener,
82 public views::ButtonListener,
83 public ShellObserver {
84 public:
85 explicit AccessibilityDetailedView(SystemTrayItem* owner,
86 user::LoginStatus login) :
87 TrayDetailsView(owner),
88 spoken_feedback_view_(NULL),
89 high_contrast_view_(NULL),
90 screen_magnifier_view_(NULL),
91 help_view_(NULL),
92 login_(login) {
93
94 Reset();
95
96 AppendAccessibilityList();
97 AppendHelpEntries();
98 CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this);
99
100 Layout();
101 }
102
103 virtual ~AccessibilityDetailedView() {
104 }
105
106 private:
107 // Add the accessibility feature list.
108 void AppendAccessibilityList() {
109 CreateScrollableList();
110 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
111
112 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
113 bool spoken_feedback_enabled = shell_delegate->IsSpokenFeedbackEnabled();
114 spoken_feedback_view_ = AddScrollListItem(
115 bundle.GetLocalizedString(
116 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK),
117 spoken_feedback_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
118 spoken_feedback_enabled);
119 bool high_contrast_mode_enabled = shell_delegate->IsHighContrastEnabled();
120 high_contrast_view_ = AddScrollListItem(
121 bundle.GetLocalizedString(
122 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE),
123 high_contrast_mode_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
124 high_contrast_mode_enabled);
125 bool screen_magnifier_enabled =
126 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL;
127 screen_magnifier_view_ = AddScrollListItem(
128 bundle.GetLocalizedString(
129 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER),
130 screen_magnifier_enabled ? gfx::Font::BOLD : gfx::Font::NORMAL,
131 screen_magnifier_enabled);
132 }
133
134 // Add help entries.
135 void AppendHelpEntries() {
136 // Currently the help page requires a browser window.
137 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286
138 if (login_ == user::LOGGED_IN_NONE ||
139 login_ == user::LOGGED_IN_LOCKED)
140 return;
141
142 views::View* bottom_row = new View();
143 views::BoxLayout* layout = new
144 views::BoxLayout(views::BoxLayout::kHorizontal,
145 kTrayMenuBottomRowPadding,
146 kTrayMenuBottomRowPadding,
147 kTrayMenuBottomRowPaddingBetweenItems);
148 layout->set_spread_blank_space(true);
149 bottom_row->SetLayoutManager(layout);
150
151 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
152
153 TrayPopupLabelButton* help = new TrayPopupLabelButton(
154 this,
155 bundle.GetLocalizedString(
156 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE));
157 bottom_row->AddChildView(help);
158 help_view_ = help;
159
160 // TODO(yoshiki): Add "Customize accessibility" button when the customize is
161 // available. crbug.com/158281
162
163 AddChildView(bottom_row);
164 }
165
166 HoverHighlightView* AddScrollListItem(const string16& text,
167 gfx::Font::FontStyle style,
168 bool checked) {
169 HoverHighlightView* container = new HoverHighlightView(this);
170 container->set_fixed_height(kTrayPopupItemHeight);
171 container->AddCheckableLabel(text, style, checked);
172 scroll_content()->AddChildView(container);
173 return container;
174 }
175
176 // Overridden from ViewClickListener.
177 virtual void ClickedOn(views::View* sender) OVERRIDE {
178 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
179 if (sender == footer()->content()) {
180 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
181 } else if (sender == spoken_feedback_view_) {
182 shell_delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
183 } else if (sender == high_contrast_view_) {
184 shell_delegate->ToggleHighContrast();
185 } else if (sender == screen_magnifier_view_) {
186 bool screen_magnifier_enabled =
187 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL;
188 shell_delegate->SetMagnifier(
189 screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL);
190 }
191 }
192
193 // Overridden from ButtonListener.
194 virtual void ButtonPressed(views::Button* sender,
195 const ui::Event& event) OVERRIDE {
196 SystemTrayDelegate* tray_delegate =
197 Shell::GetInstance()->system_tray_delegate();
198 if (sender == help_view_)
199 tray_delegate->ShowAccessibilityHelp();
200 }
201
202 views::View* spoken_feedback_view_;
203 views::View* high_contrast_view_;
204 views::View* screen_magnifier_view_;;
205 views::View* help_view_;
206 user::LoginStatus login_;
207
208 DISALLOW_COPY_AND_ASSIGN(AccessibilityDetailedView);
209 };
210
211 class AccessibilityPopupView : public TrayNotificationView { 80 class AccessibilityPopupView : public TrayNotificationView {
212 public: 81 public:
213 AccessibilityPopupView(SystemTrayItem* owner) 82 AccessibilityPopupView(SystemTrayItem* owner)
214 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK) { 83 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK) {
215 InitView(GetLabel()); 84 InitView(GetLabel());
216 } 85 }
217 86
218 private: 87 private:
219 views::Label* GetLabel() { 88 views::Label* GetLabel() {
220 views::Label* label = new views::Label( 89 views::Label* label = new views::Label(
221 l10n_util::GetStringUTF16( 90 l10n_util::GetStringUTF16(
222 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE)); 91 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE));
223 label->SetMultiLine(true); 92 label->SetMultiLine(true);
224 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 93 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
225 return label; 94 return label;
226 } 95 }
227 96
228 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); 97 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView);
229 }; 98 };
230 99
100 ////////////////////////////////////////////////////////////////////////////////
101 // ash::internal::tray::AccessibilityDetailedView
102
103 AccessibilityDetailedView::AccessibilityDetailedView(
104 SystemTrayItem* owner, user::LoginStatus login) :
105 TrayDetailsView(owner),
106 spoken_feedback_view_(NULL),
107 high_contrast_view_(NULL),
108 screen_magnifier_view_(NULL),
109 help_view_(NULL),
110 spoken_feedback_enabled_(false),
111 high_contrast_enabled_(false),
112 screen_magnifier_enabled_(false),
113 login_(login) {
114
115 Reset();
116
117 AppendAccessibilityList();
118 AppendHelpEntries();
119 CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this);
120
121 Layout();
122 }
123
124 void AccessibilityDetailedView::AppendAccessibilityList() {
125 CreateScrollableList();
126 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
127
128 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
129 spoken_feedback_enabled_ = shell_delegate->IsSpokenFeedbackEnabled();
130 spoken_feedback_view_ = AddScrollListItem(
131 bundle.GetLocalizedString(
132 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK),
133 spoken_feedback_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL,
134 spoken_feedback_enabled_);
135 high_contrast_enabled_ = shell_delegate->IsHighContrastEnabled();
136 high_contrast_view_ = AddScrollListItem(
137 bundle.GetLocalizedString(
138 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE),
139 high_contrast_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL,
140 high_contrast_enabled_);
141 screen_magnifier_enabled_ =
142 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL;
143 screen_magnifier_view_ = AddScrollListItem(
144 bundle.GetLocalizedString(
145 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER),
146 screen_magnifier_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL,
147 screen_magnifier_enabled_);
148 }
149
150 void AccessibilityDetailedView::AppendHelpEntries() {
151 // Currently the help page requires a browser window.
152 // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286
153 if (login_ == user::LOGGED_IN_NONE ||
154 login_ == user::LOGGED_IN_LOCKED)
155 return;
156
157 views::View* bottom_row = new View();
158 views::BoxLayout* layout = new
159 views::BoxLayout(views::BoxLayout::kHorizontal,
160 kTrayMenuBottomRowPadding,
161 kTrayMenuBottomRowPadding,
162 kTrayMenuBottomRowPaddingBetweenItems);
163 layout->set_spread_blank_space(true);
164 bottom_row->SetLayoutManager(layout);
165
166 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
167
168 TrayPopupLabelButton* help = new TrayPopupLabelButton(
169 this,
170 bundle.GetLocalizedString(
171 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE));
172 bottom_row->AddChildView(help);
173 help_view_ = help;
174
175 // TODO(yoshiki): Add "Customize accessibility" button when the customize is
176 // available. crbug.com/158281
177
178 AddChildView(bottom_row);
179 }
180
181 HoverHighlightView* AccessibilityDetailedView::AddScrollListItem(
182 const string16& text,
183 gfx::Font::FontStyle style,
184 bool checked) {
185 HoverHighlightView* container = new HoverHighlightView(this);
186 container->set_fixed_height(kTrayPopupItemHeight);
187 container->AddCheckableLabel(text, style, checked);
188 scroll_content()->AddChildView(container);
189 return container;
190 }
191
192 void AccessibilityDetailedView::ClickedOn(views::View* sender) {
193 ShellDelegate* shell_delegate = Shell::GetInstance()->delegate();
194 if (sender == footer()->content()) {
195 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
196 } else if (sender == spoken_feedback_view_) {
197 shell_delegate->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE);
198 } else if (sender == high_contrast_view_) {
199 shell_delegate->ToggleHighContrast();
200 } else if (sender == screen_magnifier_view_) {
201 bool screen_magnifier_enabled =
202 shell_delegate->GetMagnifierType() == ash::MAGNIFIER_FULL;
203 shell_delegate->SetMagnifier(
204 screen_magnifier_enabled ? ash::MAGNIFIER_OFF : ash::MAGNIFIER_FULL);
205 }
206 }
207
208 void AccessibilityDetailedView::ButtonPressed(views::Button* sender,
209 const ui::Event& event) {
210 SystemTrayDelegate* tray_delegate =
211 Shell::GetInstance()->system_tray_delegate();
212 if (sender == help_view_)
213 tray_delegate->ShowAccessibilityHelp();
214 }
215
231 } // namespace tray 216 } // namespace tray
232 217
218 ////////////////////////////////////////////////////////////////////////////////
219 // ash::internal::TrayAccessibility
233 220
234 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) 221 TrayAccessibility::TrayAccessibility(SystemTray* system_tray)
235 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), 222 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY),
236 default_(NULL), 223 default_(NULL),
237 detailed_(NULL), 224 detailed_popup_(NULL),
225 detailed_menu_(NULL),
238 request_popup_view_(false), 226 request_popup_view_(false),
227 tray_icon_visible_(false),
239 login_(GetCurrentLoginStatus()), 228 login_(GetCurrentLoginStatus()),
240 previous_accessibility_state_(GetAccessibilityState()) { 229 previous_accessibility_state_(GetAccessibilityState()) {
241 DCHECK(Shell::GetInstance()->delegate()); 230 DCHECK(Shell::GetInstance()->delegate());
242 DCHECK(system_tray); 231 DCHECK(system_tray);
243 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); 232 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
244 } 233 }
245 234
246 TrayAccessibility::~TrayAccessibility() { 235 TrayAccessibility::~TrayAccessibility() {
247 Shell::GetInstance()->system_tray_notifier()-> 236 Shell::GetInstance()->system_tray_notifier()->
248 RemoveAccessibilityObserver(this); 237 RemoveAccessibilityObserver(this);
249 } 238 }
250 239
240 void TrayAccessibility::SetTrayIconVisible(bool visible) {
241 if (tray_view())
242 tray_view()->SetVisible(visible);
243 tray_icon_visible_ = visible;
244 }
245
246 tray::AccessibilityDetailedView* TrayAccessibility::CreateDetailedMenu() {
247 return new tray::AccessibilityDetailedView(this, login_);
248 }
249
251 bool TrayAccessibility::GetInitialVisibility() { 250 bool TrayAccessibility::GetInitialVisibility() {
252 // Shows accessibility icon if any accessibility feature is enabled. 251 // Shows accessibility icon if any accessibility feature is enabled.
253 // Otherwise, doen't show it. 252 // Otherwise, doen't show it.
254 return GetAccessibilityState() != A11Y_NONE; 253 return GetAccessibilityState() != A11Y_NONE;
255 } 254 }
256 255
257 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { 256 views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) {
258 CHECK(default_ == NULL); 257 CHECK(default_ == NULL);
259 258
260 login_ = status; 259 login_ = status;
261 260
262 // Shows accessibility menu if: 261 // Shows accessibility menu if:
263 // - on login screen (not logged in); 262 // - on login screen (not logged in);
264 // - "Enable accessibility menu" on chrome://settings is checked; 263 // - "Enable accessibility menu" on chrome://settings is checked;
265 // - or any of accessibility features is enabled 264 // - or any of accessibility features is enabled
266 // Otherwise, not shows it. 265 // Otherwise, not shows it.
267 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 266 ShellDelegate* delegate = Shell::GetInstance()->delegate();
268 if (login_ != user::LOGGED_IN_NONE && 267 if (login_ != user::LOGGED_IN_NONE &&
269 !delegate->ShouldAlwaysShowAccessibilityMenu() && 268 !delegate->ShouldAlwaysShowAccessibilityMenu() &&
270 GetAccessibilityState() == A11Y_NONE) 269 GetAccessibilityState() == A11Y_NONE)
271 return NULL; 270 return NULL;
272 271
273 CHECK(default_ == NULL); 272 CHECK(default_ == NULL);
274 default_ = new tray::DefaultAccessibilityView(this); 273 default_ = new tray::DefaultAccessibilityView(this);
275 274
276 return default_; 275 return default_;
277 } 276 }
278 277
279 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { 278 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) {
280 CHECK(detailed_ == NULL); 279 CHECK(detailed_popup_ == NULL);
280 CHECK(detailed_menu_ == NULL);
281 281
282 login_ = status; 282 login_ = status;
283 283
284 if (request_popup_view_) { 284 if (request_popup_view_) {
285 detailed_ = new tray::AccessibilityPopupView(this); 285 detailed_popup_ = new tray::AccessibilityPopupView(this);
286 request_popup_view_ = false; 286 request_popup_view_ = false;
287 return detailed_popup_;
287 } else { 288 } else {
288 detailed_ = new tray::AccessibilityDetailedView(this, status); 289 detailed_menu_ = CreateDetailedMenu();
290 return detailed_menu_;
289 } 291 }
290
291 return detailed_;
292 } 292 }
293 293
294 void TrayAccessibility::DestroyDefaultView() { 294 void TrayAccessibility::DestroyDefaultView() {
295 default_ = NULL; 295 default_ = NULL;
296 } 296 }
297 297
298 void TrayAccessibility::DestroyDetailedView() { 298 void TrayAccessibility::DestroyDetailedView() {
299 detailed_ = NULL; 299 detailed_popup_ = NULL;
300 detailed_menu_ = NULL;
300 } 301 }
301 302
302 void TrayAccessibility::UpdateAfterLoginStatusChange(user::LoginStatus status) { 303 void TrayAccessibility::UpdateAfterLoginStatusChange(user::LoginStatus status) {
303 login_ = status; 304 login_ = status;
304 305 SetTrayIconVisible(GetInitialVisibility());
305 if (tray_view())
306 tray_view()->SetVisible(GetInitialVisibility());
307 } 306 }
308 307
309 void TrayAccessibility::OnAccessibilityModeChanged( 308 void TrayAccessibility::OnAccessibilityModeChanged(
310 AccessibilityNotificationVisibility notify) { 309 AccessibilityNotificationVisibility notify) {
311 if (tray_view()) 310 SetTrayIconVisible(GetInitialVisibility());
312 tray_view()->SetVisible(GetInitialVisibility());
313 311
314 uint32 accessibility_state = GetAccessibilityState(); 312 uint32 accessibility_state = GetAccessibilityState();
315 if ((notify == ash::A11Y_NOTIFICATION_SHOW)&& 313 if ((notify == ash::A11Y_NOTIFICATION_SHOW)&&
316 !(previous_accessibility_state_ & A11Y_SPOKEN_FEEDBACK) && 314 !(previous_accessibility_state_ & A11Y_SPOKEN_FEEDBACK) &&
317 (accessibility_state & A11Y_SPOKEN_FEEDBACK)) { 315 (accessibility_state & A11Y_SPOKEN_FEEDBACK)) {
318 // Shows popup if |notify| is true and the spoken feedback is being enabled. 316 // Shows popup if |notify| is true and the spoken feedback is being enabled.
319 request_popup_view_ = true; 317 request_popup_view_ = true;
320 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 318 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
321 } else if (detailed_) { 319 } else {
322 detailed_->GetWidget()->Close(); 320 if (detailed_popup_)
321 detailed_popup_->GetWidget()->Close();
322 if (detailed_menu_)
323 detailed_menu_->GetWidget()->Close();
323 } 324 }
324 325
325 previous_accessibility_state_ = accessibility_state; 326 previous_accessibility_state_ = accessibility_state;
326 } 327 }
327 328
328 } // namespace internal 329 } // namespace internal
329 } // namespace ash 330 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_accessibility.h ('k') | chrome/browser/chromeos/system/tray_accessibility_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698