Chromium Code Reviews| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 this.marginsUI_ = null; | 122 this.marginsUI_ = null; |
| 123 | 123 |
| 124 // Holds the custom margin values in points (if set). | 124 // Holds the custom margin values in points (if set). |
| 125 this.customMargins_ = new Margins(-1, -1, -1, -1); | 125 this.customMargins_ = new Margins(-1, -1, -1, -1); |
| 126 // Holds the previous custom margin values in points. | 126 // Holds the previous custom margin values in points. |
| 127 this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); | 127 this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); |
| 128 // Holds the width of the page in points. | 128 // Holds the width of the page in points. |
| 129 this.pageWidth_ = -1; | 129 this.pageWidth_ = -1; |
| 130 // Holds the height of the page in points. | 130 // Holds the height of the page in points. |
| 131 this.pageHeight_ = -1; | 131 this.pageHeight_ = -1; |
| 132 // The last selected margin option. | 132 // @type {number} The value of the margins type that needs to be restored |
| 133 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 133 // once the document loads. |
| 134 | 134 this.optionToRestore_ = null; |
|
kmadhusu
2011/11/02 20:40:05
Since this is a number, can you default to -1? Fro
kmadhusu
2011/11/02 20:40:05
optionToRestore_ => MarginValueToRestore_?
dpapad
2011/11/02 21:33:57
Margin value is confusing (sounds like it is a val
dpapad
2011/11/02 21:33:57
Done. In general though !!null returns false and i
| |
| 135 // Holds the currently updated default page layout values. | 135 // Holds the currently updated default page layout values. |
| 136 this.currentDefaultPageLayout = null; | 136 this.currentDefaultPageLayout = null; |
| 137 // Holds the default page layout values when the custom margins was last | 137 // Holds the default page layout values when the custom margins was last |
| 138 // selected. | 138 // selected. |
| 139 this.previousDefaultPageLayout_ = null; | 139 this.previousDefaultPageLayout_ = null; |
| 140 | 140 |
| 141 // 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. |
| 142 this.forceDisplayingMarginLines_ = true; | 142 this.forceDisplayingMarginLines_ = true; |
| 143 | 143 |
| 144 // @type {EventTracker} Used to keep track of certain event listeners. | 144 // @type {EventTracker} Used to keep track of certain event listeners. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 */ | 195 */ |
| 196 get customMargins() { | 196 get customMargins() { |
| 197 var margins = {}; | 197 var margins = {}; |
| 198 margins.marginLeft = this.customMargins_.left; | 198 margins.marginLeft = this.customMargins_.left; |
| 199 margins.marginTop = this.customMargins_.top; | 199 margins.marginTop = this.customMargins_.top; |
| 200 margins.marginRight = this.customMargins_.right; | 200 margins.marginRight = this.customMargins_.right; |
| 201 margins.marginBottom = this.customMargins_.bottom; | 201 margins.marginBottom = this.customMargins_.bottom; |
| 202 return margins; | 202 return margins; |
| 203 }, | 203 }, |
| 204 | 204 |
| 205 set customMargins(margins) { | |
|
kmadhusu
2011/11/02 20:40:05
This function is called only from line 231. Can yo
dpapad
2011/11/02 21:33:57
I could but what is the benefit? Having one less f
| |
| 206 this.customMargins_.left = margins.marginLeft; | |
| 207 this.customMargins_.top = margins.marginTop; | |
| 208 this.customMargins_.right = margins.marginRight; | |
| 209 this.customMargins_.bottom = margins.marginBottom; | |
| 210 }, | |
| 211 | |
| 205 /** | 212 /** |
| 206 * @return {number} The value of the selected margin option. | 213 * @return {number} The value of the selected margin option. |
| 207 */ | 214 */ |
| 208 get selectedMarginsValue() { | 215 get selectedMarginsValue() { |
| 209 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | 216 var val = this.marginList_.options[this.marginList_.selectedIndex].value; |
| 210 return parseInt(val, 10); | 217 return parseInt(val, 10); |
| 211 }, | 218 }, |
| 212 | 219 |
| 213 /** | 220 /** |
| 214 * Sets the current margin selection to |lastUsedMarginsType|. | 221 * Sets the current margin selection to |lastUsedMarginsType|. |
| 215 * @param {number} lastUsedMarginsType An integer value identifying a margin | 222 * @param {number} lastUsedMarginsType An integer value identifying a margin |
| 216 * type according to MarginType enum in printing/print_job_constants.h. | 223 * type according to MarginType enum in printing/print_job_constants.h. |
| 224 * @param {Object} lastUsedMargins The last used margins | |
| 217 */ | 225 */ |
| 218 setLastUsedMarginsType: function(lastUsedMarginsType) { | 226 setLastUsedMargins: function(lastUsedMarginsType, lastUsedMargins) { |
|
kmadhusu
2011/11/02 20:40:05
"lastUsedMargins" param is optional. (Document thi
dpapad
2011/11/02 21:33:57
Any parameter not specified is initialized to unde
| |
| 227 this.optionToRestore_ = lastUsedMarginsType; | |
| 219 this.marginList_.selectedIndex = | 228 this.marginList_.selectedIndex = |
| 220 this.getMarginOptionIndexByValue_(lastUsedMarginsType); | 229 this.getMarginOptionIndexByValue_(this.optionToRestore_); |
| 230 if (lastUsedMargins) | |
| 231 this.customMargins = lastUsedMargins; | |
| 221 }, | 232 }, |
| 222 | 233 |
| 223 /** | 234 /** |
| 224 * @return {number} The total width of the plugin in points. | 235 * @return {number} The total width of the plugin in points. |
| 225 */ | 236 */ |
| 226 get totalWidthInPoints() { | 237 get totalWidthInPoints() { |
| 227 var pageInformation = previewArea.pageLocationNormalized; | 238 var pageInformation = previewArea.pageLocationNormalized; |
| 228 return this.pageWidth_ / pageInformation.width; | 239 return this.pageWidth_ / pageInformation.width; |
| 229 }, | 240 }, |
| 230 | 241 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 * Executes when user selects a different margin option, ie, | 536 * Executes when user selects a different margin option, ie, |
| 526 * |this.marginList_.selectedIndex| is changed. | 537 * |this.marginList_.selectedIndex| is changed. |
| 527 * @private | 538 * @private |
| 528 */ | 539 */ |
| 529 onMarginsChanged_: function() { | 540 onMarginsChanged_: function() { |
| 530 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || | 541 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || |
| 531 this.isNoMarginsSelected()) | 542 this.isNoMarginsSelected()) |
| 532 this.onDefaultMinimumNoMarginsSelected_(); | 543 this.onDefaultMinimumNoMarginsSelected_(); |
| 533 else if (this.isCustomMarginsSelected()) | 544 else if (this.isCustomMarginsSelected()) |
| 534 this.onCustomMarginsSelected_(); | 545 this.onCustomMarginsSelected_(); |
| 535 | |
| 536 this.lastSelectedOption_ = this.selectedMarginsValue; | |
| 537 }, | 546 }, |
| 538 | 547 |
| 539 /** | 548 /** |
| 540 * Executes when the default or minimum or no margins option is selected. | 549 * Executes when the default or minimum or no margins option is selected. |
| 541 * @private | 550 * @private |
| 542 */ | 551 */ |
| 543 onDefaultMinimumNoMarginsSelected_: function() { | 552 onDefaultMinimumNoMarginsSelected_: function() { |
| 544 this.removeCustomMarginEventListeners_(); | 553 this.removeCustomMarginEventListeners_(); |
| 545 this.forceDisplayingMarginLines_ = true; | 554 this.forceDisplayingMarginLines_ = true; |
| 546 setDefaultValuesAndRegeneratePreview(false); | 555 setDefaultValuesAndRegeneratePreview(false); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 * If custom margins is the currently selected option then change to the | 629 * If custom margins is the currently selected option then change to the |
| 621 * default margins option. | 630 * default margins option. |
| 622 * @private | 631 * @private |
| 623 */ | 632 */ |
| 624 resetMarginsIfNeeded: function() { | 633 resetMarginsIfNeeded: function() { |
| 625 if (this.isCustomMarginsSelected()) { | 634 if (this.isCustomMarginsSelected()) { |
| 626 this.marginList_.options[ | 635 this.marginList_.options[ |
| 627 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; | 636 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
| 628 this.removeCustomMarginEventListeners_(); | 637 this.removeCustomMarginEventListeners_(); |
| 629 this.forceDisplayingMarginLines_ = true; | 638 this.forceDisplayingMarginLines_ = true; |
| 630 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | |
| 631 } | 639 } |
| 632 }, | 640 }, |
| 633 | 641 |
| 634 /** | 642 /** |
| 635 * Executes when a |customEvents.PDF_LOADED| event occurs. | 643 * Executes when a |customEvents.PDF_LOADED| event occurs. |
| 636 * @private | 644 * @private |
| 637 */ | 645 */ |
| 638 onPDFLoaded_: function() { | 646 onPDFLoaded_: function() { |
| 639 if (!previewModifiable) | 647 if (!previewModifiable) { |
| 640 fadeOutOption(this.marginsOption_); | 648 fadeOutOption(this.marginsOption_); |
| 649 return; | |
| 650 } | |
| 651 | |
| 652 if (this.optionToRestore_ && | |
| 653 this.optionToRestore_ == MarginSettings.MARGINS_VALUE_CUSTOM) { | |
| 654 this.onCustomMarginsSelected_(); | |
| 655 this.optionToRestore_ = null; | |
| 656 } | |
| 641 } | 657 } |
| 642 }; | 658 }; |
| 643 | 659 |
| 644 return { | 660 return { |
| 645 MarginSettings: MarginSettings, | 661 MarginSettings: MarginSettings, |
| 646 PageLayout: PageLayout, | 662 PageLayout: PageLayout, |
| 663 setLastUsedMargins: MarginSettings.prototype.setLastUsedMargins, | |
| 647 setNumberFormatAndMeasurementSystem: | 664 setNumberFormatAndMeasurementSystem: |
| 648 MarginSettings.setNumberFormatAndMeasurementSystem, | 665 MarginSettings.setNumberFormatAndMeasurementSystem, |
| 649 }; | 666 }; |
| 650 }); | 667 }); |
| OLD | NEW |