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 nsSimplePageSequence_h___
6 #define nsSimplePageSequence_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
;
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
{
30 // This object a shared by all the nsPageFrames
31 // parented to a SimplePageSequenceFrame
38 nsString mDateTimeStr
;
39 nsString mPageNumFormat
;
40 nsString mPageNumAndTotalsFormat
;
46 nsMargin mReflowMargin
;
47 // Margin for headers and footers; it defaults to 4/100 of an inch on UNIX
48 // and 0 elsewhere; I think it has to do with some inconsistency in page size
50 nsMargin mEdgePaperMargin
;
52 nsCOMPtr
<nsIPrintSettings
> mPrintSettings
;
53 nsCOMPtr
<nsIPrintOptions
> mPrintOptions
;
55 nscoord mPageContentXMost
; // xmost size from Reflow(width)
56 nscoord mPageContentSize
; // constrained size (width)
59 // Simple page sequence frame class. Used when we're in paginated mode
60 class nsSimplePageSequenceFrame
: public nsContainerFrame
,
61 public nsIPageSequenceFrame
{
63 friend nsIFrame
* NS_NewSimplePageSequenceFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
66 NS_DECL_FRAMEARENA_HELPERS
69 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
70 nsHTMLReflowMetrics
& aDesiredSize
,
71 const nsHTMLReflowState
& aMaxSize
,
72 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
74 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
75 const nsRect
& aDirtyRect
,
76 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
78 // nsIPageSequenceFrame
79 NS_IMETHOD
SetPageNo(int32_t aPageNo
) { return NS_OK
;}
80 NS_IMETHOD
SetSelectionHeight(nscoord aYOffset
, nscoord aHeight
) MOZ_OVERRIDE
{ mYSelOffset
= aYOffset
; mSelectionHeight
= aHeight
; return NS_OK
; }
81 NS_IMETHOD
SetTotalNumPages(int32_t aTotal
) MOZ_OVERRIDE
{ mTotalPages
= aTotal
; return NS_OK
; }
84 NS_IMETHOD
GetSTFPercent(float& aSTFPercent
) MOZ_OVERRIDE
;
87 NS_IMETHOD
StartPrint(nsPresContext
* aPresContext
,
88 nsIPrintSettings
* aPrintSettings
,
89 const nsAString
& aDocTitle
,
90 const nsAString
& aDocURL
) MOZ_OVERRIDE
;
91 NS_IMETHOD
PrePrintNextPage(nsITimerCallback
* aCallback
, bool* aDone
) MOZ_OVERRIDE
;
92 NS_IMETHOD
PrintNextPage() MOZ_OVERRIDE
;
93 NS_IMETHOD
ResetPrintCanvasList() MOZ_OVERRIDE
;
94 NS_IMETHOD
GetCurrentPageNum(int32_t* aPageNum
) MOZ_OVERRIDE
;
95 NS_IMETHOD
GetNumPages(int32_t* aNumPages
) MOZ_OVERRIDE
;
96 NS_IMETHOD
IsDoingPrintRange(bool* aDoing
) MOZ_OVERRIDE
;
97 NS_IMETHOD
GetPrintRange(int32_t* aFromPage
, int32_t* aToPage
) MOZ_OVERRIDE
;
98 NS_IMETHOD
DoPageEnd() MOZ_OVERRIDE
;
100 // We must allow Print Preview UI to have a background, no matter what the
102 virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE
{ return false; }
104 virtual bool HasTransformGetter() const MOZ_OVERRIDE
{ return true; }
107 * Get the "type" of the frame
109 * @see nsGkAtoms::sequenceFrame
111 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
114 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
118 nsSimplePageSequenceFrame(nsStyleContext
* aContext
);
119 virtual ~nsSimplePageSequenceFrame();
121 void SetPageNumberFormat(const char* aPropName
, const char* aDefPropVal
, bool aPageNumOnly
);
123 // SharedPageData Helper methods
124 void SetDateTimeStr(const nsAString
& aDateTimeStr
);
125 void SetPageNumberFormat(const nsAString
& aFormatStr
, bool aForPageNumOnly
);
127 // Sets the frame desired size to the size of the viewport, or the given
128 // nscoords, whichever is larger. Print scaling is applied in this function.
129 void SetDesiredSize(nsHTMLReflowMetrics
& aDesiredSize
,
130 const nsHTMLReflowState
& aReflowState
,
131 nscoord aWidth
, nscoord aHeight
);
133 void DetermineWhetherToPrintPage();
134 nsIFrame
* GetCurrentPageFrame();
138 // I18N date formatter service which we'll want to cache locally.
139 nsCOMPtr
<nsIDateTimeFormat
> mDateFormatter
;
142 nsSharedPageData
* mPageData
; // data shared by all the nsPageFrames
147 int32_t mPrintRangeType
;
148 int32_t mFromPageNum
;
150 nsTArray
<int32_t> mPageRanges
;
151 nsTArray
<nsRefPtr
<mozilla::dom::HTMLCanvasElement
> > mCurrentCanvasList
;
153 // Selection Printing Info
154 nscoord mSelectionHeight
;
159 bool mDoingPageRange
;
161 bool mIsPrintingSelection
;
163 bool mCalledBeginPage
;
165 bool mCurrentCanvasListSetup
;
168 #endif /* nsSimplePageSequence_h___ */