Chromium Code Reviews| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 frame_has_custom_page_size_style = true; | 321 frame_has_custom_page_size_style = true; |
| 322 break; | 322 break; |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 return frame_has_custom_page_size_style; | 325 return frame_has_custom_page_size_style; |
| 326 } | 326 } |
| 327 #endif // defined(ENABLE_PRINT_PREVIEW) | 327 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 328 | 328 |
| 329 // Disable scaling when either: | 329 // Disable scaling when either: |
| 330 // - The PDF specifies disabling scaling. | 330 // - The PDF specifies disabling scaling. |
| 331 // - All the pages in the PDF are the same size, and that size is the same as | 331 // - All the pages in the PDF are the same size, |
| 332 // the paper size. | 332 // - |ignore_page_size| is true and the uniform size is the same as the paper |
|
Lei Zhang
2016/08/26 02:03:26
is true -> is false?
| |
| 333 // size. | |
| 333 bool PDFShouldDisableScalingBasedOnPreset( | 334 bool PDFShouldDisableScalingBasedOnPreset( |
| 334 const blink::WebPrintPresetOptions& options, | 335 const blink::WebPrintPresetOptions& options, |
| 335 const PrintMsg_Print_Params& params) { | 336 const PrintMsg_Print_Params& params, |
| 337 bool ignore_page_size) { | |
| 336 if (options.isScalingDisabled) | 338 if (options.isScalingDisabled) |
| 337 return true; | 339 return true; |
| 338 | 340 |
| 339 if (!options.isPageSizeUniform) | 341 if (!options.isPageSizeUniform) |
| 340 return false; | 342 return false; |
| 341 | 343 |
| 342 int dpi = GetDPI(¶ms); | 344 int dpi = GetDPI(¶ms); |
| 343 if (!dpi) { | 345 if (!dpi) { |
| 344 // Likely |params| is invalid, in which case the return result does not | 346 // Likely |params| is invalid, in which case the return result does not |
| 345 // matter. Check for this so ConvertUnit() does not divide by zero. | 347 // matter. Check for this so ConvertUnit() does not divide by zero. |
| 346 return true; | 348 return true; |
| 347 } | 349 } |
| 348 | 350 |
| 351 if (ignore_page_size) | |
| 352 return false; | |
| 353 | |
| 349 blink::WebSize page_size( | 354 blink::WebSize page_size( |
| 350 ConvertUnit(params.page_size.width(), dpi, kPointsPerInch), | 355 ConvertUnit(params.page_size.width(), dpi, kPointsPerInch), |
| 351 ConvertUnit(params.page_size.height(), dpi, kPointsPerInch)); | 356 ConvertUnit(params.page_size.height(), dpi, kPointsPerInch)); |
| 352 return options.uniformPageSize == page_size; | 357 return options.uniformPageSize == page_size; |
| 353 } | 358 } |
| 354 | 359 |
| 355 bool PDFShouldDisableScaling(blink::WebLocalFrame* frame, | 360 bool PDFShouldDisableScaling(blink::WebLocalFrame* frame, |
| 356 const blink::WebNode& node, | 361 const blink::WebNode& node, |
| 357 const PrintMsg_Print_Params& params) { | 362 const PrintMsg_Print_Params& params, |
| 363 bool ignore_page_size) { | |
| 358 const bool kDefaultPDFShouldDisableScalingSetting = true; | 364 const bool kDefaultPDFShouldDisableScalingSetting = true; |
| 359 blink::WebPrintPresetOptions preset_options; | 365 blink::WebPrintPresetOptions preset_options; |
| 360 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) | 366 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) |
| 361 return kDefaultPDFShouldDisableScalingSetting; | 367 return kDefaultPDFShouldDisableScalingSetting; |
| 362 return PDFShouldDisableScalingBasedOnPreset(preset_options, params); | 368 return PDFShouldDisableScalingBasedOnPreset(preset_options, params, |
| 369 ignore_page_size); | |
| 363 } | 370 } |
| 364 | 371 |
| 365 #if defined(ENABLE_BASIC_PRINTING) | 372 #if defined(ENABLE_BASIC_PRINTING) |
| 366 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, | 373 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, |
| 367 const blink::WebNode& node, | 374 const blink::WebNode& node, |
| 368 const PrintMsg_Print_Params& params) { | 375 const PrintMsg_Print_Params& params) { |
| 369 return PDFShouldDisableScaling(frame, node, params) ? | 376 return PDFShouldDisableScaling(frame, node, params, false) ? |
| 370 NO_MARGINS : PRINTABLE_AREA_MARGINS; | 377 NO_MARGINS : PRINTABLE_AREA_MARGINS; |
| 371 } | 378 } |
| 372 #endif | 379 #endif |
| 373 | 380 |
| 374 #if defined(ENABLE_PRINT_PREVIEW) | 381 #if defined(ENABLE_PRINT_PREVIEW) |
| 375 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { | 382 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { |
| 376 bool fit_to_paper_size = false; | 383 bool fit_to_paper_size = false; |
| 377 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { | 384 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { |
| 378 NOTREACHED(); | 385 NOTREACHED(); |
| 379 } | 386 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 400 bool source_is_html, | 407 bool source_is_html, |
| 401 const base::DictionaryValue& job_settings, | 408 const base::DictionaryValue& job_settings, |
| 402 const PrintMsg_Print_Params& params) { | 409 const PrintMsg_Print_Params& params) { |
| 403 if (params.print_to_pdf) | 410 if (params.print_to_pdf) |
| 404 return blink::WebPrintScalingOptionSourceSize; | 411 return blink::WebPrintScalingOptionSourceSize; |
| 405 | 412 |
| 406 if (!source_is_html) { | 413 if (!source_is_html) { |
| 407 if (!FitToPageEnabled(job_settings)) | 414 if (!FitToPageEnabled(job_settings)) |
| 408 return blink::WebPrintScalingOptionNone; | 415 return blink::WebPrintScalingOptionNone; |
| 409 | 416 |
| 410 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params); | 417 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params, |
| 418 true); | |
| 411 if (params.is_first_request && no_plugin_scaling) | 419 if (params.is_first_request && no_plugin_scaling) |
| 412 return blink::WebPrintScalingOptionNone; | 420 return blink::WebPrintScalingOptionNone; |
| 413 } | 421 } |
| 414 return blink::WebPrintScalingOptionFitToPrintableArea; | 422 return blink::WebPrintScalingOptionFitToPrintableArea; |
| 415 } | 423 } |
| 416 #endif // defined(ENABLE_PRINT_PREVIEW) | 424 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 417 | 425 |
| 418 PrintMsg_Print_Params CalculatePrintParamsForCss( | 426 PrintMsg_Print_Params CalculatePrintParamsForCss( |
| 419 blink::WebLocalFrame* frame, | 427 blink::WebLocalFrame* frame, |
| 420 int page_index, | 428 int page_index, |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1589 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
| 1582 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1590 const blink::WebNode& source_node = print_preview_context_.source_node(); |
| 1583 | 1591 |
| 1584 blink::WebPrintPresetOptions preset_options; | 1592 blink::WebPrintPresetOptions preset_options; |
| 1585 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, | 1593 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, |
| 1586 &preset_options)) { | 1594 &preset_options)) { |
| 1587 return false; | 1595 return false; |
| 1588 } | 1596 } |
| 1589 | 1597 |
| 1590 options->is_scaling_disabled = PDFShouldDisableScalingBasedOnPreset( | 1598 options->is_scaling_disabled = PDFShouldDisableScalingBasedOnPreset( |
| 1591 preset_options, print_pages_params_->params); | 1599 preset_options, print_pages_params_->params, false); |
| 1592 options->copies = preset_options.copies; | 1600 options->copies = preset_options.copies; |
| 1593 | 1601 |
| 1594 // TODO(thestig) This should be a straight pass-through, but print preview | 1602 // TODO(thestig) This should be a straight pass-through, but print preview |
| 1595 // does not currently support short-edge printing. | 1603 // does not currently support short-edge printing. |
| 1596 switch (preset_options.duplexMode) { | 1604 switch (preset_options.duplexMode) { |
| 1597 case blink::WebSimplex: | 1605 case blink::WebSimplex: |
| 1598 options->duplex = SIMPLEX; | 1606 options->duplex = SIMPLEX; |
| 1599 break; | 1607 break; |
| 1600 case blink::WebLongEdge: | 1608 case blink::WebLongEdge: |
| 1601 options->duplex = LONG_EDGE; | 1609 options->duplex = LONG_EDGE; |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2252 blink::WebConsoleMessage::LevelWarning, message)); | 2260 blink::WebConsoleMessage::LevelWarning, message)); |
| 2253 return false; | 2261 return false; |
| 2254 } | 2262 } |
| 2255 | 2263 |
| 2256 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2264 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2257 // Reset counter on successful print. | 2265 // Reset counter on successful print. |
| 2258 count_ = 0; | 2266 count_ = 0; |
| 2259 } | 2267 } |
| 2260 | 2268 |
| 2261 } // namespace printing | 2269 } // namespace printing |
| OLD | NEW |