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 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
15 #include "content/public/renderer/render_view_observer_tracker.h" | 15 #include "content/public/renderer/render_view_observer_tracker.h" |
16 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
17 #include "printing/metafile_impl.h" | 17 #include "printing/metafile_impl.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintScalingOption
.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
22 #include "ui/gfx/size.h" | 23 #include "ui/gfx/size.h" |
23 | 24 |
24 struct PrintMsg_Print_Params; | 25 struct PrintMsg_Print_Params; |
25 struct PrintMsg_PrintPage_Params; | 26 struct PrintMsg_PrintPage_Params; |
26 struct PrintMsg_PrintPages_Params; | 27 struct PrintMsg_PrintPages_Params; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class DictionaryValue; | 30 class DictionaryValue; |
30 } | 31 } |
(...skipping 24 matching lines...) Expand all Loading... |
55 return use_browser_overlays_; | 56 return use_browser_overlays_; |
56 } | 57 } |
57 | 58 |
58 const gfx::Size& GetPrintCanvasSize() const { | 59 const gfx::Size& GetPrintCanvasSize() const { |
59 return print_canvas_size_; | 60 return print_canvas_size_; |
60 } | 61 } |
61 | 62 |
62 void FinishPrinting(); | 63 void FinishPrinting(); |
63 | 64 |
64 private: | 65 private: |
65 void StartPrinting(const gfx::Size& print_params); | 66 void StartPrinting(const gfx::Size& canvas_size, |
| 67 const gfx::Rect& printable_area, |
| 68 const gfx::Size& paper_size); |
66 | 69 |
67 WebKit::WebFrame* frame_; | 70 WebKit::WebFrame* frame_; |
68 WebKit::WebNode node_to_print_; | 71 WebKit::WebNode node_to_print_; |
69 WebKit::WebView* web_view_; | 72 WebKit::WebView* web_view_; |
70 gfx::Size print_canvas_size_; | 73 gfx::Size print_canvas_size_; |
| 74 gfx::Rect printable_area_; |
| 75 gfx::Size paper_size_; |
71 gfx::Size prev_view_size_; | 76 gfx::Size prev_view_size_; |
72 gfx::Size prev_scroll_offset_; | 77 gfx::Size prev_scroll_offset_; |
73 int dpi_; | 78 int dpi_; |
74 int expected_pages_count_; | 79 int expected_pages_count_; |
75 bool use_browser_overlays_; | 80 bool use_browser_overlays_; |
| 81 WebKit::WebPrintScalingOption print_scaling_option_; |
76 bool finished_; | 82 bool finished_; |
77 | 83 |
78 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 84 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
79 }; | 85 }; |
80 | 86 |
81 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 87 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
82 // We plan on making print asynchronous and that will require copying the DOM | 88 // We plan on making print asynchronous and that will require copying the DOM |
83 // of the document and creating a new WebView with the contents. | 89 // of the document and creating a new WebView with the contents. |
84 class PrintWebViewHelper | 90 class PrintWebViewHelper |
85 : public content::RenderViewObserver, | 91 : public content::RenderViewObserver, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 const printing::PageSizeMargins& page_layout_in_points, | 159 const printing::PageSizeMargins& page_layout_in_points, |
154 gfx::Size* page_size, | 160 gfx::Size* page_size, |
155 gfx::Rect* content_area); | 161 gfx::Rect* content_area); |
156 | 162 |
157 // Update |ignore_css_margins_| based on settings. | 163 // Update |ignore_css_margins_| based on settings. |
158 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); | 164 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); |
159 | 165 |
160 // Returns true if the current destination printer is PRINT_TO_PDF. | 166 // Returns true if the current destination printer is PRINT_TO_PDF. |
161 bool IsPrintToPdfRequested(const base::DictionaryValue& settings); | 167 bool IsPrintToPdfRequested(const base::DictionaryValue& settings); |
162 | 168 |
| 169 // Returns the print scaling option to retain/scale/crop the source page size |
| 170 // to fit the printable area of the paper. |
| 171 // |
| 172 // We retain the source page size when the current destination printer is |
| 173 // SAVE_AS_PDF. |
| 174 // |
| 175 // We crop the source page size to fit the printable area or we print only the |
| 176 // left top page contents when |
| 177 // (1) Source is PDF and the user has requested not to fit to printable area |
| 178 // via |job_settings|. |
| 179 // (2) Source is PDF. This is the first preview request and print scaling |
| 180 // option is disabled for initiator renderer plugin. |
| 181 // |
| 182 // In all other cases, we scale the source page to fit the printable area. |
| 183 WebKit::WebPrintScalingOption GetPrintScalingOption( |
| 184 bool source_is_html, |
| 185 const base::DictionaryValue& settings, |
| 186 const PrintMsg_Print_Params& params); |
| 187 |
163 // Initiate print preview. | 188 // Initiate print preview. |
164 void OnInitiatePrintPreview(); | 189 void OnInitiatePrintPreview(); |
165 | 190 |
166 // Start the process of generating a print preview using |settings|. | 191 // Start the process of generating a print preview using |settings|. |
167 void OnPrintPreview(const base::DictionaryValue& settings); | 192 void OnPrintPreview(const base::DictionaryValue& settings); |
168 | 193 |
169 // Initialize the print preview document. | 194 // Initialize the print preview document. |
170 bool CreatePreviewDocument(); | 195 bool CreatePreviewDocument(); |
171 | 196 |
172 // Renders a print preview page. |page_number| is 0-based. | 197 // Renders a print preview page. |page_number| is 0-based. |
(...skipping 20 matching lines...) Expand all Loading... |
193 | 218 |
194 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); | 219 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); |
195 | 220 |
196 // Notification when printing is done - signal tear-down/free resources. | 221 // Notification when printing is done - signal tear-down/free resources. |
197 void DidFinishPrinting(PrintingResult result); | 222 void DidFinishPrinting(PrintingResult result); |
198 | 223 |
199 // Print Settings ----------------------------------------------------------- | 224 // Print Settings ----------------------------------------------------------- |
200 | 225 |
201 // Initialize print page settings with default settings. | 226 // Initialize print page settings with default settings. |
202 // Used only for native printing workflow. | 227 // Used only for native printing workflow. |
203 bool InitPrintSettings(); | 228 bool InitPrintSettings(bool fit_to_paper_size); |
204 | 229 |
205 // Initialize print page settings with default settings and prepare the frame | 230 // Initialize print page settings with default settings and prepare the frame |
206 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the | 231 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the |
207 // request and is filled into the |prepare| argument. | 232 // request and is filled into the |prepare| argument. |
208 // Used only for native printing workflow. | 233 // Used only for native printing workflow. |
209 bool InitPrintSettingsAndPrepareFrame( | 234 bool InitPrintSettingsAndPrepareFrame( |
210 WebKit::WebFrame* frame, | 235 WebKit::WebFrame* frame, |
211 const WebKit::WebNode& node, | 236 const WebKit::WebNode& node, |
212 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); | 237 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); |
213 | 238 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 enum PrintPreviewErrorBuckets error_; | 492 enum PrintPreviewErrorBuckets error_; |
468 | 493 |
469 State state_; | 494 State state_; |
470 }; | 495 }; |
471 | 496 |
472 PrintPreviewContext print_preview_context_; | 497 PrintPreviewContext print_preview_context_; |
473 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 498 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
474 }; | 499 }; |
475 | 500 |
476 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 501 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |