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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 PowerSupplyStatus supply_status_; | 160 PowerSupplyStatus supply_status_; |
161 | 161 |
162 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); | 162 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); |
163 }; | 163 }; |
164 | 164 |
165 } // namespace tray | 165 } // namespace tray |
166 | 166 |
167 TrayPower::TrayPower() | 167 TrayPower::TrayPower() |
168 : power_(NULL), | 168 : date_(NULL), |
| 169 power_(NULL), |
169 power_tray_(NULL) { | 170 power_tray_(NULL) { |
170 } | 171 } |
171 | 172 |
172 TrayPower::~TrayPower() { | 173 TrayPower::~TrayPower() { |
173 } | 174 } |
174 | 175 |
175 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 176 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
176 // There may not be enough information when this is created about whether | 177 // 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 | 178 // there is a battery or not. So always create this, and adjust visibility as |
178 // necessary. | 179 // necessary. |
179 PowerSupplyStatus power_status = | 180 PowerSupplyStatus power_status = |
180 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 181 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
181 power_tray_.reset(new tray::PowerTrayView()); | 182 DCHECK(power_tray_ == NULL); |
| 183 power_tray_ = new tray::PowerTrayView(); |
182 power_tray_->UpdatePowerStatus(power_status); | 184 power_tray_->UpdatePowerStatus(power_status); |
183 return power_tray_.get(); | 185 return power_tray_; |
184 } | 186 } |
185 | 187 |
186 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { | 188 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { |
187 date_.reset(new tray::DateView(tray::DateView::DATE)); | 189 DCHECK(date_ == NULL); |
| 190 date_ = new tray::DateView(tray::DateView::DATE); |
188 | 191 |
189 views::View* container = new views::View; | 192 views::View* container = new views::View; |
190 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | 193 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, |
191 0, 0, 0); | 194 0, 0, 0); |
192 | 195 |
193 layout->set_spread_blank_space(true); | 196 layout->set_spread_blank_space(true); |
194 container->SetLayoutManager(layout); | 197 container->SetLayoutManager(layout); |
195 container->set_background(views::Background::CreateSolidBackground( | 198 container->set_background(views::Background::CreateSolidBackground( |
196 kHeaderBackgroundColor)); | 199 kHeaderBackgroundColor)); |
197 HoverHighlightView* view = new HoverHighlightView(NULL); | 200 HoverHighlightView* view = new HoverHighlightView(NULL); |
198 view->SetLayoutManager(new views::FillLayout); | 201 view->SetLayoutManager(new views::FillLayout); |
199 view->AddChildView(date_.get()); | 202 view->AddChildView(date_); |
200 date_->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, | 203 date_->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, |
201 kTrayPopupPaddingHorizontal, | 204 kTrayPopupPaddingHorizontal, |
202 kPaddingVertical, | 205 kPaddingVertical, |
203 kTrayPopupPaddingHorizontal)); | 206 kTrayPopupPaddingHorizontal)); |
204 container->AddChildView(view); | 207 container->AddChildView(view); |
205 view->set_focusable(false); | 208 view->set_focusable(false); |
206 | 209 |
207 if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) { | 210 if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) { |
208 date_->SetActionable(true); | 211 date_->SetActionable(true); |
209 view->set_highlight_color(kHeaderHoverBackgroundColor); | 212 view->set_highlight_color(kHeaderHoverBackgroundColor); |
210 } else { | 213 } else { |
211 view->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); | 214 view->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); |
212 } | 215 } |
213 | 216 |
214 PowerSupplyStatus power_status = | 217 PowerSupplyStatus power_status = |
215 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 218 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
216 if (power_status.battery_is_present) { | 219 if (power_status.battery_is_present) { |
217 power_.reset(new tray::PowerPopupView()); | 220 DCHECK(power_ == NULL); |
| 221 power_ = new tray::PowerPopupView(); |
218 power_->UpdatePowerStatus(power_status); | 222 power_->UpdatePowerStatus(power_status); |
219 power_->set_border(views::Border::CreateSolidSidedBorder( | 223 power_->set_border(views::Border::CreateSolidSidedBorder( |
220 kPaddingVertical, kTrayPopupPaddingHorizontal, | 224 kPaddingVertical, kTrayPopupPaddingHorizontal, |
221 kPaddingVertical, kTrayPopupPaddingHorizontal, | 225 kPaddingVertical, kTrayPopupPaddingHorizontal, |
222 SkColorSetARGB(0, 0, 0, 0))); | 226 SkColorSetARGB(0, 0, 0, 0))); |
223 container->AddChildView(power_.get()); | 227 container->AddChildView(power_); |
224 } | 228 } |
225 ash::Shell::GetInstance()->tray_delegate()->RequestStatusUpdate(); | 229 ash::Shell::GetInstance()->tray_delegate()->RequestStatusUpdate(); |
226 | 230 |
227 return container; | 231 return container; |
228 } | 232 } |
229 | 233 |
230 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { | 234 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { |
231 return NULL; | 235 return NULL; |
232 } | 236 } |
233 | 237 |
234 void TrayPower::DestroyTrayView() { | 238 void TrayPower::DestroyTrayView() { |
235 power_tray_.reset(); | 239 power_tray_ = NULL; |
236 } | 240 } |
237 | 241 |
238 void TrayPower::DestroyDefaultView() { | 242 void TrayPower::DestroyDefaultView() { |
239 date_.reset(); | 243 date_ = NULL; |
240 power_.reset(); | 244 power_ = NULL; |
241 } | 245 } |
242 | 246 |
243 void TrayPower::DestroyDetailedView() { | 247 void TrayPower::DestroyDetailedView() { |
244 } | 248 } |
245 | 249 |
246 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 250 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
247 } | 251 } |
248 | 252 |
249 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 253 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
250 if (power_tray_.get()) | 254 if (power_tray_) |
251 power_tray_->UpdatePowerStatus(status); | 255 power_tray_->UpdatePowerStatus(status); |
252 if (power_.get()) | 256 if (power_) |
253 power_->UpdatePowerStatus(status); | 257 power_->UpdatePowerStatus(status); |
254 } | 258 } |
255 | 259 |
256 } // namespace internal | 260 } // namespace internal |
257 } // namespace ash | 261 } // namespace ash |
OLD | NEW |