| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gfx/size.h" | 10 #include "base/gfx/size.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "webkit/glue/webview_delegate.h" | 13 #include "webkit/api/public/WebViewClient.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class Size; | 16 class Size; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace IPC { | 19 namespace IPC { |
| 20 class Message; | 20 class Message; |
| 21 } | 21 } |
| 22 | 22 |
| 23 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
| 24 namespace printing { | 24 namespace printing { |
| 25 class PdfPsMetafile; | 25 class PdfPsMetafile; |
| 26 typedef PdfPsMetafile NativeMetafile; | 26 typedef PdfPsMetafile NativeMetafile; |
| 27 } | 27 } |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 class RenderView; | 30 class RenderView; |
| 31 class WebView; | |
| 32 struct ViewMsg_Print_Params; | 31 struct ViewMsg_Print_Params; |
| 33 struct ViewMsg_PrintPage_Params; | 32 struct ViewMsg_PrintPage_Params; |
| 34 struct ViewMsg_PrintPages_Params; | 33 struct ViewMsg_PrintPages_Params; |
| 35 | 34 |
| 36 | |
| 37 // Class that calls the Begin and End print functions on the frame and changes | 35 // Class that calls the Begin and End print functions on the frame and changes |
| 38 // the size of the view temporarily to support full page printing.. | 36 // the size of the view temporarily to support full page printing.. |
| 39 // Do not serve any events in the time between construction and destruction of | 37 // Do not serve any events in the time between construction and destruction of |
| 40 // this class because it will cause flicker. | 38 // this class because it will cause flicker. |
| 41 class PrepareFrameAndViewForPrint { | 39 class PrepareFrameAndViewForPrint { |
| 42 public: | 40 public: |
| 43 PrepareFrameAndViewForPrint(const ViewMsg_Print_Params& print_params, | 41 PrepareFrameAndViewForPrint(const ViewMsg_Print_Params& print_params, |
| 44 WebKit::WebFrame* frame, | 42 WebKit::WebFrame* frame, |
| 45 WebView* web_view); | 43 WebKit::WebView* web_view); |
| 46 ~PrepareFrameAndViewForPrint(); | 44 ~PrepareFrameAndViewForPrint(); |
| 47 | 45 |
| 48 int GetExpectedPageCount() const { | 46 int GetExpectedPageCount() const { |
| 49 return expected_pages_count_; | 47 return expected_pages_count_; |
| 50 } | 48 } |
| 51 | 49 |
| 52 const gfx::Size& GetPrintCanvasSize() const { | 50 const gfx::Size& GetPrintCanvasSize() const { |
| 53 return print_canvas_size_; | 51 return print_canvas_size_; |
| 54 } | 52 } |
| 55 | 53 |
| 56 private: | 54 private: |
| 57 WebKit::WebFrame* frame_; | 55 WebKit::WebFrame* frame_; |
| 58 WebView* web_view_; | 56 WebKit::WebView* web_view_; |
| 59 gfx::Size print_canvas_size_; | 57 gfx::Size print_canvas_size_; |
| 60 gfx::Size prev_view_size_; | 58 gfx::Size prev_view_size_; |
| 61 int expected_pages_count_; | 59 int expected_pages_count_; |
| 62 | 60 |
| 63 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 61 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 | 64 |
| 67 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 65 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
| 68 // We plan on making print asynchronous and that will require copying the DOM | 66 // We plan on making print asynchronous and that will require copying the DOM |
| 69 // of the document and creating a new WebView with the contents. | 67 // of the document and creating a new WebView with the contents. |
| 70 class PrintWebViewHelper : public WebViewDelegate { | 68 class PrintWebViewHelper : public WebKit::WebViewClient { |
| 71 public: | 69 public: |
| 72 explicit PrintWebViewHelper(RenderView* render_view); | 70 explicit PrintWebViewHelper(RenderView* render_view); |
| 73 virtual ~PrintWebViewHelper(); | 71 virtual ~PrintWebViewHelper(); |
| 74 | 72 |
| 75 void Print(WebKit::WebFrame* frame, bool script_initiated); | 73 void Print(WebKit::WebFrame* frame, bool script_initiated); |
| 76 | 74 |
| 77 // Is there a background print in progress? | 75 // Is there a background print in progress? |
| 78 bool IsPrinting() { | 76 bool IsPrinting() { |
| 79 return print_web_view_.get() != NULL; | 77 return print_web_view_ != NULL; |
| 80 } | 78 } |
| 81 | 79 |
| 82 // Notification when printing is done - signal teardown | 80 // Notification when printing is done - signal teardown |
| 83 void DidFinishPrinting(bool success); | 81 void DidFinishPrinting(bool success); |
| 84 | 82 |
| 85 // Prints the page listed in |params| as a JPEG image. The width and height of | 83 // Prints the page listed in |params| as a JPEG image. The width and height of |
| 86 // the image will scale propotionally given the |zoom_factor| multiplier. The | 84 // the image will scale propotionally given the |zoom_factor| multiplier. The |
| 87 // encoded JPEG data will be written into the supplied vector |image_data|. | 85 // encoded JPEG data will be written into the supplied vector |image_data|. |
| 88 void PrintPageAsJPEG(const ViewMsg_PrintPage_Params& params, | 86 void PrintPageAsJPEG(const ViewMsg_PrintPage_Params& params, |
| 89 WebKit::WebFrame* frame, | 87 WebKit::WebFrame* frame, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 110 // It will implicitly revert the document to display CSS media type. | 108 // It will implicitly revert the document to display CSS media type. |
| 111 void PrintPages(const ViewMsg_PrintPages_Params& params, | 109 void PrintPages(const ViewMsg_PrintPages_Params& params, |
| 112 WebKit::WebFrame* frame); | 110 WebKit::WebFrame* frame); |
| 113 | 111 |
| 114 // IPC::Message::Sender | 112 // IPC::Message::Sender |
| 115 bool Send(IPC::Message* msg); | 113 bool Send(IPC::Message* msg); |
| 116 | 114 |
| 117 int32 routing_id(); | 115 int32 routing_id(); |
| 118 | 116 |
| 119 // WebKit::WebViewClient | 117 // WebKit::WebViewClient |
| 120 virtual WebView* createView(WebKit::WebFrame* creator) { return NULL; } | 118 virtual WebKit::WebView* createView(WebKit::WebFrame* creator) { return NULL;
} |
| 121 virtual WebKit::WebWidget* createPopupMenu(bool activatable) { return NULL; } | 119 virtual WebKit::WebWidget* createPopupMenu(bool activatable) { return NULL; } |
| 122 virtual WebKit::WebWidget* createPopupMenu( | 120 virtual WebKit::WebWidget* createPopupMenu( |
| 123 const WebKit::WebPopupMenuInfo& info) { return NULL; } | 121 const WebKit::WebPopupMenuInfo& info) { return NULL; } |
| 124 virtual void didAddMessageToConsole( | 122 virtual void didAddMessageToConsole( |
| 125 const WebKit::WebConsoleMessage& message, | 123 const WebKit::WebConsoleMessage& message, |
| 126 const WebKit::WebString& source_name, unsigned source_line) {} | 124 const WebKit::WebString& source_name, unsigned source_line) {} |
| 127 virtual void printPage(WebKit::WebFrame* frame) {} | 125 virtual void printPage(WebKit::WebFrame* frame) {} |
| 128 virtual WebKit::WebNotificationPresenter* notificationPresenter() { | 126 virtual WebKit::WebNotificationPresenter* notificationPresenter() { |
| 129 return NULL; | 127 return NULL; |
| 130 } | 128 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 virtual void show(WebKit::WebNavigationPolicy) {} | 226 virtual void show(WebKit::WebNavigationPolicy) {} |
| 229 virtual void runModal() {} | 227 virtual void runModal() {} |
| 230 virtual WebKit::WebRect windowRect(); | 228 virtual WebKit::WebRect windowRect(); |
| 231 virtual void setWindowRect(const WebKit::WebRect&) {} | 229 virtual void setWindowRect(const WebKit::WebRect&) {} |
| 232 virtual WebKit::WebRect windowResizerRect(); | 230 virtual WebKit::WebRect windowResizerRect(); |
| 233 virtual WebKit::WebRect rootWindowRect(); | 231 virtual WebKit::WebRect rootWindowRect(); |
| 234 virtual WebKit::WebScreenInfo screenInfo(); | 232 virtual WebKit::WebScreenInfo screenInfo(); |
| 235 | 233 |
| 236 private: | 234 private: |
| 237 RenderView* render_view_; | 235 RenderView* render_view_; |
| 238 scoped_ptr<WebView> print_web_view_; | 236 WebKit::WebView* print_web_view_; |
| 239 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; | 237 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; |
| 240 base::Time last_cancelled_script_print_; | 238 base::Time last_cancelled_script_print_; |
| 241 int user_cancelled_scripted_print_count_; | 239 int user_cancelled_scripted_print_count_; |
| 242 | 240 |
| 243 private: | 241 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 242 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 245 }; | 243 }; |
| 246 | 244 |
| 247 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 245 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |