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 #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 "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 explicit PrintWebViewHelper(RenderView* render_view); | 80 explicit PrintWebViewHelper(RenderView* render_view); |
81 virtual ~PrintWebViewHelper(); | 81 virtual ~PrintWebViewHelper(); |
82 | 82 |
83 // Prints |frame|. | 83 // Prints |frame|. |
84 void PrintFrame(WebKit::WebFrame* frame, | 84 void PrintFrame(WebKit::WebFrame* frame, |
85 bool script_initiated, | 85 bool script_initiated, |
86 bool is_preview); | 86 bool is_preview); |
87 | 87 |
88 // Message handlers. Public for testing. | 88 // Message handlers. Public for testing. |
89 void OnPrintingDone(int document_cookie, bool success); | 89 void OnPrintingDone(int document_cookie, bool success); |
90 void OnPrintForPrintPreview(); | 90 void OnPrintForPrintPreview(const std::string& job_settings); |
91 void OnPrintPages(); | 91 void OnPrintPages(); |
92 void OnPrintPreview(); | 92 void OnPrintPreview(); |
93 void OnPrintNodeUnderContextMenu(); | 93 void OnPrintNodeUnderContextMenu(); |
94 | 94 |
95 protected: | 95 protected: |
96 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 96 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
97 | 97 |
98 // Prints the page listed in |params|. | 98 // Prints the page listed in |params|. |
99 #if defined(USE_X11) | 99 #if defined(USE_X11) |
100 void PrintPage(const ViewMsg_PrintPage_Params& params, | 100 void PrintPage(const ViewMsg_PrintPage_Params& params, |
(...skipping 10 matching lines...) Expand all Loading... |
111 // Prints all the pages listed in |params|. | 111 // Prints all the pages listed in |params|. |
112 // It will implicitly revert the document to display CSS media type. | 112 // It will implicitly revert the document to display CSS media type. |
113 void PrintPages(const ViewMsg_PrintPages_Params& params, | 113 void PrintPages(const ViewMsg_PrintPages_Params& params, |
114 WebKit::WebFrame* frame, | 114 WebKit::WebFrame* frame, |
115 WebKit::WebNode* node); | 115 WebKit::WebNode* node); |
116 | 116 |
117 // WebKit::WebViewClient override: | 117 // WebKit::WebViewClient override: |
118 virtual void didStopLoading(); | 118 virtual void didStopLoading(); |
119 | 119 |
120 private: | 120 private: |
| 121 enum GetSettingsParam { |
| 122 DEFAULT, |
| 123 CURRENT, |
| 124 }; |
| 125 |
121 static void GetPageSizeAndMarginsInPoints( | 126 static void GetPageSizeAndMarginsInPoints( |
122 WebKit::WebFrame* frame, | 127 WebKit::WebFrame* frame, |
123 int page_index, | 128 int page_index, |
124 const ViewMsg_Print_Params& default_params, | 129 const ViewMsg_Print_Params& default_params, |
125 double* content_width_in_points, | 130 double* content_width_in_points, |
126 double* content_height_in_points, | 131 double* content_height_in_points, |
127 double* margin_top_in_points, | 132 double* margin_top_in_points, |
128 double* margin_right_in_points, | 133 double* margin_right_in_points, |
129 double* margin_bottom_in_points, | 134 double* margin_bottom_in_points, |
130 double* margin_left_in_points); | 135 double* margin_left_in_points); |
131 | 136 |
132 // RenderViewObserver implementation. | 137 // RenderViewObserver implementation. |
133 virtual bool OnMessageReceived(const IPC::Message& message); | 138 virtual bool OnMessageReceived(const IPC::Message& message); |
134 | 139 |
135 // Common method for OnPrintPages() and OnPrintPreview(). | 140 // Common method for OnPrintPages() and OnPrintPreview(). |
136 void OnPrint(bool is_preview); | 141 void OnPrint(bool is_preview); |
137 | 142 |
138 void PrintNode(WebKit::WebNode* node, | 143 void PrintNode(WebKit::WebNode* node, |
139 bool script_initiated, | 144 bool script_initiated, |
140 bool is_preview); | 145 bool is_preview); |
141 | 146 |
142 // Notification when printing is done - signal teardown | 147 // Notification when printing is done - signal teardown |
143 void DidFinishPrinting(bool success); | 148 void DidFinishPrinting(bool success); |
144 | 149 |
| 150 // Print the pages for print preview. Do not display the native print dialog |
| 151 // for user settings. Use the current print settings set by the user in |
| 152 // preview tab. |
| 153 void PrintForPrintPreview(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 154 |
145 void Print(WebKit::WebFrame* frame, | 155 void Print(WebKit::WebFrame* frame, |
146 WebKit::WebNode* node, | 156 WebKit::WebNode* node, |
147 bool script_initiated, | 157 bool script_initiated, |
148 bool is_preview); | 158 bool is_preview); |
149 | 159 |
150 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, | 160 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, |
151 WebKit::WebNode* node, | 161 WebKit::WebNode* node, |
152 ViewMsg_Print_Params* params); | 162 ViewMsg_Print_Params* params); |
153 | 163 |
154 // Initialize print page settings with default settings. | 164 // Initialize print page settings with default settings. |
155 bool InitPrintSettings(WebKit::WebFrame* frame, | 165 bool InitPrintSettings(WebKit::WebFrame* frame, |
156 WebKit::WebNode* node); | 166 WebKit::WebNode* node, |
| 167 GetSettingsParam setting_type); |
157 | 168 |
158 // Get the default printer settings. | 169 // Update the current print settings with new |job_settings|. |job_settings| |
159 bool GetDefaultPrintSettings(WebKit::WebFrame* frame, | 170 // is a json string which contains print job details such as printer name, |
160 WebKit::WebNode* node, | 171 // number of copies, page range, etc. |
161 ViewMsg_Print_Params* params); | 172 bool UpdatePrintSettings(const std::string& job_settings); |
| 173 |
| 174 // Get the print settings. |setting_type| determines whether we need to get |
| 175 // current settings or default settings. |
| 176 bool GetPrintSettings(WebKit::WebFrame* frame, |
| 177 WebKit::WebNode* node, |
| 178 GetSettingsParam setting_type, |
| 179 ViewMsg_Print_Params* params); |
162 | 180 |
163 // Get final print settings from the user. | 181 // Get final print settings from the user. |
164 // Return false if the user cancels or on error. | 182 // Return false if the user cancels or on error. |
165 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 183 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
166 int expected_pages_count, | 184 int expected_pages_count, |
167 bool use_browser_overlays); | 185 bool use_browser_overlays); |
168 | 186 |
169 // Render the frame for printing. | 187 // Render the frame for printing. |
170 void RenderPagesForPrint(WebKit::WebFrame* frame, | 188 void RenderPagesForPrint(WebKit::WebFrame* frame, |
171 WebKit::WebNode* node); | 189 WebKit::WebNode* node); |
(...skipping 25 matching lines...) Expand all Loading... |
197 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; | 215 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; |
198 base::Time last_cancelled_script_print_; | 216 base::Time last_cancelled_script_print_; |
199 int user_cancelled_scripted_print_count_; | 217 int user_cancelled_scripted_print_count_; |
200 bool is_preview_; | 218 bool is_preview_; |
201 | 219 |
202 private: | 220 private: |
203 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 221 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
204 }; | 222 }; |
205 | 223 |
206 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 224 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |