Disable accessible touch exploration by default.
[chromium-blink-merge.git] / ash / system / chromeos / settings / tray_settings.cc
blobb6f4e76f663e9a3c5ab55cefb12a8214aadddd0a
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/chromeos/settings/tray_settings.h"
7 #include "ash/shell.h"
8 #include "ash/system/chromeos/power/power_status.h"
9 #include "ash/system/chromeos/power/power_status_view.h"
10 #include "ash/system/tray/actionable_view.h"
11 #include "ash/system/tray/fixed_sized_image_view.h"
12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/system/tray/tray_constants.h"
14 #include "base/logging.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h"
18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/image/image.h"
21 #include "ui/views/controls/image_view.h"
22 #include "ui/views/controls/label.h"
23 #include "ui/views/layout/box_layout.h"
24 #include "ui/views/layout/fill_layout.h"
25 #include "ui/views/view.h"
27 namespace ash {
28 namespace tray {
30 class SettingsDefaultView : public ActionableView,
31 public PowerStatus::Observer {
32 public:
33 explicit SettingsDefaultView(user::LoginStatus status)
34 : login_status_(status),
35 label_(NULL),
36 power_status_view_(NULL) {
37 PowerStatus::Get()->AddObserver(this);
38 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
39 ash::kTrayPopupPaddingHorizontal, 0,
40 ash::kTrayPopupPaddingBetweenItems));
42 bool power_view_right_align = false;
43 if (login_status_ != user::LOGGED_IN_NONE &&
44 login_status_ != user::LOGGED_IN_LOCKED) {
45 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
46 views::ImageView* icon =
47 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
48 icon->SetImage(
49 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
50 icon->set_id(test::kSettingsTrayItemViewId);
51 AddChildView(icon);
53 base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS);
54 label_ = new views::Label(text);
55 AddChildView(label_);
56 SetAccessibleName(text);
58 power_view_right_align = true;
61 if (PowerStatus::Get()->IsBatteryPresent()) {
62 power_status_view_ = new ash::PowerStatusView(
63 ash::PowerStatusView::VIEW_DEFAULT, power_view_right_align);
64 AddChildView(power_status_view_);
65 OnPowerStatusChanged();
69 virtual ~SettingsDefaultView() {
70 PowerStatus::Get()->RemoveObserver(this);
73 // Overridden from ash::ActionableView.
74 virtual bool PerformAction(const ui::Event& event) OVERRIDE {
75 if (login_status_ == user::LOGGED_IN_NONE ||
76 login_status_ == user::LOGGED_IN_LOCKED)
77 return false;
79 ash::Shell::GetInstance()->system_tray_delegate()->ShowSettings();
80 return true;
83 // Overridden from views::View.
84 virtual void Layout() OVERRIDE {
85 views::View::Layout();
87 if (label_ && power_status_view_) {
88 // Let the box-layout do the layout first. Then move power_status_view_
89 // to right align if it is created.
90 gfx::Size size = power_status_view_->GetPreferredSize();
91 gfx::Rect bounds(size);
92 bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems);
93 bounds.set_y((height() - size.height()) / 2);
94 power_status_view_->SetBoundsRect(bounds);
98 // Overridden from views::View.
99 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE {
100 views::View::ChildPreferredSizeChanged(child);
101 Layout();
104 // Overridden from PowerStatus::Observer.
105 virtual void OnPowerStatusChanged() OVERRIDE {
106 if (!PowerStatus::Get()->IsBatteryPresent())
107 return;
109 base::string16 accessible_name = label_ ?
110 label_->text() + base::ASCIIToUTF16(", ") +
111 PowerStatus::Get()->GetAccessibleNameString(true) :
112 PowerStatus::Get()->GetAccessibleNameString(true);
113 SetAccessibleName(accessible_name);
116 private:
117 user::LoginStatus login_status_;
118 views::Label* label_;
119 ash::PowerStatusView* power_status_view_;
121 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView);
124 } // namespace tray
126 TraySettings::TraySettings(SystemTray* system_tray)
127 : SystemTrayItem(system_tray),
128 default_view_(NULL) {
131 TraySettings::~TraySettings() {
134 views::View* TraySettings::CreateTrayView(user::LoginStatus status) {
135 return NULL;
138 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) {
139 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) &&
140 !PowerStatus::Get()->IsBatteryPresent())
141 return NULL;
142 if (!ash::Shell::GetInstance()->system_tray_delegate()->ShouldShowSettings())
143 return NULL;
144 CHECK(default_view_ == NULL);
145 default_view_ = new tray::SettingsDefaultView(status);
146 return default_view_;
149 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) {
150 NOTIMPLEMENTED();
151 return NULL;
154 void TraySettings::DestroyTrayView() {
157 void TraySettings::DestroyDefaultView() {
158 default_view_ = NULL;
161 void TraySettings::DestroyDetailedView() {
164 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) {
167 } // namespace ash