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

Side by Side Diff: chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Set --bary flag Created 8 years, 6 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
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 cr.define('print_preview.ticket_items', function() { 5 cr.define('print_preview.ticket_items', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Custom page margins ticket item whose value is a 9 * Custom page margins ticket item whose value is a
10 * {@code print_preview.Margins}. 10 * {@code print_preview.Margins}.
(...skipping 28 matching lines...) Expand all
39 */ 39 */
40 CustomMargins.Orientation = { 40 CustomMargins.Orientation = {
41 TOP: 'top', 41 TOP: 'top',
42 RIGHT: 'right', 42 RIGHT: 'right',
43 BOTTOM: 'bottom', 43 BOTTOM: 'bottom',
44 LEFT: 'left' 44 LEFT: 'left'
45 }; 45 };
46 46
47 /** 47 /**
48 * Mapping of a margin orientation to its opposite. 48 * Mapping of a margin orientation to its opposite.
49 * @type {object.<CustomMargins.Orientation, CustomMargins.Orientation>} 49 * @type {!Object.<!CustomMargins.Orientation, !CustomMargins.Orientation>}
50 * @private 50 * @private
51 */ 51 */
52 CustomMargins.OppositeOrientation_ = {}; 52 CustomMargins.OppositeOrientation_ = {};
53 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.TOP] = 53 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.TOP] =
54 CustomMargins.Orientation.BOTTOM; 54 CustomMargins.Orientation.BOTTOM;
55 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.RIGHT] = 55 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.RIGHT] =
56 CustomMargins.Orientation.LEFT; 56 CustomMargins.Orientation.LEFT;
57 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.BOTTOM] = 57 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.BOTTOM] =
58 CustomMargins.Orientation.TOP; 58 CustomMargins.Orientation.TOP;
59 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.LEFT] = 59 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.LEFT] =
(...skipping 23 matching lines...) Expand all
83 } 83 }
84 return true; 84 return true;
85 }, 85 },
86 86
87 /** @override */ 87 /** @override */
88 isCapabilityAvailable: function() { 88 isCapabilityAvailable: function() {
89 return this.documentInfo_.isModifiable; 89 return this.documentInfo_.isModifiable;
90 }, 90 },
91 91
92 /** 92 /**
93 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation 93 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
94 * Specifies the margin to get the maximum value for. 94 * orientation Specifies the margin to get the maximum value for.
95 * @return {number} Maximum value in points of the specified margin. 95 * @return {number} Maximum value in points of the specified margin.
96 */ 96 */
97 getMarginMax: function(orientation) { 97 getMarginMax: function(orientation) {
98 var oppositeOrient = CustomMargins.OppositeOrientation_[orientation]; 98 var oppositeOrient = CustomMargins.OppositeOrientation_[orientation];
99 var margins = /** @type {!print_preview.Margins} */ (this.getValue()); 99 var margins = /** @type {!print_preview.Margins} */ (this.getValue());
100 return this.getMarginMax_(orientation, margins.get(oppositeOrient)); 100 return this.getMarginMax_(orientation, margins.get(oppositeOrient));
101 }, 101 },
102 102
103 /** @override */ 103 /** @override */
104 updateValue: function(value) { 104 updateValue: function(value) {
105 var margins = /** @type {!InputMargins} */ (value); 105 var margins = /** @type {!InputMargins} */ (value);
106 if (margins != null) { 106 if (margins != null) {
107 margins = new print_preview.Margins( 107 margins = new print_preview.Margins(
108 Math.round(margins.get(CustomMargins.Orientation.TOP)), 108 Math.round(margins.get(CustomMargins.Orientation.TOP)),
109 Math.round(margins.get(CustomMargins.Orientation.RIGHT)), 109 Math.round(margins.get(CustomMargins.Orientation.RIGHT)),
110 Math.round(margins.get(CustomMargins.Orientation.BOTTOM)), 110 Math.round(margins.get(CustomMargins.Orientation.BOTTOM)),
111 Math.round(margins.get(CustomMargins.Orientation.LEFT))); 111 Math.round(margins.get(CustomMargins.Orientation.LEFT)));
112 } 112 }
113 print_preview.ticket_items.TicketItem.prototype.updateValue.call( 113 print_preview.ticket_items.TicketItem.prototype.updateValue.call(
114 this, margins); 114 this, margins);
115 }, 115 },
116 116
117 /** 117 /**
118 * Updates the specified margin in points while keeping the value within 118 * Updates the specified margin in points while keeping the value within
119 * a maximum and minimum. 119 * a maximum and minimum.
120 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation 120 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
121 * Specifies the margin to update. 121 * orientation Specifies the margin to update.
122 * @param {number} value Updated margin value in points. 122 * @param {number} value Updated margin value in points.
123 */ 123 */
124 updateMargin: function(orientation, value) { 124 updateMargin: function(orientation, value) {
125 var margins = /** @type {!print_preview.Margins} */ (this.getValue()); 125 var margins = /** @type {!print_preview.Margins} */ (this.getValue());
126 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation]; 126 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation];
127 var max = 127 var max =
128 this.getMarginMax_(orientation, margins.get(oppositeOrientation)); 128 this.getMarginMax_(orientation, margins.get(oppositeOrientation));
129 value = Math.max(0, Math.min(max, value)); 129 value = Math.max(0, Math.min(max, value));
130 this.updateValue(margins.set(orientation, value)); 130 this.updateValue(margins.set(orientation, value));
131 }, 131 },
132 132
133 /** @override */ 133 /** @override */
134 getDefaultValueInternal: function() { 134 getDefaultValueInternal: function() {
135 return this.documentInfo_.margins || 135 return this.documentInfo_.margins ||
136 new print_preview.Margins(72, 72, 72, 72); 136 new print_preview.Margins(72, 72, 72, 72);
137 }, 137 },
138 138
139 /** @override */ 139 /** @override */
140 getCapabilityNotAvailableValueInternal: function() { 140 getCapabilityNotAvailableValueInternal: function() {
141 return this.documentInfo_.margins || 141 return this.documentInfo_.margins ||
142 new print_preview.Margins(72, 72, 72, 72); 142 new print_preview.Margins(72, 72, 72, 72);
143 }, 143 },
144 144
145 /** 145 /**
146 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation 146 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
147 * Specifies which margin to get the maximum value of. 147 * orientation Specifies which margin to get the maximum value of.
148 * @param {number} oppositeMargin Value of the margin in points 148 * @param {number} oppositeMargin Value of the margin in points
149 * opposite the specified margin. 149 * opposite the specified margin.
150 * @return {number} Maximum value in points of the specified margin. 150 * @return {number} Maximum value in points of the specified margin.
151 * @private 151 * @private
152 */ 152 */
153 getMarginMax_: function(orientation, oppositeMargin) { 153 getMarginMax_: function(orientation, oppositeMargin) {
154 var max; 154 var max;
155 if (orientation == CustomMargins.Orientation.TOP || 155 if (orientation == CustomMargins.Orientation.TOP ||
156 orientation == CustomMargins.Orientation.BOTTOM) { 156 orientation == CustomMargins.Orientation.BOTTOM) {
157 max = this.documentInfo_.pageSize.height - oppositeMargin - 157 max = this.documentInfo_.pageSize.height - oppositeMargin -
158 CustomMargins.MINIMUM_MARGINS_DISTANCE_; 158 CustomMargins.MINIMUM_MARGINS_DISTANCE_;
159 } else { 159 } else {
160 max = this.documentInfo_.pageSize.width - oppositeMargin - 160 max = this.documentInfo_.pageSize.width - oppositeMargin -
161 CustomMargins.MINIMUM_MARGINS_DISTANCE_; 161 CustomMargins.MINIMUM_MARGINS_DISTANCE_;
162 } 162 }
163 return Math.round(max); 163 return Math.round(max);
164 } 164 }
165 }; 165 };
166 166
167 // Export 167 // Export
168 return { 168 return {
169 CustomMargins: CustomMargins 169 CustomMargins: CustomMargins
170 }; 170 };
171 }); 171 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698