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 |
| 160 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0; | 161 // Indices in the dropdown correspoding to margins type. |
| 162 MarginSettings.OPTION_INDEX_DEFAULT = 0; | |
| 163 MarginSettings.OPTION_INDEX_NO_MARGINS = 1; | |
| 164 MarginSettings.OPTION_INDEX_MINIMUM = 2; | |
| 165 MarginSettings.OPTION_INDEX_CUSTOM = 3; | |
| 166 | |
| 161 // Group name corresponding to the top margin. | 167 // Group name corresponding to the top margin. |
| 162 MarginSettings.TOP_GROUP = 'top'; | 168 MarginSettings.TOP_GROUP = 'top'; |
| 163 // Group name corresponding to the left margin. | 169 // Group name corresponding to the left margin. |
| 164 MarginSettings.LEFT_GROUP = 'left'; | 170 MarginSettings.LEFT_GROUP = 'left'; |
| 165 // Group name corresponding to the right margin. | 171 // Group name corresponding to the right margin. |
| 166 MarginSettings.RIGHT_GROUP = 'right'; | 172 MarginSettings.RIGHT_GROUP = 'right'; |
| 167 // Group name corresponding to the bottom margin. | 173 // Group name corresponding to the bottom margin. |
| 168 MarginSettings.BOTTOM_GROUP = 'bottom'; | 174 MarginSettings.BOTTOM_GROUP = 'bottom'; |
| 169 | 175 |
| 170 /** | 176 /** |
| 171 * Extracts the number formatting and measurement system for the current | 177 * Extracts the number formatting and measurement system for the current |
| 172 * locale. | 178 * locale. |
| 173 * @param {string} numberFormat Is the formatted version of a sample number, | 179 * @param {string} numberFormat Is the formatted version of a sample number, |
| 174 * sent from the backend. | 180 * sent from the backend. |
| 175 * @oaram {number} measurementSystem 0 for SI (aka metric system), 1 for the | 181 * @oaram {number} measurementSystem 0 for SI (aka metric system), 1 for the |
| 176 * system used in the US. Note: Mathces UMeasurementSystem enum in | 182 * system used in the US. Note: Mathces UMeasurementSystem enum in |
| 177 * third_party/icu/public/i18n/unicode/ulocdata.h. | 183 * third_party/icu/public/i18n/unicode/ulocdata.h. |
| 178 */ | 184 */ |
| 179 MarginSettings.setNumberFormatAndMeasurementSystem = function( | 185 MarginSettings.setNumberFormatAndMeasurementSystem = function( |
| 180 numberFormat, measurementSystem) { | 186 numberFormat, measurementSystem) { |
| 181 var regex = /^(\d+)(\.|\,)(\d+)(\.|\,)(\d+)$/; | 187 var regex = /^(\d+)(\.|\,)(\d+)(\.|\,)(\d+)$/; |
| 182 var matches = numberFormat.match(regex); | 188 var matches = numberFormat.match(regex); |
| 183 MarginSettings.thousandsPoint = matches[2]; | 189 MarginSettings.thousandsPoint = matches[2]; |
| 184 MarginSettings.decimalPoint = matches[4]; | 190 MarginSettings.decimalPoint = matches[4]; |
| 185 MarginSettings.useMetricSystem = measurementSystem == 0; | 191 MarginSettings.useMetricSystem = measurementSystem == 0; |
| 186 }; | 192 }; |
| 187 | 193 |
| 194 /** | |
| 195 * @type {Object} Maps margin type values to indices within the drop-down | |
| 196 * margin list. | |
| 197 */ | |
| 198 MarginSettings.valueToIndex = {}; | |
|
kmadhusu
2011/11/01 17:17:57
Is there any specific reason to create this object
dpapad
2011/11/01 17:29:14
It happens to be the same, but this is not a const
| |
| 199 MarginSettings.valueToIndex[MarginSettings.MARGINS_VALUE_DEFAULT] = | |
| 200 MarginSettings.OPTION_INDEX_DEFAULT; | |
| 201 MarginSettings.valueToIndex[MarginSettings.MARGINS_VALUE_NO_MARGINS] = | |
| 202 MarginSettings.OPTION_INDEX_NO_MARGINS; | |
| 203 MarginSettings.valueToIndex[MarginSettings.MARGINS_VALUE_MINIMUM] = | |
| 204 MarginSettings.OPTION_INDEX_MINIMUM; | |
| 205 MarginSettings.valueToIndex[MarginSettings.MARGINS_VALUE_CUSTOM] = | |
| 206 MarginSettings.OPTION_INDEX_CUSTOM; | |
| 207 | |
| 188 cr.addSingletonGetter(MarginSettings); | 208 cr.addSingletonGetter(MarginSettings); |
| 189 | 209 |
| 190 MarginSettings.prototype = { | 210 MarginSettings.prototype = { |
| 191 /** | 211 /** |
| 192 * Returns a dictionary of the four custom margin values. | 212 * Returns a dictionary of the four custom margin values. |
| 193 * @return {object} | 213 * @return {object} |
| 194 */ | 214 */ |
| 195 get customMargins() { | 215 get customMargins() { |
| 196 var margins = {}; | 216 var margins = {}; |
| 197 margins.marginLeft = this.customMargins_.left; | 217 margins.marginLeft = this.customMargins_.left; |
| 198 margins.marginTop = this.customMargins_.top; | 218 margins.marginTop = this.customMargins_.top; |
| 199 margins.marginRight = this.customMargins_.right; | 219 margins.marginRight = this.customMargins_.right; |
| 200 margins.marginBottom = this.customMargins_.bottom; | 220 margins.marginBottom = this.customMargins_.bottom; |
| 201 return margins; | 221 return margins; |
| 202 }, | 222 }, |
| 203 | 223 |
| 204 /** | 224 /** |
| 205 * @return {number} The value of the selected margin option. | 225 * @return {number} The value of the selected margin option. |
| 206 */ | 226 */ |
| 207 get selectedMarginsValue() { | 227 get selectedMarginsValue() { |
| 208 var val = this.marginList_.options[this.marginList_.selectedIndex].value; | 228 var val = this.marginList_.options[this.marginList_.selectedIndex].value; |
| 209 return parseInt(val, 10); | 229 return parseInt(val, 10); |
| 210 }, | 230 }, |
| 211 | 231 |
| 212 /** | 232 /** |
| 233 * @param {number} The index to be selected within |this.marginList_|. | |
| 234 */ | |
| 235 set selectedMarginsIndex(index) { | |
| 236 this.marginList_.selectedIndex = index; | |
| 237 }, | |
| 238 | |
| 239 /** | |
| 213 * @return {number} The total width of the plugin in points. | 240 * @return {number} The total width of the plugin in points. |
| 214 */ | 241 */ |
| 215 get totalWidthInPoints() { | 242 get totalWidthInPoints() { |
| 216 var pageInformation = previewArea.pageLocationNormalized; | 243 var pageInformation = previewArea.pageLocationNormalized; |
| 217 return this.pageWidth_ / pageInformation.width; | 244 return this.pageWidth_ / pageInformation.width; |
| 218 }, | 245 }, |
| 219 | 246 |
| 220 /** | 247 /** |
| 221 * @return {number} The total height of the plugin in points. | 248 * @return {number} The total height of the plugin in points. |
| 222 */ | 249 */ |
| (...skipping 366 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 |