Bug 1668406 - Fix nsIPrintSettings.showMarginGuides. r=jfkthame

So that:

 * It accounts for @page.
 * It is correctly serialized and deserialized over IPC.
 * It's nicer to use.

Depends on D92004

Differential Revision: https://phabricator.services.mozilla.com/D92005
This commit is contained in:
Emilio Cobos Álvarez 2020-10-01 10:54:18 +00:00
Родитель fbd95bb29e
Коммит b94fd775e1
6 изменённых файлов: 18 добавлений и 13 удалений

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

@ -491,9 +491,9 @@ static void PaintMarginGuides(nsIFrame* aFrame, DrawTarget* aDrawTarget,
/* dash offset */ 0.0f);
DrawOptions options;
// FIXME(emilio, bug 1659834): Shouldn't this use the page-specific margins,
// which account for @page?
const nsMargin& margin = aFrame->PresContext()->GetDefaultPageMargin();
MOZ_RELEASE_ASSERT(aFrame->IsPageFrame());
const nsMargin& margin =
static_cast<nsPageFrame*>(aFrame)->GetUsedPageContentMargin();
int32_t appUnitsPerDevPx = aFrame->PresContext()->AppUnitsPerDevPixel();
// Get the frame's rect and inset by the margins to get the edges of the
@ -625,16 +625,13 @@ void nsPageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
set.Content()->AppendNewToTop<nsDisplayHeaderFooter>(aBuilder, this);
// For print-preview, show margin guides if requested in the settings.
if (pc->Type() == nsPresContext::eContext_PrintPreview) {
bool showGuides;
if (NS_SUCCEEDED(mPD->mPrintSettings->GetShowMarginGuides(&showGuides)) &&
showGuides) {
if (pc->Type() == nsPresContext::eContext_PrintPreview &&
mPD->mPrintSettings->GetShowMarginGuides()) {
set.Content()->AppendNewToTop<nsDisplayGeneric>(
aBuilder, this, PaintMarginGuides, "MarginGuides",
DisplayItemType::TYPE_MARGIN_GUIDES);
}
}
}
set.MoveTo(aLists);
}

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

@ -61,6 +61,10 @@ class nsPageFrame final : public nsContainerFrame {
*/
void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
const nsMargin& GetUsedPageContentMargin() const {
return mPageContentMargin;
}
protected:
explicit nsPageFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
virtual ~nsPageFrame();

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

@ -33,6 +33,7 @@ struct PrintData {
bool printBGColors;
bool printBGImages;
bool honorPageRuleMargins;
bool showMarginGuides;
short printRange;
nsString title;
nsString docURL;

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

@ -183,6 +183,9 @@ interface nsIPrintSettings : nsISupports
/** Whether @page rule margins should be honored or not. */
[infallible] attribute boolean honorPageRuleMargins;
/** Whether to draw guidelines showing the margin settings */
[infallible] attribute boolean showMarginGuides;
attribute short printRange;
attribute AString title;
@ -201,7 +204,6 @@ interface nsIPrintSettings : nsISupports
attribute boolean printSilent; /* print without putting up the dialog */
attribute boolean shrinkToFit; /* shrinks content to fit on page */
attribute boolean showPrintProgress; /* indicates whether the progress dialog should be shown */
attribute boolean showMarginGuides; /* whether to draw guidelines showing the margin settings */
/* Additional XP Related */
attribute AString paperId; /* identifier of paper (not display name) */

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

@ -597,7 +597,6 @@ NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress) {
}
NS_IMETHODIMP nsPrintSettings::GetShowMarginGuides(bool* aShowMarginGuides) {
NS_ENSURE_ARG_POINTER(aShowMarginGuides);
*aShowMarginGuides = mShowMarginGuides;
return NS_OK;
}

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

@ -114,6 +114,7 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings,
data->printBGImages() = aSettings->GetPrintBGImages();
data->honorPageRuleMargins() = aSettings->GetHonorPageRuleMargins();
data->showMarginGuides() = aSettings->GetShowMarginGuides();
aSettings->GetPrintRange(&data->printRange());
@ -212,6 +213,7 @@ nsPrintSettingsService::DeserializeToPrintSettings(const PrintData& data,
settings->SetPrintBGColors(data.printBGColors());
settings->SetPrintBGImages(data.printBGImages());
settings->SetHonorPageRuleMargins(data.honorPageRuleMargins());
settings->SetShowMarginGuides(data.showMarginGuides());
settings->SetPrintRange(data.printRange());
settings->SetTitle(data.title());