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
3 // found in the LICENSE file.
5 #include "ash/system/tray_accessibility.h"
8 #include "ash/shell_delegate.h"
9 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/tray/tray_views.h"
11 #include "grit/ash_strings.h"
12 #include "grit/ui_resources.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/image/image.h"
15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/widget/widget.h"
23 class DefaultAccessibilityView
: public ActionableView
{
25 DefaultAccessibilityView() {
26 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal
,
27 kTrayPopupPaddingHorizontal
,
29 kTrayPopupPaddingBetweenItems
));
31 ui::ResourceBundle
& bundle
= ui::ResourceBundle::GetSharedInstance();
32 FixedSizedImageView
* image
=
33 new FixedSizedImageView(0, kTrayPopupItemHeight
);
34 image
->SetImage(bundle
.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK
).
38 string16 label
= bundle
.GetLocalizedString(
39 IDS_ASH_STATUS_TRAY_DISABLE_SPOKEN_FEEDBACK
);
40 AddChildView(new views::Label(label
));
41 SetAccessibleName(label
);
44 virtual ~DefaultAccessibilityView() {}
47 // Overridden from ActionableView.
48 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
{
49 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
50 Shell::GetInstance()->delegate()->ToggleSpokenFeedback();
57 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView
);
60 TrayAccessibility::TrayAccessibility()
61 : TrayImageItem(IDR_AURA_UBER_TRAY_ACCESSIBILITY
),
66 TrayAccessibility::~TrayAccessibility() {}
68 bool TrayAccessibility::GetInitialVisibility() {
69 return Shell::GetInstance()->delegate() &&
70 Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled();
73 views::View
* TrayAccessibility::CreateDefaultView(user::LoginStatus status
) {
74 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
77 CHECK(default_
== NULL
);
78 default_
= new DefaultAccessibilityView();
83 views::View
* TrayAccessibility::CreateDetailedView(user::LoginStatus status
) {
84 CHECK(detailed_
== NULL
);
85 detailed_
= new views::View
;
87 detailed_
->SetLayoutManager(new
88 views::BoxLayout(views::BoxLayout::kHorizontal
,
89 kTrayPopupPaddingHorizontal
, 10, kTrayPopupPaddingBetweenItems
));
91 ui::ResourceBundle
& bundle
= ui::ResourceBundle::GetSharedInstance();
92 views::ImageView
* image
= new views::ImageView
;
93 image
->SetImage(bundle
.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK
).
96 detailed_
->AddChildView(image
);
97 detailed_
->AddChildView(new views::Label(bundle
.GetLocalizedString(
98 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE
)));
103 void TrayAccessibility::DestroyDefaultView() {
107 void TrayAccessibility::DestroyDetailedView() {
111 void TrayAccessibility::OnAccessibilityModeChanged(bool enabled
) {
113 tray_view()->SetVisible(enabled
);
116 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds
, false);
117 } else if (detailed_
) {
118 detailed_
->GetWidget()->Close();
122 } // namespace internal