OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/process_util.h" | 8 #include "base/process_util.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi); | 200 height = ConvertUnit(params.page_size.height(), dpi, desired_dpi); |
201 } else { | 201 } else { |
202 // Since WebKit extends the page width depending on the magical scale factor | 202 // Since WebKit extends the page width depending on the magical scale factor |
203 // we make sure the canvas covers the worst case scenario (x2.0 currently). | 203 // we make sure the canvas covers the worst case scenario (x2.0 currently). |
204 // PrintContext will then set the correct clipping region. | 204 // PrintContext will then set the correct clipping region. |
205 width = static_cast<int>(content_width_in_points * params.max_shrink); | 205 width = static_cast<int>(content_width_in_points * params.max_shrink); |
206 height = static_cast<int>(content_height_in_points * params.max_shrink); | 206 height = static_cast<int>(content_height_in_points * params.max_shrink); |
207 } | 207 } |
208 | 208 |
209 gfx::Size page_size(width, height); | 209 gfx::Size page_size(width, height); |
210 gfx::Point content_origin(static_cast<int>(margin_left_in_points), | 210 gfx::Rect content_area(static_cast<int>(margin_left_in_points), |
211 static_cast<int>(margin_top_in_points)); | 211 static_cast<int>(margin_top_in_points), |
| 212 static_cast<int>(content_width_in_points), |
| 213 static_cast<int>(content_height_in_points)); |
212 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( | 214 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( |
213 page_size, content_origin, frame->getPrintPageShrink(page_number)); | 215 page_size, content_area, frame->getPrintPageShrink(page_number)); |
214 DCHECK(device); | 216 DCHECK(device); |
215 skia::VectorCanvas canvas(device); | 217 skia::VectorCanvas canvas(device); |
216 | 218 |
217 float webkit_scale_factor = frame->printPage(page_number, &canvas); | 219 float webkit_scale_factor = frame->printPage(page_number, &canvas); |
218 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 220 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
219 NOTREACHED() << "Printing page " << page_number << " failed."; | 221 NOTREACHED() << "Printing page " << page_number << " failed."; |
220 } else { | 222 } else { |
221 // Update the dpi adjustment with the "page |scale_factor|" calculated in | 223 // Update the dpi adjustment with the "page |scale_factor|" calculated in |
222 // webkit. | 224 // webkit. |
223 *scale_factor /= webkit_scale_factor; | 225 *scale_factor /= webkit_scale_factor; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // Copy the bits into shared memory. | 306 // Copy the bits into shared memory. |
305 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 307 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
306 NOTREACHED() << "GetData() failed"; | 308 NOTREACHED() << "GetData() failed"; |
307 shared_buf.Unmap(); | 309 shared_buf.Unmap(); |
308 return false; | 310 return false; |
309 } | 311 } |
310 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 312 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
311 shared_buf.Unmap(); | 313 shared_buf.Unmap(); |
312 return true; | 314 return true; |
313 } | 315 } |
OLD | NEW |