OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 params.document_cookie != 0; | 120 params.document_cookie != 0; |
121 } | 121 } |
122 | 122 |
123 PrintMsg_Print_Params GetCssPrintParams( | 123 PrintMsg_Print_Params GetCssPrintParams( |
124 blink::WebLocalFrame* frame, | 124 blink::WebLocalFrame* frame, |
125 int page_index, | 125 int page_index, |
126 const PrintMsg_Print_Params& page_params) { | 126 const PrintMsg_Print_Params& page_params) { |
127 PrintMsg_Print_Params page_css_params = page_params; | 127 PrintMsg_Print_Params page_css_params = page_params; |
128 int dpi = GetDPI(&page_params); | 128 int dpi = GetDPI(&page_params); |
129 | 129 |
130 blink::WebSize page_size_in_pixels( | 130 blink::WebFloatSize page_size_in_pixels( |
131 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), | 131 ConvertUnitDouble(page_params.page_size.width(), dpi, kPixelsPerInch), |
132 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); | 132 ConvertUnitDouble(page_params.page_size.height(), dpi, kPixelsPerInch)); |
133 int margin_top_in_pixels = | 133 int margin_top_in_pixels = |
134 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); | 134 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); |
135 int margin_right_in_pixels = ConvertUnit( | 135 int margin_right_in_pixels = ConvertUnit( |
136 page_params.page_size.width() - | 136 page_params.page_size.width() - |
137 page_params.content_size.width() - page_params.margin_left, | 137 page_params.content_size.width() - page_params.margin_left, |
138 dpi, kPixelsPerInch); | 138 dpi, kPixelsPerInch); |
139 int margin_bottom_in_pixels = ConvertUnit( | 139 int margin_bottom_in_pixels = ConvertUnit( |
140 page_params.page_size.height() - | 140 page_params.page_size.height() - |
141 page_params.content_size.height() - page_params.margin_top, | 141 page_params.content_size.height() - page_params.margin_top, |
142 dpi, kPixelsPerInch); | 142 dpi, kPixelsPerInch); |
143 int margin_left_in_pixels = ConvertUnit( | 143 int margin_left_in_pixels = ConvertUnit( |
144 page_params.margin_left, | 144 page_params.margin_left, |
145 dpi, kPixelsPerInch); | 145 dpi, kPixelsPerInch); |
146 | 146 |
147 blink::WebSize original_page_size_in_pixels = page_size_in_pixels; | |
148 | |
149 if (frame) { | 147 if (frame) { |
150 frame->pageSizeAndMarginsInPixels(page_index, | 148 frame->pageSizeAndMarginsInPixels(page_index, |
151 page_size_in_pixels, | 149 page_size_in_pixels, |
152 margin_top_in_pixels, | 150 margin_top_in_pixels, |
153 margin_right_in_pixels, | 151 margin_right_in_pixels, |
154 margin_bottom_in_pixels, | 152 margin_bottom_in_pixels, |
155 margin_left_in_pixels); | 153 margin_left_in_pixels); |
156 } | 154 } |
157 | 155 |
158 int new_content_width = page_size_in_pixels.width - | 156 float new_content_width = page_size_in_pixels.width - |
159 margin_left_in_pixels - margin_right_in_pixels; | 157 margin_left_in_pixels - margin_right_in_pixels; |
160 int new_content_height = page_size_in_pixels.height - | 158 float new_content_height = page_size_in_pixels.height - |
161 margin_top_in_pixels - margin_bottom_in_pixels; | 159 margin_top_in_pixels - margin_bottom_in_pixels; |
162 | 160 |
163 // Invalid page size and/or margins. We just use the default setting. | 161 // Invalid page size and/or margins. We just use the default setting. |
164 if (new_content_width < 1 || new_content_height < 1) { | 162 if (new_content_width < 1 || new_content_height < 1) { |
165 CHECK(frame != NULL); | 163 CHECK(frame != NULL); |
166 page_css_params = GetCssPrintParams(NULL, page_index, page_params); | 164 page_css_params = GetCssPrintParams(NULL, page_index, page_params); |
167 return page_css_params; | 165 return page_css_params; |
168 } | 166 } |
169 | 167 |
| 168 page_css_params.page_size = |
| 169 gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), |
| 170 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); |
170 page_css_params.content_size = | 171 page_css_params.content_size = |
171 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), | 172 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), |
172 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); | 173 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); |
173 | |
174 if (original_page_size_in_pixels != page_size_in_pixels) { | |
175 page_css_params.page_size = | |
176 gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), | |
177 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); | |
178 } else { | |
179 // Printing frame doesn't have any page size css. Pixels to dpi conversion | |
180 // causes rounding off errors. Therefore use the default page size values | |
181 // directly. | |
182 page_css_params.page_size = page_params.page_size; | |
183 } | |
184 | 174 |
185 page_css_params.margin_top = | 175 page_css_params.margin_top = |
186 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); | 176 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); |
187 page_css_params.margin_left = | 177 page_css_params.margin_left = |
188 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); | 178 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); |
189 return page_css_params; | 179 return page_css_params; |
190 } | 180 } |
191 | 181 |
192 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, | 182 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, |
193 PrintMsg_Print_Params* params_to_fit) { | 183 PrintMsg_Print_Params* params_to_fit) { |
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2254 blink::WebConsoleMessage::LevelWarning, message)); | 2244 blink::WebConsoleMessage::LevelWarning, message)); |
2255 return false; | 2245 return false; |
2256 } | 2246 } |
2257 | 2247 |
2258 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2248 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2259 // Reset counter on successful print. | 2249 // Reset counter on successful print. |
2260 count_ = 0; | 2250 count_ = 0; |
2261 } | 2251 } |
2262 | 2252 |
2263 } // namespace printing | 2253 } // namespace printing |
OLD | NEW |