| 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 22 matching lines...) Expand all Loading... |
| 33 Math.pow(10, precision); | 33 Math.pow(10, precision); |
| 34 } | 34 } |
| 35 | 35 |
| 36 Margins.prototype = { | 36 Margins.prototype = { |
| 37 /** | 37 /** |
| 38 * Checks if |rhs| is equal to |this|. | 38 * Checks if |rhs| is equal to |this|. |
| 39 * @param {Margins} rhs The Margins object to compare against. | 39 * @param {Margins} rhs The Margins object to compare against. |
| 40 * @return {boolean} true if they are equal. | 40 * @return {boolean} true if they are equal. |
| 41 */ | 41 */ |
| 42 isEqual: function(rhs) { | 42 isEqual: function(rhs) { |
| 43 if (!rhs) |
| 44 return false; |
| 43 return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] && | 45 return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] && |
| 44 this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] && | 46 this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] && |
| 45 this[MarginSettings.RIGHT_GROUP] === | 47 this[MarginSettings.RIGHT_GROUP] === |
| 46 rhs[MarginSettings.RIGHT_GROUP] && | 48 rhs[MarginSettings.RIGHT_GROUP] && |
| 47 this[MarginSettings.BOTTOM_GROUP] === | 49 this[MarginSettings.BOTTOM_GROUP] === |
| 48 rhs[MarginSettings.BOTTOM_GROUP]; | 50 rhs[MarginSettings.BOTTOM_GROUP]; |
| 49 }, | 51 }, |
| 50 | 52 |
| 51 /** | 53 clone: function() { |
| 52 * Copies the four margin values from |rhs|. | 54 return new Margins(this[MarginSettings.TOP_GROUP], |
| 53 * @param {Margins} rhs The Margins object values to be used. | 55 this[MarginSettings.LEFT_GROUP], |
| 54 */ | 56 this[MarginSettings.RIGHT_GROUP], |
| 55 copy: function(rhs) { | 57 this[MarginSettings.BOTTOM_GROUP]); |
| 56 this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP]; | |
| 57 this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP]; | |
| 58 this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP]; | |
| 59 this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP]; | |
| 60 }, | 58 }, |
| 61 | 59 |
| 62 /** | 60 /** |
| 63 * Helper method returning an array of the string indices used for accessing | 61 * Helper method returning an array of the string indices used for accessing |
| 64 * all margins. | 62 * all margins. |
| 65 * @return {array} An array of string indices. | 63 * @return {array} An array of string indices. |
| 66 * @private | 64 * @private |
| 67 */ | 65 */ |
| 68 indicesAsArray_: function() { | 66 indicesAsArray_: function() { |
| 69 return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP, | 67 return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 /** | 86 /** |
| 89 * @constructor | 87 * @constructor |
| 90 * Class describing the layout of the page. | 88 * Class describing the layout of the page. |
| 91 */ | 89 */ |
| 92 function PageLayout(width, height, left, top, right, bottom) { | 90 function PageLayout(width, height, left, top, right, bottom) { |
| 93 this.contentWidth_ = width; | 91 this.contentWidth_ = width; |
| 94 this.contentHeight_ = height; | 92 this.contentHeight_ = height; |
| 95 this.margins_ = new Margins(left, top, right, bottom); | 93 this.margins_ = new Margins(left, top, right, bottom); |
| 94 this.margins_.roundToLocaleUnits(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 PageLayout.prototype = { | 97 PageLayout.prototype = { |
| 99 /** | 98 /** |
| 100 * @type {number} The width of the page. | 99 * @type {number} The width of the page. |
| 101 */ | 100 */ |
| 102 get pageWidth() { | 101 get pageWidth() { |
| 103 return this.margins_.left + this.margins_.right + this.contentWidth_; | 102 return this.margins_.left + this.margins_.right + this.contentWidth_; |
| 104 }, | 103 }, |
| 105 | 104 |
| 106 /** | 105 /** |
| 107 * @type {number} The height of the page. | 106 * @type {number} The height of the page. |
| 108 */ | 107 */ |
| 109 get pageHeight() { | 108 get pageHeight() { |
| 110 return this.margins_.top + this.margins_.bottom + this.contentHeight_; | 109 return this.margins_.top + this.margins_.bottom + this.contentHeight_; |
| 111 } | 110 } |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 /** | 113 /** |
| 115 * Creates a MarginSettings object. This object encapsulates all settings and | 114 * Creates a MarginSettings object. This object encapsulates all settings and |
| 116 * logic related to the margins mode. | 115 * logic related to the margins mode. |
| 117 * @constructor | 116 * @constructor |
| 118 */ | 117 */ |
| 119 function MarginSettings() { | 118 function MarginSettings() { |
| 120 this.marginsOption_ = $('margins-option'); | 119 this.marginsOption_ = $('margins-option'); |
| 121 this.marginList_ = $('margin-list'); | 120 this.marginList_ = $('margin-list'); |
| 122 this.marginsUI_ = null; | 121 this.marginsUI_ = null; |
| 123 | 122 |
| 124 // Holds the custom margin values in points (if set). | 123 // Holds the custom margin values in points (if set). |
| 125 this.customMargins_ = new Margins(-1, -1, -1, -1); | 124 this.customMargins_ = null; |
| 126 // Holds the previous custom margin values in points. | 125 // Holds the previous custom margin values in points. |
| 127 this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); | 126 this.previousCustomMargins_ = null; |
| 128 // Holds the width of the page in points. | 127 // Holds the width of the page in points. |
| 129 this.pageWidth_ = -1; | 128 this.pageWidth_ = -1; |
| 130 // Holds the height of the page in points. | 129 // Holds the height of the page in points. |
| 131 this.pageHeight_ = -1; | 130 this.pageHeight_ = -1; |
| 132 // The last selected margin option. | 131 // @type {boolean} True if the margins UI should be diplayed when the next |
| 133 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 132 // |customEvents.PDF_LOADED| event occurs. |
| 134 | 133 this.forceMarginsUIOnPDFLoad_ = false; |
| 135 // Holds the currently updated default page layout values. | 134 // Holds the currently updated default page layout values. |
| 136 this.currentDefaultPageLayout = null; | 135 this.currentDefaultPageLayout = null; |
| 137 // Holds the default page layout values when the custom margins was last | |
| 138 // selected. | |
| 139 this.previousDefaultPageLayout_ = null; | |
| 140 | 136 |
| 141 // True if the margins UI should be shown regardless of mouse position. | 137 // True if the margins UI should be shown regardless of mouse position. |
| 142 this.forceDisplayingMarginLines_ = true; | 138 this.forceDisplayingMarginLines_ = true; |
| 143 | 139 |
| 144 // @type {EventTracker} Used to keep track of certain event listeners. | 140 // @type {EventTracker} Used to keep track of certain event listeners. |
| 145 this.eventTracker_ = new EventTracker(); | 141 this.eventTracker_ = new EventTracker(); |
| 146 | 142 |
| 147 this.addEventListeners_(); | 143 this.addEventListeners_(); |
| 148 } | 144 } |
| 149 | 145 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 get customMargins() { | 192 get customMargins() { |
| 197 var margins = {}; | 193 var margins = {}; |
| 198 margins.marginLeft = this.customMargins_.left; | 194 margins.marginLeft = this.customMargins_.left; |
| 199 margins.marginTop = this.customMargins_.top; | 195 margins.marginTop = this.customMargins_.top; |
| 200 margins.marginRight = this.customMargins_.right; | 196 margins.marginRight = this.customMargins_.right; |
| 201 margins.marginBottom = this.customMargins_.bottom; | 197 margins.marginBottom = this.customMargins_.bottom; |
| 202 return margins; | 198 return margins; |
| 203 }, | 199 }, |
| 204 | 200 |
| 205 /** | 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 /** |
| 206 * @return {number} The value of the selected margin option. | 215 * @return {number} The value of the selected margin option. |
| 207 */ | 216 */ |
| 208 get selectedMarginsValue() { | 217 get selectedMarginsValue() { |
| 209 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | 218 var val = this.marginList_.options[this.marginList_.selectedIndex].value; |
| 210 return parseInt(val, 10); | 219 return parseInt(val, 10); |
| 211 }, | 220 }, |
| 212 | 221 |
| 213 /** | 222 /** |
| 214 * Sets the current margin selection to |lastUsedMarginsType|. | 223 * Sets the current margin selection to |lastUsedMarginType|. |
| 215 * @param {number} lastUsedMarginsType An integer value identifying a margin | 224 * @param {number} lastUsedMarginType An integer value identifying a margin |
| 216 * type according to MarginType enum in printing/print_job_constants.h. | 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. |
| 217 */ | 229 */ |
| 218 setLastUsedMarginsType: function(lastUsedMarginsType) { | 230 setLastUsedMargins: function(lastUsedMarginsSettings) { |
| 231 var lastUsedMarginsType = lastUsedMarginsSettings['marginsType'] |
| 232 this.forceMarginsUIOnPDFLoad_ = |
| 233 lastUsedMarginsType == MarginSettings.MARGINS_VALUE_CUSTOM; |
| 219 this.marginList_.selectedIndex = | 234 this.marginList_.selectedIndex = |
| 220 this.getMarginOptionIndexByValue_(lastUsedMarginsType); | 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 } |
| 221 }, | 243 }, |
| 222 | 244 |
| 223 /** | 245 /** |
| 224 * @return {number} The total width of the plugin in points. | 246 * @return {number} The total width of the plugin in points. |
| 225 */ | 247 */ |
| 226 get totalWidthInPoints() { | 248 get totalWidthInPoints() { |
| 227 var pageInformation = previewArea.pageLocationNormalized; | 249 var pageInformation = previewArea.pageLocationNormalized; |
| 228 return this.pageWidth_ / pageInformation.width; | 250 return this.pageWidth_ / pageInformation.width; |
| 229 }, | 251 }, |
| 230 | 252 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 }, | 305 }, |
| 284 | 306 |
| 285 /** | 307 /** |
| 286 * If the custom margin values have changed then request a new preview based | 308 * If the custom margin values have changed then request a new preview based |
| 287 * on the newly set margins. | 309 * on the newly set margins. |
| 288 * @private | 310 * @private |
| 289 */ | 311 */ |
| 290 requestPreviewIfNeeded_: function() { | 312 requestPreviewIfNeeded_: function() { |
| 291 if (!this.areMarginSettingsValid()) | 313 if (!this.areMarginSettingsValid()) |
| 292 return; | 314 return; |
| 315 |
| 293 if (this.customMargins_.isEqual(this.previousCustomMargins_)) | 316 if (this.customMargins_.isEqual(this.previousCustomMargins_)) |
| 294 return; | 317 return; |
| 295 this.previousCustomMargins_.copy(this.customMargins_); | 318 |
| 319 this.previousCustomMargins_ = this.customMargins_.clone(); |
| 296 setDefaultValuesAndRegeneratePreview(false); | 320 setDefaultValuesAndRegeneratePreview(false); |
| 297 }, | 321 }, |
| 298 | 322 |
| 299 /** | 323 /** |
| 300 * Listener executed when the mouse is over the sidebar. If the custom | 324 * Listener executed when the mouse is over the sidebar. If the custom |
| 301 * margin lines are displayed, then, it fades them out. | 325 * margin lines are displayed, then, it fades them out. |
| 302 * @private | 326 * @private |
| 303 */ | 327 */ |
| 304 onSidebarMouseOver_: function(e) { | 328 onSidebarMouseOver_: function(e) { |
| 329 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); |
| 330 $('navbar-container').onmouseover = null; |
| 305 if (!this.forceDisplayingMarginLines_) | 331 if (!this.forceDisplayingMarginLines_) |
| 306 this.marginsUI.hide(false); | 332 this.marginsUI.hide(false); |
| 307 }, | 333 }, |
| 308 | 334 |
| 309 /** | 335 /** |
| 310 * Listener executed when the mouse is over the main view. If the custom | 336 * Listener executed when the mouse is over the main view. If the custom |
| 311 * margin lines are hidden, then, it fades them in. | 337 * margin lines are hidden, then, it fades them in. |
| 312 * @private | 338 * @private |
| 313 */ | 339 */ |
| 314 onMainviewMouseOver_: function() { | 340 onMainviewMouseOver_: function() { |
| 341 $('mainview').onmouseover = null; |
| 342 $('navbar-container').onmouseover = this.onSidebarMouseOver_.bind(this); |
| 315 this.forceDisplayingMarginLines_ = false; | 343 this.forceDisplayingMarginLines_ = false; |
| 316 this.marginsUI.show(); | 344 this.marginsUI.show(); |
| 317 }, | 345 }, |
| 318 | 346 |
| 319 /** | 347 /** |
| 320 * Adds listeners to all margin related controls. | 348 * Adds listeners to all margin related controls. |
| 321 * @private | 349 * @private |
| 322 */ | 350 */ |
| 323 addEventListeners_: function() { | 351 addEventListeners_: function() { |
| 324 this.marginList_.onchange = this.onMarginsChanged_.bind(this); | 352 this.marginList_.onchange = this.onMarginsChanged_.bind(this); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return dragDelta * this.totalHeightInPoints; | 389 return dragDelta * this.totalHeightInPoints; |
| 362 } else { | 390 } else { |
| 363 return dragDelta * this.totalWidthInPoints; | 391 return dragDelta * this.totalWidthInPoints; |
| 364 } | 392 } |
| 365 }, | 393 }, |
| 366 | 394 |
| 367 /** | 395 /** |
| 368 * @return {boolean} True if the margin settings are valid. | 396 * @return {boolean} True if the margin settings are valid. |
| 369 */ | 397 */ |
| 370 areMarginSettingsValid: function() { | 398 areMarginSettingsValid: function() { |
| 371 if (this.marginsUI_ == null) | 399 if (!this.isCustomMarginsSelected() || !this.marginsUI_) |
| 372 return true; | 400 return true; |
| 373 | 401 |
| 374 var pairs = this.marginsUI.pairsAsList; | 402 var pairs = this.marginsUI.pairsAsList; |
| 375 return pairs.every(function(pair) { return pair.box_.isValid; }); | 403 return pairs.every(function(pair) { return pair.box_.isValid; }); |
| 376 }, | 404 }, |
| 377 | 405 |
| 378 /** | 406 /** |
| 379 * Calculates the maximum allowable value of the selected margin text for | 407 * Calculates the maximum allowable value of the selected margin text for |
| 380 * every margin. | 408 * every margin. |
| 381 * @return {array} The maximum allowable value in points in order top, left, | 409 * @return {array} The maximum allowable value in points in order top, left, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 false); | 495 false); |
| 468 this.eventTracker_.add(document, customEvents.MARGIN_TEXTBOX_FOCUSED, | 496 this.eventTracker_.add(document, customEvents.MARGIN_TEXTBOX_FOCUSED, |
| 469 this.onMarginTextboxFocused_.bind(this), false); | 497 this.onMarginTextboxFocused_.bind(this), false); |
| 470 }, | 498 }, |
| 471 | 499 |
| 472 /** | 500 /** |
| 473 * Removes the event listeners associated with the custom margins option. | 501 * Removes the event listeners associated with the custom margins option. |
| 474 * @private | 502 * @private |
| 475 */ | 503 */ |
| 476 removeCustomMarginEventListeners_: function() { | 504 removeCustomMarginEventListeners_: function() { |
| 505 if (!this.marginsUI_) |
| 506 return; |
| 477 $('mainview').onmouseover = null; | 507 $('mainview').onmouseover = null; |
| 478 $('navbar-container').onmouseover = null; | 508 $('navbar-container').onmouseover = null; |
| 479 this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); | 509 this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); |
| 480 this.eventTracker_.remove(document, customEvents.MARGIN_TEXTBOX_FOCUSED); | 510 this.eventTracker_.remove(document, customEvents.MARGIN_TEXTBOX_FOCUSED); |
| 481 this.marginsUI.hide(true); | 511 this.marginsUI.hide(true); |
| 482 }, | 512 }, |
| 483 | 513 |
| 484 /** | 514 /** |
| 485 * Updates |this.marginsUI| depending on the specified margins and the | 515 * Updates |this.marginsUI| depending on the specified margins and the |
| 486 * position of the page within the plugin. | 516 * position of the page within the plugin. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 * Executes when user selects a different margin option, ie, | 555 * Executes when user selects a different margin option, ie, |
| 526 * |this.marginList_.selectedIndex| is changed. | 556 * |this.marginList_.selectedIndex| is changed. |
| 527 * @private | 557 * @private |
| 528 */ | 558 */ |
| 529 onMarginsChanged_: function() { | 559 onMarginsChanged_: function() { |
| 530 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || | 560 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || |
| 531 this.isNoMarginsSelected()) | 561 this.isNoMarginsSelected()) |
| 532 this.onDefaultMinimumNoMarginsSelected_(); | 562 this.onDefaultMinimumNoMarginsSelected_(); |
| 533 else if (this.isCustomMarginsSelected()) | 563 else if (this.isCustomMarginsSelected()) |
| 534 this.onCustomMarginsSelected_(); | 564 this.onCustomMarginsSelected_(); |
| 535 | |
| 536 this.lastSelectedOption_ = this.selectedMarginsValue; | |
| 537 }, | 565 }, |
| 538 | 566 |
| 539 /** | 567 /** |
| 540 * Executes when the default or minimum or no margins option is selected. | 568 * Executes when the default or minimum or no margins option is selected. |
| 541 * @private | 569 * @private |
| 542 */ | 570 */ |
| 543 onDefaultMinimumNoMarginsSelected_: function() { | 571 onDefaultMinimumNoMarginsSelected_: function() { |
| 544 this.removeCustomMarginEventListeners_(); | 572 this.removeCustomMarginEventListeners_(); |
| 545 this.forceDisplayingMarginLines_ = true; | 573 this.forceDisplayingMarginLines_ = true; |
| 574 this.previousCustomMargins_ = null; |
| 546 setDefaultValuesAndRegeneratePreview(false); | 575 setDefaultValuesAndRegeneratePreview(false); |
| 547 }, | 576 }, |
| 548 | 577 |
| 549 /** | 578 /** |
| 550 * Executes when the custom margins option is selected. | 579 * Executes when the custom margins option is selected. |
| 551 * @private | 580 * @private |
| 552 */ | 581 */ |
| 553 onCustomMarginsSelected_: function() { | 582 onCustomMarginsSelected_: function() { |
| 554 this.addCustomMarginEventListeners_(); | 583 var customMarginsNotSpecified = !this.customMargins_; |
| 584 this.updatePageData_(); |
| 555 | 585 |
| 556 this.customMargins_ = this.currentDefaultPageLayout.margins_; | 586 if (customMarginsNotSpecified) { |
| 557 this.customMargins_.roundToLocaleUnits(); | 587 this.previousCustomMargins_ = this.customMargins_.clone(); |
| 558 this.previousCustomMargins_.copy(this.customMargins_); | 588 this.drawCustomMarginsUI_(); |
| 559 | 589 this.addCustomMarginEventListeners_(); |
| 560 if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { | 590 this.marginsUI.show(); |
| 561 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; | 591 } else { |
| 562 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; | 592 this.forceMarginsUIOnPDFLoad_ = true; |
| 593 this.requestPreviewIfNeeded_(); |
| 563 } | 594 } |
| 564 | |
| 565 this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; | |
| 566 this.drawCustomMarginsUI_(); | |
| 567 this.marginsUI.show(); | |
| 568 }, | 595 }, |
| 569 | 596 |
| 570 /** | 597 /** |
| 571 * Calculates the coordinates of the four margin lines. These are the | 598 * Calculates the coordinates of the four margin lines. These are the |
| 572 * coordinates where the margin lines should be displayed. The coordinates | 599 * coordinates where the margin lines should be displayed. The coordinates |
| 573 * are expressed in terms of percentages with respect to the total width | 600 * are expressed in terms of percentages with respect to the total width |
| 574 * and height of the plugin. | 601 * and height of the plugin. |
| 575 * @return {print_preview.Rect} A rectnangle that describes the position of | 602 * @return {print_preview.Rect} A rectnangle that describes the position of |
| 576 * the four margin lines. | 603 * the four margin lines. |
| 577 * @private | 604 * @private |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 * If custom margins is the currently selected option then change to the | 647 * If custom margins is the currently selected option then change to the |
| 621 * default margins option. | 648 * default margins option. |
| 622 * @private | 649 * @private |
| 623 */ | 650 */ |
| 624 resetMarginsIfNeeded: function() { | 651 resetMarginsIfNeeded: function() { |
| 625 if (this.isCustomMarginsSelected()) { | 652 if (this.isCustomMarginsSelected()) { |
| 626 this.marginList_.options[ | 653 this.marginList_.options[ |
| 627 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; | 654 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
| 628 this.removeCustomMarginEventListeners_(); | 655 this.removeCustomMarginEventListeners_(); |
| 629 this.forceDisplayingMarginLines_ = true; | 656 this.forceDisplayingMarginLines_ = true; |
| 630 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 657 this.customMargins_ = null; |
| 658 this.previousCustomMargins_ = null; |
| 631 } | 659 } |
| 632 }, | 660 }, |
| 633 | 661 |
| 634 /** | 662 /** |
| 635 * Executes when a |customEvents.PDF_LOADED| event occurs. | 663 * Executes when a |customEvents.PDF_LOADED| event occurs. |
| 636 * @private | 664 * @private |
| 637 */ | 665 */ |
| 638 onPDFLoaded_: function() { | 666 onPDFLoaded_: function() { |
| 639 if (!previewModifiable) | 667 if (!previewModifiable) { |
| 640 fadeOutOption(this.marginsOption_); | 668 fadeOutOption(this.marginsOption_); |
| 669 return; |
| 670 } |
| 671 |
| 672 if (this.forceMarginsUIOnPDFLoad_) { |
| 673 this.updatePageData_(); |
| 674 this.drawCustomMarginsUI_(); |
| 675 this.addCustomMarginEventListeners_(); |
| 676 this.marginsUI.show(); |
| 677 this.forceMarginsUIOnPDFLoad_ = false; |
| 678 } |
| 679 }, |
| 680 |
| 681 /** |
| 682 * Updates |this.customMargins_|, |this.pageWidth_|, |this.pageHeight_|. |
| 683 * @private |
| 684 */ |
| 685 updatePageData_: function() { |
| 686 if (!this.customMargins_) |
| 687 this.customMargins_ = this.currentDefaultPageLayout.margins_.clone(); |
| 688 |
| 689 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; |
| 690 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; |
| 641 } | 691 } |
| 642 }; | 692 }; |
| 643 | 693 |
| 644 return { | 694 return { |
| 645 MarginSettings: MarginSettings, | 695 MarginSettings: MarginSettings, |
| 646 PageLayout: PageLayout, | 696 PageLayout: PageLayout, |
| 647 setNumberFormatAndMeasurementSystem: | |
| 648 MarginSettings.setNumberFormatAndMeasurementSystem, | |
| 649 }; | 697 }; |
| 650 }); | 698 }); |
| OLD | NEW |