Skip to content

Commit

Permalink
Bug 1665125 - Make print background settings infallible. r=bobowen
Browse files Browse the repository at this point in the history
This makes callers simpler.

Differential Revision: https://phabricator.services.mozilla.com/D90285
  • Loading branch information
emilio committed Sep 16, 2020
1 parent eb1718e commit 94f2b90
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 55 deletions.
4 changes: 4 additions & 0 deletions layout/base/nsPresContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,10 @@ void nsPresContext::SetPrintSettings(nsIPrintSettings* aPrintSettings) {
return;
}

// set the presentation context to the value in the print settings
mDrawColorBackground = mPrintSettings->GetPrintBGColors();
mDrawImageBackground = mPrintSettings->GetPrintBGImages();

nsIntMargin unwriteableTwips = mPrintSettings->GetUnwriteableMarginInTwips();
NS_ASSERTION(unwriteableTwips.top >= 0 && unwriteableTwips.right >= 0 &&
unwriteableTwips.bottom >= 0 && unwriteableTwips.left >= 0,
Expand Down
9 changes: 1 addition & 8 deletions layout/base/nsPresContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,17 +704,10 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
bool ElementWouldPropagateScrollStyles(const mozilla::dom::Element&);

/**
* Set and get methods for controlling the background drawing
* Methods for controlling the background drawing.
*/
bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
void SetBackgroundImageDraw(bool aCanDraw) {
mDrawImageBackground = aCanDraw;
}

bool GetBackgroundColorDraw() const { return mDrawColorBackground; }
void SetBackgroundColorDraw(bool aCanDraw) {
mDrawColorBackground = aCanDraw;
}

/**
* Check if bidi enabled (set depending on the presence of RTL
Expand Down
7 changes: 0 additions & 7 deletions layout/printing/nsPrintJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,13 +1807,6 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) {
: new nsPresContext(aPO->mDocument, type);
aPO->mPresContext->SetPrintSettings(printData->mPrintSettings);

// set the presentation context to the value in the print settings
bool printBGColors;
printData->mPrintSettings->GetPrintBGColors(&printBGColors);
aPO->mPresContext->SetBackgroundColorDraw(printBGColors);
printData->mPrintSettings->GetPrintBGImages(&printBGColors);
aPO->mPresContext->SetBackgroundImageDraw(printBGColors);

// init it with the DC
MOZ_TRY(aPO->mPresContext->Init(printData->mPrintDC));

Expand Down
42 changes: 23 additions & 19 deletions layout/tools/reftest/reftest-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,29 @@ function doPrintMode(contentRootElement) {
}

function setupPrintMode() {
var PSSVC =
Cc[PRINTSETTINGS_CONTRACTID].getService(Ci.nsIPrintSettingsService);
var ps = PSSVC.newPrintSettings;
ps.paperWidth = 5;
ps.paperHeight = 3;

// Override any os-specific unwriteable margins
ps.unwriteableMarginTop = 0;
ps.unwriteableMarginLeft = 0;
ps.unwriteableMarginBottom = 0;
ps.unwriteableMarginRight = 0;

ps.headerStrLeft = "";
ps.headerStrCenter = "";
ps.headerStrRight = "";
ps.footerStrLeft = "";
ps.footerStrCenter = "";
ps.footerStrRight = "";
docShell.contentViewer.setPageModeForTesting(/* aPageMode */ true, ps);
var PSSVC =
Cc[PRINTSETTINGS_CONTRACTID].getService(Ci.nsIPrintSettingsService);
var ps = PSSVC.newPrintSettings;
ps.paperWidth = 5;
ps.paperHeight = 3;

// Override any os-specific unwriteable margins
ps.unwriteableMarginTop = 0;
ps.unwriteableMarginLeft = 0;
ps.unwriteableMarginBottom = 0;
ps.unwriteableMarginRight = 0;

ps.headerStrLeft = "";
ps.headerStrCenter = "";
ps.headerStrRight = "";
ps.footerStrLeft = "";
ps.footerStrCenter = "";
ps.footerStrRight = "";

ps.printBGColors = true;
ps.printBGImages = true;

docShell.contentViewer.setPageModeForTesting(/* aPageMode */ true, ps);
}

