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

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: '' 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,
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
164 // Returns the print scaling option to retain/scale/crop the source page size
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|.
174 // (2) Source is PDF. This is the first preview request and print scaling
175 // option is disabled for initiator renderer plugin.
176 //
177 // In all other cases, we scale the source page to fit the printable area.
178 WebKit::WebPrintScalingOption GetPrintScalingOption(
179 bool source_is_html,
180 const base::DictionaryValue& settings,
181 const PrintMsg_Print_Params& params);
182
163 // Initiate print preview. 183 // Initiate print preview.
164 void OnInitiatePrintPreview(); 184 void OnInitiatePrintPreview();
165 185
166 // Start the process of generating a print preview using |settings|. 186 // Start the process of generating a print preview using |settings|.
167 void OnPrintPreview(const base::DictionaryValue& settings); 187 void OnPrintPreview(const base::DictionaryValue& settings);
168 188
169 // Initialize the print preview document. 189 // Initialize the print preview document.
170 bool CreatePreviewDocument(); 190 bool CreatePreviewDocument();
171 191
172 // Renders a print preview page. |page_number| is 0-based. 192 // Renders a print preview page. |page_number| is 0-based.
(...skipping 20 matching lines...) Expand all
193 213
194 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); 214 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node);
195 215
196 // Notification when printing is done - signal tear-down/free resources. 216 // Notification when printing is done - signal tear-down/free resources.
197 void DidFinishPrinting(PrintingResult result); 217 void DidFinishPrinting(PrintingResult result);
198 218
199 // Print Settings ----------------------------------------------------------- 219 // Print Settings -----------------------------------------------------------
200 220
201 // Initialize print page settings with default settings. 221 // Initialize print page settings with default settings.
202 // Used only for native printing workflow. 222 // Used only for native printing workflow.
203 bool InitPrintSettings(); 223 bool InitPrintSettings(bool fit_to_paper_size);
204 224
205 // Initialize print page settings with default settings and prepare the frame 225 // Initialize print page settings with default settings and prepare the frame
206 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the 226 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the
207 // request and is filled into the |prepare| argument. 227 // request and is filled into the |prepare| argument.
208 // Used only for native printing workflow. 228 // Used only for native printing workflow.
209 bool InitPrintSettingsAndPrepareFrame( 229 bool InitPrintSettingsAndPrepareFrame(
210 WebKit::WebFrame* frame, 230 WebKit::WebFrame* frame,
211 const WebKit::WebNode& node, 231 const WebKit::WebNode& node,
212 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); 232 scoped_ptr<PrepareFrameAndViewForPrint>* prepare);
213 233
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 void set_generate_draft_pages(bool generate_draft_pages); 437 void set_generate_draft_pages(bool generate_draft_pages);
418 void set_error(enum PrintPreviewErrorBuckets error); 438 void set_error(enum PrintPreviewErrorBuckets error);
419 439
420 // Getters 440 // Getters
421 WebKit::WebFrame* frame(); 441 WebKit::WebFrame* frame();
422 const WebKit::WebNode& node() const; 442 const WebKit::WebNode& node() const;
423 int total_page_count() const; 443 int total_page_count() const;
424 bool generate_draft_pages() const; 444 bool generate_draft_pages() const;
425 printing::PreviewMetafile* metafile(); 445 printing::PreviewMetafile* metafile();
426 const PrintMsg_Print_Params& print_params() const; 446 const PrintMsg_Print_Params& print_params() const;
427 const gfx::Size& GetPrintCanvasSize() const; 447 gfx::Size GetPrintCanvasSize() const;
428 int last_error() const; 448 int last_error() const;
429 449
430 private: 450 private:
431 enum State { 451 enum State {
432 UNINITIALIZED, // Not ready to render. 452 UNINITIALIZED, // Not ready to render.
433 INITIALIZED, // Ready to render. 453 INITIALIZED, // Ready to render.
434 RENDERING, // Rendering. 454 RENDERING, // Rendering.
435 DONE // Finished rendering. 455 DONE // Finished rendering.
436 }; 456 };
437 457
(...skipping 29 matching lines...) Expand all
467 enum PrintPreviewErrorBuckets error_; 487 enum PrintPreviewErrorBuckets error_;
468 488
469 State state_; 489 State state_;
470 }; 490 };
471 491
472 PrintPreviewContext print_preview_context_; 492 PrintPreviewContext print_preview_context_;
473 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 493 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
474 }; 494 };
475 495
476 #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