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