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
;
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
32 nsSharedPageData() : mShrinkToFitRatio(1.0f
) {}
34 nsString mDateTimeStr
;
35 nsString mPageNumFormat
;
36 nsString mPageNumAndTotalsFormat
;
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
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
{
61 friend nsSimplePageSequenceFrame
* NS_NewSimplePageSequenceFrame(nsIPresShell
* aPresShell
,
62 nsStyleContext
* aContext
);
65 NS_DECL_FRAMEARENA_HELPERS
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
; }
83 NS_IMETHOD
GetSTFPercent(float& aSTFPercent
) MOZ_OVERRIDE
;
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
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
;
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();
137 // I18N date formatter service which we'll want to cache locally.
138 nsCOMPtr
<nsIDateTimeFormat
> mDateFormatter
;
141 nsSharedPageData
* mPageData
; // data shared by all the nsPageFrames
146 int32_t mPrintRangeType
;
147 int32_t mFromPageNum
;
149 nsTArray
<int32_t> mPageRanges
;
150 nsTArray
<nsRefPtr
<mozilla::dom::HTMLCanvasElement
> > mCurrentCanvasList
;
152 // Selection Printing Info
153 nscoord mSelectionHeight
;
158 bool mDoingPageRange
;
160 bool mIsPrintingSelection
;
162 bool mCalledBeginPage
;
164 bool mCurrentCanvasListSetup
;
167 #endif /* nsSimplePageSequenceFrame_h___ */