diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 21:58:29 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 21:58:29 +0000 |
commit | 8cbb6b72aaa5a36b823fb870639385a20b55a3d8 (patch) | |
tree | 41956afd03569cdaf1ee84126ced39ae197bbc77 /chrome/renderer | |
parent | 7d01ba27a7511698989bf018c5d8979d5942b13b (diff) | |
download | chromium_src-8cbb6b72aaa5a36b823fb870639385a20b55a3d8.zip chromium_src-8cbb6b72aaa5a36b823fb870639385a20b55a3d8.tar.gz chromium_src-8cbb6b72aaa5a36b823fb870639385a20b55a3d8.tar.bz2 |
Printing: Reorganize PrintWebViewHelper some more.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6612060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 56 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.h | 131 |
2 files changed, 91 insertions, 96 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 85eb7f1..d348b6b 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -118,12 +118,6 @@ void PrintWebViewHelper::PrintFrame(WebFrame* frame, Print(frame, NULL, script_initiated, is_preview); } -void PrintWebViewHelper::PrintNode(WebNode* node, - bool script_initiated, - bool is_preview) { - Print(node->document().frame(), node, script_initiated, is_preview); -} - bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) @@ -214,7 +208,7 @@ void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { // Make a copy of the node, since we will do a sync call to the browser and // during that time OnContextMenuClosed might reset context_menu_node_. WebNode context_menu_node(render_view()->context_menu_node()); - PrintNode(&context_menu_node, false, false); + Print(context_menu_node.document().frame(), &context_menu_node, false, false); } void PrintWebViewHelper::Print(WebKit::WebFrame* frame, @@ -487,51 +481,43 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame, WebNode* node) { ViewMsg_PrintPages_Params settings; - if (GetDefaultPrintSettings(frame, node, &settings.params)) { - print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); - print_pages_params_->pages.clear(); - return true; - } - return false; -} - -bool PrintWebViewHelper::UpdatePrintSettings( - const DictionaryValue& job_settings) { - ViewMsg_PrintPages_Params settings; - if (!render_view()->Send(new ViewHostMsg_UpdatePrintSettings( - render_view()->routing_id(), - print_pages_params_->params.document_cookie, - job_settings, &settings))) { - NOTREACHED(); - return false; - } - print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); - return true; -} -bool PrintWebViewHelper::GetDefaultPrintSettings(WebFrame* frame, - WebNode* node, - ViewMsg_Print_Params* params) { if (!render_view()->Send(new ViewHostMsg_GetDefaultPrintSettings( - render_view()->routing_id(), params))) { + render_view()->routing_id(), &settings.params))) { NOTREACHED(); return false; } // Check if the printer returned any settings, if the settings is empty, we // can safely assume there are no printer drivers configured. So we safely // terminate. - if (params->IsEmpty()) { + if (settings.params.IsEmpty()) { render_view()->runModalAlertDialog( frame, l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); return false; } - if (!(params->dpi && params->document_cookie)) { + if (!settings.params.dpi || !settings.params.document_cookie) { // Invalid print page settings. NOTREACHED(); return false; } - UpdatePrintableSizeInPrintParameters(frame, node, params); + UpdatePrintableSizeInPrintParameters(frame, node, &settings.params); + settings.pages.clear(); + print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); + return true; +} + +bool PrintWebViewHelper::UpdatePrintSettings( + const DictionaryValue& job_settings) { + ViewMsg_PrintPages_Params settings; + if (!render_view()->Send(new ViewHostMsg_UpdatePrintSettings( + render_view()->routing_id(), + print_pages_params_->params.document_cookie, + job_settings, &settings))) { + NOTREACHED(); + return false; + } + print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); return true; } diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 51b98ea..29b79b95 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -17,10 +17,6 @@ class DictionaryValue; -namespace gfx { -class Size; -} - #if defined(USE_X11) namespace skia { class VectorCanvas; @@ -85,75 +81,52 @@ class PrintWebViewHelper : public RenderViewObserver , bool script_initiated, bool is_preview); - // Message handlers. Public for testing. - void OnPrintingDone(int document_cookie, bool success); - - // Print the pages for print preview. Do not display the native print dialog - // for user settings. |job_settings| has new print job settings values. - void OnPrintForPrintPreview(const DictionaryValue& job_settings); - - void OnPrintPages(); - void OnPrintPreview(); - void OnPrintNodeUnderContextMenu(); - protected: - bool CopyAndPrint(WebKit::WebFrame* web_frame); - - // Prints the page listed in |params|. -#if defined(USE_X11) - void PrintPage(const ViewMsg_PrintPage_Params& params, - const gfx::Size& canvas_size, - WebKit::WebFrame* frame, - printing::NativeMetafile* metafile, - scoped_ptr<skia::VectorCanvas>* canvas); -#else - void PrintPage(const ViewMsg_PrintPage_Params& params, - const gfx::Size& canvas_size, - WebKit::WebFrame* frame); -#endif - - // Prints all the pages listed in |params|. - // It will implicitly revert the document to display CSS media type. - void PrintPages(const ViewMsg_PrintPages_Params& params, - WebKit::WebFrame* frame, - WebKit::WebNode* node); - // WebKit::WebViewClient override: virtual void didStopLoading(); private: - static void GetPageSizeAndMarginsInPoints( - WebKit::WebFrame* frame, - int page_index, - const ViewMsg_Print_Params& default_params, - double* content_width_in_points, - double* content_height_in_points, - double* margin_top_in_points, - double* margin_right_in_points, - double* margin_bottom_in_points, - double* margin_left_in_points); + friend class RenderViewTest_OnPrintPages_Test; + +#if defined(OS_WIN) + friend class RenderViewTest_DISABLED_PrintLayoutTest_Test; +#elif defined(OS_MACOSX) + friend class RenderViewTest_PrintLayoutTest_Test; +#endif // defined(OS_WIN) + +#if defined(OS_WIN) || defined(OS_MACOSX) + friend class RenderViewTest_PrintWithIframe_Test; +#endif // defined(OS_WIN) || defined(OS_MACOSX) // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message); + // Message handlers --------------------------------------------------------- + + void OnPrintPages(); + void OnPrintNodeUnderContextMenu(); + void OnPrintPreview(); + + // Print the pages for print preview. Do not display the native print dialog + // for user settings. |job_settings| has new print job settings values. + void OnPrintForPrintPreview(const DictionaryValue& job_settings); + + void OnPrintingDone(int document_cookie, bool success); + // Common method for OnPrintPages() and OnPrintPreview(). void OnPrint(bool is_preview); - void PrintNode(WebKit::WebNode* node, - bool script_initiated, - bool is_preview); - - // Notification when printing is done - signal teardown - void DidFinishPrinting(bool success); + // Main printing code ------------------------------------------------------- void Print(WebKit::WebFrame* frame, WebKit::WebNode* node, bool script_initiated, bool is_preview); - void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, - WebKit::WebNode* node, - ViewMsg_Print_Params* params); + // Notification when printing is done - signal teardown. + void DidFinishPrinting(bool success); + + // Print Settings ----------------------------------------------------------- // Initialize print page settings with default settings. bool InitPrintSettings(WebKit::WebFrame* frame, @@ -164,17 +137,33 @@ class PrintWebViewHelper : public RenderViewObserver , // copies, page range, etc. bool UpdatePrintSettings(const DictionaryValue& job_settings); - // Get the default printer settings. - bool GetDefaultPrintSettings(WebKit::WebFrame* frame, - WebKit::WebNode* node, - ViewMsg_Print_Params* params); - // Get final print settings from the user. // Return false if the user cancels or on error. bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, int expected_pages_count, bool use_browser_overlays); + // Page Printing / Rendering ------------------------------------------------ + + // Prints all the pages listed in |params|. + // It will implicitly revert the document to display CSS media type. + void PrintPages(const ViewMsg_PrintPages_Params& params, + WebKit::WebFrame* frame, + WebKit::WebNode* node); + + // Prints the page listed in |params|. +#if defined(USE_X11) + void PrintPage(const ViewMsg_PrintPage_Params& params, + const gfx::Size& canvas_size, + WebKit::WebFrame* frame, + printing::NativeMetafile* metafile, + scoped_ptr<skia::VectorCanvas>* canvas); +#else + void PrintPage(const ViewMsg_PrintPage_Params& params, + const gfx::Size& canvas_size, + WebKit::WebFrame* frame); +#endif + // Render the frame for printing. void RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); @@ -205,9 +194,30 @@ class PrintWebViewHelper : public RenderViewObserver , printing::NativeMetafile* metafile); #endif // defined(OS_WIN) + // Helper methods ----------------------------------------------------------- + + bool CopyAndPrint(WebKit::WebFrame* web_frame); + bool CopyMetafileDataToSharedMem(printing::NativeMetafile* metafile, base::SharedMemoryHandle* shared_mem_handle); + static void GetPageSizeAndMarginsInPoints( + WebKit::WebFrame* frame, + int page_index, + const ViewMsg_Print_Params& default_params, + double* content_width_in_points, + double* content_height_in_points, + double* margin_top_in_points, + double* margin_right_in_points, + double* margin_bottom_in_points, + double* margin_left_in_points); + + void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, + WebKit::WebNode* node, + ViewMsg_Print_Params* params); + + // Script Initiated Printing ------------------------------------------------ + // Returns true if script initiated printing occurs too often. bool IsScriptInitiatedPrintTooFrequent(WebKit::WebFrame* frame); @@ -224,7 +234,6 @@ class PrintWebViewHelper : public RenderViewObserver , base::Time last_cancelled_script_print_; int user_cancelled_scripted_print_count_; - private: DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); }; |