Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: printing/page_setup.cc

Issue 8201027: Move margin processing code to the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « printing/page_setup.h ('k') | printing/print_dialog_gtk_interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/page_setup.cc
diff --git a/printing/page_setup.cc b/printing/page_setup.cc
index 9ac3e5203166832ed3f17a0b4652e1f56ef8f64b..2411f6fb98954107b1a8e48453ec31ab1718edca 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
« no previous file with comments | « printing/page_setup.h ('k') | printing/print_dialog_gtk_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698