diff options
author | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 04:07:30 +0000 |
---|---|---|
committer | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 04:07:30 +0000 |
commit | 8b7d034cb32b95cd36463a23be0eee621146e150 (patch) | |
tree | ebf3da7bd9fc2ccc63364cefa7e05ae1c0679391 /chrome/browser/resources/print_preview | |
parent | 35a62d7067fd90e43945533d4f879e6f2a635958 (diff) | |
download | chromium_src-8b7d034cb32b95cd36463a23be0eee621146e150.zip chromium_src-8b7d034cb32b95cd36463a23be0eee621146e150.tar.gz chromium_src-8b7d034cb32b95cd36463a23be0eee621146e150.tar.bz2 |
Revert 110035 - Print Preview: Making margin selection sticky (part 2/2)
This CL makes "Custom" margins sticky across different preview sessions but also within the same preview session.
Here is a summary of all changes.
- Within same preview session: So far selecting "Custom" was
picking up from whatever the previous selected option was.
Now, "Custom" remembers the specified margins. To test this
select "Custom", do some dragging, then change to another
option and back to "Custom".
- Across preview sessions: Select "Custom", do some dragging,
then print. Open print preview again, the last used custom
margins are remembered.
- There was a bunch of messages sent from JS to get various
info/settings (initiator tab title, measurement system and
number format, last used margin settings, default printer).
I created a single message "getInitialSettings" to get all
at once (they are needed before the 1st preview is is
requested).
BUG=102446
TEST=See bug description.
Review URL: http://codereview.chromium.org/8351048
TBR=dpapad@chromium.org
Review URL: http://codereview.chromium.org/8564040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/print_preview')
-rw-r--r-- | chrome/browser/resources/print_preview/margin_settings.js | 130 | ||||
-rw-r--r-- | chrome/browser/resources/print_preview/print_preview.js | 49 |
2 files changed, 60 insertions, 119 deletions
diff --git a/chrome/browser/resources/print_preview/margin_settings.js b/chrome/browser/resources/print_preview/margin_settings.js index 8d8e67c..28092a3 100644 --- a/chrome/browser/resources/print_preview/margin_settings.js +++ b/chrome/browser/resources/print_preview/margin_settings.js @@ -40,8 +40,6 @@ cr.define('print_preview', function() { * @return {boolean} true if they are equal. */ isEqual: function(rhs) { - if (!rhs) - return false; return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] && this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] && this[MarginSettings.RIGHT_GROUP] === @@ -50,11 +48,15 @@ cr.define('print_preview', function() { rhs[MarginSettings.BOTTOM_GROUP]; }, - clone: function() { - return new Margins(this[MarginSettings.TOP_GROUP], - this[MarginSettings.LEFT_GROUP], - this[MarginSettings.RIGHT_GROUP], - this[MarginSettings.BOTTOM_GROUP]); + /** + * Copies the four margin values from |rhs|. + * @param {Margins} rhs The Margins object values to be used. + */ + copy: function(rhs) { + this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP]; + this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP]; + this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP]; + this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP]; }, /** @@ -91,7 +93,6 @@ cr.define('print_preview', function() { this.contentWidth_ = width; this.contentHeight_ = height; this.margins_ = new Margins(left, top, right, bottom); - this.margins_.roundToLocaleUnits(); } PageLayout.prototype = { @@ -121,18 +122,21 @@ cr.define('print_preview', function() { this.marginsUI_ = null; // Holds the custom margin values in points (if set). - this.customMargins_ = null; + this.customMargins_ = new Margins(-1, -1, -1, -1); // Holds the previous custom margin values in points. - this.previousCustomMargins_ = null; + this.previousCustomMargins_ = new Margins(-1, -1, -1, -1); // Holds the width of the page in points. this.pageWidth_ = -1; // Holds the height of the page in points. this.pageHeight_ = -1; - // @type {boolean} True if the margins UI should be diplayed when the next - // |customEvents.PDF_LOADED| event occurs. - this.forceMarginsUIOnPDFLoad_ = false; + // The last selected margin option. + this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; + // 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; @@ -199,19 +203,6 @@ cr.define('print_preview', function() { }, /** - * Sets |this.customMargins_| according to |margins|. - * @param {{marginLeft: number, marginTop: number, marginRight: number, - * marginBottom: 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() { @@ -220,26 +211,13 @@ cr.define('print_preview', function() { }, /** - * Sets the current margin selection to |lastUsedMarginType|. - * @param {number} lastUsedMarginType An integer value identifying a margin + * Sets the current margin selection to |lastUsedMarginsType|. + * @param {number} lastUsedMarginsType 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 - * |margin{Top|Bottom|Left|Right}| attributes are missing. - */ - setLastUsedMargins: function(lastUsedMarginsSettings) { - var lastUsedMarginsType = lastUsedMarginsSettings['marginsType'] - this.forceMarginsUIOnPDFLoad_ = - lastUsedMarginsType == MarginSettings.MARGINS_VALUE_CUSTOM; + */ + setLastUsedMarginsType: function(lastUsedMarginsType) { this.marginList_.selectedIndex = this.getMarginOptionIndexByValue_(lastUsedMarginsType); - if (lastUsedMarginsSettings.hasOwnProperty('marginTop') && - lastUsedMarginsSettings.hasOwnProperty('marginBottom') && - lastUsedMarginsSettings.hasOwnProperty('marginRight') && - lastUsedMarginsSettings.hasOwnProperty('marginLeft')) { - this.customMargins_ = new Margins(-1, -1, -1 , -1); - this.customMargins = lastUsedMarginsSettings; - } }, /** @@ -312,11 +290,9 @@ cr.define('print_preview', function() { requestPreviewIfNeeded_: function() { if (!this.areMarginSettingsValid()) return; - if (this.customMargins_.isEqual(this.previousCustomMargins_)) return; - - this.previousCustomMargins_ = this.customMargins_.clone(); + this.previousCustomMargins_.copy(this.customMargins_); setDefaultValuesAndRegeneratePreview(false); }, @@ -326,8 +302,6 @@ cr.define('print_preview', function() { * @private */ onSidebarMouseOver_: function(e) { - $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); - $('navbar-container').onmouseover = null; if (!this.forceDisplayingMarginLines_) this.marginsUI.hide(false); }, @@ -338,8 +312,6 @@ cr.define('print_preview', function() { * @private */ onMainviewMouseOver_: function() { - $('mainview').onmouseover = null; - $('navbar-container').onmouseover = this.onSidebarMouseOver_.bind(this); this.forceDisplayingMarginLines_ = false; this.marginsUI.show(); }, @@ -396,7 +368,7 @@ cr.define('print_preview', function() { * @return {boolean} True if the margin settings are valid. */ areMarginSettingsValid: function() { - if (!this.isCustomMarginsSelected() || !this.marginsUI_) + if (this.marginsUI_ == null) return true; var pairs = this.marginsUI.pairsAsList; @@ -502,8 +474,6 @@ cr.define('print_preview', function() { * @private */ removeCustomMarginEventListeners_: function() { - if (!this.marginsUI_) - return; $('mainview').onmouseover = null; $('navbar-container').onmouseover = null; this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); @@ -562,6 +532,8 @@ cr.define('print_preview', function() { this.onDefaultMinimumNoMarginsSelected_(); else if (this.isCustomMarginsSelected()) this.onCustomMarginsSelected_(); + + this.lastSelectedOption_ = this.selectedMarginsValue; }, /** @@ -571,7 +543,6 @@ cr.define('print_preview', function() { onDefaultMinimumNoMarginsSelected_: function() { this.removeCustomMarginEventListeners_(); this.forceDisplayingMarginLines_ = true; - this.previousCustomMargins_ = null; setDefaultValuesAndRegeneratePreview(false); }, @@ -580,18 +551,20 @@ cr.define('print_preview', function() { * @private */ onCustomMarginsSelected_: function() { - var customMarginsNotSpecified = !this.customMargins_; - this.updatePageData_(); + this.addCustomMarginEventListeners_(); - if (customMarginsNotSpecified) { - this.previousCustomMargins_ = this.customMargins_.clone(); - this.drawCustomMarginsUI_(); - this.addCustomMarginEventListeners_(); - this.marginsUI.show(); - } else { - this.forceMarginsUIOnPDFLoad_ = true; - this.requestPreviewIfNeeded_(); + this.customMargins_ = this.currentDefaultPageLayout.margins_; + this.customMargins_.roundToLocaleUnits(); + this.previousCustomMargins_.copy(this.customMargins_); + + if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { + this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; + this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; } + + this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; + this.drawCustomMarginsUI_(); + this.marginsUI.show(); }, /** @@ -654,8 +627,7 @@ cr.define('print_preview', function() { MarginSettings.OPTION_INDEX_DEFAULT].selected = true; this.removeCustomMarginEventListeners_(); this.forceDisplayingMarginLines_ = true; - this.customMargins_ = null; - this.previousCustomMargins_ = null; + this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; } }, @@ -664,35 +636,15 @@ 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_ = this.currentDefaultPageLayout.margins_.clone(); - - this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; - this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; } }; return { MarginSettings: MarginSettings, PageLayout: PageLayout, + setNumberFormatAndMeasurementSystem: + MarginSettings.setNumberFormatAndMeasurementSystem, }; }); diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js index 036f549..2491944 100644 --- a/chrome/browser/resources/print_preview/print_preview.js +++ b/chrome/browser/resources/print_preview/print_preview.js @@ -164,25 +164,9 @@ function onLoad() { $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; previewArea.showLoadingAnimation(); - chrome.send('getInitialSettings'); -} - -/** - * @param {string} initiatorTabTitle The title of the initiator tab. - * @param {object} initialSettings An object containing all the initial - * settings. - */ -function setInitialSettings(initialSettings) { - setInitiatorTabTitle(initialSettings['initiatorTabTitle']); - previewModifiable = initialSettings['previewModifiable']; - if (previewModifiable) { - print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( - initialSettings['numberFormat'], - initialSettings['measurementSystem']); - marginSettings.setLastUsedMargins(initialSettings); - } - setDefaultPrinter(initialSettings['printerName'], - initialSettings['cloudPrintData']); + chrome.send('getInitiatorTabTitle'); + chrome.send('getDefaultPrinter'); + chrome.send('getNumberFormatAndMeasurementSystem'); } /** @@ -300,9 +284,7 @@ function updateControlsWithSelectedPrinterCapabilities() { lastSelectedPrinterIndex = selectedIndex; // Regenerate the preview data based on selected printer settings. - // Do not reset the margins if no preview request has been made. - var resetMargins = lastPreviewRequestID != initialPreviewRequestID; - setDefaultValuesAndRegeneratePreview(resetMargins); + setDefaultValuesAndRegeneratePreview(true); } } @@ -322,9 +304,7 @@ function doUpdateCloudPrinterCapabilities(printer) { lastSelectedPrinterIndex = selectedIndex; // Regenerate the preview data based on selected printer settings. - // Do not reset the margins if no preview request has been made. - var resetMargins = lastPreviewRequestID != initialPreviewRequestID; - setDefaultValuesAndRegeneratePreview(resetMargins); + setDefaultValuesAndRegeneratePreview(true); } /** @@ -598,14 +578,18 @@ function fileSelectionCompleted() { * @param {string} printer Name of the default printer. Empty if none. * @param {string} cloudPrintData Cloud print related data to restore if * the default printer is a cloud printer. + * @param {number} lastUsedMarginsType Indicates the last used margins type + * (matches enum MarginType in printing/print_job_constants.h. */ -function setDefaultPrinter(printerName, cloudPrintData) { +function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { + // Setting the margin selection to the last used one. + marginSettings.setLastUsedMarginsType(lastUsedMarginsType); // Add a placeholder value so the printer list looks valid. addDestinationListOption('', '', true, true, true); - if (printerName) { - defaultOrLastUsedPrinterName = printerName; + if (printer_name) { + defaultOrLastUsedPrinterName = printer_name; if (cloudPrintData) { - cloudprint.setDefaultPrinter(printerName, + cloudprint.setDefaultPrinter(printer_name, cloudPrintData, addDestinationListOptionAtPosition, doUpdateCloudPrinterCapabilities); @@ -795,13 +779,16 @@ function setPluginPreviewPageCount() { * Update the page count and check the page range. * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). * @param {number} pageCount The number of pages. + * @param {boolean} isModifiable Indicates whether the previewed document can be + * modified. * @param {number} previewResponseId The preview request id that resulted in * this response. */ -function onDidGetPreviewPageCount(pageCount, previewResponseId) { +function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { if (!isExpectedPreviewResponse(previewResponseId)) return; pageSettings.updateState(pageCount); + previewModifiable = isModifiable; if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) return; @@ -1071,6 +1058,8 @@ PrintSettings.prototype.save = function() { /** * Updates the title of the print preview tab according to |initiatorTabTitle|. + * Called from PrintPreviewUI::OnGetInitiatorTabTitle as a result of sending a + * 'getInitiatorTabTitle' message. * @param {string} initiatorTabTitle The title of the initiator tab. */ function setInitiatorTabTitle(initiatorTabTitle) { |