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