diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 20:49:22 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 20:49:22 +0000 |
commit | 6d156893bcf18435440d1ab9668fa66d90cd5dee (patch) | |
tree | 93bdba24b976ce6d420803fc310a2d86e8dd120d | |
parent | d4a66c99465e0e42a75741220171057761ce073e (diff) | |
download | chromium_src-6d156893bcf18435440d1ab9668fa66d90cd5dee.zip chromium_src-6d156893bcf18435440d1ab9668fa66d90cd5dee.tar.gz chromium_src-6d156893bcf18435440d1ab9668fa66d90cd5dee.tar.bz2 |
Printing: Temporary fix on Linux using dummy print settings until we get the entire Linux printing pipeline to match Win/Mac.
BUG=none
TEST=printing works.
Review URL: http://codereview.chromium.org/3619002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61556 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 34 | ||||
-rw-r--r-- | printing/print_settings.cc | 49 | ||||
-rw-r--r-- | printing/print_settings.h | 9 |
3 files changed, 42 insertions, 50 deletions
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index 53e021a..b7fbdb8 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -9,7 +9,6 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "printing/native_metafile.h" -#include "printing/units.h" #include "skia/ext/vector_canvas.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" @@ -18,34 +17,6 @@ using printing::NativeMetafile; using WebKit::WebFrame; using WebKit::WebSize; -static void FillDefaultPrintParams(ViewMsg_Print_Params* params) { - // TODO(myhuang): Get printing parameters via IPC - // using the print_web_view_helper.cc version of Print. - // For testing purpose, we hard-coded printing parameters here. - - // The paper size is US Letter (8.5 in. by 11 in.). - double page_width_in_pixel = 8.5 * printing::kPixelsPerInch; - double page_height_in_pixel = 11.0 * printing::kPixelsPerInch; - params->page_size = gfx::Size( - static_cast<int>(page_width_in_pixel), - static_cast<int>(page_height_in_pixel)); - params->printable_size = gfx::Size( - static_cast<int>( - page_width_in_pixel - - (NativeMetafile::kLeftMarginInInch + - NativeMetafile::kRightMarginInInch) * printing::kPixelsPerInch), - static_cast<int>( - page_height_in_pixel - - (NativeMetafile::kTopMarginInInch + - NativeMetafile::kBottomMarginInInch) * printing::kPixelsPerInch)); - params->margin_top = static_cast<int>( - NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch); - params->margin_left = static_cast<int>( - NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch); - params->dpi = printing::kPixelsPerInch; - params->desired_dpi = params->dpi; -} - void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, WebFrame* frame) { PrepareFrameAndViewForPrint prep_frame_view(params.params, @@ -104,9 +75,6 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame, printing::NativeMetafile* metafile) { - ViewMsg_Print_Params default_params; - FillDefaultPrintParams(&default_params); - double content_width_in_points; double content_height_in_points; double margin_top_in_points; @@ -115,7 +83,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, double margin_left_in_points; GetPageSizeAndMarginsInPoints(frame, params.page_number, - default_params, + params.params, &content_width_in_points, &content_height_in_points, &margin_top_in_points, diff --git a/printing/print_settings.cc b/printing/print_settings.cc index 0950d63..6ab53f6 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,8 @@ // TODO(jhawkins): Move platform-specific implementations to their own files. #if defined(USE_X11) #include <gtk/gtk.h> +#include <gtk/gtkprinter.h> +#include "printing/native_metafile.h" #endif // defined(USE_X11) #include "base/atomic_sequence_num.h" @@ -129,7 +131,7 @@ void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format, printable_area_device_units, 72); } -#elif defined(OS_LINUX) +#elif defined(USE_X11) void PrintSettings::Init(GtkPrintSettings* settings, GtkPageSetup* page_setup, const PageRanges& new_ranges, @@ -140,23 +142,42 @@ void PrintSettings::Init(GtkPrintSettings* settings, printer_name_ = UTF8ToWide(name); device_name_ = printer_name_; ranges = new_ranges; + selection_only = print_selection_only; GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings); landscape_ = orientation == GTK_PAGE_ORIENTATION_LANDSCAPE; - selection_only = print_selection_only; + gfx::Size physical_size_device_units; + gfx::Rect printable_area_device_units; dpi_ = gtk_print_settings_get_resolution(settings); - - // Initialize page_setup_device_units_. - gfx::Size physical_size_device_units( - gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_, - gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_); - gfx::Rect printable_area_device_units( - gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_, - gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_, - gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_, - gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_); - + if (dpi_) { + // Initialize page_setup_device_units_. + physical_size_device_units.SetSize( + gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH) * dpi_, + gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH) * dpi_); + printable_area_device_units.SetRect( + gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH) * dpi_, + gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH) * dpi_, + gtk_page_setup_get_page_width(page_setup, GTK_UNIT_INCH) * dpi_, + gtk_page_setup_get_page_height(page_setup, GTK_UNIT_INCH) * dpi_); + } else { + // Use dummy values if we cannot get valid values. + // TODO(jhawkins) Remove this hack when the Linux printing refactoring + // finishes. + dpi_ = kPixelsPerInch; + double page_width_in_pixel = 8.5 * dpi_; + double page_height_in_pixel = 11.0 * dpi_; + physical_size_device_units.SetSize( + static_cast<int>(page_width_in_pixel), + static_cast<int>(page_height_in_pixel)); + printable_area_device_units.SetRect( + static_cast<int>( + NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch), + static_cast<int>( + NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch), + page_width_in_pixel, + page_height_in_pixel); + } SetPrinterPrintableArea(physical_size_device_units, printable_area_device_units, dpi_); diff --git a/printing/print_settings.h b/printing/print_settings.h index 8cde1ca..a7fe73c 100644 --- a/printing/print_settings.h +++ b/printing/print_settings.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,10 +14,13 @@ #import <ApplicationServices/ApplicationServices.h> #endif +#if defined(OS_WIN) typedef struct HDC__* HDC; typedef struct _devicemodeW DEVMODE; +#elif defined(USE_X11) typedef struct _GtkPrintSettings GtkPrintSettings; typedef struct _GtkPageSetup GtkPageSetup; +#endif namespace printing { @@ -30,7 +33,7 @@ class PrintSettings { // Reinitialize the settings to the default values. void Clear(); -#ifdef WIN32 +#if defined(OS_WIN) // Reads the settings from the selected device context. Calculates derived // values like printable_area_. void Init(HDC hdc, @@ -42,7 +45,7 @@ class PrintSettings { // Reads the settings from the given PMPrinter and PMPageFormat. void Init(PMPrinter printer, PMPageFormat page_format, const PageRanges& new_ranges, bool print_selection_only); -#elif defined(OS_LINUX) +#elif defined(USE_X11) // Initializes the settings from the given GtkPrintSettings and GtkPageSetup. // TODO(jhawkins): This method is a mess across the platforms. Refactor. void Init(GtkPrintSettings* settings, |