Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsSimplePageSequenceFrame.h
blob2f5471c3c1165995cafd7067cfb2f67d75fa9526
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___
8 #include "mozilla/Attributes.h"
9 #include "nsIPageSequenceFrame.h"
10 #include "nsContainerFrame.h"
11 #include "nsIPrintSettings.h"
12 #include "nsIPrintOptions.h"
14 class nsIDateTimeFormat;
16 namespace mozilla {
17 namespace dom {
19 class HTMLCanvasElement;
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) {}
34 nsString mDateTimeStr;
35 nsString mPageNumFormat;
36 nsString mPageNumAndTotalsFormat;
37 nsString mDocTitle;
38 nsString mDocURL;
39 nsFont mHeadFootFont;
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;
48 nsCOMPtr<nsIPrintSettings> mPrintSettings;
49 nsCOMPtr<nsIPrintOptions> mPrintOptions;
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;
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 nsSimplePageSequenceFrame* NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell,
62 nsStyleContext* aContext);
64 NS_DECL_QUERYFRAME
65 NS_DECL_FRAMEARENA_HELPERS
67 // nsIFrame
68 virtual void Reflow(nsPresContext* aPresContext,
69 nsHTMLReflowMetrics& aDesiredSize,
70 const nsHTMLReflowState& aMaxSize,
71 nsReflowStatus& aStatus) MOZ_OVERRIDE;
73 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
74 const nsRect& aDirtyRect,
75 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
77 // nsIPageSequenceFrame
78 NS_IMETHOD SetPageNo(int32_t aPageNo) { return NS_OK;}
79 NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) MOZ_OVERRIDE { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
80 NS_IMETHOD SetTotalNumPages(int32_t aTotal) MOZ_OVERRIDE { mTotalPages = aTotal; return NS_OK; }
82 // For Shrink To Fit
83 NS_IMETHOD GetSTFPercent(float& aSTFPercent) MOZ_OVERRIDE;
85 // Async Printing
86 NS_IMETHOD StartPrint(nsPresContext* aPresContext,
87 nsIPrintSettings* aPrintSettings,
88 const nsAString& aDocTitle,
89 const nsAString& aDocURL) MOZ_OVERRIDE;
90 NS_IMETHOD PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone) MOZ_OVERRIDE;
91 NS_IMETHOD PrintNextPage() MOZ_OVERRIDE;
92 NS_IMETHOD ResetPrintCanvasList() MOZ_OVERRIDE;
93 NS_IMETHOD GetCurrentPageNum(int32_t* aPageNum) MOZ_OVERRIDE;
94 NS_IMETHOD GetNumPages(int32_t* aNumPages) MOZ_OVERRIDE;
95 NS_IMETHOD IsDoingPrintRange(bool* aDoing) MOZ_OVERRIDE;
96 NS_IMETHOD GetPrintRange(int32_t* aFromPage, int32_t* aToPage) MOZ_OVERRIDE;
97 NS_IMETHOD DoPageEnd() MOZ_OVERRIDE;
99 // We must allow Print Preview UI to have a background, no matter what the
100 // user's settings
101 virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE { return false; }
103 virtual bool HasTransformGetter() const MOZ_OVERRIDE { return true; }
106 * Get the "type" of the frame
108 * @see nsGkAtoms::sequenceFrame
110 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
112 #ifdef DEBUG_FRAME_DUMP
113 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
114 #endif
116 protected:
117 explicit nsSimplePageSequenceFrame(nsStyleContext* aContext);
118 virtual ~nsSimplePageSequenceFrame();
120 void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, bool aPageNumOnly);
122 // SharedPageData Helper methods
123 void SetDateTimeStr(const nsAString& aDateTimeStr);
124 void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
126 // Sets the frame desired size to the size of the viewport, or the given
127 // nscoords, whichever is larger. Print scaling is applied in this function.
128 void SetDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
129 const nsHTMLReflowState& aReflowState,
130 nscoord aWidth, nscoord aHeight);
132 void DetermineWhetherToPrintPage();
133 nsIFrame* GetCurrentPageFrame();
135 nsMargin mMargin;
137 // I18N date formatter service which we'll want to cache locally.
138 nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
140 nsSize mSize;
141 nsSharedPageData* mPageData; // data shared by all the nsPageFrames
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<nsRefPtr<mozilla::dom::HTMLCanvasElement> > mCurrentCanvasList;
152 // Selection Printing Info
153 nscoord mSelectionHeight;
154 nscoord mYSelOffset;
156 // Asynch Printing
157 bool mPrintThisPage;
158 bool mDoingPageRange;
160 bool mIsPrintingSelection;
162 bool mCalledBeginPage;
164 bool mCurrentCanvasListSetup;
167 #endif /* nsSimplePageSequenceFrame_h___ */