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

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

Issue 10168013: [Print Preview] Modified PrepareFrameAndViewPrint class to call the new printBegin function to supp… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GetPrintScalingOption() function comments. Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 9 #include <vector>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "content/public/renderer/render_view_observer.h" 14 #include "content/public/renderer/render_view_observer.h"
15 #include "content/public/renderer/render_view_observer_tracker.h" 15 #include "content/public/renderer/render_view_observer_tracker.h"
16 #include "printing/metafile.h" 16 #include "printing/metafile.h"
17 #include "printing/metafile_impl.h" 17 #include "printing/metafile_impl.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
22 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
23 24
24 struct PrintMsg_Print_Params; 25 struct PrintMsg_Print_Params;
25 struct PrintMsg_PrintPage_Params; 26 struct PrintMsg_PrintPage_Params;
26 struct PrintMsg_PrintPages_Params; 27 struct PrintMsg_PrintPages_Params;
27 28
28 namespace base { 29 namespace base {
29 class DictionaryValue; 30 class DictionaryValue;
30 } 31 }
(...skipping 17 matching lines...) Expand all
48 void UpdatePrintParams(const PrintMsg_Print_Params& print_params); 49 void UpdatePrintParams(const PrintMsg_Print_Params& print_params);
49 50
50 int GetExpectedPageCount() const { 51 int GetExpectedPageCount() const {
51 return expected_pages_count_; 52 return expected_pages_count_;
52 } 53 }
53 54
54 bool ShouldUseBrowserOverlays() const { 55 bool ShouldUseBrowserOverlays() const {
55 return use_browser_overlays_; 56 return use_browser_overlays_;
56 } 57 }
57 58
58 const gfx::Size& GetPrintCanvasSize() const { 59 gfx::Size GetPrintCanvasSize() const {
59 return print_canvas_size_; 60 return gfx::Size(web_print_params_.printContentArea.width,
darin (slow to review) 2012/05/17 19:13:03 WebSize can automagically be converted to gfx::Siz
kmadhusu 2012/05/17 20:16:29 PrintContentArea is a WebRect. I didn't find an ea
kmadhusu 2012/05/17 21:24:44 Darin: In order to commit the webkit CL asap, I am
61 web_print_params_.printContentArea.height);
60 } 62 }
61 63
62 void FinishPrinting(); 64 void FinishPrinting();
63 65
64 private: 66 private:
65 void StartPrinting(const gfx::Size& print_params); 67 void StartPrinting(const WebKit::WebPrintParams& webkit_print_params);
66 68
67 WebKit::WebFrame* frame_; 69 WebKit::WebFrame* frame_;
68 WebKit::WebNode node_to_print_; 70 WebKit::WebNode node_to_print_;
69 WebKit::WebView* web_view_; 71 WebKit::WebView* web_view_;
70 gfx::Size print_canvas_size_; 72 WebKit::WebPrintParams web_print_params_;
71 gfx::Size prev_view_size_; 73 gfx::Size prev_view_size_;
72 gfx::Size prev_scroll_offset_; 74 gfx::Size prev_scroll_offset_;
73 int dpi_;
74 int expected_pages_count_; 75 int expected_pages_count_;
75 bool use_browser_overlays_; 76 bool use_browser_overlays_;
76 bool finished_; 77 bool finished_;
77 78
78 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); 79 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint);
79 }; 80 };
80 81
81 // PrintWebViewHelper handles most of the printing grunt work for RenderView. 82 // PrintWebViewHelper handles most of the printing grunt work for RenderView.
82 // We plan on making print asynchronous and that will require copying the DOM 83 // We plan on making print asynchronous and that will require copying the DOM
83 // of the document and creating a new WebView with the contents. 84 // of the document and creating a new WebView with the contents.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const printing::PageSizeMargins& page_layout_in_points, 154 const printing::PageSizeMargins& page_layout_in_points,
154 gfx::Size* page_size, 155 gfx::Size* page_size,
155 gfx::Rect* content_area); 156 gfx::Rect* content_area);
156 157
157 // Update |ignore_css_margins_| based on settings. 158 // Update |ignore_css_margins_| based on settings.
158 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); 159 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings);
159 160
160 // Returns true if the current destination printer is PRINT_TO_PDF. 161 // Returns true if the current destination printer is PRINT_TO_PDF.
161 bool IsPrintToPdfRequested(const base::DictionaryValue& settings); 162 bool IsPrintToPdfRequested(const base::DictionaryValue& settings);
162 163
163 // Returns false if 164 // Returns the print scaling option to retain/scale/crop the source page size
164 // (1) The current destination printer is SAVE_AS_PDF or 165 // to fit the printable area of the paper.
166 //
167 // We retain the source page size when the current destination printer is
168 // SAVE_AS_PDF.
169 //
170 // We crop the source page size to fit the printable area or we print only the
171 // left top page contents when
172 // (1) Source is PDF and the user has requested not to fit to printable area
173 // via |job_settings|.
165 // (2) Source is PDF. This is the first preview request and print scaling 174 // (2) Source is PDF. This is the first preview request and print scaling
166 // option is disabled for initiator renderer plugin. 175 // option is disabled for initiator renderer plugin.
167 // (3) Source is PDF and the user has requested not to fit to printable area 176 //
168 // via |job_settings|. 177 // In all other cases, we scale the source page to fit the printable area.
169 // In all other cases returns true to fit the print contents in paper size. 178 WebKit::WebPrintScalingOption GetPrintScalingOption(
170 bool IsFitToPaperSizeRequested(bool source_is_html, 179 bool source_is_html,
171 const base::DictionaryValue& job_settings, 180 const base::DictionaryValue& job_settings,
172 const PrintMsg_Print_Params& params); 181 const PrintMsg_Print_Params& params);
173 182
174 // Initiate print preview. 183 // Initiate print preview.
175 void OnInitiatePrintPreview(); 184 void OnInitiatePrintPreview();
176 185
177 // Start the process of generating a print preview using |settings|. 186 // Start the process of generating a print preview using |settings|.
178 void OnPrintPreview(const base::DictionaryValue& settings); 187 void OnPrintPreview(const base::DictionaryValue& settings);
179 188
180 // Initialize the print preview document. 189 // Initialize the print preview document.
181 bool CreatePreviewDocument(); 190 bool CreatePreviewDocument();
182 191
(...skipping 21 matching lines...) Expand all
204 213
205 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); 214 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node);
206 215
207 // Notification when printing is done - signal tear-down/free resources. 216 // Notification when printing is done - signal tear-down/free resources.
208 void DidFinishPrinting(PrintingResult result); 217 void DidFinishPrinting(PrintingResult result);
209 218
210 // Print Settings ----------------------------------------------------------- 219 // Print Settings -----------------------------------------------------------
211 220
212 // Initialize print page settings with default settings. 221 // Initialize print page settings with default settings.
213 // Used only for native printing workflow. 222 // Used only for native printing workflow.
214 bool InitPrintSettings(); 223 bool InitPrintSettings(bool fit_to_paper_size);
215 224
216 // Initialize print page settings with default settings and prepare the frame 225 // Initialize print page settings with default settings and prepare the frame
217 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the 226 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the
218 // request and is filled into the |prepare| argument. 227 // request and is filled into the |prepare| argument.
219 // Used only for native printing workflow. 228 // Used only for native printing workflow.
220 bool InitPrintSettingsAndPrepareFrame( 229 bool InitPrintSettingsAndPrepareFrame(
221 WebKit::WebFrame* frame, 230 WebKit::WebFrame* frame,
222 const WebKit::WebNode& node, 231 const WebKit::WebNode& node,
223 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); 232 scoped_ptr<PrepareFrameAndViewForPrint>* prepare);
224 233
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void set_generate_draft_pages(bool generate_draft_pages); 437 void set_generate_draft_pages(bool generate_draft_pages);
429 void set_error(enum PrintPreviewErrorBuckets error); 438 void set_error(enum PrintPreviewErrorBuckets error);
430 439
431 // Getters 440 // Getters
432 WebKit::WebFrame* frame(); 441 WebKit::WebFrame* frame();
433 const WebKit::WebNode& node() const; 442 const WebKit::WebNode& node() const;
434 int total_page_count() const; 443 int total_page_count() const;
435 bool generate_draft_pages() const; 444 bool generate_draft_pages() const;
436 printing::PreviewMetafile* metafile(); 445 printing::PreviewMetafile* metafile();
437 const PrintMsg_Print_Params& print_params() const; 446 const PrintMsg_Print_Params& print_params() const;
438 const gfx::Size& GetPrintCanvasSize() const; 447 gfx::Size GetPrintCanvasSize() const;
439 int last_error() const; 448 int last_error() const;
440 449
441 private: 450 private:
442 enum State { 451 enum State {
443 UNINITIALIZED, // Not ready to render. 452 UNINITIALIZED, // Not ready to render.
444 INITIALIZED, // Ready to render. 453 INITIALIZED, // Ready to render.
445 RENDERING, // Rendering. 454 RENDERING, // Rendering.
446 DONE // Finished rendering. 455 DONE // Finished rendering.
447 }; 456 };
448 457
(...skipping 29 matching lines...) Expand all
478 enum PrintPreviewErrorBuckets error_; 487 enum PrintPreviewErrorBuckets error_;
479 488
480 State state_; 489 State state_;
481 }; 490 };
482 491
483 PrintPreviewContext print_preview_context_; 492 PrintPreviewContext print_preview_context_;
484 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 493 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
485 }; 494 };
486 495
487 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 496 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698