OLD | NEW |
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/power/tray_power.h" | 5 #include "ash/system/power/tray_power.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/date/date_view.h" | 8 #include "ash/system/date/date_view.h" |
9 #include "ash/system/power/power_supply_status.h" | 9 #include "ash/system/power/power_supply_status.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 SetImage(image); | 97 SetImage(image); |
98 } | 98 } |
99 | 99 |
100 PowerSupplyStatus supply_status_; | 100 PowerSupplyStatus supply_status_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); | 102 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); |
103 }; | 103 }; |
104 | 104 |
105 // This view is used only for the popup. | 105 // This view is used only for the popup. |
106 class PowerPopupView : public views::Label { | 106 class PowerPopupView : public views::View { |
107 public: | 107 public: |
108 PowerPopupView() { | 108 PowerPopupView() { |
109 SetHorizontalAlignment(ALIGN_RIGHT); | 109 status_label_ = new views::Label; |
110 SetMultiLine(true); | 110 status_label_->SetHorizontalAlignment(views::Label::ALIGN_RIGHT); |
| 111 time_label_ = new views::Label; |
| 112 time_label_->SetHorizontalAlignment(views::Label::ALIGN_RIGHT); |
111 UpdateText(); | 113 UpdateText(); |
| 114 |
| 115 SetLayoutManager( |
| 116 new views::BoxLayout( |
| 117 views::BoxLayout::kVertical, 0, 0, kTrayPopupTextSpacingVertical)); |
| 118 AddChildView(status_label_); |
| 119 AddChildView(time_label_); |
112 } | 120 } |
113 | 121 |
114 virtual ~PowerPopupView() { | 122 virtual ~PowerPopupView() { |
115 } | 123 } |
116 | 124 |
117 void UpdatePowerStatus(const PowerSupplyStatus& status) { | 125 void UpdatePowerStatus(const PowerSupplyStatus& status) { |
118 supply_status_ = status; | 126 supply_status_ = status; |
119 // Sanitize. | 127 // Sanitize. |
120 if (supply_status_.battery_is_full) | 128 if (supply_status_.battery_is_full) |
121 supply_status_.battery_percentage = 100.0; | 129 supply_status_.battery_percentage = 100.0; |
122 | 130 |
123 UpdateText(); | 131 UpdateText(); |
124 } | 132 } |
125 | 133 |
126 private: | 134 private: |
127 void UpdateText() { | 135 void UpdateText() { |
128 if (supply_status_.is_calculating_battery_time) { | 136 if (supply_status_.is_calculating_battery_time) { |
129 SetText(l10n_util::GetStringFUTF16(supply_status_.line_power_on ? | 137 status_label_->SetText( |
130 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_ON : | 138 l10n_util::GetStringFUTF16( |
131 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_OFF, | 139 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, |
132 base::IntToString16( | 140 base::IntToString16( |
133 static_cast<int>(supply_status_.battery_percentage)))); | 141 static_cast<int>(supply_status_.battery_percentage)))); |
| 142 time_label_->SetText( |
| 143 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 144 supply_status_.line_power_on ? |
| 145 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_ON : |
| 146 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_OFF)); |
134 return; | 147 return; |
135 } | 148 } |
136 | 149 |
137 base::TimeDelta time = base::TimeDelta::FromSeconds( | 150 base::TimeDelta time = base::TimeDelta::FromSeconds( |
138 supply_status_.line_power_on ? | 151 supply_status_.line_power_on ? |
139 supply_status_.battery_seconds_to_full : | 152 supply_status_.battery_seconds_to_full : |
140 supply_status_.battery_seconds_to_empty); | 153 supply_status_.battery_seconds_to_empty); |
141 int hour = time.InHours(); | 154 int hour = time.InHours(); |
142 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes(); | 155 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes(); |
143 if (hour || min) { | 156 if (hour || min) { |
144 SetText(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_BATTERY_STATUS, | 157 status_label_->SetText( |
145 base::IntToString16( | 158 l10n_util::GetStringFUTF16( |
146 static_cast<int>(supply_status_.battery_percentage)), | 159 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, |
147 base::IntToString16(hour), | 160 base::IntToString16( |
148 base::IntToString16(min))); | 161 static_cast<int>(supply_status_.battery_percentage)))); |
| 162 time_label_->SetText( |
| 163 l10n_util::GetStringFUTF16( |
| 164 supply_status_.line_power_on ? |
| 165 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL : |
| 166 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_EMPTY, |
| 167 base::IntToString16(hour), |
| 168 base::IntToString16(min))); |
149 } else { | 169 } else { |
150 if (supply_status_.line_power_on) { | 170 if (supply_status_.line_power_on) { |
151 SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 171 status_label_->SetText( |
152 IDS_ASH_STATUS_TRAY_BATTERY_FULL)); | 172 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 173 IDS_ASH_STATUS_TRAY_BATTERY_FULL)); |
153 } else { | 174 } else { |
154 // Completely discharged? ... ha? | 175 // Completely discharged? ... ha? |
155 SetText(string16()); | 176 status_label_->SetText(string16()); |
156 } | 177 } |
| 178 time_label_->SetText(string16()); |
157 } | 179 } |
158 } | 180 } |
159 | 181 |
| 182 views::Label* status_label_; |
| 183 views::Label* time_label_; |
| 184 |
160 PowerSupplyStatus supply_status_; | 185 PowerSupplyStatus supply_status_; |
161 | 186 |
162 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); | 187 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); |
163 }; | 188 }; |
164 | 189 |
165 } // namespace tray | 190 } // namespace tray |
166 | 191 |
167 TrayPower::TrayPower() | 192 TrayPower::TrayPower() |
168 : power_(NULL), | 193 : power_(NULL), |
169 power_tray_(NULL) { | 194 power_tray_(NULL) { |
170 } | 195 } |
171 | 196 |
172 TrayPower::~TrayPower() { | 197 TrayPower::~TrayPower() { |
173 } | 198 } |
174 | 199 |
175 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 200 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
176 // There may not be enough information when this is created about whether | 201 // There may not be enough information when this is created about whether |
177 // there is a battery or not. So always create this, and adjust visibility as | 202 // there is a battery or not. So always create this, and adjust visibility as |
178 // necessary. | 203 // necessary. |
179 PowerSupplyStatus power_status = | 204 PowerSupplyStatus power_status = |
180 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 205 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
181 power_tray_.reset(new tray::PowerTrayView()); | 206 power_tray_.reset(new tray::PowerTrayView()); |
182 power_tray_->UpdatePowerStatus(power_status); | 207 power_tray_->UpdatePowerStatus(power_status); |
183 return power_tray_.get(); | 208 return power_tray_.get(); |
184 } | 209 } |
185 | 210 |
186 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { | 211 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { |
187 date_.reset(new tray::DateView(tray::DateView::DATE)); | 212 date_.reset(new tray::DateView()); |
188 | 213 |
189 views::View* container = new views::View; | 214 views::View* container = new views::View; |
190 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | 215 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, |
191 0, 0, 0); | 216 0, 0, 0); |
192 | 217 |
193 layout->set_spread_blank_space(true); | 218 layout->set_spread_blank_space(true); |
194 container->SetLayoutManager(layout); | 219 container->SetLayoutManager(layout); |
195 container->set_background(views::Background::CreateSolidBackground( | 220 container->set_background(views::Background::CreateSolidBackground( |
196 kHeaderBackgroundColor)); | 221 kHeaderBackgroundColor)); |
197 HoverHighlightView* view = new HoverHighlightView(NULL); | 222 HoverHighlightView* view = new HoverHighlightView(NULL); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 273 |
249 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 274 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
250 if (power_tray_.get()) | 275 if (power_tray_.get()) |
251 power_tray_->UpdatePowerStatus(status); | 276 power_tray_->UpdatePowerStatus(status); |
252 if (power_.get()) | 277 if (power_.get()) |
253 power_->UpdatePowerStatus(status); | 278 power_->UpdatePowerStatus(status); |
254 } | 279 } |
255 | 280 |
256 } // namespace internal | 281 } // namespace internal |
257 } // namespace ash | 282 } // namespace ash |
OLD | NEW |