| 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/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 #endif // defined(OS_CHROMEOS) | 136 #endif // defined(OS_CHROMEOS) |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, | 139 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, |
| 140 WebKit::WebFrame* frame, | 140 WebKit::WebFrame* frame, |
| 141 const WebKit::WebNode& node, | 141 const WebKit::WebNode& node, |
| 142 int* page_count, | 142 int* page_count, |
| 143 PrepareFrameAndViewForPrint* prepare, | 143 PrepareFrameAndViewForPrint* prepare, |
| 144 printing::Metafile* metafile) { | 144 printing::Metafile* metafile) { |
| 145 PrintMsg_Print_Params print_params = params.params; | 145 PrintMsg_Print_Params print_params = params.params; |
| 146 UpdatePrintableSizeInPrintParameters(frame, node, prepare, &print_params); | 146 UpdatePageSizeAndMarginsInFrameAndView(frame, node, prepare, print_params, |
| 147 ignore_css_margins_, |
| 148 fit_to_page_); |
| 147 | 149 |
| 148 *page_count = prepare->GetExpectedPageCount(); | 150 *page_count = prepare->GetExpectedPageCount(); |
| 149 if (!*page_count) | 151 if (!*page_count) |
| 150 return false; | 152 return false; |
| 151 | 153 |
| 152 #if !defined(OS_CHROMEOS) | 154 #if !defined(OS_CHROMEOS) |
| 153 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 155 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
| 154 print_params.document_cookie, | 156 print_params.document_cookie, |
| 155 *page_count)); | 157 *page_count)); |
| 156 #endif | 158 #endif |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 metafile->FinishDocument(); | 176 metafile->FinishDocument(); |
| 175 return true; | 177 return true; |
| 176 } | 178 } |
| 177 | 179 |
| 178 void PrintWebViewHelper::PrintPageInternal( | 180 void PrintWebViewHelper::PrintPageInternal( |
| 179 const PrintMsg_PrintPage_Params& params, | 181 const PrintMsg_PrintPage_Params& params, |
| 180 const gfx::Size& canvas_size, | 182 const gfx::Size& canvas_size, |
| 181 WebFrame* frame, | 183 WebFrame* frame, |
| 182 printing::Metafile* metafile) { | 184 printing::Metafile* metafile) { |
| 183 printing::PageSizeMargins page_layout_in_points; | 185 printing::PageSizeMargins page_layout_in_points; |
| 186 double scale_factor = 1.0f; |
| 184 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, | 187 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, |
| 185 &page_layout_in_points); | 188 ignore_css_margins_, fit_to_page_, &scale_factor, &page_layout_in_points); |
| 186 | 189 gfx::Size page_size; |
| 187 gfx::Size page_size( | 190 gfx::Rect content_area; |
| 188 page_layout_in_points.content_width + | 191 UpdatePageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 189 page_layout_in_points.margin_right + | 192 &content_area); |
| 190 page_layout_in_points.margin_left, | |
| 191 page_layout_in_points.content_height + | |
| 192 page_layout_in_points.margin_top + | |
| 193 page_layout_in_points.margin_bottom); | |
| 194 gfx::Rect content_area(page_layout_in_points.margin_left, | |
| 195 page_layout_in_points.margin_top, | |
| 196 page_layout_in_points.content_width, | |
| 197 page_layout_in_points.content_height); | |
| 198 | |
| 199 SkDevice* device = metafile->StartPageForVectorCanvas( | 193 SkDevice* device = metafile->StartPageForVectorCanvas( |
| 200 page_size, content_area, 1.0f); | 194 page_size, content_area, scale_factor); |
| 201 if (!device) | 195 if (!device) |
| 202 return; | 196 return; |
| 203 | 197 |
| 204 // The printPage method take a reference to the canvas we pass down, so it | 198 // The printPage method take a reference to the canvas we pass down, so it |
| 205 // can't be a stack object. | 199 // can't be a stack object. |
| 206 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 200 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
| 207 canvas->unref(); // SkRefPtr and new both took a reference. | 201 canvas->unref(); // SkRefPtr and new both took a reference. |
| 208 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 202 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 209 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 203 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 210 frame->printPage(params.page_number, canvas.get()); | 204 frame->printPage(params.page_number, canvas.get()); |
| 211 | 205 |
| 212 if (params.params.display_header_footer) { | 206 if (params.params.display_header_footer) { |
| 213 // |page_number| is 0-based, so 1 is added. | 207 // |page_number| is 0-based, so 1 is added. |
| 214 // The scale factor on Linux is 1. | 208 // The scale factor on Linux is 1. |
| 215 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 209 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
| 216 print_preview_context_.total_page_count(), 1, | 210 print_preview_context_.total_page_count(), |
| 217 page_layout_in_points, *header_footer_info_); | 211 scale_factor, page_layout_in_points, |
| 212 *header_footer_info_); |
| 218 } | 213 } |
| 219 | 214 |
| 220 // Done printing. Close the device context to retrieve the compiled metafile. | 215 // Done printing. Close the device context to retrieve the compiled metafile. |
| 221 if (!metafile->FinishPage()) | 216 if (!metafile->FinishPage()) |
| 222 NOTREACHED() << "metafile failed"; | 217 NOTREACHED() << "metafile failed"; |
| 223 } | 218 } |
| OLD | NEW |