Chromium Code Reviews| 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/scoped_ptr.h" | 9 #include "base/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 "chrome/renderer/render_view_observer.h" | 12 #include "chrome/renderer/render_view_observer.h" |
| 13 #include "printing/native_metafile.h" | 13 #include "printing/native_metafile.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 | 17 |
| 18 class DictionaryValue; | |
| 19 | |
| 18 namespace gfx { | 20 namespace gfx { |
| 19 class Size; | 21 class Size; |
| 20 } | 22 } |
| 21 | 23 |
| 22 #if defined(USE_X11) | 24 #if defined(USE_X11) |
| 23 namespace skia { | 25 namespace skia { |
| 24 class VectorCanvas; | 26 class VectorCanvas; |
| 25 } | 27 } |
| 26 #endif | 28 #endif |
| 27 | 29 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 explicit PrintWebViewHelper(RenderView* render_view); | 80 explicit PrintWebViewHelper(RenderView* render_view); |
| 79 virtual ~PrintWebViewHelper(); | 81 virtual ~PrintWebViewHelper(); |
| 80 | 82 |
| 81 // Prints |frame|. | 83 // Prints |frame|. |
| 82 void PrintFrame(WebKit::WebFrame* frame, | 84 void PrintFrame(WebKit::WebFrame* frame, |
| 83 bool script_initiated, | 85 bool script_initiated, |
| 84 bool is_preview); | 86 bool is_preview); |
| 85 | 87 |
| 86 // Message handlers. Public for testing. | 88 // Message handlers. Public for testing. |
| 87 void OnPrintingDone(int document_cookie, bool success); | 89 void OnPrintingDone(int document_cookie, bool success); |
| 88 void OnPrintForPrintPreview(); | 90 void OnPrintForPrintPreview(const DictionaryValue& job_settings); |
| 89 void OnPrintPages(); | 91 void OnPrintPages(); |
| 90 void OnPrintPreview(); | 92 void OnPrintPreview(); |
| 91 void OnPrintNodeUnderContextMenu(); | 93 void OnPrintNodeUnderContextMenu(); |
| 92 | 94 |
| 93 protected: | 95 protected: |
| 94 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 96 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
| 95 | 97 |
| 96 // Prints the page listed in |params|. | 98 // Prints the page listed in |params|. |
| 97 #if defined(USE_X11) | 99 #if defined(USE_X11) |
| 98 void PrintPage(const ViewMsg_PrintPage_Params& params, | 100 void PrintPage(const ViewMsg_PrintPage_Params& params, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 109 // Prints all the pages listed in |params|. | 111 // Prints all the pages listed in |params|. |
| 110 // It will implicitly revert the document to display CSS media type. | 112 // It will implicitly revert the document to display CSS media type. |
| 111 void PrintPages(const ViewMsg_PrintPages_Params& params, | 113 void PrintPages(const ViewMsg_PrintPages_Params& params, |
| 112 WebKit::WebFrame* frame, | 114 WebKit::WebFrame* frame, |
| 113 WebKit::WebNode* node); | 115 WebKit::WebNode* node); |
| 114 | 116 |
| 115 // WebKit::WebViewClient override: | 117 // WebKit::WebViewClient override: |
| 116 virtual void didStopLoading(); | 118 virtual void didStopLoading(); |
| 117 | 119 |
| 118 private: | 120 private: |
| 121 enum GetSettingsParam { | |
| 122 DEFAULT, | |
| 123 CURRENT, | |
| 124 }; | |
| 125 | |
| 119 static void GetPageSizeAndMarginsInPoints( | 126 static void GetPageSizeAndMarginsInPoints( |
| 120 WebKit::WebFrame* frame, | 127 WebKit::WebFrame* frame, |
| 121 int page_index, | 128 int page_index, |
| 122 const ViewMsg_Print_Params& default_params, | 129 const ViewMsg_Print_Params& default_params, |
| 123 double* content_width_in_points, | 130 double* content_width_in_points, |
| 124 double* content_height_in_points, | 131 double* content_height_in_points, |
| 125 double* margin_top_in_points, | 132 double* margin_top_in_points, |
| 126 double* margin_right_in_points, | 133 double* margin_right_in_points, |
| 127 double* margin_bottom_in_points, | 134 double* margin_bottom_in_points, |
| 128 double* margin_left_in_points); | 135 double* margin_left_in_points); |
| 129 | 136 |
| 130 // RenderViewObserver implementation. | 137 // RenderViewObserver implementation. |
| 131 virtual bool OnMessageReceived(const IPC::Message& message); | 138 virtual bool OnMessageReceived(const IPC::Message& message); |
| 132 | 139 |
| 133 // Common method for OnPrintPages() and OnPrintPreview(). | 140 // Common method for OnPrintPages() and OnPrintPreview(). |
| 134 void OnPrint(bool is_preview); | 141 void OnPrint(bool is_preview); |
| 135 | 142 |
| 136 void PrintNode(WebKit::WebNode* node, | 143 void PrintNode(WebKit::WebNode* node, |
| 137 bool script_initiated, | 144 bool script_initiated, |
| 138 bool is_preview); | 145 bool is_preview); |
| 139 | 146 |
| 140 // Notification when printing is done - signal teardown | 147 // Notification when printing is done - signal teardown |
| 141 void DidFinishPrinting(bool success); | 148 void DidFinishPrinting(bool success); |
| 142 | 149 |
| 150 // Print the pages for print preview. Do not display the native print dialog | |
| 151 // for user settings. Use the current print settings set by the user in | |
| 152 // preview tab. | |
| 153 void PrintForPrintPreview(WebKit::WebFrame* frame, WebKit::WebNode* node); | |
| 154 | |
| 143 void Print(WebKit::WebFrame* frame, | 155 void Print(WebKit::WebFrame* frame, |
| 144 WebKit::WebNode* node, | 156 WebKit::WebNode* node, |
| 145 bool script_initiated, | 157 bool script_initiated, |
| 146 bool is_preview); | 158 bool is_preview); |
| 147 | 159 |
| 148 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, | 160 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, |
| 149 WebKit::WebNode* node, | 161 WebKit::WebNode* node, |
| 150 ViewMsg_Print_Params* params); | 162 ViewMsg_Print_Params* params); |
| 151 | 163 |
| 152 // Initialize print page settings with default settings. | 164 // Initialize print page settings with default settings. |
|
Lei Zhang
2011/03/02 23:28:54
This comment needs to be updated.
kmadhusu
2011/03/04 19:39:02
I reverted my changes to this function. So I didn'
| |
| 153 bool InitPrintSettings(WebKit::WebFrame* frame, | 165 bool InitPrintSettings(WebKit::WebFrame* frame, |
| 154 WebKit::WebNode* node); | 166 WebKit::WebNode* node, |
| 167 GetSettingsParam setting_type); | |
| 155 | 168 |
| 156 // Get the default printer settings. | 169 // Update the current print settings with new |job_settings|. |job_settings| |
| 157 bool GetDefaultPrintSettings(WebKit::WebFrame* frame, | 170 // dictionary contains print job details such as printer name, number of |
| 158 WebKit::WebNode* node, | 171 // copies, page range, etc. |
| 159 ViewMsg_Print_Params* params); | 172 bool UpdatePrintSettings(const DictionaryValue& job_settings); |
| 173 | |
| 174 // Get the print settings. |setting_type| determines whether we need to get | |
| 175 // current settings or default settings. | |
| 176 bool GetPrintSettings(WebKit::WebFrame* frame, | |
| 177 WebKit::WebNode* node, | |
| 178 GetSettingsParam setting_type, | |
| 179 ViewMsg_Print_Params* params); | |
| 160 | 180 |
| 161 // Get final print settings from the user. | 181 // Get final print settings from the user. |
| 162 // Return false if the user cancels or on error. | 182 // Return false if the user cancels or on error. |
| 163 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 183 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 164 int expected_pages_count, | 184 int expected_pages_count, |
| 165 bool use_browser_overlays); | 185 bool use_browser_overlays); |
| 166 | 186 |
| 167 // Render the frame for printing. | 187 // Render the frame for printing. |
| 168 void RenderPagesForPrint(WebKit::WebFrame* frame, | 188 void RenderPagesForPrint(WebKit::WebFrame* frame, |
| 169 WebKit::WebNode* node); | 189 WebKit::WebNode* node); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; | 221 scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_; |
| 202 base::Time last_cancelled_script_print_; | 222 base::Time last_cancelled_script_print_; |
| 203 int user_cancelled_scripted_print_count_; | 223 int user_cancelled_scripted_print_count_; |
| 204 bool is_preview_; | 224 bool is_preview_; |
| 205 | 225 |
| 206 private: | 226 private: |
| 207 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 227 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 208 }; | 228 }; |
| 209 | 229 |
| 210 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 230 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |