Skip to content

Commit

Permalink
For no margins, or printable area margins, don't factor in the header…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
vandebo@chromium.org committed Oct 18, 2011
1 parent 1eec5ca commit d69d322
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 7 additions & 6 deletions printing/page_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions printing/page_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
8 changes: 6 additions & 2 deletions printing/print_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -173,13 +173,17 @@ 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;
margins.right = 0;
break;
}
case CUSTOM_MARGINS: {
margins.header = 0;
margins.footer = 0;
margins.top = ConvertUnitDouble(custom_margins_in_points_.top,
printing::kPointsPerInch,
units_per_inch);
Expand Down

0 comments on commit d69d322

Please sign in to comment.