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

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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Download progress painting -------------------------------------------------- 164 // Download progress painting --------------------------------------------------
165 165
166 // Common images used for download progress animations. We load them once the 166 // Common images used for download progress animations. We load them once the
167 // first time we do a progress paint, then reuse them as they are always the 167 // first time we do a progress paint, then reuse them as they are always the
168 // same. 168 // same.
169 gfx::ImageSkia* g_foreground_16 = NULL; 169 gfx::ImageSkia* g_foreground_16 = NULL;
170 gfx::ImageSkia* g_background_16 = NULL; 170 gfx::ImageSkia* g_background_16 = NULL;
171 gfx::ImageSkia* g_foreground_32 = NULL; 171 gfx::ImageSkia* g_foreground_32 = NULL;
172 gfx::ImageSkia* g_background_32 = NULL; 172 gfx::ImageSkia* g_background_32 = NULL;
173 173
174 void PaintCustomDownloadProgress(gfx::Canvas* canvas,
175 const gfx::ImageSkia& background_image,
176 const gfx::ImageSkia& foreground_image,
177 int image_size,
178 const gfx::Rect& bounds,
179 int start_angle,
180 int percent_done) {
181 // Draw the background progress image.
182 canvas->DrawImageInt(background_image,
183 bounds.x(),
184 bounds.y());
185
186 // Layer the foreground progress image in an arc proportional to the download
187 // progress. The arc grows clockwise, starting in the midnight position, as
188 // the download progresses. However, if the download does not have known total
189 // size (the server didn't give us one), then we just spin an arc around until
190 // we're done.
191 float sweep_angle = 0.0;
192 float start_pos = static_cast<float>(kStartAngleDegrees);
193 if (percent_done < 0) {
194 sweep_angle = kUnknownAngleDegrees;
195 start_pos = static_cast<float>(start_angle);
196 } else if (percent_done > 0) {
197 sweep_angle = static_cast<float>(kMaxDegrees / 100.0 * percent_done);
198 }
199
200 // Set up an arc clipping region for the foreground image. Don't bother using
201 // a clipping region if it would round to 360 (really 0) degrees, since that
202 // would eliminate the foreground completely and be quite confusing (it would
203 // look like 0% complete when it should be almost 100%).
204 canvas->Save();
205 if (sweep_angle < static_cast<float>(kMaxDegrees - 1)) {
206 SkRect oval;
207 oval.set(SkIntToScalar(bounds.x()),
208 SkIntToScalar(bounds.y()),
209 SkIntToScalar(bounds.x() + image_size),
210 SkIntToScalar(bounds.y() + image_size));
211 SkPath path;
212 path.arcTo(oval,
213 SkFloatToScalar(start_pos),
214 SkFloatToScalar(sweep_angle), false);
215 path.lineTo(SkIntToScalar(bounds.x() + image_size / 2),
216 SkIntToScalar(bounds.y() + image_size / 2));
217
218 // gfx::Canvas::ClipPath does not provide for anti-aliasing.
219 canvas->sk_canvas()->clipPath(path, SkRegion::kIntersect_Op, true);
220 }
221
222 canvas->DrawImageInt(foreground_image,
223 bounds.x(),
224 bounds.y());
225 canvas->Restore();
226 }
227
228
174 void PaintDownloadProgress(gfx::Canvas* canvas, 229 void PaintDownloadProgress(gfx::Canvas* canvas,
175 #if defined(TOOLKIT_VIEWS) 230 #if defined(TOOLKIT_VIEWS)
176 views::View* containing_view, 231 views::View* containing_view,
177 #endif 232 #endif
178 int origin_x, 233 int origin_x,
179 int origin_y, 234 int origin_y,
180 int start_angle, 235 int start_angle,
181 int percent_done, 236 int percent_done,
182 PaintDownloadProgressSize size) { 237 PaintDownloadProgressSize size) {
183 // Load up our common images. 238 // Load up our common images.
(...skipping 26 matching lines...) Expand all
210 // Mirror the positions if necessary. 265 // Mirror the positions if necessary.
211 int mirrored_x = containing_view->GetMirroredXForRect(bounds); 266 int mirrored_x = containing_view->GetMirroredXForRect(bounds);
212 bounds.set_x(mirrored_x); 267 bounds.set_x(mirrored_x);
213 #endif 268 #endif
214 269
215 // Draw the background progress image. 270 // Draw the background progress image.
216 canvas->DrawImageInt(*background, 271 canvas->DrawImageInt(*background,
217 bounds.x(), 272 bounds.x(),
218 bounds.y()); 273 bounds.y());
219 274
220 // Layer the foreground progress image in an arc proportional to the download 275 PaintCustomDownloadProgress(canvas, *background, *foreground,
221 // progress. The arc grows clockwise, starting in the midnight position, as 276 kProgressIconSize, bounds, start_angle,
222 // the download progresses. However, if the download does not have known total 277 percent_done);
223 // size (the server didn't give us one), then we just spin an arc around until
224 // we're done.
225 float sweep_angle = 0.0;
226 float start_pos = static_cast<float>(kStartAngleDegrees);
227 if (percent_done < 0) {
228 sweep_angle = kUnknownAngleDegrees;
229 start_pos = static_cast<float>(start_angle);
230 } else if (percent_done > 0) {
231 sweep_angle = static_cast<float>(kMaxDegrees / 100.0 * percent_done);
232 }
233
234 // Set up an arc clipping region for the foreground image. Don't bother using
235 // a clipping region if it would round to 360 (really 0) degrees, since that
236 // would eliminate the foreground completely and be quite confusing (it would
237 // look like 0% complete when it should be almost 100%).
238 canvas->Save();
239 if (sweep_angle < static_cast<float>(kMaxDegrees - 1)) {
240 SkRect oval;
241 oval.set(SkIntToScalar(bounds.x()),
242 SkIntToScalar(bounds.y()),
243 SkIntToScalar(bounds.x() + kProgressIconSize),
244 SkIntToScalar(bounds.y() + kProgressIconSize));
245 SkPath path;
246 path.arcTo(oval,
247 SkFloatToScalar(start_pos),
248 SkFloatToScalar(sweep_angle), false);
249 path.lineTo(SkIntToScalar(bounds.x() + kProgressIconSize / 2),
250 SkIntToScalar(bounds.y() + kProgressIconSize / 2));
251
252 // gfx::Canvas::ClipPath does not provide for anti-aliasing.
253 canvas->sk_canvas()->clipPath(path, SkRegion::kIntersect_Op, true);
254 }
255
256 canvas->DrawImageInt(*foreground,
257 bounds.x(),
258 bounds.y());
259 canvas->Restore();
260 } 278 }
261 279
262 void PaintDownloadComplete(gfx::Canvas* canvas, 280 void PaintDownloadComplete(gfx::Canvas* canvas,
263 #if defined(TOOLKIT_VIEWS) 281 #if defined(TOOLKIT_VIEWS)
264 views::View* containing_view, 282 views::View* containing_view,
265 #endif 283 #endif
266 int origin_x, 284 int origin_x,
267 int origin_y, 285 int origin_y,
268 double animation_progress, 286 double animation_progress,
269 PaintDownloadProgressSize size) { 287 PaintDownloadProgressSize size) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 ShowInShelfData* data = 521 ShowInShelfData* data =
504 static_cast<ShowInShelfData*>(item->GetUserData(kShowInShelfKey)); 522 static_cast<ShowInShelfData*>(item->GetUserData(kShowInShelfKey));
505 return !data || data->should_show(); 523 return !data || data->should_show();
506 } 524 }
507 525
508 void SetShouldShowInShelf(content::DownloadItem* item, bool should_show) { 526 void SetShouldShowInShelf(content::DownloadItem* item, bool should_show) {
509 item->SetUserData(kShowInShelfKey, new ShowInShelfData(should_show)); 527 item->SetUserData(kShowInShelfKey, new ShowInShelfData(should_show));
510 } 528 }
511 529
512 } // namespace download_util 530 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698