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 http://mozilla.org/MPL/2.0/. */
6 #ifndef nsPageSequenceFrame_h___
7 #define nsPageSequenceFrame_h___
9 #include "mozilla/Attributes.h"
10 #include "mozilla/UniquePtr.h"
11 #include "nsContainerFrame.h"
12 #include "nsIPrintSettings.h"
17 class PrintedSheetFrame
;
21 class HTMLCanvasElement
;
24 } // namespace mozilla
26 //-----------------------------------------------
27 // This class is used to manage some static data about the layout
28 // characteristics of our various "Pages Per Sheet" options.
29 struct nsPagesPerSheetInfo
{
30 static const nsPagesPerSheetInfo
& LookupInfo(int32_t aPPS
);
34 // This is the larger of the row-count vs. column-count for this layout
35 // (if they aren't the same). We'll aim to stack this number of pages
36 // in the sheet's longer axis.
37 uint16_t mLargerNumTracks
;
41 * This class maintains various shared data that is used by printing-related
42 * frames. The nsPageSequenceFrame strongly owns an instance of this class,
43 * which lives for as long as the nsPageSequenceFrame does.
45 class nsSharedPageData
{
47 nsString mDateTimeStr
;
48 nsString mPageNumFormat
;
49 nsString mPageNumAndTotalsFormat
;
54 // Total number of pages (populated by PrintedSheetFrame when it determines
55 // that it's reflowed the final page):
56 int32_t mRawNumPages
= 0;
58 // If there's more than one page-range, then its components are stored here
59 // as pairs of (start,end). They're stored in the order provided (not
60 // necessarily in ascending order).
61 nsTArray
<int32_t> mPageRanges
;
63 // Margin for headers and footers; it defaults to 4/100 of an inch on UNIX
64 // and 0 elsewhere; I think it has to do with some inconsistency in page size
66 nsMargin mEdgePaperMargin
;
68 nsCOMPtr
<nsIPrintSettings
> mPrintSettings
;
70 // The scaling ratio we need to apply to make all pages fit horizontally. It's
71 // the minimum "ComputedWidth / OverflowWidth" ratio of all page content
72 // frames that overflowed. It's 1.0 if none overflowed horizontally.
73 float mShrinkToFitRatio
= 1.0f
;
75 // Lazy getter, to look up our pages-per-sheet info based on mPrintSettings
76 // (if it's available). The result is stored in our mPagesPerSheetInfo
77 // member-var to speed up subsequent lookups.
78 // This API is infallible; in failure cases, it just returns the info struct
79 // that corresponds to 1 page per sheet.
80 const nsPagesPerSheetInfo
* PagesPerSheetInfo();
83 const nsPagesPerSheetInfo
* mPagesPerSheetInfo
= nullptr;
86 // Page sequence frame class. Manages a series of pages, in paginated mode.
87 // (Strictly speaking, this frame's direct children are PrintedSheetFrame
88 // instances, and each of those will usually contain one nsPageFrame, depending
89 // on the "pages-per-sheet" setting and whether the print operation is
90 // restricted to a custom page range.)
91 class nsPageSequenceFrame final
: public nsContainerFrame
{
92 using LogicalSize
= mozilla::LogicalSize
;
95 friend nsPageSequenceFrame
* NS_NewPageSequenceFrame(
96 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
99 NS_DECL_FRAMEARENA_HELPERS(nsPageSequenceFrame
)
102 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aReflowOutput
,
103 const ReflowInput
& aReflowInput
,
104 nsReflowStatus
& aStatus
) override
;
106 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
107 const nsDisplayListSet
& aLists
) override
;
110 float GetSTFPercent() const { return mPageData
->mShrinkToFitRatio
; }
112 // Gets the final print preview scale that we're applying to the previewed
114 float GetPrintPreviewScale() const;
117 nsresult
StartPrint(nsPresContext
* aPresContext
,
118 nsIPrintSettings
* aPrintSettings
,
119 const nsAString
& aDocTitle
, const nsAString
& aDocURL
);
120 nsresult
PrePrintNextSheet(nsITimerCallback
* aCallback
, bool* aDone
);
121 nsresult
PrintNextSheet();
122 void ResetPrintCanvasList();
124 uint32_t GetCurrentSheetIdx() const { return mCurrentSheetIdx
; }
126 int32_t GetRawNumPages() const { return mPageData
->mRawNumPages
; }
128 uint32_t GetPagesInFirstSheet() const;
130 nsresult
DoPageEnd();
132 ComputeTransformFunction
GetTransformGetter() const override
;
134 #ifdef DEBUG_FRAME_DUMP
135 nsresult
GetFrameName(nsAString
& aResult
) const override
;
139 nsPageSequenceFrame(ComputedStyle
*, nsPresContext
*);
140 virtual ~nsPageSequenceFrame();
142 void SetPageNumberFormat(const char* aPropName
, const char* aDefPropVal
,
145 // SharedPageData Helper methods
146 void SetDateTimeStr(const nsAString
& aDateTimeStr
);
147 void SetPageNumberFormat(const nsAString
& aFormatStr
, bool aForPageNumOnly
);
149 // Print scaling is applied in this function.
150 void PopulateReflowOutput(ReflowOutput
&, const ReflowInput
&);
152 // Helper function to compute the offset needed to center a child
153 // page-frame's margin-box inside our content-box.
154 nscoord
ComputeCenteringMargin(nscoord aContainerContentBoxWidth
,
155 nscoord aChildPaddingBoxWidth
,
156 const nsMargin
& aChildPhysicalMargin
);
158 mozilla::PrintedSheetFrame
* GetCurrentSheetFrame();
162 // These next two LogicalSize members are used when we're in print-preview to
163 // ensure that each previewed sheet will fit in the print-preview scrollport:
166 // Each component of this LogicalSize represents the maximum length of all
167 // our print-previewed sheets in that axis, plus a little extra for the
168 // print-preview margin. Note that this LogicalSize doesn't necessarily
169 // correspond to any one particular sheet's size (especially if our sheets
170 // have different sizes), since the components are tracked independently such
171 // that we end up storing the maximum in each dimension.
172 LogicalSize mMaxSheetSize
;
173 // The size of the scrollport where we're print-previewing sheets.
174 LogicalSize mScrollportSize
;
176 // Data shared by all the nsPageFrames:
177 mozilla::UniquePtr
<nsSharedPageData
> mPageData
;
179 // The zero-based index of the PrintedSheetFrame child that is being printed
180 // (or about-to-be-printed), in an async print operation.
181 // This is an index into our PrincipalChildList, effectively.
182 uint32_t mCurrentSheetIdx
= 0;
184 nsTArray
<RefPtr
<mozilla::dom::HTMLCanvasElement
> > mCurrentCanvasList
;
186 bool mCalledBeginPage
;
188 bool mCurrentCanvasListSetup
;
191 #endif /* nsPageSequenceFrame_h___ */