| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch)); | 1253 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch)); |
| 1254 | 1254 |
| 1255 double fit_to_page_scale_factor = 1.0f; | 1255 double fit_to_page_scale_factor = 1.0f; |
| 1256 if (!print_preview_context_.IsModifiable()) { | 1256 if (!print_preview_context_.IsModifiable()) { |
| 1257 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1257 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
| 1258 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1258 const blink::WebNode& source_node = print_preview_context_.source_node(); |
| 1259 blink::WebPrintPresetOptions preset_options; | 1259 blink::WebPrintPresetOptions preset_options; |
| 1260 if (source_frame->getPrintPresetOptionsForPlugin(source_node, | 1260 if (source_frame->getPrintPresetOptionsForPlugin(source_node, |
| 1261 &preset_options)) { | 1261 &preset_options)) { |
| 1262 if (preset_options.isPageSizeUniform) { | 1262 if (preset_options.isPageSizeUniform) { |
| 1263 // Figure out if the sizes have the same orientation |
| 1264 bool is_printable_area_landscape = printable_area_in_points.width() > |
| 1265 printable_area_in_points.height(); |
| 1266 bool is_preset_landscape = preset_options.uniformPageSize.width > |
| 1267 preset_options.uniformPageSize.height; |
| 1268 bool rotate = is_printable_area_landscape != is_preset_landscape; |
| 1269 // Match orientation for computing scaling |
| 1270 double printable_width = rotate ? printable_area_in_points.height() |
| 1271 : printable_area_in_points.width(); |
| 1272 double printable_height = rotate ? printable_area_in_points.width() |
| 1273 : printable_area_in_points.height(); |
| 1263 double scale_width = | 1274 double scale_width = |
| 1264 static_cast<double>(printable_area_in_points.width()) / | 1275 printable_width / |
| 1265 static_cast<double>(preset_options.uniformPageSize.width); | 1276 static_cast<double>(preset_options.uniformPageSize.width); |
| 1266 double scale_height = | 1277 double scale_height = |
| 1267 static_cast<double>(printable_area_in_points.height()) / | 1278 printable_height / |
| 1268 static_cast<double>(preset_options.uniformPageSize.height); | 1279 static_cast<double>(preset_options.uniformPageSize.height); |
| 1269 fit_to_page_scale_factor = std::min(scale_width, scale_height); | 1280 fit_to_page_scale_factor = std::min(scale_width, scale_height); |
| 1270 } else { | 1281 } else { |
| 1271 fit_to_page_scale_factor = 0.0f; | 1282 fit_to_page_scale_factor = 0.0f; |
| 1272 } | 1283 } |
| 1273 } | 1284 } |
| 1274 } | 1285 } |
| 1275 int fit_to_page_scaling = static_cast<int>(100.0f * fit_to_page_scale_factor); | 1286 int fit_to_page_scaling = static_cast<int>(100.0f * fit_to_page_scale_factor); |
| 1276 // Margins: Send default page layout to browser process. | 1287 // Margins: Send default page layout to browser process. |
| 1277 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), | 1288 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 blink::WebConsoleMessage::LevelWarning, message)); | 2371 blink::WebConsoleMessage::LevelWarning, message)); |
| 2361 return false; | 2372 return false; |
| 2362 } | 2373 } |
| 2363 | 2374 |
| 2364 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2375 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2365 // Reset counter on successful print. | 2376 // Reset counter on successful print. |
| 2366 count_ = 0; | 2377 count_ = 0; |
| 2367 } | 2378 } |
| 2368 | 2379 |
| 2369 } // namespace printing | 2380 } // namespace printing |
| OLD | NEW |