diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 02:41:36 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 02:41:36 +0000 |
commit | 089df8eba039306e50da494446c5ea7ee5cdbb54 (patch) | |
tree | 9004aac866cc9652a4c0db3aff384dde9eb3fb15 | |
parent | 42cfd01d0276aadf37c5abe4b9f877d54e9933b7 (diff) | |
download | chromium_src-089df8eba039306e50da494446c5ea7ee5cdbb54.zip chromium_src-089df8eba039306e50da494446c5ea7ee5cdbb54.tar.gz chromium_src-089df8eba039306e50da494446c5ea7ee5cdbb54.tar.bz2 |
Moved chrome/renderer/print* -> chrome/renderer/printing/print*
Moved chrome/renderer/printing/print* in printing namespace.
Review URL: https://chromiumcodereview.appspot.com/12051005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178217 0039d316-1c4b-4281-b951-d872f2087c98
12 files changed, 169 insertions, 155 deletions
diff --git a/chrome/browser/resources/print_preview/previewarea/preview_area.js b/chrome/browser/resources/print_preview/previewarea/preview_area.js index 102b026..44ebc4c 100644 --- a/chrome/browser/resources/print_preview/previewarea/preview_area.js +++ b/chrome/browser/resources/print_preview/previewarea/preview_area.js @@ -409,7 +409,8 @@ cr.define('print_preview', function() { } this.plugin_ = document.createElement('embed'); // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since - // chrome/renderer/print_web_view_helper.cc actually references it. + // chrome/renderer/printing/print_web_view_helper.cc actually references + // it. this.plugin_.setAttribute('id', 'pdf-viewer'); this.plugin_.setAttribute('class', 'preview-area-plugin'); this.plugin_.setAttribute( diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index f4c0948..a39872f 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -223,11 +223,11 @@ 'renderer/prerender/prerender_webmediaplayer.h', 'renderer/prerender/prerenderer_client.cc', 'renderer/prerender/prerenderer_client.h', - 'renderer/print_web_view_helper.cc', - 'renderer/print_web_view_helper.h', - 'renderer/print_web_view_helper_linux.cc', - 'renderer/print_web_view_helper_mac.mm', - 'renderer/print_web_view_helper_win.cc', + 'renderer/printing/print_web_view_helper.cc', + 'renderer/printing/print_web_view_helper.h', + 'renderer/printing/print_web_view_helper_linux.cc', + 'renderer/printing/print_web_view_helper_mac.mm', + 'renderer/printing/print_web_view_helper_win.cc', 'renderer/safe_browsing/feature_extractor_clock.cc', 'renderer/safe_browsing/feature_extractor_clock.h', 'renderer/safe_browsing/features.cc', @@ -328,7 +328,7 @@ 'sources!': [ 'renderer/prerender/prerender_webmediaplayer.cc', 'renderer/prerender/prerender_webmediaplayer.h', - 'renderer/print_web_view_helper.cc', + 'renderer/printing/print_web_view_helper.cc', ], 'defines': [ 'ENABLE_MOBILE_YOUTUBE_PLUGIN', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 5a20956..ad6ecfc 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1312,7 +1312,7 @@ 'renderer/automation/automation_renderer_helper_browsertest.cc', 'renderer/content_settings_observer_browsertest.cc', 'renderer/page_click_tracker_browsertest.cc', - 'renderer/print_web_view_helper_browsertest.cc', + 'renderer/printing/print_web_view_helper_browsertest.cc', 'renderer/safe_browsing/malware_dom_details_browsertest.cc', 'renderer/safe_browsing/phishing_classifier_browsertest.cc', 'renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc', diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 057bda7..d6594fe 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -59,7 +59,7 @@ #include "chrome/renderer/prerender/prerender_helper.h" #include "chrome/renderer/prerender/prerender_webmediaplayer.h" #include "chrome/renderer/prerender/prerenderer_client.h" -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "chrome/renderer/safe_browsing/malware_dom_details.h" #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" #include "chrome/renderer/searchbox/searchbox.h" @@ -287,7 +287,7 @@ void ChromeContentRendererClient::RenderViewCreated( new extensions::ExtensionHelper(render_view, extension_dispatcher_.get()); new PageLoadHistograms(render_view); #if defined(ENABLE_PRINTING) - new PrintWebViewHelper(render_view); + new printing::PrintWebViewHelper(render_view); #endif new SearchBox(render_view); new SpellCheckProvider(render_view, spellcheck_.get()); diff --git a/chrome/renderer/pepper/ppb_pdf_impl.cc b/chrome/renderer/pepper/ppb_pdf_impl.cc index c675bea7..0198b19 100644 --- a/chrome/renderer/pepper/ppb_pdf_impl.cc +++ b/chrome/renderer/pepper/ppb_pdf_impl.cc @@ -10,7 +10,7 @@ #include "build/build_config.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "content/public/common/child_process_sandbox_support_linux.h" #include "content/public/common/content_client.h" #include "content/public/renderer/render_thread.h" @@ -420,6 +420,7 @@ void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { WebKit::WebView* view = element.document().frame()->view(); content::RenderView* render_view = content::RenderView::FromWebView(view); + using printing::PrintWebViewHelper; PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view); if (print_view_helper) print_view_helper->PrintNode(element); diff --git a/chrome/renderer/printing/OWNERS b/chrome/renderer/printing/OWNERS new file mode 100644 index 0000000..f8be0e6 --- /dev/null +++ b/chrome/renderer/printing/OWNERS @@ -0,0 +1,8 @@ +abodenha@chromium.org +dpapad@chromium.org +gene@chromium.org +kmadhusu@chromium.org +scottbyer@chromium.org +thestig@chromium.org +vandebo@chromium.org +vitalybuka@chromium.org diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc index 7e19d09..9a5a487 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/printing/print_web_view_helper.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include <string> @@ -12,8 +12,8 @@ #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/process_util.h" -#include "base/stringprintf.h" #include "base/string_number_conversions.h" +#include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/print_messages.h" @@ -44,6 +44,8 @@ #include "ui/base/resource/resource_bundle.h" #include "webkit/glue/webpreferences.h" +namespace printing { + namespace { const double kMinDpi = 1.0; @@ -66,7 +68,7 @@ int GetDPI(const PrintMsg_Print_Params* print_params) { #if defined(OS_MACOSX) // On the Mac, the printable area is in points, don't do any scaling based // on dpi. - return printing::kPointsPerInch; + return kPointsPerInch; #else return static_cast<int>(print_params->dpi); #endif // defined(OS_MACOSX) @@ -121,8 +123,6 @@ PrintMsg_Print_Params GetCssPrintParams( PrintMsg_Print_Params page_css_params = page_params; int dpi = GetDPI(&page_params); - using printing::ConvertUnit; - using printing::kPixelsPerInch; WebKit::WebSize page_size_in_pixels( ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); @@ -224,7 +224,7 @@ double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, void CalculatePageLayoutFromPrintParams( const PrintMsg_Print_Params& params, - printing::PageSizeMargins* page_layout_in_points) { + PageSizeMargins* page_layout_in_points) { int dpi = GetDPI(¶ms); int content_width = params.content_size.width(); int content_height = params.content_size.height(); @@ -234,8 +234,6 @@ void CalculatePageLayoutFromPrintParams( int margin_right = params.page_size.width() - content_width - params.margin_left; - using printing::ConvertUnit; - using printing::kPointsPerInch; page_layout_in_points->content_width = ConvertUnit(content_width, dpi, kPointsPerInch); page_layout_in_points->content_height = @@ -274,7 +272,6 @@ void ComputeWebKitPrintParamsInDesiredDpi( webkit_print_params->printerDPI = dpi; webkit_print_params->printScalingOption = print_params.print_scaling_option; - using printing::ConvertUnit; webkit_print_params->printContentArea.width = ConvertUnit(print_params.content_size.width(), dpi, print_params.desired_dpi); @@ -328,18 +325,17 @@ bool PrintingFrameHasPageSizeStyle(WebKit::WebFrame* frame, return frame_has_custom_page_size_style; } -printing::MarginType GetMarginsForPdf(WebKit::WebFrame* frame, - const WebKit::WebNode& node) { +MarginType GetMarginsForPdf(WebKit::WebFrame* frame, + const WebKit::WebNode& node) { if (frame->isPrintScalingDisabledForPlugin(node)) - return printing::NO_MARGINS; + return NO_MARGINS; else - return printing::PRINTABLE_AREA_MARGINS; + return PRINTABLE_AREA_MARGINS; } bool FitToPageEnabled(const DictionaryValue& job_settings) { bool fit_to_paper_size = false; - if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled, - &fit_to_paper_size)) { + if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { NOTREACHED(); } return fit_to_paper_size; @@ -406,7 +402,7 @@ void PrintWebViewHelper::PrintHeaderAndFooter( int page_number, int total_pages, float webkit_scale_factor, - const printing::PageSizeMargins& page_layout, + const PageSizeMargins& page_layout, const DictionaryValue& header_footer_info, const PrintMsg_Print_Params& params) { skia::VectorPlatformDeviceSkia* device = @@ -722,7 +718,7 @@ void PrintWebViewHelper::OnPrintForSystemDialog() { } void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( - const printing::PageSizeMargins& page_layout_in_points, + const PageSizeMargins& page_layout_in_points, gfx::Size* page_size, gfx::Rect* content_area) { *page_size = gfx::Size( @@ -741,15 +737,15 @@ void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( void PrintWebViewHelper::UpdateFrameMarginsCssInfo( const DictionaryValue& settings) { int margins_type = 0; - if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) - margins_type = printing::DEFAULT_MARGINS; - ignore_css_margins_ = (margins_type != printing::DEFAULT_MARGINS); + if (!settings.GetInteger(kSettingMarginsType, &margins_type)) + margins_type = DEFAULT_MARGINS; + ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); } bool PrintWebViewHelper::IsPrintToPdfRequested( const DictionaryValue& job_settings) { bool print_to_pdf = false; - if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) + if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) NOTREACHED(); return print_to_pdf; } @@ -828,7 +824,7 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { print_pages_params_->params.supports_alpha_blend = true; bool generate_draft_pages = false; - if (!settings.GetBoolean(printing::kSettingGenerateDraftData, + if (!settings.GetBoolean(kSettingGenerateDraftData, &generate_draft_pages)) { NOTREACHED(); } @@ -851,7 +847,7 @@ bool PrintWebViewHelper::CreatePreviewDocument() { return false; } - printing::PageSizeMargins default_page_layout; + PageSizeMargins default_page_layout; ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, print_params, ignore_css_margins_, NULL, &default_page_layout); @@ -863,8 +859,6 @@ bool PrintWebViewHelper::CreatePreviewDocument() { print_preview_context_.total_page_count()); int dpi = GetDPI(&print_params); - using printing::ConvertUnit; - using printing::kPointsPerInch; gfx::Rect printable_area_in_points( ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch), ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch), @@ -923,7 +917,7 @@ bool PrintWebViewHelper::FinalizePrintReadyDocument() { print_preview_context_.FinalizePrintReadyDocument(); // Get the size of the resulting metafile. - printing::PreviewMetafile* metafile = print_preview_context_.metafile(); + PreviewMetafile* metafile = print_preview_context_.metafile(); uint32 buf_size = metafile->GetDataSize(); DCHECK_GT(buf_size, 0u); @@ -1174,7 +1168,7 @@ void PrintWebViewHelper::ComputePageLayoutInPointsForCss( const PrintMsg_Print_Params& page_params, bool ignore_css_margins, double* scale_factor, - printing::PageSizeMargins* page_layout_in_points) { + PageSizeMargins* page_layout_in_points) { PrintMsg_Print_Params params = CalculatePrintParamsForCss( frame, page_index, page_params, ignore_css_margins, page_params.print_scaling_option == @@ -1274,8 +1268,7 @@ bool PrintWebViewHelper::UpdatePrintSettings( bool source_is_html = true; if (print_for_preview_) { - if (!job_settings->GetBoolean(printing::kSettingPreviewModifiable, - &source_is_html)) { + if (!job_settings->GetBoolean(kSettingPreviewModifiable, &source_is_html)) { NOTREACHED(); } } else { @@ -1284,10 +1277,8 @@ bool PrintWebViewHelper::UpdatePrintSettings( if (print_for_preview_ || !source_is_html) { modified_job_settings.MergeDictionary(job_settings); - modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, - false); - modified_job_settings.SetInteger(printing::kSettingMarginsType, - printing::NO_MARGINS); + modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); + modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); job_settings = &modified_job_settings; } @@ -1326,11 +1317,11 @@ bool PrintWebViewHelper::UpdatePrintSettings( if (!print_for_preview_) { // Validate expected print preview settings. - if (!job_settings->GetInteger(printing::kPreviewUIID, + if (!job_settings->GetInteger(kPreviewUIID, &(settings.params.preview_ui_id)) || - !job_settings->GetInteger(printing::kPreviewRequestID, + !job_settings->GetInteger(kPreviewRequestID, &(settings.params.preview_request_id)) || - !job_settings->GetBoolean(printing::kIsFirstRequest, + !job_settings->GetBoolean(kIsFirstRequest, &(settings.params.is_first_request))) { NOTREACHED(); print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); @@ -1345,11 +1336,11 @@ bool PrintWebViewHelper::UpdatePrintSettings( // Header/Footer: Set |header_footer_info_|. if (settings.params.display_header_footer) { header_footer_info_.reset(new DictionaryValue()); - header_footer_info_->SetString(printing::kSettingHeaderFooterDate, + header_footer_info_->SetString(kSettingHeaderFooterDate, settings.params.date); - header_footer_info_->SetString(printing::kSettingHeaderFooterURL, + header_footer_info_->SetString(kSettingHeaderFooterURL, settings.params.url); - header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, + header_footer_info_->SetString(kSettingHeaderFooterTitle, settings.params.title); } } @@ -1371,7 +1362,7 @@ bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, params.cookie = print_pages_params_->params.document_cookie; params.has_selection = frame->hasSelection(); params.expected_pages_count = expected_pages_count; - printing::MarginType margin_type = printing::DEFAULT_MARGINS; + MarginType margin_type = DEFAULT_MARGINS; if (PrintingNodeOrPdfFrame(frame, node)) margin_type = GetMarginsForPdf(frame, node); params.margin_type = margin_type; @@ -1404,7 +1395,7 @@ bool PrintWebViewHelper::RenderPagesForPrint( #if defined(OS_POSIX) bool PrintWebViewHelper::CopyMetafileDataToSharedMem( - printing::Metafile* metafile, + Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle) { uint32 buf_size = metafile->GetDataSize(); scoped_ptr<base::SharedMemory> shared_buf( @@ -1512,8 +1503,8 @@ bool PrintWebViewHelper::CheckForCancel() { } bool PrintWebViewHelper::PreviewPageRendered(int page_number, - printing::Metafile* metafile) { - DCHECK_GE(page_number, printing::FIRST_PAGE_INDEX); + Metafile* metafile) { + DCHECK_GE(page_number, FIRST_PAGE_INDEX); // For non-modifiable files, |metafile| should be NULL, so do not bother // sending a message. If we don't generate draft metafiles, |metafile| is @@ -1594,7 +1585,7 @@ bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( DCHECK_EQ(INITIALIZED, state_); state_ = RENDERING; - metafile_.reset(new printing::PreviewMetafile); + metafile_.reset(new PreviewMetafile); if (!metafile_->Init()) { set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); LOG(ERROR) << "PreviewMetafile Init failed"; @@ -1751,7 +1742,7 @@ bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const { return generate_draft_pages_; } -printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { +PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { DCHECK(IsRendering()); return metafile_.get(); } @@ -1771,3 +1762,5 @@ void PrintWebViewHelper::PrintPreviewContext::ClearContext() { pages_to_render_.clear(); error_ = PREVIEW_ERROR_NONE; } + +} // namespace printing diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/printing/print_web_view_helper.h index c71373a..95b4604 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/printing/print_web_view_helper.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ -#define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ +#ifndef CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ +#define CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ #include <vector> @@ -29,15 +29,15 @@ namespace base { class DictionaryValue; } -namespace printing { -struct PageSizeMargins; -} - namespace WebKit { class WebFrame; class WebView; } +namespace printing { + +struct PageSizeMargins; + // Class that calls the Begin and End print functions on the frame and changes // the size of the view temporarily to support full page printing.. // Do not serve any events in the time between construction and destruction of @@ -154,7 +154,7 @@ class PrintWebViewHelper // Get |page_size| and |content_area| information from // |page_layout_in_points|. void GetPageSizeAndContentAreaFromPageLayout( - const printing::PageSizeMargins& page_layout_in_points, + const PageSizeMargins& page_layout_in_points, gfx::Size* page_size, gfx::Rect* content_area); @@ -260,7 +260,7 @@ class PrintWebViewHelper void PrintPageInternal(const PrintMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebKit::WebFrame* frame, - printing::Metafile* metafile); + Metafile* metafile); #else void PrintPageInternal(const PrintMsg_PrintPage_Params& params, const gfx::Size& canvas_size, @@ -277,20 +277,20 @@ class PrintWebViewHelper int page_number, WebKit::WebFrame* frame, bool is_preview, - printing::Metafile* metafile, + Metafile* metafile, double* scale_factor, gfx::Size* page_size_in_dpi, gfx::Rect* content_area_in_dpi); #elif defined(OS_MACOSX) void RenderPage(const PrintMsg_Print_Params& params, int page_number, WebKit::WebFrame* frame, bool is_preview, - printing::Metafile* metafile, gfx::Size* page_size, + Metafile* metafile, gfx::Size* page_size, gfx::Rect* content_rect); #elif defined(OS_POSIX) bool RenderPages(const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame, const WebKit::WebNode& node, std::vector<int>* printed_pages, - printing::Metafile* metafile); + Metafile* metafile); #endif // defined(OS_WIN) // Renders page contents from |frame| to |content_area| of |canvas|. @@ -308,7 +308,7 @@ class PrintWebViewHelper bool CopyAndPrint(WebKit::WebFrame* web_frame); - bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, + bool CopyMetafileDataToSharedMem(Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle); // Helper method to get page layout in points and fit to page if needed. @@ -318,7 +318,7 @@ class PrintWebViewHelper const PrintMsg_Print_Params& default_params, bool ignore_css_margins, double* scale_factor, - printing::PageSizeMargins* page_layout_in_points); + PageSizeMargins* page_layout_in_points); // Prepare the frame and view for print and then call this function to honor // the CSS page layout information. @@ -336,7 +336,7 @@ class PrintWebViewHelper int page_number, int total_pages, float webkit_scale_factor, - const printing::PageSizeMargins& page_layout_in_points, + const PageSizeMargins& page_layout_in_points, const base::DictionaryValue& header_footer_info, const PrintMsg_Print_Params& params); @@ -375,7 +375,7 @@ class PrintWebViewHelper // For a valid |page_number| with modifiable content, // |metafile| is the rendered page. Otherwise |metafile| is NULL. // Returns true if print preview should continue, false on failure. - bool PreviewPageRendered(int page_number, printing::Metafile* metafile); + bool PreviewPageRendered(int page_number, Metafile* metafile); // WebView used only to print the selection. WebKit::WebView* print_web_view_; @@ -455,7 +455,7 @@ class PrintWebViewHelper const WebKit::WebNode& node() const; int total_page_count() const; bool generate_draft_pages() const; - printing::PreviewMetafile* metafile(); + PreviewMetafile* metafile(); gfx::Size GetPrintCanvasSize() const; int last_error() const; @@ -475,7 +475,7 @@ class PrintWebViewHelper WebKit::WebNode node_; scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; - scoped_ptr<printing::PreviewMetafile> metafile_; + scoped_ptr<PreviewMetafile> metafile_; // Total page count in the renderer. int total_page_count_; @@ -505,4 +505,6 @@ class PrintWebViewHelper DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); }; -#endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ +} // namespace printing + +#endif // CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/printing/print_web_view_helper_browsertest.cc index 3e88799..a3e60ac 100644 --- a/chrome/renderer/print_web_view_helper_browsertest.cc +++ b/chrome/renderer/printing/print_web_view_helper_browsertest.cc @@ -6,7 +6,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/print_messages.h" #include "chrome/renderer/mock_printer.h" -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "chrome/test/base/chrome_render_view_test.h" #include "content/public/renderer/render_view.h" #include "printing/print_job_constants.h" @@ -23,6 +23,8 @@ using WebKit::WebFrame; using WebKit::WebString; #endif +namespace printing { + namespace { // A simple web page. @@ -71,20 +73,20 @@ const char kPrintPreviewHTML[] = "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; void CreatePrintSettingsDictionary(DictionaryValue* dict) { - dict->SetBoolean(printing::kSettingLandscape, false); - dict->SetBoolean(printing::kSettingCollate, false); - dict->SetInteger(printing::kSettingColor, printing::GRAY); - dict->SetBoolean(printing::kSettingPrintToPDF, true); - dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); - dict->SetInteger(printing::kSettingCopies, 1); - dict->SetString(printing::kSettingDeviceName, "dummy"); - dict->SetInteger(printing::kPreviewUIID, 4); - dict->SetInteger(printing::kPreviewRequestID, 12345); - dict->SetBoolean(printing::kIsFirstRequest, true); - dict->SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); - dict->SetBoolean(printing::kSettingPreviewModifiable, false); - dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); - dict->SetBoolean(printing::kSettingGenerateDraftData, true); + dict->SetBoolean(kSettingLandscape, false); + dict->SetBoolean(kSettingCollate, false); + dict->SetInteger(kSettingColor, GRAY); + dict->SetBoolean(kSettingPrintToPDF, true); + dict->SetInteger(kSettingDuplexMode, SIMPLEX); + dict->SetInteger(kSettingCopies, 1); + dict->SetString(kSettingDeviceName, "dummy"); + dict->SetInteger(kPreviewUIID, 4); + dict->SetInteger(kPreviewRequestID, 12345); + dict->SetBoolean(kIsFirstRequest, true); + dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS); + dict->SetBoolean(kSettingPreviewModifiable, false); + dict->SetBoolean(kSettingHeaderFooterEnabled, false); + dict->SetBoolean(kSettingGenerateDraftData, true); } } // namespace @@ -286,7 +288,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithIframe) { // Verify output through MockPrinter. const MockPrinter* printer(chrome_render_thread_->printer()); ASSERT_EQ(1, printer->GetPrintedPages()); - const printing::Image& image1(printer->GetPrintedPage(0)->image()); + const Image& image1(printer->GetPrintedPage(0)->image()); // TODO(sverrir): Figure out a way to improve this test to actually print // only the content of the iframe. Currently image1 will contain the full @@ -531,8 +533,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHTMLWithPageMarginsCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, false); - dict.SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, false); + dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -551,8 +553,8 @@ TEST_F(PrintWebViewHelperPreviewTest, NonDefaultMarginsSelectedIgnorePrintCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, false); - dict.SetInteger(printing::kSettingMarginsType, printing::NO_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, false); + dict.SetInteger(kSettingMarginsType, NO_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -571,9 +573,9 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPrintCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, true); - dict.SetInteger(printing::kSettingMarginsType, - printing::PRINTABLE_AREA_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, true); + dict.SetInteger(kSettingMarginsType, + PRINTABLE_AREA_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -604,8 +606,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorPageMarginsCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, true); - dict.SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, true); + dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -624,8 +626,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewCenterToFitPage) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, false); - dict.SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, false); + dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -654,8 +656,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, false); - dict.SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, false); + dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -672,8 +674,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, false); - dict.SetInteger(printing::kSettingMarginsType, printing::NO_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, false); + dict.SetInteger(kSettingMarginsType, NO_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -690,8 +692,8 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorOrientationCss) { // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); - dict.SetBoolean(printing::kSettingPrintToPDF, true); - dict.SetInteger(printing::kSettingMarginsType, printing::CUSTOM_MARGINS); + dict.SetBoolean(kSettingPrintToPDF, true); + dict.SetInteger(kSettingMarginsType, CUSTOM_MARGINS); OnPrintPreview(dict); EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); @@ -713,14 +715,14 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { // metafile with the selected pages. Page numbers used in the dictionary // are 1-based. DictionaryValue* page_range = new DictionaryValue(); - page_range->SetInteger(printing::kSettingPageRangeFrom, 1); - page_range->SetInteger(printing::kSettingPageRangeTo, 1); + page_range->SetInteger(kSettingPageRangeFrom, 1); + page_range->SetInteger(kSettingPageRangeTo, 1); ListValue* page_range_array = new ListValue(); page_range_array->Append(page_range); - dict.Set(printing::kSettingPageRange, page_range_array); - dict.SetBoolean(printing::kSettingGenerateDraftData, false); + dict.Set(kSettingPageRange, page_range_array); + dict.SetBoolean(kSettingGenerateDraftData, false); OnPrintPreview(dict); @@ -913,3 +915,5 @@ TEST_F(PrintWebViewHelperKioskTest, DontBlockScriptInitiatedPrinting) { LoadHTML(kPrintWithJSHTML); VerifyPagesPrinted(true); } + +} // namespace printing diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/printing/print_web_view_helper_linux.cc index d7cd691..961fed6 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/printing/print_web_view_helper_linux.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "base/file_descriptor_posix.h" #include "base/logging.h" @@ -22,6 +22,8 @@ #include "base/process_util.h" #endif // !defined(OS_CHROMEOS) +namespace printing { + using WebKit::WebFrame; using WebKit::WebNode; @@ -31,11 +33,10 @@ bool PrintWebViewHelper::RenderPreviewPage( PrintMsg_PrintPage_Params page_params; page_params.params = print_params; page_params.page_number = page_number; - scoped_ptr<printing::Metafile> draft_metafile; - printing::Metafile* initial_render_metafile = - print_preview_context_.metafile(); + scoped_ptr<Metafile> draft_metafile; + Metafile* initial_render_metafile = print_preview_context_.metafile(); if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { - draft_metafile.reset(new printing::PreviewMetafile); + draft_metafile.reset(new PreviewMetafile); initial_render_metafile = draft_metafile.get(); } @@ -57,7 +58,7 @@ bool PrintWebViewHelper::RenderPreviewPage( } bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { - printing::NativeMetafile metafile; + NativeMetafile metafile; if (!metafile.Init()) return false; @@ -124,7 +125,7 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame, const WebKit::WebNode& node, std::vector<int>* printed_pages, - printing::Metafile* metafile) { + Metafile* metafile) { PrepareFrameAndViewForPrint prepare(params.params, frame, node); PrintMsg_Print_Params print_params = params.params; UpdateFrameAndViewFromCssPageLayout(frame, node, &prepare, print_params, @@ -173,8 +174,8 @@ void PrintWebViewHelper::PrintPageInternal( const PrintMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame, - printing::Metafile* metafile) { - printing::PageSizeMargins page_layout_in_points; + Metafile* metafile) { + PageSizeMargins page_layout_in_points; double scale_factor = 1.0f; ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, ignore_css_margins_, &scale_factor, @@ -195,7 +196,7 @@ void PrintWebViewHelper::PrintPageInternal( // can't be a stack object. skia::RefPtr<skia::VectorCanvas> canvas = skia::AdoptRef(new skia::VectorCanvas(device)); - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); + MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); if (params.params.display_header_footer) { @@ -214,3 +215,5 @@ void PrintWebViewHelper::PrintPageInternal( if (!metafile->FinishPage()) NOTREACHED() << "metafile failed"; } + +} // namespace printing diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/printing/print_web_view_helper_mac.mm index 3d02052..924860f 100644 --- a/chrome/renderer/print_web_view_helper_mac.mm +++ b/chrome/renderer/printing/print_web_view_helper_mac.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #import <AppKit/AppKit.h> @@ -19,13 +19,15 @@ #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +namespace printing { + using WebKit::WebFrame; void PrintWebViewHelper::PrintPageInternal( const PrintMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame) { - printing::NativeMetafile metafile; + NativeMetafile metafile; if (!metafile.Init()) return; @@ -56,15 +58,14 @@ bool PrintWebViewHelper::RenderPreviewPage( int page_number, const PrintMsg_Print_Params& print_params) { PrintMsg_Print_Params printParams = print_params; - scoped_ptr<printing::Metafile> draft_metafile; - printing::Metafile* initial_render_metafile = - print_preview_context_.metafile(); + scoped_ptr<Metafile> draft_metafile; + Metafile* initial_render_metafile = print_preview_context_.metafile(); bool render_to_draft = print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_; if (render_to_draft) { - draft_metafile.reset(new printing::PreviewMetafile()); + draft_metafile.reset(new PreviewMetafile()); if (!draft_metafile->Init()) { print_preview_context_.set_error( PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED); @@ -96,11 +97,11 @@ bool PrintWebViewHelper::RenderPreviewPage( void PrintWebViewHelper::RenderPage( const PrintMsg_Print_Params& params, int page_number, WebFrame* frame, - bool is_preview, printing::Metafile* metafile, gfx::Size* page_size, + bool is_preview, Metafile* metafile, gfx::Size* page_size, gfx::Rect* content_rect) { double scale_factor = 1.0f; double webkit_shrink_factor = frame->getPrintPageShrink(page_number); - printing::PageSizeMargins page_layout_in_points; + PageSizeMargins page_layout_in_points; gfx::Rect content_area; ComputePageLayoutInPointsForCss(frame, page_number, params, @@ -125,7 +126,7 @@ void PrintWebViewHelper::RenderPage( skia::RefPtr<skia::VectorCanvas> canvas = skia::AdoptRef(new skia::VectorCanvas(device)); WebKit::WebCanvas* canvas_ptr = canvas.get(); - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); + MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); skia::SetIsPreviewMetafile(*canvas, is_preview); @@ -142,3 +143,5 @@ void PrintWebViewHelper::RenderPage( // Done printing. Close the device context to retrieve the compiled metafile. metafile->FinishPage(); } + +} // namespace printing diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/printing/print_web_view_helper_win.cc index 8968308..f43be00 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/printing/print_web_view_helper_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -26,10 +26,8 @@ #include "ui/gfx/rect.h" #include "ui/gfx/size.h" -using printing::ConvertUnit; -using printing::ConvertUnitDouble; -using printing::kPointsPerInch; -using printing::Metafile; +namespace printing { + using WebKit::WebFrame; void PrintWebViewHelper::PrintPageInternal( @@ -38,7 +36,7 @@ void PrintWebViewHelper::PrintPageInternal( WebFrame* frame) { // Generate a memory-based metafile. It will use the current screen's DPI. // Each metafile contains a single page. - scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); + scoped_ptr<NativeMetafile> metafile(new NativeMetafile); metafile->Init(); DCHECK(metafile->context()); skia::InitializeDC(metafile->context()); @@ -63,7 +61,7 @@ void PrintWebViewHelper::PrintPageInternal( NOTREACHED(); if (!params.params.supports_alpha_blend && metafile->IsAlphaBlendUsed()) { - scoped_ptr<printing::NativeMetafile> raster_metafile( + scoped_ptr<NativeMetafile> raster_metafile( metafile->RasterizeAlphaBlend()); if (raster_metafile.get()) metafile.swap(raster_metafile); @@ -97,11 +95,10 @@ bool PrintWebViewHelper::RenderPreviewPage( double actual_shrink = static_cast<float>(print_params.desired_dpi / print_params.dpi); scoped_ptr<Metafile> draft_metafile; - printing::Metafile* initial_render_metafile = - print_preview_context_.metafile(); + Metafile* initial_render_metafile = print_preview_context_.metafile(); if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { - draft_metafile.reset(new printing::PreviewMetafile); + draft_metafile.reset(new PreviewMetafile); initial_render_metafile = draft_metafile.get(); } @@ -126,7 +123,7 @@ void PrintWebViewHelper::RenderPage( const PrintMsg_Print_Params& params, int page_number, WebFrame* frame, bool is_preview, Metafile* metafile, double* actual_shrink, gfx::Size* page_size_in_dpi, gfx::Rect* content_area_in_dpi) { - printing::PageSizeMargins page_layout_in_points; + PageSizeMargins page_layout_in_points; double css_scale_factor = 1.0f; ComputePageLayoutInPointsForCss(frame, page_number, params, ignore_css_margins_, &css_scale_factor, @@ -139,22 +136,22 @@ void PrintWebViewHelper::RenderPage( // Calculate the actual page size and content area in dpi. if (page_size_in_dpi) { *page_size_in_dpi = gfx::Size( - static_cast<int>(ConvertUnitDouble( - page_size.width(), printing::kPointsPerInch, dpi)), - static_cast<int>(ConvertUnitDouble( - page_size.height(), printing::kPointsPerInch, dpi))); + static_cast<int>(ConvertUnitDouble(page_size.width(), kPointsPerInch, + dpi)), + static_cast<int>(ConvertUnitDouble(page_size.height(), kPointsPerInch, + dpi))); } if (content_area_in_dpi) { *content_area_in_dpi = gfx::Rect( - static_cast<int>(ConvertUnitDouble(content_area.x(), - printing::kPointsPerInch, dpi)), - static_cast<int>(ConvertUnitDouble(content_area.y(), - printing::kPointsPerInch, dpi)), - static_cast<int>(ConvertUnitDouble(content_area.width(), - printing::kPointsPerInch, dpi)), + static_cast<int>(ConvertUnitDouble(content_area.x(), kPointsPerInch, + dpi)), + static_cast<int>(ConvertUnitDouble(content_area.y(), kPointsPerInch, + dpi)), + static_cast<int>(ConvertUnitDouble(content_area.width(), kPointsPerInch, + dpi)), static_cast<int>(ConvertUnitDouble(content_area.height(), - printing::kPointsPerInch, dpi))); + kPointsPerInch, dpi))); } if (!is_preview) { @@ -183,7 +180,7 @@ void PrintWebViewHelper::RenderPage( skia::AdoptRef(new skia::VectorCanvas(device)); if (is_preview) { - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); + MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); skia::SetIsPreviewMetafile(*canvas, is_preview); } @@ -208,7 +205,7 @@ void PrintWebViewHelper::RenderPage( // TODO(gene): We should revisit this solution for the next versions. // Consider creating metafile of the right size (or resizable) // https://code.google.com/p/chromium/issues/detail?id=126037 - if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas( + if (!MetafileSkiaWrapper::GetCustomScaleOnCanvas( *canvas, actual_shrink)) { // Update the dpi adjustment with the "page |actual_shrink|" calculated in // webkit. @@ -224,7 +221,7 @@ bool PrintWebViewHelper::CopyMetafileDataToSharedMem( Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle) { uint32 buf_size = metafile->GetDataSize(); base::SharedMemory shared_buf; - if (buf_size >= printing::kMetafileMaxSize) { + if (buf_size >= kMetafileMaxSize) { NOTREACHED() << "Buffer too large: " << buf_size; return false; } @@ -248,3 +245,5 @@ bool PrintWebViewHelper::CopyMetafileDataToSharedMem( shared_mem_handle)); return true; } + +} // namespace printing |