diff options
-rw-r--r-- | chrome/browser/chromeos/login/update_view.cc | 7 | ||||
-rw-r--r-- | views/controls/progress_bar.cc | 24 | ||||
-rw-r--r-- | views/controls/progress_bar.h | 22 | ||||
-rw-r--r-- | views/controls/progress_bar_unittest.cc | 13 |
4 files changed, 30 insertions, 36 deletions
diff --git a/chrome/browser/chromeos/login/update_view.cc b/chrome/browser/chromeos/login/update_view.cc index 8bb06d7..fc22728 100644 --- a/chrome/browser/chromeos/login/update_view.cc +++ b/chrome/browser/chromeos/login/update_view.cc @@ -36,7 +36,7 @@ const SkColor kLabelColor = 0xFF000000; // Timer constants. const int kProgressTimerInterval = 200; -const int kProgressIncrement = 0.09; +const int kProgressIncrement = 9; } // namespace namespace chromeos { @@ -64,6 +64,7 @@ void UpdateView::Init() { installing_updates_label_->SetFont(base_font); progress_bar_ = new views::ProgressBar(); + progress_bar_->SetProgress(0); UpdateLocalizedStrings(); AddChildView(installing_updates_label_); @@ -100,8 +101,8 @@ void UpdateView::Layout() { } void UpdateView::OnTimerElapsed() { - double progress = progress_bar_->GetProgress(); - if (progress == 1.) { + int progress = progress_bar_->GetProgress(); + if (progress >= 100) { timer_.Stop(); if (observer_) { observer_->OnExit(ScreenObserver::UPDATE_NOUPDATE); diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc index 96ceb44..1f5cba1 100644 --- a/views/controls/progress_bar.cc +++ b/views/controls/progress_bar.cc @@ -4,6 +4,8 @@ #include "views/controls/progress_bar.h" +#include <string> + #include "app/gfx/canvas.h" #include "app/gfx/color_utils.h" #include "app/gfx/font.h" @@ -99,13 +101,11 @@ namespace views { // static const char ProgressBar::kViewClassName[] = "views/ProgressBar"; +// static: progress bar's maximum value. +const int ProgressBar::kMaxProgress = 100; -ProgressBar::ProgressBar() { - Init(0); -} -ProgressBar::ProgressBar(double progress) { - Init(progress); +ProgressBar::ProgressBar(): progress_(0) { } ProgressBar::~ProgressBar() { @@ -131,7 +131,7 @@ void ProgressBar::Paint(gfx::Canvas* canvas) { if (progress_ * width() > 1) { FillRoundRect(canvas, 0, 0, - int(progress_ * width()), height(), + progress_ * width() / kMaxProgress, height(), kCornerRadius, bar_color_start, bar_color_end, @@ -149,16 +149,16 @@ std::string ProgressBar::GetClassName() const { return kViewClassName; } -void ProgressBar::SetProgress(double progress) { +void ProgressBar::SetProgress(int progress) { progress_ = progress; if (progress_ < 0) progress_ = 0; - else if (progress_ > 1) - progress_ = 1; + else if (progress_ > kMaxProgress) + progress_ = kMaxProgress; SchedulePaint(); } -double ProgressBar::GetProgress() const { +int ProgressBar::GetProgress() const { return progress_; } @@ -205,8 +205,4 @@ bool ProgressBar::GetAccessibleState(AccessibilityTypes::State* state) { return true; } -void ProgressBar::Init(double progress) { - progress_ = progress; -} - } // namespace views diff --git a/views/controls/progress_bar.h b/views/controls/progress_bar.h index e5587d5..128941f 100644 --- a/views/controls/progress_bar.h +++ b/views/controls/progress_bar.h @@ -5,6 +5,8 @@ #ifndef VIEWS_CONTROLS_PROGRESS_BAR_H_ #define VIEWS_CONTROLS_PROGRESS_BAR_H_ +#include <string> + #include "views/view.h" namespace gfx { @@ -25,12 +27,7 @@ namespace views { class ProgressBar : public View { public: - // Creates a new progress bar with progress zero. ProgressBar(); - - // Creates a new progress bar with specified progress. - explicit ProgressBar(double progress); - virtual ~ProgressBar(); // Overridden to return preferred size of the progress bar. @@ -42,9 +39,9 @@ class ProgressBar : public View { // Overridden to paint virtual void Paint(gfx::Canvas* canvas); - // Set and get the progress bar progress in range [0, 1]. - virtual void SetProgress(double progress); - virtual double GetProgress() const; + // Set and get the progress bar progress in range [0, kMaxProgress]. + virtual void SetProgress(int progress); + virtual int GetProgress() const; // Sets the tooltip text. Default behavior for a progress bar is to show // no tooltip on mouse hover. Calling this lets you set a custom tooltip. @@ -62,11 +59,12 @@ class ProgressBar : public View { virtual bool GetAccessibleName(std::wstring* name); virtual bool GetAccessibleState(AccessibilityTypes::State* state); - private: - void Init(double progress); + // Maximum value of progress. + static const int kMaxProgress; - // Progress in range [0, 1]. - double progress_; + private: + // Progress in range [0, kMaxProgress]. + int progress_; // Tooltip text. std::wstring tooltip_text_; diff --git a/views/controls/progress_bar_unittest.cc b/views/controls/progress_bar_unittest.cc index 1f653b7..971b424 100644 --- a/views/controls/progress_bar_unittest.cc +++ b/views/controls/progress_bar_unittest.cc @@ -11,16 +11,15 @@ namespace views { TEST(ProgressBarTest, ProgressProperty) { ProgressBar bar; - double progress = 0; bar.SetProgress(-1); - progress = bar.GetProgress(); + int progress = bar.GetProgress(); EXPECT_EQ(0, progress); - bar.SetProgress(3); + bar.SetProgress(300); progress = bar.GetProgress(); - EXPECT_EQ(1, progress); - bar.SetProgress(0.618); + EXPECT_EQ(100, progress); + bar.SetProgress(62); progress = bar.GetProgress(); - EXPECT_EQ(0.618, progress); + EXPECT_EQ(62, progress); } TEST(ProgressBarTest, TooltipTextProperty) { @@ -36,7 +35,7 @@ TEST(ProgressBarTest, TooltipTextProperty) { TEST(ProgressBarTest, Accessibility) { ProgressBar bar; - bar.SetProgress(0.618); + bar.SetProgress(62); AccessibilityTypes::Role role; EXPECT_TRUE(bar.GetAccessibleRole(&role)); |