1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 /* Rendering object for a printed or print-previewed sheet of paper */
9 #ifndef LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_
10 #define LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_
12 #include "mozilla/gfx/Point.h"
13 #include "nsContainerFrame.h"
14 #include "nsHTMLParts.h"
16 class nsSharedPageData
;
20 class PrintedSheetFrame final
: public nsContainerFrame
{
22 using IntSize
= mozilla::gfx::IntSize
;
25 NS_DECL_FRAMEARENA_HELPERS(PrintedSheetFrame
)
27 friend PrintedSheetFrame
* ::NS_NewPrintedSheetFrame(
28 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
30 void SetSharedPageData(nsSharedPageData
* aPD
) { mPD
= aPD
; }
32 // XXX: this needs a better name, since it also updates style.
33 // Invokes MoveOverflowToChildList.
34 // This is intended for use by callers that need to be able to get our first/
35 // only nsPageFrame from our child list to examine its computed style just
36 // **prior** to us being reflowed. (If our first nsPageFrame will come from
37 // our prev-in-flow, we won't otherwise take ownership of it until we are
39 void ClaimPageFrameFromPrevInFlow();
42 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aReflowOutput
,
43 const ReflowInput
& aReflowInput
,
44 nsReflowStatus
& aStatus
) override
;
46 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
47 const nsDisplayListSet
& aLists
) override
;
49 #ifdef DEBUG_FRAME_DUMP
50 nsresult
GetFrameName(nsAString
& aResult
) const override
;
53 uint32_t GetNumPages() const { return mNumPages
; }
55 // These methods provide information about the grid that pages should be
56 // placed into in the case that there are multiple pages-per-sheet.
57 uint32_t GetGridNumCols() const { return mGridNumCols
; }
58 nsPoint
GetGridOrigin() const { return mGridOrigin
; }
59 nscoord
GetGridCellWidth() const { return mGridCellWidth
; }
60 nscoord
GetGridCellHeight() const { return mGridCellHeight
; }
62 nsSize
ComputeSheetSize(const nsPresContext
* aPresContext
);
65 * When we're printing one page-per-sheet and `page-orientation` on our
66 * single nsPageFrame child should cause the page to rotate, then we want to
67 * essentially rotate the sheet. We implement that by switching the
68 * dimensions of this sheet (changing its orientation), sizing the
69 * nsPageFrame to the original dimensions, and then applying the rotation to
70 * the nsPageFrame child.
72 * This returns the dimensions that this frame would have without any
73 * dimension swap we may have done to implement `page-orientation`. If
74 * there is no rotation caused by `page-orientation`, then the value returned
75 * and mRect.Size() are identical.
77 nsSize
GetSizeForChildren() const { return mSizeForChildren
; }
80 * This method returns the dimensions of the physical page that the target
81 * [pseudo-]printer should create. This may be different from our own
82 * dimensions in the case where CSS `page-orientation` causes us to be
83 * rotated, but we only support that if the PrintTarget backend supports
84 * different page sizes/orientations. That's only the case for our Save-to-PDF
85 * backends (possibly other save-to-file outputs in future).
87 * The dimensions returned are expected to be passed to
88 * nsDeviceContext::BeginPage, which will pass them on to
89 * PrintTarget::BeginPage to use as the physical dimensions of the page.
91 IntSize
GetPrintTargetSizeInPoints(
92 const int32_t aAppUnitsPerPhysicalInch
) const;
95 // Private construtor & destructor, to avoid accidental (non-FrameArena)
96 // instantiation/deletion:
97 PrintedSheetFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
98 : nsContainerFrame(aStyle
, aPresContext
, kClassID
) {}
99 ~PrintedSheetFrame() = default;
101 // Helper function to populate some pages-per-sheet metrics in our
103 // XXXjwatt: We should investigate sharing this function for the single
104 // page-per-sheet case (bug 1835782). The logic for that case
105 // (nsPageFrame::ComputePageSizeScale) is somewhat different though, since
106 // that case uses no sheet margins and uses the user/CSS specified margins on
107 // the page, with any page scaling reverted to keep the margins unchanged.
108 // We, on the other hand, use the unwriteable margins for the sheet, unscaled,
109 // and use the user/CSS margins on the pages and allow them to be scaled
110 // along with any pages-per-sheet scaling. (This behavior makes maximum use
111 // of the sheet and, by scaling the default on the pages, results in a
112 // a sensible amount of spacing between pages.)
113 void ComputePagesPerSheetGridMetrics(const nsSize
& aSheetSize
);
115 // See GetSizeForChildren.
116 nsSize mSizeForChildren
;
118 // Note: this will be set before reflow, and it's strongly owned by our
119 // nsPageSequenceFrame, which outlives us.
120 nsSharedPageData
* mPD
= nullptr;
122 // The number of visible pages in this sheet.
123 uint32_t mNumPages
= 0;
125 // Number of "columns" in our pages-per-sheet layout. For example: if we're
126 // printing with 6 pages-per-sheet, then this could be either 3 or 2,
127 // depending on whether we're printing portrait-oriented pages onto a
128 // landscape-oriented sheet (3 cols) vs. if we're printing landscape-oriented
129 // pages onto a portrait-oriented sheet (2 cols).
130 uint32_t mGridNumCols
= 1;
132 // The offset of the start of the multiple pages-per-sheet grid from the
133 // top-left of the sheet.
136 // The size of each cell on the sheet into which pages are to be placed.
137 // (The default values are arbitrary.)
138 nscoord mGridCellWidth
= 1;
139 nscoord mGridCellHeight
= 1;
142 } // namespace mozilla
144 #endif /* LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_ */