| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/date/date_view.h" | 9 #include "ash/system/date/date_view.h" |
| 10 #include "ash/system/power/power_status_view.h" | 10 #include "ash/system/power/power_status_view.h" |
| 11 #include "ash/system/power/power_supply_status.h" | 11 #include "ash/system/power/power_supply_status.h" |
| 12 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 13 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
| 14 #include "ash/system/tray/tray_notification_view.h" | 14 #include "ash/system/tray/tray_notification_view.h" |
| 15 #include "ash/system/tray/tray_views.h" | 15 #include "ash/system/tray/tray_views.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 21 #include "grit/ui_resources.h" | 21 #include "grit/ui_resources.h" |
| 22 #include "third_party/skia/include/core/SkRect.h" | 22 #include "third_party/skia/include/core/SkRect.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 27 #include "ui/gfx/image/image_skia_operations.h" |
| 27 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
| 28 #include "ui/views/controls/button/button.h" | 29 #include "ui/views/controls/button/button.h" |
| 29 #include "ui/views/controls/button/text_button.h" | 30 #include "ui/views/controls/button/text_button.h" |
| 30 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 31 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/box_layout.h" |
| 33 #include "ui/views/layout/fill_layout.h" | 34 #include "ui/views/layout/fill_layout.h" |
| 34 #include "ui/views/layout/grid_layout.h" | 35 #include "ui/views/layout/grid_layout.h" |
| 35 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
| 36 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 notification_state_(NOTIFICATION_NONE) { | 120 notification_state_(NOTIFICATION_NONE) { |
| 120 } | 121 } |
| 121 | 122 |
| 122 TrayPower::~TrayPower() { | 123 TrayPower::~TrayPower() { |
| 123 } | 124 } |
| 124 | 125 |
| 125 // static | 126 // static |
| 126 gfx::ImageSkia TrayPower::GetBatteryImage( | 127 gfx::ImageSkia TrayPower::GetBatteryImage( |
| 127 const PowerSupplyStatus& supply_status, | 128 const PowerSupplyStatus& supply_status, |
| 128 IconSet icon_set) { | 129 IconSet icon_set) { |
| 129 gfx::ImageSkia image; | |
| 130 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 130 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 131 icon_set == ICON_DARK ? | 131 icon_set == ICON_DARK ? |
| 132 IDR_AURA_UBER_TRAY_POWER_SMALL_DARK : IDR_AURA_UBER_TRAY_POWER_SMALL); | 132 IDR_AURA_UBER_TRAY_POWER_SMALL_DARK : IDR_AURA_UBER_TRAY_POWER_SMALL); |
| 133 | 133 |
| 134 int image_index = 0; | 134 int image_index = 0; |
| 135 if (supply_status.battery_percentage >= 100) { | 135 if (supply_status.battery_percentage >= 100) { |
| 136 image_index = kNumPowerImages - 1; | 136 image_index = kNumPowerImages - 1; |
| 137 } else if (!supply_status.battery_is_present) { | 137 } else if (!supply_status.battery_is_present) { |
| 138 image_index = kNumPowerImages; | 138 image_index = kNumPowerImages; |
| 139 } else { | 139 } else { |
| 140 double percentage = supply_status.is_calculating_battery_time ? 100.0 : | 140 double percentage = supply_status.is_calculating_battery_time ? 100.0 : |
| 141 supply_status.battery_percentage; | 141 supply_status.battery_percentage; |
| 142 image_index = static_cast<int>(percentage / 100.0 * (kNumPowerImages - 1)); | 142 image_index = static_cast<int>(percentage / 100.0 * (kNumPowerImages - 1)); |
| 143 image_index = std::max(std::min(image_index, kNumPowerImages - 2), 0); | 143 image_index = std::max(std::min(image_index, kNumPowerImages - 2), 0); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // TODO(mbolohan): Remove the 2px offset when the assets are centered. See | 146 // TODO(mbolohan): Remove the 2px offset when the assets are centered. See |
| 147 // crbug.com/119832. | 147 // crbug.com/119832. |
| 148 SkIRect region = SkIRect::MakeXYWH( | 148 gfx::Rect region( |
| 149 (supply_status.line_power_on ? kBatteryImageWidth : 0) + 2, | 149 (supply_status.line_power_on ? kBatteryImageWidth : 0) + 2, |
| 150 image_index * kBatteryImageHeight, | 150 image_index * kBatteryImageHeight, |
| 151 kBatteryImageWidth - 2, kBatteryImageHeight); | 151 kBatteryImageWidth - 2, kBatteryImageHeight); |
| 152 all.ToImageSkia()->extractSubset(&image, region); | 152 return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region); |
| 153 return image; | |
| 154 } | 153 } |
| 155 | 154 |
| 156 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 155 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
| 157 // There may not be enough information when this is created about whether | 156 // There may not be enough information when this is created about whether |
| 158 // there is a battery or not. So always create this, and adjust visibility as | 157 // there is a battery or not. So always create this, and adjust visibility as |
| 159 // necessary. | 158 // necessary. |
| 160 PowerSupplyStatus power_status = | 159 PowerSupplyStatus power_status = |
| 161 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | 160 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
| 162 CHECK(power_tray_ == NULL); | 161 CHECK(power_tray_ == NULL); |
| 163 power_tray_ = new tray::PowerTrayView(); | 162 power_tray_ = new tray::PowerTrayView(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return false; | 248 return false; |
| 250 case NOTIFICATION_CRITICAL: | 249 case NOTIFICATION_CRITICAL: |
| 251 return false; | 250 return false; |
| 252 } | 251 } |
| 253 NOTREACHED(); | 252 NOTREACHED(); |
| 254 return false; | 253 return false; |
| 255 } | 254 } |
| 256 | 255 |
| 257 } // namespace internal | 256 } // namespace internal |
| 258 } // namespace ash | 257 } // namespace ash |
| OLD | NEW |