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

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

Issue 2838903002: Add accessibility related notification to notification center (Closed)
Patch Set: address comments Created 3 years, 7 months 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/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/accessibility_types.h" 8 #include "ash/accessibility_types.h"
9 #include "ash/resources/vector_icons/vector_icons.h" 9 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "ash/session/session_controller.h" 10 #include "ash/session/session_controller.h"
11 #include "ash/session/session_state_delegate.h" 11 #include "ash/session/session_state_delegate.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/strings/grit/ash_strings.h" 14 #include "ash/strings/grit/ash_strings.h"
15 #include "ash/system/system_notifier.h"
15 #include "ash/system/tray/hover_highlight_view.h" 16 #include "ash/system/tray/hover_highlight_view.h"
16 #include "ash/system/tray/system_tray.h" 17 #include "ash/system/tray/system_tray.h"
17 #include "ash/system/tray/system_tray_controller.h" 18 #include "ash/system/tray/system_tray_controller.h"
18 #include "ash/system/tray/system_tray_notifier.h" 19 #include "ash/system/tray/system_tray_notifier.h"
19 #include "ash/system/tray/tray_constants.h" 20 #include "ash/system/tray/tray_constants.h"
20 #include "ash/system/tray/tray_details_view.h" 21 #include "ash/system/tray/tray_details_view.h"
21 #include "ash/system/tray/tray_item_more.h" 22 #include "ash/system/tray/tray_item_more.h"
22 #include "ash/system/tray/tray_popup_item_style.h"
23 #include "ash/system/tray/tray_popup_utils.h" 23 #include "ash/system/tray/tray_popup_utils.h"
24 #include "ash/system/tray/tri_view.h" 24 #include "ash/system/tray/tri_view.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icon_types.h"
29 #include "ui/message_center/message_center.h"
30 #include "ui/native_theme/native_theme.h" 30 #include "ui/native_theme/native_theme.h"
31 #include "ui/resources/grit/ui_resources.h" 31 #include "ui/resources/grit/ui_resources.h"
32 #include "ui/views/background.h"
33 #include "ui/views/controls/button/custom_button.h"
34 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/separator.h" 32 #include "ui/views/controls/separator.h"
37 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/grid_layout.h"
39 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
40 34
41 namespace ash { 35 namespace ash {
42 namespace { 36 namespace {
43 37
38 const char kNotificationId[] = "chrome://settings/accessibility";
39
44 enum AccessibilityState { 40 enum AccessibilityState {
45 A11Y_NONE = 0, 41 A11Y_NONE = 0,
46 A11Y_SPOKEN_FEEDBACK = 1 << 0, 42 A11Y_SPOKEN_FEEDBACK = 1 << 0,
47 A11Y_HIGH_CONTRAST = 1 << 1, 43 A11Y_HIGH_CONTRAST = 1 << 1,
48 A11Y_SCREEN_MAGNIFIER = 1 << 2, 44 A11Y_SCREEN_MAGNIFIER = 1 << 2,
49 A11Y_LARGE_CURSOR = 1 << 3, 45 A11Y_LARGE_CURSOR = 1 << 3,
50 A11Y_AUTOCLICK = 1 << 4, 46 A11Y_AUTOCLICK = 1 << 4,
51 A11Y_VIRTUAL_KEYBOARD = 1 << 5, 47 A11Y_VIRTUAL_KEYBOARD = 1 << 5,
52 A11Y_BRAILLE_DISPLAY_CONNECTED = 1 << 6, 48 A11Y_BRAILLE_DISPLAY_CONNECTED = 1 << 6,
53 A11Y_MONO_AUDIO = 1 << 7, 49 A11Y_MONO_AUDIO = 1 << 7,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 state |= A11Y_STICKY_KEYS; 83 state |= A11Y_STICKY_KEYS;
88 if (delegate->IsTapDraggingEnabled()) 84 if (delegate->IsTapDraggingEnabled())
89 state |= A11Y_TAP_DRAGGING; 85 state |= A11Y_TAP_DRAGGING;
90 return state; 86 return state;
91 } 87 }
92 88
93 LoginStatus GetCurrentLoginStatus() { 89 LoginStatus GetCurrentLoginStatus() {
94 return Shell::Get()->session_controller()->login_status(); 90 return Shell::Get()->session_controller()->login_status();
95 } 91 }
96 92
93 // Returns notification icon based on the enabled accessibility state.
94 const gfx::VectorIcon& GetNotificationIcon(uint32_t enabled_accessibility) {
95 if ((enabled_accessibility & A11Y_BRAILLE_DISPLAY_CONNECTED) &&
96 (enabled_accessibility & A11Y_SPOKEN_FEEDBACK)) {
97 return kSystemMenuAccessibilityIcon;
98 }
99 if (enabled_accessibility & A11Y_BRAILLE_DISPLAY_CONNECTED)
100 return kNotificationAccessibilityBrailleIcon;
101 else if (enabled_accessibility & A11Y_SPOKEN_FEEDBACK)
James Cook 2017/05/19 04:11:09 nit: no need for "else", here or below
yiyix 2017/05/19 17:53:54 true, i only call this function if braille or spok
102 return kSystemMenuAccessibilityChromevoxIcon;
103 else
104 return gfx::kNoneIcon;
105 }
106
97 } // namespace 107 } // namespace
98 108
99 namespace tray { 109 namespace tray {
100 110
101 class DefaultAccessibilityView : public TrayItemMore { 111 class DefaultAccessibilityView : public TrayItemMore {
102 public: 112 public:
103 explicit DefaultAccessibilityView(SystemTrayItem* owner) 113 explicit DefaultAccessibilityView(SystemTrayItem* owner)
104 : TrayItemMore(owner) { 114 : TrayItemMore(owner) {
105 base::string16 label = 115 base::string16 label =
106 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY); 116 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY);
(...skipping 11 matching lines...) Expand all
118 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 128 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
119 SetImage(gfx::CreateVectorIcon(kSystemMenuAccessibilityIcon, 129 SetImage(gfx::CreateVectorIcon(kSystemMenuAccessibilityIcon,
120 style->GetIconColor())); 130 style->GetIconColor()));
121 } 131 }
122 132
123 private: 133 private:
124 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); 134 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
125 }; 135 };
126 136
127 //////////////////////////////////////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////////////////
128 // ash::tray::AccessibilityPopupView
129
130 AccessibilityPopupView::AccessibilityPopupView(uint32_t enabled_state_bits)
131 : label_(CreateLabel(enabled_state_bits)) {}
132
133 void AccessibilityPopupView::Init() {
134 set_background(views::Background::CreateThemedSolidBackground(
135 this, ui::NativeTheme::kColorId_BubbleBackground));
136
137 views::GridLayout* layout = new views::GridLayout(this);
138 SetLayoutManager(layout);
139
140 views::ImageView* close_button = new views::ImageView();
141 close_button->SetImage(
142 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE));
143 close_button->SetHorizontalAlignment(views::ImageView::CENTER);
144 close_button->SetVerticalAlignment(views::ImageView::CENTER);
145
146 views::ImageView* icon = new views::ImageView;
147 icon->SetImage(
148 gfx::CreateVectorIcon(kSystemMenuAccessibilityIcon, kMenuIconColor));
149
150 views::ColumnSet* columns = layout->AddColumnSet(0);
151
152 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2);
153
154 // Icon
155 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
156 0, /* resize percent */
157 views::GridLayout::FIXED, kNotificationIconWidth,
158 kNotificationIconWidth);
159
160 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2);
161
162 // Contents
163 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
164 100, /* resize percent */
165 views::GridLayout::FIXED, kTrayNotificationContentsWidth,
166 kTrayNotificationContentsWidth);
167
168 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2);
169
170 // Close button
171 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING,
172 0, /* resize percent */
173 views::GridLayout::FIXED, kNotificationButtonWidth,
174 kNotificationButtonWidth);
175
176 // Layout rows
177 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems);
178 layout->StartRow(0, 0);
179 layout->AddView(icon);
180 layout->AddView(label_);
181 layout->AddView(close_button);
182 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems);
183 }
184
185 views::Label* AccessibilityPopupView::CreateLabel(uint32_t enabled_state_bits) {
186 DCHECK((enabled_state_bits &
187 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED)) != 0);
188 base::string16 text;
189 if (enabled_state_bits & A11Y_BRAILLE_DISPLAY_CONNECTED) {
190 text.append(l10n_util::GetStringUTF16(
191 IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED_BUBBLE));
192 }
193 if (enabled_state_bits & A11Y_SPOKEN_FEEDBACK) {
194 if (!text.empty())
195 text.append(base::ASCIIToUTF16(" "));
196 text.append(l10n_util::GetStringUTF16(
197 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE));
198 }
199 views::Label* label = new views::Label(text);
200 label->SetMultiLine(true);
201 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
202 return label;
203 }
204
205 ////////////////////////////////////////////////////////////////////////////////
206 // ash::tray::AccessibilityDetailedView 138 // ash::tray::AccessibilityDetailedView
207 139
208 AccessibilityDetailedView::AccessibilityDetailedView(SystemTrayItem* owner) 140 AccessibilityDetailedView::AccessibilityDetailedView(SystemTrayItem* owner)
209 : TrayDetailsView(owner) { 141 : TrayDetailsView(owner) {
210 Reset(); 142 Reset();
211 AppendAccessibilityList(); 143 AppendAccessibilityList();
212 CreateTitleRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE); 144 CreateTitleRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE);
213 Layout(); 145 Layout();
214 } 146 }
215 147
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 tap_dragging_view_ = AddScrollListCheckableItem( 230 tap_dragging_view_ = AddScrollListCheckableItem(
299 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TAP_DRAGGING), 231 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TAP_DRAGGING),
300 tap_dragging_enabled_); 232 tap_dragging_enabled_);
301 } 233 }
302 234
303 void AccessibilityDetailedView::HandleViewClicked(views::View* view) { 235 void AccessibilityDetailedView::HandleViewClicked(views::View* view) {
304 AccessibilityDelegate* delegate = Shell::Get()->accessibility_delegate(); 236 AccessibilityDelegate* delegate = Shell::Get()->accessibility_delegate();
305 UserMetricsAction user_action; 237 UserMetricsAction user_action;
306 if (view == spoken_feedback_view_) { 238 if (view == spoken_feedback_view_) {
307 user_action = delegate->IsSpokenFeedbackEnabled() 239 user_action = delegate->IsSpokenFeedbackEnabled()
308 ? ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK 240 ? UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK
309 : ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK; 241 : UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK;
310 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); 242 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE);
311 } else if (view == high_contrast_view_) { 243 } else if (view == high_contrast_view_) {
312 user_action = delegate->IsHighContrastEnabled() 244 user_action = delegate->IsHighContrastEnabled()
313 ? ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST 245 ? UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST
314 : ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST; 246 : UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST;
315 delegate->ToggleHighContrast(); 247 delegate->ToggleHighContrast();
316 } else if (view == screen_magnifier_view_) { 248 } else if (view == screen_magnifier_view_) {
317 user_action = delegate->IsMagnifierEnabled() 249 user_action = delegate->IsMagnifierEnabled()
318 ? ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER 250 ? UMA_STATUS_AREA_DISABLE_MAGNIFIER
319 : ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER; 251 : UMA_STATUS_AREA_ENABLE_MAGNIFIER;
320 delegate->SetMagnifierEnabled(!delegate->IsMagnifierEnabled()); 252 delegate->SetMagnifierEnabled(!delegate->IsMagnifierEnabled());
321 } else if (large_cursor_view_ && view == large_cursor_view_) { 253 } else if (large_cursor_view_ && view == large_cursor_view_) {
322 user_action = delegate->IsLargeCursorEnabled() 254 user_action = delegate->IsLargeCursorEnabled()
323 ? ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR 255 ? UMA_STATUS_AREA_DISABLE_LARGE_CURSOR
324 : ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR; 256 : UMA_STATUS_AREA_ENABLE_LARGE_CURSOR;
325 delegate->SetLargeCursorEnabled(!delegate->IsLargeCursorEnabled()); 257 delegate->SetLargeCursorEnabled(!delegate->IsLargeCursorEnabled());
326 } else if (autoclick_view_ && view == autoclick_view_) { 258 } else if (autoclick_view_ && view == autoclick_view_) {
327 user_action = delegate->IsAutoclickEnabled() 259 user_action = delegate->IsAutoclickEnabled()
328 ? ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK 260 ? UMA_STATUS_AREA_DISABLE_AUTO_CLICK
329 : ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK; 261 : UMA_STATUS_AREA_ENABLE_AUTO_CLICK;
330 delegate->SetAutoclickEnabled(!delegate->IsAutoclickEnabled()); 262 delegate->SetAutoclickEnabled(!delegate->IsAutoclickEnabled());
331 } else if (virtual_keyboard_view_ && view == virtual_keyboard_view_) { 263 } else if (virtual_keyboard_view_ && view == virtual_keyboard_view_) {
332 user_action = delegate->IsVirtualKeyboardEnabled() 264 user_action = delegate->IsVirtualKeyboardEnabled()
333 ? ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD 265 ? UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD
334 : ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD; 266 : UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD;
335 delegate->SetVirtualKeyboardEnabled(!delegate->IsVirtualKeyboardEnabled()); 267 delegate->SetVirtualKeyboardEnabled(!delegate->IsVirtualKeyboardEnabled());
336 } else if (caret_highlight_view_ && view == caret_highlight_view_) { 268 } else if (caret_highlight_view_ && view == caret_highlight_view_) {
337 user_action = delegate->IsCaretHighlightEnabled() 269 user_action = delegate->IsCaretHighlightEnabled()
338 ? ash::UMA_STATUS_AREA_DISABLE_CARET_HIGHLIGHT 270 ? UMA_STATUS_AREA_DISABLE_CARET_HIGHLIGHT
339 : ash::UMA_STATUS_AREA_ENABLE_CARET_HIGHLIGHT; 271 : UMA_STATUS_AREA_ENABLE_CARET_HIGHLIGHT;
340 delegate->SetCaretHighlightEnabled(!delegate->IsCaretHighlightEnabled()); 272 delegate->SetCaretHighlightEnabled(!delegate->IsCaretHighlightEnabled());
341 } else if (mono_audio_view_ && view == mono_audio_view_) { 273 } else if (mono_audio_view_ && view == mono_audio_view_) {
342 user_action = delegate->IsMonoAudioEnabled() 274 user_action = delegate->IsMonoAudioEnabled()
343 ? ash::UMA_STATUS_AREA_DISABLE_MONO_AUDIO 275 ? UMA_STATUS_AREA_DISABLE_MONO_AUDIO
344 : ash::UMA_STATUS_AREA_ENABLE_MONO_AUDIO; 276 : UMA_STATUS_AREA_ENABLE_MONO_AUDIO;
345 delegate->SetMonoAudioEnabled(!delegate->IsMonoAudioEnabled()); 277 delegate->SetMonoAudioEnabled(!delegate->IsMonoAudioEnabled());
346 } else if (highlight_mouse_cursor_view_ && 278 } else if (highlight_mouse_cursor_view_ &&
347 view == highlight_mouse_cursor_view_) { 279 view == highlight_mouse_cursor_view_) {
348 user_action = delegate->IsCursorHighlightEnabled() 280 user_action = delegate->IsCursorHighlightEnabled()
349 ? ash::UMA_STATUS_AREA_DISABLE_HIGHLIGHT_MOUSE_CURSOR 281 ? UMA_STATUS_AREA_DISABLE_HIGHLIGHT_MOUSE_CURSOR
350 : ash::UMA_STATUS_AREA_ENABLE_HIGHLIGHT_MOUSE_CURSOR; 282 : UMA_STATUS_AREA_ENABLE_HIGHLIGHT_MOUSE_CURSOR;
351 delegate->SetCursorHighlightEnabled(!delegate->IsCursorHighlightEnabled()); 283 delegate->SetCursorHighlightEnabled(!delegate->IsCursorHighlightEnabled());
352 } else if (highlight_keyboard_focus_view_ && 284 } else if (highlight_keyboard_focus_view_ &&
353 view == highlight_keyboard_focus_view_) { 285 view == highlight_keyboard_focus_view_) {
354 user_action = delegate->IsFocusHighlightEnabled() 286 user_action = delegate->IsFocusHighlightEnabled()
355 ? ash::UMA_STATUS_AREA_DISABLE_HIGHLIGHT_KEYBOARD_FOCUS 287 ? UMA_STATUS_AREA_DISABLE_HIGHLIGHT_KEYBOARD_FOCUS
356 : ash::UMA_STATUS_AREA_ENABLE_HIGHLIGHT_KEYBOARD_FOCUS; 288 : UMA_STATUS_AREA_ENABLE_HIGHLIGHT_KEYBOARD_FOCUS;
357 delegate->SetFocusHighlightEnabled(!delegate->IsFocusHighlightEnabled()); 289 delegate->SetFocusHighlightEnabled(!delegate->IsFocusHighlightEnabled());
358 } else if (sticky_keys_view_ && view == sticky_keys_view_) { 290 } else if (sticky_keys_view_ && view == sticky_keys_view_) {
359 user_action = delegate->IsStickyKeysEnabled() 291 user_action = delegate->IsStickyKeysEnabled()
360 ? ash::UMA_STATUS_AREA_DISABLE_STICKY_KEYS 292 ? UMA_STATUS_AREA_DISABLE_STICKY_KEYS
361 : ash::UMA_STATUS_AREA_ENABLE_STICKY_KEYS; 293 : UMA_STATUS_AREA_ENABLE_STICKY_KEYS;
362 delegate->SetStickyKeysEnabled(!delegate->IsStickyKeysEnabled()); 294 delegate->SetStickyKeysEnabled(!delegate->IsStickyKeysEnabled());
363 } else if (tap_dragging_view_ && view == tap_dragging_view_) { 295 } else if (tap_dragging_view_ && view == tap_dragging_view_) {
364 user_action = delegate->IsTapDraggingEnabled() 296 user_action = delegate->IsTapDraggingEnabled()
365 ? ash::UMA_STATUS_AREA_DISABLE_TAP_DRAGGING 297 ? UMA_STATUS_AREA_DISABLE_TAP_DRAGGING
366 : ash::UMA_STATUS_AREA_ENABLE_TAP_DRAGGING; 298 : UMA_STATUS_AREA_ENABLE_TAP_DRAGGING;
367 delegate->SetTapDraggingEnabled(!delegate->IsTapDraggingEnabled()); 299 delegate->SetTapDraggingEnabled(!delegate->IsTapDraggingEnabled());
368 } else { 300 } else {
369 return; 301 return;
370 } 302 }
371 ShellPort::Get()->RecordUserMetricsAction(user_action); 303 ShellPort::Get()->RecordUserMetricsAction(user_action);
372 } 304 }
373 305
374 void AccessibilityDetailedView::HandleButtonPressed(views::Button* sender, 306 void AccessibilityDetailedView::HandleButtonPressed(views::Button* sender,
375 const ui::Event& event) { 307 const ui::Event& event) {
376 if (sender == help_view_) 308 if (sender == help_view_)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } // namespace tray 341 } // namespace tray
410 342
411 //////////////////////////////////////////////////////////////////////////////// 343 ////////////////////////////////////////////////////////////////////////////////
412 // ash::TrayAccessibility 344 // ash::TrayAccessibility
413 345
414 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) 346 TrayAccessibility::TrayAccessibility(SystemTray* system_tray)
415 : TrayImageItem(system_tray, 347 : TrayImageItem(system_tray,
416 kSystemTrayAccessibilityIcon, 348 kSystemTrayAccessibilityIcon,
417 UMA_ACCESSIBILITY), 349 UMA_ACCESSIBILITY),
418 default_(NULL), 350 default_(NULL),
419 detailed_popup_(NULL),
420 detailed_menu_(NULL), 351 detailed_menu_(NULL),
421 request_popup_view_state_(A11Y_NONE),
422 tray_icon_visible_(false), 352 tray_icon_visible_(false),
423 login_(GetCurrentLoginStatus()), 353 login_(GetCurrentLoginStatus()),
424 previous_accessibility_state_(GetAccessibilityState()), 354 previous_accessibility_state_(GetAccessibilityState()),
425 show_a11y_menu_on_lock_screen_(true) { 355 show_a11y_menu_on_lock_screen_(true) {
426 DCHECK(system_tray); 356 DCHECK(system_tray);
427 Shell::Get()->system_tray_notifier()->AddAccessibilityObserver(this); 357 Shell::Get()->system_tray_notifier()->AddAccessibilityObserver(this);
428 } 358 }
429 359
430 TrayAccessibility::~TrayAccessibility() { 360 TrayAccessibility::~TrayAccessibility() {
431 Shell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this); 361 Shell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this);
(...skipping 30 matching lines...) Expand all
462 (status != LoginStatus::LOCKED || !show_a11y_menu_on_lock_screen_)) 392 (status != LoginStatus::LOCKED || !show_a11y_menu_on_lock_screen_))
463 return NULL; 393 return NULL;
464 394
465 CHECK(default_ == NULL); 395 CHECK(default_ == NULL);
466 default_ = new tray::DefaultAccessibilityView(this); 396 default_ = new tray::DefaultAccessibilityView(this);
467 397
468 return default_; 398 return default_;
469 } 399 }
470 400
471 views::View* TrayAccessibility::CreateDetailedView(LoginStatus status) { 401 views::View* TrayAccessibility::CreateDetailedView(LoginStatus status) {
472 CHECK(detailed_popup_ == NULL);
473 CHECK(detailed_menu_ == NULL); 402 CHECK(detailed_menu_ == NULL);
474 403
475 if (request_popup_view_state_) { 404 ShellPort::Get()->RecordUserMetricsAction(
476 detailed_popup_ = 405 UMA_STATUS_AREA_DETAILED_ACCESSIBILITY);
477 new tray::AccessibilityPopupView(request_popup_view_state_); 406 detailed_menu_ = CreateDetailedMenu();
478 detailed_popup_->Init(); 407 return detailed_menu_;
479 request_popup_view_state_ = A11Y_NONE;
480 return detailed_popup_;
481 } else {
482 ShellPort::Get()->RecordUserMetricsAction(
483 ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY);
484 detailed_menu_ = CreateDetailedMenu();
485 return detailed_menu_;
486 }
487 } 408 }
488 409
489 void TrayAccessibility::DestroyDefaultView() { 410 void TrayAccessibility::DestroyDefaultView() {
490 default_ = NULL; 411 default_ = NULL;
491 } 412 }
492 413
493 void TrayAccessibility::DestroyDetailedView() { 414 void TrayAccessibility::DestroyDetailedView() {
494 detailed_popup_ = NULL;
495 detailed_menu_ = NULL; 415 detailed_menu_ = NULL;
496 } 416 }
497 417
498 void TrayAccessibility::UpdateAfterLoginStatusChange(LoginStatus status) { 418 void TrayAccessibility::UpdateAfterLoginStatusChange(LoginStatus status) {
499 // Stores the a11y feature status on just entering the lock screen. 419 // Stores the a11y feature status on just entering the lock screen.
500 if (login_ != LoginStatus::LOCKED && status == LoginStatus::LOCKED) 420 if (login_ != LoginStatus::LOCKED && status == LoginStatus::LOCKED)
501 show_a11y_menu_on_lock_screen_ = (GetAccessibilityState() != A11Y_NONE); 421 show_a11y_menu_on_lock_screen_ = (GetAccessibilityState() != A11Y_NONE);
502 422
503 login_ = status; 423 login_ = status;
504 SetTrayIconVisible(GetInitialVisibility()); 424 SetTrayIconVisible(GetInitialVisibility());
505 } 425 }
506 426
507 void TrayAccessibility::OnAccessibilityModeChanged( 427 void TrayAccessibility::OnAccessibilityModeChanged(
508 AccessibilityNotificationVisibility notify) { 428 AccessibilityNotificationVisibility notify) {
509 SetTrayIconVisible(GetInitialVisibility()); 429 SetTrayIconVisible(GetInitialVisibility());
510 430
511 uint32_t accessibility_state = GetAccessibilityState(); 431 uint32_t accessibility_state = GetAccessibilityState();
512 // We'll get an extra notification if a braille display is connected when 432 // We'll get an extra notification if a braille display is connected when
513 // spoken feedback wasn't already enabled. This is because the braille 433 // spoken feedback wasn't already enabled. This is because the braille
514 // connection state is already updated when spoken feedback is enabled so 434 // connection state is already updated when spoken feedback is enabled so
515 // that the notifications can be consolidated into one. Therefore, we 435 // that the notifications can be consolidated into one. Therefore, we
516 // return early if there's no change in the state that we keep track of. 436 // return early if there's no change in the state that we keep track of.
517 if (accessibility_state == previous_accessibility_state_) 437 if (accessibility_state == previous_accessibility_state_)
518 return; 438 return;
439
440 if (detailed_menu_)
441 detailed_menu_->GetWidget()->Close();
442
443 message_center::MessageCenter* message_center =
444 message_center::MessageCenter::Get();
445 message_center->RemoveNotification(kNotificationId, false /* by_user */);
446
519 // Contains bits for spoken feedback and braille display connected currently 447 // Contains bits for spoken feedback and braille display connected currently
520 // being enabled. 448 // being enabled.
521 uint32_t being_enabled = 449 uint32_t being_enabled =
522 (accessibility_state & ~previous_accessibility_state_) & 450 (accessibility_state & ~previous_accessibility_state_) &
523 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED); 451 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED);
524 if ((notify == A11Y_NOTIFICATION_SHOW) && being_enabled != A11Y_NONE) { 452
525 // Shows popup if |notify| is true and the spoken feedback is being enabled. 453 // Shows notification if |notify| is true and the spoken feedback is being
526 request_popup_view_state_ = being_enabled; 454 // enabled or if a braille is connected.
James Cook 2017/05/19 04:11:10 nit: a braille *display*
yiyix 2017/05/19 17:53:54 Done.
527 ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 455 if (notify == A11Y_NOTIFICATION_SHOW && being_enabled &&
James Cook 2017/05/19 04:11:10 nit: I think you should just check "being_enabled
528 } else { 456 being_enabled != A11Y_NONE) {
529 if (detailed_popup_) 457 base::string16 text;
530 detailed_popup_->GetWidget()->Close(); 458 base::string16 title;
531 if (detailed_menu_) 459 if (being_enabled & A11Y_BRAILLE_DISPLAY_CONNECTED &&
532 detailed_menu_->GetWidget()->Close(); 460 being_enabled & A11Y_SPOKEN_FEEDBACK) {
461 text = l10n_util::GetStringUTF16(
462 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED);
463 title = l10n_util::GetStringUTF16(
464 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_BRAILLE_ENABLED_TITLE);
465 } else if (being_enabled & A11Y_BRAILLE_DISPLAY_CONNECTED) {
466 text = l10n_util::GetStringUTF16(
467 IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED);
468 } else {
469 title = l10n_util::GetStringUTF16(
470 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TITLE);
471 text = l10n_util::GetStringUTF16(
472 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED);
473 }
474
475 std::unique_ptr<message_center::Notification> notification =
476 base::MakeUnique<message_center::Notification>(
477 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, title,
478 text,
479 gfx::Image(gfx::CreateVectorIcon(GetNotificationIcon(being_enabled),
480 kMenuIconSize, kMenuIconColor)),
481 base::string16(), GURL(),
482 message_center::NotifierId(message_center::NotifierId::APPLICATION,
483 system_notifier::kNotifierAccessibility),
484 message_center::RichNotificationData(), nullptr);
485 message_center->AddNotification(std::move(notification));
533 } 486 }
534 487
535 previous_accessibility_state_ = accessibility_state; 488 previous_accessibility_state_ = accessibility_state;
536 } 489 }
537 490
538 } // namespace ash 491 } // 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