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

Side by Side Diff: chrome/browser/download/download_util.cc

Issue 11009017: Mac Web Intents Part 11: Progress view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 8 years, 2 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 | Annotate | Revision Log
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 // Download utility implementation 5 // Download utility implementation
6 6
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
8 8
9 #include "chrome/browser/download/download_util.h" 9 #include "chrome/browser/download/download_util.h"
10 10
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Download progress painting -------------------------------------------------- 149 // Download progress painting --------------------------------------------------
150 150
151 // Common images used for download progress animations. We load them once the 151 // Common images used for download progress animations. We load them once the
152 // first time we do a progress paint, then reuse them as they are always the 152 // first time we do a progress paint, then reuse them as they are always the
153 // same. 153 // same.
154 gfx::ImageSkia* g_foreground_16 = NULL; 154 gfx::ImageSkia* g_foreground_16 = NULL;
155 gfx::ImageSkia* g_background_16 = NULL; 155 gfx::ImageSkia* g_background_16 = NULL;
156 gfx::ImageSkia* g_foreground_32 = NULL; 156 gfx::ImageSkia* g_foreground_32 = NULL;
157 gfx::ImageSkia* g_background_32 = NULL; 157 gfx::ImageSkia* g_background_32 = NULL;
158 158
159 void PaintCustomDownloadProgress(gfx::Canvas* canvas,
160 const gfx::ImageSkia& background_image,
161 const gfx::ImageSkia& foreground_image,
162 int image_size,
163 const gfx::Rect& bounds,
164 int start_angle,
165 int percent_done) {
166 // Draw the background progress image.
167 canvas->DrawImageInt(background_image,
168 bounds.x(),
169 bounds.y());
170
171 // Layer the foreground progress image in an arc proportional to the download
172 // progress. The arc grows clockwise, starting in the midnight position, as
173 // the download progresses. However, if the download does not have known total
174 // size (the server didn't give us one), then we just spin an arc around until
175 // we're done.
176 float sweep_angle = 0.0;
177 float start_pos = static_cast<float>(kStartAngleDegrees);
178 if (percent_done < 0) {
179 sweep_angle = kUnknownAngleDegrees;
180 start_pos = static_cast<float>(start_angle);
181 } else if (percent_done > 0) {
182 sweep_angle = static_cast<float>(kMaxDegrees / 100.0 * percent_done);
183 }
184
185 // Set up an arc clipping region for the foreground image. Don't bother using
186 // a clipping region if it would round to 360 (really 0) degrees, since that
187 // would eliminate the foreground completely and be quite confusing (it would
188 // look like 0% complete when it should be almost 100%).
189 canvas->Save();
190 if (sweep_angle < static_cast<float>(kMaxDegrees - 1)) {
191 SkRect oval;
192 oval.set(SkIntToScalar(bounds.x()),
193 SkIntToScalar(bounds.y()),
194 SkIntToScalar(bounds.x() + image_size),
195 SkIntToScalar(bounds.y() + image_size));
196 SkPath path;
197 path.arcTo(oval,
198 SkFloatToScalar(start_pos),
199 SkFloatToScalar(sweep_angle), false);
200 path.lineTo(SkIntToScalar(bounds.x() + image_size / 2),
201 SkIntToScalar(bounds.y() + image_size / 2));
202
203 // gfx::Canvas::ClipPath does not provide for anti-aliasing.
204 canvas->sk_canvas()->clipPath(path, SkRegion::kIntersect_Op, true);
205 }
206
207 canvas->DrawImageInt(foreground_image,
208 bounds.x(),
209 bounds.y());
210 canvas->Restore();
211 }
212
213
159 void PaintDownloadProgress(gfx::Canvas* canvas, 214 void PaintDownloadProgress(gfx::Canvas* canvas,
160 #if defined(TOOLKIT_VIEWS) 215 #if defined(TOOLKIT_VIEWS)
161 views::View* containing_view, 216 views::View* containing_view,
162 #endif 217 #endif
163 int origin_x, 218 int origin_x,
164 int origin_y, 219 int origin_y,
165 int start_angle, 220 int start_angle,
166 int percent_done, 221 int percent_done,
167 PaintDownloadProgressSize size) { 222 PaintDownloadProgressSize size) {
168 // Load up our common images. 223 // Load up our common images.
(...skipping 26 matching lines...) Expand all
195 // Mirror the positions if necessary. 250 // Mirror the positions if necessary.
196 int mirrored_x = containing_view->GetMirroredXForRect(bounds); 251 int mirrored_x = containing_view->GetMirroredXForRect(bounds);
197 bounds.set_x(mirrored_x); 252 bounds.set_x(mirrored_x);
198 #endif 253 #endif
199 254
200 // Draw the background progress image. 255 // Draw the background progress image.
201 canvas->DrawImageInt(*background, 256 canvas->DrawImageInt(*background,
202 bounds.x(), 257 bounds.x(),
203 bounds.y()); 258 bounds.y());
204 259
205 // Layer the foreground progress image in an arc proportional to the download 260 PaintCustomDownloadProgress(canvas, *background, *foreground,
206 // progress. The arc grows clockwise, starting in the midnight position, as 261 kProgressIconSize, bounds, start_angle,
207 // the download progresses. However, if the download does not have known total 262 percent_done);
208 // size (the server didn't give us one), then we just spin an arc around until
209 // we're done.
210 float sweep_angle = 0.0;
211 float start_pos = static_cast<float>(kStartAngleDegrees);
212 if (percent_done < 0) {
213 sweep_angle = kUnknownAngleDegrees;
214 start_pos = static_cast<float>(start_angle);
215 } else if (percent_done > 0) {
216 sweep_angle = static_cast<float>(kMaxDegrees / 100.0 * percent_done);
217 }
218
219 // Set up an arc clipping region for the foreground image. Don't bother using
220 // a clipping region if it would round to 360 (really 0) degrees, since that
221 // would eliminate the foreground completely and be quite confusing (it would
222 // look like 0% complete when it should be almost 100%).
223 canvas->Save();
224 if (sweep_angle < static_cast<float>(kMaxDegrees - 1)) {
225 SkRect oval;
226 oval.set(SkIntToScalar(bounds.x()),
227 SkIntToScalar(bounds.y()),
228 SkIntToScalar(bounds.x() + kProgressIconSize),
229 SkIntToScalar(bounds.y() + kProgressIconSize));
230 SkPath path;
231 path.arcTo(oval,
232 SkFloatToScalar(start_pos),
233 SkFloatToScalar(sweep_angle), false);
234 path.lineTo(SkIntToScalar(bounds.x() + kProgressIconSize / 2),
235 SkIntToScalar(bounds.y() + kProgressIconSize / 2));
236
237 // gfx::Canvas::ClipPath does not provide for anti-aliasing.
238 canvas->sk_canvas()->clipPath(path, SkRegion::kIntersect_Op, true);
239 }
240
241 canvas->DrawImageInt(*foreground,
242 bounds.x(),
243 bounds.y());
244 canvas->Restore();
245 } 263 }
246 264
247 void PaintDownloadComplete(gfx::Canvas* canvas, 265 void PaintDownloadComplete(gfx::Canvas* canvas,
248 #if defined(TOOLKIT_VIEWS) 266 #if defined(TOOLKIT_VIEWS)
249 views::View* containing_view, 267 views::View* containing_view,
250 #endif 268 #endif
251 int origin_x, 269 int origin_x,
252 int origin_y, 270 int origin_y,
253 double animation_progress, 271 double animation_progress,
254 PaintDownloadProgressSize size) { 272 PaintDownloadProgressSize size) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 UMA_HISTOGRAM_ENUMERATION( 492 UMA_HISTOGRAM_ENUMERATION(
475 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 493 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
476 } 494 }
477 495
478 void RecordDownloadSource(ChromeDownloadSource source) { 496 void RecordDownloadSource(ChromeDownloadSource source) {
479 UMA_HISTOGRAM_ENUMERATION( 497 UMA_HISTOGRAM_ENUMERATION(
480 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); 498 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
481 } 499 }
482 500
483 } // namespace download_util 501 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/ui/cocoa/intents/web_intent_picker_view_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698