0

For no margins, or printable area margins, don't factor in the header/footer size.

BUG=NONE
TEST=NONE

Review URL: http://codereview.chromium.org/8328001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105973 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
vandebo@chromium.org
2011-10-18 00:15:21 +00:00
parent 1eec5ca7ad
commit d69d322dcd
3 changed files with 15 additions and 10 deletions

@ -76,19 +76,19 @@ void PageSetup::Init(const gfx::Size& physical_size,
printable_area_ = printable_area;
text_height_ = text_height;
CalculateSizesWithinRect(printable_area_);
CalculateSizesWithinRect(printable_area_, text_height_);
}
void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) {
requested_margins_ = requested_margins;
if (printable_area_.width() && printable_area_.height())
CalculateSizesWithinRect(printable_area_);
CalculateSizesWithinRect(printable_area_, text_height_);
}
void PageSetup::ForceRequestedMargins(const PageMargins& requested_margins) {
requested_margins_ = requested_margins;
if (physical_size_.width() && physical_size_.height())
CalculateSizesWithinRect(gfx::Rect(physical_size_));
CalculateSizesWithinRect(gfx::Rect(physical_size_), 0);
}
void PageSetup::FlipOrientation() {
@ -104,7 +104,8 @@ void PageSetup::FlipOrientation() {
}
}
void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds) {
void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds,
int text_height) {
// Calculate the effective margins. The tricky part.
effective_margins_.header = std::max(requested_margins_.header,
bounds.y());
@ -115,14 +116,14 @@ void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds) {
bounds.x());
effective_margins_.top = std::max(std::max(requested_margins_.top,
bounds.y()),
effective_margins_.header + text_height_);
effective_margins_.header + text_height);
effective_margins_.right = std::max(requested_margins_.right,
physical_size_.width() -
bounds.right());
effective_margins_.bottom =
std::max(std::max(requested_margins_.bottom,
physical_size_.height() - bounds.bottom()),
effective_margins_.footer + text_height_);
effective_margins_.footer + text_height);
// Calculate the overlay area. If the margins are excessive, the overlay_area
// size will be (0, 0).

@ -65,8 +65,8 @@ class PRINTING_EXPORT PageSetup {
private:
// Calculate overlay_area_, effective_margins_, and content_area_, based on
// a constraint of |bounds|.
void CalculateSizesWithinRect(const gfx::Rect& bounds);
// a constraint of |bounds| and |text_height|.
void CalculateSizesWithinRect(const gfx::Rect& bounds, int text_height);
// Physical size of the page, including non-printable margins.
gfx::Size physical_size_;

@ -158,13 +158,13 @@ void PrintSettings::SetPrinterPrintableArea(
header_footer_text_height);
PageMargins margins;
margins.header = header_footer_text_height;
margins.footer = header_footer_text_height;
switch (margin_type) {
case DEFAULT_MARGINS: {
// Default margins 1.0cm = ~2/5 of an inch.
int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch,
units_per_inch);
margins.header = header_footer_text_height;
margins.footer = header_footer_text_height;
margins.top = margin_printer_units;
margins.bottom = margin_printer_units;
margins.left = margin_printer_units;
@ -173,6 +173,8 @@ void PrintSettings::SetPrinterPrintableArea(
}
case NO_MARGINS:
case PRINTABLE_AREA_MARGINS: {
margins.header = 0;
margins.footer = 0;
margins.top = 0;
margins.bottom = 0;
margins.left = 0;
@ -180,6 +182,8 @@ void PrintSettings::SetPrinterPrintableArea(
break;
}
case CUSTOM_MARGINS: {
margins.header = 0;
margins.footer = 0;
margins.top = ConvertUnitDouble(custom_margins_in_points_.top,
printing::kPointsPerInch,
units_per_inch);