OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Creates a Margins object that holds four margin values in points. |
| 10 * @param {number} top The top margin in pts. |
| 11 * @param {number} right The right margin in pts. |
| 12 * @param {number} bottom The bottom margin in pts. |
| 13 * @param {number} left The left margin in pts. |
| 14 * @constructor |
| 15 */ |
| 16 function Margins(top, right, bottom, left) { |
| 17 /** |
| 18 * Backing store for the margin values in points. |
| 19 * @type {Object.< |
| 20 * print_preview.ticket_items.CustomMargins.Orientation, |
| 21 * number>} |
| 22 * @private |
| 23 */ |
| 24 this.value_ = {}; |
| 25 this.value_[print_preview.ticket_items.CustomMargins.Orientation.TOP] = top; |
| 26 this.value_[print_preview.ticket_items.CustomMargins.Orientation.RIGHT] = |
| 27 right; |
| 28 this.value_[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM] = |
| 29 bottom; |
| 30 this.value_[print_preview.ticket_items.CustomMargins.Orientation.LEFT] = |
| 31 left; |
| 32 }; |
| 33 |
| 34 Margins.prototype = { |
| 35 /** |
| 36 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 37 * Specifies the margin value to get. |
| 38 * @return {number} Value of the margin of the given orientation. |
| 39 */ |
| 40 get: function(orientation) { |
| 41 return this.value_[orientation]; |
| 42 }, |
| 43 |
| 44 /** |
| 45 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 46 * Specifies the opposite margin value to get. |
| 47 * @return {number} Value of the margin opposite to the given orientation. |
| 48 */ |
| 49 getOpposite: function(orientation) { |
| 50 var orientationEnum = |
| 51 print_preview.ticket_items.CustomMargins.Orientation; |
| 52 if (orientation == orientationEnum.TOP) { |
| 53 return this.get(orientationEnum.BOTTOM); |
| 54 } else if (orientation == orientationEnum.RIGHT) { |
| 55 return this.get(orientationEnum.LEFT); |
| 56 } else if (orientation == orientationEnum.BOTTOM) { |
| 57 return this.get(orientationEnum.TOP); |
| 58 } else { |
| 59 return this.get(orientationEnum.RIGHT); |
| 60 } |
| 61 }, |
| 62 |
| 63 /** |
| 64 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 65 * Specifies the margin to set. |
| 66 * @param {number} value Updated value of the margin in points to modify. |
| 67 * @return {!print_preview.Margins} A new copy of |this| with the |
| 68 * modification made to the specified margin. |
| 69 */ |
| 70 set: function(orientation, value) { |
| 71 var newValue = {}; |
| 72 for (var o in this.value_) { |
| 73 newValue[o] = this.value_[o]; |
| 74 } |
| 75 newValue[orientation] = value; |
| 76 return new Margins( |
| 77 newValue[print_preview.ticket_items.CustomMargins.Orientation.TOP], |
| 78 newValue[print_preview.ticket_items.CustomMargins.Orientation.RIGHT], |
| 79 newValue[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM], |
| 80 newValue[print_preview.ticket_items.CustomMargins.Orientation.LEFT]); |
| 81 }, |
| 82 |
| 83 /** |
| 84 * @param {print_preview.Margins} other The other margins object to compare |
| 85 * against. |
| 86 * @return {boolean} Whether this margins object is equal to another. |
| 87 */ |
| 88 equals: function(other) { |
| 89 if (other == null) { |
| 90 return false; |
| 91 } |
| 92 for (var orientation in this.value_) { |
| 93 if (this.value_[orientation] != other.value_[orientation]) { |
| 94 return false; |
| 95 } |
| 96 } |
| 97 return true; |
| 98 } |
| 99 }; |
| 100 |
| 101 // Export |
| 102 return { |
| 103 Margins: Margins |
| 104 }; |
| 105 }); |
OLD | NEW |