| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/status/status_area_bubble.h" | 15 #include "chrome/browser/chromeos/status/status_area_bubble.h" |
| 16 #include "chrome/browser/chromeos/view_ids.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/canvas_skia.h" | 22 #include "ui/gfx/canvas_skia.h" |
| 22 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
| 23 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 24 #include "views/controls/menu/menu_item_view.h" | 25 #include "views/controls/menu/menu_item_view.h" |
| 25 #include "views/controls/menu/menu_runner.h" | 26 #include "views/controls/menu/menu_runner.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 199 |
| 199 } // namespace | 200 } // namespace |
| 200 | 201 |
| 201 namespace chromeos { | 202 namespace chromeos { |
| 202 | 203 |
| 203 using base::TimeDelta; | 204 using base::TimeDelta; |
| 204 | 205 |
| 205 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// |
| 206 // PowerMenuButton | 207 // PowerMenuButton |
| 207 | 208 |
| 208 PowerMenuButton::PowerMenuButton(StatusAreaHost* host) | 209 PowerMenuButton::PowerMenuButton(StatusAreaButton::Delegate* delegate) |
| 209 : StatusAreaButton(host, this), | 210 : StatusAreaButton(delegate, this), |
| 210 battery_is_present_(false), | 211 battery_is_present_(false), |
| 211 line_power_on_(false), | 212 line_power_on_(false), |
| 212 battery_percentage_(0.0), | 213 battery_percentage_(0.0), |
| 213 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), | 214 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), |
| 214 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), | 215 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), |
| 215 status_(NULL) { | 216 status_(NULL) { |
| 217 set_id(VIEW_ID_STATUS_BUTTON_POWER); |
| 216 UpdateIconAndLabelInfo(); | 218 UpdateIconAndLabelInfo(); |
| 217 CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this); | 219 CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this); |
| 218 } | 220 } |
| 219 | 221 |
| 220 PowerMenuButton::~PowerMenuButton() { | 222 PowerMenuButton::~PowerMenuButton() { |
| 221 CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this); | 223 CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this); |
| 222 } | 224 } |
| 223 | 225 |
| 224 // PowerMenuButton, views::MenuDelegate implementation: | 226 // PowerMenuButton, views::MenuDelegate implementation: |
| 225 | 227 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 // If previous is 0, then it either was never set (initial condition) | 379 // If previous is 0, then it either was never set (initial condition) |
| 378 // or got down to 0. | 380 // or got down to 0. |
| 379 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 381 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
| 380 diff < kMinDiff || | 382 diff < kMinDiff || |
| 381 diff > kMaxDiff) { | 383 diff > kMaxDiff) { |
| 382 *previous = current; | 384 *previous = current; |
| 383 } | 385 } |
| 384 } | 386 } |
| 385 | 387 |
| 386 } // namespace chromeos | 388 } // namespace chromeos |
| OLD | NEW |