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_already_sent_; | |
vandebo (ex-Chrome)
2011/08/04 21:45:02
nit (if you like): already isn't really necessary.
kmadhusu
2011/08/05 22:55:22
Done.
| |
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 // Abort the print preview. | 335 // Abort the print preview. |
335 void Abort(); | 336 void Abort(); |
336 | 337 |
337 // Helper functions | 338 // Helper functions |
338 int GetNextPageNumber(); | 339 int GetNextPageNumber(); |
339 bool IsReadyToRender() const; | 340 bool IsReadyToRender() const; |
340 bool IsBusy() const; | 341 bool IsBusy() const; |
341 bool IsModifiable() const; | 342 bool IsModifiable() const; |
343 bool IsLastPageOfCompleteMetafile() const; | |
344 | |
345 // Setters | |
346 void set_generate_draft_pages(bool generate_draft_pages); | |
342 | 347 |
343 // Getters | 348 // Getters |
344 WebKit::WebFrame* frame() const; | 349 WebKit::WebFrame* frame() const; |
345 WebKit::WebNode* node() const; | 350 WebKit::WebNode* node() const; |
346 int total_page_count() const; | 351 int total_page_count() const; |
352 bool generate_draft_pages(); | |
347 printing::Metafile* metafile() const; | 353 printing::Metafile* metafile() const; |
348 const PrintMsg_Print_Params& print_params() const; | 354 const PrintMsg_Print_Params& print_params() const; |
349 const gfx::Size& GetPrintCanvasSize() const; | 355 const gfx::Size& GetPrintCanvasSize() const; |
350 | 356 |
351 private: | 357 private: |
352 enum State { | 358 enum State { |
353 UNINITIALIZED, // Not ready to render. | 359 UNINITIALIZED, // Not ready to render. |
354 INITIALIZED, // Ready to render. | 360 INITIALIZED, // Ready to render. |
355 RENDERING, // Rendering. | 361 RENDERING, // Rendering. |
356 DONE // Finished rendering. | 362 DONE // Finished rendering. |
357 }; | 363 }; |
358 | 364 |
359 // Reset some of the internal rendering context. | 365 // Reset some of the internal rendering context. |
360 void ClearContext(); | 366 void ClearContext(); |
361 | 367 |
362 // Specifies what to render for print preview. | 368 // Specifies what to render for print preview. |
363 WebKit::WebFrame* frame_; | 369 WebKit::WebFrame* frame_; |
364 scoped_ptr<WebKit::WebNode> node_; | 370 scoped_ptr<WebKit::WebNode> node_; |
365 | 371 |
366 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 372 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
367 scoped_ptr<printing::Metafile> metafile_; | 373 scoped_ptr<printing::Metafile> metafile_; |
368 scoped_ptr<PrintMsg_Print_Params> print_params_; | 374 scoped_ptr<PrintMsg_Print_Params> print_params_; |
369 | 375 |
370 // Total page count in the renderer. | 376 // Total page count in the renderer. |
371 int total_page_count_; | 377 int total_page_count_; |
372 | 378 |
373 // Number of pages to render. | 379 // List of page indices that needs to be rendered. |
vandebo (ex-Chrome)
2011/08/04 21:45:02
nit: needs -> need
kmadhusu
2011/08/05 22:55:22
Done.
| |
374 int actual_page_count_; | 380 std::vector<int> render_page_list_; |
375 | 381 |
376 // The current page to render. | 382 // Specifies the current list index. |
377 int current_page_number_; | 383 int render_page_list_index_; |
378 | 384 |
379 // |rendered_pages_| tracks which pages need to be printed as well as | 385 // True, when draft pages needs to be generated. |
380 // the page slot it should be printed in. See GetPageSlotForPage. | 386 bool generate_draft_pages_; |
381 typedef std::pair<bool, int> PreviewPageInfo; | 387 |
382 std::vector<PreviewPageInfo> rendered_pages_; | 388 // Specifies the total number of pages in complete metafile. |
vandebo (ex-Chrome)
2011/08/04 21:45:02
nit: in the complete
kmadhusu
2011/08/05 22:55:22
Done.
| |
389 int complete_metafile_page_count_; | |
383 | 390 |
384 base::TimeDelta document_render_time_; | 391 base::TimeDelta document_render_time_; |
385 base::TimeTicks begin_time_; | 392 base::TimeTicks begin_time_; |
386 | 393 |
387 State state_; | 394 State state_; |
388 }; | 395 }; |
389 | 396 |
390 PrintPreviewContext print_preview_context_; | 397 PrintPreviewContext print_preview_context_; |
391 | 398 |
392 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 399 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
393 }; | 400 }; |
394 | 401 |
395 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 402 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |