Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ui/views/controls/throbber.cc

Issue 1214693005: Introduce some util code for drawing vector assets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile and rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // The default diameter of a Throbber. If you change this, also change
22 // kCheckmarkDpSize.
23 static const int kDefaultDiameter = 16;
24 // The size of the checkmark, in dp. This magic number matches the default
25 // diamater plus padding inherent in the checkmark SVG.
26 static const int kCheckmarkDpSize = 18;
27
28 Throbber::Throbber() : checked_(false) {
21 } 29 }
22 30
23 Throbber::~Throbber() { 31 Throbber::~Throbber() {
24 Stop(); 32 Stop();
25 } 33 }
26 34
27 void Throbber::Start() { 35 void Throbber::Start() {
28 if (IsRunning()) 36 if (IsRunning())
29 return; 37 return;
30 38
(...skipping 14 matching lines...) Expand all
45 53
46 void Throbber::SetChecked(bool checked) { 54 void Throbber::SetChecked(bool checked) {
47 if (checked == checked_) 55 if (checked == checked_)
48 return; 56 return;
49 57
50 checked_ = checked; 58 checked_ = checked;
51 SchedulePaint(); 59 SchedulePaint();
52 } 60 }
53 61
54 gfx::Size Throbber::GetPreferredSize() const { 62 gfx::Size Throbber::GetPreferredSize() const {
55 const int kDefaultDiameter = 16;
56 return gfx::Size(kDefaultDiameter, kDefaultDiameter); 63 return gfx::Size(kDefaultDiameter, kDefaultDiameter);
57 } 64 }
58 65
59 void Throbber::OnPaint(gfx::Canvas* canvas) { 66 void Throbber::OnPaint(gfx::Canvas* canvas) {
67 SkColor color = GetNativeTheme()->GetSystemColor(
68 ui::NativeTheme::kColorId_ThrobberSpinningColor);
69
60 if (!IsRunning()) { 70 if (!IsRunning()) {
61 if (checked_) { 71 if (checked_) {
62 if (!checkmark_) { 72 canvas->Translate(gfx::Vector2d((width() - kCheckmarkDpSize) / 2,
63 checkmark_ = ui::ResourceBundle::GetSharedInstance() 73 (height() - kCheckmarkDpSize) / 2));
64 .GetImageNamed(IDR_CHECKMARK) 74 gfx::PaintVectorIcon(canvas, gfx::VectorIconId::CHECK_CIRCLE,
65 .ToImageSkia(); 75 kCheckmarkDpSize, 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 } 76 }
72 return; 77 return;
73 } 78 }
74 79
75 SkColor color = GetNativeTheme()->GetSystemColor(
76 ui::NativeTheme::kColorId_ThrobberSpinningColor);
77 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; 80 base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
78 gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time); 81 gfx::PaintThrobberSpinning(canvas, GetContentsBounds(), color, elapsed_time);
79 } 82 }
80 83
81 bool Throbber::IsRunning() const { 84 bool Throbber::IsRunning() const {
82 return timer_.IsRunning(); 85 return timer_.IsRunning();
83 } 86 }
84 87
85 // Smoothed throbber --------------------------------------------------------- 88 // Smoothed throbber ---------------------------------------------------------
86 89
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 stop_timer_.Start(FROM_HERE, 121 stop_timer_.Start(FROM_HERE,
119 base::TimeDelta::FromMilliseconds(stop_delay_ms_), this, 122 base::TimeDelta::FromMilliseconds(stop_delay_ms_), this,
120 &SmoothedThrobber::StopDelayOver); 123 &SmoothedThrobber::StopDelayOver);
121 } 124 }
122 125
123 void SmoothedThrobber::StopDelayOver() { 126 void SmoothedThrobber::StopDelayOver() {
124 Throbber::Stop(); 127 Throbber::Stop();
125 } 128 }
126 129
127 } // namespace views 130 } // namespace views
OLDNEW
« ui/views/controls/image_view.cc ('K') | « ui/views/controls/throbber.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698