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 function MarginsUI() { |
| 9 var marginsUI = document.createElement('div'); |
| 10 marginsUI.__proto__ = MarginsUI.prototype; |
| 11 marginsUI.id = 'customized-margins'; |
| 12 |
| 13 // @type {print_preview.MarginsUIPair} The object corresponding to the top |
| 14 // margin. |
| 15 marginsUI.topPair_ = new print_preview.MarginsUIPair( |
| 16 print_preview.MarginSettings.TOP_GROUP); |
| 17 // @type {print_preview.MarginsUIPair} The object corresponding to the left |
| 18 // margin. |
| 19 marginsUI.leftPair_ = new print_preview.MarginsUIPair( |
| 20 print_preview.MarginSettings.LEFT_GROUP); |
| 21 // @type {print_preview.MarginsUIPair} The object corresponding to the right |
| 22 // margin. |
| 23 marginsUI.rightPair_ = new print_preview.MarginsUIPair( |
| 24 print_preview.MarginSettings.RIGHT_GROUP); |
| 25 // @type {print_preview.MarginsUIPair} The object corresponding to the |
| 26 // bottom margin. |
| 27 marginsUI.bottomPair_ = new print_preview.MarginsUIPair( |
| 28 print_preview.MarginSettings.BOTTOM_GROUP); |
| 29 |
| 30 var uiPairs = marginsUI.pairsAsList; |
| 31 for (var i = 0; i < uiPairs.length; i++) |
| 32 marginsUI.appendChild(uiPairs[i]); |
| 33 |
| 34 // @type {print_preview.MarginsUIPair} The object that is being dragged. |
| 35 // null if no drag session is in progress. |
| 36 marginsUI.lastClickedMarginsUIPair = null; |
| 37 |
| 38 // @type {EventTracker} Used to keep track of certain event listeners. |
| 39 marginsUI.eventTracker_ = new EventTracker(); |
| 40 |
| 41 marginsUI.addEventListeners_(); |
| 42 return marginsUI; |
| 43 } |
| 44 |
8 /** | 45 /** |
9 * Creates a Margins object that holds four margin values. The units in which | 46 * @param {{x: number, y: number}} point The point with respect to the top |
10 * the values are expressed can be any numeric value. | 47 * left corner of the webpage. |
11 * @constructor | 48 * @return {{x: number, y: number}} The point with respect to the top left |
12 * @param {number} left The left margin. | 49 * corner of the plugin area. |
13 * @param {number} top The top margin. | |
14 * @param {number} right The right margin. | |
15 * @param {number} bottom The bottom margin. | |
16 */ | 50 */ |
17 function Margins(left, top, right, bottom) { | 51 MarginsUI.convert = function(point) { |
18 this[MarginSettings.LEFT_GROUP] = left; | 52 var mainview = $('mainview'); |
19 this[MarginSettings.TOP_GROUP] = top; | 53 return { x: point.x - mainview.offsetLeft, |
20 this[MarginSettings.RIGHT_GROUP] = right; | 54 y: point.y - mainview.offsetTop }; |
21 this[MarginSettings.BOTTOM_GROUP] = bottom; | |
22 } | 55 } |
23 | 56 |
24 /** | 57 MarginsUI.prototype = { |
25 * Rounds |value| keeping |precision| decimal numbers. Example: 32.76643 | 58 __proto__: HTMLDivElement.prototype, |
26 * becomes 32.77. | 59 |
27 * @param {number} value The number to round. | 60 /** |
28 * @param {number} precision The desired precision. | 61 * Adds an observer for |customEvents.MARGINS_MAY_HAVE_CHANGED| event. |
29 * @return {number} The rounded number. | 62 * @param {function} func A callback function to be called when |
30 */ | 63 * |customEvents.MARGINS_MAY_HAVE_CHANGED| event occurs. |
31 Margins.roundToPrecision = function(value, precision) { | 64 */ |
32 return Math.round(value * Math.pow(10, precision)) / | 65 addObserver: function(func) { |
33 Math.pow(10, precision); | 66 var uiPairs = this.pairsAsList; |
34 }; | 67 for (var i = 0; i < uiPairs.length; i++) { |
35 | 68 uiPairs[i].box_.addEventListener( |
36 Margins.prototype = { | 69 customEvents.MARGINS_MAY_HAVE_CHANGED, func); |
37 /** | 70 } |
38 * Checks if |rhs| is equal to |this|. | 71 }, |
39 * @param {Margins} rhs The Margins object to compare against. | 72 |
40 * @return {boolean} true if they are equal. | 73 /** |
41 */ | 74 * @return {array} An array including all |MarginUIPair| objects. |
42 isEqual: function(rhs) { | 75 */ |
43 if (!rhs) | 76 get pairsAsList() { |
44 return false; | 77 return [this.topPair_, this.leftPair_, this.rightPair_, this.bottomPair_]; |
45 return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] && | 78 }, |
46 this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] && | 79 |
47 this[MarginSettings.RIGHT_GROUP] === | 80 /** |
48 rhs[MarginSettings.RIGHT_GROUP] && | 81 * Updates the state of the margins UI. |
49 this[MarginSettings.BOTTOM_GROUP] === | 82 * @param {print_preview.Rect} marginsRectangle A rectangle describing the |
50 rhs[MarginSettings.BOTTOM_GROUP]; | 83 * four margins. |
51 }, | 84 * @param {Margins} marginValues The margin values in points. |
52 | 85 * @param {Array.<number>} valueLimits The maximum allowed margins for each |
53 clone: function() { | 86 * side in points. |
54 return new Margins(this[MarginSettings.LEFT_GROUP], | 87 * @param {boolean} keepDisplayedValue True if the currently displayed |
55 this[MarginSettings.TOP_GROUP], | 88 * margin values should not be updated. |
56 this[MarginSettings.RIGHT_GROUP], | 89 * @param {Array.<number>} valueLimitsInPercent The maximum allowed margins |
57 this[MarginSettings.BOTTOM_GROUP]); | 90 * for each side in percentages. |
58 }, | 91 */ |
59 | 92 update: function(marginsRectangle, marginValues, valueLimits, |
60 /** | 93 keepDisplayedValue, valueLimitsInPercent) { |
61 * Helper method returning an array of the string indices used for accessing | 94 var uiPairs = this.pairsAsList; |
62 * all margins. | 95 var order = ['top', 'left', 'right', 'bottom']; |
63 * @return {array} An array of string indices. | 96 for (var i = 0; i < uiPairs.length; i++) { |
| 97 uiPairs[i].update(marginsRectangle, |
| 98 marginValues[order[i]], |
| 99 valueLimits[i], |
| 100 keepDisplayedValue, |
| 101 valueLimitsInPercent[i]); |
| 102 } |
| 103 }, |
| 104 |
| 105 /** |
| 106 * Draws |this| based on the latest state. |
| 107 */ |
| 108 draw: function() { |
| 109 this.applyClippingMask_(); |
| 110 this.pairsAsList.forEach(function(pair) { pair.draw(); }); |
| 111 }, |
| 112 |
| 113 /** |
| 114 * Shows the margins UI. |
| 115 */ |
| 116 show: function() { |
| 117 this.hidden = false; |
| 118 this.classList.remove('invisible'); |
| 119 }, |
| 120 |
| 121 /** |
| 122 * Hides the margins UI and removes from the rendering flow if requested. |
| 123 * @param {boolean} removeFromFlow True if |this| should also be removed |
| 124 * from the rendering flow (in order to not interfere with the tab |
| 125 * order). |
| 126 */ |
| 127 hide: function(removeFromFlow) { |
| 128 removeFromFlow ? this.hidden = true : this.classList.add('invisible'); |
| 129 }, |
| 130 |
| 131 /** |
| 132 * Applies a clipping mask on |this| so that it does not paint on top of the |
| 133 * scrollbars (if any). |
| 134 */ |
| 135 applyClippingMask_: function() { |
| 136 var bottom = previewArea.height; |
| 137 var right = previewArea.width; |
| 138 this.style.clip = 'rect(0, ' + right + 'px, ' + bottom + 'px, 0)'; |
| 139 }, |
| 140 |
| 141 /** |
| 142 * Adds event listeners for various events. |
64 * @private | 143 * @private |
65 */ | 144 */ |
66 indicesAsArray_: function() { | 145 addEventListeners_: function() { |
67 return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP, | 146 var uiPairs = this.pairsAsList; |
68 MarginSettings.RIGHT_GROUP, MarginSettings.BOTTOM_GROUP]; | 147 for (var i = 0; i < uiPairs.length; i++) { |
69 }, | 148 uiPairs[i].addEventListener(customEvents.MARGIN_LINE_MOUSE_DOWN, |
70 | 149 this.onMarginLineMouseDown.bind(this)); |
71 /** | |
72 * Rounds |this| based on the precision used when displaying the margins in | |
73 * the user's prefered units. This is done by converting from points to | |
74 * those units (mm/inches) and back to points. | |
75 */ | |
76 roundToLocaleUnits: function() { | |
77 var indicesAsArray = this.indicesAsArray_(); | |
78 for (var i = 0; i < indicesAsArray.length; i++) { | |
79 this[indicesAsArray[i]] = | |
80 print_preview.convertPointsToLocaleUnitsAndBack( | |
81 this[indicesAsArray[i]]); | |
82 } | 150 } |
83 } | 151 // After snapping to min/max the MarginUIPair might not receive the |
84 }; | 152 // mouseup event since it is not under the mouse pointer, so it is handled |
85 | 153 // here. |
86 /** | 154 window.document.addEventListener('mouseup', |
87 * @constructor | 155 this.onMarginLineMouseUp.bind(this)); |
88 * Class describing the layout of the page. | 156 }, |
89 */ | 157 |
90 function PageLayout(width, height, left, top, right, bottom) { | 158 /** |
91 this.contentWidth_ = width; | 159 * Executes when a "MarginLineMouseDown" event occurs. |
92 this.contentHeight_ = height; | 160 * @param {cr.Event} e The event that triggered this listener. |
93 this.margins_ = new Margins(left, top, right, bottom); | 161 */ |
94 this.margins_.roundToLocaleUnits(); | 162 onMarginLineMouseDown: function(e) { |
95 } | 163 this.lastClickedMarginsUIPair = e.target; |
96 | 164 this.bringToFront(this.lastClickedMarginsUIPair); |
97 PageLayout.prototype = { | 165 // Note: Capturing mouse events at a higher level in the DOM than |this|, |
98 /** | 166 // so that the plugin can still receive mouse events. |
99 * @type {number} The width of the page. | 167 this.eventTracker_.add( |
100 */ | 168 window.document, 'mousemove', this.onMouseMove_.bind(this), false); |
101 get pageWidth() { | 169 }, |
102 return this.margins_.left + this.margins_.right + this.contentWidth_; | 170 |
103 }, | 171 /** |
104 | 172 * Executes when a "MarginLineMouseUp" event occurs. |
105 /** | 173 * @param {cr.Event} e The event that triggered this listener. |
106 * @type {number} The height of the page. | 174 */ |
107 */ | 175 onMarginLineMouseUp: function(e) { |
108 get pageHeight() { | 176 if (this.lastClickedMarginsUIPair == null) |
109 return this.margins_.top + this.margins_.bottom + this.contentHeight_; | |
110 } | |
111 }; | |
112 | |
113 /** | |
114 * Creates a MarginSettings object. This object encapsulates all settings and | |
115 * logic related to the margins mode. | |
116 * @constructor | |
117 */ | |
118 function MarginSettings() { | |
119 this.marginsOption_ = $('margins-option'); | |
120 this.marginList_ = $('margin-list'); | |
121 this.marginsUI_ = null; | |
122 | |
123 // Holds the custom margin values in points (if set). | |
124 this.customMargins_ = null; | |
125 // Holds the previous custom margin values in points. | |
126 this.previousCustomMargins_ = null; | |
127 // Holds the width of the page in points. | |
128 this.pageWidth_ = -1; | |
129 // Holds the height of the page in points. | |
130 this.pageHeight_ = -1; | |
131 // @type {boolean} True if the margins UI should be diplayed when the next | |
132 // |customEvents.PDF_LOADED| event occurs. | |
133 this.forceMarginsUIOnPDFLoad_ = false; | |
134 // Holds the currently updated default page layout values. | |
135 this.currentDefaultPageLayout = null; | |
136 | |
137 // True if the margins UI should be shown regardless of mouse position. | |
138 this.forceDisplayingMarginLines_ = true; | |
139 | |
140 // @type {EventTracker} Used to keep track of certain event listeners. | |
141 this.eventTracker_ = new EventTracker(); | |
142 | |
143 this.addEventListeners_(); | |
144 } | |
145 | |
146 // Number of points per inch. | |
147 MarginSettings.POINTS_PER_INCH = 72; | |
148 // Minimum allowed distance in points between top-bottom, left-right margins. | |
149 MarginSettings.MINIMUM_MARGINS_DISTANCE = 36; | |
150 // Margin list values. Matches enum MarginType in | |
151 // printing/print_job_constants.h. | |
152 MarginSettings.MARGINS_VALUE_DEFAULT = 0; | |
153 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; | |
154 MarginSettings.MARGINS_VALUE_MINIMUM = 2; | |
155 MarginSettings.MARGINS_VALUE_CUSTOM = 3; | |
156 // Default Margins option index. | |
157 MarginSettings.OPTION_INDEX_DEFAULT = 0; | |
158 // Group name corresponding to the top margin. | |
159 MarginSettings.TOP_GROUP = 'top'; | |
160 // Group name corresponding to the left margin. | |
161 MarginSettings.LEFT_GROUP = 'left'; | |
162 // Group name corresponding to the right margin. | |
163 MarginSettings.RIGHT_GROUP = 'right'; | |
164 // Group name corresponding to the bottom margin. | |
165 MarginSettings.BOTTOM_GROUP = 'bottom'; | |
166 | |
167 /** | |
168 * Extracts the number formatting and measurement system for the current | |
169 * locale. | |
170 * @param {string} numberFormat Is the formatted version of a sample number | |
171 * sent from the backend. | |
172 * @param {number} measurementSystem 0 for SI (aka metric system), 1 for the | |
173 * system used in the US. Note: Mathces UMeasurementSystem enum in | |
174 * third_party/icu/public/i18n/unicode/ulocdata.h. | |
175 */ | |
176 MarginSettings.setNumberFormatAndMeasurementSystem = function( | |
177 numberFormat, measurementSystem) { | |
178 var symbols = parseNumberFormat(numberFormat); | |
179 MarginSettings.thousandsPoint = symbols[0]; | |
180 MarginSettings.decimalPoint = symbols[1]; | |
181 MarginSettings.useMetricSystem = measurementSystem == 0; | |
182 }; | |
183 | |
184 cr.addSingletonGetter(MarginSettings); | |
185 | |
186 MarginSettings.prototype = { | |
187 /** | |
188 * Returns a dictionary containing the four custom margin values. | |
189 * @return {{marginLeft: number, marginTop: number, marginRight: number, | |
190 * marginBottom: number}} The dictionary. | |
191 */ | |
192 get customMargins() { | |
193 var margins = {}; | |
194 margins.marginLeft = this.customMargins_.left; | |
195 margins.marginTop = this.customMargins_.top; | |
196 margins.marginRight = this.customMargins_.right; | |
197 margins.marginBottom = this.customMargins_.bottom; | |
198 return margins; | |
199 }, | |
200 | |
201 /** | |
202 * Sets |this.customMargins_| according to |margins|. | |
203 * @param {{marginLeft: number, marginTop: number, marginRight: number, | |
204 * marginBottom: number}} margins An object holding the four margin | |
205 * values. | |
206 */ | |
207 set customMargins(margins) { | |
208 this.customMargins_.left = margins.marginLeft; | |
209 this.customMargins_.top = margins.marginTop; | |
210 this.customMargins_.right = margins.marginRight; | |
211 this.customMargins_.bottom = margins.marginBottom; | |
212 }, | |
213 | |
214 /** | |
215 * @return {number} The value of the selected margin option. | |
216 */ | |
217 get selectedMarginsValue() { | |
218 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | |
219 return parseInt(val, 10); | |
220 }, | |
221 | |
222 /** | |
223 * Sets the current margin selection to |lastUsedMarginType|. | |
224 * @param {number} lastUsedMarginType An integer value identifying a margin | |
225 * type according to MarginType enum in printing/print_job_constants.h. | |
226 * @param {Object} lastUsedCustomMargins The last used custom margins. If | |
227 * custom margins have not been used before | |
228 * |margin{Top|Bottom|Left|Right}| attributes are missing. | |
229 */ | |
230 setLastUsedMargins: function(lastUsedMarginsSettings) { | |
231 var lastUsedMarginsType = lastUsedMarginsSettings['marginsType']; | |
232 this.forceMarginsUIOnPDFLoad_ = | |
233 lastUsedMarginsType == MarginSettings.MARGINS_VALUE_CUSTOM; | |
234 this.marginList_.selectedIndex = | |
235 this.getMarginOptionIndexByValue_(lastUsedMarginsType); | |
236 if (lastUsedMarginsSettings.hasOwnProperty('marginTop') && | |
237 lastUsedMarginsSettings.hasOwnProperty('marginBottom') && | |
238 lastUsedMarginsSettings.hasOwnProperty('marginRight') && | |
239 lastUsedMarginsSettings.hasOwnProperty('marginLeft')) { | |
240 this.customMargins_ = new Margins(-1, -1, -1 , -1); | |
241 this.customMargins = lastUsedMarginsSettings; | |
242 } | |
243 }, | |
244 | |
245 /** | |
246 * @return {number} The total width of the plugin in points. | |
247 */ | |
248 get totalWidthInPoints() { | |
249 var pageInformation = previewArea.pageLocationNormalized; | |
250 return this.pageWidth_ / pageInformation.width; | |
251 }, | |
252 | |
253 /** | |
254 * @return {number} The total height of the plugin in points. | |
255 */ | |
256 get totalHeightInPoints() { | |
257 var pageInformation = previewArea.pageLocationNormalized; | |
258 return this.pageHeight_ / pageInformation.height; | |
259 }, | |
260 | |
261 /** | |
262 * Maps margin type values to indices within |this.marginList_|. | |
263 * @param {number} marginTypeValue An integer value identifying a margin | |
264 * type according to MarginType enum in printing/print_job_constants.h. | |
265 * @return {number} The index within |this.marginList_| that corrsponds to | |
266 * |marginTypeValue|. | |
267 * @private | |
268 */ | |
269 getMarginOptionIndexByValue_: function(marginTypeValue) { | |
270 var options = this.marginList_.options; | |
271 for (var i = 0; i < options.length; i++) { | |
272 if (options[i].getAttribute('value') == marginTypeValue) | |
273 return i; | |
274 } | |
275 return MarginSettings.OPTION_INDEX_DEFAULT; | |
276 }, | |
277 | |
278 /** | |
279 * @return {boolean} True if default margins are selected. | |
280 */ | |
281 isDefaultMarginsSelected: function() { | |
282 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; | |
283 }, | |
284 | |
285 /** | |
286 * @return {boolean} True if no margins are selected. | |
287 */ | |
288 isNoMarginsSelected: function() { | |
289 return this.selectedMarginsValue == | |
290 MarginSettings.MARGINS_VALUE_NO_MARGINS; | |
291 }, | |
292 | |
293 /** | |
294 * @return {boolean} True if custom margins are selected. | |
295 */ | |
296 isCustomMarginsSelected: function() { | |
297 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_CUSTOM; | |
298 }, | |
299 | |
300 /** | |
301 * @return {boolean} True if minimum margins are selected. | |
302 */ | |
303 isMinimumMarginsSelected: function() { | |
304 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_MINIMUM; | |
305 }, | |
306 | |
307 /** | |
308 * If the custom margin values have changed then request a new preview based | |
309 * on the newly set margins. | |
310 * @private | |
311 */ | |
312 requestPreviewIfNeeded_: function() { | |
313 if (!this.areMarginSettingsValid()) | |
314 return; | 177 return; |
315 | 178 this.lastClickedMarginsUIPair.onMouseUp(); |
316 if (this.customMargins_.isEqual(this.previousCustomMargins_)) | 179 this.lastClickedMarginsUIPair = null; |
317 return; | 180 this.eventTracker_.remove(window.document, 'mousemove'); |
318 | 181 }, |
319 this.previousCustomMargins_ = this.customMargins_.clone(); | 182 |
320 setDefaultValuesAndRegeneratePreview(false); | 183 /** |
321 }, | 184 * Brings |uiPair| in front of the other pairs. Used to make sure that the |
322 | 185 * dragged pair is visible when overlapping with a not dragged pair. |
323 /** | 186 * @param {print_preview.MarginsUIPair} uiPair The pair to bring in front. |
| 187 */ |
| 188 bringToFront: function(uiPair) { |
| 189 this.pairsAsList.forEach(function(pair) { |
| 190 pair.classList.remove('dragging'); |
| 191 }); |
| 192 uiPair.classList.add('dragging'); |
| 193 }, |
| 194 |
| 195 /** |
| 196 * Executes when a mousemove event occurs. |
| 197 * @param {MouseEvent} e The event that triggered this listener. |
| 198 */ |
| 199 onMouseMove_: function(e) { |
| 200 var point = MarginsUI.convert({ x: e.x, y: e.y }); |
| 201 |
| 202 var dragEvent = new cr.Event(customEvents.MARGIN_LINE_DRAG); |
| 203 dragEvent.dragDelta = |
| 204 this.lastClickedMarginsUIPair.getDragDisplacementFrom(point); |
| 205 dragEvent.destinationPoint = point; |
| 206 this.dispatchEvent(dragEvent); |
| 207 }, |
| 208 |
| 209 /** |
324 * Listener executed when the mouse is over the sidebar. If the custom | 210 * Listener executed when the mouse is over the sidebar. If the custom |
325 * margin lines are displayed, then, it fades them out. | 211 * margin lines are displayed, then, it fades them out. |
326 * @private | 212 * @private |
327 */ | 213 */ |
328 onSidebarMouseOver_: function(e) { | 214 onSidebarMouseOver_: function(e) { |
329 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); | 215 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); |
330 $('navbar-container').onmouseover = null; | 216 $('navbar-container').onmouseover = null; |
331 if (!this.forceDisplayingMarginLines_) | 217 if (!this.forceDisplayingMarginLines_) |
332 this.marginsUI.hide(false); | 218 this.marginsUI.hide(false); |
333 }, | 219 }, |
334 | 220 |
335 /** | 221 /** |
336 * Listener executed when the mouse is over the main view. If the custom | 222 * Listener executed when the mouse is over the main view. If the custom |
337 * margin lines are hidden, then, it fades them in. | 223 * margin lines are hidden, then, it fades them in. |
338 * @private | 224 * @private |
339 */ | 225 */ |
340 onMainviewMouseOver_: function() { | 226 onMainviewMouseOver_: function() { |
341 $('mainview').onmouseover = null; | 227 $('mainview').onmouseover = null; |
342 $('navbar-container').onmouseover = this.onSidebarMouseOver_.bind(this); | 228 $('navbar-container').onmouseover = this.onSidebarMouseOver_.bind(this); |
343 this.forceDisplayingMarginLines_ = false; | 229 this.forceDisplayingMarginLines_ = false; |
344 this.marginsUI.show(); | 230 this.marginsUI.show(); |
345 }, | 231 }, |
346 | 232 |
347 /** | 233 /** |
348 * Adds listeners to all margin related controls. | |
349 * @private | |
350 */ | |
351 addEventListeners_: function() { | |
352 this.marginList_.onchange = this.onMarginsChanged_.bind(this); | |
353 document.addEventListener(customEvents.PDF_LOADED, | |
354 this.onPDFLoaded_.bind(this)); | |
355 document.addEventListener(customEvents.PDF_GENERATION_ERROR, | |
356 this.onPDFGenerationError_.bind(this)); | |
357 }, | |
358 | |
359 /** | |
360 * Executes when a |customEvents.PDF_GENERATION_ERROR| event occurs. | 234 * Executes when a |customEvents.PDF_GENERATION_ERROR| event occurs. |
361 * @private | 235 * @private |
362 */ | 236 */ |
363 onPDFGenerationError_: function() { | 237 onPDFGenerationError_: function() { |
364 if (this.isCustomMarginsSelected()) { | 238 if (this.isCustomMarginsSelected()) { |
365 this.removeCustomMarginEventListeners_(); | 239 this.removeCustomMarginEventListeners_(); |
366 this.marginsUI.hide(true); | 240 this.marginsUI.hide(true); |
367 } | 241 } |
368 }, | 242 }, |
369 | 243 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 /** | 280 /** |
407 * Calculates the maximum allowable value of the selected margin text for | 281 * Calculates the maximum allowable value of the selected margin text for |
408 * every margin. | 282 * every margin. |
409 * @return {array} The maximum allowable value in points in order top, left, | 283 * @return {array} The maximum allowable value in points in order top, left, |
410 * right, bottom. | 284 * right, bottom. |
411 * @private | 285 * @private |
412 */ | 286 */ |
413 getMarginValueLimits_: function() { | 287 getMarginValueLimits_: function() { |
414 var marginValueLimits = []; | 288 var marginValueLimits = []; |
415 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom - | 289 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom - |
416 MarginSettings.MINIMUM_MARGINS_DISTANCE; | 290 MarginSettings.MINIMUM_MARGINS_DISTANCE_; |
417 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right - | 291 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right - |
418 MarginSettings.MINIMUM_MARGINS_DISTANCE; | 292 MarginSettings.MINIMUM_MARGINS_DISTANCE_; |
419 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left - | 293 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left - |
420 MarginSettings.MINIMUM_MARGINS_DISTANCE; | 294 MarginSettings.MINIMUM_MARGINS_DISTANCE_; |
421 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top - | 295 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top - |
422 MarginSettings.MINIMUM_MARGINS_DISTANCE; | 296 MarginSettings.MINIMUM_MARGINS_DISTANCE_; |
423 | 297 |
424 for (var i = 0; i < marginValueLimits.length; i++) { | 298 for (var i = 0; i < marginValueLimits.length; i++) { |
425 marginValueLimits[i] = Math.max(marginValueLimits[i], 0); | 299 marginValueLimits[i] = Math.max(marginValueLimits[i], 0); |
426 marginValueLimits[i] = print_preview.convertPointsToLocaleUnitsAndBack( | 300 marginValueLimits[i] = print_preview.convertPointsToLocaleUnitsAndBack( |
427 marginValueLimits[i]); | 301 marginValueLimits[i]); |
428 } | 302 } |
429 return marginValueLimits; | 303 return marginValueLimits; |
430 }, | 304 }, |
431 | 305 |
432 /** | 306 /** |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 * accessibility. | 423 * accessibility. |
550 * @private | 424 * @private |
551 */ | 425 */ |
552 onMarginTextboxFocused_: function() { | 426 onMarginTextboxFocused_: function() { |
553 this.forceDisplayingMarginLines_ = true; | 427 this.forceDisplayingMarginLines_ = true; |
554 this.marginsUI.show(); | 428 this.marginsUI.show(); |
555 }, | 429 }, |
556 | 430 |
557 /** | 431 /** |
558 * Executes when user selects a different margin option, ie, | 432 * Executes when user selects a different margin option, ie, |
559 * |this.marginList_.selectedIndex| is changed. | 433 * |this.select_.selectedIndex| is changed. |
560 * @private | 434 * @private |
561 */ | 435 */ |
562 onMarginsChanged_: function() { | 436 onMarginsChanged_: function() { |
563 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || | 437 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || |
564 this.isNoMarginsSelected()) | 438 this.isNoMarginsSelected()) |
565 this.onDefaultMinimumNoMarginsSelected_(); | 439 this.onDefaultMinimumNoMarginsSelected_(); |
566 else if (this.isCustomMarginsSelected()) | 440 else if (this.isCustomMarginsSelected()) |
567 this.onCustomMarginsSelected_(); | 441 this.onCustomMarginsSelected_(); |
568 }, | 442 }, |
569 | 443 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 return marginsInPercent; | 524 return marginsInPercent; |
651 }, | 525 }, |
652 | 526 |
653 /** | 527 /** |
654 * If custom margins is the currently selected option then change to the | 528 * If custom margins is the currently selected option then change to the |
655 * default margins option. | 529 * default margins option. |
656 * @private | 530 * @private |
657 */ | 531 */ |
658 resetMarginsIfNeeded: function() { | 532 resetMarginsIfNeeded: function() { |
659 if (this.isCustomMarginsSelected()) { | 533 if (this.isCustomMarginsSelected()) { |
660 this.marginList_.options[ | 534 this.select_.options[ |
661 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; | 535 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
662 this.removeCustomMarginEventListeners_(); | 536 this.removeCustomMarginEventListeners_(); |
663 this.forceDisplayingMarginLines_ = true; | 537 this.forceDisplayingMarginLines_ = true; |
664 this.customMargins_ = null; | |
665 this.previousCustomMargins_ = null; | |
666 } | 538 } |
667 }, | 539 }, |
668 | 540 |
669 /** | 541 /** |
670 * Executes when a |customEvents.PDF_LOADED| event occurs. | 542 * Executes when a |customEvents.PDF_LOADED| event occurs. |
671 * @private | 543 * @private |
672 */ | 544 */ |
673 onPDFLoaded_: function() { | 545 onPDFLoaded_: function() { |
674 if (!previewModifiable) { | 546 if (!previewModifiable) { |
675 fadeOutOption(this.marginsOption_); | 547 fadeOutOption(this.marginsOption_); |
(...skipping 16 matching lines...) Expand all Loading... |
692 updatePageData_: function() { | 564 updatePageData_: function() { |
693 if (!this.customMargins_) | 565 if (!this.customMargins_) |
694 this.customMargins_ = this.currentDefaultPageLayout.margins_.clone(); | 566 this.customMargins_ = this.currentDefaultPageLayout.margins_.clone(); |
695 | 567 |
696 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; | 568 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; |
697 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; | 569 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; |
698 } | 570 } |
699 }; | 571 }; |
700 | 572 |
701 return { | 573 return { |
702 MarginSettings: MarginSettings, | 574 MarginsUI: MarginsUI |
703 PageLayout: PageLayout | |
704 }; | 575 }; |
705 }); | 576 }); |
OLD | NEW |