// Message the parent process to ask it to print the current page to a PDF file.
Expand Down
5 changes: 2 additions & 3 deletions widget/cocoa/nsPrintDialogX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ - (void)addAppearanceSection {
mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors"
andFrame:NSMakeRect(156, 103, 0, 0)];

bool geckoBool;
mSettings->GetPrintBGColors(&geckoBool);
bool geckoBool = mSettings->GetPrintBGColors();
[mPrintBGColorsCheckbox setState:(geckoBool ? NSOnState : NSOffState)];

[self addSubview:mPrintBGColorsCheckbox];
Expand All @@ -409,7 +408,7 @@ - (void)addAppearanceSection {
mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages"
andFrame:NSMakeRect(156, 81, 0, 0)];

mSettings->GetPrintBGImages(&geckoBool);
geckoBool = mSettings->GetPrintBGImages();
[mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)];

[self addSubview:mPrintBGImagesCheckbox];
Expand Down
6 changes: 2 additions & 4 deletions widget/gtk/nsPrintDialogGTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,11 @@ nsresult nsPrintDialogWidgetGTK::ImportSettings(nsIPrintSettings* aNSSettings) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(shrink_to_fit_toggle),
geckoBool);

aNSSettings->GetPrintBGColors(&geckoBool);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_bg_colors_toggle),
geckoBool);
aNSSettings->GetPrintBGColors());

aNSSettings->GetPrintBGImages(&geckoBool);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_bg_images_toggle),
geckoBool);
aNSSettings->GetPrintBGImages());

gtk_print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(dialog), settings);
gtk_print_unix_dialog_set_page_setup(GTK_PRINT_UNIX_DIALOG(dialog), setup);
Expand Down
8 changes: 4 additions & 4 deletions widget/nsIPrintSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ interface nsIPrintSettings : nsISupports
/**
* Makes a new copy
*/
nsIPrintSettings clone();
nsIPrintSettings clone();

/**
* Assigns the internal values from the "in" arg to the current object
*/
void assign(in nsIPrintSettings aPS);
void assign(in nsIPrintSettings aPS);

/**
* Data Members
Expand Down Expand Up @@ -177,8 +177,8 @@ interface nsIPrintSettings : nsISupports
attribute double unwriteableMarginRight;

attribute double scaling; /* values 0.0 - 1.0 */
attribute boolean printBGColors; /* Print Background Colors */
attribute boolean printBGImages; /* Print Background Images */
[infallible] attribute boolean printBGColors; /* Print Background Colors */
[infallible] attribute boolean printBGImages; /* Print Background Images */

attribute short printRange;

Expand Down
19 changes: 9 additions & 10 deletions widget/nsPrintSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings,

aSettings->GetScaling(&data->scaling());

aSettings->GetPrintBGColors(&data->printBGColors());
aSettings->GetPrintBGImages(&data->printBGImages());
data->printBGColors() = aSettings->GetPrintBGColors();
data->printBGImages() = aSettings->GetPrintBGImages();

aSettings->GetPrintRange(&data->printRange());

aSettings->GetTitle(data->title());
Expand Down Expand Up @@ -733,17 +734,15 @@ nsresult nsPrintSettingsService::WritePrefs(nsIPrintSettings* aPS,
}

if (aFlags & nsIPrintSettings::kInitSaveBGColors) {
if (NS_SUCCEEDED(aPS->GetPrintBGColors(&b))) {
DUMP_BOOL(kWriteStr, kPrintBGColors, b);
Preferences::SetBool(GetPrefName(kPrintBGColors, aPrinterName), b);
}
b = aPS->GetPrintBGColors();
DUMP_BOOL(kWriteStr, kPrintBGColors, b);
Preferences::SetBool(GetPrefName(kPrintBGColors, aPrinterName), b);
}

if (aFlags & nsIPrintSettings::kInitSaveBGImages) {
if (NS_SUCCEEDED(aPS->GetPrintBGImages(&b))) {
DUMP_BOOL(kWriteStr, kPrintBGImages, b);
Preferences::SetBool(GetPrefName(kPrintBGImages, aPrinterName), b);
}
b = aPS->GetPrintBGImages();
DUMP_BOOL(kWriteStr, kPrintBGImages, b);
Preferences::SetBool(GetPrefName(kPrintBGImages, aPrinterName), b);
}

if (aFlags & nsIPrintSettings::kInitSaveReversed) {
Expand Down

0 comments on commit 94f2b90

Please sign in to comment.