Chromium Code Reviews| Index: chrome/browser/resources/print_preview/margin_settings.js |
| diff --git a/chrome/browser/resources/print_preview/margin_settings.js b/chrome/browser/resources/print_preview/margin_settings.js |
| index 11577c22508f3aa6f908a88ef00cd7ed814efe20..dbce88328898aa608d20e277f2dda4f04f003aee 100644 |
| --- a/chrome/browser/resources/print_preview/margin_settings.js |
| +++ b/chrome/browser/resources/print_preview/margin_settings.js |
| @@ -93,6 +93,7 @@ cr.define('print_preview', function() { |
| this.contentWidth_ = width; |
| this.contentHeight_ = height; |
| this.margins_ = new Margins(left, top, right, bottom); |
| + this.margins_.roundToLocaleUnits(); |
| } |
| PageLayout.prototype = { |
| @@ -122,21 +123,18 @@ cr.define('print_preview', function() { |
| this.marginsUI_ = null; |
| // Holds the custom margin values in points (if set). |
| - this.customMargins_ = new Margins(-1, -1, -1, -1); |
| + this.customMargins_ = null; |
| // Holds the previous custom margin values in points. |
| - this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); |
| + this.previousCustomMargins_ = null; |
| // Holds the width of the page in points. |
| this.pageWidth_ = -1; |
| // Holds the height of the page in points. |
| this.pageHeight_ = -1; |
| - // The last selected margin option. |
| - this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
| - |
| + // @type {boolean} True if the margins UI should be diplayed when the next |
| + // |customEvents.PDF_LOADED| event occurs. |
| + this.forceMarginsUIOnPDFLoad_ = false; |
| // Holds the currently updated default page layout values. |
| this.currentDefaultPageLayout = null; |
| - // Holds the default page layout values when the custom margins was last |
| - // selected. |
| - this.previousDefaultPageLayout_ = null; |
| // True if the margins UI should be shown regardless of mouse position. |
| this.forceDisplayingMarginLines_ = true; |
| @@ -203,6 +201,19 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| + * Sets |this.customMargins_| according to |margins|. |
| + * @param {{marginLeft: number, marginTop: number, marginRight: bottom, |
|
kmadhusu
2011/11/09 00:57:54
"marginRight: bottom" => "marginBottom: number"
dpapad
2011/11/09 03:19:00
Done.
|
| + * marginRight: number}} margins An object holding the four margin |
| + * values. |
| + */ |
| + set customMargins(margins) { |
| + this.customMargins_.left = margins.marginLeft; |
| + this.customMargins_.top = margins.marginTop; |
| + this.customMargins_.right = margins.marginRight; |
| + this.customMargins_.bottom = margins.marginBottom; |
| + }, |
| + |
| + /** |
| * @return {number} The value of the selected margin option. |
| */ |
| get selectedMarginsValue() { |
| @@ -211,13 +222,22 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| - * Sets the current margin selection to |lastUsedMarginsType|. |
| - * @param {number} lastUsedMarginsType An integer value identifying a margin |
| + * Sets the current margin selection to |lastUsedMarginType|. |
| + * @param {number} lastUsedMarginType An integer value identifying a margin |
| * type according to MarginType enum in printing/print_job_constants.h. |
| + * @param {Object} lastUsedCustomMargins The last used custom margins. If |
| + * custom margins have not been used before |
|
kmadhusu
2011/11/09 00:57:54
nit:
@param {Object} lastUsedCustomMargins The la
dpapad
2011/11/09 03:19:00
As discussed in IM, this is not true anymore, last
|
| + * |margin{Top|Bottom|Left|Right}| attributes are missing. |
| */ |
| - setLastUsedMarginsType: function(lastUsedMarginsType) { |
| + setLastUsedMargins: function(lastUsedMarginType, lastUsedCustomMargins) { |
| + this.forceMarginsUIOnPDFLoad_ = |
| + lastUsedMarginType == MarginSettings.MARGINS_VALUE_CUSTOM; |
| this.marginList_.selectedIndex = |
| - this.getMarginOptionIndexByValue_(lastUsedMarginsType); |
| + this.getMarginOptionIndexByValue_(lastUsedMarginType); |
| + if (lastUsedCustomMargins.hasOwnProperty('marginTop')) { |
| + this.customMargins_ = new Margins(-1, -1, -1 , -1); |
| + this.customMargins = lastUsedCustomMargins; |
|
kmadhusu
2011/11/09 00:57:54
"this.customMargins" => "this.customMargins_"? Mis
dpapad
2011/11/09 03:19:00
This is on purpose, leaving the underscore out, ca
|
| + } |
| }, |
| /** |
| @@ -290,8 +310,13 @@ cr.define('print_preview', function() { |
| requestPreviewIfNeeded_: function() { |
| if (!this.areMarginSettingsValid()) |
| return; |
| - if (this.customMargins_.isEqual(this.previousCustomMargins_)) |
| + |
| + if (this.previousCustomMargins_ && |
| + this.customMargins_.isEqual(this.previousCustomMargins_)) |
| return; |
| + |
| + if (!this.previousCustomMargins_) |
| + this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); |
| this.previousCustomMargins_.copy(this.customMargins_); |
|
kmadhusu
2011/11/09 00:57:54
Do you need to the same in line 239?
this.customM
dpapad
2011/11/09 03:19:00
It is not needed there, because a preview request
|
| setDefaultValuesAndRegeneratePreview(false); |
| }, |
| @@ -302,6 +327,8 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| onSidebarMouseOver_: function(e) { |
| + $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); |
| + $('sidebar').onmouseover = null; |
| if (!this.forceDisplayingMarginLines_) |
| this.marginsUI.hide(false); |
| }, |
| @@ -312,6 +339,8 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| onMainviewMouseOver_: function() { |
| + $('mainview').onmouseover = null; |
| + $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); |
| this.forceDisplayingMarginLines_ = false; |
| this.marginsUI.show(); |
| }, |
| @@ -368,7 +397,7 @@ cr.define('print_preview', function() { |
| * @return {boolean} True if the margin settings are valid. |
| */ |
| areMarginSettingsValid: function() { |
| - if (this.marginsUI_ == null) |
| + if (!this.isCustomMarginsSelected() || !this.marginsUI_) |
| return true; |
| var pairs = this.marginsUI.pairsAsList; |
| @@ -474,6 +503,8 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| removeCustomMarginEventListeners_: function() { |
| + if (!this.marginsUI_) |
| + return; |
| $('mainview').onmouseover = null; |
| $('sidebar').onmouseover = null; |
| this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); |
| @@ -532,8 +563,6 @@ cr.define('print_preview', function() { |
| this.onDefaultMinimumNoMarginsSelected_(); |
| else if (this.isCustomMarginsSelected()) |
| this.onCustomMarginsSelected_(); |
| - |
| - this.lastSelectedOption_ = this.selectedMarginsValue; |
| }, |
| /** |
| @@ -543,6 +572,7 @@ cr.define('print_preview', function() { |
| onDefaultMinimumNoMarginsSelected_: function() { |
| this.removeCustomMarginEventListeners_(); |
| this.forceDisplayingMarginLines_ = true; |
| + this.previousCustomMargins_ = null; |
| setDefaultValuesAndRegeneratePreview(false); |
| }, |
| @@ -551,20 +581,19 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| onCustomMarginsSelected_: function() { |
| - this.addCustomMarginEventListeners_(); |
| - |
| - this.customMargins_ = this.currentDefaultPageLayout.margins_; |
| - this.customMargins_.roundToLocaleUnits(); |
| - this.previousCustomMargins_.copy(this.customMargins_); |
| + var customMarginsNotSpecified = !this.customMargins_; |
| + this.updatePageData_(); |
| - if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { |
| - this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; |
| - this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; |
| + if (customMarginsNotSpecified) { |
|
kmadhusu
2011/11/09 00:57:54
customMarginsNotSpecified variable is not required
dpapad
2011/11/09 03:19:00
this.updatePageData_ will initialize |this.customM
|
| + this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); |
| + this.previousCustomMargins_.copy(this.customMargins_); |
|
kmadhusu
2011/11/09 00:57:54
this.customMargins_ is null here.
Instead of lin
kmadhusu
2011/11/09 00:57:54
Can you create a helper function to do the followi
dpapad
2011/11/09 03:19:00
|this.customMargins_| is not null here, explained
dpapad
2011/11/09 03:19:00
Done. Created a clone() function which is much mor
|
| + this.drawCustomMarginsUI_(); |
| + this.addCustomMarginEventListeners_(); |
| + this.marginsUI.show(); |
| + } else { |
| + this.forceMarginsUIOnPDFLoad_ = true; |
| + this.requestPreviewIfNeeded_(); |
| } |
| - |
| - this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; |
| - this.drawCustomMarginsUI_(); |
| - this.marginsUI.show(); |
| }, |
| /** |
| @@ -627,7 +656,6 @@ cr.define('print_preview', function() { |
| MarginSettings.OPTION_INDEX_DEFAULT].selected = true; |
| this.removeCustomMarginEventListeners_(); |
| this.forceDisplayingMarginLines_ = true; |
| - this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
| } |
| }, |
| @@ -636,15 +664,37 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| onPDFLoaded_: function() { |
| - if (!previewModifiable) |
| + if (!previewModifiable) { |
| fadeOutOption(this.marginsOption_); |
| + return; |
| + } |
| + |
| + if (this.forceMarginsUIOnPDFLoad_) { |
| + this.updatePageData_(); |
| + this.drawCustomMarginsUI_(); |
| + this.addCustomMarginEventListeners_(); |
| + this.marginsUI.show(); |
| + this.forceMarginsUIOnPDFLoad_ = false; |
| + } |
| + }, |
| + |
| + /** |
| + * Updates |this.customMargins_|, |this.pageWidth_|, |this.pageHeight_|. |
| + * @private |
| + */ |
| + updatePageData_: function() { |
| + if (!this.customMargins_) { |
| + this.customMargins_ = new Margins(-1, -1, -1. -1); |
| + this.customMargins_.copy(this.currentDefaultPageLayout.margins_); |
| + } |
| + |
| + this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; |
| + this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; |
| } |
| }; |
| return { |
| MarginSettings: MarginSettings, |
| PageLayout: PageLayout, |
| - setNumberFormatAndMeasurementSystem: |
| - MarginSettings.setNumberFormatAndMeasurementSystem, |
| }; |
| }); |