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

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: Created 6 years, 8 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 LOG(ERROR) << "Popping up " << text; // TODO: remove.
dmazzoni 2014/03/26 19:02:46 Reminder to remove this
108 DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); 119 views::Label* label = new views::Label(text);
109 }; 120 label->SetMultiLine(true);
121 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
122 return label;
123 }
110 124
111 //////////////////////////////////////////////////////////////////////////////// 125 ////////////////////////////////////////////////////////////////////////////////
112 // ash::internal::tray::AccessibilityDetailedView 126 // ash::internal::tray::AccessibilityDetailedView
113 127
114 AccessibilityDetailedView::AccessibilityDetailedView( 128 AccessibilityDetailedView::AccessibilityDetailedView(
115 SystemTrayItem* owner, user::LoginStatus login) : 129 SystemTrayItem* owner, user::LoginStatus login) :
116 TrayDetailsView(owner), 130 TrayDetailsView(owner),
117 spoken_feedback_view_(NULL), 131 spoken_feedback_view_(NULL),
118 high_contrast_view_(NULL), 132 high_contrast_view_(NULL),
119 screen_magnifier_view_(NULL), 133 screen_magnifier_view_(NULL),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } // namespace tray 309 } // namespace tray
296 310
297 //////////////////////////////////////////////////////////////////////////////// 311 ////////////////////////////////////////////////////////////////////////////////
298 // ash::internal::TrayAccessibility 312 // ash::internal::TrayAccessibility
299 313
300 TrayAccessibility::TrayAccessibility(SystemTray* system_tray) 314 TrayAccessibility::TrayAccessibility(SystemTray* system_tray)
301 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), 315 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY),
302 default_(NULL), 316 default_(NULL),
303 detailed_popup_(NULL), 317 detailed_popup_(NULL),
304 detailed_menu_(NULL), 318 detailed_menu_(NULL),
305 request_popup_view_(false), 319 request_popup_view_state_(A11Y_NONE),
306 tray_icon_visible_(false), 320 tray_icon_visible_(false),
307 login_(GetCurrentLoginStatus()), 321 login_(GetCurrentLoginStatus()),
308 previous_accessibility_state_(GetAccessibilityState()), 322 previous_accessibility_state_(GetAccessibilityState()),
309 show_a11y_menu_on_lock_screen_(true) { 323 show_a11y_menu_on_lock_screen_(true) {
310 DCHECK(Shell::GetInstance()->delegate()); 324 DCHECK(Shell::GetInstance()->delegate());
311 DCHECK(system_tray); 325 DCHECK(system_tray);
312 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); 326 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
313 } 327 }
314 328
315 TrayAccessibility::~TrayAccessibility() { 329 TrayAccessibility::~TrayAccessibility() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 CHECK(default_ == NULL); 366 CHECK(default_ == NULL);
353 default_ = new tray::DefaultAccessibilityView(this); 367 default_ = new tray::DefaultAccessibilityView(this);
354 368
355 return default_; 369 return default_;
356 } 370 }
357 371
358 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { 372 views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) {
359 CHECK(detailed_popup_ == NULL); 373 CHECK(detailed_popup_ == NULL);
360 CHECK(detailed_menu_ == NULL); 374 CHECK(detailed_menu_ == NULL);
361 375
362 if (request_popup_view_) { 376 if (request_popup_view_state_) {
363 detailed_popup_ = new tray::AccessibilityPopupView(this); 377 detailed_popup_ =
364 request_popup_view_ = false; 378 new tray::AccessibilityPopupView(this, request_popup_view_state_);
379 request_popup_view_state_ = A11Y_NONE;
365 return detailed_popup_; 380 return detailed_popup_;
366 } else { 381 } else {
367 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 382 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
368 ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY); 383 ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY);
369 detailed_menu_ = CreateDetailedMenu(); 384 detailed_menu_ = CreateDetailedMenu();
370 return detailed_menu_; 385 return detailed_menu_;
371 } 386 }
372 } 387 }
373 388
374 void TrayAccessibility::DestroyDefaultView() { 389 void TrayAccessibility::DestroyDefaultView() {
(...skipping 12 matching lines...) Expand all
387 402
388 login_ = status; 403 login_ = status;
389 SetTrayIconVisible(GetInitialVisibility()); 404 SetTrayIconVisible(GetInitialVisibility());
390 } 405 }
391 406
392 void TrayAccessibility::OnAccessibilityModeChanged( 407 void TrayAccessibility::OnAccessibilityModeChanged(
393 AccessibilityNotificationVisibility notify) { 408 AccessibilityNotificationVisibility notify) {
394 SetTrayIconVisible(GetInitialVisibility()); 409 SetTrayIconVisible(GetInitialVisibility());
395 410
396 uint32 accessibility_state = GetAccessibilityState(); 411 uint32 accessibility_state = GetAccessibilityState();
397 if ((notify == ash::A11Y_NOTIFICATION_SHOW) && 412 // We'll get an extra notification if a braille display is connected when
398 !(previous_accessibility_state_ & A11Y_SPOKEN_FEEDBACK) && 413 // spoken feedback wasn't already enabled. This is because the braille
399 (accessibility_state & A11Y_SPOKEN_FEEDBACK)) { 414 // connection state is already updated when spoken feedback is enabled so
415 // that the notifications can be consolidated into one. Therefore, we
416 // return early if there's no change in the state that we keep track of.
417 if (accessibility_state == previous_accessibility_state_)
418 return;
419 // Contains bits for spoken feedback and braille display connected currently
420 // being enabled.
421 uint32 being_enabled =
422 (accessibility_state & ~previous_accessibility_state_) &
423 (A11Y_SPOKEN_FEEDBACK | A11Y_BRAILLE_DISPLAY_CONNECTED);
424 if ((notify == ash::A11Y_NOTIFICATION_SHOW) && being_enabled != A11Y_NONE) {
400 // Shows popup if |notify| is true and the spoken feedback is being enabled. 425 // Shows popup if |notify| is true and the spoken feedback is being enabled.
401 request_popup_view_ = true; 426 request_popup_view_state_ = being_enabled;
402 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 427 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
403 } else { 428 } else {
429 LOG(ERROR) << "Closing";
dmazzoni 2014/03/26 19:02:46 Remove
404 if (detailed_popup_) 430 if (detailed_popup_)
405 detailed_popup_->GetWidget()->Close(); 431 detailed_popup_->GetWidget()->Close();
406 if (detailed_menu_) 432 if (detailed_menu_)
407 detailed_menu_->GetWidget()->Close(); 433 detailed_menu_->GetWidget()->Close();
408 } 434 }
409 435
410 previous_accessibility_state_ = accessibility_state; 436 previous_accessibility_state_ = accessibility_state;
411 } 437 }
412 438
413 } // namespace internal 439 } // namespace internal
414 } // namespace ash 440 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698