Bug 1669149 p4: Change unwriteable margin pref to be stored in twips. r=jwatt

This means that more precise values can be stored, so that they match what we
actually retrieve from the printer and use in layout.

Depends on D99806

Differential Revision: https://phabricator.services.mozilla.com/D99807
This commit is contained in:
Bob Owen 2021-11-16 08:17:04 +00:00
parent c5214a2110
commit 773d934c75
2 changed files with 48 additions and 34 deletions

View file

@ -987,20 +987,8 @@ pref("print.save_print_settings", true);
// configuration.
pref("print.more-settings.open", false);
// Enables you to specify the amount of the paper that is to be treated
// as unwriteable. The print_edge_XXX and print_margin_XXX preferences
// are treated as offsets that are added to this pref.
// Default is "-1", which means "use the system default". (If there is
// no system default, then the -1 is treated as if it were 0.)
// This is used by both Printing and Print Preview.
// Units are in 1/100ths of an inch.
pref("print.print_unwriteable_margin_top", -1);
pref("print.print_unwriteable_margin_left", -1);
pref("print.print_unwriteable_margin_right", -1);
pref("print.print_unwriteable_margin_bottom", -1);
// Enables you to specify the gap from the edge of the paper's
// unwriteable area to the margin.
// Enables you to specify a user unwriteable margin, if a printer's actual
// unwriteable margin is greater than this the printer one will be used.
// This is used by both Printing and Print Preview
// Units are in 1/100ths of an inch.
pref("print.print_edge_top", 0);

View file

@ -43,6 +43,18 @@ static const char kEdgeTop[] = "print_edge_top";
static const char kEdgeLeft[] = "print_edge_left";
static const char kEdgeBottom[] = "print_edge_bottom";
static const char kEdgeRight[] = "print_edge_right";
static const char kUnwriteableMarginTopTwips[] =
"print_unwriteable_margin_top_twips";
static const char kUnwriteableMarginLeftTwips[] =
"print_unwriteable_margin_left_twips";
static const char kUnwriteableMarginBottomTwips[] =
"print_unwriteable_margin_bottom_twips";
static const char kUnwriteableMarginRightTwips[] =
"print_unwriteable_margin_right_twips";
// These are legacy versions of the above UnwriteableMargin prefs. The new ones,
// which are in twips, were introduced to more accurately record the values.
static const char kUnwriteableMarginTop[] = "print_unwriteable_margin_top";
static const char kUnwriteableMarginLeft[] = "print_unwriteable_margin_left";
static const char kUnwriteableMarginBottom[] =
@ -358,15 +370,26 @@ nsresult nsPrintSettingsService::ReadPrefs(nsIPrintSettings* aPS,
if (aFlags & nsIPrintSettings::kInitSaveUnwriteableMargins) {
nsIntMargin margin;
bool allPrefsRead =
GETINTPREF(kUnwriteableMarginTopTwips, &margin.top) &&
GETINTPREF(kUnwriteableMarginRightTwips, &margin.right) &&
GETINTPREF(kUnwriteableMarginBottomTwips, &margin.bottom) &&
GETINTPREF(kUnwriteableMarginLeftTwips, &margin.left);
if (!allPrefsRead) {
// We failed to read the new unwritable margin twips prefs. Try to read
// the old ones in case they exist.
ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginTop, aPrinterName),
margin.top, kUnwriteableMarginTop);
ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginLeft, aPrinterName),
margin.left, kUnwriteableMarginLeft);
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginLeft, aPrinterName), margin.left,
kUnwriteableMarginLeft);
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginBottom, aPrinterName), margin.bottom,
kUnwriteableMarginBottom);
ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginRight, aPrinterName),
margin.right, kUnwriteableMarginRight);
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginRight, aPrinterName), margin.right,
kUnwriteableMarginRight);
}
// SetUnwriteableMarginInTwips does its own validation and drops negative
// values individually. We still want to block overly large values though,
// so we do that part of MarginIsOK manually.
@ -567,18 +590,21 @@ nsresult nsPrintSettingsService::WritePrefs(nsIPrintSettings* aPS,
if (aFlags & nsIPrintSettings::kInitSaveUnwriteableMargins) {
nsIntMargin unwriteableMargin = aPS->GetUnwriteableMarginInTwips();
WriteInchesIntFromTwipsPref(
GetPrefName(kUnwriteableMarginTop, aPrinterName),
Preferences::SetInt(GetPrefName(kUnwriteableMarginTopTwips, aPrinterName),
unwriteableMargin.top);
WriteInchesIntFromTwipsPref(
GetPrefName(kUnwriteableMarginLeft, aPrinterName),
Preferences::SetInt(GetPrefName(kUnwriteableMarginLeftTwips, aPrinterName),
unwriteableMargin.left);
WriteInchesIntFromTwipsPref(
GetPrefName(kUnwriteableMarginBottom, aPrinterName),
Preferences::SetInt(
GetPrefName(kUnwriteableMarginBottomTwips, aPrinterName),
unwriteableMargin.bottom);
WriteInchesIntFromTwipsPref(
GetPrefName(kUnwriteableMarginRight, aPrinterName),
Preferences::SetInt(GetPrefName(kUnwriteableMarginRightTwips, aPrinterName),
unwriteableMargin.right);
// Remove the old unwriteableMargin prefs.
Preferences::ClearUser(GetPrefName(kUnwriteableMarginTop, aPrinterName));
Preferences::ClearUser(GetPrefName(kUnwriteableMarginRight, aPrinterName));
Preferences::ClearUser(GetPrefName(kUnwriteableMarginBottom, aPrinterName));
Preferences::ClearUser(GetPrefName(kUnwriteableMarginLeft, aPrinterName));
}
// Paper size prefs are saved as a group