| 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 UpdatePrintableSizeInPrintParameters(frame, node, prepare, print_params, |
| 147 ignore_frame_margins_css_, |
| 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_frame_margins_css_, fit_to_page_, |
| 186 | 189 &scale_factor, &page_layout_in_points); |
| 187 gfx::Size page_size( | 190 gfx::Size page_size( |
| 188 page_layout_in_points.content_width + | 191 page_layout_in_points.content_width + |
| 189 page_layout_in_points.margin_right + | 192 page_layout_in_points.margin_right + |
| 190 page_layout_in_points.margin_left, | 193 page_layout_in_points.margin_left, |
| 191 page_layout_in_points.content_height + | 194 page_layout_in_points.content_height + |
| 192 page_layout_in_points.margin_top + | 195 page_layout_in_points.margin_top + |
| 193 page_layout_in_points.margin_bottom); | 196 page_layout_in_points.margin_bottom); |
| 194 gfx::Rect content_area(page_layout_in_points.margin_left, | 197 gfx::Rect content_area(page_layout_in_points.margin_left, |
| 195 page_layout_in_points.margin_top, | 198 page_layout_in_points.margin_top, |
| 196 page_layout_in_points.content_width, | 199 page_layout_in_points.content_width, |
| 197 page_layout_in_points.content_height); | 200 page_layout_in_points.content_height); |
| 198 | |
| 199 SkDevice* device = metafile->StartPageForVectorCanvas( | 201 SkDevice* device = metafile->StartPageForVectorCanvas( |
| 200 page_size, content_area, 1.0f); | 202 page_size, content_area, scale_factor); |
| 201 if (!device) | 203 if (!device) |
| 202 return; | 204 return; |
| 203 | 205 |
| 204 // The printPage method take a reference to the canvas we pass down, so it | 206 // The printPage method take a reference to the canvas we pass down, so it |
| 205 // can't be a stack object. | 207 // can't be a stack object. |
| 206 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 208 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
| 207 canvas->unref(); // SkRefPtr and new both took a reference. | 209 canvas->unref(); // SkRefPtr and new both took a reference. |
| 208 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 210 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 209 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 211 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 210 frame->printPage(params.page_number, canvas.get()); | 212 frame->printPage(params.page_number, canvas.get()); |
| 211 | 213 |
| 212 if (params.params.display_header_footer) { | 214 if (params.params.display_header_footer) { |
| 213 // |page_number| is 0-based, so 1 is added. | 215 // |page_number| is 0-based, so 1 is added. |
| 214 // The scale factor on Linux is 1. | 216 // The scale factor on Linux is 1. |
| 215 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 217 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
| 216 print_preview_context_.total_page_count(), 1, | 218 print_preview_context_.total_page_count(), |
| 217 page_layout_in_points, *header_footer_info_); | 219 scale_factor, page_layout_in_points, |
| 220 *header_footer_info_); |
| 218 } | 221 } |
| 219 | 222 |
| 220 // Done printing. Close the device context to retrieve the compiled metafile. | 223 // Done printing. Close the device context to retrieve the compiled metafile. |
| 221 if (!metafile->FinishPage()) | 224 if (!metafile->FinishPage()) |
| 222 NOTREACHED() << "metafile failed"; | 225 NOTREACHED() << "metafile failed"; |
| 223 } | 226 } |
| OLD | NEW |