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