| 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/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" |
| 10 #include "base/time.h" | 11 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 menu_button_->battery_index_); | 170 menu_button_->battery_index_); |
| 170 if (menu_button_->battery_percentage_ < 100 || | 171 if (menu_button_->battery_percentage_ < 100 || |
| 171 !menu_button_->line_power_on_) { | 172 !menu_button_->line_power_on_) { |
| 172 draw_percentage_text = true; | 173 draw_percentage_text = true; |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 int image_x = kPadLeftX, image_y = (height() - image.height()) / 2; | 176 int image_x = kPadLeftX, image_y = (height() - image.height()) / 2; |
| 176 canvas->DrawBitmapInt(image, image_x, image_y); | 177 canvas->DrawBitmapInt(image, image_x, image_y); |
| 177 | 178 |
| 178 if (draw_percentage_text) { | 179 if (draw_percentage_text) { |
| 179 string16 text = UTF8ToUTF16(StringPrintf( | 180 string16 text = UTF8ToUTF16(base::StringPrintf( |
| 180 "%d%%", | 181 "%d%%", |
| 181 static_cast<int>(menu_button_->battery_percentage_))); | 182 static_cast<int>(menu_button_->battery_percentage_))); |
| 182 int text_h = percentage_font_.GetHeight(); | 183 int text_h = percentage_font_.GetHeight(); |
| 183 int text_y = ((height() - text_h) / 2); | 184 int text_y = ((height() - text_h) / 2); |
| 184 canvas->DrawStringInt( | 185 canvas->DrawStringInt( |
| 185 text, percentage_font_, kPercentageShadowColor, | 186 text, percentage_font_, kPercentageShadowColor, |
| 186 image_x, text_y + 1, image.width(), text_h, | 187 image_x, text_y + 1, image.width(), text_h, |
| 187 gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS); | 188 gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS); |
| 188 canvas->DrawStringInt( | 189 canvas->DrawStringInt( |
| 189 text, percentage_font_, kPercentageColor, | 190 text, percentage_font_, kPercentageColor, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // If previous is 0, then it either was never set (initial condition) | 414 // If previous is 0, then it either was never set (initial condition) |
| 414 // or got down to 0. | 415 // or got down to 0. |
| 415 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 416 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
| 416 diff < kMinDiff || | 417 diff < kMinDiff || |
| 417 diff > kMaxDiff) { | 418 diff > kMaxDiff) { |
| 418 *previous = current; | 419 *previous = current; |
| 419 } | 420 } |
| 420 } | 421 } |
| 421 | 422 |
| 422 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |