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 /** | 5 /** |
6 * The overlay displaying the image. | 6 * The overlay displaying the image. |
7 * @param {HTMLElement} container The container element. | 7 * @param {HTMLElement} container The container element. |
8 * @param {Viewport} viewport The viewport. | 8 * @param {Viewport} viewport The viewport. |
9 * @param {MetadataCache} metadataCache The metadataCache. | 9 * @param {MetadataCache} metadataCache The metadataCache. |
10 */ | 10 */ |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 * @param {boolean} opt_reuseScreenCanvas True if it is OK to reuse the screen | 488 * @param {boolean} opt_reuseScreenCanvas True if it is OK to reuse the screen |
489 * resolution canvas. | 489 * resolution canvas. |
490 * @param {number} opt_width Image width. | 490 * @param {number} opt_width Image width. |
491 * @param {number} opt_height Image height. | 491 * @param {number} opt_height Image height. |
492 * @param {boolean} opt_preview True if the image is a preview (not full res). | 492 * @param {boolean} opt_preview True if the image is a preview (not full res). |
493 * @private | 493 * @private |
494 */ | 494 */ |
495 ImageView.prototype.replaceContent_ = function( | 495 ImageView.prototype.replaceContent_ = function( |
496 content, opt_reuseScreenCanvas, opt_width, opt_height, opt_preview) { | 496 content, opt_reuseScreenCanvas, opt_width, opt_height, opt_preview) { |
497 | 497 |
| 498 if (this.contentCanvas_ && this.contentCanvas_.parentNode == this.container_) |
| 499 this.container_.removeChild(this.contentCanvas_); |
| 500 |
498 if (content.constructor.name == 'HTMLVideoElement') { | 501 if (content.constructor.name == 'HTMLVideoElement') { |
499 this.contentCanvas_ = null; | 502 this.contentCanvas_ = null; |
500 this.videoElement_ = content; | 503 this.videoElement_ = content; |
501 this.screenImage_ = content; | 504 this.screenImage_ = content; |
502 this.screenImage_.className = 'image'; | 505 this.screenImage_.className = 'image'; |
503 return; | 506 return; |
504 } | 507 } |
505 | 508 |
506 if (!opt_reuseScreenCanvas || !this.screenImage_ || | 509 if (!opt_reuseScreenCanvas || !this.screenImage_ || |
507 this.screenImage_.constructor.name == 'HTMLVideoElement') { | 510 this.screenImage_.constructor.name == 'HTMLVideoElement') { |
(...skipping 11 matching lines...) Expand all Loading... |
519 this.viewport_.update(); | 522 this.viewport_.update(); |
520 this.draw(); | 523 this.draw(); |
521 | 524 |
522 if (opt_reuseScreenCanvas && !this.screenImage_.parentNode) { | 525 if (opt_reuseScreenCanvas && !this.screenImage_.parentNode) { |
523 this.container_.appendChild(this.screenImage_); | 526 this.container_.appendChild(this.screenImage_); |
524 } | 527 } |
525 | 528 |
526 this.preview_ = opt_preview; | 529 this.preview_ = opt_preview; |
527 // If this is not a thumbnail, cache the content and the screen-scale image. | 530 // If this is not a thumbnail, cache the content and the screen-scale image. |
528 if (this.hasValidImage()) { | 531 if (this.hasValidImage()) { |
| 532 // Insert the full resolution canvas into DOM so that it can be printed. |
| 533 this.container_.appendChild(this.contentCanvas_); |
| 534 this.contentCanvas_.classList.add('fullres'); |
| 535 |
529 this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true); | 536 this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true); |
530 this.screenCache_.putItem(this.contentID_, this.screenImage_); | 537 this.screenCache_.putItem(this.contentID_, this.screenImage_); |
531 | 538 |
532 // TODO(kaznacheev): It is better to pass screenImage_ as it is usually | 539 // TODO(kaznacheev): It is better to pass screenImage_ as it is usually |
533 // much smaller than contentCanvas_ and still contains the entire image. | 540 // much smaller than contentCanvas_ and still contains the entire image. |
534 // Once we implement zoom/pan we should pass contentCanvas_ instead. | 541 // Once we implement zoom/pan we should pass contentCanvas_ instead. |
535 this.updateThumbnail_(this.screenImage_); | 542 this.updateThumbnail_(this.screenImage_); |
536 | 543 |
537 this.contentRevision_++; | 544 this.contentRevision_++; |
538 for (var i = 0; i != this.contentCallbacks_.length; i++) { | 545 for (var i = 0; i != this.contentCallbacks_.length; i++) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 797 |
791 /** | 798 /** |
792 * Evict the least recently used items. | 799 * Evict the least recently used items. |
793 */ | 800 */ |
794 ImageView.Cache.prototype.evictLRU = function() { | 801 ImageView.Cache.prototype.evictLRU = function() { |
795 if (this.order_.length == this.capacity_) { | 802 if (this.order_.length == this.capacity_) { |
796 var id = this.order_.shift(); | 803 var id = this.order_.shift(); |
797 delete this.map_[id]; | 804 delete this.map_[id]; |
798 } | 805 } |
799 }; | 806 }; |
OLD | NEW |