summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
authorsverrir@chromium.org <sverrir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 14:34:43 +0000
committersverrir@chromium.org <sverrir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 14:34:43 +0000
commit4ecd074560bcbeb46cb9c0a328f32df433d671d9 (patch)
treea7946de51f5702307818f16ebe2acee50e1ef85c /chrome/browser/printing
parent66e8f2e6e53a03c6e526e60eb85bb96894d8e783 (diff)
downloadchromium_src-4ecd074560bcbeb46cb9c0a328f32df433d671d9.zip
chromium_src-4ecd074560bcbeb46cb9c0a328f32df433d671d9.tar.gz
chromium_src-4ecd074560bcbeb46cb9c0a328f32df433d671d9.tar.bz2
Simplify code in PrintSettings. Removes support for settings margins
etc in metric units but I will add again if required. This is to prepare adding user defined print settings. Also fixes some typos in printing code. Review URL: http://codereview.chromium.org/56077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/print_settings.cc91
-rw-r--r--chrome/browser/printing/print_settings.h16
-rw-r--r--chrome/browser/printing/print_view_manager.cc4
-rw-r--r--chrome/browser/printing/printed_document.h14
-rw-r--r--chrome/browser/printing/printed_page.h6
-rw-r--r--chrome/browser/printing/win_printing_context.cc8
6 files changed, 36 insertions, 103 deletions
diff --git a/chrome/browser/printing/print_settings.cc b/chrome/browser/printing/print_settings.cc
index 4f8903b..8c33acd 100644
--- a/chrome/browser/printing/print_settings.cc
+++ b/chrome/browser/printing/print_settings.cc
@@ -29,7 +29,6 @@ void PrintSettings::Clear() {
desired_dpi = 72;
printer_name_.clear();
device_name_.clear();
- page_setup_cmm_.Clear();
page_setup_pixels_.Clear();
dpi_ = 0;
landscape_ = false;
@@ -46,7 +45,6 @@ void PrintSettings::Init(HDC hdc,
ranges = new_ranges;
landscape_ = dev_mode.dmOrientation == DMORIENT_LANDSCAPE;
- int old_dpi = dpi_;
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
@@ -64,80 +62,30 @@ void PrintSettings::Init(HDC hdc,
GetDeviceCaps(hdc, PHYSICALOFFSETY),
GetDeviceCaps(hdc, HORZRES),
GetDeviceCaps(hdc, VERTRES));
- // Hard-code text_height = 0.5cm = ~1/5 of inch
- page_setup_pixels_.Init(physical_size_pixels,
- printable_area_pixels,
- ConvertUnit(500, kHundrethsMMPerInch, dpi_));
- // Initialize page_setup_cmm_.
- // In theory, we should be using HORZSIZE and VERTSIZE but their value is
- // so wrong it's useless. So read the values in dpi unit and convert them back
- // in 0.01 mm.
- gfx::Size physical_size_cmm(
- ConvertUnit(physical_size_pixels.width(), dpi_, kHundrethsMMPerInch),
- ConvertUnit(physical_size_pixels.height(), dpi_, kHundrethsMMPerInch));
- gfx::Rect printable_area_cmm(
- ConvertUnit(printable_area_pixels.x(), dpi_, kHundrethsMMPerInch),
- ConvertUnit(printable_area_pixels.y(), dpi_, kHundrethsMMPerInch),
- ConvertUnit(printable_area_pixels.width(), dpi_, kHundrethsMMPerInch),
- ConvertUnit(printable_area_pixels.bottom(), dpi_, kHundrethsMMPerInch));
-
- static const int kRoundingTolerance = 5;
- // Some printers may advertise a slightly larger printable area than the
- // physical area. This is mostly due to integer calculation and rounding.
- if (physical_size_cmm.height() > printable_area_cmm.bottom() &&
- physical_size_cmm.height() <= (printable_area_cmm.bottom() +
- kRoundingTolerance)) {
- physical_size_cmm.set_height(printable_area_cmm.bottom());
- }
- if (physical_size_cmm.width() > printable_area_cmm.right() &&
- physical_size_cmm.width() <= (printable_area_cmm.right() +
- kRoundingTolerance)) {
- physical_size_cmm.set_width(printable_area_cmm.right());
- }
- page_setup_cmm_.Init(physical_size_cmm, printable_area_cmm, 500);
+ SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels);
}
#endif
-void PrintSettings::UpdateMarginsMetric(const PageMargins& new_margins) {
- // Apply the new margins in 0.01 mm unit.
- page_setup_cmm_.SetRequestedMargins(new_margins);
-
- // Converts the margins in dpi unit and apply those too.
- PageMargins pixels_margins;
- pixels_margins.header = ConvertUnit(new_margins.header,
- kHundrethsMMPerInch,
- dpi_);
- pixels_margins.footer = ConvertUnit(new_margins.footer,
- kHundrethsMMPerInch,
- dpi_);
- pixels_margins.left = ConvertUnit(new_margins.left,
- kHundrethsMMPerInch,
- dpi_);
- pixels_margins.top = ConvertUnit(new_margins.top, kHundrethsMMPerInch, dpi_);
- pixels_margins.right = ConvertUnit(new_margins.right,
- kHundrethsMMPerInch,
- dpi_);
- pixels_margins.bottom = ConvertUnit(new_margins.bottom,
- kHundrethsMMPerInch,
- dpi_);
- page_setup_pixels_.SetRequestedMargins(pixels_margins);
-}
+void PrintSettings::SetPrinterPrintableArea(
+ gfx::Size const& physical_size_pixels,
+ gfx::Rect const& printable_area_pixels) {
+
+ // Start by setting the user configuration
+ // Hard-code text_height = 0.5cm = ~1/5 of inch
+ page_setup_pixels_.Init(physical_size_pixels,
+ printable_area_pixels,
+ ConvertUnit(500, kHundrethsMMPerInch, dpi_));
-void PrintSettings::UpdateMarginsMilliInch(const PageMargins& new_margins) {
- // Convert margins from thousandth inches to cmm (0.01mm).
- PageMargins cmm_margins;
- cmm_margins.header =
- ConvertMilliInchToHundredThousanthMeter(new_margins.header);
- cmm_margins.footer =
- ConvertMilliInchToHundredThousanthMeter(new_margins.footer);
- cmm_margins.left = ConvertMilliInchToHundredThousanthMeter(new_margins.left);
- cmm_margins.top = ConvertMilliInchToHundredThousanthMeter(new_margins.top);
- cmm_margins.right =
- ConvertMilliInchToHundredThousanthMeter(new_margins.right);
- cmm_margins.bottom =
- ConvertMilliInchToHundredThousanthMeter(new_margins.bottom);
- UpdateMarginsMetric(cmm_margins);
+ // Now apply user configured settings.
+ PageMargins margins;
+ margins.header = 500;
+ margins.footer = 500;
+ margins.left = 500;
+ margins.top = 500;
+ margins.right = 500;
+ margins.bottom = 500;
+ page_setup_pixels_.SetRequestedMargins(margins);
}
void PrintSettings::RenderParams(ViewMsg_Print_Params* params) const {
@@ -166,7 +114,6 @@ bool PrintSettings::Equals(const PrintSettings& rhs) const {
overlays.Equals(rhs.overlays) &&
device_name_ == rhs.device_name_ &&
page_setup_pixels_.Equals(rhs.page_setup_pixels_) &&
- page_setup_cmm_.Equals(rhs.page_setup_cmm_) &&
dpi_ == rhs.dpi_ &&
landscape_ == rhs.landscape_;
}
diff --git a/chrome/browser/printing/print_settings.h b/chrome/browser/printing/print_settings.h
index 48a39e6..da65cb3 100644
--- a/chrome/browser/printing/print_settings.h
+++ b/chrome/browser/printing/print_settings.h
@@ -33,11 +33,9 @@ class PrintSettings {
const std::wstring& new_device_name);
#endif
- // Sets margins in 0.01 millimeter unit.
- void UpdateMarginsMetric(const PageMargins& new_margins);
-
- // Sets margins in thousandth of inch.
- void UpdateMarginsMilliInch(const PageMargins& new_margins);
+ // Set printer printable area in in pixels.
+ void SetPrinterPrintableArea(gfx::Size const& physical_size_pixels,
+ gfx::Rect const& printable_area_pixels);
// Initializes the print parameters that needs to be sent to the renderer
// process.
@@ -54,11 +52,10 @@ class PrintSettings {
}
const std::wstring& device_name() const { return device_name_; }
int dpi() const { return dpi_; }
- const PageSetup& page_setup_cmm() const { return page_setup_cmm_; }
const PageSetup& page_setup_pixels() const { return page_setup_pixels_; }
- // Multipage printing. Each PageRange describes a from-to page combinaison.
- // This permits printing some selected pages only.
+ // Multi-page printing. Each PageRange describes a from-to page combination.
+ // This permits printing selected pages only.
PageRanges ranges;
// By imaging to a width a little wider than the available pixels, thin pages
@@ -96,9 +93,6 @@ class PrintSettings {
// Printer device name as opened by the OS.
std::wstring device_name_;
- // Page setup in centimillimeter (0.01 mm) units.
- PageSetup page_setup_cmm_;
-
// Page setup in pixel units, dpi adjusted.
PageSetup page_setup_pixels_;
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 1c4c51b..b8d1095 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -82,8 +82,8 @@ void PrintViewManager::DidPrintPage(
PrintedDocument* document = print_job_->document();
if (!document || params.document_cookie != document->cookie()) {
- // Out of sync. It may happens since we are completely asynchronous. Old
- // spurious message can happen if one of the processes is overloaded.
+ // Out of sync. It may happen since we are completely asynchronous. Old
+ // spurious messages can be received if one of the processes is overloaded.
return;
}
diff --git a/chrome/browser/printing/printed_document.h b/chrome/browser/printing/printed_document.h
index 0f6fc158..00d4c88 100644
--- a/chrome/browser/printing/printed_document.h
+++ b/chrome/browser/printing/printed_document.h
@@ -25,7 +25,7 @@ namespace printing {
class PrintedPage;
class PrintedPagesSource;
-// A collection of rendered pages. The settings are immuable. If the print
+// A collection of rendered pages. The settings are immutable. If the print
// settings are changed, a new PrintedDocument must be created.
// Warning: May be accessed from many threads at the same time. Only one thread
// will have write access. Sensible functions are protected by a lock.
@@ -93,7 +93,7 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
// Note: locks for a short amount of time.
int expected_page_count() const;
- // Getters. All these items are immuable hence thread-safe.
+ // Getters. All these items are immutable hence thread-safe.
const PrintSettings& settings() const { return immutable_.settings_; }
const std::wstring& name() const {
return immutable_.name_;
@@ -138,22 +138,22 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
Immutable(const PrintSettings& settings, PrintedPagesSource* source,
int cookie);
- // Print settings used to generate this document. Immuable.
+ // Print settings used to generate this document. Immutable.
PrintSettings settings_;
// Native thread for the render source.
MessageLoop* source_message_loop_;
- // Document name. Immuable.
+ // Document name. Immutable.
std::wstring name_;
- // URL that generated this document. Immuable.
+ // URL that generated this document. Immutable.
GURL url_;
- // The date on which this job started. Immuable.
+ // The date on which this job started. Immutable.
std::wstring date_;
- // The time at which this job started. Immuable.
+ // The time at which this job started. Immutable.
std::wstring time_;
// Cookie to uniquely identify this document. It is used to make sure that a
diff --git a/chrome/browser/printing/printed_page.h b/chrome/browser/printing/printed_page.h
index 19c740e..9058d72 100644
--- a/chrome/browser/printing/printed_page.h
+++ b/chrome/browser/printing/printed_page.h
@@ -17,11 +17,11 @@ class Emf;
namespace printing {
// Contains the data to reproduce a printed page, either on screen or on
-// paper. Once created, this object is immuable. It has no reference to the
+// paper. Once created, this object is immutable. It has no reference to the
// PrintedDocument containing this page.
// Note: May be accessed from many threads at the same time. This is an non
-// issue since this object is immuable. The reason is that a page may be printed
-// and be displayed at the same time.
+// issue since this object is immutable. The reason is that a page may be
+// printed and be displayed at the same time.
class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> {
public:
PrintedPage(int page_number,
diff --git a/chrome/browser/printing/win_printing_context.cc b/chrome/browser/printing/win_printing_context.cc
index c9d0053..7a43b4d 100644
--- a/chrome/browser/printing/win_printing_context.cc
+++ b/chrome/browser/printing/win_printing_context.cc
@@ -409,14 +409,6 @@ bool PrintingContext::InitializeSettings(const DEVMODE& dev_mode,
ranges_vector.push_back(range);
}
settings_.Init(hdc_, dev_mode, ranges_vector, new_device_name);
- PageMargins margins;
- margins.header = 500;
- margins.footer = 500;
- margins.left = 500;
- margins.top = 500;
- margins.right = 500;
- margins.bottom = 500;
- settings_.UpdateMarginsMilliInch(margins);
return true;
}