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

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

Issue 1067593006: Implement material throbber and use it in one place (Autofill card (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 8 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
« ui/views/controls/throbber.h ('K') | « ui/views/controls/throbber.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/time/time.h" 7 #include "base/time/time.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.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"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 // Checkmark throbber --------------------------------------------------------- 137 // Checkmark throbber ---------------------------------------------------------
138 138
139 CheckmarkThrobber::CheckmarkThrobber() 139 CheckmarkThrobber::CheckmarkThrobber()
140 : Throbber(kFrameTimeMs, false), 140 : Throbber(kFrameTimeMs, false),
141 checked_(false), 141 checked_(false),
142 checkmark_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 142 checkmark_(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
143 IDR_CHECKMARK).ToImageSkia()) { 143 IDR_CHECKMARK).ToImageSkia()) {
144 } 144 }
145 145
146 CheckmarkThrobber::~CheckmarkThrobber() {
147 }
148
146 void CheckmarkThrobber::SetChecked(bool checked) { 149 void CheckmarkThrobber::SetChecked(bool checked) {
147 bool changed = checked != checked_; 150 bool changed = checked != checked_;
148 if (changed) { 151 if (changed) {
149 checked_ = checked; 152 checked_ = checked;
150 SchedulePaint(); 153 SchedulePaint();
151 } 154 }
152 } 155 }
153 156
154 void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) { 157 void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) {
155 if (running_) { 158 if (running_) {
156 // Let the throbber throb... 159 // Let the throbber throb...
157 Throbber::OnPaint(canvas); 160 Throbber::OnPaint(canvas);
158 return; 161 return;
159 } 162 }
160 // Otherwise we paint our tick mark or nothing depending on our state. 163 // Otherwise we paint our tick mark or nothing depending on our state.
161 if (checked_) { 164 if (checked_) {
162 int checkmark_x = (width() - checkmark_->width()) / 2; 165 int checkmark_x = (width() - checkmark_->width()) / 2;
163 int checkmark_y = (height() - checkmark_->height()) / 2; 166 int checkmark_y = (height() - checkmark_->height()) / 2;
164 canvas->DrawImageInt(*checkmark_, checkmark_x, checkmark_y); 167 canvas->DrawImageInt(*checkmark_, checkmark_x, checkmark_y);
165 } 168 }
166 } 169 }
167 170
171 // Material throbber -----------------------------------------------------------
172
173 MaterialThrobber::MaterialThrobber() : preferred_diameter_(0) {
174 }
175
176 MaterialThrobber::~MaterialThrobber() {
177 }
178
179 gfx::Size MaterialThrobber::GetPreferredSize() const {
180 if (preferred_diameter_ == 0)
181 return CheckmarkThrobber::GetPreferredSize();
182
183 return gfx::Size(preferred_diameter_, preferred_diameter_);
184 }
185
186 int MaterialThrobber::GetHeightForWidth(int w) const {
187 return w;
188 }
189
190 void MaterialThrobber::OnPaint(gfx::Canvas* canvas) {
191 if (!running_) {
192 CheckmarkThrobber::OnPaint(canvas);
193 return;
194 }
195
196 gfx::Rect bounds = GetContentsBounds();
197 // Inset by half the stroke width to make sure the whole arc is inside
198 // the visible rect.
199 SkScalar stroke_width = SkIntToScalar(bounds.width()) / 10.0;
200 gfx::Rect oval = bounds;
201 int inset = SkScalarCeilToInt(stroke_width / 2.0);
202 oval.Inset(inset, inset);
203
204 // Calculate start and end points. The angles are counter-clockwise because
205 // the throbber spins counter-clockwise. The finish angle starts at 12 o'clock
206 // (90 degrees) and rotates steadily. The start angle trails 180 degrees
207 // behind, except for the first half revolution, when it stays at 12 o'clock.
208 base::TimeDelta revolution_time = base::TimeDelta::FromMilliseconds(1320);
209 base::TimeDelta elapsed_time = base::Time::Now() - start_time();
210 int64_t finish_angle = 90 + 360 * elapsed_time / revolution_time;
211 int64_t start_angle = std::max(finish_angle - 180, 90L);
212
213 SkPath path;
214 // Negate the angles to convert to the clockwise numbers Skia expects.
215 path.arcTo(gfx::RectToSkRect(oval), -start_angle,
216 -(finish_angle - start_angle), true);
217
218 SkPaint paint;
219 // TODO(estade): find a place for this color.
220 paint.setColor(SkColorSetRGB(0x42, 0x85, 0xF4));
221 paint.setStrokeCap(SkPaint::kRound_Cap);
222 paint.setStrokeWidth(stroke_width);
223 paint.setStyle(SkPaint::kStroke_Style);
224 paint.setAntiAlias(true);
225 canvas->DrawPath(path, paint);
226 }
227
168 } // namespace views 228 } // namespace views
OLDNEW
« ui/views/controls/throbber.h ('K') | « ui/views/controls/throbber.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698