| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = |
| 167 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 167 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
| 168 | 168 |
| 169 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, | 169 skia::VectorCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
| 170 canvas_area, | 170 page_size, canvas_area, scale_factor); |
| 171 scale_factor); | 171 if (!canvas) |
| 172 if (!device) | |
| 173 return; | 172 return; |
| 174 | 173 |
| 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); | 174 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 180 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 175 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 181 | 176 |
| 182 if (params.params.display_header_footer) { | 177 if (params.params.display_header_footer) { |
| 183 // |page_number| is 0-based, so 1 is added. | 178 // |page_number| is 0-based, so 1 is added. |
| 184 // TODO(vitalybuka) : why does it work only with 1.25? | 179 // TODO(vitalybuka) : why does it work only with 1.25? |
| 185 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 180 PrintHeaderAndFooter(canvas, params.page_number + 1, |
| 186 print_preview_context_.total_page_count(), | 181 print_preview_context_.total_page_count(), |
| 187 scale_factor / 1.25, | 182 scale_factor / 1.25, |
| 188 page_layout_in_points, *header_footer_info_, | 183 page_layout_in_points, *header_footer_info_, |
| 189 params.params); | 184 params.params); |
| 190 } | 185 } |
| 191 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 186 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
| 192 scale_factor, canvas.get()); | 187 scale_factor, canvas); |
| 193 | 188 |
| 194 // Done printing. Close the device context to retrieve the compiled metafile. | 189 // Done printing. Close the canvas to retrieve the compiled metafile. |
| 195 if (!metafile->FinishPage()) | 190 if (!metafile->FinishPage()) |
| 196 NOTREACHED() << "metafile failed"; | 191 NOTREACHED() << "metafile failed"; |
| 197 } | 192 } |
| 198 | 193 |
| 199 } // namespace printing | 194 } // namespace printing |
| OLD | NEW |