OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "components/printing/common/print_messages.h" | 9 #include "components/printing/common/print_messages.h" |
10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
11 #include "printing/metafile_skia_wrapper.h" | 11 #include "printing/metafile_skia_wrapper.h" |
12 #include "printing/page_size_margins.h" | 12 #include "printing/page_size_margins.h" |
13 #include "printing/pdf_metafile_skia.h" | 13 #include "printing/pdf_metafile_skia.h" |
14 #include "skia/ext/platform_device.h" | 14 #include "skia/ext/platform_device.h" |
15 #include "skia/ext/vector_canvas.h" | |
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
17 | 16 |
18 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 17 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
19 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
20 #else | 19 #else |
21 #include "base/file_descriptor_posix.h" | 20 #include "base/file_descriptor_posix.h" |
22 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 21 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
23 | 22 |
24 namespace printing { | 23 namespace printing { |
25 | 24 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 153 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
155 ignore_css_margins_, &scale_factor, | 154 ignore_css_margins_, &scale_factor, |
156 &page_layout_in_points); | 155 &page_layout_in_points); |
157 gfx::Size page_size; | 156 gfx::Size page_size; |
158 gfx::Rect content_area; | 157 gfx::Rect content_area; |
159 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 158 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
160 &content_area); | 159 &content_area); |
161 gfx::Rect canvas_area = | 160 gfx::Rect canvas_area = |
162 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 161 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
163 | 162 |
164 skia::VectorCanvas* canvas = | 163 skia::PlatformCanvas* canvas = |
165 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); | 164 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); |
166 if (!canvas) | 165 if (!canvas) |
167 return; | 166 return; |
168 | 167 |
169 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 168 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
170 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 169 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
171 | 170 |
172 #if defined(ENABLE_PRINT_PREVIEW) | 171 #if defined(ENABLE_PRINT_PREVIEW) |
173 if (params.params.display_header_footer) { | 172 if (params.params.display_header_footer) { |
174 // |page_number| is 0-based, so 1 is added. | 173 // |page_number| is 0-based, so 1 is added. |
175 // TODO(vitalybuka) : why does it work only with 1.25? | 174 // TODO(vitalybuka) : why does it work only with 1.25? |
176 PrintHeaderAndFooter(canvas, params.page_number + 1, | 175 PrintHeaderAndFooter(canvas, params.page_number + 1, |
177 print_preview_context_.total_page_count(), *frame, | 176 print_preview_context_.total_page_count(), *frame, |
178 scale_factor / 1.25, page_layout_in_points, | 177 scale_factor / 1.25, page_layout_in_points, |
179 params.params); | 178 params.params); |
180 } | 179 } |
181 #endif // defined(ENABLE_PRINT_PREVIEW) | 180 #endif // defined(ENABLE_PRINT_PREVIEW) |
182 | 181 |
183 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 182 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
184 scale_factor, canvas); | 183 scale_factor, canvas); |
185 | 184 |
186 // Done printing. Close the canvas to retrieve the compiled metafile. | 185 // Done printing. Close the canvas to retrieve the compiled metafile. |
187 if (!metafile->FinishPage()) | 186 if (!metafile->FinishPage()) |
188 NOTREACHED() << "metafile failed"; | 187 NOTREACHED() << "metafile failed"; |
189 } | 188 } |
190 | 189 |
191 } // namespace printing | 190 } // namespace printing |
OLD | NEW |