| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/status/power_menu_button.h" | 5 #include "chrome/browser/chromeos/status/power_menu_button.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 13 #include "gfx/canvas.h" | 13 #include "gfx/canvas.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 // PowerMenuButton | 20 // PowerMenuButton |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 const int PowerMenuButton::kNumPowerImages = 12; | 23 const int PowerMenuButton::kNumPowerImages = 16; |
| 24 | 24 |
| 25 PowerMenuButton::PowerMenuButton() | 25 PowerMenuButton::PowerMenuButton() |
| 26 : StatusAreaButton(this), | 26 : StatusAreaButton(this), |
| 27 battery_is_present_(false), | 27 battery_is_present_(false), |
| 28 line_power_on_(false), | 28 line_power_on_(false), |
| 29 battery_fully_charged_(false), | 29 battery_fully_charged_(false), |
| 30 battery_percentage_(0.0), | 30 battery_percentage_(0.0), |
| 31 icon_id_(-1), | 31 icon_id_(-1), |
| 32 ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) { | 32 ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) { |
| 33 UpdateIconAndLabelInfo(); | 33 UpdateIconAndLabelInfo(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 104 // PowerMenuButton, PowerLibrary::Observer implementation: | 104 // PowerMenuButton, PowerLibrary::Observer implementation: |
| 105 | 105 |
| 106 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { | 106 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { |
| 107 UpdateIconAndLabelInfo(); | 107 UpdateIconAndLabelInfo(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
| 111 // PowerMenuButton, StatusAreaButton implementation: | 111 // PowerMenuButton, StatusAreaButton implementation: |
| 112 | 112 |
| 113 void PowerMenuButton::DrawPressed(gfx::Canvas* canvas) { | |
| 114 DrawPowerIcon(canvas, *ResourceBundle::GetSharedInstance(). | |
| 115 GetBitmapNamed(IDR_STATUSBAR_BATTERY_PRESSED)); | |
| 116 } | |
| 117 | |
| 118 void PowerMenuButton::DrawIcon(gfx::Canvas* canvas) { | |
| 119 DrawPowerIcon(canvas, icon()); | |
| 120 } | |
| 121 | |
| 122 void PowerMenuButton::DrawPowerIcon(gfx::Canvas* canvas, SkBitmap icon) { | |
| 123 // Draw the battery icon 5 pixels down to center it. | |
| 124 static const int kIconVerticalPadding = 5; | |
| 125 canvas->DrawBitmapInt(icon, 0, kIconVerticalPadding); | |
| 126 } | |
| 127 | |
| 128 void PowerMenuButton::UpdateIconAndLabelInfo() { | 113 void PowerMenuButton::UpdateIconAndLabelInfo() { |
| 129 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); | 114 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); |
| 130 if (!cros) | 115 if (!cros) |
| 131 return; | 116 return; |
| 132 | 117 |
| 133 bool cros_loaded = CrosLibrary::Get()->EnsureLoaded(); | 118 bool cros_loaded = CrosLibrary::Get()->EnsureLoaded(); |
| 134 if (cros_loaded) { | 119 if (cros_loaded) { |
| 135 battery_is_present_ = cros->battery_is_present(); | 120 battery_is_present_ = cros->battery_is_present(); |
| 136 line_power_on_ = cros->line_power_on(); | 121 line_power_on_ = cros->line_power_on(); |
| 137 battery_fully_charged_ = cros->battery_fully_charged(); | 122 battery_fully_charged_ = cros->battery_fully_charged(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 161 IDR_STATUSBAR_BATTERY_CHARGING_3, | 146 IDR_STATUSBAR_BATTERY_CHARGING_3, |
| 162 IDR_STATUSBAR_BATTERY_CHARGING_4, | 147 IDR_STATUSBAR_BATTERY_CHARGING_4, |
| 163 IDR_STATUSBAR_BATTERY_CHARGING_5, | 148 IDR_STATUSBAR_BATTERY_CHARGING_5, |
| 164 IDR_STATUSBAR_BATTERY_CHARGING_6, | 149 IDR_STATUSBAR_BATTERY_CHARGING_6, |
| 165 IDR_STATUSBAR_BATTERY_CHARGING_7, | 150 IDR_STATUSBAR_BATTERY_CHARGING_7, |
| 166 IDR_STATUSBAR_BATTERY_CHARGING_8, | 151 IDR_STATUSBAR_BATTERY_CHARGING_8, |
| 167 IDR_STATUSBAR_BATTERY_CHARGING_9, | 152 IDR_STATUSBAR_BATTERY_CHARGING_9, |
| 168 IDR_STATUSBAR_BATTERY_CHARGING_10, | 153 IDR_STATUSBAR_BATTERY_CHARGING_10, |
| 169 IDR_STATUSBAR_BATTERY_CHARGING_11, | 154 IDR_STATUSBAR_BATTERY_CHARGING_11, |
| 170 IDR_STATUSBAR_BATTERY_CHARGING_12, | 155 IDR_STATUSBAR_BATTERY_CHARGING_12, |
| 156 IDR_STATUSBAR_BATTERY_CHARGING_13, |
| 157 IDR_STATUSBAR_BATTERY_CHARGING_14, |
| 158 IDR_STATUSBAR_BATTERY_CHARGING_15, |
| 159 IDR_STATUSBAR_BATTERY_CHARGING_16, |
| 171 }; | 160 }; |
| 172 static const int kDischargingImages[kNumPowerImages] = { | 161 static const int kDischargingImages[kNumPowerImages] = { |
| 173 IDR_STATUSBAR_BATTERY_DISCHARGING_1, | 162 IDR_STATUSBAR_BATTERY_DISCHARGING_1, |
| 174 IDR_STATUSBAR_BATTERY_DISCHARGING_2, | 163 IDR_STATUSBAR_BATTERY_DISCHARGING_2, |
| 175 IDR_STATUSBAR_BATTERY_DISCHARGING_3, | 164 IDR_STATUSBAR_BATTERY_DISCHARGING_3, |
| 176 IDR_STATUSBAR_BATTERY_DISCHARGING_4, | 165 IDR_STATUSBAR_BATTERY_DISCHARGING_4, |
| 177 IDR_STATUSBAR_BATTERY_DISCHARGING_5, | 166 IDR_STATUSBAR_BATTERY_DISCHARGING_5, |
| 178 IDR_STATUSBAR_BATTERY_DISCHARGING_6, | 167 IDR_STATUSBAR_BATTERY_DISCHARGING_6, |
| 179 IDR_STATUSBAR_BATTERY_DISCHARGING_7, | 168 IDR_STATUSBAR_BATTERY_DISCHARGING_7, |
| 180 IDR_STATUSBAR_BATTERY_DISCHARGING_8, | 169 IDR_STATUSBAR_BATTERY_DISCHARGING_8, |
| 181 IDR_STATUSBAR_BATTERY_DISCHARGING_9, | 170 IDR_STATUSBAR_BATTERY_DISCHARGING_9, |
| 182 IDR_STATUSBAR_BATTERY_DISCHARGING_10, | 171 IDR_STATUSBAR_BATTERY_DISCHARGING_10, |
| 183 IDR_STATUSBAR_BATTERY_DISCHARGING_11, | 172 IDR_STATUSBAR_BATTERY_DISCHARGING_11, |
| 184 IDR_STATUSBAR_BATTERY_DISCHARGING_12, | 173 IDR_STATUSBAR_BATTERY_DISCHARGING_12, |
| 174 IDR_STATUSBAR_BATTERY_DISCHARGING_13, |
| 175 IDR_STATUSBAR_BATTERY_DISCHARGING_14, |
| 176 IDR_STATUSBAR_BATTERY_DISCHARGING_15, |
| 177 IDR_STATUSBAR_BATTERY_DISCHARGING_16, |
| 185 }; | 178 }; |
| 186 | 179 |
| 187 int index = static_cast<int>(battery_percentage_ / 100.0 * | 180 int index = static_cast<int>(battery_percentage_ / 100.0 * |
| 188 nextafter(static_cast<float>(kNumPowerImages), 0)); | 181 nextafter(static_cast<float>(kNumPowerImages), 0)); |
| 189 index = std::max(std::min(index, kNumPowerImages - 1), 0); | 182 index = std::max(std::min(index, kNumPowerImages - 1), 0); |
| 190 icon_id_ = line_power_on_ ? | 183 icon_id_ = line_power_on_ ? |
| 191 kChargingImages[index] : kDischargingImages[index]; | 184 kChargingImages[index] : kDischargingImages[index]; |
| 192 } | 185 } |
| 193 | 186 |
| 194 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id_)); | 187 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id_)); |
| 195 SetTooltipText(UTF16ToWide(GetLabelAt(0))); | 188 SetTooltipText(UTF16ToWide(GetLabelAt(0))); |
| 196 SchedulePaint(); | 189 SchedulePaint(); |
| 197 } | 190 } |
| 198 | 191 |
| 199 } // namespace chromeos | 192 } // namespace chromeos |
| OLD | NEW |