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/print_web_view_helper.h" | 5 #include "chrome/renderer/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 "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // we make sure the canvas covers the worst case scenario (x2.0 currently). | 155 // we make sure the canvas covers the worst case scenario (x2.0 currently). |
156 // PrintContext will then set the correct clipping region. | 156 // PrintContext will then set the correct clipping region. |
157 page_size = gfx::Size( | 157 page_size = gfx::Size( |
158 static_cast<int>(page_layout_in_points.content_width * | 158 static_cast<int>(page_layout_in_points.content_width * |
159 params.max_shrink), | 159 params.max_shrink), |
160 static_cast<int>(page_layout_in_points.content_height * | 160 static_cast<int>(page_layout_in_points.content_height * |
161 params.max_shrink)); | 161 params.max_shrink)); |
162 } | 162 } |
163 | 163 |
164 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number); | 164 float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number); |
| 165 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
| 166 |
| 167 gfx::Rect canvas_area = |
| 168 params.display_header_footer ? gfx::Rect(page_size) : content_area; |
| 169 |
165 SkDevice* device = metafile->StartPageForVectorCanvas( | 170 SkDevice* device = metafile->StartPageForVectorCanvas( |
166 page_size, content_area, css_scale_factor * webkit_page_shrink_factor); | 171 page_size, canvas_area, scale_factor); |
167 DCHECK(device); | 172 DCHECK(device); |
168 // The printPage method may take a reference to the canvas we pass down, so it | 173 // The printPage method may take a reference to the canvas we pass down, so it |
169 // can't be a stack object. | 174 // can't be a stack object. |
170 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 175 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
171 canvas->unref(); // SkRefPtr and new both took a reference. | 176 canvas->unref(); // SkRefPtr and new both took a reference. |
| 177 |
172 if (is_preview) { | 178 if (is_preview) { |
173 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 179 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
174 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 180 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
175 skia::SetIsPreviewMetafile(*canvas, is_preview); | 181 skia::SetIsPreviewMetafile(*canvas, is_preview); |
176 } | 182 } |
177 | 183 |
178 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); | |
179 | |
180 if (params.display_header_footer) { | 184 if (params.display_header_footer) { |
181 // |page_number| is 0-based, so 1 is added. | 185 // |page_number| is 0-based, so 1 is added. |
182 PrintHeaderAndFooter(canvas.get(), page_number + 1, | 186 PrintHeaderAndFooter(canvas.get(), page_number + 1, |
183 print_preview_context_.total_page_count(), | 187 print_preview_context_.total_page_count(), scale_factor, |
184 css_scale_factor * webkit_page_shrink_factor, | 188 page_layout_in_points, *header_footer_info_, params); |
185 page_layout_in_points, *header_footer_info_, params); | |
186 } | 189 } |
187 | 190 |
| 191 float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area, |
| 192 content_area, scale_factor, |
| 193 canvas.get()); |
| 194 |
188 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { | 195 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { |
189 NOTREACHED() << "Printing page " << page_number << " failed."; | 196 NOTREACHED() << "Printing page " << page_number << " failed."; |
190 } else { | 197 } else { |
191 // While rendering certain plugins (PDF) to metafile, we might need to | 198 // While rendering certain plugins (PDF) to metafile, we might need to |
192 // set custom scale factor. Update |actual_shrink| with custom scale | 199 // set custom scale factor. Update |actual_shrink| with custom scale |
193 // if it is set on canvas. | 200 // if it is set on canvas. |
194 // TODO(gene): We should revisit this solution for the next versions. | 201 // TODO(gene): We should revisit this solution for the next versions. |
195 // Consider creating metafile of the right size (or resizable) | 202 // Consider creating metafile of the right size (or resizable) |
196 // https://code.google.com/p/chromium/issues/detail?id=126037 | 203 // https://code.google.com/p/chromium/issues/detail?id=126037 |
197 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( | 204 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( |
(...skipping 29 matching lines...) Expand all Loading... |
227 shared_buf.Unmap(); | 234 shared_buf.Unmap(); |
228 return false; | 235 return false; |
229 } | 236 } |
230 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 237 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
231 shared_buf.Unmap(); | 238 shared_buf.Unmap(); |
232 | 239 |
233 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 240 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
234 shared_mem_handle)); | 241 shared_mem_handle)); |
235 return true; | 242 return true; |
236 } | 243 } |
OLD | NEW |