Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: printing/printing_context_no_system_dialog.cc

Issue 46623002: Move settings setup for PDF and cloud print into single location in PrintingContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/printing_context_no_system_dialog.h ('k') | printing/printing_context_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_no_system_dialog.h" 5 #include "printing/printing_context_no_system_dialog.h"
6 6
7 #include <unicode/ulocdata.h> 7 #include <unicode/ulocdata.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 23 matching lines...) Expand all
34 bool has_selection, 34 bool has_selection,
35 const PrintSettingsCallback& callback) { 35 const PrintSettingsCallback& callback) {
36 // We don't want to bring up a dialog here. Ever. Just signal the callback. 36 // We don't want to bring up a dialog here. Ever. Just signal the callback.
37 callback.Run(OK); 37 callback.Run(OK);
38 } 38 }
39 39
40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() { 40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
41 DCHECK(!in_print_job_); 41 DCHECK(!in_print_job_);
42 42
43 ResetSettings(); 43 ResetSettings();
44 // TODO(abodenha): Fetch these settings from the OS where possible. See 44 settings_.set_dpi(kDefaultPdfDpi);
45 // bug 102583. 45 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
46 // TODO(sanjeevr): We need a better feedback loop between the cloud print 46 // Assume full page is printable for now.
47 // dialog and this code. 47 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
48 int dpi = 300; 48 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi);
49 gfx::Size physical_size_device_units; 49 settings_.SetPrinterPrintableArea(physical_size, printable_area, true);
50 gfx::Rect printable_area_device_units; 50 return OK;
51 }
52
53 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
51 int32_t width = 0; 54 int32_t width = 0;
52 int32_t height = 0; 55 int32_t height = 0;
53 UErrorCode error = U_ZERO_ERROR; 56 UErrorCode error = U_ZERO_ERROR;
54 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); 57 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
55 if (error > U_ZERO_ERROR) { 58 if (error > U_ZERO_ERROR) {
56 // If the call failed, assume a paper size of 8.5 x 11 inches. 59 // If the call failed, assume a paper size of 8.5 x 11 inches.
57 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " 60 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
58 << error; 61 << error;
59 width = static_cast<int>(8.5 * dpi); 62 width = static_cast<int>(
60 height = static_cast<int>(11 * dpi); 63 kLetterWidthInch * settings_.device_units_per_inch());
64 height = static_cast<int>(
65 kLetterHeightInch * settings_.device_units_per_inch());
61 } else { 66 } else {
62 // ulocdata_getPaperSize returns the width and height in mm. 67 // ulocdata_getPaperSize returns the width and height in mm.
63 // Convert this to pixels based on the dpi. 68 // Convert this to pixels based on the dpi.
64 width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi); 69 float multiplier = 100 * settings_.device_units_per_inch();
65 height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi); 70 multiplier /= kHundrethsMMPerInch;
71 width *= multiplier;
72 height *= multiplier;
66 } 73 }
67 74 return gfx::Size(width, height);
68 physical_size_device_units.SetSize(width, height);
69
70 // Assume full page is printable for now.
71 printable_area_device_units.SetRect(0, 0, width, height);
72
73 settings_.set_dpi(dpi);
74 settings_.SetPrinterPrintableArea(physical_size_device_units,
75 printable_area_device_units,
76 dpi, true);
77
78 return OK;
79 } 75 }
80 76
81 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings( 77 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
82 bool target_is_pdf,
83 bool external_preview) { 78 bool external_preview) {
84 79
85 if (settings_.dpi() == 0) 80 if (settings_.dpi() == 0)
86 UseDefaultSettings(); 81 UseDefaultSettings();
87 82
88 return OK; 83 return OK;
89 } 84 }
90 85
91 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings( 86 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
92 const PrintSettings& settings) { 87 const PrintSettings& settings) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Intentional No-op. 138 // Intentional No-op.
144 } 139 }
145 140
146 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const { 141 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
147 // Intentional No-op. 142 // Intentional No-op.
148 return NULL; 143 return NULL;
149 } 144 }
150 145
151 } // namespace printing 146 } // namespace printing
152 147
OLDNEW
« no previous file with comments | « printing/printing_context_no_system_dialog.h ('k') | printing/printing_context_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698