зеркало из https://github.com/mozilla/gecko-dev.git
Bug 35228 - Ability to print even/odd pages. r=emilio,fluent-reviewers,mstriemer
Ability to print all even pages or all odd pages. Differential Revision: https://phabricator.services.mozilla.com/D130111
This commit is contained in:
Родитель
8b68ee613b
Коммит
c6510e2e9e
|
@ -20,6 +20,8 @@
|
|||
<template id="page-range-template">
|
||||
<select id="range-picker" name="page-range-type" data-l10n-id="printui-page-range-picker" is="setting-select">
|
||||
<option value="all" selected data-l10n-id="printui-page-range-all"></option>
|
||||
<option value="odd" data-l10n-id="printui-page-range-odd"></option>
|
||||
<option value="even" name="even" data-l10n-id="printui-page-range-even"></option>
|
||||
<option value="custom" data-l10n-id="printui-page-range-custom"></option>
|
||||
</select>
|
||||
<input id="custom-range" type="text" disabled hidden data-l10n-id="printui-page-custom-range-input" aria-errormessage="error-invalid-range error-invalid-start-range-overflow">
|
||||
|
|
|
@ -2054,6 +2054,7 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
this._rangeInput = this.querySelector("#custom-range");
|
||||
this._rangeInput.title = "";
|
||||
this._rangePicker = this.querySelector("#range-picker");
|
||||
this._rangePickerEvenOption = this._rangePicker.namedItem("even");
|
||||
this._rangeError = this.querySelector("#error-invalid-range");
|
||||
this._startRangeOverflowError = this.querySelector(
|
||||
"#error-invalid-start-range-overflow"
|
||||
|
@ -2071,15 +2072,26 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
}
|
||||
|
||||
updatePageRange() {
|
||||
let isAll = this._rangePicker.value == "all";
|
||||
if (isAll) {
|
||||
let isCustom = this._rangePicker.value == "custom";
|
||||
if (isCustom) {
|
||||
this.validateRangeInput();
|
||||
} else {
|
||||
this._pagesSet.clear();
|
||||
|
||||
if (this._rangePicker.value == "odd") {
|
||||
for (let i = 1; i <= this._numPages; i += 2) {
|
||||
this._pagesSet.add(i);
|
||||
}
|
||||
} else if (this._rangePicker.value == "even") {
|
||||
for (let i = 2; i <= this._numPages; i += 2) {
|
||||
this._pagesSet.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._rangeInput.checkValidity()) {
|
||||
this._rangeInput.setCustomValidity("");
|
||||
this._rangeInput.value = "";
|
||||
}
|
||||
} else {
|
||||
this.validateRangeInput();
|
||||
}
|
||||
|
||||
this.dispatchEvent(new Event("revalidate", { bubbles: true }));
|
||||
|
@ -2094,7 +2106,7 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
|
||||
// If it's valid, update the page range and hide the error messages.
|
||||
// Otherwise, set the appropriate error message
|
||||
if (this._rangeInput.validity.valid || isAll) {
|
||||
if (this._rangeInput.validity.valid || !isCustom) {
|
||||
window.clearTimeout(this.showErrorTimeoutId);
|
||||
this._startRangeOverflowError.hidden = this._rangeError.hidden = true;
|
||||
} else {
|
||||
|
@ -2104,7 +2116,10 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
|
||||
dispatchPageRange(shouldCancel = true) {
|
||||
window.clearTimeout(this.showErrorTimeoutId);
|
||||
if (this._rangeInput.validity.valid || this._rangePicker.value == "all") {
|
||||
if (
|
||||
this._rangeInput.validity.valid ||
|
||||
this._rangePicker.value != "custom"
|
||||
) {
|
||||
this.dispatchSettingsChange({
|
||||
pageRanges: this.formatPageRange(),
|
||||
});
|
||||
|
@ -2129,7 +2144,7 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
formatPageRange() {
|
||||
if (
|
||||
this._pagesSet.size == 0 ||
|
||||
this._rangeInput.value == "" ||
|
||||
(this._rangePicker.value == "custom" && this._rangeInput.value == "") ||
|
||||
this._rangePicker.value == "all"
|
||||
) {
|
||||
// Show all pages.
|
||||
|
@ -2250,7 +2265,8 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
}
|
||||
|
||||
validateRangeInput() {
|
||||
let value = this._rangePicker.value == "all" ? "" : this._rangeInput.value;
|
||||
let value =
|
||||
this._rangePicker.value == "custom" ? this._rangeInput.value : "";
|
||||
this._validateRangeInput(value, this._numPages);
|
||||
}
|
||||
|
||||
|
@ -2277,6 +2293,7 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
|
||||
this._numPages = totalPages;
|
||||
this._rangeInput.disabled = false;
|
||||
this._rangePickerEvenOption.disabled = this._numPages < 2;
|
||||
|
||||
let prevPages = Array.from(this._pagesSet);
|
||||
this.updatePageRange();
|
||||
|
@ -2296,7 +2313,7 @@ class PageRangeInput extends PrintUIControlMixin(HTMLElement) {
|
|||
}
|
||||
|
||||
if (e.target == this._rangePicker) {
|
||||
this._rangeInput.hidden = e.target.value == "all";
|
||||
this._rangeInput.hidden = e.target.value != "custom";
|
||||
this.updatePageRange();
|
||||
this.dispatchPageRange();
|
||||
if (!this._rangeInput.hidden) {
|
||||
|
|
|
@ -3,22 +3,31 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
function changeAllToCustom(helper) {
|
||||
function changeRangeTo(helper, destination) {
|
||||
let rangeSelect = helper.get("range-picker");
|
||||
let options = getRangeOptions(helper);
|
||||
let numberMove =
|
||||
options.indexOf(destination) - options.indexOf(rangeSelect.value);
|
||||
let direction = numberMove > 0 ? "down" : "up";
|
||||
|
||||
rangeSelect.focus();
|
||||
rangeSelect.scrollIntoView({ block: "center" });
|
||||
EventUtils.sendKey("space", helper.win);
|
||||
EventUtils.sendKey("down", helper.win);
|
||||
for (let i = Math.abs(numberMove); i > 0; i--) {
|
||||
EventUtils.sendKey(direction, helper.win);
|
||||
}
|
||||
EventUtils.sendKey("return", helper.win);
|
||||
}
|
||||
|
||||
function changeCustomToAll(helper) {
|
||||
function getRangeOptions(helper) {
|
||||
let rangeSelect = helper.get("range-picker");
|
||||
rangeSelect.focus();
|
||||
rangeSelect.scrollIntoView({ block: "center" });
|
||||
EventUtils.sendKey("space", helper.win);
|
||||
EventUtils.sendKey("up", helper.win);
|
||||
EventUtils.sendKey("return", helper.win);
|
||||
let options = [];
|
||||
for (let el of rangeSelect.options) {
|
||||
if (!el.disabled) {
|
||||
options.push(el.value);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function getSheetCount(helper) {
|
||||
|
@ -34,7 +43,7 @@ add_task(async function testRangeResetAfterScale() {
|
|||
await helper.setupMockPrint();
|
||||
|
||||
helper.mockFilePicker("changeRangeFromScale.pdf");
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
|
||||
await helper.openMoreSettings();
|
||||
let scaleRadio = helper.get("percent-scale-choice");
|
||||
|
@ -74,7 +83,7 @@ add_task(async function testRangeResetAfterPaperSize() {
|
|||
await helper.waitForPreview(() => helper.text(percentScale, "200"));
|
||||
|
||||
let customRange = helper.get("custom-range");
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
await BrowserTestUtils.waitForAttributeRemoval("hidden", customRange);
|
||||
|
||||
let rangeError = helper.get("error-invalid-range");
|
||||
|
@ -107,7 +116,7 @@ add_task(async function testInvalidRangeResetAfterDestinationChange() {
|
|||
let customPageRange = helper.get("custom-range");
|
||||
|
||||
await helper.assertSettingsNotChanged({ pageRanges: [] }, async () => {
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
});
|
||||
let rangeError = helper.get("error-invalid-range");
|
||||
|
||||
|
@ -142,7 +151,7 @@ add_task(async function testPageRangeSets() {
|
|||
|
||||
ok(customRange.hidden, "Custom range input is hidden");
|
||||
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
await BrowserTestUtils.waitForAttributeRemoval("hidden", customRange);
|
||||
|
||||
ok(!customRange.hidden, "Custom range is showing");
|
||||
|
@ -167,8 +176,7 @@ add_task(async function testPageRangeSets() {
|
|||
"1-": [1, 50],
|
||||
"-": [],
|
||||
"-20": [1, 20],
|
||||
"-,1": [],
|
||||
"-1,1-": [],
|
||||
"-1,1-": [1, 50],
|
||||
"-1,1-2": [1, 2],
|
||||
",9": [9, 9],
|
||||
",": [],
|
||||
|
@ -180,10 +188,9 @@ add_task(async function testPageRangeSets() {
|
|||
for (let [str, expected] of Object.entries(validStrings)) {
|
||||
pageRangeInput._validateRangeInput(str, 50);
|
||||
let pageRanges = pageRangeInput.formatPageRange();
|
||||
|
||||
is(
|
||||
expected.every((page, index) => page === pageRanges[index]),
|
||||
true,
|
||||
ok(
|
||||
expected.length == pageRanges.length &&
|
||||
expected.every((page, index) => page === pageRanges[index]),
|
||||
`Expected page range for "${str}" matches "${expected}"`
|
||||
);
|
||||
|
||||
|
@ -203,11 +210,39 @@ add_task(async function testPageRangeSets() {
|
|||
});
|
||||
});
|
||||
|
||||
add_task(async function testPageRangeSelect() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
|
||||
let pageRangeInput = helper.get("page-range-input");
|
||||
|
||||
changeRangeTo(helper, "all");
|
||||
let pageRanges = pageRangeInput.formatPageRange();
|
||||
ok(!pageRanges.length, "Page range for all should be []");
|
||||
|
||||
changeRangeTo(helper, "odd");
|
||||
pageRanges = pageRangeInput.formatPageRange();
|
||||
ok(
|
||||
pageRanges.length == 4 &&
|
||||
[1, 1, 3, 3].every((page, index) => page === pageRanges[index]),
|
||||
"Page range for odd should be [1, 1, 3, 3]"
|
||||
);
|
||||
|
||||
changeRangeTo(helper, "even");
|
||||
pageRanges = pageRangeInput.formatPageRange();
|
||||
ok(
|
||||
pageRanges.length == 2 &&
|
||||
[2, 2].every((page, index) => page === pageRanges[index]),
|
||||
"Page range for even should be [2, 2]"
|
||||
);
|
||||
}, "longerArticle.html");
|
||||
});
|
||||
|
||||
add_task(async function testRangeError() {
|
||||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
|
||||
let invalidError = helper.get("error-invalid-range");
|
||||
let invalidOverflowError = helper.get("error-invalid-start-range-overflow");
|
||||
|
@ -230,7 +265,7 @@ add_task(async function testStartOverflowRangeError() {
|
|||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
|
||||
await helper.openMoreSettings();
|
||||
let scaleRadio = helper.get("percent-scale-choice");
|
||||
|
@ -262,7 +297,7 @@ add_task(async function testErrorClearedAfterSwitchingToAll() {
|
|||
await PrintHelper.withTestPage(async helper => {
|
||||
await helper.startPrint();
|
||||
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
|
||||
let customRange = helper.get("custom-range");
|
||||
let rangeError = helper.get("error-invalid-range");
|
||||
|
@ -273,7 +308,7 @@ add_task(async function testErrorClearedAfterSwitchingToAll() {
|
|||
await BrowserTestUtils.waitForAttributeRemoval("hidden", rangeError);
|
||||
ok(!rangeError.hidden, "Generic error message is showing");
|
||||
|
||||
changeCustomToAll(helper);
|
||||
changeRangeTo(helper, "all");
|
||||
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => rangeError.hidden,
|
||||
|
@ -368,7 +403,7 @@ add_task(async function testPageCountChangeRangeNoRerender() {
|
|||
]);
|
||||
|
||||
await helper.waitForPreview(async () => {
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
helper.text(helper.get("custom-range"), "1");
|
||||
});
|
||||
}
|
||||
|
@ -425,7 +460,7 @@ add_task(async function testPageCountChangeRangeRerender() {
|
|||
]);
|
||||
|
||||
await helper.waitForPreview(async () => {
|
||||
changeAllToCustom(helper);
|
||||
changeRangeTo(helper, "custom");
|
||||
helper.text(helper.get("custom-range"), "1-");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ printui-sheets-count =
|
|||
}
|
||||
|
||||
printui-page-range-all = All
|
||||
printui-page-range-odd = Odd
|
||||
printui-page-range-even = Even
|
||||
printui-page-range-custom = Custom
|
||||
printui-page-range-label = Pages
|
||||
printui-page-range-picker =
|
||||
|
|
Загрузка…
Ссылка в новой задаче