gecko-dev/layout/printing/nsPrintObject.h
Daniel Holbert 49e37dc76e Bug 1776074 part 7: Remove mFrameType member (and PrintObjectType in general) from nsPrintObject.h. r=emilio
This patch does not change behavior (other than a minor correctness fix in some
off-by-default logging; see below).

As shown in the removed line of the init list, this mFrameType member-var's
semantics are equivalent to a null-check of the mParent member-var.  So: rather
than encoding that same information twice, this patch simplifies to just
directly null-check the mParent pointer at all the usage sites.

Before this patch, nsPrintJob.cpp had two different patterns for logging
mFrameType; sometimes with a global `gFrameTypesStr` array, and other times
with a local `types` array (with shorter 2-character strings).  I've converted
both of these to helper-functions.

In the case of the `types` array, the old code used a 4-value array, which was
interesting since the enum type only had 2 possible values. This discrepancy is
just due to an oversight in bug 1769508, where we recently condensed the enum
from 4 values to 2; that bug technically should've condensed these arrays as
well (but didn't do so).  This left these arrays' enum-to-string mapping being
wrong (since eIFrame changed its numeric value from 2 to 1 in bug 1769508), but
probably nobody has used this logging code in a while, so nobody
noticed. Anyway: in this patch, I'm restoring the mappings that we had before
that change (so we'll log "DC" for root print objects and "IF" for non-root
i.e. iframe-flavored print objects).

Differential Revision: https://phabricator.services.mozilla.com/D150177
2022-06-23 22:57:00 +00:00

89 lines
2.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsPrintObject_h___
#define nsPrintObject_h___
#include "mozilla/Attributes.h"
#include "mozilla/UniquePtr.h"
// Interfaces
#include "nsCOMPtr.h"
#include "nsViewManager.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeOwner.h"
class nsIContent;
class nsPresContext;
namespace mozilla {
class PresShell;
} // namespace mozilla
//---------------------------------------------------
//-- nsPrintObject Class
//---------------------------------------------------
class nsPrintObject final {
public:
/**
* If aParent is nullptr (default), then this instance will be initialized as
* a "root" nsPrintObject. Otherwise, this will be a "nested" nsPrintObject.
*/
nsPrintObject(nsIDocShell& aDocShell, mozilla::dom::Document& aDoc,
nsPrintObject* aParent = nullptr);
~nsPrintObject();
void DestroyPresentation();
/**
* Recursively sets all the PO items to be printed
* from the given item down into the tree
*/
void EnablePrinting(bool aEnable);
/**
* Recursively sets all the PO items to be printed if they have a selection.
*/
void EnablePrintingSelectionOnly();
bool PrintingIsEnabled() const { return mPrintingIsEnabled; }
bool HasSelection() const;
// Data Members
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIDocShellTreeOwner> mTreeOwner;
RefPtr<mozilla::dom::Document> mDocument;
RefPtr<nsPresContext> mPresContext;
RefPtr<mozilla::PresShell> mPresShell;
RefPtr<nsViewManager> mViewManager;
nsCOMPtr<nsIContent> mContent;
nsTArray<mozilla::UniquePtr<nsPrintObject>> mKids;
const nsPrintObject* mParent; // This is a non-owning pointer.
bool mHasBeenPrinted = false;
bool mInvisible = false; // Indicates PO is set to not visible by CSS
// The scale factor that sheets should be scaled by. This is either the
// explicit scale chosen by the user or else the shrink-to-fit scale factor
// if the user selects shrink-to-fit. Only set on the top-level nsPrintObject
// since this is only used by nsPageFrame (via nsPresContext::GetPageScale()).
float mZoomRatio = 1.0;
// If the user selects the shrink-to-fit option, the shrink-to-fit scale
// factor is calculated and stored here. Only set on the top-level
// nsPrintObject.
float mShrinkRatio = 1.0;
private:
nsPrintObject& operator=(const nsPrintObject& aOther) = delete;
bool mPrintingIsEnabled = false;
};
#endif /* nsPrintObject_h___ */