Bug 1760439 [wpt PR 33220] - Implement FedCM permission delegates in content_shell...
[gecko.git] / layout / generic / nsPageSequenceFrame.h
blobdd7b4d1fefcfdaefc0233fefb7bab8bd57a6290c
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"
14 namespace mozilla {
16 class PresShell;
17 class PrintedSheetFrame;
19 namespace dom {
21 class HTMLCanvasElement;
23 } // namespace dom
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);
32 uint16_t mNumPages;
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;
40 /**
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 {
46 public:
47 nsString mDateTimeStr;
48 nsString mPageNumFormat;
49 nsString mPageNumAndTotalsFormat;
50 nsString mDocTitle;
51 nsString mDocURL;
52 nsFont mHeadFootFont;
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
65 // computations
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 // The mPagesPerSheet{...} members are only used if
76 // PagesPerSheetInfo()->mNumPages > 1. They're initialized with reasonable
77 // defaults here (which correspond to what we do for the regular
78 // 1-page-per-sheet scenario, though we don't actually use these members in
79 // that case). If we're in >1 pages-per-sheet scenario, then these members
80 // will be assigned "real" values during the reflow of the first
81 // PrintedSheetFrame.
82 float mPagesPerSheetScale = 1.0f;
83 // Number of "columns" in our pages-per-sheet layout. For example: if we're
84 // printing with 6 pages-per-sheet, then this could be either 3 or 2,
85 // depending on whether we're printing portrait-oriented pages onto a
86 // landscape-oriented sheet (3 cols) vs. if we're printing landscape-oriented
87 // pages onto a portrait-oriented sheet (2 cols).
88 uint32_t mPagesPerSheetNumCols = 1;
89 nsPoint mPagesPerSheetGridOrigin;
91 // Lazy getter, to look up our pages-per-sheet info based on mPrintSettings
92 // (if it's available). The result is stored in our mPagesPerSheetInfo
93 // member-var to speed up subsequent lookups.
94 // This API is infallible; in failure cases, it just returns the info struct
95 // that corresponds to 1 page per sheet.
96 const nsPagesPerSheetInfo* PagesPerSheetInfo();
98 private:
99 const nsPagesPerSheetInfo* mPagesPerSheetInfo = nullptr;
102 // Page sequence frame class. Manages a series of pages, in paginated mode.
103 // (Strictly speaking, this frame's direct children are PrintedSheetFrame
104 // instances, and each of those will usually contain one nsPageFrame, depending
105 // on the "pages-per-sheet" setting and whether the print operation is
106 // restricted to a custom page range.)
107 class nsPageSequenceFrame final : public nsContainerFrame {
108 using LogicalSize = mozilla::LogicalSize;
110 public:
111 friend nsPageSequenceFrame* NS_NewPageSequenceFrame(
112 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
114 NS_DECL_QUERYFRAME
115 NS_DECL_FRAMEARENA_HELPERS(nsPageSequenceFrame)
117 // nsIFrame
118 void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
119 const ReflowInput& aReflowInput,
120 nsReflowStatus& aStatus) override;
122 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
123 const nsDisplayListSet& aLists) override;
125 // For Shrink To Fit
126 float GetSTFPercent() const { return mPageData->mShrinkToFitRatio; }
128 // Gets the final print preview scale that we're applying to the previewed
129 // sheets of paper.
130 float GetPrintPreviewScale() const;
132 // Async Printing
133 nsresult StartPrint(nsPresContext* aPresContext,
134 nsIPrintSettings* aPrintSettings,
135 const nsAString& aDocTitle, const nsAString& aDocURL);
136 nsresult PrePrintNextSheet(nsITimerCallback* aCallback, bool* aDone);
137 nsresult PrintNextSheet();
138 void ResetPrintCanvasList();
140 uint32_t GetCurrentSheetIdx() const { return mCurrentSheetIdx; }
142 int32_t GetRawNumPages() const { return mPageData->mRawNumPages; }
144 uint32_t GetPagesInFirstSheet() const;
146 nsresult DoPageEnd();
148 // We must allow Print Preview UI to have a background, no matter what the
149 // user's settings
150 bool HonorPrintBackgroundSettings() const override { return false; }
152 ComputeTransformFunction GetTransformGetter() const override;
154 #ifdef DEBUG_FRAME_DUMP
155 nsresult GetFrameName(nsAString& aResult) const override;
156 #endif
158 protected:
159 nsPageSequenceFrame(ComputedStyle*, nsPresContext*);
160 virtual ~nsPageSequenceFrame();
162 void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal,
163 bool aPageNumOnly);
165 // SharedPageData Helper methods
166 void SetDateTimeStr(const nsAString& aDateTimeStr);
167 void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
169 // Print scaling is applied in this function.
170 void PopulateReflowOutput(ReflowOutput&, const ReflowInput&);
172 // Helper function to compute the offset needed to center a child
173 // page-frame's margin-box inside our content-box.
174 nscoord ComputeCenteringMargin(nscoord aContainerContentBoxWidth,
175 nscoord aChildPaddingBoxWidth,
176 const nsMargin& aChildPhysicalMargin);
178 mozilla::PrintedSheetFrame* GetCurrentSheetFrame();
180 nsSize mSize;
182 // These next two LogicalSize members are used when we're in print-preview to
183 // ensure that each previewed sheet will fit in the print-preview scrollport:
184 // -------
186 // Each component of this LogicalSize represents the maximum length of all
187 // our print-previewed sheets in that axis, plus a little extra for the
188 // print-preview margin. Note that this LogicalSize doesn't necessarily
189 // correspond to any one particular sheet's size (especially if our sheets
190 // have different sizes), since the components are tracked independently such
191 // that we end up storing the maximum in each dimension.
192 LogicalSize mMaxSheetSize;
193 // The size of the scrollport where we're print-previewing sheets.
194 LogicalSize mScrollportSize;
196 // Data shared by all the nsPageFrames:
197 mozilla::UniquePtr<nsSharedPageData> mPageData;
199 // The zero-based index of the PrintedSheetFrame child that is being printed
200 // (or about-to-be-printed), in an async print operation.
201 // This is an index into our PrincipalChildList, effectively.
202 uint32_t mCurrentSheetIdx = 0;
204 nsTArray<RefPtr<mozilla::dom::HTMLCanvasElement> > mCurrentCanvasList;
206 bool mCalledBeginPage;
208 bool mCurrentCanvasListSetup;
211 #endif /* nsPageSequenceFrame_h___ */