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 "chrome/renderer/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/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 "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 static_cast<int>(ConvertUnitDouble( | 165 static_cast<int>(ConvertUnitDouble( |
166 page_size.height(), kPointsPerInch, dpi))); | 166 page_size.height(), kPointsPerInch, dpi))); |
167 } | 167 } |
168 | 168 |
169 if (content_area_in_dpi) { | 169 if (content_area_in_dpi) { |
170 // Output PDF matches paper size and should be printer edge to edge. | 170 // Output PDF matches paper size and should be printer edge to edge. |
171 *content_area_in_dpi = | 171 *content_area_in_dpi = |
172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
173 } | 173 } |
174 | 174 |
175 gfx::Rect canvas_area = | 175 gfx::Rect canvas_area = gfx::Rect(page_size); |
176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | |
177 | 176 |
178 float webkit_page_shrink_factor = | 177 float webkit_page_shrink_factor = |
179 frame->getPrintPageShrink(params.page_number); | 178 frame->getPrintPageShrink(params.page_number); |
180 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 179 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
181 | 180 |
182 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, | 181 skia::RefPtr<skia::VectorCanvas> canvas = |
183 canvas_area, | 182 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); |
184 scale_factor); | 183 if (!canvas.get()) { |
Vitaly Buka (NO REVIEWS)
2014/11/03 20:03:29
Please try to keep style of the file consistent, d
hal.canary
2014/11/04 15:30:35
Done.
| |
185 if (!device) | |
186 return; | 184 return; |
185 } | |
187 | 186 |
188 // The printPage method take a reference to the canvas we pass down, so it | |
189 // can't be a stack object. | |
190 skia::RefPtr<skia::VectorCanvas> canvas = | |
191 skia::AdoptRef(new skia::VectorCanvas(device)); | |
192 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 187 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
193 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 188 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
194 | 189 |
195 if (params.params.display_header_footer) { | 190 if (params.params.display_header_footer) { |
196 // |page_number| is 0-based, so 1 is added. | 191 // |page_number| is 0-based, so 1 is added. |
197 PrintHeaderAndFooter(canvas.get(), | 192 PrintHeaderAndFooter(canvas.get(), |
198 params.page_number + 1, | 193 params.page_number + 1, |
199 print_preview_context_.total_page_count(), | 194 print_preview_context_.total_page_count(), |
200 *frame, | 195 *frame, |
201 scale_factor, | 196 scale_factor, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 } | 229 } |
235 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 230 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
236 shared_buf.Unmap(); | 231 shared_buf.Unmap(); |
237 | 232 |
238 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 233 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
239 shared_mem_handle)); | 234 shared_mem_handle)); |
240 return true; | 235 return true; |
241 } | 236 } |
242 | 237 |
243 } // namespace printing | 238 } // namespace printing |
OLD | NEW |