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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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}.
11 * @param {!print_preview.AppState} appState App state used to persist custom 11 * @param {!print_preview.AppState} appState App state used to persist custom
12 * margins. 12 * margins.
13 * @param {!print_preview.DocumentInfo} documentInfo Information about the 13 * @param {!print_preview.DocumentInfo} documentInfo Information about the
14 * document to print. 14 * document to print.
15 * @constructor 15 * @constructor
16 * @extends {print_preview.ticket_items.TicketItem} 16 * @extends {print_preview.ticket_items.TicketItem}
17 */ 17 */
18 function CustomMargins(appState, documentInfo) { 18 function CustomMargins(appState, documentInfo) {
19 print_preview.ticket_items.TicketItem.call( 19 print_preview.ticket_items.TicketItem.call(
20 this, 20 this, appState, print_preview.AppState.Field.CUSTOM_MARGINS,
21 appState, 21 null /*destinationStore*/, documentInfo);
22 print_preview.AppState.Field.CUSTOM_MARGINS,
23 null /*destinationStore*/,
24 documentInfo);
25 }; 22 };
26 23
27 /** 24 /**
28 * Enumeration of the orientations of margins. 25 * Enumeration of the orientations of margins.
29 * @enum {string} 26 * @enum {string}
30 */ 27 */
31 CustomMargins.Orientation = { 28 CustomMargins.Orientation =
32 TOP: 'top', 29 {TOP: 'top', RIGHT: 'right', BOTTOM: 'bottom', LEFT: 'left'};
33 RIGHT: 'right',
34 BOTTOM: 'bottom',
35 LEFT: 'left'
36 };
37 30
38 /** 31 /**
39 * Mapping of a margin orientation to its opposite. 32 * Mapping of a margin orientation to its opposite.
40 * @type {!Object<!print_preview.ticket_items.CustomMargins.Orientation, 33 * @type {!Object<!print_preview.ticket_items.CustomMargins.Orientation,
41 * !print_preview.ticket_items.CustomMargins.Orientation>} 34 * !print_preview.ticket_items.CustomMargins.Orientation>}
42 * @private 35 * @private
43 */ 36 */
44 CustomMargins.OppositeOrientation_ = {}; 37 CustomMargins.OppositeOrientation_ = {};
45 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.TOP] = 38 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.TOP] =
46 CustomMargins.Orientation.BOTTOM; 39 CustomMargins.Orientation.BOTTOM;
47 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.RIGHT] = 40 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.RIGHT] =
48 CustomMargins.Orientation.LEFT; 41 CustomMargins.Orientation.LEFT;
49 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.BOTTOM] = 42 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.BOTTOM] =
50 CustomMargins.Orientation.TOP; 43 CustomMargins.Orientation.TOP;
51 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.LEFT] = 44 CustomMargins.OppositeOrientation_[CustomMargins.Orientation.LEFT] =
52 CustomMargins.Orientation.RIGHT; 45 CustomMargins.Orientation.RIGHT;
53 46
54 /** 47 /**
55 * Minimum distance in points that two margins can be separated by. 48 * Minimum distance in points that two margins can be separated by.
56 * @type {number} 49 * @type {number}
57 * @const 50 * @const
58 * @private 51 * @private
59 */ 52 */
60 CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch. 53 CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch.
61 54
62 CustomMargins.prototype = { 55 CustomMargins.prototype = {
63 __proto__: print_preview.ticket_items.TicketItem.prototype, 56 __proto__: print_preview.ticket_items.TicketItem.prototype,
64 57
65 /** @override */ 58 /** @override */
66 wouldValueBeValid: function(value) { 59 wouldValueBeValid: function(value) {
67 var margins = /** @type {!print_preview.Margins} */ (value); 60 var margins = /** @type {!print_preview.Margins} */ (value);
68 for (var key in CustomMargins.Orientation) { 61 for (var key in CustomMargins.Orientation) {
69 var o = CustomMargins.Orientation[key]; 62 var o = CustomMargins.Orientation[key];
70 var max = this.getMarginMax_( 63 var max = this.getMarginMax_(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation]; 116 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation];
124 var max = 117 var max =
125 this.getMarginMax_(orientation, margins.get(oppositeOrientation)); 118 this.getMarginMax_(orientation, margins.get(oppositeOrientation));
126 value = Math.max(0, Math.min(max, value)); 119 value = Math.max(0, Math.min(max, value));
127 this.updateValue(margins.set(orientation, value)); 120 this.updateValue(margins.set(orientation, value));
128 }, 121 },
129 122
130 /** @override */ 123 /** @override */
131 getDefaultValueInternal: function() { 124 getDefaultValueInternal: function() {
132 return this.getDocumentInfoInternal().margins || 125 return this.getDocumentInfoInternal().margins ||
133 new print_preview.Margins(72, 72, 72, 72); 126 new print_preview.Margins(72, 72, 72, 72);
134 }, 127 },
135 128
136 /** @override */ 129 /** @override */
137 getCapabilityNotAvailableValueInternal: function() { 130 getCapabilityNotAvailableValueInternal: function() {
138 return this.getDocumentInfoInternal().margins || 131 return this.getDocumentInfoInternal().margins ||
139 new print_preview.Margins(72, 72, 72, 72); 132 new print_preview.Margins(72, 72, 72, 72);
140 }, 133 },
141 134
142 /** 135 /**
143 * @param {!print_preview.ticket_items.CustomMargins.Orientation} 136 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
144 * orientation Specifies which margin to get the maximum value of. 137 * orientation Specifies which margin to get the maximum value of.
145 * @param {number} oppositeMargin Value of the margin in points 138 * @param {number} oppositeMargin Value of the margin in points
146 * opposite the specified margin. 139 * opposite the specified margin.
147 * @return {number} Maximum value in points of the specified margin. 140 * @return {number} Maximum value in points of the specified margin.
148 * @private 141 * @private
149 */ 142 */
150 getMarginMax_: function(orientation, oppositeMargin) { 143 getMarginMax_: function(orientation, oppositeMargin) {
151 var max; 144 var max;
152 if (orientation == CustomMargins.Orientation.TOP || 145 if (orientation == CustomMargins.Orientation.TOP ||
153 orientation == CustomMargins.Orientation.BOTTOM) { 146 orientation == CustomMargins.Orientation.BOTTOM) {
154 max = this.getDocumentInfoInternal().pageSize.height - oppositeMargin - 147 max = this.getDocumentInfoInternal().pageSize.height - oppositeMargin -
155 CustomMargins.MINIMUM_MARGINS_DISTANCE_; 148 CustomMargins.MINIMUM_MARGINS_DISTANCE_;
156 } else { 149 } else {
157 max = this.getDocumentInfoInternal().pageSize.width - oppositeMargin - 150 max = this.getDocumentInfoInternal().pageSize.width - oppositeMargin -
158 CustomMargins.MINIMUM_MARGINS_DISTANCE_; 151 CustomMargins.MINIMUM_MARGINS_DISTANCE_;
159 } 152 }
160 return Math.round(max); 153 return Math.round(max);
161 } 154 }
162 }; 155 };
163 156
164 // Export 157 // Export
165 return { 158 return {CustomMargins: CustomMargins};
166 CustomMargins: CustomMargins
167 };
168 }); 159 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698