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> | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
14 #include "base/time.h" | 13 #include "base/time.h" |
15 #include "content/renderer/render_view_observer.h" | 14 #include "content/renderer/render_view_observer.h" |
16 #include "content/renderer/render_view_observer_tracker.h" | 15 #include "content/renderer/render_view_observer_tracker.h" |
17 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void OnPrintForSystemDialog(); | 127 void OnPrintForSystemDialog(); |
129 | 128 |
130 // Initiate print preview. | 129 // Initiate print preview. |
131 void OnInitiatePrintPreview(); | 130 void OnInitiatePrintPreview(); |
132 | 131 |
133 // Start the process of generating a print preview using |settings|. | 132 // Start the process of generating a print preview using |settings|. |
134 void OnPrintPreview(const base::DictionaryValue& settings); | 133 void OnPrintPreview(const base::DictionaryValue& settings); |
135 // Initialize the print preview document. | 134 // Initialize the print preview document. |
136 bool CreatePreviewDocument(); | 135 bool CreatePreviewDocument(); |
137 | 136 |
138 // Continue generating the print preview. |requested_preview_page_index| | 137 // Continue generating the print preview. |
139 // specifies the browser requested preview page index. It is 1-based or | 138 void OnContinuePreview(); |
140 // |printing::INVALID_PAGE_INDEX| to continue with next page. | |
141 void OnContinuePreview(int requested_preview_page_index); | |
142 // Renders a print preview page. |page_number| is 0-based. | 139 // Renders a print preview page. |page_number| is 0-based. |
143 void RenderPreviewPage(int page_number); | 140 void RenderPreviewPage(int page_number); |
144 // Finalize the print preview document. | 141 // Finalize the print preview document. |
145 bool FinalizePreviewDocument(); | 142 bool FinalizePreviewDocument(); |
146 | 143 |
147 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' | 144 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' |
148 // state. | 145 // state. |
149 void OnAbortPreview(); | 146 void OnAbortPreview(); |
150 | 147 |
151 // Print / preview the node under the context menu. | 148 // Print / preview the node under the context menu. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 282 |
286 // Notify the browser a print preview page has been rendered. | 283 // Notify the browser a print preview page has been rendered. |
287 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 284 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check |
288 // for pending preview requests. | 285 // for pending preview requests. |
289 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 286 void PreviewPageRendered(int page_number, printing::Metafile* metafile); |
290 | 287 |
291 WebKit::WebView* print_web_view_; | 288 WebKit::WebView* print_web_view_; |
292 | 289 |
293 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 290 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
294 bool is_preview_; | 291 bool is_preview_; |
| 292 bool is_complete_metafile_sent_; |
295 | 293 |
296 // Used for scripted initiated printing blocking. | 294 // Used for scripted initiated printing blocking. |
297 base::Time last_cancelled_script_print_; | 295 base::Time last_cancelled_script_print_; |
298 int user_cancelled_scripted_print_count_; | 296 int user_cancelled_scripted_print_count_; |
299 | 297 |
300 // Let the browser process know of a printing failure. Only set to false when | 298 // Let the browser process know of a printing failure. Only set to false when |
301 // the failure came from the browser in the first place. | 299 // the failure came from the browser in the first place. |
302 bool notify_browser_of_print_failure_; | 300 bool notify_browser_of_print_failure_; |
303 | 301 |
304 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 302 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
(...skipping 13 matching lines...) Expand all Loading... |
318 void OnPrintPreview(); | 316 void OnPrintPreview(); |
319 | 317 |
320 // Create the print preview document. |pages| is empty to print all pages. | 318 // Create the print preview document. |pages| is empty to print all pages. |
321 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 319 bool CreatePreviewDocument(PrintMsg_Print_Params* params, |
322 const std::vector<int>& pages); | 320 const std::vector<int>& pages); |
323 | 321 |
324 // Called after a page gets rendered. |page_time| is how long the | 322 // Called after a page gets rendered. |page_time| is how long the |
325 // rendering took. | 323 // rendering took. |
326 void RenderedPreviewPage(const base::TimeDelta& page_time); | 324 void RenderedPreviewPage(const base::TimeDelta& page_time); |
327 | 325 |
| 326 // Updates the print preview context when the required pages are rendered. |
| 327 void PreviewPagesRendered(); |
| 328 |
328 // Finalizes the print preview document. | 329 // Finalizes the print preview document. |
329 void FinalizePreviewDocument(); | 330 void FinalizePreviewDocument(); |
330 | 331 |
331 // Cleanup after print preview finishes. | 332 // Cleanup after print preview finishes. |
332 void Finished(); | 333 void Finished(); |
333 | 334 |
334 // Cleanup after print preview fails. | 335 // Cleanup after print preview fails. |
335 void Failed(); | 336 void Failed(); |
336 | 337 |
337 // Abort the print preview. | 338 // Abort the print preview. |
338 void Abort(); | 339 void Abort(); |
339 | 340 |
340 // Helper functions | 341 // Helper functions |
341 int GetNextPageNumber(); | 342 int GetNextPageNumber(); |
342 bool IsReadyToRender() const; | 343 bool IsReadyToRender() const; |
343 bool IsBusy() const; | 344 bool IsBusy() const; |
344 bool IsModifiable() const; | 345 bool IsModifiable() const; |
| 346 bool IsLastPageOfCompleteMetafile() const; |
| 347 bool IsFinalPageRendered() const; |
| 348 |
| 349 // Setters |
| 350 void set_generate_draft_pages(bool generate_draft_pages); |
345 | 351 |
346 // Getters | 352 // Getters |
347 WebKit::WebFrame* frame() const; | 353 WebKit::WebFrame* frame() const; |
348 WebKit::WebNode* node() const; | 354 WebKit::WebNode* node() const; |
349 int total_page_count() const; | 355 int total_page_count() const; |
| 356 bool generate_draft_pages(); |
350 printing::Metafile* metafile() const; | 357 printing::Metafile* metafile() const; |
351 const PrintMsg_Print_Params& print_params() const; | 358 const PrintMsg_Print_Params& print_params() const; |
352 const gfx::Size& GetPrintCanvasSize() const; | 359 const gfx::Size& GetPrintCanvasSize() const; |
353 | 360 |
354 private: | 361 private: |
355 enum State { | 362 enum State { |
356 UNINITIALIZED, // Not ready to render. | 363 UNINITIALIZED, // Not ready to render. |
357 INITIALIZED, // Ready to render. | 364 INITIALIZED, // Ready to render. |
358 RENDERING, // Rendering. | 365 RENDERING, // Rendering. |
359 DONE // Finished rendering. | 366 DONE // Finished rendering. |
360 }; | 367 }; |
361 | 368 |
362 // Reset some of the internal rendering context. | 369 // Reset some of the internal rendering context. |
363 void ClearContext(); | 370 void ClearContext(); |
364 | 371 |
365 // Specifies what to render for print preview. | 372 // Specifies what to render for print preview. |
366 WebKit::WebFrame* frame_; | 373 WebKit::WebFrame* frame_; |
367 scoped_ptr<WebKit::WebNode> node_; | 374 scoped_ptr<WebKit::WebNode> node_; |
368 | 375 |
369 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 376 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
370 scoped_ptr<printing::Metafile> metafile_; | 377 scoped_ptr<printing::Metafile> metafile_; |
371 scoped_ptr<PrintMsg_Print_Params> print_params_; | 378 scoped_ptr<PrintMsg_Print_Params> print_params_; |
372 | 379 |
373 // Total page count in the renderer. | 380 // Total page count in the renderer. |
374 int total_page_count_; | 381 int total_page_count_; |
375 | 382 |
376 // Number of pages to render. | 383 // List of page indices that need to be rendered. |
377 int actual_page_count_; | 384 std::vector<int> render_page_list_; |
378 | 385 |
379 // The current page to render. | 386 // Specifies the current list index. |
380 int current_page_number_; | 387 int render_page_list_index_; |
381 | 388 |
382 // |rendered_pages_| tracks which pages need to be printed as well as | 389 // True, when draft pages needs to be generated. |
383 // the page slot it should be printed in. See GetPageSlotForPage. | 390 bool generate_draft_pages_; |
384 typedef std::pair<bool, int> PreviewPageInfo; | 391 |
385 std::vector<PreviewPageInfo> rendered_pages_; | 392 // Specifies the total number of pages in the complete metafile. |
| 393 int complete_metafile_page_count_; |
386 | 394 |
387 base::TimeDelta document_render_time_; | 395 base::TimeDelta document_render_time_; |
388 base::TimeTicks begin_time_; | 396 base::TimeTicks begin_time_; |
389 | 397 |
390 State state_; | 398 State state_; |
391 }; | 399 }; |
392 | 400 |
393 PrintPreviewContext print_preview_context_; | 401 PrintPreviewContext print_preview_context_; |
394 | 402 |
395 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 403 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
396 }; | 404 }; |
397 | 405 |
398 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 406 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |