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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ComputePageLayoutInPointsForCss(frame, page_number, params, | 107 ComputePageLayoutInPointsForCss(frame, page_number, params, |
108 ignore_css_margins_, &scale_factor, | 108 ignore_css_margins_, &scale_factor, |
109 &page_layout_in_points); | 109 &page_layout_in_points); |
110 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, | 110 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, |
111 &content_area); | 111 &content_area); |
112 if (content_rect) | 112 if (content_rect) |
113 *content_rect = content_area; | 113 *content_rect = content_area; |
114 | 114 |
115 scale_factor *= webkit_shrink_factor; | 115 scale_factor *= webkit_shrink_factor; |
116 | 116 |
117 gfx::Rect canvas_area = | 117 gfx::Rect canvas_area = gfx::Rect(*page_size); // Allow drawing on |
118 params.display_header_footer ? gfx::Rect(*page_size) : content_area; | 118 // entire page. |
| 119 skia::RefPtr<skia::VectorCanvas> canvas = |
| 120 metafile->GetVectorCanvasForNewPage(*page_size, canvas_area, scale_factor); |
| 121 if (!canvas.get()) |
| 122 return; |
119 | 123 |
120 { | 124 blink::WebCanvas* canvas_ptr = canvas.get(); |
121 SkBaseDevice* device = metafile->StartPageForVectorCanvas( | 125 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
122 *page_size, canvas_area, scale_factor); | 126 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
123 if (!device) | 127 skia::SetIsPreviewMetafile(*canvas, is_preview); |
124 return; | |
125 | 128 |
126 skia::RefPtr<skia::VectorCanvas> canvas = | 129 if (params.display_header_footer) { |
127 skia::AdoptRef(new skia::VectorCanvas(device)); | 130 PrintHeaderAndFooter(canvas_ptr, |
128 blink::WebCanvas* canvas_ptr = canvas.get(); | 131 page_number + 1, |
129 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 132 print_preview_context_.total_page_count(), |
130 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 133 *frame, |
131 skia::SetIsPreviewMetafile(*canvas, is_preview); | 134 scale_factor, |
| 135 page_layout_in_points, |
| 136 params); |
| 137 } |
| 138 RenderPageContent(frame, page_number, canvas_area, content_area, |
| 139 scale_factor, canvas_ptr); |
132 | 140 |
133 if (params.display_header_footer) { | 141 canvas.clear(); // Unref the canvas before calling FinishPage(). |
134 PrintHeaderAndFooter(canvas_ptr, | |
135 page_number + 1, | |
136 print_preview_context_.total_page_count(), | |
137 *frame, | |
138 scale_factor, | |
139 page_layout_in_points, | |
140 params); | |
141 } | |
142 RenderPageContent(frame, page_number, canvas_area, content_area, | |
143 scale_factor, canvas_ptr); | |
144 } | |
145 | |
146 // Done printing. Close the device context to retrieve the compiled metafile. | 142 // Done printing. Close the device context to retrieve the compiled metafile. |
147 metafile->FinishPage(); | 143 metafile->FinishPage(); |
148 } | 144 } |
149 | 145 |
150 } // namespace printing | 146 } // namespace printing |
OLD | NEW |