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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/win/scoped_gdi_object.h" | 11 #include "base/win/scoped_gdi_object.h" |
12 #include "base/win/scoped_hdc.h" | 12 #include "base/win/scoped_hdc.h" |
13 #include "base/win/scoped_select_object.h" | 13 #include "base/win/scoped_select_object.h" |
14 #include "chrome/common/print_messages.h" | 14 #include "chrome/common/print_messages.h" |
15 #include "printing/metafile.h" | 15 #include "printing/metafile.h" |
16 #include "printing/metafile_impl.h" | 16 #include "printing/metafile_impl.h" |
17 #include "printing/metafile_skia_wrapper.h" | 17 #include "printing/metafile_skia_wrapper.h" |
18 #include "printing/page_size_margins.h" | 18 #include "printing/page_size_margins.h" |
19 #include "printing/units.h" | 19 #include "printing/units.h" |
| 20 #include "skia/ext/platform_device.h" |
| 21 #include "skia/ext/refptr.h" |
20 #include "skia/ext/vector_canvas.h" | 22 #include "skia/ext/vector_canvas.h" |
21 #include "skia/ext/platform_device.h" | |
22 #include "third_party/skia/include/core/SkRefCnt.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
24 #include "ui/gfx/gdi_util.h" | 24 #include "ui/gfx/gdi_util.h" |
25 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
27 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
28 | 28 |
29 using printing::ConvertUnit; | 29 using printing::ConvertUnit; |
30 using printing::ConvertUnitDouble; | 30 using printing::ConvertUnitDouble; |
31 using printing::kPointsPerInch; | 31 using printing::kPointsPerInch; |
32 using printing::Metafile; | 32 using printing::Metafile; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 172 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
173 | 173 |
174 gfx::Rect canvas_area = | 174 gfx::Rect canvas_area = |
175 params.display_header_footer ? gfx::Rect(page_size) : content_area; | 175 params.display_header_footer ? gfx::Rect(page_size) : content_area; |
176 | 176 |
177 SkDevice* device = metafile->StartPageForVectorCanvas( | 177 SkDevice* device = metafile->StartPageForVectorCanvas( |
178 page_size, canvas_area, scale_factor); | 178 page_size, canvas_area, scale_factor); |
179 DCHECK(device); | 179 DCHECK(device); |
180 // The printPage method may take a reference to the canvas we pass down, so it | 180 // The printPage method may take a reference to the canvas we pass down, so it |
181 // can't be a stack object. | 181 // can't be a stack object. |
182 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 182 skia::RefPtr<skia::VectorCanvas> canvas = |
183 canvas->unref(); // SkRefPtr and new both took a reference. | 183 skia::AdoptRef(new skia::VectorCanvas(device)); |
184 | 184 |
185 if (is_preview) { | 185 if (is_preview) { |
186 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 186 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
187 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 187 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
188 skia::SetIsPreviewMetafile(*canvas, is_preview); | 188 skia::SetIsPreviewMetafile(*canvas, is_preview); |
189 } | 189 } |
190 | 190 |
191 if (params.display_header_footer) { | 191 if (params.display_header_footer) { |
192 // |page_number| is 0-based, so 1 is added. | 192 // |page_number| is 0-based, so 1 is added. |
193 PrintHeaderAndFooter(canvas.get(), page_number + 1, | 193 PrintHeaderAndFooter(canvas.get(), page_number + 1, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 shared_buf.Unmap(); | 241 shared_buf.Unmap(); |
242 return false; | 242 return false; |
243 } | 243 } |
244 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 244 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
245 shared_buf.Unmap(); | 245 shared_buf.Unmap(); |
246 | 246 |
247 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 247 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
248 shared_mem_handle)); | 248 shared_mem_handle)); |
249 return true; | 249 return true; |
250 } | 250 } |
OLD | NEW |