Bug 1673634: custom margins must factor in page orientation when calculating maximum values r=mstriemer

When the orientation changes, we must recalculate the maximum height and width.
For portrait orientation, marginTop and marginBottom should be compared to the
paper width, and for landscape orientation, they should be compared to the paper
height (vice versa for marginLeft and marginRight).

If the custom margin values are valid after an orientation switch, they will
persist. If they are no longer valid, they will be reset to the default values,
and the margin dropdown will still have custom selected.

Differential Revision: https://phabricator.services.mozilla.com/D96099
This commit is contained in:
Emma Malysz 2020-11-06 18:49:19 +00:00
Родитель a279a44108
Коммит 12b483048a
2 изменённых файлов: 56 добавлений и 5 удалений

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

@ -522,11 +522,19 @@ var PrintEventHandler = {
let paperHeightInInches = paperWrapper.paper.height * INCHES_PER_POINT;
let paperWidthInInches = paperWrapper.paper.width * INCHES_PER_POINT;
let height =
(changedSettings.orientation || this.viewSettings.orientation) == 0
? paperHeightInInches
: paperWidthInInches;
let width =
(changedSettings.orientation || this.viewSettings.orientation) == 0
? paperWidthInInches
: paperHeightInInches;
if (
parseFloat(this.viewSettings.customMargins.marginTop) +
parseFloat(this.viewSettings.customMargins.marginBottom) >
paperHeightInInches -
height -
paperWrapper.unwriteableMarginTop -
paperWrapper.unwriteableMarginBottom ||
this.viewSettings.customMargins.marginTop < 0 ||
@ -540,7 +548,7 @@ var PrintEventHandler = {
if (
parseFloat(this.viewSettings.customMargins.marginRight) +
parseFloat(this.viewSettings.customMargins.marginLeft) >
paperWidthInInches -
width -
paperWrapper.unwriteableMarginRight -
paperWrapper.unwriteableMarginLeft ||
this.viewSettings.customMargins.marginLeft < 0 ||
@ -1986,7 +1994,8 @@ class MarginsPicker extends PrintUIControlMixin(HTMLElement) {
// Re-evaluate which margin options should be enabled whenever the printer or paper changes
if (
settings.paperId !== this._paperId ||
settings.printerName !== this._printerName
settings.printerName !== this._printerName ||
settings.orientation !== this._orientation
) {
let enabledMargins = settings.marginOptions;
for (let option of this._marginPicker.options) {
@ -1994,13 +2003,19 @@ class MarginsPicker extends PrintUIControlMixin(HTMLElement) {
}
this._paperId = settings.paperId;
this._printerName = settings.printerName;
this._orientation = settings.orientation;
let height =
this._orientation == 0 ? settings.paperHeight : settings.paperWidth;
let width =
this._orientation == 0 ? settings.paperWidth : settings.paperHeight;
this._maxHeight =
settings.paperHeight -
height -
settings.unwriteableMarginTop -
settings.unwriteableMarginBottom;
this._maxWidth =
settings.paperWidth -
width -
settings.unwriteableMarginLeft -
settings.unwriteableMarginRight;

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

@ -713,3 +713,39 @@ add_task(async function testRevalidateCustomMarginsAfterPaperChanges() {
);
});
});
add_task(async function testRevalidateCustomMarginsAfterOrientationChanges() {
await PrintHelper.withTestPage(async helper => {
await setupLetterPaper();
await helper.startPrint();
await helper.openMoreSettings();
this.changeDefaultToCustom(helper);
await helper.awaitAnimationFrame();
let marginError = helper.get("error-invalid-margin");
await helper.assertSettingsChanged(
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
{ marginTop: 5, marginRight: 0.5, marginBottom: 5, marginLeft: 0.5 },
async () => {
await helper.text(helper.get("custom-margin-top"), "5");
await helper.text(helper.get("custom-margin-bottom"), "5");
assertPendingMarginsUpdate(helper);
// Wait for the preview to update, the margin options delay updates by
// INPUT_DELAY_MS, which is 500ms.
await helper.waitForSettingsEvent();
ok(marginError.hidden, "Margin error is hidden");
}
);
await helper.assertSettingsChanged(
{ marginTop: 5, marginRight: 0.5, marginBottom: 5, marginLeft: 0.5 },
{ marginTop: 0.5, marginRight: 0.5, marginBottom: 0.5, marginLeft: 0.5 },
async () => {
await helper.dispatchSettingsChange({ orientation: 1 });
await helper.waitForSettingsEvent();
ok(marginError.hidden, "Margin error is hidden");
}
);
});
});