Commit 1120f472 authored by Mark Striemer's avatar Mark Striemer
Browse files

Bug 1669725 - Hide print settings that don't apply to PDF for PDFs r=sfoster

Differential Revision: https://phabricator.services.mozilla.com/D98679
parent b0ea773e
......@@ -176,11 +176,11 @@
<section id="more-settings-options" class="section-block">
<label class="block-label" data-l10n-id="printui-options"></label>
<div class="row cols-2">
<div id="headers-footers" class="row cols-2">
<input is="setting-checkbox" type="checkbox" id="headers-footers-enabled" data-setting-name="printFootersHeaders">
<label for="headers-footers-enabled" data-l10n-id="printui-headers-footers-checkbox"></label>
</div>
<div class="row cols-2">
<div id="backgrounds" class="row cols-2">
<input is="setting-checkbox" type="checkbox" id="backgrounds-enabled" data-setting-name="printBackgrounds">
<label for="backgrounds-enabled" data-l10n-id="printui-backgrounds-checkbox"></label>
</div>
......
......@@ -20,6 +20,7 @@ ChromeUtils.defineModuleGetter(
"resource://gre/modules/DeferredTask.jsm"
);
const PDF_JS_URI = "resource://pdf.js/web/viewer.html";
const INPUT_DELAY_MS = Cu.isInAutomation ? 100 : 500;
const MM_PER_POINT = 25.4 / 72;
const INCHES_PER_POINT = 1 / 72;
......@@ -171,12 +172,19 @@ var PrintEventHandler = {
existingBrowser.remove();
}
let sourcePrincipal =
sourceBrowsingContext.currentWindowGlobal.documentPrincipal;
let sourceIsPdf =
!sourcePrincipal.isNullPrincipal && sourcePrincipal.spec == PDF_JS_URI;
this.originalSourceContentTitle =
sourceBrowsingContext.currentWindowContext.documentTitle;
this.originalSourceCurrentURI =
sourceBrowsingContext.currentWindowContext.documentURI.spec;
this.printForm = document.getElementById("print");
if (sourceIsPdf) {
this.printForm.removeNonPdfSettings();
}
// Let the dialog appear before doing any potential main thread work.
await ourBrowser._dialogReady;
......@@ -1674,6 +1682,17 @@ class PrintUIForm extends PrintUIControlMixin(HTMLFormElement) {
);
}
removeNonPdfSettings() {
let selectors = ["#margins", "#headers-footers", "#backgrounds"];
for (let selector of selectors) {
this.querySelector(selector).remove();
}
let moreSettings = this.querySelector("#more-settings-options");
if (moreSettings.children.length <= 1) {
moreSettings.remove();
}
}
requestPrint() {
this.requestSubmit(this.printButton);
}
......
......@@ -17,6 +17,9 @@ support-files =
file_page_change_print_original_2.html
skip-if = os == "mac"
[browser_pdf_hidden_settings.js]
support-files =
file_pdf.pdf
[browser_print_paper_sizes.js]
[browser_pdf_printer_settings.js]
[browser_print_bcg_id_overflow.js]
......
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const hiddenPdfIds = [
"margins",
"backgrounds",
"headers-footers",
"more-settings-options",
];
async function checkElements({ removed, file, testName }) {
await PrintHelper.withTestPage(async helper => {
await helper.startPrint();
for (let id of hiddenPdfIds) {
is(
!helper.get(id),
removed,
`${id} is ${removed ? "" : "not "}removed (${testName})`
);
}
await helper.closeDialog();
}, file);
}
add_task(async function testSettingsShownForNonPdf() {
await checkElements({ removed: false, testName: "non-pdf" });
});
add_task(async function testSettingsHiddenForPdf() {
await checkElements({
removed: true,
file: "file_pdf.pdf",
testName: "pdf",
});
});
......@@ -8,17 +8,43 @@ class PrintHelper {
await SpecialPowers.pushPrefEnv({
set: [["print.tab_modal.enabled", true]],
});
let pageUrl = pagePathname
? this.getTestPageUrl(pagePathname)
: this.defaultTestPageUrl;
info("withTestPage: " + pageUrl);
let taskReturn = await BrowserTestUtils.withNewTab(pageUrl, async function(
browser
) {
await testFn(new PrintHelper(browser));
});
let isPdf = pageUrl.endsWith(".pdf");
if (isPdf) {
await SpecialPowers.pushPrefEnv({
set: [["pdfjs.eventBusDispatchToDOM", true]],
});
}
let taskReturn = await BrowserTestUtils.withNewTab(
isPdf ? "about:blank" : pageUrl,
async function(browser) {
if (isPdf) {
let loaded = BrowserTestUtils.waitForContentEvent(
browser,
"documentloaded",
false,
null,
true
);
await SpecialPowers.spawn(browser, [pageUrl], contentUrl => {
content.location = contentUrl;
});
await loaded;
}
await testFn(new PrintHelper(browser));
}
);
await SpecialPowers.popPrefEnv();
if (isPdf) {
await SpecialPowers.popPrefEnv();
}
// Reset all of the other printing prefs to their default.
for (let name of Services.prefs.getChildList("print.")) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment