OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * Creates a Margins object that holds four margin values. The units in which | 9 * Creates a Margins object that holds four margin values. The units in which |
10 * the values are expressed can be any numeric value. | 10 * the values are expressed can be any numeric value. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * @param {Margins} rhs The Margins object values to be used. | 53 * @param {Margins} rhs The Margins object values to be used. |
54 */ | 54 */ |
55 copy: function(rhs) { | 55 copy: function(rhs) { |
56 this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP]; | 56 this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP]; |
57 this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP]; | 57 this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP]; |
58 this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP]; | 58 this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP]; |
59 this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP]; | 59 this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP]; |
60 }, | 60 }, |
61 | 61 |
62 /** | 62 /** |
| 63 * Helper method returning an array of the string indices used for accessing |
| 64 * all margins. |
| 65 * @return {array} An array of string indices. |
| 66 * @private |
| 67 */ |
| 68 indicesAsArray_: function() { |
| 69 return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP, |
| 70 MarginSettings.RIGHT_GROUP, MarginSettings.BOTTOM_GROUP]; |
| 71 }, |
| 72 |
| 73 /** |
| 74 * Rounds |this| based on the precision used when displaying the margins in |
| 75 * inches. This is done by converting from points to inches and back to |
| 76 * points. |
| 77 */ |
| 78 roundToInches: function() { |
| 79 var indicesAsArray = this.indicesAsArray_(); |
| 80 for (var i = 0; i < indicesAsArray.length; i++) { |
| 81 this[indicesAsArray[i]] = |
| 82 print_preview.convertPointsToInchesTextAndBack( |
| 83 this[indicesAsArray[i]]); |
| 84 } |
| 85 }, |
| 86 |
| 87 /** |
63 * Converts |this| to inches and returns the result in a new Margins object. | 88 * Converts |this| to inches and returns the result in a new Margins object. |
64 * |this| is not affected. It assumes that |this| is currently expressed in | 89 * |this| is not affected. It assumes that |this| is currently expressed in |
65 * points. | 90 * points. |
66 * @param {number} The number of decimal points to keep. | 91 * @param {number} The number of decimal points to keep. |
67 * @return {Margins} The equivalent of |this| in inches. | 92 * @return {Margins} The equivalent of |this| in inches. |
68 */ | 93 */ |
69 toInches: function(precision) { | 94 toInches: function(precision) { |
70 return new Margins( | 95 return new Margins( |
71 Margins.roundToPrecision(convertPointsToInches( | 96 Margins.roundToPrecision(convertPointsToInches( |
72 this[MarginSettings.LEFT_GROUP]), precision), | 97 this[MarginSettings.LEFT_GROUP]), precision), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 153 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
129 | 154 |
130 // Holds the currently updated default page layout values. | 155 // Holds the currently updated default page layout values. |
131 this.currentDefaultPageLayout = null; | 156 this.currentDefaultPageLayout = null; |
132 // Holds the default page layout values when the custom margins was last | 157 // Holds the default page layout values when the custom margins was last |
133 // selected. | 158 // selected. |
134 this.previousDefaultPageLayout_ = null; | 159 this.previousDefaultPageLayout_ = null; |
135 | 160 |
136 // True if the margins UI should be shown regardless of mouse position. | 161 // True if the margins UI should be shown regardless of mouse position. |
137 this.forceDisplayingMarginLines_ = true; | 162 this.forceDisplayingMarginLines_ = true; |
| 163 |
| 164 // @type {EventTracker} Used to keep track of certain event listeners. |
| 165 this.eventTracker = new EventTracker(); |
138 } | 166 } |
139 | 167 |
140 // Number of points per inch. | 168 // Number of points per inch. |
141 MarginSettings.POINTS_PER_INCH = 72; | 169 MarginSettings.POINTS_PER_INCH = 72; |
| 170 // Minimum allowed distance in points between top-bottom, left-right margins. |
| 171 MarginSettings.MINIMUM_MARGINS_DISTANCE = 36; |
142 // Margin list values. | 172 // Margin list values. |
143 MarginSettings.MARGINS_VALUE_DEFAULT = 0; | 173 MarginSettings.MARGINS_VALUE_DEFAULT = 0; |
144 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; | 174 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; |
145 MarginSettings.MARGINS_VALUE_CUSTOM = 2; | 175 MarginSettings.MARGINS_VALUE_CUSTOM = 2; |
146 // Default Margins option index. | 176 // Default Margins option index. |
147 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0; | 177 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0; |
148 // Group name corresponding to the top margin. | 178 // Group name corresponding to the top margin. |
149 MarginSettings.TOP_GROUP = 'top'; | 179 MarginSettings.TOP_GROUP = 'top'; |
150 // Group name corresponding to the left margin. | 180 // Group name corresponding to the left margin. |
151 MarginSettings.LEFT_GROUP = 'left'; | 181 MarginSettings.LEFT_GROUP = 'left'; |
(...skipping 20 matching lines...) Expand all Loading... |
172 | 202 |
173 /** | 203 /** |
174 * @return {number} The value of the selected margin option. | 204 * @return {number} The value of the selected margin option. |
175 */ | 205 */ |
176 get selectedMarginsValue() { | 206 get selectedMarginsValue() { |
177 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | 207 var val = this.marginList_.options[this.marginList_.selectedIndex].value; |
178 return parseInt(val, 10); | 208 return parseInt(val, 10); |
179 }, | 209 }, |
180 | 210 |
181 /** | 211 /** |
| 212 * @return {number} The total width of the plugin in points. |
| 213 */ |
| 214 get totalWidthInPoints() { |
| 215 var pageInformation = previewArea.pageLocationNormalized; |
| 216 return this.pageWidth_ / pageInformation.width; |
| 217 }, |
| 218 |
| 219 /** |
| 220 * @return {number} The total height of the plugin in points. |
| 221 */ |
| 222 get totalHeightInPoints() { |
| 223 var pageInformation = previewArea.pageLocationNormalized; |
| 224 return this.pageHeight_ / pageInformation.height; |
| 225 }, |
| 226 |
| 227 /** |
182 * @return {boolean} True if default margins are selected. | 228 * @return {boolean} True if default margins are selected. |
183 */ | 229 */ |
184 isDefaultMarginsSelected: function() { | 230 isDefaultMarginsSelected: function() { |
185 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; | 231 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; |
186 }, | 232 }, |
187 | 233 |
188 /** | 234 /** |
189 * @return {boolean} True if no margins are selected. | 235 * @return {boolean} True if no margins are selected. |
190 */ | 236 */ |
191 isNoMarginsSelected: function() { | 237 isNoMarginsSelected: function() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 284 |
239 /** | 285 /** |
240 * Adds listeners to all margin related controls. | 286 * Adds listeners to all margin related controls. |
241 */ | 287 */ |
242 addEventListeners: function() { | 288 addEventListeners: function() { |
243 this.marginList_.onchange = this.onMarginsChanged_.bind(this); | 289 this.marginList_.onchange = this.onMarginsChanged_.bind(this); |
244 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); | 290 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); |
245 }, | 291 }, |
246 | 292 |
247 /** | 293 /** |
| 294 * Executes whenever a "DragEvent" occurs. |
| 295 * @param {cr.Event} e The event that triggered this listener. |
| 296 */ |
| 297 onDragEvent_: function(e) { |
| 298 var dragDeltaInPoints = this.convertDragDeltaToPoints_(e.dragDelta); |
| 299 this.marginsUI.lastClickedMarginsUIPair.updateWhileDragging( |
| 300 dragDeltaInPoints, e.destinationPoint); |
| 301 }, |
| 302 |
| 303 /** |
| 304 * @param {number} dragDelta The difference in pixels between the original |
| 305 * and current postion of the last clicked margin line. |
| 306 * @return {number} The difference in points. |
| 307 * @private |
| 308 */ |
| 309 convertDragDeltaToPoints_: function(dragDelta) { |
| 310 if (this.marginsUI.lastClickedMarginsUIPair.isTop_() || |
| 311 this.marginsUI.lastClickedMarginsUIPair.isBottom_()) { |
| 312 return dragDelta * this.totalHeightInPoints; |
| 313 } else { |
| 314 return dragDelta * this.totalWidthInPoints; |
| 315 } |
| 316 }, |
| 317 |
| 318 /** |
248 * @return {boolean} True if the margin settings are valid. | 319 * @return {boolean} True if the margin settings are valid. |
249 */ | 320 */ |
250 areMarginSettingsValid: function() { | 321 areMarginSettingsValid: function() { |
251 if (this.marginsUI_ == null) | 322 if (this.marginsUI_ == null) |
252 return true; | 323 return true; |
253 | 324 |
254 var pairs = this.marginsUI.pairsAsList; | 325 var pairs = this.marginsUI.pairsAsList; |
255 return pairs.every(function(pair) { return pair.box_.isValid; }); | 326 return pairs.every(function(pair) { return pair.box_.isValid; }); |
256 }, | 327 }, |
257 | 328 |
258 /** | 329 /** |
259 * Calculates the maximum allowable value of the selected margin text for | 330 * Calculates the maximum allowable value of the selected margin text for |
260 * every margin. | 331 * every margin. |
261 * @return {array} The maximum allowable value in order top, left, right, | 332 * @return {array} The maximum allowable value in points in order top, left, |
262 * bottom. | 333 * right, bottom. |
263 * @private | 334 * @private |
264 */ | 335 */ |
265 getMarginValueLimits_: function() { | 336 getMarginValueLimits_: function() { |
266 var marginValueLimits = []; | 337 var marginValueLimits = []; |
267 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom; | 338 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom - |
268 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right; | 339 MarginSettings.MINIMUM_MARGINS_DISTANCE; |
269 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left; | 340 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right - |
270 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top; | 341 MarginSettings.MINIMUM_MARGINS_DISTANCE; |
| 342 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left - |
| 343 MarginSettings.MINIMUM_MARGINS_DISTANCE; |
| 344 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top - |
| 345 MarginSettings.MINIMUM_MARGINS_DISTANCE; |
| 346 |
| 347 for (var i = 0; i < marginValueLimits.length; i++) { |
| 348 marginValueLimits[i] = Math.max(marginValueLimits[i], 0); |
| 349 marginValueLimits[i] = print_preview.convertPointsToInchesTextAndBack( |
| 350 marginValueLimits[i]); |
| 351 } |
271 return marginValueLimits; | 352 return marginValueLimits; |
272 }, | 353 }, |
273 | 354 |
274 /** | 355 /** |
| 356 * @return {array} The margin value limits positions normalized to the total |
| 357 * width and height of the plugin and with respect to the top left |
| 358 * corner of the plugin. |
| 359 */ |
| 360 getMarginValueLimitsInPercent_: function() { |
| 361 var pageInformation = previewArea.pageLocationNormalized; |
| 362 var totalWidthInPoints = this.pageWidth_ / pageInformation.width; |
| 363 var totalHeightInPoints = this.pageHeight_ / pageInformation.height; |
| 364 var marginValueLimits = this.getMarginValueLimits_(); |
| 365 var marginValueLimitsInPercent = []; |
| 366 marginValueLimitsInPercent[0] = pageInformation.y + marginValueLimits[0] / |
| 367 totalHeightInPoints; |
| 368 marginValueLimitsInPercent[1] = pageInformation.x + marginValueLimits[1] / |
| 369 totalWidthInPoints; |
| 370 marginValueLimitsInPercent[2] = pageInformation.x + |
| 371 pageInformation.width - marginValueLimits[2] / totalWidthInPoints; |
| 372 marginValueLimitsInPercent[3] = pageInformation.y + |
| 373 pageInformation.height - marginValueLimits[3] / totalHeightInPoints; |
| 374 return marginValueLimitsInPercent; |
| 375 }, |
| 376 |
| 377 /** |
275 * When the user stops typing in the margin text box a new print preview is | 378 * When the user stops typing in the margin text box a new print preview is |
276 * requested, only if | 379 * requested, only if |
277 * 1) The input is compeletely valid (it can be parsed in its entirety). | 380 * 1) The input is compeletely valid (it can be parsed in its entirety). |
278 * 2) The newly selected margins differ from the previously selected. | 381 * 2) The newly selected margins differ from the previously selected. |
279 * @param {cr.Event} event The change event holding information about what | 382 * @param {cr.Event} event The change event holding information about what |
280 * changed. | 383 * changed. |
281 * @private | 384 * @private |
282 */ | 385 */ |
283 onMarginTextValueMayHaveChanged_: function(event) { | 386 onMarginTextValueMayHaveChanged_: function(event) { |
284 var marginBox = event.target; | 387 var marginBox = event.target; |
285 var marginBoxValue = convertInchesToPoints(marginBox.margin); | 388 var marginBoxValue = convertInchesToPoints(marginBox.margin); |
286 this.customMargins_[marginBox.marginGroup] = marginBoxValue; | 389 this.customMargins_[marginBox.marginGroup] = marginBoxValue; |
287 this.requestPreviewIfNeeded_(); | 390 this.requestPreviewIfNeeded_(); |
288 }, | 391 }, |
289 | 392 |
290 /** | 393 /** |
291 * @type {print_preview.MarginsUI} The object holding the UI for specifying | 394 * @type {print_preview.MarginsUI} The object holding the UI for specifying |
292 * custom margins. | 395 * custom margins. |
293 */ | 396 */ |
294 get marginsUI() { | 397 get marginsUI() { |
295 if (!this.marginsUI_) { | 398 if (!this.marginsUI_) { |
296 this.marginsUI_ = new print_preview.MarginsUI($('mainview')); | 399 this.marginsUI_ = new print_preview.MarginsUI(); |
| 400 $('mainview').appendChild(this.marginsUI_); |
297 this.marginsUI_.addObserver( | 401 this.marginsUI_.addObserver( |
298 this.onMarginTextValueMayHaveChanged_.bind(this)); | 402 this.onMarginTextValueMayHaveChanged_.bind(this)); |
299 } | 403 } |
300 return this.marginsUI_; | 404 return this.marginsUI_; |
301 }, | 405 }, |
302 | 406 |
303 /** | 407 /** |
304 * Adds listeners when the custom margins option is selected. | 408 * Adds listeners when the custom margins option is selected. |
305 * @private | 409 * @private |
306 */ | 410 */ |
307 addCustomMarginEventListeners_: function() { | 411 addCustomMarginEventListeners_: function() { |
308 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); | 412 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); |
309 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); | 413 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); |
| 414 this.eventTracker.add( |
| 415 this.marginsUI, 'DragEvent', this.onDragEvent_.bind(this), false); |
310 }, | 416 }, |
311 | 417 |
312 /** | 418 /** |
313 * Removes the event listeners associated with the custom margins option. | 419 * Removes the event listeners associated with the custom margins option. |
314 * @private | 420 * @private |
315 */ | 421 */ |
316 removeCustomMarginEventListeners_: function() { | 422 removeCustomMarginEventListeners_: function() { |
317 $('mainview').onmouseover = null; | 423 $('mainview').onmouseover = null; |
318 $('sidebar').onmouseover = null; | 424 $('sidebar').onmouseover = null; |
| 425 this.eventTracker.remove(this.marginsUI, 'DragEvent'); |
319 this.marginsUI.hide(); | 426 this.marginsUI.hide(); |
320 }, | 427 }, |
321 | 428 |
322 /** | 429 /** |
323 * Updates |this.marginsUI| depending on the specified margins and the | 430 * Updates |this.marginsUI| depending on the specified margins and the |
324 * position of the page within the plugin. | 431 * position of the page within the plugin. |
325 * @private | 432 * @private |
326 */ | 433 */ |
327 drawCustomMarginsUI_: function() { | 434 drawCustomMarginsUI_: function() { |
328 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| | 435 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| |
329 // directly produces the opposite value even though | 436 // directly produces the opposite value even though |
330 // |this.getMarginsRectangleInPercent_()| and | 437 // |this.getMarginsRectangleInPercent_()| and |
331 // |this.getMarginValueLimits_()| have no side effects. | 438 // |this.getMarginValueLimits_()| have no side effects. |
332 var keepDisplayedValue = !this.areMarginSettingsValid(); | 439 var keepDisplayedValue = !this.areMarginSettingsValid(); |
333 this.marginsUI.update(this.getMarginsRectangleInPercent_(), | 440 this.marginsUI.update(this.getMarginsRectangleInPercent_(), |
334 this.customMargins_, | 441 this.customMargins_, |
335 this.getMarginValueLimits_(), | 442 this.getMarginValueLimits_(), |
336 keepDisplayedValue); | 443 keepDisplayedValue, |
| 444 this.getMarginValueLimitsInPercent_()); |
337 this.marginsUI.draw(); | 445 this.marginsUI.draw(); |
338 }, | 446 }, |
339 | 447 |
340 /** | 448 /** |
341 * Called when there is change in the preview position or size. | 449 * Called when there is change in the preview position or size. |
342 */ | 450 */ |
343 onPreviewPositionChanged: function() { | 451 onPreviewPositionChanged: function() { |
344 if (this.isCustomMarginsSelected() && previewArea.pdfLoaded && | 452 if (this.isCustomMarginsSelected() && previewArea.pdfLoaded && |
345 pageSettings.totalPageCount != undefined) { | 453 pageSettings.totalPageCount != undefined) { |
| 454 previewArea.update(); |
346 this.drawCustomMarginsUI_(); | 455 this.drawCustomMarginsUI_(); |
347 } | 456 } |
348 }, | 457 }, |
349 | 458 |
350 /** | 459 /** |
351 * Executes when user selects a different margin option, ie, | 460 * Executes when user selects a different margin option, ie, |
352 * |this.marginList_.selectedIndex| is changed. | 461 * |this.marginList_.selectedIndex| is changed. |
353 * @private | 462 * @private |
354 */ | 463 */ |
355 onMarginsChanged_: function() { | 464 onMarginsChanged_: function() { |
(...skipping 28 matching lines...) Expand all Loading... |
384 setDefaultValuesAndRegeneratePreview(false); | 493 setDefaultValuesAndRegeneratePreview(false); |
385 }, | 494 }, |
386 | 495 |
387 /** | 496 /** |
388 * Executes when the custom margins option is selected. | 497 * Executes when the custom margins option is selected. |
389 * @private | 498 * @private |
390 */ | 499 */ |
391 onCustomMarginsSelected_: function() { | 500 onCustomMarginsSelected_: function() { |
392 this.addCustomMarginEventListeners_(); | 501 this.addCustomMarginEventListeners_(); |
393 | 502 |
394 if (this.lastSelectedOption_ == MarginSettings.MARGINS_VALUE_DEFAULT) | 503 if (this.lastSelectedOption_ == MarginSettings.MARGINS_VALUE_DEFAULT) { |
395 this.customMargins_ = this.currentDefaultPageLayout.margins_; | 504 this.customMargins_ = this.currentDefaultPageLayout.margins_; |
| 505 this.customMargins_.roundToInches(); |
| 506 } |
396 this.previousCustomMargins_.copy(this.customMargins_); | 507 this.previousCustomMargins_.copy(this.customMargins_); |
397 | 508 |
398 if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { | 509 if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { |
399 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; | 510 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; |
400 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; | 511 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; |
401 } | 512 } |
402 | 513 |
403 this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; | 514 this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; |
404 this.drawCustomMarginsUI_(); | 515 this.drawCustomMarginsUI_(); |
405 this.marginsUI.show(); | 516 this.marginsUI.show(); |
406 }, | 517 }, |
407 | 518 |
408 /** | 519 /** |
409 * Calculates the coordinates of the four margin lines. These are the | 520 * Calculates the coordinates of the four margin lines. These are the |
410 * coordinates where the margin lines should be displayed. The coordinates | 521 * coordinates where the margin lines should be displayed. The coordinates |
411 * are expressed in terms of percentages with respect to the total width | 522 * are expressed in terms of percentages with respect to the total width |
412 * and height of the plugin. | 523 * and height of the plugin. |
413 * @return {print_preview.Rect} A rectnangle that describes the position of | 524 * @return {print_preview.Rect} A rectnangle that describes the position of |
414 * the four margin lines. | 525 * the four margin lines. |
415 * @private | 526 * @private |
416 */ | 527 */ |
417 getMarginsRectangleInPercent_: function() { | 528 getMarginsRectangleInPercent_: function() { |
418 var pageLocation = previewArea.getPageLocationNormalized(); | 529 var pageLocation = previewArea.pageLocationNormalized; |
419 var marginsInPercent = this.getMarginsInPercent_(); | 530 var marginsInPercent = this.getMarginsInPercent_(); |
420 var leftX = pageLocation.x + marginsInPercent.left; | 531 var leftX = pageLocation.x + marginsInPercent.left; |
421 var topY = pageLocation.y + marginsInPercent.top; | 532 var topY = pageLocation.y + marginsInPercent.top; |
422 var contentWidth = pageLocation.width - (marginsInPercent.left + | 533 var contentWidth = pageLocation.width - (marginsInPercent.left + |
423 marginsInPercent.right); | 534 marginsInPercent.right); |
424 var contentHeight = pageLocation.height - (marginsInPercent.top + | 535 var contentHeight = pageLocation.height - (marginsInPercent.top + |
425 marginsInPercent.bottom); | 536 marginsInPercent.bottom); |
426 return new print_preview.Rect( | 537 return new print_preview.Rect( |
427 leftX, topY, contentWidth, contentHeight); | 538 leftX, topY, contentWidth, contentHeight); |
428 }, | 539 }, |
429 | 540 |
430 /** | 541 /** |
431 * @return {print_preview.Margins} The currently selected margin values | 542 * @return {print_preview.Margins} The currently selected margin values |
432 * normalized to the total width and height of the plugin. | 543 * normalized to the total width and height of the plugin. |
433 * @private | 544 * @private |
434 */ | 545 */ |
435 getMarginsInPercent_: function() { | 546 getMarginsInPercent_: function() { |
436 var pageInformation = previewArea.getPageLocationNormalized(); | 547 return this.convertMarginsInPointsToPercent(this.customMargins_); |
| 548 }, |
| 549 |
| 550 /** |
| 551 * Converts |marginsToConvert| to points and normalizes it to the height and |
| 552 * width of the plugin. |
| 553 * @return {print_preview.Margins} The margins in percent. |
| 554 * @private |
| 555 */ |
| 556 convertMarginsInPointsToPercent: function(marginsToConvert) { |
| 557 var pageInformation = previewArea.pageLocationNormalized; |
437 var totalWidthInPoints = this.pageWidth_ / pageInformation.width; | 558 var totalWidthInPoints = this.pageWidth_ / pageInformation.width; |
438 var totalHeightInPoints = this.pageHeight_ / pageInformation.height; | 559 var totalHeightInPoints = this.pageHeight_ / pageInformation.height; |
439 var marginsInPercent = new Margins( | 560 var marginsInPercent = new Margins( |
440 this.customMargins_.left / totalWidthInPoints, | 561 marginsToConvert.left / totalWidthInPoints, |
441 this.customMargins_.top / totalHeightInPoints, | 562 marginsToConvert.top / totalHeightInPoints, |
442 this.customMargins_.right / totalWidthInPoints, | 563 marginsToConvert.right / totalWidthInPoints, |
443 this.customMargins_.bottom / totalHeightInPoints); | 564 marginsToConvert.bottom / totalHeightInPoints); |
444 return marginsInPercent; | 565 return marginsInPercent; |
445 }, | 566 }, |
446 | 567 |
447 /** | 568 /** |
448 * If custom margins is the currently selected option then change to the | 569 * If custom margins is the currently selected option then change to the |
449 * default margins option. | 570 * default margins option. |
450 * @private | 571 * @private |
451 */ | 572 */ |
452 resetMarginsIfNeeded: function() { | 573 resetMarginsIfNeeded: function() { |
453 if (this.isCustomMarginsSelected()) { | 574 if (this.isCustomMarginsSelected()) { |
454 this.marginList_.options[ | 575 this.marginList_.options[ |
455 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; | 576 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; |
456 this.removeCustomMarginEventListeners_(); | 577 this.removeCustomMarginEventListeners_(); |
| 578 this.forceDisplayingMarginLines_ = true; |
457 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 579 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
458 } | 580 } |
459 }, | 581 }, |
460 | 582 |
461 /** | 583 /** |
462 * Executes when a PDFLoaded event occurs. | 584 * Executes when a PDFLoaded event occurs. |
463 * @private | 585 * @private |
464 */ | 586 */ |
465 onPDFLoaded_: function() { | 587 onPDFLoaded_: function() { |
466 if (!previewModifiable) | 588 if (!previewModifiable) |
467 fadeOutElement(this.marginsOption_); | 589 fadeOutElement(this.marginsOption_); |
468 } | 590 } |
469 }; | 591 }; |
470 | 592 |
471 return { | 593 return { |
472 MarginSettings: MarginSettings, | 594 MarginSettings: MarginSettings, |
473 PageLayout: PageLayout, | 595 PageLayout: PageLayout, |
474 }; | 596 }; |
475 }); | 597 }); |
OLD | NEW |