replace OVERRIDE and FINAL with override and final in ash/
[chromium-blink-merge.git] / ash / system / chromeos / settings / tray_settings.cc
blob8b4c6c9dfa4e310e1b004d662fd03625ae5d84d7
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/session/session_state_delegate.h"
8 #include "ash/shell.h"
9 #include "ash/system/chromeos/power/power_status.h"
10 #include "ash/system/chromeos/power/power_status_view.h"
11 #include "ash/system/tray/actionable_view.h"
12 #include "ash/system/tray/fixed_sized_image_view.h"
13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/system/tray/tray_constants.h"
15 #include "base/logging.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "grit/ash_resources.h"
18 #include "grit/ash_strings.h"
19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h"
22 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/fill_layout.h"
26 #include "ui/views/view.h"
28 namespace ash {
29 namespace tray {
31 class SettingsDefaultView : public ActionableView,
32 public PowerStatus::Observer {
33 public:
34 explicit SettingsDefaultView(user::LoginStatus status)
35 : login_status_(status),
36 label_(NULL),
37 power_status_view_(NULL) {
38 PowerStatus::Get()->AddObserver(this);
39 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
40 ash::kTrayPopupPaddingHorizontal, 0,
41 ash::kTrayPopupPaddingBetweenItems));
43 bool power_view_right_align = false;
44 bool userAddingRunning = ash::Shell::GetInstance()
45 ->session_state_delegate()
46 ->IsInSecondaryLoginScreen();
48 if (login_status_ != user::LOGGED_IN_NONE &&
49 login_status_ != user::LOGGED_IN_LOCKED && !userAddingRunning) {
50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
51 views::ImageView* icon =
52 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
53 icon->SetImage(
54 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
55 icon->set_id(test::kSettingsTrayItemViewId);
56 AddChildView(icon);
58 base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS);
59 label_ = new views::Label(text);
60 AddChildView(label_);
61 SetAccessibleName(text);
63 power_view_right_align = true;
66 if (PowerStatus::Get()->IsBatteryPresent()) {
67 power_status_view_ = new ash::PowerStatusView(
68 ash::PowerStatusView::VIEW_DEFAULT, power_view_right_align);
69 AddChildView(power_status_view_);
70 OnPowerStatusChanged();
74 virtual ~SettingsDefaultView() {
75 PowerStatus::Get()->RemoveObserver(this);
78 // Overridden from ash::ActionableView.
79 virtual bool PerformAction(const ui::Event& event) override {
80 bool userAddingRunning = ash::Shell::GetInstance()
81 ->session_state_delegate()
82 ->IsInSecondaryLoginScreen();
84 if (login_status_ == user::LOGGED_IN_NONE ||
85 login_status_ == user::LOGGED_IN_LOCKED || userAddingRunning)
86 return false;
88 ash::Shell::GetInstance()->system_tray_delegate()->ShowSettings();
89 return true;
92 // Overridden from views::View.
93 virtual void Layout() override {
94 views::View::Layout();
96 if (label_ && power_status_view_) {
97 // Let the box-layout do the layout first. Then move power_status_view_
98 // to right align if it is created.
99 gfx::Size size = power_status_view_->GetPreferredSize();
100 gfx::Rect bounds(size);
101 bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems);
102 bounds.set_y((height() - size.height()) / 2);
103 power_status_view_->SetBoundsRect(bounds);
107 // Overridden from views::View.
108 virtual void ChildPreferredSizeChanged(views::View* child) override {
109 views::View::ChildPreferredSizeChanged(child);
110 Layout();
113 // Overridden from PowerStatus::Observer.
114 virtual void OnPowerStatusChanged() override {
115 if (!PowerStatus::Get()->IsBatteryPresent())
116 return;
118 base::string16 accessible_name = label_ ?
119 label_->text() + base::ASCIIToUTF16(", ") +
120 PowerStatus::Get()->GetAccessibleNameString(true) :
121 PowerStatus::Get()->GetAccessibleNameString(true);
122 SetAccessibleName(accessible_name);
125 private:
126 user::LoginStatus login_status_;
127 views::Label* label_;
128 ash::PowerStatusView* power_status_view_;
130 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView);
133 } // namespace tray
135 TraySettings::TraySettings(SystemTray* system_tray)
136 : SystemTrayItem(system_tray),
137 default_view_(NULL) {
140 TraySettings::~TraySettings() {
143 views::View* TraySettings::CreateTrayView(user::LoginStatus status) {
144 return NULL;
147 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) {
148 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) &&
149 !PowerStatus::Get()->IsBatteryPresent())
150 return NULL;
151 if (!ash::Shell::GetInstance()->system_tray_delegate()->ShouldShowSettings())
152 return NULL;
153 CHECK(default_view_ == NULL);
154 default_view_ = new tray::SettingsDefaultView(status);
155 return default_view_;
158 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) {
159 NOTIMPLEMENTED();
160 return NULL;
163 void TraySettings::DestroyTrayView() {
166 void TraySettings::DestroyDefaultView() {
167 default_view_ = NULL;
170 void TraySettings::DestroyDetailedView() {
173 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) {
176 } // namespace ash