Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/renderer/print_web_view_helper.h

Issue 7647010: Print preview page selection should not require a rerendering of draft pages. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "printing/metafile_impl.h" 17 #include "printing/metafile_impl.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, 101 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest,
103 BlockScriptInitiatedPrinting); 102 BlockScriptInitiatedPrinting);
104 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); 103 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages);
105 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreview); 104 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreview);
106 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel); 105 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel);
107 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewFail); 106 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewFail);
108 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, 107 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
109 OnPrintForPrintPreview); 108 OnPrintForPrintPreview);
110 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, 109 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
111 OnPrintForPrintPreviewFail); 110 OnPrintForPrintPreviewFail);
111 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
112 OnPrintPreviewForSelectedPages);
112 113
113 #if defined(OS_WIN) || defined(OS_MACOSX) 114 #if defined(OS_WIN) || defined(OS_MACOSX)
114 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); 115 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest);
115 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); 116 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe);
116 #endif // defined(OS_WIN) || defined(OS_MACOSX) 117 #endif // defined(OS_WIN) || defined(OS_MACOSX)
117 118
118 // RenderViewObserver implementation. 119 // RenderViewObserver implementation.
119 virtual bool OnMessageReceived(const IPC::Message& message); 120 virtual bool OnMessageReceived(const IPC::Message& message);
120 virtual void PrintPage(WebKit::WebFrame* frame); 121 virtual void PrintPage(WebKit::WebFrame* frame);
121 122
(...skipping 10 matching lines...) Expand all
132 133
133 // Start the process of generating a print preview using |settings|. 134 // Start the process of generating a print preview using |settings|.
134 void OnPrintPreview(const base::DictionaryValue& settings); 135 void OnPrintPreview(const base::DictionaryValue& settings);
135 // Initialize the print preview document. 136 // Initialize the print preview document.
136 bool CreatePreviewDocument(); 137 bool CreatePreviewDocument();
137 138
138 // Renders a print preview page. |page_number| is 0-based. 139 // Renders a print preview page. |page_number| is 0-based.
139 // Returns true if print preview should continue, false on failure. 140 // Returns true if print preview should continue, false on failure.
140 bool RenderPreviewPage(int page_number); 141 bool RenderPreviewPage(int page_number);
141 142
142 // Finalize the print preview document. 143 // Finalize the print ready preview document.
143 bool FinalizePreviewDocument(); 144 bool FinalizePrintReadyDocument();
144 145
145 // Print / preview the node under the context menu. 146 // Print / preview the node under the context menu.
146 void OnPrintNodeUnderContextMenu(); 147 void OnPrintNodeUnderContextMenu();
147 148
148 // Print the pages for print preview. Do not display the native print dialog 149 // Print the pages for print preview. Do not display the native print dialog
149 // for user settings. |job_settings| has new print job settings values. 150 // for user settings. |job_settings| has new print job settings values.
150 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); 151 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings);
151 152
152 void OnPrintingDone(bool success); 153 void OnPrintingDone(bool success);
153 154
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // |page_number| is 0-based. 296 // |page_number| is 0-based.
296 // For a valid |page_number| with modifiable content, 297 // For a valid |page_number| with modifiable content,
297 // |metafile| is the rendered page. Otherwise |metafile| is NULL. 298 // |metafile| is the rendered page. Otherwise |metafile| is NULL.
298 // Returns true if print preview should continue, false on failure. 299 // Returns true if print preview should continue, false on failure.
299 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); 300 bool PreviewPageRendered(int page_number, printing::Metafile* metafile);
300 301
301 WebKit::WebView* print_web_view_; 302 WebKit::WebView* print_web_view_;
302 303
303 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; 304 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
304 bool is_preview_; 305 bool is_preview_;
306 bool is_print_ready_metafile_sent_;
305 307
306 // Used for scripted initiated printing blocking. 308 // Used for scripted initiated printing blocking.
307 base::Time last_cancelled_script_print_; 309 base::Time last_cancelled_script_print_;
308 int user_cancelled_scripted_print_count_; 310 int user_cancelled_scripted_print_count_;
309 311
310 // Let the browser process know of a printing failure. Only set to false when 312 // Let the browser process know of a printing failure. Only set to false when
311 // the failure came from the browser in the first place. 313 // the failure came from the browser in the first place.
312 bool notify_browser_of_print_failure_; 314 bool notify_browser_of_print_failure_;
313 315
314 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; 316 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
(...skipping 17 matching lines...) Expand all
332 void OnPrintPreview(); 334 void OnPrintPreview();
333 335
334 // Create the print preview document. |pages| is empty to print all pages. 336 // Create the print preview document. |pages| is empty to print all pages.
335 bool CreatePreviewDocument(PrintMsg_Print_Params* params, 337 bool CreatePreviewDocument(PrintMsg_Print_Params* params,
336 const std::vector<int>& pages); 338 const std::vector<int>& pages);
337 339
338 // Called after a page gets rendered. |page_time| is how long the 340 // Called after a page gets rendered. |page_time| is how long the
339 // rendering took. 341 // rendering took.
340 void RenderedPreviewPage(const base::TimeDelta& page_time); 342 void RenderedPreviewPage(const base::TimeDelta& page_time);
341 343
342 // Finalizes the print preview document. 344 // Updates the print preview context when the required pages are rendered.
343 void FinalizePreviewDocument(); 345 void AllPagesRendered();
346
347 // Finalizes the print ready preview document.
348 void FinalizePrintReadyDocument();
344 349
345 // Cleanup after print preview finishes. 350 // Cleanup after print preview finishes.
346 void Finished(); 351 void Finished();
347 352
348 // Cleanup after print preview fails. 353 // Cleanup after print preview fails.
349 void Failed(); 354 void Failed();
350 355
351 // Helper functions 356 // Helper functions
352 int GetNextPageNumber(); 357 int GetNextPageNumber();
353 bool IsReadyToRender() const; 358 bool IsReadyToRender() const;
354 bool IsModifiable() const; 359 bool IsModifiable() const;
360 bool IsLastPageOfPrintReadyMetafile() const;
361
362 // Setters
363 void set_generate_draft_pages(bool generate_draft_pages);
355 364
356 // Getters 365 // Getters
357 WebKit::WebFrame* frame() const; 366 WebKit::WebFrame* frame() const;
358 WebKit::WebNode* node() const; 367 WebKit::WebNode* node() const;
359 int total_page_count() const; 368 int total_page_count() const;
369 bool generate_draft_pages();
360 printing::PreviewMetafile* metafile() const; 370 printing::PreviewMetafile* metafile() const;
361 const PrintMsg_Print_Params& print_params() const; 371 const PrintMsg_Print_Params& print_params() const;
362 const gfx::Size& GetPrintCanvasSize() const; 372 const gfx::Size& GetPrintCanvasSize() const;
363 373
364 private: 374 private:
365 enum State { 375 enum State {
366 UNINITIALIZED, // Not ready to render. 376 UNINITIALIZED, // Not ready to render.
367 INITIALIZED, // Ready to render. 377 INITIALIZED, // Ready to render.
368 RENDERING, // Rendering. 378 RENDERING, // Rendering.
369 DONE // Finished rendering. 379 DONE // Finished rendering.
370 }; 380 };
371 381
372 // Reset some of the internal rendering context. 382 // Reset some of the internal rendering context.
373 void ClearContext(); 383 void ClearContext();
374 384
375 // Specifies what to render for print preview. 385 // Specifies what to render for print preview.
376 WebKit::WebFrame* frame_; 386 WebKit::WebFrame* frame_;
377 scoped_ptr<WebKit::WebNode> node_; 387 scoped_ptr<WebKit::WebNode> node_;
378 388
379 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; 389 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
380 scoped_ptr<printing::PreviewMetafile> metafile_; 390 scoped_ptr<printing::PreviewMetafile> metafile_;
381 scoped_ptr<PrintMsg_Print_Params> print_params_; 391 scoped_ptr<PrintMsg_Print_Params> print_params_;
382 392
383 // Total page count in the renderer. 393 // Total page count in the renderer.
384 int total_page_count_; 394 int total_page_count_;
385 395
386 // Number of pages to render. 396 // List of page indices that need to be rendered.
387 int actual_page_count_; 397 std::vector<int> render_page_list_;
388 398
389 // The current page to render. 399 // Specifies the current list index.
vandebo (ex-Chrome) 2011/08/29 18:21:56 nit: These names seem fine.
kmadhusu 2011/08/30 17:27:00 Done.
390 int current_page_index_; 400 int render_page_list_index_;
391 401
392 std::vector<int> pages_to_render_; 402 // True, when draft pages needs to be generated.
403 bool generate_draft_pages_;
404
405 // Specifies the total number of pages in the print ready metafile.
406 int print_ready_metafile_page_count_;
393 407
394 base::TimeDelta document_render_time_; 408 base::TimeDelta document_render_time_;
395 base::TimeTicks begin_time_; 409 base::TimeTicks begin_time_;
396 410
397 State state_; 411 State state_;
398 }; 412 };
399 413
400 PrintPreviewContext print_preview_context_; 414 PrintPreviewContext print_preview_context_;
401 415
402 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 416 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
403 }; 417 };
404 418
405 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 419 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698