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.getMarginOptionIndexByValue_(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 * @private | |
246 */ | |
247 getMarginOptionIndexByValue_: function(marginTypeValue) { | |
248 var options = this.marginList_.options; | |
249 for (var i = 0; i < options.length; i++) { | |
250 if (options[i].getAttribute('value') == marginTypeValue) | |
251 return i; | |
252 } | |
253 return 0; | |
kmadhusu
2011/11/01 22:41:00
nit: 0 => MarginSettings.OPTION_INDEX_DEFAULT
| |
254 }, | |
255 | |
256 /** | |
229 * @return {boolean} True if default margins are selected. | 257 * @return {boolean} True if default margins are selected. |
230 */ | 258 */ |
231 isDefaultMarginsSelected: function() { | 259 isDefaultMarginsSelected: function() { |
232 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; | 260 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; |
233 }, | 261 }, |
234 | 262 |
235 /** | 263 /** |
236 * @return {boolean} True if no margins are selected. | 264 * @return {boolean} True if no margins are selected. |
237 */ | 265 */ |
238 isNoMarginsSelected: function() { | 266 isNoMarginsSelected: function() { |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 }, | 617 }, |
590 | 618 |
591 /** | 619 /** |
592 * 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 |
593 * default margins option. | 621 * default margins option. |
594 * @private | 622 * @private |
595 */ | 623 */ |
596 resetMarginsIfNeeded: function() { | 624 resetMarginsIfNeeded: function() { |
597 if (this.isCustomMarginsSelected()) { | 625 if (this.isCustomMarginsSelected()) { |
598 this.marginList_.options[ | 626 this.marginList_.options[ |
599 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; | 627 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
600 this.removeCustomMarginEventListeners_(); | 628 this.removeCustomMarginEventListeners_(); |
601 this.forceDisplayingMarginLines_ = true; | 629 this.forceDisplayingMarginLines_ = true; |
602 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 630 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
603 } | 631 } |
604 }, | 632 }, |
605 | 633 |
606 /** | 634 /** |
607 * Executes when a |customEvents.PDF_LOADED| event occurs. | 635 * Executes when a |customEvents.PDF_LOADED| event occurs. |
608 * @private | 636 * @private |
609 */ | 637 */ |
610 onPDFLoaded_: function() { | 638 onPDFLoaded_: function() { |
611 if (!previewModifiable) | 639 if (!previewModifiable) |
612 fadeOutOption(this.marginsOption_); | 640 fadeOutOption(this.marginsOption_); |
613 } | 641 } |
614 }; | 642 }; |
615 | 643 |
616 return { | 644 return { |
617 MarginSettings: MarginSettings, | 645 MarginSettings: MarginSettings, |
618 PageLayout: PageLayout, | 646 PageLayout: PageLayout, |
619 setNumberFormatAndMeasurementSystem: | 647 setNumberFormatAndMeasurementSystem: |
620 MarginSettings.setNumberFormatAndMeasurementSystem, | 648 MarginSettings.setNumberFormatAndMeasurementSystem, |
621 }; | 649 }; |
622 }); | 650 }); |
OLD | NEW |