Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 : #ifndef nsSimplePageSequenceFrame_h___
6 : #define nsSimplePageSequenceFrame_h___
7 :
8 : #include "mozilla/Attributes.h"
9 : #include "nsIPageSequenceFrame.h"
10 : #include "nsContainerFrame.h"
11 : #include "nsIPrintSettings.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : class HTMLCanvasElement;
17 :
18 : } // namespace dom
19 : } // namespace mozilla
20 :
21 : //-----------------------------------------------
22 : // This class maintains all the data that
23 : // is used by all the page frame
24 : // It lives while the nsSimplePageSequenceFrame lives
25 0 : class nsSharedPageData {
26 : public:
27 : // This object a shared by all the nsPageFrames
28 : // parented to a SimplePageSequenceFrame
29 0 : nsSharedPageData() : mShrinkToFitRatio(1.0f) {}
30 :
31 : nsString mDateTimeStr;
32 : nsString mPageNumFormat;
33 : nsString mPageNumAndTotalsFormat;
34 : nsString mDocTitle;
35 : nsString mDocURL;
36 : nsFont mHeadFootFont;
37 :
38 : nsSize mReflowSize;
39 : nsMargin mReflowMargin;
40 : // Margin for headers and footers; it defaults to 4/100 of an inch on UNIX
41 : // and 0 elsewhere; I think it has to do with some inconsistency in page size
42 : // computations
43 : nsMargin mEdgePaperMargin;
44 :
45 : nsCOMPtr<nsIPrintSettings> mPrintSettings;
46 :
47 : // The scaling ratio we need to apply to make all pages fit horizontally. It's
48 : // the minimum "ComputedWidth / OverflowWidth" ratio of all page content frames
49 : // that overflowed. It's 1.0 if none overflowed horizontally.
50 : float mShrinkToFitRatio;
51 : };
52 :
53 : // Simple page sequence frame class. Used when we're in paginated mode
54 : class nsSimplePageSequenceFrame final
55 : : public nsContainerFrame
56 : , public nsIPageSequenceFrame
57 : {
58 : public:
59 : friend nsSimplePageSequenceFrame* NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell,
60 : nsStyleContext* aContext);
61 :
62 : NS_DECL_QUERYFRAME
63 0 : NS_DECL_FRAMEARENA_HELPERS(nsSimplePageSequenceFrame)
64 :
65 : // nsIFrame
66 : void Reflow(nsPresContext* aPresContext,
67 : ReflowOutput& aDesiredSize,
68 : const ReflowInput& aMaxSize,
69 : nsReflowStatus& aStatus) override;
70 :
71 : void BuildDisplayList(nsDisplayListBuilder* aBuilder,
72 : const nsRect& aDirtyRect,
73 : const nsDisplayListSet& aLists) override;
74 :
75 : // nsIPageSequenceFrame
76 0 : NS_IMETHOD SetPageNo(int32_t aPageNo) { return NS_OK;}
77 0 : NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) override { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
78 0 : NS_IMETHOD SetTotalNumPages(int32_t aTotal) override { mTotalPages = aTotal; return NS_OK; }
79 :
80 : // For Shrink To Fit
81 : NS_IMETHOD GetSTFPercent(float& aSTFPercent) override;
82 :
83 : // Async Printing
84 : NS_IMETHOD StartPrint(nsPresContext* aPresContext,
85 : nsIPrintSettings* aPrintSettings,
86 : const nsAString& aDocTitle,
87 : const nsAString& aDocURL) override;
88 : NS_IMETHOD PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone) override;
89 : NS_IMETHOD PrintNextPage() override;
90 : NS_IMETHOD ResetPrintCanvasList() override;
91 : NS_IMETHOD GetCurrentPageNum(int32_t* aPageNum) override;
92 : NS_IMETHOD GetNumPages(int32_t* aNumPages) override;
93 : NS_IMETHOD IsDoingPrintRange(bool* aDoing) override;
94 : NS_IMETHOD GetPrintRange(int32_t* aFromPage, int32_t* aToPage) override;
95 : NS_IMETHOD DoPageEnd() override;
96 :
97 : // We must allow Print Preview UI to have a background, no matter what the
98 : // user's settings
99 0 : bool HonorPrintBackgroundSettings() override { return false; }
100 :
101 0 : bool HasTransformGetter() const override { return true; }
102 :
103 : /**
104 : * Return our first page frame.
105 : */
106 : void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
107 :
108 : #ifdef DEBUG_FRAME_DUMP
109 : nsresult GetFrameName(nsAString& aResult) const override;
110 : #endif
111 :
112 : protected:
113 : explicit nsSimplePageSequenceFrame(nsStyleContext* aContext);
114 : virtual ~nsSimplePageSequenceFrame();
115 :
116 : void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, bool aPageNumOnly);
117 :
118 : // SharedPageData Helper methods
119 : void SetDateTimeStr(const nsAString& aDateTimeStr);
120 : void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
121 :
122 : // Sets the frame desired size to the size of the viewport, or the given
123 : // nscoords, whichever is larger. Print scaling is applied in this function.
124 : void SetDesiredSize(ReflowOutput& aDesiredSize,
125 : const ReflowInput& aReflowInput,
126 : nscoord aWidth, nscoord aHeight);
127 :
128 : // Helper function to compute the offset needed to center a child
129 : // page-frame's margin-box inside our content-box.
130 : nscoord ComputeCenteringMargin(nscoord aContainerContentBoxWidth,
131 : nscoord aChildPaddingBoxWidth,
132 : const nsMargin& aChildPhysicalMargin);
133 :
134 :
135 : void DetermineWhetherToPrintPage();
136 : nsIFrame* GetCurrentPageFrame();
137 :
138 : nsMargin mMargin;
139 :
140 : nsSize mSize;
141 : nsSharedPageData* mPageData; // data shared by all the nsPageFrames
142 :
143 : // Asynch Printing
144 : int32_t mPageNum;
145 : int32_t mTotalPages;
146 : int32_t mPrintRangeType;
147 : int32_t mFromPageNum;
148 : int32_t mToPageNum;
149 : nsTArray<int32_t> mPageRanges;
150 : nsTArray<RefPtr<mozilla::dom::HTMLCanvasElement> > mCurrentCanvasList;
151 :
152 : // Selection Printing Info
153 : nscoord mSelectionHeight;
154 : nscoord mYSelOffset;
155 :
156 : // Asynch Printing
157 : bool mPrintThisPage;
158 : bool mDoingPageRange;
159 :
160 : bool mIsPrintingSelection;
161 :
162 : bool mCalledBeginPage;
163 :
164 : bool mCurrentCanvasListSetup;
165 : };
166 :
167 : #endif /* nsSimplePageSequenceFrame_h___ */
168 :
|