diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 01:26:32 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 01:26:32 +0000 |
commit | b076a082a0fe88ad5cf48e3ed0c406787edd085d (patch) | |
tree | 6225617fc22614b5f6b09ff2b2600e3908cc36e1 /printing | |
parent | f98ead6cf97707ff5a13896aa0206364703aa393 (diff) | |
download | chromium_src-b076a082a0fe88ad5cf48e3ed0c406787edd085d.zip chromium_src-b076a082a0fe88ad5cf48e3ed0c406787edd085d.tar.gz chromium_src-b076a082a0fe88ad5cf48e3ed0c406787edd085d.tar.bz2 |
Clarify that the custom margin value is not validated and add tests.
BUG=NONE
TEST=NONE
Review URL: http://codereview.chromium.org/8342059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/page_setup_unittest.cc | 29 | ||||
-rw-r--r-- | printing/print_settings.cc | 33 | ||||
-rw-r--r-- | printing/print_settings.h | 6 |
3 files changed, 51 insertions, 17 deletions
diff --git a/printing/page_setup_unittest.cc b/printing/page_setup_unittest.cc index 8d65e72..54e436c 100644 --- a/printing/page_setup_unittest.cc +++ b/printing/page_setup_unittest.cc @@ -161,3 +161,32 @@ TEST(PageSetupTest, HardCoded) { " " << page_size.ToString() << " " << printable_area.ToString() << " " << kTextHeight; } + +TEST(PageSetupTest, OutOfRangeMargins) { + printing::PageMargins margins; + margins.header = 0; + margins.footer = 0; + margins.left = -10; + margins.top = -11; + margins.right = -12; + margins.bottom = -13; + + gfx::Size page_size(100, 100); + gfx::Rect printable_area(1, 2, 96, 94); + + // Make the calculations. + printing::PageSetup setup; + setup.SetRequestedMargins(margins); + setup.Init(page_size, printable_area, 0); + + EXPECT_EQ(setup.effective_margins().left, 1); + EXPECT_EQ(setup.effective_margins().top, 2); + EXPECT_EQ(setup.effective_margins().right, 3); + EXPECT_EQ(setup.effective_margins().bottom, 4); + + setup.ForceRequestedMargins(margins); + EXPECT_EQ(setup.effective_margins().left, 0); + EXPECT_EQ(setup.effective_margins().top, 0); + EXPECT_EQ(setup.effective_margins().right, 0); + EXPECT_EQ(setup.effective_margins().bottom, 0); +} diff --git a/printing/print_settings.cc b/printing/print_settings.cc index 11828e2..70ace6d 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -184,18 +184,22 @@ void PrintSettings::SetPrinterPrintableArea( case CUSTOM_MARGINS: { margins.header = 0; margins.footer = 0; - margins.top = ConvertUnitDouble(custom_margins_in_points_.top, - kPointsPerInch, - units_per_inch); - margins.bottom = ConvertUnitDouble(custom_margins_in_points_.bottom, - kPointsPerInch, - units_per_inch); - margins.left = ConvertUnitDouble(custom_margins_in_points_.left, - kPointsPerInch, - units_per_inch); - margins.right = ConvertUnitDouble(custom_margins_in_points_.right, - kPointsPerInch, - units_per_inch); + margins.top = ConvertUnitDouble( + requested_custom_margins_in_points_.top, + kPointsPerInch, + units_per_inch); + margins.bottom = ConvertUnitDouble( + requested_custom_margins_in_points_.bottom, + kPointsPerInch, + units_per_inch); + margins.left = ConvertUnitDouble( + requested_custom_margins_in_points_.left, + kPointsPerInch, + units_per_inch); + margins.right = ConvertUnitDouble( + requested_custom_margins_in_points_.right, + kPointsPerInch, + units_per_inch); break; } default: { @@ -209,8 +213,9 @@ void PrintSettings::SetPrinterPrintableArea( page_setup_device_units_.ForceRequestedMargins(margins); } -void PrintSettings::SetCustomMargins(const PageMargins& margins_in_points) { - custom_margins_in_points_ = margins_in_points; +void PrintSettings::SetCustomMargins( + const PageMargins& requested_margins_in_points) { + requested_custom_margins_in_points_ = requested_margins_in_points; margin_type = CUSTOM_MARGINS; } diff --git a/printing/print_settings.h b/printing/print_settings.h index 31417de..07d2c54 100644 --- a/printing/print_settings.h +++ b/printing/print_settings.h @@ -41,7 +41,7 @@ class PRINTING_EXPORT PrintSettings { gfx::Rect const& printable_area_device_units, int units_per_inch); - void SetCustomMargins(const PageMargins& margins_in_points); + void SetCustomMargins(const PageMargins& requested_margins_in_points); // Equality operator. // NOTE: printer_name is NOT tested for equality since it doesn't affect the @@ -139,8 +139,8 @@ class PRINTING_EXPORT PrintSettings { // True if this printer supports AlphaBlend. bool supports_alpha_blend_; - // If margin type is custom, these are the margins. - PageMargins custom_margins_in_points_; + // If margin type is custom, this is what was requested. + PageMargins requested_custom_margins_in_points_; }; } // namespace printing |