diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-15 22:30:48 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-15 22:30:48 +0000 |
commit | 1c23b4e86cf43bf86c591840bba6be39ad49b0c9 (patch) | |
tree | 5e3c268f4544a27d74fc81d0820e0a3fd82949ae /printing/page_setup.cc | |
parent | 0374b165987b53354edca740082640315091fd95 (diff) | |
download | chromium_src-1c23b4e86cf43bf86c591840bba6be39ad49b0c9.zip chromium_src-1c23b4e86cf43bf86c591840bba6be39ad49b0c9.tar.gz chromium_src-1c23b4e86cf43bf86c591840bba6be39ad49b0c9.tar.bz2 |
Move margin processing code to the browser process.
It seems that this is where it is supposed to live and it was erroneously added to PrintWebViewHelper.
BUG=67091, 92045, 91880, 92000, 92218, 95905
TEST=NONE
Review URL: http://codereview.chromium.org/8201027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105688 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/page_setup.cc')
-rw-r--r-- | printing/page_setup.cc | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/printing/page_setup.cc b/printing/page_setup.cc index 9ac3e520..2411f6f 100644 --- a/printing/page_setup.cc +++ b/printing/page_setup.cc @@ -37,7 +37,8 @@ bool PageMargins::Equals(const PageMargins& rhs) const { bottom == rhs.bottom; } -PageSetup::PageSetup() : text_height_(0) { +PageSetup::PageSetup() { + Clear(); } PageSetup::~PageSetup() {} @@ -75,35 +76,64 @@ void PageSetup::Init(const gfx::Size& physical_size, printable_area_ = printable_area; text_height_ = text_height; + CalculateSizesWithinRect(printable_area_); +} + +void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { + requested_margins_ = requested_margins; + if (printable_area_.width() && printable_area_.height()) + CalculateSizesWithinRect(printable_area_); +} + +void PageSetup::ForceRequestedMargins(const PageMargins& requested_margins) { + requested_margins_ = requested_margins; + if (physical_size_.width() && physical_size_.height()) + CalculateSizesWithinRect(gfx::Rect(physical_size_)); +} + +void PageSetup::FlipOrientation() { + if (physical_size_.width() && physical_size_.height()) { + gfx::Size new_size(physical_size_.height(), physical_size_.width()); + int new_y = physical_size_.width() - + (printable_area_.width() + printable_area_.x()); + gfx::Rect new_printable_area(printable_area_.y(), + new_y, + printable_area_.height(), + printable_area_.width()); + Init(new_size, new_printable_area, text_height_); + } +} + +void PageSetup::CalculateSizesWithinRect(const gfx::Rect& bounds) { // Calculate the effective margins. The tricky part. effective_margins_.header = std::max(requested_margins_.header, - printable_area_.y()); + bounds.y()); effective_margins_.footer = std::max(requested_margins_.footer, - physical_size.height() - - printable_area_.bottom()); + physical_size_.height() - + bounds.bottom()); effective_margins_.left = std::max(requested_margins_.left, - printable_area_.x()); + bounds.x()); effective_margins_.top = std::max(std::max(requested_margins_.top, - printable_area_.y()), - effective_margins_.header + text_height); + bounds.y()), + effective_margins_.header + text_height_); effective_margins_.right = std::max(requested_margins_.right, - physical_size.width() - - printable_area_.right()); - effective_margins_.bottom = std::max(std::max(requested_margins_.bottom, - physical_size.height() - - printable_area_.bottom()), - effective_margins_.footer + text_height); + 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_); // Calculate the overlay area. If the margins are excessive, the overlay_area // size will be (0, 0). overlay_area_.set_x(effective_margins_.left); overlay_area_.set_y(effective_margins_.header); overlay_area_.set_width(std::max(0, - physical_size.width() - + physical_size_.width() - effective_margins_.right - overlay_area_.x())); overlay_area_.set_height(std::max(0, - physical_size.height() - + physical_size_.height() - effective_margins_.footer - overlay_area_.y())); @@ -112,32 +142,13 @@ void PageSetup::Init(const gfx::Size& physical_size, content_area_.set_x(effective_margins_.left); content_area_.set_y(effective_margins_.top); content_area_.set_width(std::max(0, - physical_size.width() - + physical_size_.width() - effective_margins_.right - content_area_.x())); content_area_.set_height(std::max(0, - physical_size.height() - + physical_size_.height() - effective_margins_.bottom - content_area_.y())); } -void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { - requested_margins_ = requested_margins; - if (physical_size_.width() && physical_size_.height()) - Init(physical_size_, printable_area_, text_height_); -} - -void PageSetup::FlipOrientation() { - if (physical_size_.width() && physical_size_.height()) { - gfx::Size new_size(physical_size_.height(), physical_size_.width()); - int new_y = physical_size_.width() - - (printable_area_.width() + printable_area_.x()); - gfx::Rect new_printable_area(printable_area_.y(), - new_y, - printable_area_.height(), - printable_area_.width()); - Init(new_size, new_printable_area, text_height_); - } -} - } // namespace printing |