OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" | |
6 | |
7 #include "content/public/browser/browser_thread.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "printing/printing_context.h" | |
10 #include "printing/units.h" | |
11 | |
12 namespace content { | |
13 | |
14 namespace { | |
15 | |
16 #if defined(ENABLE_PRINTING) | |
17 // Print units conversion functions. | |
18 int32_t DeviceUnitsInPoints(int32_t device_units, | |
19 int32_t device_units_per_inch) { | |
20 | |
brettw
2012/09/18 21:41:38
Remove blank.
raymes
2012/09/18 23:43:57
Done.
| |
21 return printing::ConvertUnit(device_units, printing::kPointsPerInch, | |
22 device_units_per_inch); | |
23 } | |
24 | |
25 PP_Size PrintSizeToPPPrintSize(const gfx::Size& print_size, | |
26 int32_t device_units_per_inch) { | |
27 PP_Size result; | |
28 result.width = DeviceUnitsInPoints(print_size.width(), device_units_per_inch); | |
29 result.height = DeviceUnitsInPoints(print_size.height(), | |
30 device_units_per_inch); | |
31 return result; | |
32 } | |
33 | |
34 PP_Rect PrintAreaToPPPrintArea(const gfx::Rect& print_area, | |
35 int32_t device_units_per_inch) { | |
36 PP_Rect result; | |
37 result.point.x = DeviceUnitsInPoints(print_area.origin().x(), | |
38 device_units_per_inch); | |
39 result.point.y = DeviceUnitsInPoints(print_area.origin().y(), | |
40 device_units_per_inch); | |
41 result.size = PrintSizeToPPPrintSize(print_area.size(), | |
42 device_units_per_inch); | |
43 return result; | |
44 } | |
45 | |
46 PepperPrintSettingsManager::Result ComputeDefaultPrintSettings() { | |
47 // This function should run on the UI thread because |PrintingContext| methods | |
48 // call into platform APIs. | |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
50 scoped_ptr<printing::PrintingContext> context( | |
51 printing::PrintingContext::Create("")); | |
brettw
2012/09/18 21:41:38
"" -> std::string()
raymes
2012/09/18 23:43:57
Done.
| |
52 if (!context.get()) | |
brettw
2012/09/18 21:41:38
Need {} for multiline bodies as per style guide.
raymes
2012/09/18 23:43:57
Done.
| |
53 return PepperPrintSettingsManager::Result(PP_PrintSettings_Dev(), | |
54 PP_ERROR_FAILED); | |
55 context->UseDefaultSettings(); | |
56 const printing::PrintSettings& print_settings = context->settings(); | |
57 const printing::PageSetup& page_setup = | |
58 print_settings.page_setup_device_units(); | |
59 int device_units_per_inch = print_settings.device_units_per_inch(); | |
60 PP_PrintSettings_Dev settings; | |
61 settings.printable_area = PrintAreaToPPPrintArea( | |
62 page_setup.printable_area(), device_units_per_inch); | |
63 settings.content_area = PrintAreaToPPPrintArea( | |
64 page_setup.content_area(), device_units_per_inch); | |
65 settings.paper_size = PrintSizeToPPPrintSize( | |
66 page_setup.physical_size(), device_units_per_inch); | |
67 settings.dpi = print_settings.dpi(); | |
68 | |
69 // The remainder of the attributes are hard-coded to the defaults as set | |
70 // elsewhere. | |
71 settings.orientation = PP_PRINTORIENTATION_NORMAL; | |
72 settings.grayscale = PP_FALSE; | |
73 settings.print_scaling_option = PP_PRINTSCALINGOPTION_SOURCE_SIZE; | |
74 | |
75 // TODO(raymes): Should be computed in the same way as | |
76 // |PluginInstance::GetPreferredPrintOutputFormat|. | |
77 // |PP_PRINTOUTPUTFORMAT_PDF| is currently the only supported format though, | |
78 // so just make it the default. | |
79 settings.format = PP_PRINTOUTPUTFORMAT_PDF; | |
80 return PepperPrintSettingsManager::Result(settings, PP_OK); | |
81 } | |
82 #else | |
83 PepperPrintSettingsManager::Result ComputeDefaultPrintSettings() { | |
84 return PepperPrintSettingsManager::Result(PP_PrintSettings_Dev(), | |
85 PP_ERROR_NOTSUPPORTED); | |
86 } | |
87 #endif | |
88 | |
89 } // namespace | |
brettw
2012/09/18 21:41:38
two spaces before //
raymes
2012/09/18 23:43:57
Done.
| |
90 | |
91 void PepperPrintSettingsManagerImpl::GetDefaultPrintSettings( | |
92 PepperPrintSettingsManager::Callback callback) { | |
93 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, | |
94 base::Bind(ComputeDefaultPrintSettings), callback); | |
95 } | |
96 | |
97 MockPepperPrintSettingsManager::MockPepperPrintSettingsManager( | |
98 const PP_PrintSettings_Dev& settings) | |
99 : settings_(settings) { | |
100 } | |
101 | |
102 void MockPepperPrintSettingsManager::GetDefaultPrintSettings( | |
103 PepperPrintSettingsManager::Callback callback) { | |
104 callback.Run(PepperPrintSettingsManager::Result(settings_, PP_OK)); | |
105 } | |
106 | |
107 } // namespace content | |
OLD | NEW |