Bug 1665904 - Rename paperName to paperId for better clarity (front-end). r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D90791
This commit is contained in:
Jonathan Kew 2020-09-20 14:09:59 +00:00
Родитель 7fd751e756
Коммит 039d64f49f
3 изменённых файлов: 38 добавлений и 43 удалений

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

@ -29,12 +29,12 @@ async function run() {
is(settings.printerName, printer.name, "Print settings' printer should match the printer that created them.");
console.log(typeof settings.paperWidth);
is(typeof settings.paperName, "string", "Paper name should never be null.");
is(typeof settings.paperWidth, "number", "Paper width hould never be null.");
is(typeof settings.paperHeight, "number", "Paper height hould never be null.");
is(typeof settings.paperId, "string", "Paper ID should never be null.");
is(typeof settings.paperWidth, "number", "Paper width should never be null.");
is(typeof settings.paperHeight, "number", "Paper height should never be null.");
if (settings.paperName != "") {
info(`Paper: ${settings.paperName}`);
if (settings.paperId != "") {
info(`Paper: ${settings.paperId}`);
info(`Size: (${settings.paperWidth} x ${settings.paperHeight})`);
ok(settings.paperWidth > 0.0, "Paper width should be greater than zero.");
ok(settings.paperHeight > 0.0, "Paper height should be greater than zero.");

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

@ -122,7 +122,7 @@
<section id="paper-size" class="section-block">
<label for="paper-size-picker" class="block-label" data-l10n-id="printui-paper-size-label"></label>
<select is="paper-size-select" id="paper-size-picker" class="row" data-setting-name="paperName">
<select is="paper-size-select" id="paper-size-picker" class="row" data-setting-name="paperId">
</select>
</section>

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

@ -112,7 +112,7 @@ var PrintEventHandler = {
settingFlags: {
margins: Ci.nsIPrintSettings.kInitSaveMargins,
orientation: Ci.nsIPrintSettings.kInitSaveOrientation,
paperName:
paperId:
Ci.nsIPrintSettings.kInitSavePaperSize |
Ci.nsIPrintSettings.kInitSaveUnwriteableMargins,
printInColor: Ci.nsIPrintSettings.kInitSaveInColor,
@ -139,7 +139,6 @@ var PrintEventHandler = {
"printAllOrCustomRange",
"startPageRange",
"endPageRange",
"paperName",
]),
async init() {
@ -399,36 +398,32 @@ var PrintEventHandler = {
delete this._userChangedSettings.printInColor;
}
// See if the paperName needs to change.
// Note that paperName here is the internal paper ID, not the localizable,
// human-friendly name that is displayed in the user interface.
// XXX We should probably do an extensive renaming of s/paperName/paperId/
// throughout this code.
let paperName, paperWidth, paperHeight, paperSizeUnit;
if (settingsToUpdate.paperName) {
// The user changed paperName in this instance and session,
// See if the paperId needs to change.
let paperId, paperWidth, paperHeight, paperSizeUnit;
if (settingsToUpdate.paperId) {
// The user changed paperId in this instance and session,
// We should have details on the paper size from the previous printer
paperName = settingsToUpdate.paperName;
let cachedPaperSize = this.allPaperSizes[paperName];
paperId = settingsToUpdate.paperId;
let cachedPaperSize = this.allPaperSizes[paperId];
paperWidth = cachedPaperSize.width;
paperHeight = cachedPaperSize.height;
paperSizeUnit = cachedPaperSize.paperSizeUnit;
} else {
paperName = this.viewSettings.paperName;
paperId = this.viewSettings.paperId;
paperWidth = this.viewSettings.paperWidth;
paperHeight = this.viewSettings.paperHeight;
paperSizeUnit = this.viewSettings.paperSizeUnit;
}
logger.debug("Using paperName: ", paperName);
logger.debug("Using paperId: ", paperId);
logger.debug(
"Available paper sizes: ",
PrintSettingsViewProxy.availablePaperSizes
);
let matchedPaper =
paperName &&
paperId &&
PrintSettingsViewProxy.getBestPaperMatch(
paperName,
paperId,
paperWidth,
paperHeight,
paperSizeUnit
@ -438,15 +433,15 @@ var PrintEventHandler = {
matchedPaper = Object.values(
PrintSettingsViewProxy.availablePaperSizes
)[0];
delete this._userChangedSettings.paperName;
delete this._userChangedSettings.paperId;
}
if (matchedPaper.id !== paperName) {
// The exact paper name doesn't exist for this printer
if (matchedPaper.id !== paperId) {
// The exact paper id doesn't exist for this printer
logger.log(
`Requested paperName: "${paperName}" missing on this printer, using: ${matchedPaper.id} instead`
`Requested paperId: "${paperId}" missing on this printer, using: ${matchedPaper.id} instead`
);
delete this._userChangedSettings.paperName;
settingsToUpdate.paperName = matchedPaper.id;
delete this._userChangedSettings.paperId;
settingsToUpdate.paperId = matchedPaper.id;
}
return settingsToUpdate;
},
@ -490,11 +485,11 @@ var PrintEventHandler = {
let flags = 0;
logger.debug("updateSettings ", changedSettings, printerChanged);
if (printerChanged || changedSettings.paperName) {
if (printerChanged || changedSettings.paperId) {
// The paper's margin properties are async,
// so resolve those now before we update the settings
await PrintSettingsViewProxy.fetchPaperMargins(
changedSettings.paperName || this.viewSettings.paperName
changedSettings.paperId || this.viewSettings.paperId
);
}
@ -806,8 +801,8 @@ var PrintSettingsViewProxy = {
"Microsoft XPS Document Writer",
]),
getBestPaperMatch(paperName, paperWidth, paperHeight, paperSizeUnit) {
let matchedPaper = paperName && this.availablePaperSizes[paperName];
getBestPaperMatch(paperId, paperWidth, paperHeight, paperSizeUnit) {
let matchedPaper = paperId && this.availablePaperSizes[paperId];
if (matchedPaper) {
return matchedPaper;
}
@ -847,11 +842,11 @@ var PrintSettingsViewProxy = {
return null;
},
async fetchPaperMargins(paperName) {
async fetchPaperMargins(paperId) {
// resolve any async and computed properties we need on the paper
let paperInfo = this.availablePaperSizes[paperName];
let paperInfo = this.availablePaperSizes[paperId];
if (!paperInfo) {
throw new Error("Can't fetchPaperMargins: " + paperName);
throw new Error("Can't fetchPaperMargins: " + paperId);
}
if (paperInfo._resolved) {
// We've already resolved and calculated these values
@ -962,8 +957,8 @@ var PrintSettingsViewProxy = {
get(target, name) {
switch (name) {
case "currentPaper": {
let paperName = this.get(target, "paperName");
return paperName && this.availablePaperSizes[paperName];
let paperId = this.get(target, "paperId");
return paperId && this.availablePaperSizes[paperId];
}
case "marginPresets":
@ -1084,7 +1079,7 @@ var PrintSettingsViewProxy = {
}
break;
case "paperName": {
case "paperId": {
let paperId = value;
let paperSize = this.availablePaperSizes[paperId];
target.paperWidth = paperSize.width;
@ -1093,8 +1088,8 @@ var PrintSettingsViewProxy = {
target.unwriteableMarginRight = paperSize.unwriteableMarginRight;
target.unwriteableMarginBottom = paperSize.unwriteableMarginBottom;
target.unwriteableMarginLeft = paperSize.unwriteableMarginLeft;
target.paperName = paperSize.id;
// pull new margin values for the new paperName
target.paperId = paperSize.id;
// pull new margin values for the new paper size
this.set(target, "margins", this.get(target, "margins"));
break;
}
@ -1282,14 +1277,14 @@ class MarginsPicker extends PrintSettingSelect {
update(settings) {
// Re-evaluate which margin options should be enabled whenever the printer or paper changes
if (
settings.paperName !== this._paperName ||
settings.paperId !== this._paperId ||
settings.printerName !== this._printerName
) {
let enabledMargins = settings.marginOptions;
for (let option of this.options) {
option.hidden = !enabledMargins[option.value];
}
this._paperName = settings.paperName;
this._paperId = settings.paperId;
this._printerName = settings.printerName;
}
super.update(settings);
@ -1310,7 +1305,7 @@ class PaperSizePicker extends PrintSettingSelect {
this._printerName = settings.printerName;
this.setOptions(settings.paperSizes);
}
this.value = settings.paperName;
this.value = settings.paperId;
}
}
customElements.define("paper-size-select", PaperSizePicker, {