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/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 "chrome/common/print_messages.h" | 9 #include "chrome/common/print_messages.h" |
10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 PdfMetafileSkia* metafile) { | 151 PdfMetafileSkia* metafile) { |
152 PageSizeMargins page_layout_in_points; | 152 PageSizeMargins page_layout_in_points; |
153 double scale_factor = 1.0f; | 153 double scale_factor = 1.0f; |
154 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 154 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
155 ignore_css_margins_, &scale_factor, | 155 ignore_css_margins_, &scale_factor, |
156 &page_layout_in_points); | 156 &page_layout_in_points); |
157 gfx::Size page_size; | 157 gfx::Size page_size; |
158 gfx::Rect content_area; | 158 gfx::Rect content_area; |
159 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 159 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
160 &content_area); | 160 &content_area); |
161 gfx::Rect canvas_area = | 161 gfx::Rect canvas_area = gfx::Rect(page_size); // Allow drawing on |
162 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 162 // entire page. |
163 | 163 skia::RefPtr<skia::VectorCanvas> canvas = |
164 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, | 164 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); |
165 canvas_area, | 165 if (!canvas.get()) |
166 scale_factor); | |
167 if (!device) | |
168 return; | 166 return; |
169 | 167 |
170 // The printPage method take a reference to the canvas we pass down, so it | |
171 // can't be a stack object. | |
172 skia::RefPtr<skia::VectorCanvas> canvas = | |
173 skia::AdoptRef(new skia::VectorCanvas(device)); | |
174 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 168 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
175 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 169 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
176 | 170 |
177 if (params.params.display_header_footer) { | 171 if (params.params.display_header_footer) { |
178 // |page_number| is 0-based, so 1 is added. | 172 // |page_number| is 0-based, so 1 is added. |
179 // TODO(vitalybuka) : why does it work only with 1.25? | 173 // TODO(vitalybuka) : why does it work only with 1.25? |
180 PrintHeaderAndFooter(canvas.get(), | 174 PrintHeaderAndFooter(canvas.get(), |
181 params.page_number + 1, | 175 params.page_number + 1, |
182 print_preview_context_.total_page_count(), | 176 print_preview_context_.total_page_count(), |
183 *frame, | 177 *frame, |
184 scale_factor / 1.25, | 178 scale_factor / 1.25, |
185 page_layout_in_points, | 179 page_layout_in_points, |
186 params.params); | 180 params.params); |
187 } | 181 } |
188 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 182 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
189 scale_factor, canvas.get()); | 183 scale_factor, canvas.get()); |
| 184 canvas.clear(); // Unref canvas before calling FinishPage. |
190 | 185 |
191 // Done printing. Close the device context to retrieve the compiled metafile. | 186 // Done printing. Close the device context to retrieve the compiled metafile. |
192 if (!metafile->FinishPage()) | 187 if (!metafile->FinishPage()) |
193 NOTREACHED() << "metafile failed"; | 188 NOTREACHED() << "metafile failed"; |
194 } | 189 } |
195 | 190 |
196 } // namespace printing | 191 } // namespace printing |
OLD | NEW |