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

Side by Side Diff: chrome/browser/resources/downloads/downloads.js

Issue 10830217: Fix alpha mask for download progress on high DPI displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: JsDoc fixes. Created 8 years, 4 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
« no previous file with comments | « chrome/browser/resources/downloads/downloads.css ('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 // 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 * Sets the display style of a node. 8 * Sets the display style of a node.
9 * @param {!Element} node The target element to show or hide.
10 * @param {boolean} isShow Should the target element be visible.
9 */ 11 */
10 function showInline(node, isShow) { 12 function showInline(node, isShow) {
11 node.style.display = isShow ? 'inline' : 'none'; 13 node.style.display = isShow ? 'inline' : 'none';
12 } 14 }
13 15
16 /**
17 * Sets the display style of a node.
18 * @param {!Element} node The target element to show or hide.
19 * @param {boolean} isShow Should the target element be visible.
20 */
14 function showInlineBlock(node, isShow) { 21 function showInlineBlock(node, isShow) {
15 node.style.display = isShow ? 'inline-block' : 'none'; 22 node.style.display = isShow ? 'inline-block' : 'none';
16 } 23 }
17 24
18 /** 25 /**
19 * Creates an element of a specified type with a specified class name. 26 * Creates an element of a specified type with a specified class name.
20 * @param {string} type The node type. 27 * @param {string} type The node type.
21 * @param {string} className The class name to use. 28 * @param {string} className The class name to use.
29 * @return {Element} The created element.
22 */ 30 */
23 function createElementWithClassName(type, className) { 31 function createElementWithClassName(type, className) {
24 var elm = document.createElement(type); 32 var elm = document.createElement(type);
25 elm.className = className; 33 elm.className = className;
26 return elm; 34 return elm;
27 } 35 }
28 36
29 /** 37 /**
30 * Creates a link with a specified onclick handler and content 38 * Creates a link with a specified onclick handler and content.
31 * @param {function()} onclick The onclick handler 39 * @param {function()} onclick The onclick handler.
32 * @param {string} value The link text 40 * @param {string} value The link text.
41 * @return {Element} The created link element.
33 */ 42 */
34 function createLink(onclick, value) { 43 function createLink(onclick, value) {
35 var link = document.createElement('a'); 44 var link = document.createElement('a');
36 link.onclick = onclick; 45 link.onclick = onclick;
37 link.href = '#'; 46 link.href = '#';
38 link.textContent = value; 47 link.textContent = value;
39 link.oncontextmenu = function() { return false; }; 48 link.oncontextmenu = function() { return false; };
40 return link; 49 return link;
41 } 50 }
42 51
43 /** 52 /**
44 * Creates a button with a specified onclick handler and content 53 * Creates a button with a specified onclick handler and content.
45 * @param {function()} onclick The onclick handler 54 * @param {function()} onclick The onclick handler.
46 * @param {string} value The button text 55 * @param {string} value The button text.
56 * @return {Element} The created button.
47 */ 57 */
48 function createButton(onclick, value) { 58 function createButton(onclick, value) {
49 var button = document.createElement('input'); 59 var button = document.createElement('input');
50 button.type = 'button'; 60 button.type = 'button';
51 button.value = value; 61 button.value = value;
52 button.onclick = onclick; 62 button.onclick = onclick;
53 return button; 63 return button;
54 } 64 }
55 65
56 /////////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////////
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Container for all 'safe download' UI. 248 // Container for all 'safe download' UI.
239 this.safe_ = createElementWithClassName('div', 'safe'); 249 this.safe_ = createElementWithClassName('div', 'safe');
240 this.safe_.ondragstart = this.drag_.bind(this); 250 this.safe_.ondragstart = this.drag_.bind(this);
241 this.node.appendChild(this.safe_); 251 this.node.appendChild(this.safe_);
242 252
243 if (download.state != Download.States.COMPLETE) { 253 if (download.state != Download.States.COMPLETE) {
244 this.nodeProgressBackground_ = 254 this.nodeProgressBackground_ =
245 createElementWithClassName('div', 'progress background'); 255 createElementWithClassName('div', 'progress background');
246 this.safe_.appendChild(this.nodeProgressBackground_); 256 this.safe_.appendChild(this.nodeProgressBackground_);
247 257
248 this.canvasProgress_ = 258 this.nodeProgressForeground_ =
249 document.getCSSCanvasContext('2d', 'canvas_' + download.id, 259 createElementWithClassName('canvas', 'progress');
250 Download.Progress.width, 260 this.nodeProgressForeground_.width = Download.Progress.width;
251 Download.Progress.height); 261 this.nodeProgressForeground_.height = Download.Progress.height;
262 this.canvasProgress_ = this.nodeProgressForeground_.getContext('2d');
252 263
253 this.nodeProgressForeground_ = 264 this.canvasProgressForegroundImage_ = new Image();
254 createElementWithClassName('div', 'progress foreground'); 265 this.canvasProgressForegroundImage_.src =
255 this.nodeProgressForeground_.style.webkitMask = 266 'chrome://theme/IDR_DOWNLOAD_PROGRESS_FOREGROUND_32@' +
256 '-webkit-canvas(canvas_' + download.id + ')'; 267 window.devicePixelRatio + 'x';
257 this.safe_.appendChild(this.nodeProgressForeground_); 268 this.safe_.appendChild(this.nodeProgressForeground_);
258 } 269 }
259 270
260 this.nodeImg_ = createElementWithClassName('img', 'icon'); 271 this.nodeImg_ = createElementWithClassName('img', 'icon');
261 this.safe_.appendChild(this.nodeImg_); 272 this.safe_.appendChild(this.nodeImg_);
262 273
263 // FileLink is used for completed downloads, otherwise we show FileName. 274 // FileLink is used for completed downloads, otherwise we show FileName.
264 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area'); 275 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area');
265 this.safe_.appendChild(this.nodeTitleArea_); 276 this.safe_.appendChild(this.nodeTitleArea_);
266 277
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 NOT_DANGEROUS: 'NOT_DANGEROUS', 368 NOT_DANGEROUS: 'NOT_DANGEROUS',
358 DANGEROUS_FILE: 'DANGEROUS_FILE', 369 DANGEROUS_FILE: 'DANGEROUS_FILE',
359 DANGEROUS_URL: 'DANGEROUS_URL', 370 DANGEROUS_URL: 'DANGEROUS_URL',
360 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT', 371 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT',
361 UNCOMMON_CONTENT: 'UNCOMMON_CONTENT' 372 UNCOMMON_CONTENT: 'UNCOMMON_CONTENT'
362 }; 373 };
363 374
364 /** 375 /**
365 * Constants for the progress meter. 376 * Constants for the progress meter.
366 */ 377 */
367 Download.Progress = { 378
368 width: 48, 379 Download.Progress = (function() {
369 height: 48, 380 var scale = window.devicePixelRatio;
370 radius: 24, 381 return {
371 centerX: 24, 382 width: 48 * scale,
372 centerY: 24, 383 height: 48 * scale,
373 base: -0.5 * Math.PI, 384 radius: 24 * scale,
374 dir: false, 385 centerX: 24 * scale,
375 }; 386 centerY: 24 * scale,
387 base: -0.5 * Math.PI,
388 dir: false,
389 };
390 })();
376 391
377 /** 392 /**
378 * Updates the download to reflect new data. 393 * Updates the download to reflect new data.
379 * @param {Object} download A backend download object (see downloads_ui.cc) 394 * @param {Object} download A backend download object (see downloads_ui.cc)
380 */ 395 */
381 Download.prototype.update = function(download) { 396 Download.prototype.update = function(download) {
382 this.id_ = download.id; 397 this.id_ = download.id;
383 this.filePath_ = download.file_path; 398 this.filePath_ = download.file_path;
384 this.fileUrl_ = download.file_url; 399 this.fileUrl_ = download.file_url;
385 this.fileName_ = download.file_name; 400 this.fileName_ = download.file_name;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // undesirable reordering. http://crbug.com/13216 453 // undesirable reordering. http://crbug.com/13216
439 showInlineBlock(this.nodeFileName_, 454 showInlineBlock(this.nodeFileName_,
440 this.state_ != Download.States.COMPLETE || 455 this.state_ != Download.States.COMPLETE ||
441 this.fileExternallyRemoved_); 456 this.fileExternallyRemoved_);
442 457
443 if (this.state_ == Download.States.IN_PROGRESS) { 458 if (this.state_ == Download.States.IN_PROGRESS) {
444 this.nodeProgressForeground_.style.display = 'block'; 459 this.nodeProgressForeground_.style.display = 'block';
445 this.nodeProgressBackground_.style.display = 'block'; 460 this.nodeProgressBackground_.style.display = 'block';
446 461
447 // Draw a pie-slice for the progress. 462 // Draw a pie-slice for the progress.
448 this.canvasProgress_.clearRect(0, 0, 463 this.canvasProgress_.globalCompositeOperation = 'copy';
449 Download.Progress.width, 464 this.canvasProgress_.drawImage(this.canvasProgressForegroundImage_, 0, 0);
450 Download.Progress.height); 465 this.canvasProgress_.globalCompositeOperation = 'destination-in';
451 this.canvasProgress_.beginPath(); 466 this.canvasProgress_.beginPath();
452 this.canvasProgress_.moveTo(Download.Progress.centerX, 467 this.canvasProgress_.moveTo(Download.Progress.centerX,
453 Download.Progress.centerY); 468 Download.Progress.centerY);
454 469
455 // Draw an arc CW for both RTL and LTR. http://crbug.com/13215 470 // Draw an arc CW for both RTL and LTR. http://crbug.com/13215
456 this.canvasProgress_.arc(Download.Progress.centerX, 471 this.canvasProgress_.arc(Download.Progress.centerX,
457 Download.Progress.centerY, 472 Download.Progress.centerY,
458 Download.Progress.radius, 473 Download.Progress.radius,
459 Download.Progress.base, 474 Download.Progress.base,
460 Download.Progress.base + Math.PI * 0.02 * 475 Download.Progress.base + Math.PI * 0.02 *
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 case Download.States.COMPLETE: 553 case Download.States.COMPLETE:
539 return this.fileExternallyRemoved_ ? 554 return this.fileExternallyRemoved_ ?
540 loadTimeData.getString('status_removed') : ''; 555 loadTimeData.getString('status_removed') : '';
541 } 556 }
542 }; 557 };
543 558
544 /** 559 /**
545 * Tells the backend to initiate a drag, allowing users to drag 560 * Tells the backend to initiate a drag, allowing users to drag
546 * files from the download page and have them appear as native file 561 * files from the download page and have them appear as native file
547 * drags. 562 * drags.
563 * @return {boolean} Returns false to prevent the default action.
548 * @private 564 * @private
549 */ 565 */
550 Download.prototype.drag_ = function() { 566 Download.prototype.drag_ = function() {
551 chrome.send('drag', [this.id_.toString()]); 567 chrome.send('drag', [this.id_.toString()]);
552 return false; 568 return false;
553 }; 569 };
554 570
555 /** 571 /**
556 * Tells the backend to open this file. 572 * Tells the backend to open this file.
573 * @return {boolean} Returns false to prevent the default action.
557 * @private 574 * @private
558 */ 575 */
559 Download.prototype.openFile_ = function() { 576 Download.prototype.openFile_ = function() {
560 chrome.send('openFile', [this.id_.toString()]); 577 chrome.send('openFile', [this.id_.toString()]);
561 return false; 578 return false;
562 }; 579 };
563 580
564 /** 581 /**
565 * Tells the backend that the user chose to save a dangerous file. 582 * Tells the backend that the user chose to save a dangerous file.
583 * @return {boolean} Returns false to prevent the default action.
566 * @private 584 * @private
567 */ 585 */
568 Download.prototype.saveDangerous_ = function() { 586 Download.prototype.saveDangerous_ = function() {
569 chrome.send('saveDangerous', [this.id_.toString()]); 587 chrome.send('saveDangerous', [this.id_.toString()]);
570 return false; 588 return false;
571 }; 589 };
572 590
573 /** 591 /**
574 * Tells the backend that the user chose to discard a dangerous file. 592 * Tells the backend that the user chose to discard a dangerous file.
593 * @return {boolean} Returns false to prevent the default action.
575 * @private 594 * @private
576 */ 595 */
577 Download.prototype.discardDangerous_ = function() { 596 Download.prototype.discardDangerous_ = function() {
578 chrome.send('discardDangerous', [this.id_.toString()]); 597 chrome.send('discardDangerous', [this.id_.toString()]);
579 downloads.remove(this.id_); 598 downloads.remove(this.id_);
580 return false; 599 return false;
581 }; 600 };
582 601
583 /** 602 /**
584 * Tells the backend to show the file in explorer. 603 * Tells the backend to show the file in explorer.
604 * @return {boolean} Returns false to prevent the default action.
585 * @private 605 * @private
586 */ 606 */
587 Download.prototype.show_ = function() { 607 Download.prototype.show_ = function() {
588 chrome.send('show', [this.id_.toString()]); 608 chrome.send('show', [this.id_.toString()]);
589 return false; 609 return false;
590 }; 610 };
591 611
592 /** 612 /**
593 * Tells the backend to pause this download. 613 * Tells the backend to pause this download.
614 * @return {boolean} Returns false to prevent the default action.
594 * @private 615 * @private
595 */ 616 */
596 Download.prototype.togglePause_ = function() { 617 Download.prototype.togglePause_ = function() {
597 chrome.send('togglepause', [this.id_.toString()]); 618 chrome.send('togglepause', [this.id_.toString()]);
598 return false; 619 return false;
599 }; 620 };
600 621
601 /** 622 /**
602 * Tells the backend to remove this download from history and download shelf. 623 * Tells the backend to remove this download from history and download shelf.
624 * @return {boolean} Returns false to prevent the default action.
603 * @private 625 * @private
604 */ 626 */
605 Download.prototype.remove_ = function() { 627 Download.prototype.remove_ = function() {
606 chrome.send('remove', [this.id_.toString()]); 628 chrome.send('remove', [this.id_.toString()]);
607 return false; 629 return false;
608 }; 630 };
609 631
610 /** 632 /**
611 * Tells the backend to cancel this download. 633 * Tells the backend to cancel this download.
634 * @return {boolean} Returns false to prevent the default action.
612 * @private 635 * @private
613 */ 636 */
614 Download.prototype.cancel_ = function() { 637 Download.prototype.cancel_ = function() {
615 chrome.send('cancel', [this.id_.toString()]); 638 chrome.send('cancel', [this.id_.toString()]);
616 return false; 639 return false;
617 }; 640 };
618 641
619 /////////////////////////////////////////////////////////////////////////////// 642 ///////////////////////////////////////////////////////////////////////////////
620 // Page: 643 // Page:
621 var downloads, resultsTimeout; 644 var downloads, resultsTimeout;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 downloads.clear(); 695 downloads.clear();
673 downloads.setSearchText(''); 696 downloads.setSearchText('');
674 chrome.send('clearAll'); 697 chrome.send('clearAll');
675 } 698 }
676 699
677 /////////////////////////////////////////////////////////////////////////////// 700 ///////////////////////////////////////////////////////////////////////////////
678 // Chrome callbacks: 701 // Chrome callbacks:
679 /** 702 /**
680 * Our history system calls this function with results from searches or when 703 * Our history system calls this function with results from searches or when
681 * downloads are added or removed. 704 * downloads are added or removed.
705 * @param {Array.<Object>} results List of updates.
682 */ 706 */
683 function downloadsList(results) { 707 function downloadsList(results) {
684 if (downloads && downloads.isUpdateNeeded(results)) { 708 if (downloads && downloads.isUpdateNeeded(results)) {
685 if (resultsTimeout) 709 if (resultsTimeout)
686 clearTimeout(resultsTimeout); 710 clearTimeout(resultsTimeout);
687 fifo_results.length = 0; 711 fifo_results.length = 0;
688 downloads.clear(); 712 downloads.clear();
689 downloadUpdated(results); 713 downloadUpdated(results);
690 } 714 }
691 downloads.updateSummary(); 715 downloads.updateSummary();
692 } 716 }
693 717
694 /** 718 /**
695 * When a download is updated (progress, state change), this is called. 719 * When a download is updated (progress, state change), this is called.
720 * @param {Array.<Object>} results List of updates for the download process.
696 */ 721 */
697 function downloadUpdated(results) { 722 function downloadUpdated(results) {
698 // Sometimes this can get called too early. 723 // Sometimes this can get called too early.
699 if (!downloads) 724 if (!downloads)
700 return; 725 return;
701 726
702 fifo_results = fifo_results.concat(results); 727 fifo_results = fifo_results.concat(results);
703 tryDownloadUpdatedPeriodically(); 728 tryDownloadUpdatedPeriodically();
704 } 729 }
705 730
(...skipping 10 matching lines...) Expand all
716 if (Date.now() - start > 50) { 741 if (Date.now() - start > 50) {
717 clearTimeout(resultsTimeout); 742 clearTimeout(resultsTimeout);
718 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); 743 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
719 break; 744 break;
720 } 745 }
721 } 746 }
722 } 747 }
723 748
724 // Add handlers to HTML elements. 749 // Add handlers to HTML elements.
725 window.addEventListener('DOMContentLoaded', load); 750 window.addEventListener('DOMContentLoaded', load);
OLDNEW
« no previous file with comments | « chrome/browser/resources/downloads/downloads.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698