Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "printing/page_setup.h" | 5 #include "printing/page_setup.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace printing { | 11 namespace printing { |
| 12 | 12 |
| 13 PageMargins::PageMargins() | 13 PageMargins::PageMargins() |
| 14 : header(0), | 14 : header(0), |
| 15 footer(0), | 15 footer(0), |
| 16 left(0), | 16 left(0), |
| 17 right(0), | 17 right(0), |
| 18 top(0), | 18 top(0), |
| 19 bottom(0) { | 19 bottom(0) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 PageMargins::PageMargins(const PageMargins& margins, bool rotate_margins) { | |
| 23 header = margins.header; | |
| 24 footer = margins.footer; | |
| 25 if (rotate_margins) { | |
| 26 top = margins.right; | |
| 27 left = margins.top; | |
| 28 bottom = margins.left; | |
| 29 right = margins.bottom; | |
| 30 } else { | |
| 31 top = margins.top; | |
| 32 left = margins.left; | |
| 33 bottom = margins.bottom; | |
| 34 right = margins.right; | |
| 35 } | |
| 36 } | |
| 37 | |
| 22 void PageMargins::Clear() { | 38 void PageMargins::Clear() { |
| 23 header = 0; | 39 header = 0; |
| 24 footer = 0; | 40 footer = 0; |
| 25 left = 0; | 41 left = 0; |
| 26 right = 0; | 42 right = 0; |
| 27 top = 0; | 43 top = 0; |
| 28 bottom = 0; | 44 bottom = 0; |
| 29 } | 45 } |
| 30 | 46 |
| 31 bool PageMargins::Equals(const PageMargins& rhs) const { | 47 bool PageMargins::Equals(const PageMargins& rhs) const { |
| 32 return header == rhs.header && | 48 return header == rhs.header && |
| 33 footer == rhs.footer && | 49 footer == rhs.footer && |
| 34 left == rhs.left && | 50 left == rhs.left && |
| 35 top == rhs.top && | 51 top == rhs.top && |
| 36 right == rhs.right && | 52 right == rhs.right && |
| 37 bottom == rhs.bottom; | 53 bottom == rhs.bottom; |
| 38 } | 54 } |
| 39 | 55 |
| 40 PageSetup::PageSetup() { | 56 PageSetup::PageSetup() : has_forced_margins_value(false) { |
| 41 Clear(); | 57 Clear(); |
| 42 } | 58 } |
| 43 | 59 |
| 44 PageSetup::~PageSetup() {} | 60 PageSetup::~PageSetup() {} |
| 45 | 61 |
| 46 void PageSetup::Clear() { | 62 void PageSetup::Clear() { |
| 47 physical_size_.SetSize(0, 0); | 63 physical_size_.SetSize(0, 0); |
| 48 printable_area_.SetRect(0, 0, 0, 0); | 64 printable_area_.SetRect(0, 0, 0, 0); |
| 49 overlay_area_.SetRect(0, 0, 0, 0); | 65 overlay_area_.SetRect(0, 0, 0, 0); |
| 50 content_area_.SetRect(0, 0, 0, 0); | 66 content_area_.SetRect(0, 0, 0, 0); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 74 DCHECK_GE(text_height, 0); | 90 DCHECK_GE(text_height, 0); |
| 75 physical_size_ = physical_size; | 91 physical_size_ = physical_size; |
| 76 printable_area_ = printable_area; | 92 printable_area_ = printable_area; |
| 77 text_height_ = text_height; | 93 text_height_ = text_height; |
| 78 | 94 |
| 79 CalculateSizesWithinRect(printable_area_, text_height_); | 95 CalculateSizesWithinRect(printable_area_, text_height_); |
| 80 } | 96 } |
| 81 | 97 |
| 82 void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { | 98 void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { |
| 83 requested_margins_ = requested_margins; | 99 requested_margins_ = requested_margins; |
| 100 has_forced_margins_value = false; | |
| 84 if (printable_area_.width() && printable_area_.height()) | 101 if (printable_area_.width() && printable_area_.height()) |
| 85 CalculateSizesWithinRect(printable_area_, text_height_); | 102 CalculateSizesWithinRect(printable_area_, text_height_); |
| 86 } | 103 } |
| 87 | 104 |
| 88 void PageSetup::ForceRequestedMargins(const PageMargins& requested_margins) { | 105 void PageSetup::ForceRequestedMargins(const PageMargins& requested_margins) { |
| 89 requested_margins_ = requested_margins; | 106 requested_margins_ = requested_margins; |
| 107 has_forced_margins_value = true; | |
| 90 if (physical_size_.width() && physical_size_.height()) | 108 if (physical_size_.width() && physical_size_.height()) |
| 91 CalculateSizesWithinRect(gfx::Rect(physical_size_), 0); | 109 CalculateSizesWithinRect(gfx::Rect(physical_size_), 0); |
| 92 } | 110 } |
| 93 | 111 |
| 94 void PageSetup::FlipOrientation() { | 112 void PageSetup::FlipOrientation() { |
| 95 if (physical_size_.width() && physical_size_.height()) { | 113 if (physical_size_.width() && physical_size_.height()) { |
| 96 gfx::Size new_size(physical_size_.height(), physical_size_.width()); | 114 gfx::Size new_size(physical_size_.height(), physical_size_.width()); |
| 97 int new_y = physical_size_.width() - | 115 int new_y = physical_size_.width() - |
| 98 (printable_area_.width() + printable_area_.x()); | 116 (printable_area_.width() + printable_area_.x()); |
| 99 gfx::Rect new_printable_area(printable_area_.y(), | 117 gfx::Rect new_printable_area(printable_area_.y(), |
| 100 new_y, | 118 new_y, |
| 101 printable_area_.height(), | 119 printable_area_.height(), |
| 102 printable_area_.width()); | 120 printable_area_.width()); |
| 103 Init(new_size, new_printable_area, text_height_); | 121 Init(new_size, new_printable_area, text_height_); |
| 122 PageMargins new_requested_margins(requested_margins_, true); | |
| 123 if (has_forced_margins_value) | |
|
vandebo (ex-Chrome)
2011/11/02 20:26:03
With the addition of has_forced_margins_value, I t
kmadhusu
2011/11/02 23:15:03
Done.
| |
| 124 ForceRequestedMargins(new_requested_margins); | |
| 125 else | |
| 126 SetRequestedMargins(new_requested_margins); | |
| 104 } | 127 } |
| 105 } | 128 } |
| 106 | 129 |
| 107 void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds, | 130 void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds, |
| 108 int text_height) { | 131 int text_height) { |
| 109 // Calculate the effective margins. The tricky part. | 132 // Calculate the effective margins. The tricky part. |
| 110 effective_margins_.header = std::max(requested_margins_.header, | 133 effective_margins_.header = std::max(requested_margins_.header, |
| 111 bounds.y()); | 134 bounds.y()); |
| 112 effective_margins_.footer = std::max(requested_margins_.footer, | 135 effective_margins_.footer = std::max(requested_margins_.footer, |
| 113 physical_size_.height() - | 136 physical_size_.height() - |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 physical_size_.width() - | 169 physical_size_.width() - |
| 147 effective_margins_.right - | 170 effective_margins_.right - |
| 148 content_area_.x())); | 171 content_area_.x())); |
| 149 content_area_.set_height(std::max(0, | 172 content_area_.set_height(std::max(0, |
| 150 physical_size_.height() - | 173 physical_size_.height() - |
| 151 effective_margins_.bottom - | 174 effective_margins_.bottom - |
| 152 content_area_.y())); | 175 content_area_.y())); |
| 153 } | 176 } |
| 154 | 177 |
| 155 } // namespace printing | 178 } // namespace printing |
| OLD | NEW |