OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * The overlay displaying the image. | 8 * The overlay displaying the image. |
9 * | 9 * |
10 * @param {HTMLElement} container The container element. | 10 * @param {HTMLElement} container The container element. |
11 * @param {Viewport} viewport The viewport. | 11 * @param {Viewport} viewport The viewport. |
12 * @constructor | 12 * @constructor |
13 * @extends {ImageBuffer.Overlay} | |
13 */ | 14 */ |
14 function ImageView(container, viewport) { | 15 function ImageView(container, viewport) { |
16 ImageBuffer.Overlay.call(this); | |
17 | |
15 this.container_ = container; | 18 this.container_ = container; |
16 this.viewport_ = viewport; | 19 this.viewport_ = viewport; |
17 this.document_ = container.ownerDocument; | 20 this.document_ = container.ownerDocument; |
18 this.contentGeneration_ = 0; | 21 this.contentGeneration_ = 0; |
19 this.displayedContentGeneration_ = 0; | 22 this.displayedContentGeneration_ = 0; |
20 this.displayedViewportGeneration_ = 0; | 23 this.displayedViewportGeneration_ = 0; |
21 | 24 |
22 this.imageLoader_ = new ImageUtil.ImageLoader(this.document_); | 25 this.imageLoader_ = new ImageUtil.ImageLoader(this.document_); |
23 // We have a separate image loader for prefetch which does not get cancelled | 26 // We have a separate image loader for prefetch which does not get cancelled |
24 // when the selection changes. | 27 // when the selection changes. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 ImageView.LOAD_TYPE_OFFLINE = 4; | 85 ImageView.LOAD_TYPE_OFFLINE = 4; |
83 | 86 |
84 /** | 87 /** |
85 * The total number of load types. | 88 * The total number of load types. |
86 */ | 89 */ |
87 ImageView.LOAD_TYPE_TOTAL = 5; | 90 ImageView.LOAD_TYPE_TOTAL = 5; |
88 | 91 |
89 ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype}; | 92 ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype}; |
90 | 93 |
91 /** | 94 /** |
92 * Draws below overlays with the default zIndex. | 95 * @override |
93 * @return {number} Z-index. | |
94 */ | 96 */ |
95 ImageView.prototype.getZIndex = function() { return -1; }; | 97 ImageView.prototype.getZIndex = function() { return -1; }; |
96 | 98 |
97 /** | 99 /** |
98 * Draws the image on screen. | 100 * @override |
99 */ | 101 */ |
100 ImageView.prototype.draw = function() { | 102 ImageView.prototype.draw = function() { |
103 console.log('draw'); | |
mtomasz
2014/07/11 06:34:11
nit: remove
hirono
2014/07/11 06:41:17
Done.
| |
101 if (!this.contentCanvas_) // Do nothing if the image content is not set. | 104 if (!this.contentCanvas_) // Do nothing if the image content is not set. |
102 return; | 105 return; |
103 | 106 |
104 var forceRepaint = false; | 107 var forceRepaint = false; |
105 | 108 |
106 if (this.displayedViewportGeneration_ !== | 109 if (this.displayedViewportGeneration_ !== |
107 this.viewport_.getCacheGeneration()) { | 110 this.viewport_.getCacheGeneration()) { |
108 this.displayedViewportGeneration_ = this.viewport_.getCacheGeneration(); | 111 this.displayedViewportGeneration_ = this.viewport_.getCacheGeneration(); |
109 | 112 |
110 this.setupDeviceBuffer(this.screenImage_); | 113 this.setupDeviceBuffer(this.screenImage_); |
111 | 114 |
112 forceRepaint = true; | 115 forceRepaint = true; |
113 } | 116 } |
114 | 117 |
115 if (forceRepaint || | 118 if (forceRepaint || |
116 this.displayedContentGeneration_ !== this.contentGeneration_) { | 119 this.displayedContentGeneration_ !== this.contentGeneration_) { |
117 this.displayedContentGeneration_ = this.contentGeneration_; | 120 this.displayedContentGeneration_ = this.contentGeneration_; |
118 | 121 |
119 ImageUtil.trace.resetTimer('paint'); | 122 ImageUtil.trace.resetTimer('paint'); |
120 this.paintDeviceRect(this.viewport_.getDeviceClipped(), | 123 this.paintDeviceRect(this.viewport_.getDeviceClipped(), |
121 this.contentCanvas_, this.viewport_.getImageClipped()); | 124 this.contentCanvas_, this.viewport_.getImageClipped()); |
122 ImageUtil.trace.reportTimer('paint'); | 125 ImageUtil.trace.reportTimer('paint'); |
123 } | 126 } |
124 }; | 127 }; |
125 | 128 |
126 /** | 129 /** |
127 * @param {number} x X pointer position. | 130 * @override |
128 * @param {number} y Y pointer position. | |
129 * @param {boolean} mouseDown True if mouse is down. | |
130 * @return {string} CSS cursor style. | |
131 */ | 131 */ |
132 ImageView.prototype.getCursorStyle = function(x, y, mouseDown) { | 132 ImageView.prototype.getCursorStyle = function(x, y, mouseDown) { |
133 // Indicate that the image is draggable. | 133 // Indicate that the image is draggable. |
134 if (this.viewport_.isClipped() && | 134 if (this.viewport_.isClipped() && |
135 this.viewport_.getScreenClipped().inside(x, y)) | 135 this.viewport_.getScreenClipped().inside(x, y)) |
136 return 'move'; | 136 return 'move'; |
137 | 137 |
138 return null; | 138 return null; |
139 }; | 139 }; |
140 | 140 |
141 /** | 141 /** |
142 * @param {number} x X pointer position. | 142 * @override |
143 * @param {number} y Y pointer position. | |
144 * @return {function} The closure to call on drag. | |
145 */ | 143 */ |
146 ImageView.prototype.getDragHandler = function(x, y) { | 144 ImageView.prototype.getDragHandler = function(x, y) { |
147 var cursor = this.getCursorStyle(x, y); | 145 var cursor = this.getCursorStyle(x, y); |
148 if (cursor === 'move') { | 146 if (cursor === 'move') { |
149 // Return the handler that drags the entire image. | 147 // Return the handler that drags the entire image. |
150 return this.viewport_.createOffsetSetter(x, y); | 148 return this.viewport_.createOffsetSetter(x, y); |
151 } | 149 } |
152 | 150 |
153 return null; | 151 return null; |
154 }; | 152 }; |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 }; | 977 }; |
980 | 978 |
981 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; | 979 ImageView.Effect.Rotate.prototype = { __proto__: ImageView.Effect.prototype }; |
982 | 980 |
983 /** | 981 /** |
984 * @override | 982 * @override |
985 */ | 983 */ |
986 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { | 984 ImageView.Effect.Rotate.prototype.transform = function(element, viewport) { |
987 return viewport.getInverseTransformForRotatedImage(this.orientation_); | 985 return viewport.getInverseTransformForRotatedImage(this.orientation_); |
988 }; | 986 }; |
OLD | NEW |