Commit 1943d11a authored by dpapad@chromium.org's avatar dpapad@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110035 0039d316-1c4b-4281-b951-d872f2087c98
parent a4a092b1
...@@ -99,8 +99,16 @@ PrintPreviewUI* PrintPreviewMessageHandler::OnFailure(int document_cookie) { ...@@ -99,8 +99,16 @@ PrintPreviewUI* PrintPreviewMessageHandler::OnFailure(int document_cookie) {
return static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); return static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
} }
void PrintPreviewMessageHandler::OnRequestPrintPreview() { void PrintPreviewMessageHandler::OnRequestPrintPreview(
bool source_is_modifiable) {
PrintPreviewTabController::PrintPreview(tab_contents_wrapper()); PrintPreviewTabController::PrintPreview(tab_contents_wrapper());
TabContentsWrapper* print_preview_tab = GetPrintPreviewTab();
if (!print_preview_tab || !print_preview_tab->web_ui())
return;
PrintPreviewUI* print_preview_ui =
static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
print_preview_ui->SetSourceIsModifiable(source_is_modifiable);
} }
void PrintPreviewMessageHandler::OnDidGetPreviewPageCount( void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
......
...@@ -43,7 +43,7 @@ class PrintPreviewMessageHandler : public TabContentsObserver { ...@@ -43,7 +43,7 @@ class PrintPreviewMessageHandler : public TabContentsObserver {
PrintPreviewUI* OnFailure(int document_cookie); PrintPreviewUI* OnFailure(int document_cookie);
// Message handlers. // Message handlers.
void OnRequestPrintPreview(); void OnRequestPrintPreview(bool source_is_modifiable);
void OnDidGetDefaultPageLayout( void OnDidGetDefaultPageLayout(
const printing::PageSizeMargins& page_layout_in_points); const printing::PageSizeMargins& page_layout_in_points);
void OnDidGetPreviewPageCount( void OnDidGetPreviewPageCount(
......
...@@ -316,25 +316,22 @@ PrintSystemTaskProxy::~PrintSystemTaskProxy() { ...@@ -316,25 +316,22 @@ PrintSystemTaskProxy::~PrintSystemTaskProxy() {
void PrintSystemTaskProxy::GetDefaultPrinter() { void PrintSystemTaskProxy::GetDefaultPrinter() {
VLOG(1) << "Get default printer start"; VLOG(1) << "Get default printer start";
StringValue* default_printer = NULL; std::string* default_printer = NULL;
if (PrintPreviewHandler::last_used_printer_name_ == NULL) { if (PrintPreviewHandler::last_used_printer_name_ == NULL) {
default_printer = new StringValue( default_printer = new std::string(print_backend_->GetDefaultPrinterName());
print_backend_->GetDefaultPrinterName());
} else { } else {
default_printer = new StringValue( default_printer = new std::string(
*PrintPreviewHandler::last_used_printer_name_); *PrintPreviewHandler::last_used_printer_name_);
} }
std::string default_printer_string;
default_printer->GetAsString(&default_printer_string);
VLOG(1) << "Get default printer finished, found: " VLOG(1) << "Get default printer finished, found: "
<< default_printer_string; << default_printer;
StringValue* cloud_print_data = NULL; std::string* cloud_print_data = NULL;
if (PrintPreviewHandler::last_used_printer_cloud_print_data_ != NULL) { if (PrintPreviewHandler::last_used_printer_cloud_print_data_ != NULL) {
cloud_print_data = new StringValue( cloud_print_data = new std::string(
*PrintPreviewHandler::last_used_printer_cloud_print_data_); *PrintPreviewHandler::last_used_printer_cloud_print_data_);
} else { } else {
cloud_print_data = new StringValue(""); cloud_print_data = new std::string;
} }
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -344,9 +341,9 @@ void PrintSystemTaskProxy::GetDefaultPrinter() { ...@@ -344,9 +341,9 @@ void PrintSystemTaskProxy::GetDefaultPrinter() {
} }
void PrintSystemTaskProxy::SendDefaultPrinter( void PrintSystemTaskProxy::SendDefaultPrinter(
const StringValue* default_printer, const StringValue* cloud_print_data) { const std::string* default_printer, const std::string* cloud_print_data) {
if (handler_) if (handler_)
handler_->SendDefaultPrinter(*default_printer, *cloud_print_data); handler_->SendInitialSettings(*default_printer, *cloud_print_data);
delete default_printer; delete default_printer;
} }
......
...@@ -55,8 +55,8 @@ class PrintSystemTaskProxy ...@@ -55,8 +55,8 @@ class PrintSystemTaskProxy
content::BrowserThread::UI>; content::BrowserThread::UI>;
friend class DeleteTask<PrintSystemTaskProxy>; friend class DeleteTask<PrintSystemTaskProxy>;
void SendDefaultPrinter(const base::StringValue* default_printer, void SendDefaultPrinter(const std::string* default_printer,
const base::StringValue* cloud_print_data); const std::string* cloud_print_data);
void SetupPrinterList(base::ListValue* printers); void SetupPrinterList(base::ListValue* printers);
void SendPrinterCapabilities(base::DictionaryValue* settings_info); void SendPrinterCapabilities(base::DictionaryValue* settings_info);
......
...@@ -40,6 +40,8 @@ cr.define('print_preview', function() { ...@@ -40,6 +40,8 @@ cr.define('print_preview', function() {
* @return {boolean} true if they are equal. * @return {boolean} true if they are equal.
*/ */
isEqual: function(rhs) { isEqual: function(rhs) {
if (!rhs)
return false;
return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] && return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] &&
this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] && this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] &&
this[MarginSettings.RIGHT_GROUP] === this[MarginSettings.RIGHT_GROUP] ===
...@@ -48,15 +50,11 @@ cr.define('print_preview', function() { ...@@ -48,15 +50,11 @@ cr.define('print_preview', function() {
rhs[MarginSettings.BOTTOM_GROUP]; rhs[MarginSettings.BOTTOM_GROUP];
}, },
/** clone: function() {
* Copies the four margin values from |rhs|. return new Margins(this[MarginSettings.TOP_GROUP],
* @param {Margins} rhs The Margins object values to be used. this[MarginSettings.LEFT_GROUP],
*/ this[MarginSettings.RIGHT_GROUP],
copy: function(rhs) { this[MarginSettings.BOTTOM_GROUP]);
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];
}, },
/** /**
...@@ -93,6 +91,7 @@ cr.define('print_preview', function() { ...@@ -93,6 +91,7 @@ cr.define('print_preview', function() {
this.contentWidth_ = width; this.contentWidth_ = width;
this.contentHeight_ = height; this.contentHeight_ = height;
this.margins_ = new Margins(left, top, right, bottom); this.margins_ = new Margins(left, top, right, bottom);
this.margins_.roundToLocaleUnits();
} }
PageLayout.prototype = { PageLayout.prototype = {
...@@ -122,21 +121,18 @@ cr.define('print_preview', function() { ...@@ -122,21 +121,18 @@ cr.define('print_preview', function() {
this.marginsUI_ = null; this.marginsUI_ = null;
// Holds the custom margin values in points (if set). // 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. // 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. // Holds the width of the page in points.
this.pageWidth_ = -1; this.pageWidth_ = -1;
// Holds the height of the page in points. // Holds the height of the page in points.
this.pageHeight_ = -1; this.pageHeight_ = -1;
// The last selected margin option. // @type {boolean} True if the margins UI should be diplayed when the next
this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; // |customEvents.PDF_LOADED| event occurs.
this.forceMarginsUIOnPDFLoad_ = false;
// Holds the currently updated default page layout values. // Holds the currently updated default page layout values.
this.currentDefaultPageLayout = null; 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. // True if the margins UI should be shown regardless of mouse position.
this.forceDisplayingMarginLines_ = true; this.forceDisplayingMarginLines_ = true;
...@@ -202,6 +198,19 @@ cr.define('print_preview', function() { ...@@ -202,6 +198,19 @@ cr.define('print_preview', function() {
return margins; return margins;
}, },
/**
* 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. * @return {number} The value of the selected margin option.
*/ */
...@@ -211,13 +220,26 @@ cr.define('print_preview', function() { ...@@ -211,13 +220,26 @@ cr.define('print_preview', function() {
}, },
/** /**
* Sets the current margin selection to |lastUsedMarginsType|. * Sets the current margin selection to |lastUsedMarginType|.
* @param {number} lastUsedMarginsType An integer value identifying a margin * @param {number} lastUsedMarginType An integer value identifying a margin
* type according to MarginType enum in printing/print_job_constants.h. * type according to MarginType enum in printing/print_job_constants.h.
*/ * @param {Object} lastUsedCustomMargins The last used custom margins. If
setLastUsedMarginsType: function(lastUsedMarginsType) { * 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;
this.marginList_.selectedIndex = this.marginList_.selectedIndex =
this.getMarginOptionIndexByValue_(lastUsedMarginsType); 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;
}
}, },
/** /**
...@@ -290,9 +312,11 @@ cr.define('print_preview', function() { ...@@ -290,9 +312,11 @@ cr.define('print_preview', function() {
requestPreviewIfNeeded_: function() { requestPreviewIfNeeded_: function() {
if (!this.areMarginSettingsValid()) if (!this.areMarginSettingsValid())
return; return;
if (this.customMargins_.isEqual(this.previousCustomMargins_)) if (this.customMargins_.isEqual(this.previousCustomMargins_))
return; return;
this.previousCustomMargins_.copy(this.customMargins_);
this.previousCustomMargins_ = this.customMargins_.clone();
setDefaultValuesAndRegeneratePreview(false); setDefaultValuesAndRegeneratePreview(false);
}, },
...@@ -302,6 +326,8 @@ cr.define('print_preview', function() { ...@@ -302,6 +326,8 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
onSidebarMouseOver_: function(e) { onSidebarMouseOver_: function(e) {
$('mainview').onmouseover = this.onMainviewMouseOver_.bind(this);
$('navbar-container').onmouseover = null;
if (!this.forceDisplayingMarginLines_) if (!this.forceDisplayingMarginLines_)
this.marginsUI.hide(false); this.marginsUI.hide(false);
}, },
...@@ -312,6 +338,8 @@ cr.define('print_preview', function() { ...@@ -312,6 +338,8 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
onMainviewMouseOver_: function() { onMainviewMouseOver_: function() {
$('mainview').onmouseover = null;
$('navbar-container').onmouseover = this.onSidebarMouseOver_.bind(this);
this.forceDisplayingMarginLines_ = false; this.forceDisplayingMarginLines_ = false;
this.marginsUI.show(); this.marginsUI.show();
}, },
...@@ -368,7 +396,7 @@ cr.define('print_preview', function() { ...@@ -368,7 +396,7 @@ cr.define('print_preview', function() {
* @return {boolean} True if the margin settings are valid. * @return {boolean} True if the margin settings are valid.
*/ */
areMarginSettingsValid: function() { areMarginSettingsValid: function() {
if (this.marginsUI_ == null) if (!this.isCustomMarginsSelected() || !this.marginsUI_)
return true; return true;
var pairs = this.marginsUI.pairsAsList; var pairs = this.marginsUI.pairsAsList;
...@@ -474,6 +502,8 @@ cr.define('print_preview', function() { ...@@ -474,6 +502,8 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
removeCustomMarginEventListeners_: function() { removeCustomMarginEventListeners_: function() {
if (!this.marginsUI_)
return;
$('mainview').onmouseover = null; $('mainview').onmouseover = null;
$('navbar-container').onmouseover = null; $('navbar-container').onmouseover = null;
this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG);
...@@ -532,8 +562,6 @@ cr.define('print_preview', function() { ...@@ -532,8 +562,6 @@ cr.define('print_preview', function() {
this.onDefaultMinimumNoMarginsSelected_(); this.onDefaultMinimumNoMarginsSelected_();
else if (this.isCustomMarginsSelected()) else if (this.isCustomMarginsSelected())
this.onCustomMarginsSelected_(); this.onCustomMarginsSelected_();
this.lastSelectedOption_ = this.selectedMarginsValue;
}, },
/** /**
...@@ -543,6 +571,7 @@ cr.define('print_preview', function() { ...@@ -543,6 +571,7 @@ cr.define('print_preview', function() {
onDefaultMinimumNoMarginsSelected_: function() { onDefaultMinimumNoMarginsSelected_: function() {
this.removeCustomMarginEventListeners_(); this.removeCustomMarginEventListeners_();
this.forceDisplayingMarginLines_ = true; this.forceDisplayingMarginLines_ = true;
this.previousCustomMargins_ = null;
setDefaultValuesAndRegeneratePreview(false); setDefaultValuesAndRegeneratePreview(false);
}, },
...@@ -551,20 +580,18 @@ cr.define('print_preview', function() { ...@@ -551,20 +580,18 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
onCustomMarginsSelected_: function() { onCustomMarginsSelected_: function() {
this.addCustomMarginEventListeners_(); var customMarginsNotSpecified = !this.customMargins_;
this.updatePageData_();
this.customMargins_ = this.currentDefaultPageLayout.margins_; if (customMarginsNotSpecified) {
this.customMargins_.roundToLocaleUnits(); this.previousCustomMargins_ = this.customMargins_.clone();
this.previousCustomMargins_.copy(this.customMargins_); this.drawCustomMarginsUI_();
this.addCustomMarginEventListeners_();
if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { this.marginsUI.show();
this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; } else {
this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; this.forceMarginsUIOnPDFLoad_ = true;
this.requestPreviewIfNeeded_();
} }
this.previousDefaultPageLayout_ = this.currentDefaultPageLayout;
this.drawCustomMarginsUI_();
this.marginsUI.show();
}, },
/** /**
...@@ -627,7 +654,8 @@ cr.define('print_preview', function() { ...@@ -627,7 +654,8 @@ cr.define('print_preview', function() {
MarginSettings.OPTION_INDEX_DEFAULT].selected = true; MarginSettings.OPTION_INDEX_DEFAULT].selected = true;
this.removeCustomMarginEventListeners_(); this.removeCustomMarginEventListeners_();
this.forceDisplayingMarginLines_ = true; this.forceDisplayingMarginLines_ = true;
this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; this.customMargins_ = null;
this.previousCustomMargins_ = null;
} }
}, },
...@@ -636,15 +664,35 @@ cr.define('print_preview', function() { ...@@ -636,15 +664,35 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
onPDFLoaded_: function() { onPDFLoaded_: function() {
if (!previewModifiable) if (!previewModifiable) {
fadeOutOption(this.marginsOption_); 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 { return {
MarginSettings: MarginSettings, MarginSettings: MarginSettings,
PageLayout: PageLayout, PageLayout: PageLayout,
setNumberFormatAndMeasurementSystem:
MarginSettings.setNumberFormatAndMeasurementSystem,
}; };
}); });
...@@ -164,9 +164,25 @@ function onLoad() { ...@@ -164,9 +164,25 @@ function onLoad() {
$('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
previewArea.showLoadingAnimation(); previewArea.showLoadingAnimation();
chrome.send('getInitiatorTabTitle'); chrome.send('getInitialSettings');
chrome.send('getDefaultPrinter'); }
chrome.send('getNumberFormatAndMeasurementSystem');
/**
* @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']);
} }
/** /**
...@@ -284,7 +300,9 @@ function updateControlsWithSelectedPrinterCapabilities() { ...@@ -284,7 +300,9 @@ function updateControlsWithSelectedPrinterCapabilities() {
lastSelectedPrinterIndex = selectedIndex; lastSelectedPrinterIndex = selectedIndex;
// Regenerate the preview data based on selected printer settings. // Regenerate the preview data based on selected printer settings.
setDefaultValuesAndRegeneratePreview(true); // Do not reset the margins if no preview request has been made.
var resetMargins = lastPreviewRequestID != initialPreviewRequestID;
setDefaultValuesAndRegeneratePreview(resetMargins);
} }
} }
...@@ -304,7 +322,9 @@ function doUpdateCloudPrinterCapabilities(printer) { ...@@ -304,7 +322,9 @@ function doUpdateCloudPrinterCapabilities(printer) {
lastSelectedPrinterIndex = selectedIndex; lastSelectedPrinterIndex = selectedIndex;
// Regenerate the preview data based on selected printer settings. // Regenerate the preview data based on selected printer settings.
setDefaultValuesAndRegeneratePreview(true); // Do not reset the margins if no preview request has been made.
var resetMargins = lastPreviewRequestID != initialPreviewRequestID;
setDefaultValuesAndRegeneratePreview(resetMargins);
} }
/** /**
...@@ -578,18 +598,14 @@ function fileSelectionCompleted() { ...@@ -578,18 +598,14 @@ function fileSelectionCompleted() {
* @param {string} printer Name of the default printer. Empty if none. * @param {string} printer Name of the default printer. Empty if none.
* @param {string} cloudPrintData Cloud print related data to restore if * @param {string} cloudPrintData Cloud print related data to restore if
* the default printer is a cloud printer. * 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(printer_name, cloudPrintData, lastUsedMarginsType) { function setDefaultPrinter(printerName, cloudPrintData) {
// Setting the margin selection to the last used one.
marginSettings.setLastUsedMarginsType(lastUsedMarginsType);
// Add a placeholder value so the printer list looks valid. // Add a placeholder value so the printer list looks valid.
addDestinationListOption('', '', true, true, true); addDestinationListOption('', '', true, true, true);
if (printer_name) { if (printerName) {
defaultOrLastUsedPrinterName = printer_name; defaultOrLastUsedPrinterName = printerName;
if (cloudPrintData) { if (cloudPrintData) {
cloudprint.setDefaultPrinter(printer_name, cloudprint.setDefaultPrinter(printerName,
cloudPrintData, cloudPrintData,
addDestinationListOptionAtPosition, addDestinationListOptionAtPosition,
doUpdateCloudPrinterCapabilities); doUpdateCloudPrinterCapabilities);
...@@ -779,16 +795,13 @@ function setPluginPreviewPageCount() { ...@@ -779,16 +795,13 @@ function setPluginPreviewPageCount() {
* Update the page count and check the page range. * Update the page count and check the page range.
* Called from PrintPreviewUI::OnDidGetPreviewPageCount(). * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
* @param {number} pageCount The number of pages. * @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 * @param {number} previewResponseId The preview request id that resulted in
* this response. * this response.
*/ */
function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { function onDidGetPreviewPageCount(pageCount, previewResponseId) {
if (!isExpectedPreviewResponse(previewResponseId)) if (!isExpectedPreviewResponse(previewResponseId))
return; return;
pageSettings.updateState(pageCount); pageSettings.updateState(pageCount);
previewModifiable = isModifiable;
if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded())
return; return;
...@@ -1058,8 +1071,6 @@ PrintSettings.prototype.save = function() { ...@@ -1058,8 +1071,6 @@ PrintSettings.prototype.save = function() {
/** /**
* Updates the title of the print preview tab according to |initiatorTabTitle|. * 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. * @param {string} initiatorTabTitle The title of the initiator tab.
*/ */
function setInitiatorTabTitle(initiatorTabTitle) { function setInitiatorTabTitle(initiatorTabTitle) {
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "printing/metafile.h" #include "printing/metafile.h"
#include "printing/metafile_impl.h" #include "printing/metafile_impl.h"
#include "printing/page_range.h" #include "printing/page_range.h"
#include "printing/page_size_margins.h"
#include "printing/print_settings.h" #include "printing/print_settings.h"
#include "unicode/ulocdata.h" #include "unicode/ulocdata.h"
...@@ -96,6 +97,17 @@ void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) { ...@@ -96,6 +97,17 @@ void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) {
PRINT_SETTINGS_BUCKET_BOUNDARY); PRINT_SETTINGS_BUCKET_BOUNDARY);
} }
// Name of a dictionary fielad holdong cloud print related data;
const char kCloudPrintData[] = "cloudPrintData";
// Name of a dictionary field holding the initiator tab title.
const char kInitiatorTabTitle[] = "initiatorTabTitle";
// Name of a dictionary field holding the measurement system according to the
// locale.
const char kMeasurementSystem[] = "measurementSystem";
// Name of a dictionary field holding the number format according to the locale.
const char kNumberFormat[] = "numberFormat";
// Get the print job settings dictionary from |args|. The caller takes // Get the print job settings dictionary from |args|. The caller takes
// ownership of the returned DictionaryValue. Returns NULL on failure. // ownership of the returned DictionaryValue. Returns NULL on failure.
DictionaryValue* GetSettingsDictionary(const ListValue* args) { DictionaryValue* GetSettingsDictionary(const ListValue* args) {
...@@ -206,6 +218,8 @@ printing::ColorModels PrintPreviewHandler::last_used_color_model_ = ...@@ -206,6 +218,8 @@ printing::ColorModels PrintPreviewHandler::last_used_color_model_ =
printing::UNKNOWN_COLOR_MODEL; printing::UNKNOWN_COLOR_MODEL;
printing::MarginType PrintPreviewHandler::last_used_margins_type_ = printing::MarginType PrintPreviewHandler::last_used_margins_type_ =
printing::DEFAULT_MARGINS; printing::DEFAULT_MARGINS;
printing::PageSizeMargins*
PrintPreviewHandler::last_used_page_size_margins_ = NULL;
PrintPreviewHandler::PrintPreviewHandler() PrintPreviewHandler::PrintPreviewHandler()
: print_backend_(printing::PrintBackend::CreateInstance(NULL)), : print_backend_(printing::PrintBackend::CreateInstance(NULL)),
...@@ -222,9 +236,6 @@ PrintPreviewHandler::~PrintPreviewHandler() { ...@@ -222,9 +236,6 @@ PrintPreviewHandler::~PrintPreviewHandler() {
} }
void PrintPreviewHandler::RegisterMessages() { void PrintPreviewHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback("getDefaultPrinter",
base::Bind(&PrintPreviewHandler::HandleGetDefaultPrinter,
base::Unretained(this)));
web_ui_->RegisterMessageCallback("getPrinters", web_ui_->RegisterMessageCallback("getPrinters",
base::Bind(&PrintPreviewHandler::HandleGetPrinters, base::Bind(&PrintPreviewHandler::HandleGetPrinters,
base::Unretained(this))); base::Unretained(this)));
...@@ -264,13 +275,9 @@ void PrintPreviewHandler::RegisterMessages() { ...@@ -264,13 +275,9 @@ void PrintPreviewHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback("saveLastPrinter", web_ui_->RegisterMessageCallback("saveLastPrinter",
base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter,
base::Unretained(this))); base::Unretained(this)));
web_ui_->RegisterMessageCallback("getInitiatorTabTitle", web_ui_->RegisterMessageCallback("getInitialSettings",
base::Bind(&PrintPreviewHandler::HandleGetInitiatorTabTitle, base::Bind(&PrintPreviewHandler::HandleGetInitialSettings,
base::Unretained(this))); base::Unretained(this)));
web_ui_->RegisterMessageCallback("getNumberFormatAndMeasurementSystem",
base::Bind(
&PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem,
base::Unretained(this)));
} }
TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const {
...@@ -280,16 +287,6 @@ TabContents* PrintPreviewHandler::preview_tab() const { ...@@ -280,16 +287,6 @@ TabContents* PrintPreviewHandler::preview_tab() const {
return web_ui_->tab_contents(); return web_ui_->tab_contents();
} }
void PrintPreviewHandler::HandleGetDefaultPrinter(const ListValue* /*args*/) {
scoped_refptr<PrintSystemTaskProxy> task =
new PrintSystemTaskProxy(AsWeakPtr(),
print_backend_.get(),
has_logged_printers_count_);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get()));
}
void PrintPreviewHandler::HandleGetPrinters(const ListValue* /*args*/) { void PrintPreviewHandler::HandleGetPrinters(const ListValue* /*args*/) {
scoped_refptr<PrintSystemTaskProxy> task = scoped_refptr<PrintSystemTaskProxy> task =
new PrintSystemTaskProxy(AsWeakPtr(), new PrintSystemTaskProxy(AsWeakPtr(),
...@@ -397,10 +394,19 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { ...@@ -397,10 +394,19 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
last_used_color_model_ = static_cast<printing::ColorModels>(color_model); last_used_color_model_ = static_cast<printing::ColorModels>(color_model);
// Storing last used margin settings. // Storing last used margin settings.
int margin_type; bool is_modifiable;
if (!settings->GetInteger(printing::kSettingMarginsType, &margin_type)) settings->GetBoolean(printing::kSettingPreviewModifiable, &is_modifiable);
margin_type = printing::DEFAULT_MARGINS; if (is_modifiable) {
last_used_margins_type_ = static_cast<printing::MarginType>(margin_type); int margin_type;
if (!settings->GetInteger(printing::kSettingMarginsType, &margin_type))
margin_type = printing::DEFAULT_MARGINS;
last_used_margins_type_ = static_cast<printing::MarginType>(margin_type);
if (last_used_margins_type_ == printing::CUSTOM_MARGINS) {
if (!last_used_page_size_margins_)
last_used_page_size_margins_ = new printing::PageSizeMargins();
getCustomMarginsFromJobSettings(*settings, last_used_page_size_margins_);
}
}
bool print_to_pdf = false; bool print_to_pdf = false;
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
...@@ -613,32 +619,67 @@ void PrintPreviewHandler::ReportStats() { ...@@ -613,32 +619,67 @@ void PrintPreviewHandler::ReportStats() {
manage_printers_dialog_request_count_); manage_printers_dialog_request_count_);
} }
void PrintPreviewHandler::HandleGetInitiatorTabTitle( void PrintPreviewHandler::GetNumberFormatAndMeasurementSystem(
const ListValue* /*args*/) { base::DictionaryValue* settings) {
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_);
base::StringValue tab_title(print_preview_ui->initiator_tab_title());
web_ui_->CallJavascriptFunction("setInitiatorTabTitle", tab_title);
}
void PrintPreviewHandler::HandleGetNumberFormatAndMeasurementSystem(
const ListValue* /*args*/) {
// Getting the measurement system based on the locale. // Getting the measurement system based on the locale.
UErrorCode errorCode = U_ZERO_ERROR; UErrorCode errorCode = U_ZERO_ERROR;
const char* locale = g_browser_process->GetApplicationLocale().c_str(); const char* locale = g_browser_process->GetApplicationLocale().c_str();
UMeasurementSystem measurement_system = UMeasurementSystem system = ulocdata_getMeasurementSystem(locale, &errorCode);
ulocdata_getMeasurementSystem(locale, &errorCode); if (errorCode > U_ZERO_ERROR || system == UMS_LIMIT)
if (errorCode > U_ZERO_ERROR || measurement_system == UMS_LIMIT) system = UMS_SI;
measurement_system = UMS_SI;
// Getting the number formatting based on the locale and writing to
// dictionary.
settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2));
settings->SetInteger(kMeasurementSystem, system);
}
void PrintPreviewHandler::GetLastUsedMarginSettings(
base::DictionaryValue* custom_margins) {
custom_margins->SetInteger(printing::kSettingMarginsType,
PrintPreviewHandler::last_used_margins_type_);
if (last_used_page_size_margins_) {
custom_margins->SetDouble(printing::kSettingMarginTop,
last_used_page_size_margins_->margin_top);
custom_margins->SetDouble(printing::kSettingMarginBottom,
last_used_page_size_margins_->margin_bottom);
custom_margins->SetDouble(printing::kSettingMarginLeft,
last_used_page_size_margins_->margin_left);
custom_margins->SetDouble(printing::kSettingMarginRight,
last_used_page_size_margins_->margin_right);
}
}
// Getting the number formatting based on the locale. void PrintPreviewHandler::HandleGetInitialSettings(const ListValue* /*args*/) {
StringValue number_format(base::FormatDouble(123456.78, 2)); scoped_refptr<PrintSystemTaskProxy> task =
base::FundamentalValue system(measurement_system); new PrintSystemTaskProxy(AsWeakPtr(),
print_backend_.get(),
has_logged_printers_count_);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get()));
}
void PrintPreviewHandler::SendInitialSettings(
const std::string& default_printer,
const std::string& cloud_print_data) {
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_);
web_ui_->CallJavascriptFunction( base::DictionaryValue initial_settings;
"print_preview.setNumberFormatAndMeasurementSystem", initial_settings.SetString(kInitiatorTabTitle,
number_format, print_preview_ui->initiator_tab_title());
system); initial_settings.SetBoolean(printing::kSettingPreviewModifiable,
print_preview_ui->source_is_modifiable());
initial_settings.SetString(printing::kSettingPrinterName,
default_printer);
initial_settings.SetString(kCloudPrintData, cloud_print_data);
if (print_preview_ui->source_is_modifiable()) {
GetLastUsedMarginSettings(&initial_settings);
GetNumberFormatAndMeasurementSystem(&initial_settings);
}
web_ui_->CallJavascriptFunction("setInitialSettings", initial_settings);
} }
void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() {
...@@ -657,17 +698,6 @@ void PrintPreviewHandler::SendPrinterCapabilities( ...@@ -657,17 +698,6 @@ void PrintPreviewHandler::SendPrinterCapabilities(
settings_info); settings_info);
} }
void PrintPreviewHandler::SendDefaultPrinter(
const StringValue& default_printer,
const StringValue& cloud_print_data) {
base::FundamentalValue margins_type(
PrintPreviewHandler::last_used_margins_type_);
web_ui_->CallJavascriptFunction("setDefaultPrinter",
default_printer,
cloud_print_data,
margins_type);
}
void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) {
SendCloudPrintEnabled(); SendCloudPrintEnabled();
web_ui_->CallJavascriptFunction("setPrinters", printers); web_ui_->CallJavascriptFunction("setPrinters", printers);
......
...@@ -27,6 +27,7 @@ class StringValue; ...@@ -27,6 +27,7 @@ class StringValue;
} }
namespace printing { namespace printing {
struct PageSizeMargins;
class PrintBackend; class PrintBackend;
} }
...@@ -67,14 +68,20 @@ class PrintPreviewHandler : public WebUIMessageHandler, ...@@ -67,14 +68,20 @@ class PrintPreviewHandler : public WebUIMessageHandler,
void ShowSystemDialog(); void ShowSystemDialog();
private: private:
friend class PrintPreviewHandlerTest;
friend class PrintSystemTaskProxy; friend class PrintSystemTaskProxy;
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsDefault);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
StickyMarginsCustomThenDefault);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
GetLastUsedMarginSettingsCustom);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
GetLastUsedMarginSettingsDefault);
TabContentsWrapper* preview_tab_wrapper() const; TabContentsWrapper* preview_tab_wrapper() const;
TabContents* preview_tab() const; TabContents* preview_tab() const;
// Gets the default printer. |args| is unused.
void HandleGetDefaultPrinter(const base::ListValue* args);
// Gets the list of printers. |args| is unused. // Gets the list of printers. |args| is unused.
void HandleGetPrinters(const base::ListValue* args); void HandleGetPrinters(const base::ListValue* args);
...@@ -131,22 +138,18 @@ class PrintPreviewHandler : public WebUIMessageHandler, ...@@ -131,22 +138,18 @@ class PrintPreviewHandler : public WebUIMessageHandler,
// Asks the browser to close the preview tab. |args| is unused. // Asks the browser to close the preview tab. |args| is unused.
void HandleClosePreviewTab(const base::ListValue* args); void HandleClosePreviewTab(const base::ListValue* args);
// Asks the browser for the title of the initiator tab. // Asks the browser for several settings that are needed before the first
// |args| is unused. // preview is displayed.
void HandleGetInitiatorTabTitle(const base::ListValue* args); void HandleGetInitialSettings(const base::ListValue* args);
// Asks the browser for the number formatting and measurement system according void SendInitialSettings(
// to the current locale. const std::string& default_printer,
void HandleGetNumberFormatAndMeasurementSystem(const base::ListValue* args); const std::string& cloud_print_data);
// Sends the printer capabilities to the Web UI. |settings_info| contains // Sends the printer capabilities to the Web UI. |settings_info| contains
// printer capabilities information. // printer capabilities information.
void SendPrinterCapabilities(const base::DictionaryValue& settings_info); void SendPrinterCapabilities(const base::DictionaryValue& settings_info);
// Sends the default printer to the Web UI.
void SendDefaultPrinter(const base::StringValue& default_printer,
const base::StringValue& cloud_print_data);
// Send the list of printers to the Web UI. // Send the list of printers to the Web UI.
void SetupPrinterList(const base::ListValue& printers); void SetupPrinterList(const base::ListValue& printers);
...@@ -178,6 +181,14 @@ class PrintPreviewHandler : public WebUIMessageHandler, ...@@ -178,6 +181,14 @@ class PrintPreviewHandler : public WebUIMessageHandler,
// Posts a task to save to pdf at |print_to_pdf_path_|. // Posts a task to save to pdf at |print_to_pdf_path_|.
void PostPrintToPdfTask(); void PostPrintToPdfTask();
// Populates |settings| according to the current locale.
void GetNumberFormatAndMeasurementSystem(base::DictionaryValue* settings);
// Populates |last_used_custom_margins| according to the last used margin
// settings.
void GetLastUsedMarginSettings(
base::DictionaryValue* last_used_custom_margins);
// Pointer to current print system. // Pointer to current print system.
scoped_refptr<printing::PrintBackend> print_backend_; scoped_refptr<printing::PrintBackend> print_backend_;
...@@ -189,6 +200,7 @@ class PrintPreviewHandler : public WebUIMessageHandler, ...@@ -189,6 +200,7 @@ class PrintPreviewHandler : public WebUIMessageHandler,
static std::string* last_used_printer_name_; static std::string* last_used_printer_name_;
static printing::ColorModels last_used_color_model_; static printing::ColorModels last_used_color_model_;
static printing::MarginType last_used_margins_type_; static printing::MarginType last_used_margins_type_;
static printing::PageSizeMargins* last_used_page_size_margins_;
// A count of how many requests received to regenerate preview data. // A count of how many requests received to regenerate preview data.
// Initialized to 0 then incremented and emitted to a histogram. // Initialized to 0 then incremented and emitted to a histogram.
......
This diff is collapsed.
...@@ -116,6 +116,10 @@ void PrintPreviewUI::SetInitiatorTabURLAndTitle( ...@@ -116,6 +116,10 @@ void PrintPreviewUI::SetInitiatorTabURLAndTitle(
initiator_tab_title_ = job_title; initiator_tab_title_ = job_title;
} }
void PrintPreviewUI::SetSourceIsModifiable(bool source_is_modifiable) {
source_is_modifiable_ = source_is_modifiable;
}
// static // static
void PrintPreviewUI::GetCurrentPrintPreviewStatus( void PrintPreviewUI::GetCurrentPrintPreviewStatus(
const std::string& preview_ui_addr, const std::string& preview_ui_addr,
...@@ -159,10 +163,8 @@ void PrintPreviewUI::OnDidGetPreviewPageCount( ...@@ -159,10 +163,8 @@ void PrintPreviewUI::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params) { const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
DCHECK_GT(params.page_count, 0); DCHECK_GT(params.page_count, 0);
base::FundamentalValue count(params.page_count); base::FundamentalValue count(params.page_count);
base::FundamentalValue modifiable(params.is_modifiable);
base::FundamentalValue request_id(params.preview_request_id); base::FundamentalValue request_id(params.preview_request_id);
CallJavascriptFunction("onDidGetPreviewPageCount", count, modifiable, CallJavascriptFunction("onDidGetPreviewPageCount", count,request_id);
request_id);
} }
void PrintPreviewUI::OnDidGetDefaultPageLayout( void PrintPreviewUI::OnDidGetDefaultPageLayout(
......
...@@ -50,6 +50,10 @@ class PrintPreviewUI : public ChromeWebUI { ...@@ -50,6 +50,10 @@ class PrintPreviewUI : public ChromeWebUI {
string16 initiator_tab_title() { return initiator_tab_title_; } string16 initiator_tab_title() { return initiator_tab_title_; }
bool source_is_modifiable() { return source_is_modifiable_; }
void SetSourceIsModifiable(bool source_is_modifiable);
// Determines whether to cancel a print preview request based on // Determines whether to cancel a print preview request based on
// |preview_ui_addr| and |request_id|. // |preview_ui_addr| and |request_id|.
// Can be called from any thread. // Can be called from any thread.
...@@ -114,6 +118,15 @@ class PrintPreviewUI : public ChromeWebUI { ...@@ -114,6 +118,15 @@ class PrintPreviewUI : public ChromeWebUI {
void OnCancelPendingPreviewRequest(); void OnCancelPendingPreviewRequest();
private: private:
friend class PrintPreviewHandlerTest;
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsDefault);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
StickyMarginsCustomThenDefault);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
GetLastUsedMarginSettingsCustom);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest,
GetLastUsedMarginSettingsDefault);
FRIEND_TEST_ALL_PREFIXES(PrintPreviewTabControllerUnitTest, FRIEND_TEST_ALL_PREFIXES(PrintPreviewTabControllerUnitTest,
TitleAfterReload); TitleAfterReload);
...@@ -132,6 +145,9 @@ class PrintPreviewUI : public ChromeWebUI { ...@@ -132,6 +145,9 @@ class PrintPreviewUI : public ChromeWebUI {
// when the initiator tab is closed/crashed. // when the initiator tab is closed/crashed.
std::string initiator_url_; std::string initiator_url_;
// Indicates whether the source document can be modified.
bool source_is_modifiable_;
// Store the initiator tab title, used for populating the print preview tab // Store the initiator tab title, used for populating the print preview tab
// title. // title.
string16 initiator_tab_title_; string16 initiator_tab_title_;
......
...@@ -1864,6 +1864,7 @@ ...@@ -1864,6 +1864,7 @@
'browser/ui/webui/html_dialog_tab_contents_delegate_unittest.cc', 'browser/ui/webui/html_dialog_tab_contents_delegate_unittest.cc',
'browser/ui/webui/options/chromeos/virtual_keyboard_manager_handler_unittest.cc', 'browser/ui/webui/options/chromeos/virtual_keyboard_manager_handler_unittest.cc',
'browser/ui/webui/options/language_options_handler_unittest.cc', 'browser/ui/webui/options/language_options_handler_unittest.cc',
'browser/ui/webui/print_preview_handler_unittest.cc',
'browser/ui/webui/print_preview_ui_unittest.cc', 'browser/ui/webui/print_preview_ui_unittest.cc',
'browser/ui/webui/sync_internals_ui_unittest.cc', 'browser/ui/webui/sync_internals_ui_unittest.cc',
'browser/ui/webui/theme_source_unittest.cc', 'browser/ui/webui/theme_source_unittest.cc',
......
...@@ -343,7 +343,7 @@ IPC_MESSAGE_CONTROL1(PrintHostMsg_TempFileForPrintingWritten, ...@@ -343,7 +343,7 @@ IPC_MESSAGE_CONTROL1(PrintHostMsg_TempFileForPrintingWritten,
#endif #endif
// Asks the browser to do print preview. // Asks the browser to do print preview.
IPC_MESSAGE_ROUTED0(PrintHostMsg_RequestPrintPreview) IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview, bool /* is_modifiable */)
// Notify the browser the number of pages in the print preview document. // Notify the browser the number of pages in the print preview document.
IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount, IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount,
......
...@@ -1282,7 +1282,8 @@ void PrintWebViewHelper::DisplayPrintJobError() { ...@@ -1282,7 +1282,8 @@ void PrintWebViewHelper::DisplayPrintJobError() {
void PrintWebViewHelper::RequestPrintPreview() { void PrintWebViewHelper::RequestPrintPreview() {
old_print_pages_params_.reset(); old_print_pages_params_.reset();
Send(new PrintHostMsg_RequestPrintPreview(routing_id())); Send(new PrintHostMsg_RequestPrintPreview(
routing_id(), print_preview_context_.IsModifiable()));
} }
bool PrintWebViewHelper::CheckForCancel() { bool PrintWebViewHelper::CheckForCancel() {
......
...@@ -26,7 +26,7 @@ PrintPreviewWebUITest.prototype = { ...@@ -26,7 +26,7 @@ PrintPreviewWebUITest.prototype = {
* @override * @override
*/ */
preLoad: function() { preLoad: function() {
this.makeAndRegisterMockHandler(['getDefaultPrinter', this.makeAndRegisterMockHandler(['getInitialSettings',
'getPrinters', 'getPrinters',
'getPreview', 'getPreview',
'print', 'print',
...@@ -45,7 +45,7 @@ PrintPreviewWebUITest.prototype = { ...@@ -45,7 +45,7 @@ PrintPreviewWebUITest.prototype = {
// Register stubs for methods expected to be called before tests // Register stubs for methods expected to be called before tests
// run. Specific expectations can be made in the tests themselves. // run. Specific expectations can be made in the tests themselves.
this.mockHandler.stubs().getDefaultPrinter(). this.mockHandler.stubs().getInitialSettings().
will(callFunction(function() { will(callFunction(function() {
setDefaultPrinter('FooDevice'); setDefaultPrinter('FooDevice');
})); }));
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/page_size_margins.h"
#include "base/logging.h"
#include "base/values.h"
#include "printing/print_job_constants.h"
namespace printing {
void getCustomMarginsFromJobSettings(const base::DictionaryValue& settings,
PageSizeMargins* page_size_margins) {
DictionaryValue* custom_margins;
if (!settings.GetDictionary(kSettingMarginsCustom, &custom_margins) ||
!custom_margins->GetDouble(kSettingMarginTop,
&page_size_margins->margin_top) ||
!custom_margins->GetDouble(kSettingMarginBottom,
&page_size_margins->margin_bottom) ||
!custom_margins->GetDouble(kSettingMarginLeft,
&page_size_margins->margin_left) ||
!custom_margins->GetDouble(kSettingMarginRight,
&page_size_margins->margin_right)) {
NOTREACHED();
}
}
} // namespace printing
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#ifndef PRINTING_PAGE_SIZE_MARGINS_H_ #ifndef PRINTING_PAGE_SIZE_MARGINS_H_
#define PRINTING_PAGE_SIZE_MARGINS_H_ #define PRINTING_PAGE_SIZE_MARGINS_H_
namespace base {
class DictionaryValue;
}
namespace printing { namespace printing {
// Struct that holds margin and content area sizes of a page. Units are // Struct that holds margin and content area sizes of a page. Units are
...@@ -18,7 +22,9 @@ struct PageSizeMargins { ...@@ -18,7 +22,9 @@ struct PageSizeMargins {
double margin_left; double margin_left;
}; };
void getCustomMarginsFromJobSettings(const base::DictionaryValue& settings,
PageSizeMargins* page_size_margins);
} // namespace printing } // namespace printing
#endif // PRINTING_PAGE_SIZE_MARGINS_H_ #endif // PRINTING_PAGE_SIZE_MARGINS_H_
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
'page_range.h', 'page_range.h',
'page_setup.cc', 'page_setup.cc',
'page_setup.h', 'page_setup.h',
'page_size_margins.cc',
'page_size_margins.h', 'page_size_margins.h',
'pdf_metafile_cg_mac.cc', 'pdf_metafile_cg_mac.cc',
'pdf_metafile_cg_mac.h', 'pdf_metafile_cg_mac.h',
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/values.h" #include "base/values.h"
#include "printing/page_setup.h" #include "printing/page_setup.h"
#include "printing/page_size_margins.h"
#include "printing/print_settings_initializer.h" #include "printing/print_settings_initializer.h"
namespace printing { namespace printing {
...@@ -62,27 +63,15 @@ PrintingContext::Result PrintingContext::UpdatePrintSettings( ...@@ -62,27 +63,15 @@ PrintingContext::Result PrintingContext::UpdatePrintSettings(
settings_.margin_type = static_cast<MarginType>(margin_type); settings_.margin_type = static_cast<MarginType>(margin_type);
if (margin_type == CUSTOM_MARGINS) { if (margin_type == CUSTOM_MARGINS) {
double top_margin_in_points = 0; printing::PageSizeMargins page_size_margins;
double bottom_margin_in_points = 0; getCustomMarginsFromJobSettings(job_settings, &page_size_margins);
double left_margin_in_points = 0;
double right_margin_in_points = 0;
DictionaryValue* custom_margins;
if (!job_settings.GetDictionary(kSettingMarginsCustom, &custom_margins) ||
!custom_margins->GetDouble(kSettingMarginTop, &top_margin_in_points) ||
!custom_margins->GetDouble(kSettingMarginBottom,
&bottom_margin_in_points) ||
!custom_margins->GetDouble(kSettingMarginLeft,
&left_margin_in_points) ||
!custom_margins->GetDouble(kSettingMarginRight,
&right_margin_in_points)) {
NOTREACHED();
}
PageMargins margins_in_points; PageMargins margins_in_points;
margins_in_points.Clear(); margins_in_points.Clear();
margins_in_points.top = top_margin_in_points; margins_in_points.top = page_size_margins.margin_top;
margins_in_points.bottom = bottom_margin_in_points; margins_in_points.bottom = page_size_margins.margin_bottom;
margins_in_points.left = left_margin_in_points; margins_in_points.left = page_size_margins.margin_left;
margins_in_points.right = right_margin_in_points; margins_in_points.right = page_size_margins.margin_right;
settings_.SetCustomMargins(margins_in_points); settings_.SetCustomMargins(margins_in_points);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment