Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: ui/views/controls/throbber.cc

Issue 1103903003: Clean up Throbber. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix spaces Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/views/controls/throbber.h ('K') | « ui/views/controls/throbber.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/throbber.cc
diff --git a/ui/views/controls/throbber.cc b/ui/views/controls/throbber.cc
index 30cfb3b33a422df9fa9092a61cb2e304aa3e3e6b..7b513c7d404461a2c8001f61f244b7d6843aba21 100644
--- a/ui/views/controls/throbber.cc
+++ b/ui/views/controls/throbber.cc
@@ -4,24 +4,18 @@
#include "ui/views/controls/throbber.h"
-#include "base/time/time.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/resources/grit/ui_resources.h"
-using base::Time;
tfarina 2015/04/24 23:08:19 Would you mind keep the using declarations? They d
Evan Stade 2015/04/24 23:15:32 in my experience, we don't usually use using direc
-using base::TimeDelta;
-
namespace views {
-Throbber::Throbber(int frame_time_ms,
- bool paint_while_stopped)
- : running_(false),
- paint_while_stopped_(paint_while_stopped),
+Throbber::Throbber(int frame_time_ms, bool paint_while_stopped)
+ : paint_while_stopped_(paint_while_stopped),
frames_(NULL),
- frame_time_(TimeDelta::FromMilliseconds(frame_time_ms)) {
+ frame_time_(base::TimeDelta::FromMilliseconds(frame_time_ms)) {
SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_THROBBER).ToImageSkia());
}
@@ -31,26 +25,20 @@ Throbber::~Throbber() {
}
void Throbber::Start() {
- if (running_)
+ if (IsRunning())
return;
- start_time_ = Time::Now();
-
- timer_.Start(FROM_HERE, frame_time_ - TimeDelta::FromMilliseconds(10),
- this, &Throbber::Run);
-
- running_ = true;
-
+ start_time_ = base::TimeTicks::Now();
+ timer_.Start(FROM_HERE, frame_time_ - base::TimeDelta::FromMilliseconds(10),
+ this, &Throbber::SchedulePaint);
SchedulePaint(); // paint right away
}
void Throbber::Stop() {
- if (!running_)
+ if (!IsRunning())
return;
timer_.Stop();
-
- running_ = false;
SchedulePaint(); // Important if we're not painting while stopped
}
@@ -62,21 +50,15 @@ void Throbber::SetFrames(const gfx::ImageSkia* frames) {
PreferredSizeChanged();
}
-void Throbber::Run() {
- DCHECK(running_);
-
- SchedulePaint();
-}
-
gfx::Size Throbber::GetPreferredSize() const {
return gfx::Size(frames_->height(), frames_->height());
}
void Throbber::OnPaint(gfx::Canvas* canvas) {
- if (!running_ && !paint_while_stopped_)
+ if (!IsRunning() && !paint_while_stopped_)
return;
- const TimeDelta elapsed_time = Time::Now() - start_time_;
+ const base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
const int current_frame =
static_cast<int>(elapsed_time / frame_time_) % frame_count_;
@@ -88,18 +70,18 @@ void Throbber::OnPaint(gfx::Canvas* canvas) {
false);
}
-
+bool Throbber::IsRunning() const {
+ return timer_.IsRunning();
+}
// Smoothed throbber ---------------------------------------------------------
-
// Delay after work starts before starting throbber, in milliseconds.
static const int kStartDelay = 200;
// Delay after work stops before stopping, in milliseconds.
static const int kStopDelay = 50;
-
SmoothedThrobber::SmoothedThrobber(int frame_time_ms)
: Throbber(frame_time_ms, /* paint_while_stopped= */ false),
start_delay_ms_(kStartDelay),
@@ -111,9 +93,10 @@ SmoothedThrobber::~SmoothedThrobber() {}
void SmoothedThrobber::Start() {
stop_timer_.Stop();
- if (!running() && !start_timer_.IsRunning()) {
- start_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(start_delay_ms_),
- this, &SmoothedThrobber::StartDelayOver);
+ if (!IsRunning() && !start_timer_.IsRunning()) {
+ start_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(start_delay_ms_), this,
+ &SmoothedThrobber::StartDelayOver);
}
}
@@ -122,12 +105,13 @@ void SmoothedThrobber::StartDelayOver() {
}
void SmoothedThrobber::Stop() {
- if (!running())
+ if (!IsRunning())
start_timer_.Stop();
stop_timer_.Stop();
- stop_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(stop_delay_ms_),
- this, &SmoothedThrobber::StopDelayOver);
+ stop_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(stop_delay_ms_), this,
+ &SmoothedThrobber::StopDelayOver);
}
void SmoothedThrobber::StopDelayOver() {
@@ -170,7 +154,7 @@ int MaterialThrobber::GetHeightForWidth(int w) const {
}
void MaterialThrobber::OnPaint(gfx::Canvas* canvas) {
- if (!running()) {
+ if (!IsRunning()) {
if (checked_) {
if (!checkmark_) {
checkmark_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
@@ -197,7 +181,7 @@ void MaterialThrobber::OnPaint(gfx::Canvas* canvas) {
// (90 degrees) and rotates steadily. The start angle trails 180 degrees
// behind, except for the first half revolution, when it stays at 12 o'clock.
base::TimeDelta revolution_time = base::TimeDelta::FromMilliseconds(1320);
- base::TimeDelta elapsed_time = base::Time::Now() - start_time();
+ base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time();
int64_t twelve_oclock = 90;
int64_t finish_angle = twelve_oclock + 360 * elapsed_time / revolution_time;
int64_t start_angle = std::max(finish_angle - 180, twelve_oclock);
« ui/views/controls/throbber.h ('K') | « ui/views/controls/throbber.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698