OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "printing/native_metafile.h" | 9 #include "printing/native_metafile.h" |
10 #include "skia/ext/vector_canvas.h" | 10 #include "skia/ext/vector_canvas.h" |
11 #include "webkit/api/public/WebFrame.h" | 11 #include "webkit/api/public/WebFrame.h" |
12 | 12 |
13 using WebKit::WebFrame; | 13 using WebKit::WebFrame; |
14 | 14 |
15 void PrintWebViewHelper::Print(WebFrame* frame, bool script_initiated) { | 15 void PrintWebViewHelper::Print(WebFrame* frame, bool script_initiated) { |
16 // If still not finished with earlier print request simply ignore. | 16 // If still not finished with earlier print request simply ignore. |
17 if (IsPrinting()) | 17 if (IsPrinting()) |
18 return; | 18 return; |
19 | 19 |
20 // TODO(myhuang): Get printing parameters via IPC. | 20 // TODO(myhuang): Get printing parameters via IPC. |
21 // For testing purpose, we hard-coded printing parameters here. | 21 // For testing purpose, we hard-coded printing parameters here. |
22 | 22 |
23 // The paper size is US Letter (8.5 in. by 11 in.). | 23 // The paper size is US Letter (8.5 in. by 11 in.). |
24 // Using default margins: | 24 // Using default margins: |
25 // Left = 0.25 in. | 25 // Left = 0.25 in. |
26 // Right = 0.25 in. | 26 // Right = 0.25 in. |
27 // Top = 0.25 in. | 27 // Top = 0.25 in. |
28 // Bottom = 0.56 in. | 28 // Bottom = 0.56 in. |
29 const int kDPI = 72; | 29 const int kDPI = 72; |
30 const int kWidth = (8.5-0.25-0.25) * kDPI; | 30 const int kWidth = static_cast<int>((8.5-0.25-0.25) * kDPI); |
31 const int kHeight = (11-0.25-0.56) * kDPI; | 31 const int kHeight = static_cast<int>((11-0.25-0.56) * kDPI); |
32 ViewMsg_Print_Params default_settings; | 32 ViewMsg_Print_Params default_settings; |
33 default_settings.printable_size = gfx::Size(kWidth, kHeight); | 33 default_settings.printable_size = gfx::Size(kWidth, kHeight); |
34 default_settings.dpi = kDPI; | 34 default_settings.dpi = kDPI; |
35 default_settings.min_shrink = 1.25; | 35 default_settings.min_shrink = 1.25; |
36 default_settings.max_shrink = 2.0; | 36 default_settings.max_shrink = 2.0; |
37 default_settings.desired_dpi = kDPI; | 37 default_settings.desired_dpi = kDPI; |
38 default_settings.document_cookie = NULL; | 38 default_settings.document_cookie = 0; |
39 default_settings.selection_only = false; | 39 default_settings.selection_only = false; |
40 | 40 |
41 ViewMsg_PrintPages_Params print_settings; | 41 ViewMsg_PrintPages_Params print_settings; |
42 print_settings.params = default_settings; | 42 print_settings.params = default_settings; |
43 | 43 |
44 PrintPages(print_settings, frame); | 44 PrintPages(print_settings, frame); |
45 } | 45 } |
46 | 46 |
47 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, | 47 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, |
48 WebFrame* frame) { | 48 WebFrame* frame) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 // TODO(myhuang): We should handle transformation for paper margins. | 147 // TODO(myhuang): We should handle transformation for paper margins. |
148 // TODO(myhuang): We should render the header and the footer. | 148 // TODO(myhuang): We should render the header and the footer. |
149 | 149 |
150 // Done printing. Close the device context to retrieve the compiled metafile. | 150 // Done printing. Close the device context to retrieve the compiled metafile. |
151 if (!metafile->FinishPage(shrink)) { | 151 if (!metafile->FinishPage(shrink)) { |
152 NOTREACHED() << "metafile failed"; | 152 NOTREACHED() << "metafile failed"; |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
OLD | NEW |