Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/throbber.h" | 5 #include "ui/views/controls/throbber.h" |
| 6 | 6 |
| 7 #include "ui/base/resource/resource_bundle.h" | 7 #include "ui/base/resource/resource_bundle.h" |
| 8 #include "ui/gfx/animation/tween.h" | 8 #include "ui/gfx/animation/tween.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| 11 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/paint_throbber.h" | 12 #include "ui/gfx/paint_throbber.h" |
| 13 #include "ui/gfx/vector_icons.h" | |
| 13 #include "ui/native_theme/common_theme.h" | 14 #include "ui/native_theme/common_theme.h" |
| 14 #include "ui/native_theme/native_theme.h" | 15 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/resources/grit/ui_resources.h" | 16 #include "ui/resources/grit/ui_resources.h" |
| 16 #include "ui/views/resources/grit/views_resources.h" | 17 #include "ui/views/resources/grit/views_resources.h" |
| 17 | 18 |
| 18 namespace views { | 19 namespace views { |
| 19 | 20 |
| 20 Throbber::Throbber() : checked_(false), checkmark_(nullptr) { | 21 Throbber::Throbber() : checked_(false) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 Throbber::~Throbber() { | 24 Throbber::~Throbber() { |
| 24 Stop(); | 25 Stop(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void Throbber::Start() { | 28 void Throbber::Start() { |
| 28 if (IsRunning()) | 29 if (IsRunning()) |
| 29 return; | 30 return; |
| 30 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 50 checked_ = checked; | 51 checked_ = checked; |
| 51 SchedulePaint(); | 52 SchedulePaint(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 gfx::Size Throbber::GetPreferredSize() const { | 55 gfx::Size Throbber::GetPreferredSize() const { |
| 55 const int kDefaultDiameter = 16; | 56 const int kDefaultDiameter = 16; |
| 56 return gfx::Size(kDefaultDiameter, kDefaultDiameter); | 57 return gfx::Size(kDefaultDiameter, kDefaultDiameter); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void Throbber::OnPaint(gfx::Canvas* canvas) { | 60 void Throbber::OnPaint(gfx::Canvas* canvas) { |
| 61 SkColor color = GetNativeTheme()->GetSystemColor( | |
| 62 ui::NativeTheme::kColorId_ThrobberSpinningColor); | |
| 63 | |
| 60 if (!IsRunning()) { | 64 if (!IsRunning()) { |
| 61 if (checked_) { | 65 if (checked_) { |
| 62 if (!checkmark_) { | 66 const int kDipSize = 18; |
|
Peter Kasting
2015/07/01 22:26:58
Hardcoding this makes me sad... is there any way t
Evan Stade
2015/07/02 00:08:06
Yea, it's tricky. 18 is the magic dp for which the
| |
| 63 checkmark_ = ui::ResourceBundle::GetSharedInstance() | 67 canvas->Translate(gfx::Vector2d((width() - kDipSize) / 2, |
| 64 .GetImageNamed(IDR_CHECKMARK) | 68 (height() - kDipSize) / 2)); |
| 65 .ToImageSkia(); | 69 gfx::PaintVectorIcon(canvas, gfx::VectorIconId::CHECK_CIRCLE, kDipSize, |
| 66 } | 70 color); |
| 67 | |
| 68 int checkmark_x = (width() - checkmark_->width()) / 2; | |
| 69 int checkmark_y = (height() - checkmark_->height()) / 2; | |
| 70 canvas->DrawImageInt(*checkmark_, checkmark_x, checkmark_y); | |
| 71 } | 71 } |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 | 74 |
| 75 SkColor color = GetNativeTheme()->GetSystemColor( | |
| 76 ui::NativeTheme::kColorId_ThrobberSpinningColor); | |
| 77 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 75 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; |
| 78 gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); | 76 gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); |
| 79 } | 77 } |
| 80 | 78 |
| 81 bool Throbber::IsRunning() const { | 79 bool Throbber::IsRunning() const { |
| 82 return timer_.IsRunning(); | 80 return timer_.IsRunning(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 // Smoothed throbber --------------------------------------------------------- | 83 // Smoothed throbber --------------------------------------------------------- |
| 86 | 84 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 stop_timer_.Start(FROM_HERE, | 116 stop_timer_.Start(FROM_HERE, |
| 119 base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, | 117 base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, |
| 120 &SmoothedThrobber::StopDelayOver); | 118 &SmoothedThrobber::StopDelayOver); |
| 121 } | 119 } |
| 122 | 120 |
| 123 void SmoothedThrobber::StopDelayOver() { | 121 void SmoothedThrobber::StopDelayOver() { |
| 124 Throbber::Stop(); | 122 Throbber::Stop(); |
| 125 } | 123 } |
| 126 | 124 |
| 127 } // namespace views | 125 } // namespace views |
| OLD | NEW |