| 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/paint_vector_icon.h" | 
|  | 14 #include "ui/gfx/vector_icons_public.h" | 
| 13 #include "ui/native_theme/common_theme.h" | 15 #include "ui/native_theme/common_theme.h" | 
| 14 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" | 
| 15 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" | 
| 16 #include "ui/views/resources/grit/views_resources.h" | 18 #include "ui/views/resources/grit/views_resources.h" | 
| 17 | 19 | 
| 18 namespace views { | 20 namespace views { | 
| 19 | 21 | 
| 20 Throbber::Throbber() : checked_(false), checkmark_(nullptr) { | 22 // The default diameter of a Throbber. If you change this, also change | 
|  | 23 // kCheckmarkDipSize. | 
|  | 24 static const int kDefaultDiameter = 16; | 
|  | 25 // The size of the checkmark, in DIP. This magic number matches the default | 
|  | 26 // diamater plus padding inherent in the checkmark SVG. | 
|  | 27 static const int kCheckmarkDipSize = 18; | 
|  | 28 | 
|  | 29 Throbber::Throbber() : checked_(false) { | 
| 21 } | 30 } | 
| 22 | 31 | 
| 23 Throbber::~Throbber() { | 32 Throbber::~Throbber() { | 
| 24   Stop(); | 33   Stop(); | 
| 25 } | 34 } | 
| 26 | 35 | 
| 27 void Throbber::Start() { | 36 void Throbber::Start() { | 
| 28   if (IsRunning()) | 37   if (IsRunning()) | 
| 29     return; | 38     return; | 
| 30 | 39 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 45 | 54 | 
| 46 void Throbber::SetChecked(bool checked) { | 55 void Throbber::SetChecked(bool checked) { | 
| 47   if (checked == checked_) | 56   if (checked == checked_) | 
| 48     return; | 57     return; | 
| 49 | 58 | 
| 50   checked_ = checked; | 59   checked_ = checked; | 
| 51   SchedulePaint(); | 60   SchedulePaint(); | 
| 52 } | 61 } | 
| 53 | 62 | 
| 54 gfx::Size Throbber::GetPreferredSize() const { | 63 gfx::Size Throbber::GetPreferredSize() const { | 
| 55   const int kDefaultDiameter = 16; |  | 
| 56   return gfx::Size(kDefaultDiameter, kDefaultDiameter); | 64   return gfx::Size(kDefaultDiameter, kDefaultDiameter); | 
| 57 } | 65 } | 
| 58 | 66 | 
| 59 void Throbber::OnPaint(gfx::Canvas* canvas) { | 67 void Throbber::OnPaint(gfx::Canvas* canvas) { | 
|  | 68   SkColor color = GetNativeTheme()->GetSystemColor( | 
|  | 69       ui::NativeTheme::kColorId_ThrobberSpinningColor); | 
|  | 70 | 
| 60   if (!IsRunning()) { | 71   if (!IsRunning()) { | 
| 61     if (checked_) { | 72     if (checked_) { | 
| 62       if (!checkmark_) { | 73       canvas->Translate(gfx::Vector2d((width() - kCheckmarkDipSize) / 2, | 
| 63         checkmark_ = ui::ResourceBundle::GetSharedInstance() | 74                                       (height() - kCheckmarkDipSize) / 2)); | 
| 64                          .GetImageNamed(IDR_CHECKMARK) | 75       gfx::PaintVectorIcon(canvas, gfx::VectorIconId::CHECK_CIRCLE, | 
| 65                          .ToImageSkia(); | 76                            kCheckmarkDipSize, color); | 
| 66       } |  | 
| 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     } | 77     } | 
| 72     return; | 78     return; | 
| 73   } | 79   } | 
| 74 | 80 | 
| 75   SkColor color = GetNativeTheme()->GetSystemColor( |  | 
| 76       ui::NativeTheme::kColorId_ThrobberSpinningColor); |  | 
| 77   base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 81   base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 
| 78   gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); | 82   gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); | 
| 79 } | 83 } | 
| 80 | 84 | 
| 81 bool Throbber::IsRunning() const { | 85 bool Throbber::IsRunning() const { | 
| 82   return timer_.IsRunning(); | 86   return timer_.IsRunning(); | 
| 83 } | 87 } | 
| 84 | 88 | 
| 85 // Smoothed throbber --------------------------------------------------------- | 89 // Smoothed throbber --------------------------------------------------------- | 
| 86 | 90 | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 118   stop_timer_.Start(FROM_HERE, | 122   stop_timer_.Start(FROM_HERE, | 
| 119                     base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, | 123                     base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, | 
| 120                     &SmoothedThrobber::StopDelayOver); | 124                     &SmoothedThrobber::StopDelayOver); | 
| 121 } | 125 } | 
| 122 | 126 | 
| 123 void SmoothedThrobber::StopDelayOver() { | 127 void SmoothedThrobber::StopDelayOver() { | 
| 124   Throbber::Stop(); | 128   Throbber::Stop(); | 
| 125 } | 129 } | 
| 126 | 130 | 
| 127 }  // namespace views | 131 }  // namespace views | 
| OLD | NEW | 
|---|