summaryrefslogtreecommitdiffstats
path: root/printing/print_settings.cc
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 17:57:52 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 17:57:52 +0000
commit4993f34cdf20cf9e1124656164e2c647efba6989 (patch)
tree272b55c8054c6a79444efafe55ad2311e89fa5dd /printing/print_settings.cc
parentcaf706f870d1d9d576277110ab1df022b2756203 (diff)
downloadchromium_src-4993f34cdf20cf9e1124656164e2c647efba6989.zip
chromium_src-4993f34cdf20cf9e1124656164e2c647efba6989.tar.gz
chromium_src-4993f34cdf20cf9e1124656164e2c647efba6989.tar.bz2
Printing: Refactor PrintSettings::Init into a PrintSettingsFactory class
per-platform. BUG=none TEST=none Review URL: http://codereview.chromium.org/4040001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/print_settings.cc')
-rw-r--r--printing/print_settings.cc146
1 files changed, 0 insertions, 146 deletions
diff --git a/printing/print_settings.cc b/printing/print_settings.cc
index 6ab53f6..cf8c50a 100644
--- a/printing/print_settings.cc
+++ b/printing/print_settings.cc
@@ -4,18 +4,7 @@
#include "printing/print_settings.h"
-// 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"
-#include "base/logging.h"
-#include "base/string_piece.h"
-#include "base/sys_string_conversions.h"
-#include "base/utf_string_conversions.h"
#include "printing/units.h"
namespace printing {
@@ -49,141 +38,6 @@ void PrintSettings::Clear() {
landscape_ = false;
}
-#if defined(OS_WIN)
-void PrintSettings::Init(HDC hdc,
- const DEVMODE& dev_mode,
- const PageRanges& new_ranges,
- const std::wstring& new_device_name,
- bool print_selection_only) {
- DCHECK(hdc);
- printer_name_ = dev_mode.dmDeviceName;
- device_name_ = new_device_name;
- ranges = new_ranges;
- landscape_ = dev_mode.dmOrientation == DMORIENT_LANDSCAPE;
- selection_only = print_selection_only;
-
- dpi_ = GetDeviceCaps(hdc, LOGPIXELSX);
- // No printer device is known to advertise different dpi in X and Y axis; even
- // the fax device using the 200x100 dpi setting. It's ought to break so many
- // applications that it's not even needed to care about. WebKit doesn't
- // support different dpi settings in X and Y axis.
- DCHECK_EQ(dpi_, GetDeviceCaps(hdc, LOGPIXELSY));
-
- DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
- DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
-
- // Initialize page_setup_device_units_.
- gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
- GetDeviceCaps(hdc, PHYSICALHEIGHT));
- gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
- GetDeviceCaps(hdc, PHYSICALOFFSETY),
- GetDeviceCaps(hdc, HORZRES),
- GetDeviceCaps(hdc, VERTRES));
-
- SetPrinterPrintableArea(physical_size_device_units,
- printable_area_device_units,
- dpi_);
-}
-#elif defined(OS_MACOSX)
-void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format,
- const PageRanges& new_ranges,
- bool print_selection_only) {
- printer_name_ = base::SysCFStringRefToWide(PMPrinterGetName(printer));
- device_name_ = base::SysCFStringRefToWide(PMPrinterGetID(printer));
- ranges = new_ranges;
- PMOrientation orientation = kPMPortrait;
- PMGetOrientation(page_format, &orientation);
- landscape_ = orientation == kPMLandscape;
- selection_only = print_selection_only;
-
- UInt32 resolution_count = 0;
- PMResolution best_resolution = { 72.0, 72.0 };
- OSStatus status = PMPrinterGetPrinterResolutionCount(printer,
- &resolution_count);
- if (status == noErr) {
- // Resolution indexes are 1-based.
- for (uint32 i = 1; i <= resolution_count; ++i) {
- PMResolution resolution;
- PMPrinterGetIndexedPrinterResolution(printer, i, &resolution);
- if (resolution.hRes > best_resolution.hRes)
- best_resolution = resolution;
- }
- }
- dpi_ = best_resolution.hRes;
- // See comment in the Windows code above.
- DCHECK_EQ(dpi_, best_resolution.vRes);
-
- // Get printable area and paper rects (in points)
- PMRect page_rect, paper_rect;
- PMGetAdjustedPageRect(page_format, &page_rect);
- PMGetAdjustedPaperRect(page_format, &paper_rect);
- // Device units are in points. Units per inch is 72.
- gfx::Size physical_size_device_units(
- (paper_rect.right - paper_rect.left),
- (paper_rect.bottom - paper_rect.top));
- gfx::Rect printable_area_device_units(
- (page_rect.left - paper_rect.left),
- (page_rect.top - paper_rect.top),
- (page_rect.right - page_rect.left),
- (page_rect.bottom - page_rect.top));
-
- SetPrinterPrintableArea(physical_size_device_units,
- printable_area_device_units,
- 72);
-}
-#elif defined(USE_X11)
-void PrintSettings::Init(GtkPrintSettings* settings,
- GtkPageSetup* page_setup,
- const PageRanges& new_ranges,
- bool print_selection_only) {
- // TODO(jhawkins): |printer_name_| and |device_name_| should be string16.
- base::StringPiece name(
- reinterpret_cast<const char*>(gtk_print_settings_get_printer(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;
-
- gfx::Size physical_size_device_units;
- gfx::Rect printable_area_device_units;
- dpi_ = gtk_print_settings_get_resolution(settings);
- 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_);
-}
-#endif
-
void PrintSettings::SetPrinterPrintableArea(
gfx::Size const& physical_size_device_units,
gfx::Rect const& printable_area_device_units,