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