| 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" | |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
| 11 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| 12 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chromeos/dbus/power_supply_status.h" |
| 15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
| 16 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/views/controls/button/button.h" | 23 #include "ui/views/controls/button/button.h" |
| 24 #include "ui/views/controls/button/text_button.h" | 24 #include "ui/views/controls/button/text_button.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 // This view is used only for the tray. | 46 // This view is used only for the tray. |
| 47 class PowerTrayView : public views::ImageView { | 47 class PowerTrayView : public views::ImageView { |
| 48 public: | 48 public: |
| 49 PowerTrayView() { | 49 PowerTrayView() { |
| 50 UpdateImage(); | 50 UpdateImage(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual ~PowerTrayView() { | 53 virtual ~PowerTrayView() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 void UpdatePowerStatus(const PowerSupplyStatus& status) { | 56 void UpdatePowerStatus(const chromeos::PowerSupplyStatus& status) { |
| 57 supply_status_ = status; | 57 supply_status_ = status; |
| 58 // Sanitize. | 58 // Sanitize. |
| 59 if (supply_status_.battery_is_full) | 59 if (supply_status_.battery_is_full) |
| 60 supply_status_.battery_percentage = 100.0; | 60 supply_status_.battery_percentage = 100.0; |
| 61 | 61 |
| 62 UpdateImage(); | 62 UpdateImage(); |
| 63 SetVisible(status.battery_is_present); | 63 SetVisible(status.battery_is_present); |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 | 84 |
| 85 SkIRect region = SkIRect::MakeXYWH( | 85 SkIRect region = SkIRect::MakeXYWH( |
| 86 supply_status_.line_power_on ? kBatteryImageWidth : 0, | 86 supply_status_.line_power_on ? kBatteryImageWidth : 0, |
| 87 image_index * kBatteryImageHeight, | 87 image_index * kBatteryImageHeight, |
| 88 kBatteryImageWidth, kBatteryImageHeight); | 88 kBatteryImageWidth, kBatteryImageHeight); |
| 89 all.ToSkBitmap()->extractSubset(&image, region); | 89 all.ToSkBitmap()->extractSubset(&image, region); |
| 90 | 90 |
| 91 SetImage(image); | 91 SetImage(image); |
| 92 } | 92 } |
| 93 | 93 |
| 94 PowerSupplyStatus supply_status_; | 94 chromeos::PowerSupplyStatus supply_status_; |
| 95 | 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); | 96 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // This view is used only for the popup. | 99 // This view is used only for the popup. |
| 100 class PowerPopupView : public views::Label { | 100 class PowerPopupView : public views::Label { |
| 101 public: | 101 public: |
| 102 PowerPopupView() { | 102 PowerPopupView() { |
| 103 SetHorizontalAlignment(ALIGN_RIGHT); | 103 SetHorizontalAlignment(ALIGN_RIGHT); |
| 104 UpdateText(); | 104 UpdateText(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual ~PowerPopupView() { | 107 virtual ~PowerPopupView() { |
| 108 } | 108 } |
| 109 | 109 |
| 110 void UpdatePowerStatus(const PowerSupplyStatus& status) { | 110 void UpdatePowerStatus(const chromeos::PowerSupplyStatus& status) { |
| 111 supply_status_ = status; | 111 supply_status_ = status; |
| 112 // Sanitize. | 112 // Sanitize. |
| 113 if (supply_status_.battery_is_full) | 113 if (supply_status_.battery_is_full) |
| 114 supply_status_.battery_percentage = 100.0; | 114 supply_status_.battery_percentage = 100.0; |
| 115 | 115 |
| 116 UpdateText(); | 116 UpdateText(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 void UpdateText() { | 120 void UpdateText() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 134 } else { | 134 } else { |
| 135 if (supply_status_.line_power_on) { | 135 if (supply_status_.line_power_on) { |
| 136 SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL)); | 136 SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL)); |
| 137 } else { | 137 } else { |
| 138 // Completely discharged? ... ha? | 138 // Completely discharged? ... ha? |
| 139 SetText(string16()); | 139 SetText(string16()); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 PowerSupplyStatus supply_status_; | 144 chromeos::PowerSupplyStatus supply_status_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); | 146 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace tray | 149 } // namespace tray |
| 150 | 150 |
| 151 TrayPower::TrayPower() | 151 TrayPower::TrayPower() |
| 152 : power_(NULL), | 152 : power_(NULL), |
| 153 power_tray_(NULL) { | 153 power_tray_(NULL) { |
| 154 } | 154 } |
| 155 | 155 |
| 156 TrayPower::~TrayPower() { | 156 TrayPower::~TrayPower() { |
| 157 } | 157 } |
| 158 | 158 |
| 159 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 159 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
| 160 // There may not be enough information when this is created about whether | 160 // There may not be enough information when this is created about whether |
| 161 // there is a battery or not. So always create this, and adjust visibility as | 161 // there is a battery or not. So always create this, and adjust visibility as |
| 162 // necessary. | 162 // necessary. |
| 163 PowerSupplyStatus power_status = | 163 chromeos::PowerSupplyStatus power_status = |
| 164 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 164 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
| 165 power_tray_.reset(new tray::PowerTrayView()); | 165 power_tray_.reset(new tray::PowerTrayView()); |
| 166 power_tray_->UpdatePowerStatus(power_status); | 166 power_tray_->UpdatePowerStatus(power_status); |
| 167 return power_tray_.get(); | 167 return power_tray_.get(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { | 170 views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { |
| 171 date_.reset(new tray::DateView(tray::DateView::DATE)); | 171 date_.reset(new tray::DateView(tray::DateView::DATE)); |
| 172 if (status != user::LOGGED_IN_NONE) | 172 if (status != user::LOGGED_IN_NONE) |
| 173 date_->set_actionable(true); | 173 date_->set_actionable(true); |
| 174 | 174 |
| 175 views::View* container = new views::View; | 175 views::View* container = new views::View; |
| 176 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | 176 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 177 kTrayPopupPaddingHorizontal, 10, 0); | 177 kTrayPopupPaddingHorizontal, 10, 0); |
| 178 layout->set_spread_blank_space(true); | 178 layout->set_spread_blank_space(true); |
| 179 container->SetLayoutManager(layout); | 179 container->SetLayoutManager(layout); |
| 180 container->set_background(views::Background::CreateSolidBackground( | 180 container->set_background(views::Background::CreateSolidBackground( |
| 181 SkColorSetRGB(245, 245, 245))); | 181 SkColorSetRGB(245, 245, 245))); |
| 182 container->AddChildView(date_.get()); | 182 container->AddChildView(date_.get()); |
| 183 | 183 |
| 184 PowerSupplyStatus power_status = | 184 chromeos::PowerSupplyStatus power_status = |
| 185 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 185 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
| 186 if (power_status.battery_is_present) { | 186 if (power_status.battery_is_present) { |
| 187 power_.reset(new tray::PowerPopupView()); | 187 power_.reset(new tray::PowerPopupView()); |
| 188 power_->UpdatePowerStatus(power_status); | 188 power_->UpdatePowerStatus(power_status); |
| 189 container->AddChildView(power_.get()); | 189 container->AddChildView(power_.get()); |
| 190 } | 190 } |
| 191 return container; | 191 return container; |
| 192 } | 192 } |
| 193 | 193 |
| 194 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { | 194 views::View* TrayPower::CreateDetailedView(user::LoginStatus status) { |
| 195 return NULL; | 195 return NULL; |
| 196 } | 196 } |
| 197 | 197 |
| 198 void TrayPower::DestroyTrayView() { | 198 void TrayPower::DestroyTrayView() { |
| 199 power_tray_.reset(); | 199 power_tray_.reset(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void TrayPower::DestroyDefaultView() { | 202 void TrayPower::DestroyDefaultView() { |
| 203 date_.reset(); | 203 date_.reset(); |
| 204 power_.reset(); | 204 power_.reset(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void TrayPower::DestroyDetailedView() { | 207 void TrayPower::DestroyDetailedView() { |
| 208 } | 208 } |
| 209 | 209 |
| 210 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 210 void TrayPower::OnPowerStatusChanged( |
| 211 const chromeos::PowerSupplyStatus& status) { |
| 211 if (power_tray_.get()) | 212 if (power_tray_.get()) |
| 212 power_tray_->UpdatePowerStatus(status); | 213 power_tray_->UpdatePowerStatus(status); |
| 213 if (power_.get()) | 214 if (power_.get()) |
| 214 power_->UpdatePowerStatus(status); | 215 power_->UpdatePowerStatus(status); |
| 215 } | 216 } |
| 216 | 217 |
| 217 } // namespace internal | 218 } // namespace internal |
| 218 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |