| 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/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 } | 136 } |
| 137 | 137 |
| 138 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, | 138 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, |
| 139 WebKit::WebFrame* frame, | 139 WebKit::WebFrame* frame, |
| 140 const WebKit::WebNode& node, | 140 const WebKit::WebNode& node, |
| 141 int* page_count, | 141 int* page_count, |
| 142 PrepareFrameAndViewForPrint* prepare, | 142 PrepareFrameAndViewForPrint* prepare, |
| 143 printing::Metafile* metafile) { | 143 printing::Metafile* metafile) { |
| 144 PrintMsg_Print_Params print_params = params.params; | 144 PrintMsg_Print_Params print_params = params.params; |
| 145 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare, print_params, | 145 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare, print_params, |
| 146 ignore_css_margins_, fit_to_page_); | 146 ignore_css_margins_); |
| 147 | 147 |
| 148 *page_count = prepare->GetExpectedPageCount(); | 148 *page_count = prepare->GetExpectedPageCount(); |
| 149 if (!*page_count) | 149 if (!*page_count) |
| 150 return false; | 150 return false; |
| 151 | 151 |
| 152 #if !defined(OS_CHROMEOS) | 152 #if !defined(OS_CHROMEOS) |
| 153 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 153 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
| 154 print_params.document_cookie, | 154 print_params.document_cookie, |
| 155 *page_count)); | 155 *page_count)); |
| 156 #endif | 156 #endif |
| (...skipping 19 matching lines...) Expand all Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 void PrintWebViewHelper::PrintPageInternal( | 178 void PrintWebViewHelper::PrintPageInternal( |
| 179 const PrintMsg_PrintPage_Params& params, | 179 const PrintMsg_PrintPage_Params& params, |
| 180 const gfx::Size& canvas_size, | 180 const gfx::Size& canvas_size, |
| 181 WebFrame* frame, | 181 WebFrame* frame, |
| 182 printing::Metafile* metafile) { | 182 printing::Metafile* metafile) { |
| 183 printing::PageSizeMargins page_layout_in_points; | 183 printing::PageSizeMargins page_layout_in_points; |
| 184 double scale_factor = 1.0f; | 184 double scale_factor = 1.0f; |
| 185 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 185 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 186 ignore_css_margins_, fit_to_page_, | 186 ignore_css_margins_, &scale_factor, |
| 187 &scale_factor, &page_layout_in_points); | 187 &page_layout_in_points); |
| 188 gfx::Size page_size; | 188 gfx::Size page_size; |
| 189 gfx::Rect content_area; | 189 gfx::Rect content_area; |
| 190 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 190 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 191 &content_area); | 191 &content_area); |
| 192 SkDevice* device = metafile->StartPageForVectorCanvas( | 192 SkDevice* device = metafile->StartPageForVectorCanvas( |
| 193 page_size, content_area, scale_factor); | 193 page_size, content_area, scale_factor); |
| 194 if (!device) | 194 if (!device) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 // The printPage method take a reference to the canvas we pass down, so it | 197 // The printPage method take a reference to the canvas we pass down, so it |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 208 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
| 209 print_preview_context_.total_page_count(), | 209 print_preview_context_.total_page_count(), |
| 210 scale_factor, page_layout_in_points, | 210 scale_factor, page_layout_in_points, |
| 211 *header_footer_info_); | 211 *header_footer_info_); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Done printing. Close the device context to retrieve the compiled metafile. | 214 // Done printing. Close the device context to retrieve the compiled metafile. |
| 215 if (!metafile->FinishPage()) | 215 if (!metafile->FinishPage()) |
| 216 NOTREACHED() << "metafile failed"; | 216 NOTREACHED() << "metafile failed"; |
| 217 } | 217 } |
| OLD | NEW |