Chromium Code Reviews| Index: printing/page_setup.cc |
| diff --git a/printing/page_setup.cc b/printing/page_setup.cc |
| index b870323e04cc3c7180faaf1e798de0d251818ddb..696899bf24061bf75cbbbf6fa6f90c77f83954c0 100644 |
| --- a/printing/page_setup.cc |
| +++ b/printing/page_setup.cc |
| @@ -19,6 +19,16 @@ PageMargins::PageMargins() |
| bottom(0) { |
| } |
| +void PageMargins::RotatePageMarginsAndUpdateCurrentValue( |
| + const PageMargins& margins) { |
| + header = margins.header; |
| + footer = margins.footer; |
| + top = margins.right; |
| + left = margins.top; |
| + bottom = margins.left; |
| + right = margins.bottom; |
| +} |
| + |
| void PageMargins::Clear() { |
| header = 0; |
| footer = 0; |
| @@ -37,7 +47,7 @@ bool PageMargins::Equals(const PageMargins& rhs) const { |
| bottom == rhs.bottom; |
| } |
| -PageSetup::PageSetup() { |
| +PageSetup::PageSetup() : forced_margins_(false) { |
| Clear(); |
| } |
| @@ -80,15 +90,13 @@ void PageSetup::Init(const gfx::Size& physical_size, |
| } |
| void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { |
| - requested_margins_ = requested_margins; |
| - if (printable_area_.width() && printable_area_.height()) |
| - CalculateSizesWithinRect(printable_area_, text_height_); |
| + forced_margins_ = false; |
| + SetRequestedMarginsAndUpdateValues(requested_margins); |
| } |
| void PageSetup::ForceRequestedMargins(const PageMargins& requested_margins) { |
| - requested_margins_ = requested_margins; |
| - if (physical_size_.width() && physical_size_.height()) |
| - CalculateSizesWithinRect(gfx::Rect(physical_size_), 0); |
| + forced_margins_ = true; |
| + SetRequestedMarginsAndUpdateValues(requested_margins); |
| } |
| void PageSetup::FlipOrientation() { |
| @@ -101,6 +109,21 @@ void PageSetup::FlipOrientation() { |
| printable_area_.height(), |
| printable_area_.width()); |
| Init(new_size, new_printable_area, text_height_); |
| + PageMargins new_margins; |
| + new_margins.RotatePageMarginsAndUpdateCurrentValue(requested_margins_); |
| + SetRequestedMarginsAndUpdateValues(new_margins); |
| + } |
| +} |
| + |
| +void PageSetup::SetRequestedMarginsAndUpdateValues( |
| + const PageMargins& requested_margins) { |
| + requested_margins_ = requested_margins; |
| + if (forced_margins_) { |
| + if (physical_size_.width() && physical_size_.height()) |
|
vandebo (ex-Chrome)
2011/11/03 17:26:35
Pull this 'if' up one scope so you don't have to r
kmadhusu
2011/11/03 20:46:54
if (physical_size_....) {
if (forced_margins_)
|
| + CalculateSizesWithinRect(gfx::Rect(physical_size_), 0); |
| + } else { |
| + if (printable_area_.width() && printable_area_.height()) |
| + CalculateSizesWithinRect(printable_area_, text_height_); |
| } |
| } |
| @@ -137,7 +160,6 @@ void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds, |
| physical_size_.height() - |
| effective_margins_.footer - |
| overlay_area_.y())); |
| - |
| // Calculate the content area. If the margins are excessive, the content_area |
| // size will be (0, 0). |
| content_area_.set_x(effective_margins_.left); |