| 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 "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "chrome/common/print_messages.h" | 11 #include "chrome/common/print_messages.h" |
| 12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.h" |
| 13 #include "printing/metafile.h" | 13 #include "printing/metafile.h" |
| 14 #include "printing/metafile_impl.h" | 14 #include "printing/metafile_impl.h" |
| 15 #include "printing/metafile_skia_wrapper.h" | 15 #include "printing/metafile_skia_wrapper.h" |
| 16 #include "printing/page_size_margins.h" | 16 #include "printing/page_size_margins.h" |
| 17 #include "skia/ext/platform_device.h" | 17 #include "skia/ext/platform_device.h" |
| 18 #include "skia/ext/refptr.h" |
| 18 #include "skia/ext/vector_canvas.h" | 19 #include "skia/ext/vector_canvas.h" |
| 19 #include "third_party/skia/include/core/SkRefCnt.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 21 | 21 |
| 22 #if !defined(OS_CHROMEOS) | 22 #if !defined(OS_CHROMEOS) |
| 23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
| 24 #endif // !defined(OS_CHROMEOS) | 24 #endif // !defined(OS_CHROMEOS) |
| 25 | 25 |
| 26 using WebKit::WebFrame; | 26 using WebKit::WebFrame; |
| 27 using WebKit::WebNode; | 27 using WebKit::WebNode; |
| 28 | 28 |
| 29 bool PrintWebViewHelper::RenderPreviewPage( | 29 bool PrintWebViewHelper::RenderPreviewPage( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 180 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 181 ignore_css_margins_, &scale_factor, | 181 ignore_css_margins_, &scale_factor, |
| 182 &page_layout_in_points); | 182 &page_layout_in_points); |
| 183 gfx::Size page_size; | 183 gfx::Size page_size; |
| 184 gfx::Rect content_area; | 184 gfx::Rect content_area; |
| 185 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 185 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 186 &content_area); | 186 &content_area); |
| 187 gfx::Rect canvas_area = | 187 gfx::Rect canvas_area = |
| 188 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 188 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
| 189 | 189 |
| 190 SkDevice* device = metafile->StartPageForVectorCanvas(page_size, canvas_area, | 190 skia::RefPtr<SkDevice> device = metafile->StartPageForVectorCanvas( |
| 191 scale_factor); | 191 page_size, canvas_area, scale_factor); |
| 192 if (!device) | 192 if (!device) |
| 193 return; | 193 return; |
| 194 | 194 |
| 195 // The printPage method take a reference to the canvas we pass down, so it | 195 // The printPage method take a reference to the canvas we pass down, so it |
| 196 // can't be a stack object. | 196 // can't be a stack object. |
| 197 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 197 skia::RefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
| 198 canvas->unref(); // SkRefPtr and new both took a reference. | |
| 199 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 198 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 200 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 199 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 201 | 200 |
| 202 if (params.params.display_header_footer) { | 201 if (params.params.display_header_footer) { |
| 203 // |page_number| is 0-based, so 1 is added. | 202 // |page_number| is 0-based, so 1 is added. |
| 204 // TODO(vitalybuka) : why does it work only with 1.25? | 203 // TODO(vitalybuka) : why does it work only with 1.25? |
| 205 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 204 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
| 206 print_preview_context_.total_page_count(), | 205 print_preview_context_.total_page_count(), |
| 207 scale_factor / 1.25, | 206 scale_factor / 1.25, |
| 208 page_layout_in_points, *header_footer_info_, | 207 page_layout_in_points, *header_footer_info_, |
| 209 params.params); | 208 params.params); |
| 210 } | 209 } |
| 211 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 210 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
| 212 scale_factor, canvas.get()); | 211 scale_factor, canvas.get()); |
| 213 | 212 |
| 214 // Done printing. Close the device context to retrieve the compiled metafile. | 213 // Done printing. Close the device context to retrieve the compiled metafile. |
| 215 if (!metafile->FinishPage()) | 214 if (!metafile->FinishPage()) |
| 216 NOTREACHED() << "metafile failed"; | 215 NOTREACHED() << "metafile failed"; |
| 217 } | 216 } |
| OLD | NEW |