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
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user