diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 09:05:42 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 09:05:42 +0000 |
commit | 6a7fdfd56a9b569a27c4e6937d26f058ea94cb63 (patch) | |
tree | f5b9fb251070aab04217109820de8a3d82eae9ea /chrome | |
parent | 6ffcb08137cb8512ecc5f0c8eaf6e871b502263c (diff) | |
download | chromium_src-6a7fdfd56a9b569a27c4e6937d26f058ea94cb63.zip chromium_src-6a7fdfd56a9b569a27c4e6937d26f058ea94cb63.tar.gz chromium_src-6a7fdfd56a9b569a27c4e6937d26f058ea94cb63.tar.bz2 |
More options for the types of margins to add.
Original (broken) CL: http://codereview.chromium.org/8227034
Already approved by dpapad@
TBR=dpapad@chromium.org
BUG=NONE
TEST=NONE
Review URL: http://codereview.chromium.org/8261005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 33 insertions, 32 deletions
diff --git a/chrome/browser/resources/print_preview/margin_settings.js b/chrome/browser/resources/print_preview/margin_settings.js index 5f48ed7..1e30663 100644 --- a/chrome/browser/resources/print_preview/margin_settings.js +++ b/chrome/browser/resources/print_preview/margin_settings.js @@ -172,24 +172,24 @@ cr.define('print_preview', function() { /** * @return {number} The value of the selected margin option. - * @private */ - get selectedMarginsValue_() { - return this.marginList_.options[this.marginList_.selectedIndex].value; + get selectedMarginsValue() { + var val = this.marginList_.options[this.marginList_.selectedIndex].value; + return parseInt(val, 10); }, /** * @return {boolean} True if default margins are selected. */ isDefaultMarginsSelected: function() { - return this.selectedMarginsValue_ == MarginSettings.MARGINS_VALUE_DEFAULT; + return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; }, /** * @return {boolean} True if no margins are selected. */ isNoMarginsSelected: function() { - return this.selectedMarginsValue_ == + return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_NO_MARGINS; }, @@ -197,7 +197,7 @@ cr.define('print_preview', function() { * @return {boolean} True if custom margins are selected. */ isCustomMarginsSelected: function() { - return this.selectedMarginsValue_ == MarginSettings.MARGINS_VALUE_CUSTOM; + return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_CUSTOM; }, /** @@ -360,7 +360,7 @@ cr.define('print_preview', function() { else if (this.isCustomMarginsSelected()) this.onCustomMarginsSelected_(); - this.lastSelectedOption_ = this.selectedMarginsValue_; + this.lastSelectedOption_ = this.selectedMarginsValue; }, /** diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js index 13fde31d..5378744 100644 --- a/chrome/browser/resources/print_preview/print_preview.js +++ b/chrome/browser/resources/print_preview/print_preview.js @@ -355,11 +355,13 @@ function getSettings() { 'printWithCloudPrint': printWithCloudPrint, 'isFirstRequest' : false, 'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(), - 'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(), - 'margins': marginSettings.customMargins, + 'marginsType': marginSettings.selectedMarginsValue, 'requestID': -1, 'generateDraftData': generateDraftData}; + if (marginSettings.isCustomMarginsSelected()) + settings['marginsCustom'] = marginSettings.customMargins; + var printerList = $('printer-list'); var selectedPrinter = printerList.selectedIndex; if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index e651d36..afbb262 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -164,37 +164,36 @@ void SetMarginsForPDF(PrintMsg_Print_Params* settings) { // Get the margins option selected and set custom margins appropriately. void SetCustomMarginsIfSelected(const DictionaryValue& job_settings, PrintMsg_PrintPages_Params* settings) { - bool default_margins_selected; - if (!job_settings.GetBoolean(printing::kSettingDefaultMarginsSelected, - &default_margins_selected)) { + int margin_type = printing::DEFAULT_MARGINS; + if (!job_settings.GetInteger(printing::kSettingMarginsType, &margin_type)) { NOTREACHED(); - default_margins_selected = true; } - if (default_margins_selected) + if (margin_type == printing::DEFAULT_MARGINS) return; - DictionaryValue* custom_margins; - if (!job_settings.GetDictionary(printing::kSettingMargins, - &custom_margins)) { - NOTREACHED(); - return; - } - double custom_margin_top_in_points = 0; double custom_margin_left_in_points = 0; double custom_margin_right_in_points = 0; double custom_margin_bottom_in_points = 0; - if (!custom_margins->GetDouble(printing::kSettingMarginTop, - &custom_margin_top_in_points) || - !custom_margins->GetDouble(printing::kSettingMarginLeft, - &custom_margin_left_in_points) || - !custom_margins->GetDouble(printing::kSettingMarginRight, - &custom_margin_right_in_points) || - !custom_margins->GetDouble(printing::kSettingMarginBottom, - &custom_margin_bottom_in_points)) { - NOTREACHED(); - return; + if (margin_type == printing::CUSTOM_MARGINS) { + DictionaryValue* custom_margins; + if (!job_settings.GetDictionary(printing::kSettingMarginsCustom, + &custom_margins)) { + NOTREACHED(); + return; + } + if (!custom_margins->GetDouble(printing::kSettingMarginTop, + &custom_margin_top_in_points) || + !custom_margins->GetDouble(printing::kSettingMarginLeft, + &custom_margin_left_in_points) || + !custom_margins->GetDouble(printing::kSettingMarginRight, + &custom_margin_right_in_points) || + !custom_margins->GetDouble(printing::kSettingMarginBottom, + &custom_margin_bottom_in_points)) { + NOTREACHED(); + return; + } } int dpi = GetDPI(&settings->params); diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc index d784e80..3c362cf 100644 --- a/chrome/renderer/print_web_view_helper_browsertest.cc +++ b/chrome/renderer/print_web_view_helper_browsertest.cc @@ -49,7 +49,7 @@ void CreatePrintSettingsDictionary(DictionaryValue* dict) { dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); dict->SetInteger(printing::kPreviewRequestID, 12345); dict->SetBoolean(printing::kIsFirstRequest, true); - dict->SetBoolean(printing::kSettingDefaultMarginsSelected, true); + dict->SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); dict->SetBoolean(printing::kSettingGenerateDraftData, true); } |