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