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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 283 |
287 // Notify the browser a print preview page has been rendered. | 284 // Notify the browser a print preview page has been rendered. |
288 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 285 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check |
289 // for pending preview requests. | 286 // for pending preview requests. |
290 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 287 void PreviewPageRendered(int page_number, printing::Metafile* metafile); |
291 | 288 |
292 WebKit::WebView* print_web_view_; | 289 WebKit::WebView* print_web_view_; |
293 | 290 |
294 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 291 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
295 bool is_preview_; | 292 bool is_preview_; |
| 293 bool is_complete_metafile_already_sent_; |
296 | 294 |
297 // Used for scripted initiated printing blocking. | 295 // Used for scripted initiated printing blocking. |
298 base::Time last_cancelled_script_print_; | 296 base::Time last_cancelled_script_print_; |
299 int user_cancelled_scripted_print_count_; | 297 int user_cancelled_scripted_print_count_; |
300 | 298 |
301 // Let the browser process know of a printing failure. Only set to false when | 299 // Let the browser process know of a printing failure. Only set to false when |
302 // the failure came from the browser in the first place. | 300 // the failure came from the browser in the first place. |
303 bool notify_browser_of_print_failure_; | 301 bool notify_browser_of_print_failure_; |
304 | 302 |
305 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 303 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
(...skipping 14 matching lines...) Expand all Loading... |
320 | 318 |
321 // Create the print preview document. |pages| is empty to print all pages. | 319 // Create the print preview document. |pages| is empty to print all pages. |
322 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 320 bool CreatePreviewDocument(PrintMsg_Print_Params* params, |
323 const std::vector<int>& pages); | 321 const std::vector<int>& pages); |
324 | 322 |
325 // Called after a page gets rendered. |page_time| is how long the | 323 // Called after a page gets rendered. |page_time| is how long the |
326 // rendering took. | 324 // rendering took. |
327 void RenderedPreviewPage(const base::TimeDelta& page_time); | 325 void RenderedPreviewPage(const base::TimeDelta& page_time); |
328 | 326 |
329 // Finalizes the print preview document. | 327 // Finalizes the print preview document. |
330 void FinalizePreviewDocument(); | 328 void FinalizePreviewDocument(bool is_complete_metafile_already_sent); |
331 | 329 |
332 // Cleanup after print preview finishes. | 330 // Cleanup after print preview finishes. |
333 void Finished(); | 331 void Finished(); |
334 | 332 |
335 // Abort the print preview. | 333 // Abort the print preview. |
336 void Abort(); | 334 void Abort(); |
337 | 335 |
338 // Helper functions | 336 // Helper functions |
339 int GetNextPageNumber(); | 337 int GetNextPageNumber(); |
340 bool IsReadyToRender() const; | 338 bool IsReadyToRender() const; |
341 bool IsBusy() const; | 339 bool IsBusy() const; |
342 bool IsModifiable() const; | 340 bool IsModifiable() const; |
| 341 bool IsCompleteMetafileReady() const; |
| 342 |
| 343 void set_generate_draft_pages(bool generate_draft_pages) { |
| 344 generate_draft_pages_ = generate_draft_pages; |
| 345 } |
| 346 bool get_generate_draft_pages() { |
| 347 return generate_draft_pages_; |
| 348 } |
343 | 349 |
344 // Return the page slot in the final document for |page_number|. i.e. if | 350 // Return the page slot in the final document for |page_number|. i.e. if |
345 // the user selected just page 3, the page slot would be 0, since it is | 351 // the user selected just page 3, the page slot would be 0, since it is |
346 // the first page in the resulting document. | 352 // the first page in the resulting document. |
347 int GetPageSlotForPage(int page_number) const; | 353 int GetPageSlotForPage(int page_number) const; |
348 | 354 |
349 // Getters | 355 // Getters |
350 WebKit::WebFrame* frame() const; | 356 WebKit::WebFrame* frame() const; |
351 WebKit::WebNode* node() const; | 357 WebKit::WebNode* node() const; |
352 int total_page_count() const; | 358 int total_page_count() const; |
(...skipping 16 matching lines...) Expand all Loading... |
369 WebKit::WebFrame* frame_; | 375 WebKit::WebFrame* frame_; |
370 scoped_ptr<WebKit::WebNode> node_; | 376 scoped_ptr<WebKit::WebNode> node_; |
371 | 377 |
372 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 378 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
373 scoped_ptr<printing::Metafile> metafile_; | 379 scoped_ptr<printing::Metafile> metafile_; |
374 scoped_ptr<PrintMsg_Print_Params> print_params_; | 380 scoped_ptr<PrintMsg_Print_Params> print_params_; |
375 | 381 |
376 // Total page count in the renderer. | 382 // Total page count in the renderer. |
377 int total_page_count_; | 383 int total_page_count_; |
378 | 384 |
379 // Number of pages to render. | 385 // Requested preview page index list. |
380 int actual_page_count_; | 386 std::vector<int> render_page_index_list_; |
381 | 387 |
382 // The current page to render. | 388 // True, when draft pages needs to be generated. |
383 int current_page_number_; | 389 bool generate_draft_pages_; |
384 | 390 |
385 // |rendered_pages_| tracks which pages need to be printed as well as | 391 // Specifies the total number of pages in complete metafile. |
386 // the page slot it should be printed in. See GetPageSlotForPage. | 392 int complete_metafile_page_count_; |
387 typedef std::pair<bool, int> PreviewPageInfo; | 393 |
388 std::vector<PreviewPageInfo> rendered_pages_; | 394 // Specifies the current preview page index. |
| 395 int current_page_index_; |
389 | 396 |
390 base::TimeDelta document_render_time_; | 397 base::TimeDelta document_render_time_; |
391 base::TimeTicks begin_time_; | 398 base::TimeTicks begin_time_; |
392 | 399 |
393 State state_; | 400 State state_; |
394 }; | 401 }; |
395 | 402 |
396 PrintPreviewContext print_preview_context_; | 403 PrintPreviewContext print_preview_context_; |
397 | 404 |
398 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 405 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
399 }; | 406 }; |
400 | 407 |
401 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 408 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |