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

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

Issue 7621087: Print Preview: Go from event driven print preview back to print preview with sync messages. The s... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 9 years, 4 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> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
kmadhusu 2011/08/20 00:07:11 Fix the comment.
Lei Zhang 2011/08/20 03:25:52 Done.
146 // cancellation / failure.
147 bool RenderPreviewPage(int page_number);
kmadhusu 2011/08/20 00:07:11 This function can now return void.
Lei Zhang 2011/08/20 03:25:52 No, it still need to handle the possible failures
148
150 // Finalize the print preview document. 149 // Finalize the print preview document.
151 bool FinalizePreviewDocument(); 150 bool FinalizePreviewDocument();
152 151
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. 152 // Print / preview the node under the context menu.
158 void OnPrintNodeUnderContextMenu(); 153 void OnPrintNodeUnderContextMenu();
159 154
160 // Print the pages for print preview. Do not display the native print dialog 155 // 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. 156 // for user settings. |job_settings| has new print job settings values.
162 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); 157 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings);
163 158
164 void OnPrintingDone(bool success); 159 void OnPrintingDone(bool success);
165 160
166 // Main printing code ------------------------------------------------------- 161 // Main printing code -------------------------------------------------------
167 162
168 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node); 163 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node);
169 164
170 enum PrintingResult { 165 enum PrintingResult {
171 OK, 166 OK,
172 FAIL_PRINT, 167 FAIL_PRINT,
173 FAIL_PREVIEW, 168 FAIL_PREVIEW,
174 ABORT_PREVIEW,
175 }; 169 };
176 170
177 // Notification when printing is done - signal tear-down/free resources. 171 // Notification when printing is done - signal tear-down/free resources.
178 void DidFinishPrinting(PrintingResult result); 172 void DidFinishPrinting(PrintingResult result);
179 173
180 // Print Settings ----------------------------------------------------------- 174 // Print Settings -----------------------------------------------------------
181 175
182 // Initialize print page settings with default settings. 176 // Initialize print page settings with default settings.
183 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); 177 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node);
184 178
185 // Initialize print page settings with default settings and prepare the frame 179 // Initialize print page settings with default settings and prepare the frame
186 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the 180 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the
187 // request and is filled into the |prepare| argument. 181 // request and is filled into the |prepare| argument.
188 bool InitPrintSettingsAndPrepareFrame( 182 bool InitPrintSettingsAndPrepareFrame(
189 WebKit::WebFrame* frame, 183 WebKit::WebFrame* frame,
190 WebKit::WebNode* node, 184 WebKit::WebNode* node,
191 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); 185 scoped_ptr<PrepareFrameAndViewForPrint>* prepare);
192 186
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| 187 // Update the current print settings with new |job_settings|. |job_settings|
199 // dictionary contains print job details such as printer name, number of 188 // dictionary contains print job details such as printer name, number of
200 // copies, page range, etc. 189 // copies, page range, etc.
201 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); 190 bool UpdatePrintSettings(const base::DictionaryValue& job_settings);
202 191
203 // Get final print settings from the user. 192 // Get final print settings from the user.
204 // Return false if the user cancels or on error. 193 // Return false if the user cancels or on error.
205 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, 194 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame,
206 int expected_pages_count, 195 int expected_pages_count,
207 bool use_browser_overlays); 196 bool use_browser_overlays);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 289
301 // Increment the counter for script initiated printing. 290 // Increment the counter for script initiated printing.
302 // Scripted printing will be blocked for a limited amount of time. 291 // Scripted printing will be blocked for a limited amount of time.
303 void IncrementScriptedPrintCount(); 292 void IncrementScriptedPrintCount();
304 293
305 // Displays the print job error message to the user. 294 // Displays the print job error message to the user.
306 void DisplayPrintJobError(); 295 void DisplayPrintJobError();
307 296
308 void RequestPrintPreview(); 297 void RequestPrintPreview();
309 298
310 // Notify the browser a print preview page has been rendered. 299 // Checks whether print preview should continue or not.
311 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check 300 // Returns true if continuing, false if cancelling.
kmadhusu 2011/08/20 00:07:11 nit: This function should return true if cancellin
Lei Zhang 2011/08/20 03:25:52 Done.
312 // for pending preview requests. 301 bool CheckForCancel();
313 void PreviewPageRendered(int page_number, printing::Metafile* metafile); 302
303 // Notifies the browser a print preview page has been rendered.
304 // |page_number| is 0-based.
305 // For a valid |page_number| with modifiable content,
306 // |metafile| is the rendered page. Otherwise |metafile| is NULL.
307 // Returns true if print preview should continue, false on failure.
308 bool PreviewPageRendered(int page_number, printing::Metafile* metafile);
kmadhusu 2011/08/20 00:07:11 This function can return void.
Lei Zhang 2011/08/20 03:25:52 No, if we encounter a failure, we have to let our
314 309
315 WebKit::WebView* print_web_view_; 310 WebKit::WebView* print_web_view_;
316 311
317 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; 312 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
318 bool is_preview_; 313 bool is_preview_;
319 314
320 // Used for scripted initiated printing blocking. 315 // Used for scripted initiated printing blocking.
321 base::Time last_cancelled_script_print_; 316 base::Time last_cancelled_script_print_;
322 int user_cancelled_scripted_print_count_; 317 int user_cancelled_scripted_print_count_;
323 318
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 350
356 // Finalizes the print preview document. 351 // Finalizes the print preview document.
357 void FinalizePreviewDocument(); 352 void FinalizePreviewDocument();
358 353
359 // Cleanup after print preview finishes. 354 // Cleanup after print preview finishes.
360 void Finished(); 355 void Finished();
361 356
362 // Cleanup after print preview fails. 357 // Cleanup after print preview fails.
363 void Failed(); 358 void Failed();
364 359
365 // Abort the print preview.
366 void Abort();
367
368 // Helper functions 360 // Helper functions
369 int GetNextPageNumber(); 361 int GetNextPageNumber();
370 bool IsReadyToRender() const; 362 bool IsReadyToRender() const;
371 bool IsBusy() const;
372 bool IsModifiable() const; 363 bool IsModifiable() const;
373 364
374 // Getters 365 // Getters
375 WebKit::WebFrame* frame() const; 366 WebKit::WebFrame* frame() const;
376 WebKit::WebNode* node() const; 367 WebKit::WebNode* node() const;
377 int total_page_count() const; 368 int total_page_count() const;
378 printing::PreviewMetafile* metafile() const; 369 printing::PreviewMetafile* metafile() const;
379 const PrintMsg_Print_Params& print_params() const; 370 const PrintMsg_Print_Params& print_params() const;
380 const gfx::Size& GetPrintCanvasSize() const; 371 const gfx::Size& GetPrintCanvasSize() const;
381 372
(...skipping 16 matching lines...) Expand all
398 scoped_ptr<printing::PreviewMetafile> metafile_; 389 scoped_ptr<printing::PreviewMetafile> metafile_;
399 scoped_ptr<PrintMsg_Print_Params> print_params_; 390 scoped_ptr<PrintMsg_Print_Params> print_params_;
400 391
401 // Total page count in the renderer. 392 // Total page count in the renderer.
402 int total_page_count_; 393 int total_page_count_;
403 394
404 // Number of pages to render. 395 // Number of pages to render.
405 int actual_page_count_; 396 int actual_page_count_;
406 397
407 // The current page to render. 398 // The current page to render.
408 int current_page_number_; 399 int current_page_index_;
409 400
410 // |rendered_pages_| tracks which pages need to be printed as well as 401 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 402
415 base::TimeDelta document_render_time_; 403 base::TimeDelta document_render_time_;
416 base::TimeTicks begin_time_; 404 base::TimeTicks begin_time_;
417 405
418 State state_; 406 State state_;
419 }; 407 };
420 408
421 PrintPreviewContext print_preview_context_; 409 PrintPreviewContext print_preview_context_;
422 410
423 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 411 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
424 }; 412 };
425 413
426 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 414 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698