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___
8 
9 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
11 #include "nsLeafFrame.h"
12 
13 class nsFontMetrics;
14 class nsPageContentFrame;
15 class nsSharedPageData;
16 
17 namespace mozilla {
18 class PresShell;
19 }  // namespace mozilla
20 
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)
26 
27   friend nsPageFrame* NS_NewPageFrame(mozilla::PresShell* aPresShell,
28                                       ComputedStyle* aStyle);
29 
30   void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
31               const ReflowInput& aReflowInput,
32               nsReflowStatus& aStatus) override;
33 
34   void BuildDisplayList(nsDisplayListBuilder* aBuilder,
35                         const nsDisplayListSet& aLists) override;
36 
37 #ifdef DEBUG_FRAME_DUMP
38   nsresult GetFrameName(nsAString& aResult) const override;
39 #endif
40 
41   //////////////////
42   // For Printing
43   //////////////////
44 
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();
GetPageNum()48   int32_t GetPageNum() const { return mPageNum; }
49 
50   void SetSharedPageData(nsSharedPageData* aPD);
GetSharedPageData()51   nsSharedPageData* GetSharedPageData() const { return mPD; }
52 
53   // We must allow Print Preview UI to have a background, no matter what the
54   // user's settings
HonorPrintBackgroundSettings()55   bool HonorPrintBackgroundSettings() const override { return false; }
56 
57   void PaintHeaderFooter(gfxContext& aRenderingContext, nsPoint aPt,
58                          bool aSubpixelAA);
59 
GetUsedPageContentMargin()60   const nsMargin& GetUsedPageContentMargin() const {
61     return mPageContentMargin;
62   }
63 
IndexOnSheet()64   uint32_t IndexOnSheet() const { return mIndexOnSheet; }
SetIndexOnSheet(uint32_t aIndexOnSheet)65   void SetIndexOnSheet(uint32_t aIndexOnSheet) {
66     mIndexOnSheet = aIndexOnSheet;
67   }
68 
69   ComputeTransformFunction GetTransformGetter() const override;
70 
71   nsPageContentFrame* PageContentFrame() const;
72 
73   nsSize ComputePageSize() const;
74 
75  protected:
76   explicit nsPageFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
77   virtual ~nsPageFrame();
78 
79   typedef enum { eHeader, eFooter } nsHeaderFooterEnum;
80 
81   nscoord GetXPosition(gfxContext& aRenderingContext,
82                        nsFontMetrics& aFontMetrics, const nsRect& aRect,
83                        int32_t aJust, const nsString& aStr);
84 
85   nsReflowStatus ReflowPageContent(nsPresContext*,
86                                    const ReflowInput& aPageReflowInput);
87 
88   void DrawHeaderFooter(gfxContext& aRenderingContext,
89                         nsFontMetrics& aFontMetrics,
90                         nsHeaderFooterEnum aHeaderFooter, int32_t aJust,
91                         const nsString& sStr, const nsRect& aRect,
92                         nscoord aHeight, nscoord aAscent, nscoord aWidth);
93 
94   void DrawHeaderFooter(gfxContext& aRenderingContext,
95                         nsFontMetrics& aFontMetrics,
96                         nsHeaderFooterEnum aHeaderFooter,
97                         const nsString& aStrLeft, const nsString& aStrRight,
98                         const nsString& aStrCenter, const nsRect& aRect,
99                         nscoord aAscent, nscoord aHeight);
100 
101   void ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr);
102 
103   static constexpr int32_t kPageNumUnset = -1;
104   // 1-based page-num
105   int32_t mPageNum = kPageNumUnset;
106 
107   // 0-based index on the sheet that we belong to. Unused/meaningless if this
108   // page has frame state bit NS_PAGE_SKIPPED_BY_CUSTOM_RANGE.
109   uint32_t mIndexOnSheet = 0;
110 
111   // Note: this will be set before reflow, and it's strongly owned by our
112   // nsPageSequenceFrame, which outlives us.
113   nsSharedPageData* mPD = nullptr;
114 
115   nsMargin mPageContentMargin;
116 };
117 
118 class nsPageBreakFrame final : public nsLeafFrame {
119   NS_DECL_FRAMEARENA_HELPERS(nsPageBreakFrame)
120 
121   explicit nsPageBreakFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
122   ~nsPageBreakFrame();
123 
124   void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
125               const ReflowInput& aReflowInput,
126               nsReflowStatus& aStatus) override;
127 
128 #ifdef DEBUG_FRAME_DUMP
129   nsresult GetFrameName(nsAString& aResult) const override;
130 #endif
131 
132  protected:
133   nscoord GetIntrinsicISize() override;
134   nscoord GetIntrinsicBSize() override;
135 
136   bool mHaveReflowed;
137 
138   friend nsIFrame* NS_NewPageBreakFrame(mozilla::PresShell* aPresShell,
139                                         ComputedStyle* aStyle);
140 };
141 
142 #endif /* nsPageFrame_h___ */
143