| 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/common/system/chromeos/power/tray_power.h" | 5 #include "ash/common/system/chromeos/power/tray_power.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accessibility_delegate.h" | 9 #include "ash/common/accessibility_delegate.h" |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 << " Remaining time: " << remaining_minutes << " minutes."; | 85 << " Remaining time: " << remaining_minutes << " minutes."; |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 namespace tray { | 90 namespace tray { |
| 91 | 91 |
| 92 // This view is used only for the tray. | 92 // This view is used only for the tray. |
| 93 class PowerTrayView : public views::ImageView { | 93 class PowerTrayView : public views::ImageView { |
| 94 public: | 94 public: |
| 95 PowerTrayView() { | 95 PowerTrayView() { UpdateImage(); } |
| 96 UpdateImage(); | |
| 97 } | |
| 98 | 96 |
| 99 ~PowerTrayView() override {} | 97 ~PowerTrayView() override {} |
| 100 | 98 |
| 101 // Overriden from views::View. | 99 // Overriden from views::View. |
| 102 void GetAccessibleState(ui::AXViewState* state) override { | 100 void GetAccessibleState(ui::AXViewState* state) override { |
| 103 state->name = accessible_name_; | 101 state->name = accessible_name_; |
| 104 state->role = ui::AX_ROLE_BUTTON; | 102 state->role = ui::AX_ROLE_BUTTON; |
| 105 } | 103 } |
| 106 | 104 |
| 107 void UpdateStatus(bool battery_alert) { | 105 void UpdateStatus(bool battery_alert) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 views::View* TrayPower::CreateDefaultView(LoginStatus status) { | 171 views::View* TrayPower::CreateDefaultView(LoginStatus status) { |
| 174 // Make sure icon status is up to date. (Also triggers stub activation). | 172 // Make sure icon status is up to date. (Also triggers stub activation). |
| 175 PowerStatus::Get()->RequestStatusUpdate(); | 173 PowerStatus::Get()->RequestStatusUpdate(); |
| 176 return NULL; | 174 return NULL; |
| 177 } | 175 } |
| 178 | 176 |
| 179 void TrayPower::DestroyTrayView() { | 177 void TrayPower::DestroyTrayView() { |
| 180 power_tray_ = NULL; | 178 power_tray_ = NULL; |
| 181 } | 179 } |
| 182 | 180 |
| 183 void TrayPower::DestroyDefaultView() { | 181 void TrayPower::DestroyDefaultView() {} |
| 184 } | |
| 185 | 182 |
| 186 void TrayPower::UpdateAfterLoginStatusChange(LoginStatus status) {} | 183 void TrayPower::UpdateAfterLoginStatusChange(LoginStatus status) {} |
| 187 | 184 |
| 188 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 185 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 189 SetTrayImageItemBorder(power_tray_, alignment); | 186 SetTrayImageItemBorder(power_tray_, alignment); |
| 190 } | 187 } |
| 191 | 188 |
| 192 void TrayPower::OnPowerStatusChanged() { | 189 void TrayPower::OnPowerStatusChanged() { |
| 193 bool battery_alert = UpdateNotificationState(); | 190 bool battery_alert = UpdateNotificationState(); |
| 194 if (power_tray_) | 191 if (power_tray_) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return; | 256 return; |
| 260 } | 257 } |
| 261 | 258 |
| 262 if (!dual_role_notification_) | 259 if (!dual_role_notification_) |
| 263 dual_role_notification_.reset(new DualRoleNotification(message_center_)); | 260 dual_role_notification_.reset(new DualRoleNotification(message_center_)); |
| 264 dual_role_notification_->Update(); | 261 dual_role_notification_->Update(); |
| 265 } | 262 } |
| 266 | 263 |
| 267 bool TrayPower::UpdateNotificationState() { | 264 bool TrayPower::UpdateNotificationState() { |
| 268 const PowerStatus& status = *PowerStatus::Get(); | 265 const PowerStatus& status = *PowerStatus::Get(); |
| 269 if (!status.IsBatteryPresent() || | 266 if (!status.IsBatteryPresent() || status.IsBatteryTimeBeingCalculated() || |
| 270 status.IsBatteryTimeBeingCalculated() || | |
| 271 status.IsMainsChargerConnected()) { | 267 status.IsMainsChargerConnected()) { |
| 272 notification_state_ = NOTIFICATION_NONE; | 268 notification_state_ = NOTIFICATION_NONE; |
| 273 return false; | 269 return false; |
| 274 } | 270 } |
| 275 | 271 |
| 276 return status.IsUsbChargerConnected() ? | 272 return status.IsUsbChargerConnected() |
| 277 UpdateNotificationStateForRemainingPercentage() : | 273 ? UpdateNotificationStateForRemainingPercentage() |
| 278 UpdateNotificationStateForRemainingTime(); | 274 : UpdateNotificationStateForRemainingTime(); |
| 279 } | 275 } |
| 280 | 276 |
| 281 bool TrayPower::UpdateNotificationStateForRemainingTime() { | 277 bool TrayPower::UpdateNotificationStateForRemainingTime() { |
| 282 // The notification includes a rounded minutes value, so round the estimate | 278 // The notification includes a rounded minutes value, so round the estimate |
| 283 // received from the power manager to match. | 279 // received from the power manager to match. |
| 284 const int remaining_minutes = static_cast<int>( | 280 const int remaining_minutes = static_cast<int>( |
| 285 PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5); | 281 PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5); |
| 286 | 282 |
| 287 if (remaining_minutes >= kNoWarningMinutes || | 283 if (remaining_minutes >= kNoWarningMinutes || |
| 288 PowerStatus::Get()->IsBatteryFull()) { | 284 PowerStatus::Get()->IsBatteryFull()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 350 } |
| 355 NOTREACHED(); | 351 NOTREACHED(); |
| 356 return false; | 352 return false; |
| 357 } | 353 } |
| 358 | 354 |
| 359 void TrayPower::NotifyUsbNotificationClosedByUser() { | 355 void TrayPower::NotifyUsbNotificationClosedByUser() { |
| 360 usb_notification_dismissed_ = true; | 356 usb_notification_dismissed_ = true; |
| 361 } | 357 } |
| 362 | 358 |
| 363 } // namespace ash | 359 } // namespace ash |
| OLD | NEW |