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