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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 160 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
161 ignore_css_margins_, &scale_factor, | 161 ignore_css_margins_, &scale_factor, |
162 &page_layout_in_points); | 162 &page_layout_in_points); |
163 gfx::Size page_size; | 163 gfx::Size page_size; |
164 gfx::Rect content_area; | 164 gfx::Rect content_area; |
165 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 165 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
166 &content_area); | 166 &content_area); |
167 gfx::Rect canvas_area = | 167 gfx::Rect canvas_area = |
168 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 168 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
169 | 169 |
170 SkDevice* device = metafile->StartPageForVectorCanvas(page_size, canvas_area, | 170 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, |
171 scale_factor); | 171 canvas_area, |
| 172 scale_factor); |
172 if (!device) | 173 if (!device) |
173 return; | 174 return; |
174 | 175 |
175 // The printPage method take a reference to the canvas we pass down, so it | 176 // The printPage method take a reference to the canvas we pass down, so it |
176 // can't be a stack object. | 177 // can't be a stack object. |
177 skia::RefPtr<skia::VectorCanvas> canvas = | 178 skia::RefPtr<skia::VectorCanvas> canvas = |
178 skia::AdoptRef(new skia::VectorCanvas(device)); | 179 skia::AdoptRef(new skia::VectorCanvas(device)); |
179 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 180 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
180 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 181 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
181 | 182 |
182 if (params.params.display_header_footer) { | 183 if (params.params.display_header_footer) { |
183 // |page_number| is 0-based, so 1 is added. | 184 // |page_number| is 0-based, so 1 is added. |
184 // TODO(vitalybuka) : why does it work only with 1.25? | 185 // TODO(vitalybuka) : why does it work only with 1.25? |
185 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 186 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
186 print_preview_context_.total_page_count(), | 187 print_preview_context_.total_page_count(), |
187 scale_factor / 1.25, | 188 scale_factor / 1.25, |
188 page_layout_in_points, *header_footer_info_, | 189 page_layout_in_points, *header_footer_info_, |
189 params.params); | 190 params.params); |
190 } | 191 } |
191 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 192 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
192 scale_factor, canvas.get()); | 193 scale_factor, canvas.get()); |
193 | 194 |
194 // Done printing. Close the device context to retrieve the compiled metafile. | 195 // Done printing. Close the device context to retrieve the compiled metafile. |
195 if (!metafile->FinishPage()) | 196 if (!metafile->FinishPage()) |
196 NOTREACHED() << "metafile failed"; | 197 NOTREACHED() << "metafile failed"; |
197 } | 198 } |
198 | 199 |
199 } // namespace printing | 200 } // namespace printing |
OLD | NEW |