Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / nsPageFrame.h
blob616d508a86f745fafa57050266460043a280b6f4
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 nsPageFrame_h___
7 #define nsPageFrame_h___
9 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
11 #include "nsLeafFrame.h"
13 class nsFontMetrics;
14 class nsPageContentFrame;
15 class nsSharedPageData;
17 namespace mozilla {
18 class PresShell;
19 } // namespace mozilla
21 // Page frame class. Represents an individual page, in paginated mode.
22 class nsPageFrame final : public nsContainerFrame {
23 public:
24 NS_DECL_QUERYFRAME
25 NS_DECL_FRAMEARENA_HELPERS(nsPageFrame)
27 friend nsPageFrame* NS_NewPageFrame(mozilla::PresShell* aPresShell,
28 ComputedStyle* aStyle);
30 void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
31 const ReflowInput& aReflowInput,
32 nsReflowStatus& aStatus) override;
34 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
35 const nsDisplayListSet& aLists) override;
37 #ifdef DEBUG_FRAME_DUMP
38 nsresult GetFrameName(nsAString& aResult) const override;
39 #endif
41 //////////////////
42 // For Printing
43 //////////////////
45 // Determine this page's page-number, based on its previous continuation
46 // (whose page number is presumed to already be known).
47 void DeterminePageNum();
48 int32_t GetPageNum() const { return mPageNum; }
50 void SetSharedPageData(nsSharedPageData* aPD);
51 nsSharedPageData* GetSharedPageData() const { return mPD; }
53 void PaintHeaderFooter(gfxContext& aRenderingContext, nsPoint aPt,
54 bool aSubpixelAA);
56 const nsMargin& GetUsedPageContentMargin() const {
57 return mPageContentMargin;
60 uint32_t IndexOnSheet() const { return mIndexOnSheet; }
61 void SetIndexOnSheet(uint32_t aIndexOnSheet) {
62 mIndexOnSheet = aIndexOnSheet;
65 ComputeTransformFunction GetTransformGetter() const override;
67 nsPageContentFrame* PageContentFrame() const;
69 nsSize ComputePageSize() const;
71 // Computes the scaling factor to fit the page to the sheet in the single
72 // page-per-sheet case. (The multiple pages-per-sheet case is currently
73 // different - see the comment for
74 // PrintedSheetFrame::ComputePagesPerSheetGridMetrics and code in
75 // ComputePagesPerSheetAndPageSizeTransform.) The page and sheet dimensions
76 // may be different due to a CSS page-size that gives the page a size that is
77 // too large to fit on the sheet that we are printing to.
78 float ComputeSinglePPSPageSizeScale(const nsSize aContentPageSize) const;
80 // Returns the rotation from CSS `page-orientation` property, if set, and if
81 // it applies. Note: the single page-per-sheet case is special since in that
82 // case we effectively rotate the sheet (as opposed to rotating pages in
83 // their pages-per-sheet grid cell). In this case we return zero if the
84 // output medium does not support changing the dimensions (orientation) of
85 // the sheet (i.e. only print preview and save-to-PDF are supported).
86 double GetPageOrientationRotation(nsSharedPageData* aPD) const;
88 // The default implementation of FirstContinuation in nsSplittableFrame is
89 // implemented in linear time, walking back through the linked list of
90 // continuations via mPrevContinuation.
91 // For nsPageFrames, we can find the first continuation through the frame
92 // tree structure in constant time.
93 nsIFrame* FirstContinuation() const final;
95 protected:
96 explicit nsPageFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
97 virtual ~nsPageFrame();
99 typedef enum { eHeader, eFooter } nsHeaderFooterEnum;
101 nscoord GetXPosition(gfxContext& aRenderingContext,
102 nsFontMetrics& aFontMetrics, const nsRect& aRect,
103 int32_t aJust, const nsString& aStr);
105 nsReflowStatus ReflowPageContent(nsPresContext*,
106 const ReflowInput& aPageReflowInput);
108 void DrawHeaderFooter(gfxContext& aRenderingContext,
109 nsFontMetrics& aFontMetrics,
110 nsHeaderFooterEnum aHeaderFooter, int32_t aJust,
111 const nsString& sStr, const nsRect& aRect,
112 nscoord aHeight, nscoord aAscent, nscoord aWidth);
114 void DrawHeaderFooter(gfxContext& aRenderingContext,
115 nsFontMetrics& aFontMetrics,
116 nsHeaderFooterEnum aHeaderFooter,
117 const nsString& aStrLeft, const nsString& aStrRight,
118 const nsString& aStrCenter, const nsRect& aRect,
119 nscoord aAscent, nscoord aHeight);
121 void ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr);
123 static constexpr int32_t kPageNumUnset = -1;
124 // 1-based page-num
125 int32_t mPageNum = kPageNumUnset;
127 // 0-based index on the sheet that we belong to. Unused/meaningless if this
128 // page has frame state bit NS_PAGE_SKIPPED_BY_CUSTOM_RANGE.
129 uint32_t mIndexOnSheet = 0;
131 // Note: this will be set before reflow, and it's strongly owned by our
132 // nsPageSequenceFrame, which outlives us.
133 nsSharedPageData* mPD = nullptr;
135 // Computed page content margins.
137 // This is the amount of space from the edges of the content to the edges,
138 // measured in the content coordinate space. This is as opposed to the
139 // coordinate space of the physical paper. This might be different due to
140 // a CSS page-size that is too large to fit on the paper, causing content to
141 // be scaled to fit.
143 // These margins take into account:
144 // * CSS-defined margins (content units)
145 // * User-supplied margins (physical units)
146 // * Unwriteable-supplied margins (physical units)
148 // When computing these margins, all physical units have the inverse of the
149 // scaling factor caused by CSS page-size downscaling applied. This ensures
150 // that even if the content will be downscaled, it will respect the (now
151 // upscaled) physical unwriteable margins required by the printer.
152 // For user-supplied margins, it isn't immediately obvious to the user what
153 // the intended page-size of the document is, so we consider these margins to
154 // be in the physical space of the paper.
155 nsMargin mPageContentMargin;
158 class nsPageBreakFrame final : public nsLeafFrame {
159 NS_DECL_FRAMEARENA_HELPERS(nsPageBreakFrame)
161 explicit nsPageBreakFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
162 ~nsPageBreakFrame();
164 void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
165 const ReflowInput& aReflowInput,
166 nsReflowStatus& aStatus) override;
168 #ifdef DEBUG_FRAME_DUMP
169 nsresult GetFrameName(nsAString& aResult) const override;
170 #endif
172 protected:
173 nscoord GetIntrinsicISize() override;
174 nscoord GetIntrinsicBSize() override;
176 friend nsIFrame* NS_NewPageBreakFrame(mozilla::PresShell* aPresShell,
177 ComputedStyle* aStyle);
180 #endif /* nsPageFrame_h___ */