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