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 // TODO(jhawkins): Use hidden instead of showInline* and display:none. | 5 // TODO(jhawkins): Use hidden instead of showInline* and display:none. |
6 | 6 |
7 /** | 7 /** |
8 * The type of the download object. The definition is based on | 8 * The type of the download object. The definition is based on |
9 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue() | 9 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue() |
10 * @typedef {{by_ext_id: (string|undefined), | 10 * @typedef {{by_ext_id: (string|undefined), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 this.summary_ = $('downloads-summary-text'); | 94 this.summary_ = $('downloads-summary-text'); |
95 this.searchText_ = ''; | 95 this.searchText_ = ''; |
96 | 96 |
97 // Keep track of the dates of the newest and oldest downloads so that we | 97 // Keep track of the dates of the newest and oldest downloads so that we |
98 // know where to insert them. | 98 // know where to insert them. |
99 this.newestTime_ = -1; | 99 this.newestTime_ = -1; |
100 | 100 |
101 // Icon load request queue. | 101 // Icon load request queue. |
102 this.iconLoadQueue_ = []; | 102 this.iconLoadQueue_ = []; |
103 this.isIconLoading_ = false; | 103 this.isIconLoading_ = false; |
| 104 |
| 105 this.progressForeground1_ = new Image(); |
| 106 this.progressForeground1_.src = |
| 107 'chrome://theme/IDR_DOWNLOAD_PROGRESS_FOREGROUND_32@1x'; |
| 108 this.progressForeground2_ = new Image(); |
| 109 this.progressForeground2_.src = |
| 110 'chrome://theme/IDR_DOWNLOAD_PROGRESS_FOREGROUND_32@2x'; |
104 } | 111 } |
105 | 112 |
106 /** | 113 /** |
107 * Called when a download has been updated or added. | 114 * Called when a download has been updated or added. |
108 * @param {BackendDownloadObject} download A backend download object | 115 * @param {BackendDownloadObject} download A backend download object |
109 */ | 116 */ |
110 Downloads.prototype.updated = function(download) { | 117 Downloads.prototype.updated = function(download) { |
111 var id = download.id; | 118 var id = download.id; |
112 if (!!this.downloads_[id]) { | 119 if (!!this.downloads_[id]) { |
113 this.downloads_[id].update(download); | 120 this.downloads_[id].update(download); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 486 } |
480 computeDownloadProgress(); | 487 computeDownloadProgress(); |
481 | 488 |
482 // Listens for when device-pixel-ratio changes between any zoom level. | 489 // Listens for when device-pixel-ratio changes between any zoom level. |
483 [0.3, 0.4, 0.6, 0.7, 0.8, 0.95, 1.05, 1.2, 1.4, 1.6, 1.9, 2.2, 2.7, 3.5, 4.5 | 490 [0.3, 0.4, 0.6, 0.7, 0.8, 0.95, 1.05, 1.2, 1.4, 1.6, 1.9, 2.2, 2.7, 3.5, 4.5 |
484 ].forEach(function(scale) { | 491 ].forEach(function(scale) { |
485 var media = '(-webkit-min-device-pixel-ratio:' + scale + ')'; | 492 var media = '(-webkit-min-device-pixel-ratio:' + scale + ')'; |
486 window.matchMedia(media).addListener(computeDownloadProgress); | 493 window.matchMedia(media).addListener(computeDownloadProgress); |
487 }); | 494 }); |
488 | 495 |
489 var ImageCache = {}; | |
490 function getCachedImage(src) { | |
491 if (!ImageCache[src]) { | |
492 ImageCache[src] = new Image(); | |
493 ImageCache[src].src = src; | |
494 } | |
495 return ImageCache[src]; | |
496 } | |
497 | |
498 /** | 496 /** |
499 * Updates the download to reflect new data. | 497 * Updates the download to reflect new data. |
500 * @param {BackendDownloadObject} download A backend download object | 498 * @param {BackendDownloadObject} download A backend download object |
501 */ | 499 */ |
502 Download.prototype.update = function(download) { | 500 Download.prototype.update = function(download) { |
503 this.id_ = download.id; | 501 this.id_ = download.id; |
504 this.filePath_ = download.file_path; | 502 this.filePath_ = download.file_path; |
505 this.fileUrl_ = download.file_url; | 503 this.fileUrl_ = download.file_url; |
506 this.fileName_ = download.file_name; | 504 this.fileName_ = download.file_name; |
507 this.url_ = download.url; | 505 this.url_ = download.url; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 showInlineBlock(this.nodeFileName_, | 550 showInlineBlock(this.nodeFileName_, |
553 this.state_ != Download.States.COMPLETE || | 551 this.state_ != Download.States.COMPLETE || |
554 this.fileExternallyRemoved_); | 552 this.fileExternallyRemoved_); |
555 | 553 |
556 if (this.state_ == Download.States.IN_PROGRESS) { | 554 if (this.state_ == Download.States.IN_PROGRESS) { |
557 this.nodeProgressForeground_.style.display = 'block'; | 555 this.nodeProgressForeground_.style.display = 'block'; |
558 this.nodeProgressBackground_.style.display = 'block'; | 556 this.nodeProgressBackground_.style.display = 'block'; |
559 this.nodeProgressForeground_.width = Download.Progress.width; | 557 this.nodeProgressForeground_.width = Download.Progress.width; |
560 this.nodeProgressForeground_.height = Download.Progress.height; | 558 this.nodeProgressForeground_.height = Download.Progress.height; |
561 | 559 |
562 var foregroundImage = getCachedImage( | 560 var foregroundImage = (window.devicePixelRatio < 2) ? |
563 'chrome://theme/IDR_DOWNLOAD_PROGRESS_FOREGROUND_32@' + | 561 downloads.progressForeground1_ : downloads.progressForeground2_; |
564 window.devicePixelRatio + 'x'); | |
565 | 562 |
566 // Draw a pie-slice for the progress. | 563 // Draw a pie-slice for the progress. |
567 this.canvasProgress_.globalCompositeOperation = 'copy'; | 564 this.canvasProgress_.globalCompositeOperation = 'copy'; |
568 this.canvasProgress_.drawImage( | 565 this.canvasProgress_.drawImage( |
569 foregroundImage, | 566 foregroundImage, |
570 0, 0, // sx, sy | 567 0, 0, // sx, sy |
571 foregroundImage.width, | 568 foregroundImage.width, |
572 foregroundImage.height, | 569 foregroundImage.height, |
573 0, 0, // x, y | 570 0, 0, // x, y |
574 Download.Progress.width, Download.Progress.height); | 571 Download.Progress.width, Download.Progress.height); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); | 967 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); |
971 break; | 968 break; |
972 } | 969 } |
973 } | 970 } |
974 } | 971 } |
975 | 972 |
976 // Add handlers to HTML elements. | 973 // Add handlers to HTML elements. |
977 window.addEventListener('DOMContentLoaded', load); | 974 window.addEventListener('DOMContentLoaded', load); |
978 | 975 |
979 preventDefaultOnPoundLinkClicks(); // From util.js. | 976 preventDefaultOnPoundLinkClicks(); // From util.js. |
OLD | NEW |