зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1664570: implement custom margins in new print UI r=sfoster,mstriemer,fluent-reviewers,flod
Differential Revision: https://phabricator.services.mozilla.com/D90636
This commit is contained in:
Родитель
5cf3dce38d
Коммит
6c274b34d0
|
@ -271,6 +271,23 @@ input[type="text"] {
|
|||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.vertical-margins,
|
||||
.horizontal-margins {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-block: 5px;
|
||||
}
|
||||
|
||||
.margin-input {
|
||||
width: 6em !important;
|
||||
}
|
||||
|
||||
.margin-descriptor {
|
||||
text-align: center;
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
input[type="number"]:invalid {
|
||||
border: 1px solid #D70022;
|
||||
box-shadow: 0 0 0 1px #D70022, 0 0 0 4px rgba(215, 0, 34, 0.3);
|
||||
|
|
|
@ -76,6 +76,38 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<template id="margins-template">
|
||||
<select is="margins-select" id="margins-picker" name="margin-type" class="row" data-setting-name="margins">
|
||||
<option value="default" data-l10n-id="printui-margins-default"></option>
|
||||
<option value="minimum" data-l10n-id="printui-margins-min"></option>
|
||||
<option value="none" data-l10n-id="printui-margins-none"></option>
|
||||
<option value="custom" data-l10n-id="printui-margins-custom"></option>
|
||||
</select>
|
||||
<div id="custom-margins" class="margin-group" hidden>
|
||||
<div class="vertical-margins">
|
||||
<div class="margin-pair">
|
||||
<input id="custom-margin-top" type="number" class="margin-input photon-number" min="0" step="0.01" autocomplete="off" required>
|
||||
<label for="custom-margin-top" class="margin-descriptor" data-l10n-id="printui-margins-custom-top"></label>
|
||||
</div>
|
||||
<div class="margin-pair">
|
||||
<input id="custom-margin-bottom" type="number" class="margin-input photon-number" min="0" step="0.01" autocomplete="off" required>
|
||||
<label for="custom-margin-bottom" class="margin-descriptor" data-l10n-id="printui-margins-custom-bottom"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="horizontal-margins">
|
||||
<div class="margin-pair">
|
||||
<input id="custom-margin-left" type="number" class="margin-input photon-number" min="0" step="0.01" autocomplete="off" required>
|
||||
<label for="custom-margin-left" class="margin-descriptor" data-l10n-id="printui-margins-custom-left"></label>
|
||||
</div>
|
||||
<div class="margin-pair">
|
||||
<input id="custom-margin-right" type="number" class="margin-input photon-number" min="0" step="0.01" autocomplete="off" required>
|
||||
<label for="custom-margin-right" class="margin-descriptor" data-l10n-id="printui-margins-custom-right"></label>
|
||||
</div>
|
||||
</div>
|
||||
<p id="error-invalid-margin" hidden data-l10n-id="printui-error-invalid-margin" class="error-message" role="alert"></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<header class="header-container" role="none">
|
||||
<h2 data-l10n-id="printui-title"></h2>
|
||||
<div aria-live="off">
|
||||
|
@ -132,12 +164,8 @@
|
|||
</section>
|
||||
|
||||
<section id="margins" class="section-block">
|
||||
<label for="margins-picker" class="block-label" data-l10n-id="printui-margins"></label>
|
||||
<select is="margins-select" id="margins-picker" class="row" data-setting-name="margins">
|
||||
<option value="default" data-l10n-id="printui-margins-default"></option>
|
||||
<option value="minimum" data-l10n-id="printui-margins-min"></option>
|
||||
<option value="none" data-l10n-id="printui-margins-none"></option>
|
||||
</select>
|
||||
<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>
|
||||
</section>
|
||||
|
||||
<section id="more-settings-options" class="section-block">
|
||||
|
|
|
@ -111,6 +111,7 @@ var PrintEventHandler = {
|
|||
_userChangedSettings: {},
|
||||
settingFlags: {
|
||||
margins: Ci.nsIPrintSettings.kInitSaveMargins,
|
||||
customMargins: Ci.nsIPrintSettings.kInitSaveMargins,
|
||||
orientation: Ci.nsIPrintSettings.kInitSaveOrientation,
|
||||
paperId:
|
||||
Ci.nsIPrintSettings.kInitSavePaperSize |
|
||||
|
@ -377,7 +378,10 @@ var PrintEventHandler = {
|
|||
// Some settings are only used by the UI
|
||||
// assigning new values should update the underlying settings
|
||||
this.viewSettings = new Proxy(this.settings, PrintSettingsViewProxy);
|
||||
return this.getSettingsToUpdate();
|
||||
},
|
||||
|
||||
getSettingsToUpdate() {
|
||||
// Get the previously-changed settings we want to try to use on this printer
|
||||
let settingsToUpdate = Object.assign({}, this._userChangedSettings);
|
||||
|
||||
|
@ -439,6 +443,28 @@ var PrintEventHandler = {
|
|||
delete this._userChangedSettings.paperId;
|
||||
settingsToUpdate.paperId = matchedPaper.id;
|
||||
}
|
||||
|
||||
// See if we need to change the custom margin values
|
||||
if (
|
||||
parseFloat(this.viewSettings.customMargins.marginTop) +
|
||||
parseFloat(this.viewSettings.customMargins.marginBottom) >
|
||||
paperHeight
|
||||
) {
|
||||
let { marginTop, marginBottom } = this.viewSettings.defaultMargins;
|
||||
settingsToUpdate.marginTop = settingsToUpdate.customMargins.marginTop = marginTop;
|
||||
settingsToUpdate.marginBottom = settingsToUpdate.customMargins.marginBottom = marginBottom;
|
||||
}
|
||||
|
||||
if (
|
||||
parseFloat(this.viewSettings.customMargins.marginRight) +
|
||||
parseFloat(this.viewSettings.customMargins.marginLeft) >
|
||||
paperWidth
|
||||
) {
|
||||
let { marginLeft, marginRight } = this.viewSettings.defaultMargins;
|
||||
settingsToUpdate.marginLeft = settingsToUpdate.customMargins.marginLeft = marginLeft;
|
||||
settingsToUpdate.marginRight = settingsToUpdate.customMargins.marginRight = marginRight;
|
||||
}
|
||||
|
||||
return settingsToUpdate;
|
||||
},
|
||||
|
||||
|
@ -461,7 +487,10 @@ var PrintEventHandler = {
|
|||
// Treat a printerName change separately, because it involves a settings
|
||||
// object switch and we don't want to set the new name on the old settings.
|
||||
changedSettings = await this.refreshSettings(changedSettings.printerName);
|
||||
} else {
|
||||
changedSettings = this.getSettingsToUpdate();
|
||||
}
|
||||
|
||||
let shouldPreviewUpdate = await this.updateSettings(
|
||||
changedSettings,
|
||||
!!changedSettings.printerName
|
||||
|
@ -709,6 +738,21 @@ var PrintEventHandler = {
|
|||
marginBottom: 0,
|
||||
marginRight: 0,
|
||||
};
|
||||
case "custom":
|
||||
return {
|
||||
marginTop:
|
||||
PrintSettingsViewProxy._lastCustomMarginValues.marginTop ??
|
||||
this.settings.marginTop,
|
||||
marginBottom:
|
||||
PrintSettingsViewProxy._lastCustomMarginValues.marginBottom ??
|
||||
this.settings.marginBottom,
|
||||
marginLeft:
|
||||
PrintSettingsViewProxy._lastCustomMarginValues.marginLeft ??
|
||||
this.settings.marginLeft,
|
||||
marginRight:
|
||||
PrintSettingsViewProxy._lastCustomMarginValues.marginRight ??
|
||||
this.settings.marginRight,
|
||||
};
|
||||
default: {
|
||||
let minimum = this.getMarginPresets("minimum", paper);
|
||||
return {
|
||||
|
@ -777,6 +821,15 @@ var PrintSettingsViewProxy = {
|
|||
headerStrRight: "print.print_headerright",
|
||||
},
|
||||
|
||||
// Custom margins are not saved by a pref, so we need to keep track of them
|
||||
// in order to save the value.
|
||||
_lastCustomMarginValues: {
|
||||
marginTop: null,
|
||||
marginBottom: null,
|
||||
marginLeft: null,
|
||||
marginRight: null,
|
||||
},
|
||||
|
||||
// This list was taken from nsDeviceContextSpecWin.cpp which records telemetry on print target type
|
||||
knownSaveToFilePrinters: new Set([
|
||||
"Microsoft Print to PDF",
|
||||
|
@ -964,13 +1017,14 @@ var PrintSettingsViewProxy = {
|
|||
none: PrintEventHandler.getMarginPresets("none", paperSize),
|
||||
minimum: PrintEventHandler.getMarginPresets("minimum", paperSize),
|
||||
default: PrintEventHandler.getMarginPresets("default", paperSize),
|
||||
custom: PrintEventHandler.getMarginPresets("custom", paperSize),
|
||||
};
|
||||
|
||||
case "marginOptions": {
|
||||
let allMarginPresets = this.get(target, "marginPresets");
|
||||
let uniqueMargins = new Set();
|
||||
let marginsEnabled = {};
|
||||
for (let name of ["none", "default", "minimum"]) {
|
||||
for (let name of ["none", "default", "minimum", "custom"]) {
|
||||
let {
|
||||
marginTop,
|
||||
marginLeft,
|
||||
|
@ -980,7 +1034,8 @@ var PrintSettingsViewProxy = {
|
|||
let key = [marginTop, marginLeft, marginBottom, marginRight].join(
|
||||
","
|
||||
);
|
||||
marginsEnabled[name] = !uniqueMargins.has(key);
|
||||
// Custom margins are initialized to default margins
|
||||
marginsEnabled[name] = !uniqueMargins.has(key) || name == "custom";
|
||||
uniqueMargins.add(key);
|
||||
}
|
||||
return marginsEnabled;
|
||||
|
@ -993,9 +1048,9 @@ var PrintSettingsViewProxy = {
|
|||
marginBottom: target.marginBottom,
|
||||
marginRight: target.marginRight,
|
||||
};
|
||||
// see if they match the none and then minimum margin values
|
||||
// see if they match the none, minimum, or default margin values
|
||||
let allMarginPresets = this.get(target, "marginPresets");
|
||||
for (let presetName of ["none", "minimum"]) {
|
||||
for (let presetName of ["none", "minimum", "default"]) {
|
||||
let marginPresets = allMarginPresets[presetName];
|
||||
if (
|
||||
Object.keys(marginSettings).every(
|
||||
|
@ -1007,8 +1062,21 @@ var PrintSettingsViewProxy = {
|
|||
return presetName;
|
||||
}
|
||||
}
|
||||
// Fall back to the default for any other values
|
||||
return "default";
|
||||
|
||||
// Fall back to custom for other values
|
||||
return "custom";
|
||||
|
||||
case "defaultMargins":
|
||||
return PrintEventHandler.getMarginPresets(
|
||||
"default",
|
||||
this.get(target, "currentPaper")
|
||||
);
|
||||
|
||||
case "customMargins":
|
||||
return PrintEventHandler.getMarginPresets(
|
||||
"custom",
|
||||
this.get(target, "currentPaper")
|
||||
);
|
||||
|
||||
case "paperSizes":
|
||||
return Object.values(this.availablePaperSizes)
|
||||
|
@ -1062,7 +1130,7 @@ var PrintSettingsViewProxy = {
|
|||
set(target, name, value) {
|
||||
switch (name) {
|
||||
case "margins":
|
||||
if (!["default", "minimum", "none"].includes(value)) {
|
||||
if (!["default", "minimum", "none", "custom"].includes(value)) {
|
||||
logger.warn("Unexpected margin preset name: ", value);
|
||||
value = "default";
|
||||
}
|
||||
|
@ -1113,6 +1181,13 @@ var PrintSettingsViewProxy = {
|
|||
: Ci.nsIPrintSettings.kRangeSpecifiedPageRange;
|
||||
break;
|
||||
|
||||
case "customMargins":
|
||||
for (let [settingName, newVal] of Object.entries(value)) {
|
||||
target[settingName] = newVal;
|
||||
this._lastCustomMarginValues[settingName] = newVal;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
target[name] = value;
|
||||
}
|
||||
|
@ -1163,12 +1238,10 @@ function PrintUIControlMixin(superClass) {
|
|||
|
||||
handleKeypress(e) {
|
||||
let char = String.fromCharCode(e.charCode);
|
||||
if (
|
||||
!char.match(/^[0-9]$/) &&
|
||||
!char.match("\x00") &&
|
||||
!e.ctrlKey &&
|
||||
!e.metaKey
|
||||
) {
|
||||
let acceptedChar = e.target.step.includes(".")
|
||||
? char.match(/^[0-9.]$/)
|
||||
: char.match(/^[0-9]$/);
|
||||
if (!acceptedChar && !char.match("\x00") && !e.ctrlKey && !e.metaKey) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
@ -1177,11 +1250,12 @@ function PrintUIControlMixin(superClass) {
|
|||
let paste = (e.clipboardData || window.clipboardData)
|
||||
.getData("text")
|
||||
.trim();
|
||||
|
||||
if (paste.match(/^[0-9]*$/)) {
|
||||
e.target.value = paste;
|
||||
let acceptedChars = e.target.step.includes(".")
|
||||
? paste.match(/^[0-9.]*$/)
|
||||
: paste.match(/^[0-9]*$/);
|
||||
if (!acceptedChars) {
|
||||
e.preventDefault();
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
handleEvent(event) {}
|
||||
|
@ -1270,27 +1344,6 @@ customElements.define("color-mode-select", ColorModePicker, {
|
|||
extends: "select",
|
||||
});
|
||||
|
||||
class MarginsPicker extends PrintSettingSelect {
|
||||
update(settings) {
|
||||
// Re-evaluate which margin options should be enabled whenever the printer or paper changes
|
||||
if (
|
||||
settings.paperId !== this._paperId ||
|
||||
settings.printerName !== this._printerName
|
||||
) {
|
||||
let enabledMargins = settings.marginOptions;
|
||||
for (let option of this.options) {
|
||||
option.hidden = !enabledMargins[option.value];
|
||||
}
|
||||
this._paperId = settings.paperId;
|
||||
this._printerName = settings.printerName;
|
||||
}
|
||||
super.update(settings);
|
||||
}
|
||||
}
|
||||
customElements.define("margins-select", MarginsPicker, {
|
||||
extends: "select",
|
||||
});
|
||||
|
||||
class PaperSizePicker extends PrintSettingSelect {
|
||||
initialize() {
|
||||
super.initialize();
|
||||
|
@ -1691,6 +1744,183 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
}
|
||||
customElements.define("page-range-input", PageRangeInput);
|
||||
|
||||
class MarginsPicker extends PrintUIControlMixin(HTMLElement) {
|
||||
initialize() {
|
||||
super.initialize();
|
||||
|
||||
this._marginPicker = this.querySelector("#margins-picker");
|
||||
this._customTopMargin = this.querySelector("#custom-margin-top");
|
||||
this._customBottomMargin = this.querySelector("#custom-margin-bottom");
|
||||
this._customLeftMargin = this.querySelector("#custom-margin-left");
|
||||
this._customRightMargin = this.querySelector("#custom-margin-right");
|
||||
this._marginError = this.querySelector("#error-invalid-margin");
|
||||
|
||||
this._updateMarginTask = createDeferredTask(
|
||||
() => this.updateMargins(),
|
||||
INPUT_DELAY_MS
|
||||
);
|
||||
|
||||
this.addEventListener("input", this);
|
||||
this.addEventListener("keypress", this);
|
||||
this.addEventListener("paste", this);
|
||||
}
|
||||
|
||||
get templateId() {
|
||||
return "margins-template";
|
||||
}
|
||||
|
||||
updateMargins() {
|
||||
let newMargins = {
|
||||
marginTop: this._customTopMargin.value,
|
||||
marginBottom: this._customBottomMargin.value,
|
||||
marginLeft: this._customLeftMargin.value,
|
||||
marginRight: this._customRightMargin.value,
|
||||
};
|
||||
|
||||
this.dispatchSettingsChange({
|
||||
customMargins: newMargins,
|
||||
});
|
||||
}
|
||||
|
||||
formatMargin(target) {
|
||||
if (target.value.includes(".")) {
|
||||
if (target.value.split(".")[1].length > 2) {
|
||||
let dotIndex = target.value.indexOf(".");
|
||||
target.value = target.value.slice(0, dotIndex + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setAllMarginValues(settings) {
|
||||
this._customTopMargin.value = parseFloat(
|
||||
settings.customMargins.marginTop
|
||||
).toFixed(2);
|
||||
this._customBottomMargin.value = parseFloat(
|
||||
settings.customMargins.marginBottom
|
||||
).toFixed(2);
|
||||
this._customLeftMargin.value = parseFloat(
|
||||
settings.customMargins.marginLeft
|
||||
).toFixed(2);
|
||||
this._customRightMargin.value = parseFloat(
|
||||
settings.customMargins.marginRight
|
||||
).toFixed(2);
|
||||
}
|
||||
|
||||
update(settings) {
|
||||
// Re-evaluate which margin options should be enabled whenever the printer or paper changes
|
||||
if (
|
||||
settings.paperId !== this._paperId ||
|
||||
settings.printerName !== this._printerName
|
||||
) {
|
||||
let enabledMargins = settings.marginOptions;
|
||||
for (let option of this._marginPicker.options) {
|
||||
option.hidden = !enabledMargins[option.value];
|
||||
}
|
||||
this._paperId = settings.paperId;
|
||||
this._printerName = settings.printerName;
|
||||
|
||||
this._maxHeight =
|
||||
settings.paperHeight -
|
||||
settings.unwriteableMarginTop -
|
||||
settings.unwriteableMarginBottom;
|
||||
this._maxWidth =
|
||||
settings.paperWidth -
|
||||
settings.unwriteableMarginLeft -
|
||||
settings.unwriteableMarginRight;
|
||||
|
||||
this._defaultPresets = settings.defaultMargins;
|
||||
// The values in custom fields should be initialized to custom margin values
|
||||
// and must be overriden if they are no longer valid.
|
||||
this.setAllMarginValues(settings);
|
||||
}
|
||||
|
||||
// We need to ensure we don't override the value if the value should be custom.
|
||||
if (this._marginPicker.value != "custom") {
|
||||
// Reset the custom margin values if they are not valid and revalidate the form
|
||||
if (
|
||||
!this._customTopMargin.checkValidity() ||
|
||||
!this._customBottomMargin.checkValidity() ||
|
||||
!this._customLeftMargin.checkValidity() ||
|
||||
!this._customRightMargin.checkValidity()
|
||||
) {
|
||||
window.clearTimeout(this.showErrorTimeoutId);
|
||||
this.setAllMarginValues(settings);
|
||||
this.dispatchEvent(new Event("revalidate", { bubbles: true }));
|
||||
this._marginError.hidden = true;
|
||||
}
|
||||
if (settings.margins == "custom") {
|
||||
// Ensure that we display the custom margin boxes
|
||||
this.querySelector(".margin-group").hidden = false;
|
||||
}
|
||||
this._marginPicker.value = settings.margins;
|
||||
}
|
||||
|
||||
this._customTopMargin.max =
|
||||
this._maxHeight - this._customBottomMargin.value;
|
||||
this._customBottomMargin.max =
|
||||
this._maxHeight - this._customTopMargin.value;
|
||||
this._customLeftMargin.max = this._maxWidth - this._customRightMargin.value;
|
||||
this._customRightMargin.max = this._maxWidth - this._customLeftMargin.value;
|
||||
}
|
||||
|
||||
handleEvent(e) {
|
||||
if (e.type == "keypress") {
|
||||
this.handleKeypress(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.type === "paste") {
|
||||
this.handlePaste(e);
|
||||
}
|
||||
|
||||
this._updateMarginTask.disarm();
|
||||
|
||||
if (e.target == this._marginPicker) {
|
||||
let customMargin = e.target.value == "custom";
|
||||
this.querySelector(".margin-group").hidden = !customMargin;
|
||||
if (customMargin) {
|
||||
// Update the custom margin values to ensure consistency
|
||||
this.updateMargins();
|
||||
}
|
||||
|
||||
this.dispatchSettingsChange({
|
||||
margins: e.target.value,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
e.target == this._customTopMargin ||
|
||||
e.target == this._customBottomMargin ||
|
||||
e.target == this._customLeftMargin ||
|
||||
e.target == this._customRightMargin
|
||||
) {
|
||||
if (e.target.checkValidity()) {
|
||||
this.formatMargin(e.target);
|
||||
this._updateMarginTask.arm();
|
||||
} else if (e.target.validity.stepMismatch) {
|
||||
// If this is the third digit after the decimal point, we should
|
||||
// truncate the string.
|
||||
this.formatMargin(e.target);
|
||||
}
|
||||
}
|
||||
|
||||
window.clearTimeout(this.showErrorTimeoutId);
|
||||
if (
|
||||
this._customTopMargin.validity.valid &&
|
||||
this._customBottomMargin.validity.valid &&
|
||||
this._customLeftMargin.validity.valid &&
|
||||
this._customRightMargin.validity.valid
|
||||
) {
|
||||
this._marginError.hidden = true;
|
||||
} else {
|
||||
this.showErrorTimeoutId = window.setTimeout(() => {
|
||||
this._marginError.hidden = false;
|
||||
}, INPUT_DELAY_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
customElements.define("margins-select", MarginsPicker);
|
||||
|
||||
class PrintSettingNumber extends PrintUIControlMixin(HTMLInputElement) {
|
||||
connectedCallback() {
|
||||
this.type = "number";
|
||||
|
|
|
@ -14,6 +14,7 @@ support-files =
|
|||
skip-if = os == "mac"
|
||||
|
||||
[browser_pdf_printer_settings.js]
|
||||
[browser_print_margins.js]
|
||||
[browser_sheet_count.js]
|
||||
[browser_window_print.js]
|
||||
support-files =
|
||||
|
|
|
@ -0,0 +1,291 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
function changeDefaultToCustom(helper) {
|
||||
let marginSelect = helper.get("margins-picker");
|
||||
marginSelect.focus();
|
||||
EventUtils.sendKey("space", helper.win);
|
||||
EventUtils.sendKey("down", helper.win);
|
||||
EventUtils.sendKey("down", helper.win);
|
||||
EventUtils.sendKey("down", helper.win);
|
||||
EventUtils.sendKey("return", helper.win);
|
||||
}
|
||||
|
||||
function changeCustomToDefault(helper) {
|
||||
let marginSelect = helper.get("margins-picker");
|
||||
marginSelect.focus();
|
||||
EventUtils.sendKey("space", helper.win);
|
||||
EventUtils.sendKey("up", helper.win);
|
||||
EventUtils.sendKey("up", helper.win);
|
||||
EventUtils.sendKey("up", helper.win);
|
||||
EventUtils.sendKey("return", helper.win);
|
||||
}
|
||||
|
||||
function assertPendingMarginsUpdate(helper) {
|
||||
let marginsPicker = helper.get("margins-select");
|
||||
ok(marginsPicker._updateMarginTask.isArmed, "The update task is armed");
|
||||
}
|
||||
|
||||
function assertNoPendingMarginsUpdate(helper) {
|
||||
let marginsPicker = helper.get("margins-select");
|
||||
ok(!marginsPicker._updateMarginTask.isArmed, "The update task isn't armed");
|
||||
}
|
||||
|
||||
add_task(async function testPresetMargins() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
|
||||
await helper.assertSettingsChanged(
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
{ marginTop: 0.25, marginRight: 1, marginBottom: 2, marginLeft: 0.75 },
|
||||
async () => {
|
||||
let marginSelect = helper.get("margins-picker");
|
||||
let customMargins = helper.get("custom-margins");
|
||||
|
||||
ok(customMargins.hidden, "Custom margins are hidden");
|
||||
is(marginSelect.value, "default", "Default margins set");
|
||||
|
||||
this.changeDefaultToCustom(helper);
|
||||
|
||||
is(marginSelect.value, "custom", "Custom margins are now set");
|
||||
ok(!customMargins.hidden, "Custom margins are present");
|
||||
// Check that values are initialized to correct values
|
||||
is(
|
||||
helper.get("custom-margin-top").value,
|
||||
"0.50",
|
||||
"Top margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-right").value,
|
||||
"0.50",
|
||||
"Right margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-bottom").value,
|
||||
"0.50",
|
||||
"Bottom margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-left").value,
|
||||
"0.50",
|
||||
"Left margin placeholder is correct"
|
||||
);
|
||||
|
||||
await helper.awaitAnimationFrame();
|
||||
|
||||
await helper.text(helper.get("custom-margin-top"), "0.25");
|
||||
await helper.text(helper.get("custom-margin-right"), "1");
|
||||
await helper.text(helper.get("custom-margin-bottom"), "2");
|
||||
await helper.text(helper.get("custom-margin-left"), "0.75");
|
||||
|
||||
assertPendingMarginsUpdate(helper);
|
||||
|
||||
// Wait for the preview to update, the margin options delay updates by
|
||||
// INPUT_DELAY_MS, which is 500ms.
|
||||
await helper.waitForSettingsEvent();
|
||||
}
|
||||
);
|
||||
await helper.closeDialog();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testHeightError() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
this.changeDefaultToCustom(helper);
|
||||
|
||||
await helper.assertSettingsNotChanged(
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
async () => {
|
||||
let marginError = helper.get("error-invalid-margin");
|
||||
ok(marginError.hidden, "Margin error is hidden");
|
||||
|
||||
await helper.text(helper.get("custom-margin-top"), "20");
|
||||
await BrowserTestUtils.waitForAttributeRemoval("hidden", marginError);
|
||||
|
||||
ok(!marginError.hidden, "Margin error is showing");
|
||||
assertNoPendingMarginsUpdate(helper);
|
||||
}
|
||||
);
|
||||
await helper.closeDialog();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testWidthError() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
this.changeDefaultToCustom(helper);
|
||||
|
||||
await helper.assertSettingsNotChanged(
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
async () => {
|
||||
let marginError = helper.get("error-invalid-margin");
|
||||
ok(marginError.hidden, "Margin error is hidden");
|
||||
|
||||
await helper.text(helper.get("custom-margin-right"), "20");
|
||||
await BrowserTestUtils.waitForAttributeRemoval("hidden", marginError);
|
||||
|
||||
ok(!marginError.hidden, "Margin error is showing");
|
||||
assertNoPendingMarginsUpdate(helper);
|
||||
}
|
||||
);
|
||||
await helper.closeDialog();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testInvalidMarginsReset() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
this.changeDefaultToCustom(helper);
|
||||
let marginError = helper.get("error-invalid-margin");
|
||||
|
||||
await helper.assertSettingsNotChanged(
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
async () => {
|
||||
ok(marginError.hidden, "Margin error is hidden");
|
||||
|
||||
await helper.awaitAnimationFrame();
|
||||
await helper.text(helper.get("custom-margin-top"), "20");
|
||||
await helper.text(helper.get("custom-margin-right"), "20");
|
||||
assertNoPendingMarginsUpdate(helper);
|
||||
await BrowserTestUtils.waitForAttributeRemoval("hidden", marginError);
|
||||
}
|
||||
);
|
||||
|
||||
this.changeCustomToDefault(helper);
|
||||
assertNoPendingMarginsUpdate(helper);
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => marginError.hidden,
|
||||
"Wait for margin error to be hidden"
|
||||
);
|
||||
this.changeDefaultToCustom(helper);
|
||||
await helper.assertSettingsMatch({
|
||||
marginTop: 0.5,
|
||||
marginRight: 0.5,
|
||||
marginBottom: 0.5,
|
||||
marginLeft: 0.5,
|
||||
});
|
||||
|
||||
is(
|
||||
helper.get("margins-picker").value,
|
||||
"custom",
|
||||
"The custom option is selected"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-top").value,
|
||||
"0.50",
|
||||
"Top margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-right").value,
|
||||
"0.50",
|
||||
"Right margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-bottom").value,
|
||||
"0.50",
|
||||
"Bottom margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-left").value,
|
||||
"0.50",
|
||||
"Left margin placeholder is correct"
|
||||
);
|
||||
assertNoPendingMarginsUpdate(helper);
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => marginError.hidden,
|
||||
"Wait for margin error to be hidden"
|
||||
);
|
||||
await helper.closeDialog();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testCustomMarginsPersist() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
|
||||
await helper.assertSettingsChanged(
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
{ marginTop: 0.25, marginRight: 1, marginBottom: 2, marginLeft: 0 },
|
||||
async () => {
|
||||
this.changeDefaultToCustom(helper);
|
||||
await helper.awaitAnimationFrame();
|
||||
|
||||
await helper.text(helper.get("custom-margin-top"), "0.25");
|
||||
await helper.text(helper.get("custom-margin-right"), "1");
|
||||
await helper.text(helper.get("custom-margin-bottom"), "2");
|
||||
await helper.text(helper.get("custom-margin-left"), "0");
|
||||
|
||||
assertPendingMarginsUpdate(helper);
|
||||
|
||||
// Wait for the preview to update, the margin options delay updates by
|
||||
// INPUT_DELAY_MS, which is 500ms.
|
||||
await helper.waitForSettingsEvent();
|
||||
}
|
||||
);
|
||||
|
||||
await helper.closeDialog();
|
||||
|
||||
await helper.startPrint();
|
||||
await helper.openMoreSettings();
|
||||
|
||||
await helper.assertSettingsMatch({
|
||||
marginTop: 0.25,
|
||||
marginRight: 1,
|
||||
marginBottom: 2,
|
||||
marginLeft: 0,
|
||||
});
|
||||
|
||||
is(
|
||||
helper.get("margins-picker").value,
|
||||
"custom",
|
||||
"The custom option is selected"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-top").value,
|
||||
"0.25",
|
||||
"Top margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-right").value,
|
||||
"1.00",
|
||||
"Right margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-bottom").value,
|
||||
"2.00",
|
||||
"Bottom margin placeholder is correct"
|
||||
);
|
||||
is(
|
||||
helper.get("custom-margin-left").value,
|
||||
"0.00",
|
||||
"Left margin placeholder is correct"
|
||||
);
|
||||
await helper.assertSettingsChanged(
|
||||
{ marginTop: 0.25, marginRight: 1, marginBottom: 2, marginLeft: 0 },
|
||||
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
|
||||
async () => {
|
||||
await helper.awaitAnimationFrame();
|
||||
|
||||
await helper.text(helper.get("custom-margin-top"), "0.50");
|
||||
await helper.text(helper.get("custom-margin-right"), "0.50");
|
||||
await helper.text(helper.get("custom-margin-bottom"), "0.50");
|
||||
await helper.text(helper.get("custom-margin-left"), "0.50");
|
||||
|
||||
assertPendingMarginsUpdate(helper);
|
||||
|
||||
// Wait for the preview to update, the margin options delay updates by
|
||||
// INPUT_DELAY_MS, which is 500ms.
|
||||
await helper.waitForSettingsEvent();
|
||||
}
|
||||
);
|
||||
await helper.closeDialog();
|
||||
});
|
||||
});
|
|
@ -57,7 +57,15 @@ class PrintHelper {
|
|||
await dialog._closingPromise;
|
||||
}
|
||||
|
||||
resetSettings() {
|
||||
this.win.PrintEventHandler.settings = this.win.PrintEventHandler.defaultSettings;
|
||||
this.win.PrintEventHandler.saveSettingsToPrefs(
|
||||
this.win.PrintEventHandler.kInitSaveAll
|
||||
);
|
||||
}
|
||||
|
||||
async closeDialog() {
|
||||
this.resetSettings();
|
||||
await this.withClosingFn(() => this.dialog.close());
|
||||
}
|
||||
|
||||
|
@ -142,7 +150,15 @@ class PrintHelper {
|
|||
await BrowserTestUtils.waitForEvent(this.doc, "preview-updated");
|
||||
}
|
||||
|
||||
click(el) {
|
||||
async waitForSettingsEvent() {
|
||||
await BrowserTestUtils.waitForEvent(this.doc, "print-settings");
|
||||
}
|
||||
|
||||
click(el, { scroll = true } = {}) {
|
||||
if (scroll) {
|
||||
el.scrollIntoView();
|
||||
}
|
||||
ok(BrowserTestUtils.is_visible(el), "Element must be visible to click");
|
||||
EventUtils.synthesizeMouseAtCenter(el, {}, this.win);
|
||||
}
|
||||
|
||||
|
@ -173,6 +189,32 @@ class PrintHelper {
|
|||
return this.win.PrintEventHandler.viewSettings;
|
||||
}
|
||||
|
||||
assertSettingsMatch(expected) {
|
||||
let { settings } = this;
|
||||
for (let [setting, value] of Object.entries(expected)) {
|
||||
is(settings[setting], value, `${setting} matches`);
|
||||
}
|
||||
}
|
||||
|
||||
async assertSettingsChanged(from, to, changeFn) {
|
||||
is(
|
||||
Object.keys(from).length,
|
||||
Object.keys(to).length,
|
||||
"Got the same number of settings to check"
|
||||
);
|
||||
ok(
|
||||
Object.keys(from).every(s => s in to),
|
||||
"Checking the same setting names"
|
||||
);
|
||||
this.assertSettingsMatch(from);
|
||||
await changeFn();
|
||||
this.assertSettingsMatch(to);
|
||||
}
|
||||
|
||||
async assertSettingsNotChanged(settings, changeFn) {
|
||||
await this.assertSettingsChanged(settings, settings, changeFn);
|
||||
}
|
||||
|
||||
awaitAnimationFrame() {
|
||||
return new Promise(resolve => this.win.requestAnimationFrame(resolve));
|
||||
}
|
||||
|
|
|
@ -63,6 +63,11 @@ printui-margins = Margins
|
|||
printui-margins-default = Default
|
||||
printui-margins-min = Minimum
|
||||
printui-margins-none = None
|
||||
printui-margins-custom = Custom
|
||||
printui-margins-custom-top = Top
|
||||
printui-margins-custom-bottom = Bottom
|
||||
printui-margins-custom-left = Left
|
||||
printui-margins-custom-right = Right
|
||||
|
||||
printui-system-dialog-link = Print using the system dialog…
|
||||
|
||||
|
@ -96,6 +101,7 @@ printui-paper-tabloid = Tabloid
|
|||
## Error messages shown when a user has an invalid input
|
||||
|
||||
printui-error-invalid-scale = Scale must be a number between 10 and 200.
|
||||
printui-error-invalid-margin = Please enter a valid margin for the selected paper size.
|
||||
|
||||
# Variables
|
||||
# $numPages (integer) - Number of pages
|
||||
|
|
Загрузка…
Ссылка в новой задаче