| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 void OnPrintForSystemDialog(); | 134 void OnPrintForSystemDialog(); |
| 135 | 135 |
| 136 // Initiate print preview. | 136 // Initiate print preview. |
| 137 void OnInitiatePrintPreview(); | 137 void OnInitiatePrintPreview(); |
| 138 | 138 |
| 139 // Start the process of generating a print preview using |settings|. | 139 // Start the process of generating a print preview using |settings|. |
| 140 void OnPrintPreview(const base::DictionaryValue& settings); | 140 void OnPrintPreview(const base::DictionaryValue& settings); |
| 141 // Initialize the print preview document. | 141 // Initialize the print preview document. |
| 142 bool CreatePreviewDocument(); | 142 bool CreatePreviewDocument(); |
| 143 | 143 |
| 144 // Continue generating the print preview. |requested_preview_page_index| | |
| 145 // specifies the browser requested preview page index. It is 1-based or | |
| 146 // |printing::INVALID_PAGE_INDEX| to continue with next page. | |
| 147 void OnContinuePreview(int requested_preview_page_index); | |
| 148 // Renders a print preview page. |page_number| is 0-based. | 144 // Renders a print preview page. |page_number| is 0-based. |
| 149 void RenderPreviewPage(int page_number); | 145 // Returns true if print preview should continue, false on failure. |
| 146 bool RenderPreviewPage(int page_number); |
| 147 |
| 150 // Finalize the print preview document. | 148 // Finalize the print preview document. |
| 151 bool FinalizePreviewDocument(); | 149 bool FinalizePreviewDocument(); |
| 152 | 150 |
| 153 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' | |
| 154 // state. | |
| 155 void OnAbortPreview(); | |
| 156 | |
| 157 // Print / preview the node under the context menu. | 151 // Print / preview the node under the context menu. |
| 158 void OnPrintNodeUnderContextMenu(); | 152 void OnPrintNodeUnderContextMenu(); |
| 159 | 153 |
| 160 // Print the pages for print preview. Do not display the native print dialog | 154 // Print the pages for print preview. Do not display the native print dialog |
| 161 // for user settings. |job_settings| has new print job settings values. | 155 // for user settings. |job_settings| has new print job settings values. |
| 162 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); | 156 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); |
| 163 | 157 |
| 164 void OnPrintingDone(bool success); | 158 void OnPrintingDone(bool success); |
| 165 | 159 |
| 166 // Main printing code ------------------------------------------------------- | 160 // Main printing code ------------------------------------------------------- |
| 167 | 161 |
| 168 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node); | 162 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 169 | 163 |
| 170 enum PrintingResult { | 164 enum PrintingResult { |
| 171 OK, | 165 OK, |
| 172 FAIL_PRINT, | 166 FAIL_PRINT, |
| 173 FAIL_PREVIEW, | 167 FAIL_PREVIEW, |
| 174 ABORT_PREVIEW, | |
| 175 }; | 168 }; |
| 176 | 169 |
| 177 // Notification when printing is done - signal tear-down/free resources. | 170 // Notification when printing is done - signal tear-down/free resources. |
| 178 void DidFinishPrinting(PrintingResult result); | 171 void DidFinishPrinting(PrintingResult result); |
| 179 | 172 |
| 180 // Print Settings ----------------------------------------------------------- | 173 // Print Settings ----------------------------------------------------------- |
| 181 | 174 |
| 182 // Initialize print page settings with default settings. | 175 // Initialize print page settings with default settings. |
| 183 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); | 176 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 184 | 177 |
| 185 // Initialize print page settings with default settings and prepare the frame | 178 // Initialize print page settings with default settings and prepare the frame |
| 186 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the | 179 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the |
| 187 // request and is filled into the |prepare| argument. | 180 // request and is filled into the |prepare| argument. |
| 188 bool InitPrintSettingsAndPrepareFrame( | 181 bool InitPrintSettingsAndPrepareFrame( |
| 189 WebKit::WebFrame* frame, | 182 WebKit::WebFrame* frame, |
| 190 WebKit::WebNode* node, | 183 WebKit::WebNode* node, |
| 191 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); | 184 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); |
| 192 | 185 |
| 193 // Parse the request id out of |job_settings| and store it in |params|. | |
| 194 // Returns false on failure. | |
| 195 bool UpdatePrintSettingsRequestId(const base::DictionaryValue& job_settings, | |
| 196 PrintMsg_Print_Params* params); | |
| 197 | |
| 198 // Update the current print settings with new |job_settings|. |job_settings| | 186 // Update the current print settings with new |job_settings|. |job_settings| |
| 199 // dictionary contains print job details such as printer name, number of | 187 // dictionary contains print job details such as printer name, number of |
| 200 // copies, page range, etc. | 188 // copies, page range, etc. |
| 201 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); | 189 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); |
| 202 | 190 |
| 203 // Get final print settings from the user. | 191 // Get final print settings from the user. |
| 204 // Return false if the user cancels or on error. | 192 // Return false if the user cancels or on error. |
| 205 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 193 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 206 int expected_pages_count, | 194 int expected_pages_count, |
| 207 bool use_browser_overlays); | 195 bool use_browser_overlays); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 288 |
| 301 // Increment the counter for script initiated printing. | 289 // Increment the counter for script initiated printing. |
| 302 // Scripted printing will be blocked for a limited amount of time. | 290 // Scripted printing will be blocked for a limited amount of time. |
| 303 void IncrementScriptedPrintCount(); | 291 void IncrementScriptedPrintCount(); |
| 304 | 292 |
| 305 // Displays the print job error message to the user. | 293 // Displays the print job error message to the user. |
| 306 void DisplayPrintJobError(); | 294 void DisplayPrintJobError(); |
| 307 | 295 |
| 308 void RequestPrintPreview(); | 296 void RequestPrintPreview(); |
| 309 | 297 |
| 310 // Notify the browser a print preview page has been rendered. | 298 // Checks whether print preview should continue or not. |
| 311 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 299 // Returns true if cancelling, false if continuing. |
| 312 // for pending preview requests. | 300 bool CheckForCancel(); |
| 313 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 301 |
| 302 // Notifies the browser a print preview page has been rendered. |
| 303 // |page_number| is 0-based. |
| 304 // For a valid |page_number| with modifiable content, |
| 305 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
| 306 // Returns true if print preview should continue, false on failure. |
| 307 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); |
| 314 | 308 |
| 315 WebKit::WebView* print_web_view_; | 309 WebKit::WebView* print_web_view_; |
| 316 | 310 |
| 317 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 311 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
| 318 bool is_preview_; | 312 bool is_preview_; |
| 319 | 313 |
| 320 // Used for scripted initiated printing blocking. | 314 // Used for scripted initiated printing blocking. |
| 321 base::Time last_cancelled_script_print_; | 315 base::Time last_cancelled_script_print_; |
| 322 int user_cancelled_scripted_print_count_; | 316 int user_cancelled_scripted_print_count_; |
| 323 | 317 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 349 |
| 356 // Finalizes the print preview document. | 350 // Finalizes the print preview document. |
| 357 void FinalizePreviewDocument(); | 351 void FinalizePreviewDocument(); |
| 358 | 352 |
| 359 // Cleanup after print preview finishes. | 353 // Cleanup after print preview finishes. |
| 360 void Finished(); | 354 void Finished(); |
| 361 | 355 |
| 362 // Cleanup after print preview fails. | 356 // Cleanup after print preview fails. |
| 363 void Failed(); | 357 void Failed(); |
| 364 | 358 |
| 365 // Abort the print preview. | |
| 366 void Abort(); | |
| 367 | |
| 368 // Helper functions | 359 // Helper functions |
| 369 int GetNextPageNumber(); | 360 int GetNextPageNumber(); |
| 370 bool IsReadyToRender() const; | 361 bool IsReadyToRender() const; |
| 371 bool IsBusy() const; | |
| 372 bool IsModifiable() const; | 362 bool IsModifiable() const; |
| 373 | 363 |
| 374 // Getters | 364 // Getters |
| 375 WebKit::WebFrame* frame() const; | 365 WebKit::WebFrame* frame() const; |
| 376 WebKit::WebNode* node() const; | 366 WebKit::WebNode* node() const; |
| 377 int total_page_count() const; | 367 int total_page_count() const; |
| 378 printing::PreviewMetafile* metafile() const; | 368 printing::PreviewMetafile* metafile() const; |
| 379 const PrintMsg_Print_Params& print_params() const; | 369 const PrintMsg_Print_Params& print_params() const; |
| 380 const gfx::Size& GetPrintCanvasSize() const; | 370 const gfx::Size& GetPrintCanvasSize() const; |
| 381 | 371 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 398 scoped_ptr<printing::PreviewMetafile> metafile_; | 388 scoped_ptr<printing::PreviewMetafile> metafile_; |
| 399 scoped_ptr<PrintMsg_Print_Params> print_params_; | 389 scoped_ptr<PrintMsg_Print_Params> print_params_; |
| 400 | 390 |
| 401 // Total page count in the renderer. | 391 // Total page count in the renderer. |
| 402 int total_page_count_; | 392 int total_page_count_; |
| 403 | 393 |
| 404 // Number of pages to render. | 394 // Number of pages to render. |
| 405 int actual_page_count_; | 395 int actual_page_count_; |
| 406 | 396 |
| 407 // The current page to render. | 397 // The current page to render. |
| 408 int current_page_number_; | 398 int current_page_index_; |
| 409 | 399 |
| 410 // |rendered_pages_| tracks which pages need to be printed as well as | 400 std::vector<int> pages_to_render_; |
| 411 // the page slot it should be printed in. See GetPageSlotForPage. | |
| 412 typedef std::pair<bool, int> PreviewPageInfo; | |
| 413 std::vector<PreviewPageInfo> rendered_pages_; | |
| 414 | 401 |
| 415 base::TimeDelta document_render_time_; | 402 base::TimeDelta document_render_time_; |
| 416 base::TimeTicks begin_time_; | 403 base::TimeTicks begin_time_; |
| 417 | 404 |
| 418 State state_; | 405 State state_; |
| 419 }; | 406 }; |
| 420 | 407 |
| 421 PrintPreviewContext print_preview_context_; | 408 PrintPreviewContext print_preview_context_; |
| 422 | 409 |
| 423 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 410 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 424 }; | 411 }; |
| 425 | 412 |
| 426 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 413 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |