| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/oobe_progress_bar.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "grit/theme_resources.h" | |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | |
| 11 #include "ui/base/l10n/l10n_util.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/gfx/canvas_skia.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 // static | |
| 18 SkBitmap* OobeProgressBar::dot_current_ = NULL; | |
| 19 SkBitmap* OobeProgressBar::dot_empty_ = NULL; | |
| 20 SkBitmap* OobeProgressBar::dot_filled_ = NULL; | |
| 21 SkBitmap* OobeProgressBar::line_ = NULL; | |
| 22 SkBitmap* OobeProgressBar::line_left_ = NULL; | |
| 23 SkBitmap* OobeProgressBar::line_right_ = NULL; | |
| 24 | |
| 25 static const SkColor kCurrentTextColor = SkColorSetRGB(255, 255, 255); | |
| 26 static const SkColor kEmptyTextColor = SkColorSetRGB(112, 115, 118); | |
| 27 static const SkColor kFilledTextColor = SkColorSetRGB(112, 115, 118); | |
| 28 static const int kTextPadding = 5; | |
| 29 | |
| 30 OobeProgressBar::OobeProgressBar(const std::vector<int>& steps) | |
| 31 : steps_(steps), progress_(0) { | |
| 32 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 33 font_ = rb.GetFont(ResourceBundle::BaseFont); | |
| 34 InitClass(); | |
| 35 } | |
| 36 | |
| 37 OobeProgressBar::~OobeProgressBar() {} | |
| 38 | |
| 39 // static | |
| 40 void OobeProgressBar::InitClass() { | |
| 41 static bool initialized = false; | |
| 42 if (!initialized) { | |
| 43 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 44 | |
| 45 // Load images. | |
| 46 dot_current_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_CURRENT); | |
| 47 dot_empty_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_EMPTY); | |
| 48 dot_filled_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_FILLED); | |
| 49 line_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE); | |
| 50 line_left_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE_LEFT); | |
| 51 line_right_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE_RIGHT); | |
| 52 | |
| 53 initialized = true; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void OobeProgressBar::OnPaint(gfx::Canvas* canvas) { | |
| 58 gfx::Rect bounds = GetContentsBounds(); | |
| 59 | |
| 60 int x = bounds.x(); | |
| 61 int y = bounds.y(); | |
| 62 | |
| 63 double step_width = static_cast<double>(bounds.width()) / steps_.size(); | |
| 64 | |
| 65 for (size_t i = 0; i < steps_.size(); ++i) { | |
| 66 SkBitmap* dot; | |
| 67 SkColor color; | |
| 68 SkBitmap* line_before = line_; | |
| 69 SkBitmap* line_after = line_; | |
| 70 if (i < progress_) { | |
| 71 dot = dot_filled_; | |
| 72 color = kFilledTextColor; | |
| 73 } else if (i == progress_) { | |
| 74 dot = dot_current_; | |
| 75 color = kCurrentTextColor; | |
| 76 line_before = line_left_; | |
| 77 line_after = line_right_; | |
| 78 } else { | |
| 79 dot = dot_empty_; | |
| 80 color = kEmptyTextColor; | |
| 81 } | |
| 82 | |
| 83 // x coordinate for next step. | |
| 84 int next_x = static_cast<int>((i + 1) * step_width); | |
| 85 | |
| 86 // Offset of line origin from dot origin. | |
| 87 int line_offset_y = (dot->height() - line_->height()) / 2; | |
| 88 | |
| 89 // Current x for painting. | |
| 90 int ix = x; | |
| 91 | |
| 92 int line_width = ((next_x - x) - | |
| 93 (line_before->width() + dot->width() + line_after->width())) / 2; | |
| 94 if (i > 0) { | |
| 95 canvas->TileImageInt(*line_, ix, y + line_offset_y, | |
| 96 line_width, line_->height()); | |
| 97 } | |
| 98 ix += line_width; | |
| 99 if (i > 0) { | |
| 100 canvas->DrawBitmapInt(*line_before, ix, y + line_offset_y); | |
| 101 } | |
| 102 ix += line_before->width(); | |
| 103 | |
| 104 canvas->DrawBitmapInt(*dot, ix, y); | |
| 105 ix += dot->width(); | |
| 106 | |
| 107 if (i != steps_.size() - 1) | |
| 108 canvas->DrawBitmapInt(*line_after, ix, y + line_offset_y); | |
| 109 ix += line_after->width(); | |
| 110 | |
| 111 if (i != steps_.size() - 1) { | |
| 112 canvas->TileImageInt(*line_, ix, y + line_offset_y, | |
| 113 next_x - ix, line_->height()); | |
| 114 } | |
| 115 | |
| 116 string16 str = l10n_util::GetStringUTF16(steps_[i]); | |
| 117 canvas->DrawStringInt(str, font_, color, | |
| 118 x + kTextPadding, y + dot->height() + kTextPadding, | |
| 119 (next_x - x - 2 * kTextPadding), | |
| 120 (bounds.height() - dot->height() - 2 * kTextPadding), | |
| 121 gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER | | |
| 122 gfx::Canvas::TEXT_VALIGN_TOP | gfx::Canvas::NO_ELLIPSIS); | |
| 123 | |
| 124 x = next_x; | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 void OobeProgressBar::OnLocaleChanged() { | |
| 129 font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); | |
| 130 SchedulePaint(); | |
| 131 } | |
| 132 | |
| 133 void OobeProgressBar::SetStep(int step) { | |
| 134 for (size_t i = 0; i < steps_.size(); ++i) { | |
| 135 if (steps_[i] == step) { | |
| 136 progress_ = i; | |
| 137 SchedulePaint(); | |
| 138 return; | |
| 139 } | |
| 140 } | |
| 141 NOTREACHED(); | |
| 142 } | |
| 143 | |
| 144 } // namespace chromeos | |
| OLD | NEW |