| 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 "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "content/renderer/render_view_observer.h" | 12 #include "content/renderer/render_view_observer.h" |
| 13 #include "content/renderer/render_view_observer_tracker.h" | 13 #include "content/renderer/render_view_observer_tracker.h" |
| 14 #include "printing/metafile.h" | 14 #include "printing/metafile.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
| 17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 18 | 18 |
| 19 class DictionaryValue; | 19 class DictionaryValue; |
| 20 struct PrintMsg_Print_Params; | 20 struct PrintMsg_Print_Params; |
| 21 struct PrintMsg_PrintPage_Params; | 21 struct PrintMsg_PrintPage_Params; |
| 22 struct PrintMsg_PrintPages_Params; | 22 struct PrintMsg_PrintPages_Params; |
| 23 | 23 |
| 24 #if defined(USE_X11) | |
| 25 namespace skia { | |
| 26 class VectorCanvas; | |
| 27 } | |
| 28 #endif | |
| 29 | |
| 30 // Class that calls the Begin and End print functions on the frame and changes | 24 // Class that calls the Begin and End print functions on the frame and changes |
| 31 // the size of the view temporarily to support full page printing.. | 25 // the size of the view temporarily to support full page printing.. |
| 32 // Do not serve any events in the time between construction and destruction of | 26 // Do not serve any events in the time between construction and destruction of |
| 33 // this class because it will cause flicker. | 27 // this class because it will cause flicker. |
| 34 class PrepareFrameAndViewForPrint { | 28 class PrepareFrameAndViewForPrint { |
| 35 public: | 29 public: |
| 36 // Prints |frame|. If |node| is not NULL, then only that node will be | 30 // Prints |frame|. If |node| is not NULL, then only that node will be |
| 37 // printed. | 31 // printed. |
| 38 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, | 32 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, |
| 39 WebKit::WebFrame* frame, | 33 WebKit::WebFrame* frame, |
| 40 WebKit::WebNode* node, | 34 WebKit::WebNode* node, |
| 41 WebKit::WebView* web_view); | 35 WebKit::WebView* web_view); |
| 42 ~PrepareFrameAndViewForPrint(); | 36 ~PrepareFrameAndViewForPrint(); |
| 43 | 37 |
| 44 int GetExpectedPageCount() const { | 38 int GetExpectedPageCount() const { |
| 45 return expected_pages_count_; | 39 return expected_pages_count_; |
| 46 } | 40 } |
| 47 | 41 |
| 48 bool ShouldUseBrowserOverlays() const { | 42 bool ShouldUseBrowserOverlays() const { |
| 49 return use_browser_overlays_; | 43 return use_browser_overlays_; |
| 50 } | 44 } |
| 51 | 45 |
| 52 const gfx::Size& GetPrintCanvasSize() const { | 46 const gfx::Size& GetPrintCanvasSize() const { |
| 53 return print_canvas_size_; | 47 return print_canvas_size_; |
| 54 } | 48 } |
| 55 | 49 |
| 50 void FinishPrinting(); |
| 51 |
| 56 private: | 52 private: |
| 57 WebKit::WebFrame* frame_; | 53 WebKit::WebFrame* frame_; |
| 58 WebKit::WebView* web_view_; | 54 WebKit::WebView* web_view_; |
| 59 gfx::Size print_canvas_size_; | 55 gfx::Size print_canvas_size_; |
| 60 gfx::Size prev_view_size_; | 56 gfx::Size prev_view_size_; |
| 61 gfx::Size prev_scroll_offset_; | 57 gfx::Size prev_scroll_offset_; |
| 62 int expected_pages_count_; | 58 int expected_pages_count_; |
| 63 bool use_browser_overlays_; | 59 bool use_browser_overlays_; |
| 60 bool finished_; |
| 64 | 61 |
| 65 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 62 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
| 66 }; | 63 }; |
| 67 | 64 |
| 68 | 65 |
| 69 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 66 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
| 70 // We plan on making print asynchronous and that will require copying the DOM | 67 // We plan on making print asynchronous and that will require copying the DOM |
| 71 // of the document and creating a new WebView with the contents. | 68 // of the document and creating a new WebView with the contents. |
| 72 class PrintWebViewHelper : public RenderViewObserver , | 69 class PrintWebViewHelper : public RenderViewObserver , |
| 73 public RenderViewObserverTracker<PrintWebViewHelper>, | 70 public RenderViewObserverTracker<PrintWebViewHelper>, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // It will implicitly revert the document to display CSS media type. | 155 // It will implicitly revert the document to display CSS media type. |
| 159 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 156 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
| 160 WebKit::WebFrame* frame, | 157 WebKit::WebFrame* frame, |
| 161 WebKit::WebNode* node); | 158 WebKit::WebNode* node); |
| 162 | 159 |
| 163 // Prints the page listed in |params|. | 160 // Prints the page listed in |params|. |
| 164 #if defined(USE_X11) | 161 #if defined(USE_X11) |
| 165 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 162 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 166 const gfx::Size& canvas_size, | 163 const gfx::Size& canvas_size, |
| 167 WebKit::WebFrame* frame, | 164 WebKit::WebFrame* frame, |
| 168 printing::Metafile* metafile, | 165 printing::Metafile* metafile); |
| 169 scoped_ptr<skia::VectorCanvas>* canvas); | |
| 170 #else | 166 #else |
| 171 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 167 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 172 const gfx::Size& canvas_size, | 168 const gfx::Size& canvas_size, |
| 173 WebKit::WebFrame* frame); | 169 WebKit::WebFrame* frame); |
| 174 #endif | 170 #endif |
| 175 | 171 |
| 176 // Render the frame for printing. | 172 // Render the frame for printing. |
| 177 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); | 173 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 178 | 174 |
| 179 // Render the frame for preview. | 175 // Render the frame for preview. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 int user_cancelled_scripted_print_count_; | 255 int user_cancelled_scripted_print_count_; |
| 260 | 256 |
| 261 // Let the browser process know of a printing failure. Only set to false when | 257 // Let the browser process know of a printing failure. Only set to false when |
| 262 // the failure came from the browser in the first place. | 258 // the failure came from the browser in the first place. |
| 263 bool notify_browser_of_print_failure_; | 259 bool notify_browser_of_print_failure_; |
| 264 | 260 |
| 265 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 261 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 266 }; | 262 }; |
| 267 | 263 |
| 268 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 264 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |