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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 views::Label* time_label_; | 183 views::Label* time_label_; |
184 | 184 |
185 PowerSupplyStatus supply_status_; | 185 PowerSupplyStatus supply_status_; |
186 | 186 |
187 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); | 187 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); |
188 }; | 188 }; |
189 | 189 |
190 } // namespace tray | 190 } // namespace tray |
191 | 191 |
192 TrayPower::TrayPower() | 192 TrayPower::TrayPower() |
193 : power_(NULL), | 193 : date_(NULL), |
| 194 power_(NULL), |
194 power_tray_(NULL) { | 195 power_tray_(NULL) { |
195 } | 196 } |
196 | 197 |
197 TrayPower::~TrayPower() { | 198 TrayPower::~TrayPower() { |
198 } | 199 } |
199 | 200 |
200 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 201 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
201 // There may not be enough information when this is created about whether | 202 // There may not be enough information when this is created about whether |
202 // there is a battery or not. So always create this, and adjust visibility as | 203 // there is a battery or not. So always create this, and adjust visibility as |
203 // necessary. | 204 // necessary. |
204 PowerSupplyStatus power_status = | 205 PowerSupplyStatus power_status = |
205 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 206 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
206 power_tray_.reset(new tray::PowerTrayView()); | 207 CHECK(power_tray_ == NULL); |
| 208 power_tray_ = new tray::PowerTrayView(); |
207 power_tray_->UpdatePowerStatus(power_status); | 209 power_tray_->UpdatePowerStatus(power_status); |
208 return power_tray_.get(); | 210 return power_tray_; |
209 } | 211 } |
210 | 212 |
211 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { | 213 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { |
212 date_.reset(new tray::DateView()); | 214 CHECK(date_ == NULL); |
| 215 date_ = new tray::DateView(); |
213 | 216 |
214 views::View* container = new views::View; | 217 views::View* container = new views::View; |
215 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | 218 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, |
216 0, 0, 0); | 219 0, 0, 0); |
217 | 220 |
218 layout->set_spread_blank_space(true); | 221 layout->set_spread_blank_space(true); |
219 container->SetLayoutManager(layout); | 222 container->SetLayoutManager(layout); |
220 container->set_background(views::Background::CreateSolidBackground( | 223 container->set_background(views::Background::CreateSolidBackground( |
221 kHeaderBackgroundColor)); | 224 kHeaderBackgroundColor)); |
222 HoverHighlightView* view = new HoverHighlightView(NULL); | 225 HoverHighlightView* view = new HoverHighlightView(NULL); |
223 view->SetLayoutManager(new views::FillLayout); | 226 view->SetLayoutManager(new views::FillLayout); |
224 view->AddChildView(date_.get()); | 227 view->AddChildView(date_); |
225 date_->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, | 228 date_->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, |
226 kTrayPopupPaddingHorizontal, | 229 kTrayPopupPaddingHorizontal, |
227 kPaddingVertical, | 230 kPaddingVertical, |
228 kTrayPopupPaddingHorizontal)); | 231 kTrayPopupPaddingHorizontal)); |
229 container->AddChildView(view); | 232 container->AddChildView(view); |
230 view->set_focusable(false); | 233 view->set_focusable(false); |
231 | 234 |
232 if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) { | 235 if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) { |
233 date_->SetActionable(true); | 236 date_->SetActionable(true); |
234 view->set_highlight_color(kHeaderHoverBackgroundColor); | 237 view->set_highlight_color(kHeaderHoverBackgroundColor); |
235 } else { | 238 } else { |
236 view->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); | 239 view->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); |
237 } | 240 } |
238 | 241 |
239 PowerSupplyStatus power_status = | 242 PowerSupplyStatus power_status = |
240 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 243 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
241 if (power_status.battery_is_present) { | 244 if (power_status.battery_is_present) { |
242 power_.reset(new tray::PowerPopupView()); | 245 CHECK(power_ == NULL); |
| 246 power_ = new tray::PowerPopupView(); |
243 power_->UpdatePowerStatus(power_status); | 247 power_->UpdatePowerStatus(power_status); |
244 power_->set_border(views::Border::CreateSolidSidedBorder( | 248 power_->set_border(views::Border::CreateSolidSidedBorder( |
245 kPaddingVertical, kTrayPopupPaddingHorizontal, | 249 kPaddingVertical, kTrayPopupPaddingHorizontal, |
246 kPaddingVertical, kTrayPopupPaddingHorizontal, | 250 kPaddingVertical, kTrayPopupPaddingHorizontal, |
247 SkColorSetARGB(0, 0, 0, 0))); | 251 SkColorSetARGB(0, 0, 0, 0))); |
248 container->AddChildView(power_.get()); | 252 container->AddChildView(power_); |
249 } | 253 } |
250 ash::Shell::GetInstance()->tray_delegate()->RequestStatusUpdate(); | 254 ash::Shell::GetInstance()->tray_delegate()->RequestStatusUpdate(); |
251 | 255 |
252 return container; | 256 return container; |
253 } | 257 } |
254 | 258 |
255 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { | 259 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { |
256 return NULL; | 260 return NULL; |
257 } | 261 } |
258 | 262 |
259 void TrayPower::DestroyTrayView() { | 263 void TrayPower::DestroyTrayView() { |
260 power_tray_.reset(); | 264 power_tray_ = NULL; |
261 } | 265 } |
262 | 266 |
263 void TrayPower::DestroyDefaultView() { | 267 void TrayPower::DestroyDefaultView() { |
264 date_.reset(); | 268 date_ = NULL; |
265 power_.reset(); | 269 power_ = NULL; |
266 } | 270 } |
267 | 271 |
268 void TrayPower::DestroyDetailedView() { | 272 void TrayPower::DestroyDetailedView() { |
269 } | 273 } |
270 | 274 |
271 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 275 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
272 } | 276 } |
273 | 277 |
274 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 278 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
275 if (power_tray_.get()) | 279 if (power_tray_) |
276 power_tray_->UpdatePowerStatus(status); | 280 power_tray_->UpdatePowerStatus(status); |
277 if (power_.get()) | 281 if (power_) |
278 power_->UpdatePowerStatus(status); | 282 power_->UpdatePowerStatus(status); |
279 } | 283 } |
280 | 284 |
281 } // namespace internal | 285 } // namespace internal |
282 } // namespace ash | 286 } // namespace ash |
OLD | NEW |