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_settings_initializer.h" | 11 #include "printing/print_settings_initializer.h" |
| 12 #include "printing/units.h" |
12 | 13 |
13 namespace printing { | 14 namespace printing { |
14 | 15 |
| 16 namespace { |
| 17 const float kCloudPrintMarginInch = 0.25; |
| 18 } |
| 19 |
15 PrintingContext::PrintingContext(const std::string& app_locale) | 20 PrintingContext::PrintingContext(const std::string& app_locale) |
16 : dialog_box_dismissed_(false), | 21 : dialog_box_dismissed_(false), |
17 in_print_job_(false), | 22 in_print_job_(false), |
18 abort_printing_(false), | 23 abort_printing_(false), |
19 app_locale_(app_locale) { | 24 app_locale_(app_locale) { |
20 } | 25 } |
21 | 26 |
22 PrintingContext::~PrintingContext() { | 27 PrintingContext::~PrintingContext() { |
23 } | 28 } |
24 | 29 |
(...skipping 15 matching lines...) Expand all Loading... |
40 PrintingContext::Result PrintingContext::OnError() { | 45 PrintingContext::Result PrintingContext::OnError() { |
41 ResetSettings(); | 46 ResetSettings(); |
42 return abort_printing_ ? CANCEL : FAILED; | 47 return abort_printing_ ? CANCEL : FAILED; |
43 } | 48 } |
44 | 49 |
45 PrintingContext::Result PrintingContext::UpdatePrintSettings( | 50 PrintingContext::Result PrintingContext::UpdatePrintSettings( |
46 const base::DictionaryValue& job_settings, | 51 const base::DictionaryValue& job_settings, |
47 const PageRanges& ranges) { | 52 const PageRanges& ranges) { |
48 ResetSettings(); | 53 ResetSettings(); |
49 | 54 |
50 if (settings_.dpi() == 0) | |
51 UseDefaultSettings(); | |
52 | |
53 if (!PrintSettingsInitializer::InitSettings(job_settings, ranges, | 55 if (!PrintSettingsInitializer::InitSettings(job_settings, ranges, |
54 &settings_)) { | 56 &settings_)) { |
55 NOTREACHED(); | 57 NOTREACHED(); |
56 return OnError(); | 58 return OnError(); |
57 } | 59 } |
58 | 60 |
59 bool print_to_pdf = false; | 61 bool print_to_pdf = false; |
60 bool is_cloud_dialog = false; | 62 bool is_cloud_dialog = false; |
61 | 63 |
62 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || | 64 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || |
63 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog)) { | 65 !job_settings.GetBoolean(kSettingCloudPrintDialog, &is_cloud_dialog)) { |
64 NOTREACHED(); | 66 NOTREACHED(); |
65 return OnError(); | 67 return OnError(); |
66 } | 68 } |
67 | 69 |
68 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); | 70 bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId); |
69 bool open_in_external_preview = | 71 bool open_in_external_preview = |
70 job_settings.HasKey(kSettingOpenPDFInPreview); | 72 job_settings.HasKey(kSettingOpenPDFInPreview); |
71 | 73 |
72 return UpdatePrinterSettings( | 74 if (!open_in_external_preview && |
73 print_to_pdf || is_cloud_dialog || print_to_cloud, | 75 (print_to_pdf || print_to_cloud || is_cloud_dialog)) { |
74 open_in_external_preview); | 76 settings_.set_dpi(kDefaultPdfDpi); |
| 77 // Cloud print should get size and rect from capabilities received from |
| 78 // server. |
| 79 gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); |
| 80 gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); |
| 81 if (print_to_cloud) { |
| 82 paper_rect.Inset( |
| 83 kCloudPrintMarginInch * settings_.device_units_per_inch(), |
| 84 kCloudPrintMarginInch * settings_.device_units_per_inch()); |
| 85 } |
| 86 settings_.SetPrinterPrintableArea(paper_size, paper_rect, true); |
| 87 return OK; |
| 88 } |
| 89 |
| 90 return UpdatePrinterSettings(open_in_external_preview); |
75 } | 91 } |
76 | 92 |
77 } // namespace printing | 93 } // namespace printing |
OLD | NEW |