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

Side by Side Diff: printing/print_settings.cc

Issue 8201027: Move margin processing code to the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/print_settings.h" 5 #include "printing/print_settings.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "printing/units.h" 8 #include "printing/units.h"
9 9
10 namespace printing { 10 namespace printing {
11 11
12 // Global SequenceNumber used for generating unique cookie values. 12 // Global SequenceNumber used for generating unique cookie values.
13 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); 13 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED);
14 14
15 PrintSettings::PrintSettings() 15 PrintSettings::PrintSettings()
16 : min_shrink(1.25), 16 : min_shrink(1.25),
17 max_shrink(2.0), 17 max_shrink(2.0),
18 desired_dpi(72), 18 desired_dpi(72),
19 selection_only(false), 19 selection_only(false),
20 use_overlays(true), 20 margin_type(DEFAULT_MARGINS),
21 display_header_footer(false), 21 display_header_footer(false),
22 dpi_(0), 22 dpi_(0),
23 landscape_(false), 23 landscape_(false),
24 supports_alpha_blend_(true) { 24 supports_alpha_blend_(true) {
25 } 25 }
26 26
27 PrintSettings::~PrintSettings() { 27 PrintSettings::~PrintSettings() {
28 } 28 }
29 29
30 void PrintSettings::Clear() { 30 void PrintSettings::Clear() {
(...skipping 12 matching lines...) Expand all
43 dpi_ = 0; 43 dpi_ = 0;
44 landscape_ = false; 44 landscape_ = false;
45 supports_alpha_blend_ = true; 45 supports_alpha_blend_ = true;
46 } 46 }
47 47
48 void PrintSettings::SetPrinterPrintableArea( 48 void PrintSettings::SetPrinterPrintableArea(
49 gfx::Size const& physical_size_device_units, 49 gfx::Size const& physical_size_device_units,
50 gfx::Rect const& printable_area_device_units, 50 gfx::Rect const& printable_area_device_units,
51 int units_per_inch) { 51 int units_per_inch) {
52 52
53 int header_footer_text_height = 0; 53 if (margin_type == NO_MARGINS) {
54 int margin_printer_units = 0; 54 gfx::Rect page_rect(physical_size_device_units.width(),
55 if (use_overlays) { 55 physical_size_device_units.height());
56 // Hard-code text_height = 0.5cm = ~1/5 of inch. 56 page_setup_device_units_.Init(physical_size_device_units, page_rect, 0);
57 header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch, 57 } else {
58 units_per_inch); 58 int header_footer_text_height = 0;
59 // Default margins 1.0cm = ~2/5 of an inch. 59 if (display_header_footer) {
60 margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, 60 // Hard-code text_height = 0.5cm = ~1/5 of inch.
61 header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch,
62 units_per_inch);
63 }
64 // Start by setting the user configuration
65 page_setup_device_units_.Init(physical_size_device_units,
66 printable_area_device_units,
67 header_footer_text_height);
68
69 PageMargins margins;
70 margins.header = header_footer_text_height;
71 margins.footer = header_footer_text_height;
72 if (margin_type == CUSTOM_MARGINS) {
73 margins.top = ConvertUnitDouble(custom_margins_in_points_.top,
74 printing::kPointsPerInch,
75 units_per_inch);
76 margins.bottom = ConvertUnitDouble(custom_margins_in_points_.bottom,
77 printing::kPointsPerInch,
78 units_per_inch);
79 margins.left = ConvertUnitDouble(custom_margins_in_points_.left,
80 printing::kPointsPerInch,
61 units_per_inch); 81 units_per_inch);
82 margins.right = ConvertUnitDouble(custom_margins_in_points_.right,
83 printing::kPointsPerInch,
84 units_per_inch);
85 } else {
86 // Default margins 1.0cm = ~2/5 of an inch.
87 int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch,
88 units_per_inch);
89 margins.top = margin_printer_units;
90 margins.bottom = margin_printer_units;
91 margins.left = margin_printer_units;
92 margins.right = margin_printer_units;
93 }
94 page_setup_device_units_.SetRequestedMargins(margins);
62 } 95 }
63 // Start by setting the user configuration 96 }
64 page_setup_device_units_.Init(physical_size_device_units,
65 printable_area_device_units,
66 header_footer_text_height);
67 97
68 98 void PrintSettings::SetCustomMargins(const PageMargins& margins_in_points) {
69 // Apply default margins (not user configurable just yet). 99 custom_margins_in_points_ = margins_in_points;
70 // Since the font height is half the margin we put the header and footers at 100 margin_type = CUSTOM_MARGINS;
71 // the font height from the margins.
72 PageMargins margins;
73 margins.header = header_footer_text_height;
74 margins.footer = header_footer_text_height;
75 margins.left = margin_printer_units;
76 margins.top = margin_printer_units;
77 margins.right = margin_printer_units;
78 margins.bottom = margin_printer_units;
79 page_setup_device_units_.SetRequestedMargins(margins);
80 } 101 }
81 102
82 bool PrintSettings::Equals(const PrintSettings& rhs) const { 103 bool PrintSettings::Equals(const PrintSettings& rhs) const {
83 // Do not test the display device name (printer_name_) for equality since it 104 // Do not test the display device name (printer_name_) for equality since it
84 // may sometimes be chopped off at 30 chars. As long as device_name is the 105 // may sometimes be chopped off at 30 chars. As long as device_name is the
85 // same, that's fine. 106 // same, that's fine.
86 return ranges == rhs.ranges && 107 return ranges == rhs.ranges &&
87 min_shrink == rhs.min_shrink && 108 min_shrink == rhs.min_shrink &&
88 max_shrink == rhs.max_shrink && 109 max_shrink == rhs.max_shrink &&
89 desired_dpi == rhs.desired_dpi && 110 desired_dpi == rhs.desired_dpi &&
90 device_name_ == rhs.device_name_ && 111 device_name_ == rhs.device_name_ &&
91 page_setup_device_units_.Equals(rhs.page_setup_device_units_) && 112 page_setup_device_units_.Equals(rhs.page_setup_device_units_) &&
92 dpi_ == rhs.dpi_ && 113 dpi_ == rhs.dpi_ &&
93 landscape_ == rhs.landscape_; 114 landscape_ == rhs.landscape_;
94 } 115 }
95 116
96 int PrintSettings::NewCookie() { 117 int PrintSettings::NewCookie() {
97 // A cookie of 0 is used to mark a document as unassigned, count from 1. 118 // A cookie of 0 is used to mark a document as unassigned, count from 1.
98 return cookie_seq.GetNext() + 1; 119 return cookie_seq.GetNext() + 1;
99 } 120 }
100 121
101 void PrintSettings::SetOrientation(bool landscape) { 122 void PrintSettings::SetOrientation(bool landscape) {
102 if (landscape_ != landscape) { 123 if (landscape_ != landscape) {
103 landscape_ = landscape; 124 landscape_ = landscape;
104 page_setup_device_units_.FlipOrientation(); 125 page_setup_device_units_.FlipOrientation();
105 } 126 }
106 } 127 }
107 128
108 } // namespace printing 129 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698