harfbuzz-ng roll
[chromium-blink-merge.git] / ash / system / tray_accessibility.cc
blob95adc428402f86ccd3425b58ad8043d24869fbff
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"
7 #include "ash/shell.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"
20 namespace ash {
21 namespace internal {
23 class DefaultAccessibilityView : public ActionableView {
24 public:
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).
35 ToImageSkia());
37 AddChildView(image);
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() {}
46 protected:
47 // Overridden from ActionableView.
48 virtual bool PerformAction(const ui::Event& event) OVERRIDE {
49 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
50 Shell::GetInstance()->delegate()->ToggleSpokenFeedback();
51 GetWidget()->Close();
52 return true;
55 private:
57 DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView);
60 TrayAccessibility::TrayAccessibility()
61 : TrayImageItem(IDR_AURA_UBER_TRAY_ACCESSIBILITY),
62 default_(NULL),
63 detailed_(NULL) {
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())
75 return NULL;
77 CHECK(default_ == NULL);
78 default_ = new DefaultAccessibilityView();
80 return default_;
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).
94 ToImageSkia());
96 detailed_->AddChildView(image);
97 detailed_->AddChildView(new views::Label(bundle.GetLocalizedString(
98 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TURNED_ON_BUBBLE)));
100 return detailed_;
103 void TrayAccessibility::DestroyDefaultView() {
104 default_ = NULL;
107 void TrayAccessibility::DestroyDetailedView() {
108 detailed_ = NULL;
111 void TrayAccessibility::OnAccessibilityModeChanged(bool enabled) {
112 if (tray_view())
113 tray_view()->SetVisible(enabled);
115 if (enabled) {
116 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
117 } else if (detailed_) {
118 detailed_->GetWidget()->Close();
122 } // namespace internal
123 } // namespace ash