Chromium Code Reviews| Index: printing/page_setup.cc |
| diff --git a/printing/page_setup.cc b/printing/page_setup.cc |
| index b870323e04cc3c7180faaf1e798de0d251818ddb..6ae6991660e024f4ea652e05a08bd847de33242e 100644 |
| --- a/printing/page_setup.cc |
| +++ b/printing/page_setup.cc |
| @@ -19,6 +19,14 @@ PageMargins::PageMargins() |
| bottom(0) { |
| } |
| +void PageMargins::Rotate() { |
| + int temp_right = right; |
| + right = bottom; |
| + bottom = left; |
| + left = top; |
| + top = temp_right; |
| +} |
| + |
| void PageMargins::Clear() { |
| header = 0; |
| footer = 0; |
| @@ -37,7 +45,7 @@ bool PageMargins::Equals(const PageMargins& rhs) const { |
| bottom == rhs.bottom; |
| } |
| -PageSetup::PageSetup() { |
| +PageSetup::PageSetup() : forced_margins_(false) { |
|
vandebo (ex-Chrome)
2011/11/03 21:12:57
nit: not needed because it's in Clear
kmadhusu
2011/11/03 22:37:39
Done.
|
| Clear(); |
| } |
| @@ -50,6 +58,7 @@ void PageSetup::Clear() { |
| content_area_.SetRect(0, 0, 0, 0); |
| effective_margins_.Clear(); |
| text_height_ = 0; |
| + forced_margins_ = false; |
| } |
| bool PageSetup::Equals(const PageSetup& rhs) const { |
| @@ -76,19 +85,17 @@ void PageSetup::Init(const gfx::Size& physical_size, |
| printable_area_ = printable_area; |
| text_height_ = text_height; |
| - CalculateSizesWithinRect(printable_area_, text_height_); |
| + SetRequestedMarginsAndUpdateValues(requested_margins_); |
| } |
| 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() { |
| @@ -100,10 +107,22 @@ void PageSetup::FlipOrientation() { |
| new_y, |
| printable_area_.height(), |
| printable_area_.width()); |
| + requested_margins_.Rotate(); |
| Init(new_size, new_printable_area, text_height_); |
| } |
| } |
| +void PageSetup::SetRequestedMarginsAndUpdateValues( |
| + const PageMargins& requested_margins) { |
| + requested_margins_ = requested_margins; |
| + if (physical_size_.width() && physical_size_.height()) { |
| + if (forced_margins_) |
| + CalculateSizesWithinRect(gfx::Rect(physical_size_), 0); |
| + else |
| + CalculateSizesWithinRect(printable_area_, text_height_); |
| + } |
| +} |
| + |
| void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds, |
| int text_height) { |
| // Calculate the effective margins. The tricky part. |