| 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; | 
| 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::CHECK_CIRCLE, kDipSize, 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     } | 70     } | 
| 72     return; | 71     return; | 
| 73   } | 72   } | 
| 74 | 73 | 
| 75   SkColor color = GetNativeTheme()->GetSystemColor( |  | 
| 76       ui::NativeTheme::kColorId_ThrobberSpinningColor); |  | 
| 77   base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 74   base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; | 
| 78   gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); | 75   gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); | 
| 79 } | 76 } | 
| 80 | 77 | 
| 81 bool Throbber::IsRunning() const { | 78 bool Throbber::IsRunning() const { | 
| 82   return timer_.IsRunning(); | 79   return timer_.IsRunning(); | 
| 83 } | 80 } | 
| 84 | 81 | 
| 85 // Smoothed throbber --------------------------------------------------------- | 82 // Smoothed throbber --------------------------------------------------------- | 
| 86 | 83 | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 118   stop_timer_.Start(FROM_HERE, | 115   stop_timer_.Start(FROM_HERE, | 
| 119                     base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, | 116                     base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, | 
| 120                     &SmoothedThrobber::StopDelayOver); | 117                     &SmoothedThrobber::StopDelayOver); | 
| 121 } | 118 } | 
| 122 | 119 | 
| 123 void SmoothedThrobber::StopDelayOver() { | 120 void SmoothedThrobber::StopDelayOver() { | 
| 124   Throbber::Stop(); | 121   Throbber::Stop(); | 
| 125 } | 122 } | 
| 126 | 123 | 
| 127 }  // namespace views | 124 }  // namespace views | 
| OLD | NEW | 
|---|