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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Draggable control for setting a page margin. | 9 * Draggable control for setting a page margin. |
10 * @param {!print_preview.ticket_items.CustomMargins.Orientation} orientation | 10 * @param {!print_preview.ticket_items.CustomMarginsOrientation} orientation |
11 * Orientation of the margin control that determines where the margin | 11 * Orientation of the margin control that determines where the margin |
12 * textbox will be placed. | 12 * textbox will be placed. |
13 * @constructor | 13 * @constructor |
14 * @extends {print_preview.Component} | 14 * @extends {print_preview.Component} |
15 */ | 15 */ |
16 function MarginControl(orientation) { | 16 function MarginControl(orientation) { |
17 print_preview.Component.call(this); | 17 print_preview.Component.call(this); |
18 | 18 |
19 /** | 19 /** |
20 * Determines where the margin textbox will be placed. | 20 * Determines where the margin textbox will be placed. |
21 * @type {!print_preview.ticket_items.CustomMargins.Orientation} | 21 * @type {!print_preview.ticket_items.CustomMarginsOrientation} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.orientation_ = orientation; | 24 this.orientation_ = orientation; |
25 | 25 |
26 /** | 26 /** |
27 * Position of the margin control in points. | 27 * Position of the margin control in points. |
28 * @type {number} | 28 * @type {number} |
29 * @private | 29 * @private |
30 */ | 30 */ |
31 this.positionInPts_ = 0; | 31 this.positionInPts_ = 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 MarginControl.prototype = { | 144 MarginControl.prototype = { |
145 __proto__: print_preview.Component.prototype, | 145 __proto__: print_preview.Component.prototype, |
146 | 146 |
147 /** @return {boolean} Whether this margin control is in focus. */ | 147 /** @return {boolean} Whether this margin control is in focus. */ |
148 getIsFocused: function() { | 148 getIsFocused: function() { |
149 return this.isFocused_; | 149 return this.isFocused_; |
150 }, | 150 }, |
151 | 151 |
152 /** | 152 /** |
153 * @return {!print_preview.ticket_items.CustomMargins.Orientation} | 153 * @return {!print_preview.ticket_items.CustomMarginsOrientation} |
154 * Orientation of the margin control. | 154 * Orientation of the margin control. |
155 */ | 155 */ |
156 getOrientation: function() { | 156 getOrientation: function() { |
157 return this.orientation_; | 157 return this.orientation_; |
158 }, | 158 }, |
159 | 159 |
160 /** | 160 /** |
161 * @param {number} scaleTransform New scale transform of the margin control. | 161 * @param {number} scaleTransform New scale transform of the margin control. |
162 */ | 162 */ |
163 setScaleTransform: function(scaleTransform) { | 163 setScaleTransform: function(scaleTransform) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 getPositionInPts: function() { | 213 getPositionInPts: function() { |
214 return this.positionInPts_; | 214 return this.positionInPts_; |
215 }, | 215 }, |
216 | 216 |
217 /** | 217 /** |
218 * @param {number} posInPts New position of the margin control in points. | 218 * @param {number} posInPts New position of the margin control in points. |
219 */ | 219 */ |
220 setPositionInPts: function(posInPts) { | 220 setPositionInPts: function(posInPts) { |
221 this.positionInPts_ = posInPts; | 221 this.positionInPts_ = posInPts; |
222 var orientationEnum = | 222 var orientationEnum = |
223 print_preview.ticket_items.CustomMargins.Orientation; | 223 print_preview.ticket_items.CustomMarginsOrientation; |
224 var x = this.translateTransform_.x; | 224 var x = this.translateTransform_.x; |
225 var y = this.translateTransform_.y; | 225 var y = this.translateTransform_.y; |
226 var width = null, height = null; | 226 var width = null, height = null; |
227 if (this.orientation_ == orientationEnum.TOP) { | 227 if (this.orientation_ == orientationEnum.TOP) { |
228 y = this.scaleTransform_ * posInPts + this.translateTransform_.y - | 228 y = this.scaleTransform_ * posInPts + this.translateTransform_.y - |
229 MarginControl.RADIUS_; | 229 MarginControl.RADIUS_; |
230 width = this.scaleTransform_ * this.pageSize_.width; | 230 width = this.scaleTransform_ * this.pageSize_.width; |
231 } else if (this.orientation_ == orientationEnum.RIGHT) { | 231 } else if (this.orientation_ == orientationEnum.RIGHT) { |
232 x = this.scaleTransform_ * (this.pageSize_.width - posInPts) + | 232 x = this.scaleTransform_ * (this.pageSize_.width - posInPts) + |
233 this.translateTransform_.x - MarginControl.RADIUS_; | 233 this.translateTransform_.x - MarginControl.RADIUS_; |
(...skipping 30 matching lines...) Expand all Loading... |
264 }, | 264 }, |
265 | 265 |
266 /** | 266 /** |
267 * Converts a value in pixels to points. | 267 * Converts a value in pixels to points. |
268 * @param {number} pixels Pixel value to convert. | 268 * @param {number} pixels Pixel value to convert. |
269 * @return {number} Given value expressed in points. | 269 * @return {number} Given value expressed in points. |
270 */ | 270 */ |
271 convertPixelsToPts: function(pixels) { | 271 convertPixelsToPts: function(pixels) { |
272 var pts; | 272 var pts; |
273 var orientationEnum = | 273 var orientationEnum = |
274 print_preview.ticket_items.CustomMargins.Orientation; | 274 print_preview.ticket_items.CustomMarginsOrientation; |
275 if (this.orientation_ == orientationEnum.TOP) { | 275 if (this.orientation_ == orientationEnum.TOP) { |
276 pts = pixels - this.translateTransform_.y + MarginControl.RADIUS_; | 276 pts = pixels - this.translateTransform_.y + MarginControl.RADIUS_; |
277 pts /= this.scaleTransform_; | 277 pts /= this.scaleTransform_; |
278 } else if (this.orientation_ == orientationEnum.RIGHT) { | 278 } else if (this.orientation_ == orientationEnum.RIGHT) { |
279 pts = pixels - this.translateTransform_.x + MarginControl.RADIUS_; | 279 pts = pixels - this.translateTransform_.x + MarginControl.RADIUS_; |
280 pts /= this.scaleTransform_; | 280 pts /= this.scaleTransform_; |
281 pts = this.pageSize_.width - pts; | 281 pts = this.pageSize_.width - pts; |
282 } else if (this.orientation_ == orientationEnum.BOTTOM) { | 282 } else if (this.orientation_ == orientationEnum.BOTTOM) { |
283 pts = pixels - this.translateTransform_.y + MarginControl.RADIUS_; | 283 pts = pixels - this.translateTransform_.y + MarginControl.RADIUS_; |
284 pts /= this.scaleTransform_; | 284 pts /= this.scaleTransform_; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 this.setIsFocused_(false); | 445 this.setIsFocused_(false); |
446 cr.dispatchSimpleEvent(this, MarginControl.EventType.TEXT_CHANGE); | 446 cr.dispatchSimpleEvent(this, MarginControl.EventType.TEXT_CHANGE); |
447 } | 447 } |
448 }; | 448 }; |
449 | 449 |
450 // Export | 450 // Export |
451 return { | 451 return { |
452 MarginControl: MarginControl | 452 MarginControl: MarginControl |
453 }; | 453 }; |
454 }); | 454 }); |
OLD | NEW |