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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // @type {EventTracker} Used to keep track of certain event listeners. | 144 // @type {EventTracker} Used to keep track of certain event listeners. |
| 145 this.eventTracker_ = new EventTracker(); | 145 this.eventTracker_ = new EventTracker(); |
| 146 | 146 |
| 147 this.addEventListeners_(); | 147 this.addEventListeners_(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Number of points per inch. | 150 // Number of points per inch. |
| 151 MarginSettings.POINTS_PER_INCH = 72; | 151 MarginSettings.POINTS_PER_INCH = 72; |
| 152 // Minimum allowed distance in points between top-bottom, left-right margins. | 152 // Minimum allowed distance in points between top-bottom, left-right margins. |
| 153 MarginSettings.MINIMUM_MARGINS_DISTANCE = 36; | 153 MarginSettings.MINIMUM_MARGINS_DISTANCE = 36; |
| 154 // Margin list values. | 154 // Margin list values. Matches enum MarginType in |
| 155 // printing/print_job_constants.h. | |
| 155 MarginSettings.MARGINS_VALUE_DEFAULT = 0; | 156 MarginSettings.MARGINS_VALUE_DEFAULT = 0; |
| 156 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; | 157 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; |
| 157 MarginSettings.MARGINS_VALUE_CUSTOM = 2; | 158 MarginSettings.MARGINS_VALUE_MINIMUM = 2; |
| 158 MarginSettings.MARGINS_VALUE_MINIMUM = 3; | 159 MarginSettings.MARGINS_VALUE_CUSTOM = 3; |
| 159 // Default Margins option index. | 160 // Default Margins option index. |
| 160 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0; | 161 MarginSettings.OPTION_INDEX_DEFAULT = 0; |
| 161 // Group name corresponding to the top margin. | 162 // Group name corresponding to the top margin. |
| 162 MarginSettings.TOP_GROUP = 'top'; | 163 MarginSettings.TOP_GROUP = 'top'; |
| 163 // Group name corresponding to the left margin. | 164 // Group name corresponding to the left margin. |
| 164 MarginSettings.LEFT_GROUP = 'left'; | 165 MarginSettings.LEFT_GROUP = 'left'; |
| 165 // Group name corresponding to the right margin. | 166 // Group name corresponding to the right margin. |
| 166 MarginSettings.RIGHT_GROUP = 'right'; | 167 MarginSettings.RIGHT_GROUP = 'right'; |
| 167 // Group name corresponding to the bottom margin. | 168 // Group name corresponding to the bottom margin. |
| 168 MarginSettings.BOTTOM_GROUP = 'bottom'; | 169 MarginSettings.BOTTOM_GROUP = 'bottom'; |
| 169 | 170 |
| 170 /** | 171 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 204 |
| 204 /** | 205 /** |
| 205 * @return {number} The value of the selected margin option. | 206 * @return {number} The value of the selected margin option. |
| 206 */ | 207 */ |
| 207 get selectedMarginsValue() { | 208 get selectedMarginsValue() { |
| 208 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | 209 var val = this.marginList_.options[this.marginList_.selectedIndex].value; |
| 209 return parseInt(val, 10); | 210 return parseInt(val, 10); |
| 210 }, | 211 }, |
| 211 | 212 |
| 212 /** | 213 /** |
| 214 * Sets the current margin selection to |lastUsedMarginsType|. | |
| 215 * @param {number} lastUsedMarginsType An integer value identifying a margin | |
| 216 * type according to MarginType enum in printing/print_job_constants.h. | |
| 217 */ | |
| 218 setLastUsedMarginsType: function(lastUsedMarginsType) { | |
| 219 this.marginList_.selectedIndex = | |
| 220 this.marginValueTypeToIndex(lastUsedMarginsType); | |
| 221 }, | |
| 222 | |
| 223 /** | |
| 213 * @return {number} The total width of the plugin in points. | 224 * @return {number} The total width of the plugin in points. |
| 214 */ | 225 */ |
| 215 get totalWidthInPoints() { | 226 get totalWidthInPoints() { |
| 216 var pageInformation = previewArea.pageLocationNormalized; | 227 var pageInformation = previewArea.pageLocationNormalized; |
| 217 return this.pageWidth_ / pageInformation.width; | 228 return this.pageWidth_ / pageInformation.width; |
| 218 }, | 229 }, |
| 219 | 230 |
| 220 /** | 231 /** |
| 221 * @return {number} The total height of the plugin in points. | 232 * @return {number} The total height of the plugin in points. |
| 222 */ | 233 */ |
| 223 get totalHeightInPoints() { | 234 get totalHeightInPoints() { |
| 224 var pageInformation = previewArea.pageLocationNormalized; | 235 var pageInformation = previewArea.pageLocationNormalized; |
| 225 return this.pageHeight_ / pageInformation.height; | 236 return this.pageHeight_ / pageInformation.height; |
| 226 }, | 237 }, |
| 227 | 238 |
| 228 /** | 239 /** |
| 240 * Maps margin type values to indices within |this.marginList_|. | |
| 241 * @param {number} marginTypeValue An integer value identifying a margin | |
| 242 * type according to MarginType enum in printing/print_job_constants.h. | |
| 243 * @return {number} The index within |this.marginList_| that corrsponds to | |
| 244 * |marginTypeValue|. | |
| 245 */ | |
| 246 marginValueTypeToIndex: function(marginTypeValue) { | |
|
kmadhusu
2011/11/01 22:12:25
marginValueTypeToIndex => getMarginOptionIndexByV
kmadhusu
2011/11/01 22:12:25
private function?
dpapad
2011/11/01 22:38:34
Done.
dpapad
2011/11/01 22:38:34
Done.
| |
| 247 var options = this.marginList_.options; | |
| 248 for (var i = 0; i < options.length; i++) { | |
| 249 if (options[i].getAttribute('value') == marginTypeValue) | |
| 250 return i; | |
| 251 } | |
| 252 return 0; | |
| 253 }, | |
| 254 | |
| 255 /** | |
| 229 * @return {boolean} True if default margins are selected. | 256 * @return {boolean} True if default margins are selected. |
| 230 */ | 257 */ |
| 231 isDefaultMarginsSelected: function() { | 258 isDefaultMarginsSelected: function() { |
| 232 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; | 259 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; |
| 233 }, | 260 }, |
| 234 | 261 |
| 235 /** | 262 /** |
| 236 * @return {boolean} True if no margins are selected. | 263 * @return {boolean} True if no margins are selected. |
| 237 */ | 264 */ |
| 238 isNoMarginsSelected: function() { | 265 isNoMarginsSelected: function() { |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 }, | 616 }, |
| 590 | 617 |
| 591 /** | 618 /** |
| 592 * If custom margins is the currently selected option then change to the | 619 * If custom margins is the currently selected option then change to the |
| 593 * default margins option. | 620 * default margins option. |
| 594 * @private | 621 * @private |
| 595 */ | 622 */ |
| 596 resetMarginsIfNeeded: function() { | 623 resetMarginsIfNeeded: function() { |
| 597 if (this.isCustomMarginsSelected()) { | 624 if (this.isCustomMarginsSelected()) { |
| 598 this.marginList_.options[ | 625 this.marginList_.options[ |
| 599 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; | 626 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
| 600 this.removeCustomMarginEventListeners_(); | 627 this.removeCustomMarginEventListeners_(); |
| 601 this.forceDisplayingMarginLines_ = true; | 628 this.forceDisplayingMarginLines_ = true; |
| 602 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 629 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
| 603 } | 630 } |
| 604 }, | 631 }, |
| 605 | 632 |
| 606 /** | 633 /** |
| 607 * Executes when a |customEvents.PDF_LOADED| event occurs. | 634 * Executes when a |customEvents.PDF_LOADED| event occurs. |
| 608 * @private | 635 * @private |
| 609 */ | 636 */ |
| 610 onPDFLoaded_: function() { | 637 onPDFLoaded_: function() { |
| 611 if (!previewModifiable) | 638 if (!previewModifiable) |
| 612 fadeOutOption(this.marginsOption_); | 639 fadeOutOption(this.marginsOption_); |
| 613 } | 640 } |
| 614 }; | 641 }; |
| 615 | 642 |
| 616 return { | 643 return { |
| 617 MarginSettings: MarginSettings, | 644 MarginSettings: MarginSettings, |
| 618 PageLayout: PageLayout, | 645 PageLayout: PageLayout, |
| 619 setNumberFormatAndMeasurementSystem: | 646 setNumberFormatAndMeasurementSystem: |
| 620 MarginSettings.setNumberFormatAndMeasurementSystem, | 647 MarginSettings.setNumberFormatAndMeasurementSystem, |
| 621 }; | 648 }; |
| 622 }); | 649 }); |
| OLD | NEW |