OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
10 #include "components/printing/common/print_messages.h" | 10 #include "components/printing/common/print_messages.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 #include "printing/metafile_skia_wrapper.h" | 12 #include "printing/metafile_skia_wrapper.h" |
13 #include "printing/page_size_margins.h" | 13 #include "printing/page_size_margins.h" |
14 #include "printing/pdf_metafile_skia.h" | 14 #include "printing/pdf_metafile_skia.h" |
15 #include "printing/units.h" | 15 #include "printing/units.h" |
16 #include "skia/ext/platform_device.h" | 16 #include "skia/ext/platform_device.h" |
17 #include "skia/ext/vector_canvas.h" | 17 #include "skia/ext/vector_canvas.h" |
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
19 | 19 |
20 | |
21 namespace printing { | 20 namespace printing { |
22 | 21 |
23 using blink::WebFrame; | 22 using blink::WebFrame; |
24 | 23 |
25 bool PrintWebViewHelper::RenderPreviewPage( | 24 bool PrintWebViewHelper::RenderPreviewPage( |
26 int page_number, | 25 int page_number, |
27 const PrintMsg_Print_Params& print_params) { | 26 const PrintMsg_Print_Params& print_params) { |
28 PrintMsg_PrintPage_Params page_params; | 27 PrintMsg_PrintPage_Params page_params; |
29 page_params.params = print_params; | 28 page_params.params = print_params; |
30 page_params.page_number = page_number; | 29 page_params.page_number = page_number; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ignore_css_margins_, &css_scale_factor, | 152 ignore_css_margins_, &css_scale_factor, |
154 &page_layout_in_points); | 153 &page_layout_in_points); |
155 gfx::Size page_size; | 154 gfx::Size page_size; |
156 gfx::Rect content_area; | 155 gfx::Rect content_area; |
157 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 156 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
158 &content_area); | 157 &content_area); |
159 int dpi = static_cast<int>(params.params.dpi); | 158 int dpi = static_cast<int>(params.params.dpi); |
160 // Calculate the actual page size and content area in dpi. | 159 // Calculate the actual page size and content area in dpi. |
161 if (page_size_in_dpi) { | 160 if (page_size_in_dpi) { |
162 *page_size_in_dpi = | 161 *page_size_in_dpi = |
163 gfx::Size(static_cast<int>(ConvertUnitDouble( | 162 gfx::Size(static_cast<int>(ConvertUnitDouble(page_size.width(), |
164 page_size.width(), kPointsPerInch, dpi)), | 163 kPointsPerInch, dpi)), |
165 static_cast<int>(ConvertUnitDouble( | 164 static_cast<int>(ConvertUnitDouble(page_size.height(), |
166 page_size.height(), kPointsPerInch, dpi))); | 165 kPointsPerInch, dpi))); |
167 } | 166 } |
168 | 167 |
169 if (content_area_in_dpi) { | 168 if (content_area_in_dpi) { |
170 // Output PDF matches paper size and should be printer edge to edge. | 169 // Output PDF matches paper size and should be printer edge to edge. |
171 *content_area_in_dpi = | 170 *content_area_in_dpi = |
172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 171 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
173 } | 172 } |
174 | 173 |
175 gfx::Rect canvas_area = | 174 gfx::Rect canvas_area = |
176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 175 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 223 } |
225 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 224 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
226 shared_buf.Unmap(); | 225 shared_buf.Unmap(); |
227 | 226 |
228 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 227 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
229 shared_mem_handle)); | 228 shared_mem_handle)); |
230 return true; | 229 return true; |
231 } | 230 } |
232 | 231 |
233 } // namespace printing | 232 } // namespace printing |
OLD | NEW |