Add enums for a "fit to paper" scaling print setting
The new enum values (added to Blink and Pepper) will be handled properly by the PDF plugin, but we want to avoid passing it to any other plugins, notably Flash. Accordingly, a previous CL [1] exposed to the UI whether the content being printed is a PDF to prevent the new scaling option for Flash. Additionally, this CL adds a check in PepperPluginInstanceImpl::PrintBegin() to avoid sending the new enum to a non-PDF plugin. A future CL will implement the functionality of "fit to paper" scaling and another will add an option to the UI. [1] https://chromium-review.googlesource.com/c/chromium/src/+/1788484 Bug: 989978 Change-Id: I91e821f8d04d1da0fb718b71fb7f331e45dfed07 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1780961 Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Reviewed-by: Raymes Khoury <raymes@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#698031}
This commit is contained in:

committed by
Commit Bot

parent
0a388f2006
commit
7f2909c480
components/printing/renderer
content/renderer/pepper
ppapi
printing
third_party/blink/public/web
@ -449,10 +449,20 @@ gfx::Size GetPdfPageSize(const gfx::Size& page_size, int dpi) {
|
||||
}
|
||||
|
||||
bool FitToPageEnabled(const base::DictionaryValue& job_settings) {
|
||||
bool fit_to_paper_size = false;
|
||||
if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) {
|
||||
bool fit_to_page_size = false;
|
||||
if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_page_size)) {
|
||||
NOTREACHED();
|
||||
}
|
||||
return fit_to_page_size;
|
||||
}
|
||||
|
||||
bool FitToPaperEnabled(const base::DictionaryValue& job_settings) {
|
||||
bool fit_to_paper_size = false;
|
||||
if (!job_settings.GetBoolean(kSettingFitToPaperEnabled, &fit_to_paper_size)) {
|
||||
// TODO(dhoss): Bug 989978: Should be NOTREACHED(). Will fix when
|
||||
// |job_settings| contains a "fitToPaperEnabled" boolean field.
|
||||
return false;
|
||||
}
|
||||
return fit_to_paper_size;
|
||||
}
|
||||
|
||||
@ -480,12 +490,20 @@ blink::WebPrintScalingOption GetPrintScalingOption(
|
||||
return blink::kWebPrintScalingOptionSourceSize;
|
||||
|
||||
if (!source_is_html) {
|
||||
if (!FitToPageEnabled(job_settings))
|
||||
bool fit_to_page = FitToPageEnabled(job_settings);
|
||||
bool fit_to_paper = FitToPaperEnabled(job_settings);
|
||||
|
||||
// The following conditions are ordered for an optimization that avoids
|
||||
// calling PDFShouldDisableScaling(), which has to make a call using PPAPI.
|
||||
if (!fit_to_page && !fit_to_paper)
|
||||
return blink::kWebPrintScalingOptionNone;
|
||||
|
||||
bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params, true);
|
||||
if (params.is_first_request && no_plugin_scaling)
|
||||
return blink::kWebPrintScalingOptionNone;
|
||||
|
||||
if (fit_to_paper)
|
||||
return blink::kWebPrintScalingOptionFitToPaper;
|
||||
}
|
||||
return blink::kWebPrintScalingOptionFitToPrintableArea;
|
||||
}
|
||||
|
@ -293,6 +293,8 @@ STATIC_ASSERT_ENUM(blink::kWebPrintScalingOptionFitToPrintableArea,
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA);
|
||||
STATIC_ASSERT_ENUM(blink::kWebPrintScalingOptionSourceSize,
|
||||
PP_PRINTSCALINGOPTION_SOURCE_SIZE);
|
||||
STATIC_ASSERT_ENUM(blink::kWebPrintScalingOptionFitToPaper,
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PAPER);
|
||||
|
||||
#undef STATIC_ASSERT_ENUM
|
||||
|
||||
@ -1959,6 +1961,11 @@ int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) {
|
||||
num_pages = plugin_pdf_interface_->PrintBegin(
|
||||
pp_instance(), &print_settings, &pdf_print_settings);
|
||||
} else {
|
||||
// If the content is not from the PDF plugin, "fit to paper" should have
|
||||
// never been a scaling option for the user to begin with.
|
||||
DCHECK_NE(print_settings.print_scaling_option,
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PAPER);
|
||||
|
||||
num_pages = plugin_print_interface_->Begin(pp_instance(), &print_settings);
|
||||
}
|
||||
if (!num_pages)
|
||||
|
@ -29,7 +29,8 @@ enum PP_PrintScalingOption_Dev {
|
||||
PP_PRINTSCALINGOPTION_NONE = 0,
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA = 1,
|
||||
PP_PRINTSCALINGOPTION_SOURCE_SIZE = 2,
|
||||
PP_PRINTSCALINGOPTION_LAST = PP_PRINTSCALINGOPTION_SOURCE_SIZE
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PAPER = 3,
|
||||
PP_PRINTSCALINGOPTION_LAST = PP_PRINTSCALINGOPTION_FIT_TO_PAPER
|
||||
};
|
||||
|
||||
[assert_size(60)]
|
||||
|
@ -3,7 +3,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/* From dev/pp_print_settings_dev.idl modified Wed Oct 25 09:45:07 2017. */
|
||||
/* From dev/pp_print_settings_dev.idl modified Tue Sep 3 14:00:26 2019. */
|
||||
|
||||
#ifndef PPAPI_C_DEV_PP_PRINT_SETTINGS_DEV_H_
|
||||
#define PPAPI_C_DEV_PP_PRINT_SETTINGS_DEV_H_
|
||||
@ -46,7 +46,8 @@ typedef enum {
|
||||
PP_PRINTSCALINGOPTION_NONE = 0,
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA = 1,
|
||||
PP_PRINTSCALINGOPTION_SOURCE_SIZE = 2,
|
||||
PP_PRINTSCALINGOPTION_LAST = PP_PRINTSCALINGOPTION_SOURCE_SIZE
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PAPER = 3,
|
||||
PP_PRINTSCALINGOPTION_LAST = PP_PRINTSCALINGOPTION_FIT_TO_PAPER
|
||||
} PP_PrintScalingOption_Dev;
|
||||
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PrintScalingOption_Dev, 4);
|
||||
/**
|
||||
|
@ -67,6 +67,10 @@ const char kSettingDuplexMode[] = "duplex";
|
||||
// selected else false.
|
||||
const char kSettingFitToPageEnabled[] = "fitToPageEnabled";
|
||||
|
||||
// Option to fit source page contents to paper size: true if
|
||||
// selected else false.
|
||||
const char kSettingFitToPaperEnabled[] = "fitToPaperEnabled";
|
||||
|
||||
// Option to print headers and Footers: true if selected, false if not.
|
||||
const char kSettingHeaderFooterEnabled[] = "headerFooterEnabled";
|
||||
|
||||
|
@ -29,6 +29,7 @@ PRINTING_EXPORT extern const char kSettingDpiVertical[];
|
||||
PRINTING_EXPORT extern const char kSettingDuplexMode[];
|
||||
PRINTING_EXPORT extern const char kSettingFitToPageEnabled[];
|
||||
PRINTING_EXPORT extern const char kSettingFitToPageScaling[];
|
||||
PRINTING_EXPORT extern const char kSettingFitToPaperEnabled[];
|
||||
PRINTING_EXPORT extern const char kSettingHeaderFooterEnabled[];
|
||||
PRINTING_EXPORT extern const float kSettingHeaderFooterInterstice;
|
||||
PRINTING_EXPORT extern const char kSettingHeaderFooterDate[];
|
||||
|
@ -43,7 +43,9 @@ enum WebPrintScalingOption {
|
||||
kWebPrintScalingOptionSourceSize, // Print output page size is same as the
|
||||
// actual source page size. Do not
|
||||
// scale/center/fit to printable area.
|
||||
kWebPrintScalingOptionLast = kWebPrintScalingOptionSourceSize
|
||||
kWebPrintScalingOptionFitToPaper, // Reduces or enlarges each page to fit the
|
||||
// selected printer paper size.
|
||||
kWebPrintScalingOptionLast = kWebPrintScalingOptionFitToPaper
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
Reference in New Issue
Block a user