Bug 1673713 - Part 2: Pages per sheet option behind a pref r=sfoster,fluent-reviewers,flod

This adds the pages per sheet option behind the print.pages_per_sheet.enabled
pref. Sizes of 2 and 6 aren't supported yet, so this is off by default.

Differential Revision: https://phabricator.services.mozilla.com/D95335
This commit is contained in:
Mark Striemer 2020-11-30 22:46:46 +00:00
Родитель 8a4e6bf3a5
Коммит 14475634e9
6 изменённых файлов: 97 добавлений и 3 удалений

Просмотреть файл

@ -9028,6 +9028,12 @@
value: @IS_EARLY_BETA_OR_EARLIER@
mirror: always
# Whether the pages per sheet print setting is enabled.
- name: print.pages_per_sheet.enabled
type: RelaxedAtomicBool
value: false
mirror: always
# Whether we allow the print progress dialog to show up.
- name: print.show_print_progress
type: RelaxedAtomicBool

Просмотреть файл

@ -163,6 +163,16 @@
<scale-input></scale-input>
</section>
<section id="pages-per-sheet" class="section-block" hidden>
<label id="pages-per-sheet-label" class="block-label" data-l10n-id="printui-pages-per-sheet"></label>
<select is="setting-select" id="pages-per-sheet-picker" class="row" data-setting-name="numPagesPerSheet">
<option value="1">1</option>
<option value="4">4</option>
<option value="9">9</option>
<option value="16">16</option>
</select>
</section>
<section id="margins" class="section-block">
<label for="margins-select" class="block-label" data-l10n-id="printui-margins"></label>
<div id="margins-select" is="margins-select" class="margins-select row"></div>

Просмотреть файл

@ -148,7 +148,7 @@ var PrintEventHandler = {
// These settings do not have an associated pref value or flag, but
// changing them requires us to update the print preview.
_nonFlaggedUpdatePreviewSettings: new Set(["pageRanges"]),
_nonFlaggedUpdatePreviewSettings: new Set(["pageRanges", "numPagesPerSheet"]),
async init() {
Services.telemetry.scalarAdd("printing.preview_opened_tm", 1);
@ -1546,6 +1546,10 @@ class PrintUIForm extends PrintUIControlMixin(HTMLFormElement) {
// Move the Print button to the end if this isn't Windows.
this.printButton.parentElement.append(this.printButton);
}
this.querySelector("#pages-per-sheet").hidden = !Services.prefs.getBoolPref(
"print.pages_per_sheet.enabled",
false
);
}
requestPrint() {

Просмотреть файл

@ -117,3 +117,73 @@ add_task(async function testSheetCountPageRange() {
is(sheets, 2, "There are now only 2 pages shown");
});
});
add_task(async function testPagesPerSheetCount() {
await PrintHelper.withTestPage(async helper => {
let mockPrinterName = "A real printer!";
helper.addMockPrinter(mockPrinterName);
await SpecialPowers.pushPrefEnv({
set: [
["print.pages_per_sheet.enabled", true],
["print_printer", mockPrinterName],
],
});
await helper.startPrint();
await helper.waitForPreview(() =>
helper.dispatchSettingsChange({
shrinkToFit: false,
scaling: 2,
})
);
let sheetCount = helper.get("sheet-count");
let sheets = getSheetCount(sheetCount);
ok(sheets > 1, "There are multiple pages");
await helper.openMoreSettings();
let pagesPerSheet = helper.get("pages-per-sheet-picker");
ok(BrowserTestUtils.is_visible(pagesPerSheet), "Pages per sheet is shown");
pagesPerSheet.focus();
EventUtils.sendKey("space", helper.win);
for (let i = 0; i < 5; i++) {
EventUtils.sendKey("down", helper.win);
if (pagesPerSheet.value == 16) {
break;
}
}
await helper.waitForPreview(() => EventUtils.sendKey("return", helper.win));
sheets = getSheetCount(sheetCount);
is(sheets, 1, "There's only one sheet now");
await helper.waitForSettingsEvent(() =>
helper.dispatchSettingsChange({ numCopies: 5 })
);
sheets = getSheetCount(sheetCount);
is(sheets, 5, "Copies are handled with pages per sheet correctly");
await helper.closeDialog();
});
});
add_task(async function testPagesPerSheetPref() {
await SpecialPowers.pushPrefEnv({
set: [["print.pages_per_sheet.enabled", false]],
});
await PrintHelper.withTestPage(async helper => {
await helper.startPrint();
ok(
BrowserTestUtils.is_hidden(helper.get("pages-per-sheet")),
"Pages per sheet is hidden"
);
await helper.closeDialog();
});
});

Просмотреть файл

@ -265,8 +265,10 @@ class PrintHelper {
await BrowserTestUtils.waitForEvent(this.doc, "preview-updated");
}
async waitForSettingsEvent() {
await BrowserTestUtils.waitForEvent(this.doc, "print-settings");
async waitForSettingsEvent(changeFn) {
let changed = BrowserTestUtils.waitForEvent(this.doc, "print-settings");
await changeFn?.();
await changed;
}
click(el, { scroll = true } = {}) {

Просмотреть файл

@ -87,6 +87,8 @@ printui-loading = Preparing Preview
printui-preview-label =
.aria-label = Print Preview
printui-pages-per-sheet = Pages per sheet
## Paper sizes that may be supported by the Save to PDF destination:
printui-paper-a5 = A5