Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/resources/print_preview/margin_settings.js

Issue 8351048: Print Preview: Making margin selection sticky (part 2/2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 {boolean} True if the margins UI should be diplayed when the next
kmadhusu 2011/11/03 17:35:38 As per the comments, Margins options will not be s
133 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; 133 // |customEvents.PDF_LOADED| event occurs.
134 134 this.forceMarginsUIOnPDFLoad_ = false;
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 /** 205 /**
206 * Sets |this.customMargins_| according to |margins|.
207 * @param {{marginLeft: number, marginTop: number, marginRight: bottom,
208 * marginRight: number}} margins An object holding the four margin
209 * values.
210 */
211 set customMargins(margins) {
212 this.customMargins_.left = margins.marginLeft;
213 this.customMargins_.top = margins.marginTop;
214 this.customMargins_.right = margins.marginRight;
215 this.customMargins_.bottom = margins.marginBottom;
216 },
217
218 /**
206 * @return {number} The value of the selected margin option. 219 * @return {number} The value of the selected margin option.
207 */ 220 */
208 get selectedMarginsValue() { 221 get selectedMarginsValue() {
209 var val = this.marginList_.options[this.marginList_.selectedIndex].value; 222 var val = this.marginList_.options[this.marginList_.selectedIndex].value;
210 return parseInt(val, 10); 223 return parseInt(val, 10);
211 }, 224 },
212 225
213 /** 226 /**
214 * Sets the current margin selection to |lastUsedMarginsType|. 227 * Sets the current margin selection to |lastUsedMarginsType|.
215 * @param {number} lastUsedMarginsType An integer value identifying a margin 228 * @param {number} lastUsedMarginsType An integer value identifying a margin
216 * type according to MarginType enum in printing/print_job_constants.h. 229 * type according to MarginType enum in printing/print_job_constants.h.
230 * @param {Object} lastUsedMargins The last used margins. It is undefined if
vandebo (ex-Chrome) 2011/11/03 18:07:27 nit: It is only used if |lastUsedMarginsType| == M
dpapad 2011/11/03 18:48:27 Done.
231 * |lastUsedMarginsType| differs from
232 * |MarginSettings.MARGINS_VALUE_CUSTOM|.
217 */ 233 */
218 setLastUsedMarginsType: function(lastUsedMarginsType) { 234 setLastUsedMargins: function(lastUsedMarginsType, lastUsedMargins) {
235 this.forceMarginsUIOnPDFLoad_ =
236 lastUsedMarginsType == MarginSettings.MARGINS_VALUE_CUSTOM;
219 this.marginList_.selectedIndex = 237 this.marginList_.selectedIndex =
220 this.getMarginOptionIndexByValue_(lastUsedMarginsType); 238 this.getMarginOptionIndexByValue_(lastUsedMarginsType);
239 if (lastUsedMargins)
240 this.customMargins = lastUsedMargins;
221 }, 241 },
222 242
223 /** 243 /**
224 * @return {number} The total width of the plugin in points. 244 * @return {number} The total width of the plugin in points.
225 */ 245 */
226 get totalWidthInPoints() { 246 get totalWidthInPoints() {
227 var pageInformation = previewArea.pageLocationNormalized; 247 var pageInformation = previewArea.pageLocationNormalized;
228 return this.pageWidth_ / pageInformation.width; 248 return this.pageWidth_ / pageInformation.width;
229 }, 249 },
230 250
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 * Executes when user selects a different margin option, ie, 545 * Executes when user selects a different margin option, ie,
526 * |this.marginList_.selectedIndex| is changed. 546 * |this.marginList_.selectedIndex| is changed.
527 * @private 547 * @private
528 */ 548 */
529 onMarginsChanged_: function() { 549 onMarginsChanged_: function() {
530 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() || 550 if (this.isDefaultMarginsSelected() || this.isMinimumMarginsSelected() ||
531 this.isNoMarginsSelected()) 551 this.isNoMarginsSelected())
532 this.onDefaultMinimumNoMarginsSelected_(); 552 this.onDefaultMinimumNoMarginsSelected_();
533 else if (this.isCustomMarginsSelected()) 553 else if (this.isCustomMarginsSelected())
534 this.onCustomMarginsSelected_(); 554 this.onCustomMarginsSelected_();
535
536 this.lastSelectedOption_ = this.selectedMarginsValue;
537 }, 555 },
538 556
539 /** 557 /**
540 * Executes when the default or minimum or no margins option is selected. 558 * Executes when the default or minimum or no margins option is selected.
541 * @private 559 * @private
542 */ 560 */
543 onDefaultMinimumNoMarginsSelected_: function() { 561 onDefaultMinimumNoMarginsSelected_: function() {
544 this.removeCustomMarginEventListeners_(); 562 this.removeCustomMarginEventListeners_();
545 this.forceDisplayingMarginLines_ = true; 563 this.forceDisplayingMarginLines_ = true;
546 setDefaultValuesAndRegeneratePreview(false); 564 setDefaultValuesAndRegeneratePreview(false);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 * If custom margins is the currently selected option then change to the 638 * If custom margins is the currently selected option then change to the
621 * default margins option. 639 * default margins option.
622 * @private 640 * @private
623 */ 641 */
624 resetMarginsIfNeeded: function() { 642 resetMarginsIfNeeded: function() {
625 if (this.isCustomMarginsSelected()) { 643 if (this.isCustomMarginsSelected()) {
626 this.marginList_.options[ 644 this.marginList_.options[
627 MarginSettings.OPTION_INDEX_DEFAULT].selected = true; 645 MarginSettings.OPTION_INDEX_DEFAULT].selected = true;
628 this.removeCustomMarginEventListeners_(); 646 this.removeCustomMarginEventListeners_();
629 this.forceDisplayingMarginLines_ = true; 647 this.forceDisplayingMarginLines_ = true;
630 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT;
631 } 648 }
632 }, 649 },
633 650
634 /** 651 /**
635 * Executes when a |customEvents.PDF_LOADED| event occurs. 652 * Executes when a |customEvents.PDF_LOADED| event occurs.
636 * @private 653 * @private
637 */ 654 */
638 onPDFLoaded_: function() { 655 onPDFLoaded_: function() {
639 if (!previewModifiable) 656 if (!previewModifiable) {
640 fadeOutOption(this.marginsOption_); 657 fadeOutOption(this.marginsOption_);
658 return;
659 }
660
661 if (this.forceMarginsUIOnPDFLoad_) {
662 this.onCustomMarginsSelected_();
663 this.forceMarginsUIOnPDFLoad_ = false;
664 }
641 } 665 }
642 }; 666 };
643 667
644 return { 668 return {
645 MarginSettings: MarginSettings, 669 MarginSettings: MarginSettings,
646 PageLayout: PageLayout, 670 PageLayout: PageLayout,
671 setLastUsedMargins: MarginSettings.prototype.setLastUsedMargins,
647 setNumberFormatAndMeasurementSystem: 672 setNumberFormatAndMeasurementSystem:
648 MarginSettings.setNumberFormatAndMeasurementSystem, 673 MarginSettings.setNumberFormatAndMeasurementSystem,
649 }; 674 };
650 }); 675 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698