| Index: ui/views/controls/throbber.cc
|
| diff --git a/ui/views/controls/throbber.cc b/ui/views/controls/throbber.cc
|
| index d1d5c1d892369a72213428a065f38d43ab2451a3..a520f1f580d09bdd001b0ca594aadfbff5fa4ef8 100644
|
| --- a/ui/views/controls/throbber.cc
|
| +++ b/ui/views/controls/throbber.cc
|
| @@ -143,6 +143,9 @@ CheckmarkThrobber::CheckmarkThrobber()
|
| IDR_CHECKMARK).ToImageSkia()) {
|
| }
|
|
|
| +CheckmarkThrobber::~CheckmarkThrobber() {
|
| +}
|
| +
|
| void CheckmarkThrobber::SetChecked(bool checked) {
|
| bool changed = checked != checked_;
|
| if (changed) {
|
| @@ -165,4 +168,61 @@ void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) {
|
| }
|
| }
|
|
|
| +// Material throbber -----------------------------------------------------------
|
| +
|
| +MaterialThrobber::MaterialThrobber() : preferred_diameter_(0) {
|
| +}
|
| +
|
| +MaterialThrobber::~MaterialThrobber() {
|
| +}
|
| +
|
| +gfx::Size MaterialThrobber::GetPreferredSize() const {
|
| + if (preferred_diameter_ == 0)
|
| + return CheckmarkThrobber::GetPreferredSize();
|
| +
|
| + return gfx::Size(preferred_diameter_, preferred_diameter_);
|
| +}
|
| +
|
| +int MaterialThrobber::GetHeightForWidth(int w) const {
|
| + return w;
|
| +}
|
| +
|
| +void MaterialThrobber::OnPaint(gfx::Canvas* canvas) {
|
| + if (!running_) {
|
| + CheckmarkThrobber::OnPaint(canvas);
|
| + return;
|
| + }
|
| +
|
| + 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 finish_angle = 90 + 360 * elapsed_time / revolution_time;
|
| + int64_t start_angle = std::max(finish_angle - 180, 90L);
|
| +
|
| + 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
|
|
|