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

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

Issue 213233003: Show a notification when a braille display is connected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Style and const correctness fixes. Created 6 years, 9 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/metrics/user_metrics_recorder.h" 8 #include "ash/metrics/user_metrics_recorder.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/hover_highlight_view.h" 10 #include "ash/system/tray/hover_highlight_view.h"
11 #include "ash/system/tray/system_tray.h" 11 #include "ash/system/tray/system_tray.h"
12 #include "ash/system/tray/system_tray_delegate.h" 12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/system/tray/system_tray_notifier.h" 13 #include "ash/system/tray/system_tray_notifier.h"
14 #include "ash/system/tray/tray_constants.h" 14 #include "ash/system/tray/tray_constants.h"
15 #include "ash/system/tray/tray_details_view.h" 15 #include "ash/system/tray/tray_details_view.h"
16 #include "ash/system/tray/tray_item_more.h" 16 #include "ash/system/tray/tray_item_more.h"
17 #include "ash/system/tray/tray_notification_view.h"
18 #include "ash/system/tray/tray_popup_label_button.h" 17 #include "ash/system/tray/tray_popup_label_button.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "grit/ash_resources.h" 19 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
24 #include "ui/views/controls/image_view.h" 24 #include "ui/views/controls/image_view.h"
25 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
26 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
28 28
29 namespace ash { 29 namespace ash {
30 namespace internal { 30 namespace internal {
31 31
32 namespace { 32 namespace {
33 33
34 enum AccessibilityState { 34 enum AccessibilityState {
35 A11Y_NONE = 0, 35 A11Y_NONE = 0,
36 A11Y_SPOKEN_FEEDBACK = 1 << 0, 36 A11Y_SPOKEN_FEEDBACK = 1 << 0,
37 A11Y_HIGH_CONTRAST = 1 << 1, 37 A11Y_HIGH_CONTRAST = 1 << 1,
38 A11Y_SCREEN_MAGNIFIER = 1 << 2, 38 A11Y_SCREEN_MAGNIFIER = 1 << 2,
39 A11Y_LARGE_CURSOR = 1 << 3, 39 A11Y_LARGE_CURSOR = 1 << 3,
40 A11Y_AUTOCLICK = 1 << 4, 40 A11Y_AUTOCLICK = 1 << 4,
41 A11Y_VIRTUAL_KEYBOARD = 1 << 5, 41 A11Y_VIRTUAL_KEYBOARD = 1 << 5,
42 A11Y_BRAILLE_DISPLAY_CONNECTED = 1 << 6,
42 }; 43 };
43 44
44 uint32 GetAccessibilityState() { 45 uint32 GetAccessibilityState() {
45 AccessibilityDelegate* delegate = 46 AccessibilityDelegate* delegate =
46 Shell::GetInstance()->accessibility_delegate(); 47 Shell::GetInstance()->accessibility_delegate();
47 uint32 state = A11Y_NONE; 48 uint32 state = A11Y_NONE;
48 if (delegate->IsSpokenFeedbackEnabled()) 49 if (delegate->IsSpokenFeedbackEnabled())
49 state |= A11Y_SPOKEN_FEEDBACK; 50 state |= A11Y_SPOKEN_FEEDBACK;
50 if (delegate->IsHighContrastEnabled()) 51 if (delegate->IsHighContrastEnabled())
51 state |= A11Y_HIGH_CONTRAST; 52 state |= A11Y_HIGH_CONTRAST;
52 if (delegate->IsMagnifierEnabled()) 53 if (delegate->IsMagnifierEnabled())
53 state |= A11Y_SCREEN_MAGNIFIER; 54 state |= A11Y_SCREEN_MAGNIFIER;
54 if (delegate->IsLargeCursorEnabled()) 55 if (delegate->IsLargeCursorEnabled())
55 state |= A11Y_LARGE_CURSOR; 56 state |= A11Y_LARGE_CURSOR;
56 if (delegate->IsAutoclickEnabled()) 57 if (delegate->IsAutoclickEnabled())
57 state |= A11Y_AUTOCLICK; 58 state |= A11Y_AUTOCLICK;
58 if (delegate->IsVirtualKeyboardEnabled()) 59 if (delegate->IsVirtualKeyboardEnabled())
59 state |= A11Y_VIRTUAL_KEYBOARD; 60 state |= A11Y_VIRTUAL_KEYBOARD;
61 if (delegate->IsBrailleDisplayConnected())
62 state |= A11Y_BRAILLE_DISPLAY_CONNECTED;
60 return state; 63 return state;
61 } 64 }
62 65
63 user::LoginStatus GetCurrentLoginStatus() { 66 user::LoginStatus GetCurrentLoginStatus() {
64 return Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); 67 return Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
65 } 68 }
66 69
67 } // namespace 70 } // namespace
68 71
69 namespace tray { 72 namespace tray {
(...skipping 11 matching lines...) Expand all
81 SetAccessibleName(label); 84 SetAccessibleName(label);
82 } 85 }
83 86
84 virtual ~DefaultAccessibilityView() { 87 virtual ~DefaultAccessibilityView() {
85 } 88 }
86 89
87 private: 90 private:
88 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); 91 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
89 }; 92 };
90 93
91 class AccessibilityPopupView : public TrayNotificationView { 94 ////////////////////////////////////////////////////////////////////////////////
92 public: 95 // ash::internal::tray::AccessibilityPopupView
93 AccessibilityPopupView(SystemTrayItem* owner) 96
94 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK) { 97 AccessibilityPopupView::AccessibilityPopupView(SystemTrayItem* owner,
95 InitView(GetLabel()); 98 uint32 enabled_state_bits)
99 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK),
100 label_(CreateLabel(enabled_state_bits)) {
101 InitView(label_);
102 }
103
104 views::Label* AccessibilityPopupView::CreateLabel(uint32 enabled_state_bits) {
105 DCHECK((enabled_state_bits &
106 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED)) != 0);
107 base::string16 text;
108 if (enabled_state_bits & A11Y_BRAILLE_DISPLAY_CONNECTED) {
109 text.append(l10n_util::GetStringUTF16(
110 IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED_BUBBLE));
96 } 111 }
97 112 if (enabled_state_bits & A11Y_SPOKEN_FEEDBACK) {
98 private: 113 if (!text.empty())
99 views::Label* GetLabel() { 114 text.append(base::ASCIIToUTF16(" "));
100 views::Label* label = new views::Label( 115 text.append(l10n_util::GetStringUTF16(
101 l10n_util::GetStringUTF16( 116 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE));
102 IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE));
103 label->SetMultiLine(true);
104 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
105 return label;
106 } 117 }
107 118 views::Label* label = new views::Label(text);
108 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); 119 label->SetMultiLine(true);
109 }; 120 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
121 return label;
122 }
110 123
111 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
112 // ash::internal::tray::AccessibilityDetailedView 125 // ash::internal::tray::AccessibilityDetailedView
113 126
114 AccessibilityDetailedView::AccessibilityDetailedView( 127 AccessibilityDetailedView::AccessibilityDetailedView(
115 SystemTrayItem* owner, user::LoginStatus login) : 128 SystemTrayItem* owner, user::LoginStatus login) :
116 TrayDetailsView(owner), 129 TrayDetailsView(owner),
117 spoken_feedback_view_(NULL), 130 spoken_feedback_view_(NULL),
118 high_contrast_view_(NULL), 131 high_contrast_view_(NULL),
119 screen_magnifier_view_(NULL), 132 screen_magnifier_view_(NULL),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } // namespace tray 308 } // namespace tray
296 309
297 //////////////////////////////////////////////////////////////////////////////// 310 ////////////////////////////////////////////////////////////////////////////////
298 // ash::internal::TrayAccessibility 311 // ash::internal::TrayAccessibility
299 312
300 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) 313 TrayAccessibility::TrayAccessibility(SystemTray* system_tray)
301 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), 314 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY),
302 default_(NULL), 315 default_(NULL),
303 detailed_popup_(NULL), 316 detailed_popup_(NULL),
304 detailed_menu_(NULL), 317 detailed_menu_(NULL),
305 request_popup_view_(false), 318 request_popup_view_state_(A11Y_NONE),
306 tray_icon_visible_(false), 319 tray_icon_visible_(false),
307 login_(GetCurrentLoginStatus()), 320 login_(GetCurrentLoginStatus()),
308 previous_accessibility_state_(GetAccessibilityState()), 321 previous_accessibility_state_(GetAccessibilityState()),
309 show_a11y_menu_on_lock_screen_(true) { 322 show_a11y_menu_on_lock_screen_(true) {
310 DCHECK(Shell::GetInstance()->delegate()); 323 DCHECK(Shell::GetInstance()->delegate());
311 DCHECK(system_tray); 324 DCHECK(system_tray);
312 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); 325 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
313 } 326 }
314 327
315 TrayAccessibility::~TrayAccessibility() { 328 TrayAccessibility::~TrayAccessibility() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 CHECK(default_ == NULL); 365 CHECK(default_ == NULL);
353 default_ = new tray::DefaultAccessibilityView(this); 366 default_ = new tray::DefaultAccessibilityView(this);
354 367
355 return default_; 368 return default_;
356 } 369 }
357 370
358 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { 371 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) {
359 CHECK(detailed_popup_ == NULL); 372 CHECK(detailed_popup_ == NULL);
360 CHECK(detailed_menu_ == NULL); 373 CHECK(detailed_menu_ == NULL);
361 374
362 if (request_popup_view_) { 375 if (request_popup_view_state_) {
363 detailed_popup_ = new tray::AccessibilityPopupView(this); 376 detailed_popup_ =
364 request_popup_view_ = false; 377 new tray::AccessibilityPopupView(this, request_popup_view_state_);
378 request_popup_view_state_ = A11Y_NONE;
365 return detailed_popup_; 379 return detailed_popup_;
366 } else { 380 } else {
367 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 381 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
368 ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY); 382 ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY);
369 detailed_menu_ = CreateDetailedMenu(); 383 detailed_menu_ = CreateDetailedMenu();
370 return detailed_menu_; 384 return detailed_menu_;
371 } 385 }
372 } 386 }
373 387
374 void TrayAccessibility::DestroyDefaultView() { 388 void TrayAccessibility::DestroyDefaultView() {
(...skipping 12 matching lines...) Expand all
387 401
388 login_ = status; 402 login_ = status;
389 SetTrayIconVisible(GetInitialVisibility()); 403 SetTrayIconVisible(GetInitialVisibility());
390 } 404 }
391 405
392 void TrayAccessibility::OnAccessibilityModeChanged( 406 void TrayAccessibility::OnAccessibilityModeChanged(
393 AccessibilityNotificationVisibility notify) { 407 AccessibilityNotificationVisibility notify) {
394 SetTrayIconVisible(GetInitialVisibility()); 408 SetTrayIconVisible(GetInitialVisibility());
395 409
396 uint32 accessibility_state = GetAccessibilityState(); 410 uint32 accessibility_state = GetAccessibilityState();
397 if ((notify == ash::A11Y_NOTIFICATION_SHOW) && 411 // We'll get an extra notification if a braille display is connected when
398 !(previous_accessibility_state_ & A11Y_SPOKEN_FEEDBACK) && 412 // spoken feedback wasn't already enabled. This is because the braille
399 (accessibility_state & A11Y_SPOKEN_FEEDBACK)) { 413 // connection state is already updated when spoken feedback is enabled so
414 // that the notifications can be consolidated into one. Therefore, we
415 // return early if there's no change in the state that we keep track of.
416 if (accessibility_state == previous_accessibility_state_)
417 return;
418 // Contains bits for spoken feedback and braille display connected currently
419 // being enabled.
420 uint32 being_enabled =
421 (accessibility_state & ~previous_accessibility_state_) &
422 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED);
423 if ((notify == ash::A11Y_NOTIFICATION_SHOW) && being_enabled != A11Y_NONE) {
400 // Shows popup if |notify| is true and the spoken feedback is being enabled. 424 // Shows popup if |notify| is true and the spoken feedback is being enabled.
401 request_popup_view_ = true; 425 request_popup_view_state_ = being_enabled;
402 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 426 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
403 } else { 427 } else {
404 if (detailed_popup_) 428 if (detailed_popup_)
405 detailed_popup_->GetWidget()->Close(); 429 detailed_popup_->GetWidget()->Close();
406 if (detailed_menu_) 430 if (detailed_menu_)
407 detailed_menu_->GetWidget()->Close(); 431 detailed_menu_->GetWidget()->Close();
408 } 432 }
409 433
410 previous_accessibility_state_ = accessibility_state; 434 previous_accessibility_state_ = accessibility_state;
411 } 435 }
412 436
413 } // namespace internal 437 } // namespace internal
414 } // namespace ash 438 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_accessibility.h ('k') | chrome/browser/chromeos/accessibility/accessibility_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698