| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 struct ViewMsg_PrintPage_Params; | 38 struct ViewMsg_PrintPage_Params; |
| 39 struct ViewMsg_PrintPages_Params; | 39 struct ViewMsg_PrintPages_Params; |
| 40 struct ViewHostMsg_DidPreviewDocument_Params; | 40 struct ViewHostMsg_DidPreviewDocument_Params; |
| 41 | 41 |
| 42 // Class that calls the Begin and End print functions on the frame and changes | 42 // Class that calls the Begin and End print functions on the frame and changes |
| 43 // the size of the view temporarily to support full page printing.. | 43 // the size of the view temporarily to support full page printing.. |
| 44 // Do not serve any events in the time between construction and destruction of | 44 // Do not serve any events in the time between construction and destruction of |
| 45 // this class because it will cause flicker. | 45 // this class because it will cause flicker. |
| 46 class PrepareFrameAndViewForPrint { | 46 class PrepareFrameAndViewForPrint { |
| 47 public: | 47 public: |
| 48 // Prints |frame|. If |node| is not NULL, then only that node will be |
| 49 // printed. |
| 48 PrepareFrameAndViewForPrint(const ViewMsg_Print_Params& print_params, | 50 PrepareFrameAndViewForPrint(const ViewMsg_Print_Params& print_params, |
| 49 WebKit::WebFrame* frame, | 51 WebKit::WebFrame* frame, |
| 52 WebKit::WebNode* node, |
| 50 WebKit::WebView* web_view); | 53 WebKit::WebView* web_view); |
| 51 ~PrepareFrameAndViewForPrint(); | 54 ~PrepareFrameAndViewForPrint(); |
| 52 | 55 |
| 53 int GetExpectedPageCount() const { | 56 int GetExpectedPageCount() const { |
| 54 return expected_pages_count_; | 57 return expected_pages_count_; |
| 55 } | 58 } |
| 56 | 59 |
| 57 bool ShouldUseBrowserOverlays() const { | 60 bool ShouldUseBrowserOverlays() const { |
| 58 return use_browser_overlays_; | 61 return use_browser_overlays_; |
| 59 } | 62 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 | 79 |
| 77 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 80 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
| 78 // We plan on making print asynchronous and that will require copying the DOM | 81 // We plan on making print asynchronous and that will require copying the DOM |
| 79 // of the document and creating a new WebView with the contents. | 82 // of the document and creating a new WebView with the contents. |
| 80 class PrintWebViewHelper : public WebKit::WebViewClient, | 83 class PrintWebViewHelper : public WebKit::WebViewClient, |
| 81 public WebKit::WebFrameClient { | 84 public WebKit::WebFrameClient { |
| 82 public: | 85 public: |
| 83 explicit PrintWebViewHelper(RenderView* render_view); | 86 explicit PrintWebViewHelper(RenderView* render_view); |
| 84 virtual ~PrintWebViewHelper(); | 87 virtual ~PrintWebViewHelper(); |
| 85 | 88 |
| 86 void Print(WebKit::WebFrame* frame, bool script_initiated, bool is_preview); | 89 void PrintFrame(WebKit::WebFrame* frame, |
| 90 bool script_initiated, |
| 91 bool is_preview); |
| 92 |
| 93 void PrintNode(WebKit::WebNode* node, |
| 94 bool script_initiated, |
| 95 bool is_preview); |
| 87 | 96 |
| 88 // Is there a background print in progress? | 97 // Is there a background print in progress? |
| 89 bool IsPrinting() { | 98 bool IsPrinting() { |
| 90 return print_web_view_ != NULL; | 99 return print_web_view_ != NULL; |
| 91 } | 100 } |
| 92 | 101 |
| 93 // Notification when printing is done - signal teardown | 102 // Notification when printing is done - signal teardown |
| 94 void DidFinishPrinting(bool success); | 103 void DidFinishPrinting(bool success); |
| 95 | 104 |
| 96 protected: | 105 protected: |
| 97 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 106 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
| 98 | 107 |
| 99 // Prints the page listed in |params|. | 108 // Prints the page listed in |params|. |
| 100 #if defined(USE_X11) | 109 #if defined(USE_X11) |
| 101 void PrintPage(const ViewMsg_PrintPage_Params& params, | 110 void PrintPage(const ViewMsg_PrintPage_Params& params, |
| 102 const gfx::Size& canvas_size, | 111 const gfx::Size& canvas_size, |
| 103 WebKit::WebFrame* frame, | 112 WebKit::WebFrame* frame, |
| 104 printing::NativeMetafile* metafile, | 113 printing::NativeMetafile* metafile, |
| 105 skia::VectorCanvas** canvas); | 114 skia::VectorCanvas** canvas); |
| 106 #else | 115 #else |
| 107 void PrintPage(const ViewMsg_PrintPage_Params& params, | 116 void PrintPage(const ViewMsg_PrintPage_Params& params, |
| 108 const gfx::Size& canvas_size, | 117 const gfx::Size& canvas_size, |
| 109 WebKit::WebFrame* frame); | 118 WebKit::WebFrame* frame); |
| 110 #endif | 119 #endif |
| 111 | 120 |
| 112 // Prints all the pages listed in |params|. | 121 // Prints all the pages listed in |params|. |
| 113 // It will implicitly revert the document to display CSS media type. | 122 // It will implicitly revert the document to display CSS media type. |
| 114 void PrintPages(const ViewMsg_PrintPages_Params& params, | 123 void PrintPages(const ViewMsg_PrintPages_Params& params, |
| 115 WebKit::WebFrame* frame); | 124 WebKit::WebFrame* frame, |
| 125 WebKit::WebNode* node); |
| 116 | 126 |
| 117 // IPC::Message::Sender | 127 // IPC::Message::Sender |
| 118 bool Send(IPC::Message* msg); | 128 bool Send(IPC::Message* msg); |
| 119 | 129 |
| 120 int32 routing_id(); | 130 int32 routing_id(); |
| 121 | 131 |
| 122 // WebKit::WebViewClient override: | 132 // WebKit::WebViewClient override: |
| 123 virtual void didStopLoading(); | 133 virtual void didStopLoading(); |
| 124 | 134 |
| 125 private: | 135 private: |
| 126 static void GetPageSizeAndMarginsInPoints( | 136 static void GetPageSizeAndMarginsInPoints( |
| 127 WebKit::WebFrame* frame, | 137 WebKit::WebFrame* frame, |
| 128 int page_index, | 138 int page_index, |
| 129 const ViewMsg_Print_Params& default_params, | 139 const ViewMsg_Print_Params& default_params, |
| 130 double* content_width_in_points, | 140 double* content_width_in_points, |
| 131 double* content_height_in_points, | 141 double* content_height_in_points, |
| 132 double* margin_top_in_points, | 142 double* margin_top_in_points, |
| 133 double* margin_right_in_points, | 143 double* margin_right_in_points, |
| 134 double* margin_bottom_in_points, | 144 double* margin_bottom_in_points, |
| 135 double* margin_left_in_points); | 145 double* margin_left_in_points); |
| 136 | 146 |
| 147 void Print(WebKit::WebFrame* frame, |
| 148 WebKit::WebNode* node, |
| 149 bool script_initiated, |
| 150 bool is_preview); |
| 151 |
| 137 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, | 152 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, |
| 153 WebKit::WebNode* node, |
| 138 ViewMsg_Print_Params* params); | 154 ViewMsg_Print_Params* params); |
| 139 | 155 |
| 140 // Initialize print page settings with default settings. | 156 // Initialize print page settings with default settings. |
| 141 bool InitPrintSettings(WebKit::WebFrame* frame); | 157 bool InitPrintSettings(WebKit::WebFrame* frame, |
| 158 WebKit::WebNode* node); |
| 142 | 159 |
| 143 // Get the default printer settings. | 160 // Get the default printer settings. |
| 144 bool GetDefaultPrintSettings(WebKit::WebFrame* frame, | 161 bool GetDefaultPrintSettings(WebKit::WebFrame* frame, |
| 162 WebKit::WebNode* node, |
| 145 ViewMsg_Print_Params* params); | 163 ViewMsg_Print_Params* params); |
| 146 | 164 |
| 147 // Get final print settings from the user. | 165 // Get final print settings from the user. |
| 148 // Return false if the user cancels or on error. | 166 // Return false if the user cancels or on error. |
| 149 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 167 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 150 int expected_pages_count, | 168 int expected_pages_count, |
| 151 bool use_browser_overlays); | 169 bool use_browser_overlays); |
| 152 | 170 |
| 153 // Render the frame for printing. | 171 // Render the frame for printing. |
| 154 void RenderPagesForPrint(WebKit::WebFrame* frame); | 172 void RenderPagesForPrint(WebKit::WebFrame* frame, |
| 173 WebKit::WebNode* node); |
| 155 | 174 |
| 156 // Render the frame for preview. | 175 // Render the frame for preview. |
| 157 void RenderPagesForPreview(WebKit::WebFrame* frame); | 176 void RenderPagesForPreview(WebKit::WebFrame* frame); |
| 158 void CreatePreviewDocument(const ViewMsg_PrintPages_Params& params, | 177 void CreatePreviewDocument(const ViewMsg_PrintPages_Params& params, |
| 159 WebKit::WebFrame* frame, | 178 WebKit::WebFrame* frame, |
| 160 ViewHostMsg_DidPreviewDocument_Params* print_params); | 179 ViewHostMsg_DidPreviewDocument_Params* print_params); |
| 161 #if defined(OS_MACOSX) | 180 #if defined(OS_MACOSX) |
| 162 void RenderPage(const gfx::Size& page_size, const gfx::Point& content_origin, | 181 void RenderPage(const gfx::Size& page_size, const gfx::Point& content_origin, |
| 163 const float& scale_factor, int page_number, | 182 const float& scale_factor, int page_number, |
| 164 WebKit::WebFrame* frame, printing::NativeMetafile* metafile); | 183 WebKit::WebFrame* frame, printing::NativeMetafile* metafile); |
| 165 bool CopyMetafileDataToSharedMem(printing::NativeMetafile* metafile, | 184 bool CopyMetafileDataToSharedMem(printing::NativeMetafile* metafile, |
| 166 base::SharedMemoryHandle* shared_mem_handle); | 185 base::SharedMemoryHandle* shared_mem_handle); |
| 167 #endif | 186 #endif |
| 168 | 187 |
| 169 RenderView* render_view_; | 188 RenderView* render_view_; |
| 170 WebKit::WebView* print_web_view_; | 189 WebKit::WebView* print_web_view_; |
| 171 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; | 190 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; |
| 172 base::Time last_cancelled_script_print_; | 191 base::Time last_cancelled_script_print_; |
| 173 int user_cancelled_scripted_print_count_; | 192 int user_cancelled_scripted_print_count_; |
| 174 bool is_preview_; | 193 bool is_preview_; |
| 175 | 194 |
| 176 private: | 195 private: |
| 177 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 196 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 178 }; | 197 }; |
| 179 | 198 |
| 180 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 199 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |