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

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

Powered by Google App Engine
This is Rietveld 408576698