| OLD | NEW |
| 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 #include "printing/printing_context.h" | 5 #include "printing/printing_context.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "printing/page_setup.h" | 9 #include "printing/page_setup.h" |
| 10 #include "printing/page_size_margins.h" | 10 #include "printing/page_size_margins.h" |
| 11 #include "printing/print_job_constants.h" | 11 #include "printing/print_job_constants.h" |
| 12 #include "printing/print_settings_initializer.h" | 12 #include "printing/print_settings_conversion.h" |
| 13 #include "printing/units.h" | 13 #include "printing/units.h" |
| 14 | 14 |
| 15 namespace printing { | 15 namespace printing { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const float kCloudPrintMarginInch = 0.25; | 18 const float kCloudPrintMarginInch = 0.25; |
| 19 } | 19 } |
| 20 | 20 |
| 21 PrintingContext::PrintingContext(const std::string& app_locale) | 21 PrintingContext::PrintingContext(const std::string& app_locale) |
| 22 : dialog_box_dismissed_(false), | 22 : dialog_box_dismissed_(false), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 pdf_settings->SetInteger(kSettingMarginsType, printing::NO_MARGINS); | 56 pdf_settings->SetInteger(kSettingMarginsType, printing::NO_MARGINS); |
| 57 pdf_settings->SetBoolean(kSettingCollate, true); | 57 pdf_settings->SetBoolean(kSettingCollate, true); |
| 58 pdf_settings->SetInteger(kSettingCopies, 1); | 58 pdf_settings->SetInteger(kSettingCopies, 1); |
| 59 pdf_settings->SetInteger(kSettingColor, printing::COLOR); | 59 pdf_settings->SetInteger(kSettingColor, printing::COLOR); |
| 60 pdf_settings->SetInteger(kSettingDuplexMode, printing::SIMPLEX); | 60 pdf_settings->SetInteger(kSettingDuplexMode, printing::SIMPLEX); |
| 61 pdf_settings->SetBoolean(kSettingLandscape, false); | 61 pdf_settings->SetBoolean(kSettingLandscape, false); |
| 62 pdf_settings->SetString(kSettingDeviceName, ""); | 62 pdf_settings->SetString(kSettingDeviceName, ""); |
| 63 pdf_settings->SetBoolean(kSettingPrintToPDF, true); | 63 pdf_settings->SetBoolean(kSettingPrintToPDF, true); |
| 64 pdf_settings->SetBoolean(kSettingCloudPrintDialog, false); | 64 pdf_settings->SetBoolean(kSettingCloudPrintDialog, false); |
| 65 pdf_settings->SetBoolean(kSettingPrintWithPrivet, false); | 65 pdf_settings->SetBoolean(kSettingPrintWithPrivet, false); |
| 66 return UpdatePrintSettings(*pdf_settings, PageRanges()); | 66 return UpdatePrintSettings(*pdf_settings); |
| 67 } | 67 } |
| 68 | 68 |
| 69 PrintingContext::Result PrintingContext::UpdatePrintSettings( | 69 PrintingContext::Result PrintingContext::UpdatePrintSettings( |
| 70 const base::DictionaryValue& job_settings, | 70 const base::DictionaryValue& job_settings) { |
| 71 const PageRanges& ranges) { | |
| 72 ResetSettings(); | 71 ResetSettings(); |
| 73 | 72 |
| 74 if (!PrintSettingsInitializer::InitSettings(job_settings, ranges, | 73 if (!PrintSettingsFromJobSettings(job_settings, &settings_)) { |
| 75 &settings_)) { | |
| 76 NOTREACHED(); | 74 NOTREACHED(); |
| 77 return OnError(); | 75 return OnError(); |
| 78 } | 76 } |
| 79 | 77 |
| 80 bool print_to_pdf = false; | 78 bool print_to_pdf = false; |
| 81 bool is_cloud_dialog = false; | 79 bool is_cloud_dialog = false; |
| 82 bool print_with_privet = false; | 80 bool print_with_privet = false; |
| 83 | 81 |
| 84 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || | 82 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || |
| 85 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog) || | 83 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog) || |
| 86 !job_settings.GetBoolean(kSettingPrintWithPrivet, &print_with_privet)) { | 84 !job_settings.GetBoolean(kSettingPrintWithPrivet, &print_with_privet)) { |
| 87 NOTREACHED(); | 85 NOTREACHED(); |
| 88 return OnError(); | 86 return OnError(); |
| 89 } | 87 } |
| 90 | 88 |
| 91 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); | 89 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); |
| 92 bool open_in_external_preview = | 90 bool open_in_external_preview = |
| 93 job_settings.HasKey(kSettingOpenPDFInPreview); | 91 job_settings.HasKey(kSettingOpenPDFInPreview); |
| 94 | 92 |
| 95 if (!open_in_external_preview && (print_to_pdf || print_to_cloud || | 93 if (!open_in_external_preview && (print_to_pdf || print_to_cloud || |
| 96 is_cloud_dialog || print_with_privet)) { | 94 is_cloud_dialog || print_with_privet)) { |
| 97 settings_.set_dpi(kDefaultPdfDpi); | 95 settings_.set_dpi(kDefaultPdfDpi); |
| 98 gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); | 96 gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); |
| 99 if (!settings_.requested_media().size_microns.IsEmpty()) { | 97 if (!settings_.requested_media().size_microns.IsEmpty()) { |
| 100 float deviceMicronsPerDeviceUnit = | 98 float deviceMicronsPerDeviceUnit = |
| 101 (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); | 99 (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); |
| 102 paper_size = gfx::Size(settings_.requested_media().size_microns.width() / | 100 paper_size = gfx::Size(settings_.requested_media().size_microns.width() / |
| 103 deviceMicronsPerDeviceUnit, | 101 deviceMicronsPerDeviceUnit, |
| 104 settings_.requested_media().size_microns.height() / | 102 settings_.requested_media().size_microns.height() / |
| 105 deviceMicronsPerDeviceUnit); | 103 deviceMicronsPerDeviceUnit); |
| 106 } | 104 } |
| 107 gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); | 105 gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); |
| 108 if (print_to_cloud || print_with_privet) { | 106 if (print_to_cloud || print_with_privet) { |
| 109 paper_rect.Inset( | 107 paper_rect.Inset( |
| 110 kCloudPrintMarginInch * settings_.device_units_per_inch(), | 108 kCloudPrintMarginInch * settings_.device_units_per_inch(), |
| 111 kCloudPrintMarginInch * settings_.device_units_per_inch()); | 109 kCloudPrintMarginInch * settings_.device_units_per_inch()); |
| 112 } | 110 } |
| 113 settings_.SetPrinterPrintableArea(paper_size, paper_rect, true); | 111 settings_.SetPrinterPrintableArea(paper_size, paper_rect, true); |
| 114 return OK; | 112 return OK; |
| 115 } | 113 } |
| 116 | 114 |
| 117 return UpdatePrinterSettings(open_in_external_preview); | 115 return UpdatePrinterSettings(open_in_external_preview); |
| 118 } | 116 } |
| 119 | 117 |
| 120 } // namespace printing | 118 } // namespace printing |
| OLD | NEW |