| Index: ui/views/controls/throbber.cc
|
| diff --git a/ui/views/controls/throbber.cc b/ui/views/controls/throbber.cc
|
| index d1d5c1d892369a72213428a065f38d43ab2451a3..30cfb3b33a422df9fa9092a61cb2e304aa3e3e6b 100644
|
| --- a/ui/views/controls/throbber.cc
|
| +++ b/ui/views/controls/throbber.cc
|
| @@ -111,7 +111,7 @@ SmoothedThrobber::~SmoothedThrobber() {}
|
| void SmoothedThrobber::Start() {
|
| stop_timer_.Stop();
|
|
|
| - if (!running_ && !start_timer_.IsRunning()) {
|
| + if (!running() && !start_timer_.IsRunning()) {
|
| start_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(start_delay_ms_),
|
| this, &SmoothedThrobber::StartDelayOver);
|
| }
|
| @@ -122,7 +122,7 @@ void SmoothedThrobber::StartDelayOver() {
|
| }
|
|
|
| void SmoothedThrobber::Stop() {
|
| - if (!running_)
|
| + if (!running())
|
| start_timer_.Stop();
|
|
|
| stop_timer_.Stop();
|
| @@ -134,35 +134,87 @@ void SmoothedThrobber::StopDelayOver() {
|
| Throbber::Stop();
|
| }
|
|
|
| -// Checkmark throbber ---------------------------------------------------------
|
| +// Material throbber -----------------------------------------------------------
|
| +
|
| +// The length of a frame in milliseconds.
|
| +// TODO(estade): remove the +10 when the -10 is removed from Throbber::Start().
|
| +static const int kMaterialThrobberFrameTimeMs = 30 + 10;
|
|
|
| -CheckmarkThrobber::CheckmarkThrobber()
|
| - : Throbber(kFrameTimeMs, false),
|
| - checked_(false),
|
| - checkmark_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
|
| - IDR_CHECKMARK).ToImageSkia()) {
|
| +MaterialThrobber::MaterialThrobber() :
|
| + Throbber(kMaterialThrobberFrameTimeMs, false),
|
| + preferred_diameter_(0),
|
| + checked_(false),
|
| + checkmark_(nullptr) {
|
| }
|
|
|
| -void CheckmarkThrobber::SetChecked(bool checked) {
|
| - bool changed = checked != checked_;
|
| - if (changed) {
|
| - checked_ = checked;
|
| - SchedulePaint();
|
| - }
|
| +MaterialThrobber::~MaterialThrobber() {
|
| }
|
|
|
| -void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) {
|
| - if (running_) {
|
| - // Let the throbber throb...
|
| - Throbber::OnPaint(canvas);
|
| +void MaterialThrobber::SetChecked(bool checked) {
|
| + if (checked == checked_)
|
| + return;
|
| +
|
| + checked_ = checked;
|
| + SchedulePaint();
|
| +}
|
| +
|
| +gfx::Size MaterialThrobber::GetPreferredSize() const {
|
| + if (preferred_diameter_ == 0)
|
| + return Throbber::GetPreferredSize();
|
| +
|
| + return gfx::Size(preferred_diameter_, preferred_diameter_);
|
| +}
|
| +
|
| +int MaterialThrobber::GetHeightForWidth(int w) const {
|
| + return w;
|
| +}
|
| +
|
| +void MaterialThrobber::OnPaint(gfx::Canvas* canvas) {
|
| + if (!running()) {
|
| + if (checked_) {
|
| + if (!checkmark_) {
|
| + checkmark_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
|
| + IDR_CHECKMARK).ToImageSkia();
|
| + }
|
| +
|
| + int checkmark_x = (width() - checkmark_->width()) / 2;
|
| + int checkmark_y = (height() - checkmark_->height()) / 2;
|
| + canvas->DrawImageInt(*checkmark_, checkmark_x, checkmark_y);
|
| + }
|
| return;
|
| }
|
| - // Otherwise we paint our tick mark or nothing depending on our state.
|
| - if (checked_) {
|
| - int checkmark_x = (width() - checkmark_->width()) / 2;
|
| - int checkmark_y = (height() - checkmark_->height()) / 2;
|
| - canvas->DrawImageInt(*checkmark_, checkmark_x, checkmark_y);
|
| - }
|
| +
|
| + gfx::Rect bounds = GetContentsBounds();
|
| + // Inset by half the stroke width to make sure the whole arc is inside
|
| + // the visible rect.
|
| + SkScalar stroke_width = SkIntToScalar(bounds.width()) / 10.0;
|
| + gfx::Rect oval = bounds;
|
| + int inset = SkScalarCeilToInt(stroke_width / 2.0);
|
| + oval.Inset(inset, inset);
|
| +
|
| + // Calculate start and end points. The angles are counter-clockwise because
|
| + // the throbber spins counter-clockwise. The finish angle starts at 12 o'clock
|
| + // (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();
|
| + 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);
|
| +
|
| + SkPath path;
|
| + // Negate the angles to convert to the clockwise numbers Skia expects.
|
| + path.arcTo(gfx::RectToSkRect(oval), -start_angle,
|
| + -(finish_angle - start_angle), true);
|
| +
|
| + SkPaint paint;
|
| + // TODO(estade): find a place for this color.
|
| + paint.setColor(SkColorSetRGB(0x42, 0x85, 0xF4));
|
| + paint.setStrokeCap(SkPaint::kRound_Cap);
|
| + paint.setStrokeWidth(stroke_width);
|
| + paint.setStyle(SkPaint::kStroke_Style);
|
| + paint.setAntiAlias(true);
|
| + canvas->DrawPath(path, paint);
|
| }
|
|
|
| } // namespace views
|
|
|