зеркало из https://github.com/mozilla/pjs.git
Initial check in for print preview work it is complied in for Windows and linix only
The bulk of print preview can be turned on/off with NS_PRINT_PREVIEW define Bug 107562 r=kmcclusk sr=attinasi
This commit is contained in:
Родитель
626f01eda6
Коммит
760f64245a
|
@ -353,7 +353,7 @@ CFLAGS=$(CFLAGS) -DMOZ_SVG
|
|||
CFLAGS=$(CFLAGS) -DMOZ_REFLOW_PERF -DMOZ_REFLOW_PERF_DSP
|
||||
!endif
|
||||
|
||||
CFLAGS=$(CFLAGS) -DUSE_IMG2
|
||||
CFLAGS=$(CFLAGS) -DUSE_IMG2 -DNS_PRINT_PREVIEW
|
||||
|
||||
!ifdef MOZ_STATIC_COMPONENT_LIBS
|
||||
CFLAGS=$(CFLAGS) -DXPCOM_TRANSLATE_NSGM_ENTRY_POINT -DMOZ_STATIC_COMPONENT_LIBS
|
||||
|
|
|
@ -528,6 +528,8 @@ endif
|
|||
DEFINES += -DOSTYPE=\"$(OS_CONFIG)\"
|
||||
DEFINES += -DOSARCH=\"$(OS_ARCH)\"
|
||||
|
||||
DEFINES += -DNS_PRINT_PREVIEW
|
||||
|
||||
ifdef MOZ_DEBUG
|
||||
DEFINES += -DMOZ_REFLOW_PERF -DMOZ_REFLOW_PERF_DSP
|
||||
endif
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -127,6 +127,7 @@ interface nsIDOMWindowInternal : nsIDOMWindow
|
|||
void stop();
|
||||
|
||||
void print();
|
||||
void printPreview();
|
||||
|
||||
void moveTo(in long xPos, in long yPos);
|
||||
void moveBy(in long xDif, in long yDif);
|
||||
|
|
|
@ -1933,20 +1933,35 @@ NS_IMETHODIMP GlobalWindowImpl::Stop()
|
|||
return webNav->Stop(nsIWebNavigation::STOP_ALL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GlobalWindowImpl::Print()
|
||||
nsresult GlobalWindowImpl::DoPrint(PRBool aDoPreview)
|
||||
{
|
||||
if (mDocShell) {
|
||||
nsCOMPtr<nsIContentViewer> viewer;
|
||||
mDocShell->GetContentViewer(getter_AddRefs(viewer));
|
||||
if (viewer) {
|
||||
nsCOMPtr<nsIContentViewerFile> viewerFile(do_QueryInterface(viewer));
|
||||
if (viewerFile)
|
||||
return viewerFile->Print(PR_FALSE, nsnull);
|
||||
if (viewerFile) {
|
||||
if (aDoPreview) {
|
||||
return viewerFile->PrintPreview();
|
||||
} else {
|
||||
return viewerFile->Print(PR_FALSE, nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GlobalWindowImpl::Print()
|
||||
{
|
||||
return DoPrint(PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GlobalWindowImpl::PrintPreview()
|
||||
{
|
||||
return DoPrint(PR_TRUE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos)
|
||||
{
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
|
|
|
@ -236,6 +236,8 @@ protected:
|
|||
nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height);
|
||||
nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top);
|
||||
|
||||
nsresult DoPrint(PRBool aDoPreview);
|
||||
|
||||
// Helper for window.find()
|
||||
nsresult FindInternal(nsAReadableString& aStr, PRBool caseSensitive,
|
||||
PRBool backwards, PRBool wrapAround, PRBool wholeWord,
|
||||
|
|
|
@ -124,6 +124,13 @@ public:
|
|||
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC);
|
||||
NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC) { *aAltDC = mAltDC.get(); NS_IF_ADDREF(*aAltDC); return NS_OK;}
|
||||
NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn);
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual ~DeviceContextImpl();
|
||||
|
@ -150,6 +157,11 @@ protected:
|
|||
nsHashtable* mFontAliasTable;
|
||||
float mCPixelScale;
|
||||
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
nsCOMPtr<nsIDeviceContext> mAltDC;
|
||||
PRUint8 mUseAltDC;
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsNativeWidget mWidget;
|
||||
};
|
||||
|
|
|
@ -94,6 +94,15 @@ typedef void * nsNativeDeviceContext;
|
|||
#define NS_ERROR_GFX_PRINTER_FILE_IO_ERROR \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+12)
|
||||
|
||||
/**
|
||||
* Conts need for Print Preview
|
||||
*/
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
const PRUint8 kUseAltDCFor_NONE = 0x00; // Do not use the AltDC for anything
|
||||
const PRUint8 kUseAltDCFor_FONTMETRICS = 0x01; // Use it for only getting the font metrics
|
||||
const PRUint8 kUseAltDCFor_CREATE_RC = 0x02; // Use when creating RenderingContexts
|
||||
const PRUint8 kUseAltDCFor_SURFACE_DIM = 0x04; // Use it for getting the Surface Dimensions
|
||||
#endif
|
||||
|
||||
#define NS_IDEVICE_CONTEXT_IID \
|
||||
{ 0x5931c580, 0xb917, 0x11d1, \
|
||||
|
@ -415,6 +424,26 @@ public:
|
|||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD EndPage(void) = 0;
|
||||
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
/**
|
||||
* Set an Alternative Device Context where some of the calls
|
||||
* are deferred to it
|
||||
*/
|
||||
NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC) = 0;
|
||||
|
||||
/**
|
||||
* Get the Alternate Device Context
|
||||
*/
|
||||
NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC) = 0;
|
||||
|
||||
/**
|
||||
* Turn on/off which types of information is retrived
|
||||
* via the alt device context
|
||||
*/
|
||||
NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn) = 0;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIDeviceContext_h___ */
|
||||
|
|
|
@ -254,6 +254,13 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
|
|||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&aContext)
|
||||
{
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// Defer to Alt when there is one
|
||||
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATE_RC)) {
|
||||
return mAltDC->CreateRenderingContext(aContext);
|
||||
}
|
||||
#endif
|
||||
|
||||
nsIRenderingContext *pContext;
|
||||
nsresult rv;
|
||||
nsDrawingSurfaceGTK *surf;
|
||||
|
@ -398,6 +405,13 @@ NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName)
|
|||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// Defer to Alt when there is one
|
||||
if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) {
|
||||
return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mWidth == -1)
|
||||
mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ nsresult nsDeviceContextWin :: Init(nsNativeDeviceContext aContext, nsIDeviceCon
|
|||
|
||||
CommonInit(mDC);
|
||||
|
||||
|
||||
GetTwipsToDevUnits(newscale);
|
||||
aOrigContext->GetTwipsToDevUnits(origscale);
|
||||
|
||||
|
@ -273,6 +274,13 @@ static NS_DEFINE_CID(kRCCID,NS_RENDERING_CONTEXT_CID);
|
|||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: CreateRenderingContext(nsIRenderingContext *&aContext)
|
||||
{
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// Defer to Alt when there is one
|
||||
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATE_RC)) {
|
||||
return mAltDC->CreateRenderingContext(aContext);
|
||||
}
|
||||
#endif
|
||||
|
||||
nsIRenderingContext *pContext;
|
||||
nsresult rv;
|
||||
nsDrawingSurfaceWin *surf;
|
||||
|
@ -577,13 +585,21 @@ NS_IMETHODIMP nsDeviceContextWin :: ConvertPixel(nscolor aColor, PRUint32 & aPix
|
|||
|
||||
NS_IMETHODIMP nsDeviceContextWin :: GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// Defer to Alt when there is one
|
||||
if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) {
|
||||
return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( mSpec )
|
||||
{
|
||||
// we have a printer device
|
||||
aWidth = NSToIntRound(mWidth * mDevUnitsToAppUnits);
|
||||
aHeight = NSToIntRound(mHeight * mDevUnitsToAppUnits);
|
||||
}
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
nsRect area;
|
||||
ComputeFullAreaUsingScreen ( &area );
|
||||
aWidth = area.width;
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
#include "nsObjectFrame.h"
|
||||
#include "nsRuleNode.h"
|
||||
#include "nsIXULDocument.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
||||
|
@ -3259,10 +3260,12 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
|
|||
PRBool isScrollable = IsScrollable(aPresContext, display);
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
aPresContext->IsPaginated(&isPaginated);
|
||||
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext(do_QueryInterface(aPresContext));
|
||||
|
||||
nsIFrame* scrollFrame = nsnull;
|
||||
|
||||
// build a scrollframe
|
||||
if (!isPaginated && isScrollable) {
|
||||
if ((!isPaginated || (isPaginated && printPreviewContext)) && isScrollable) {
|
||||
nsIFrame* newScrollFrame = nsnull;
|
||||
nsCOMPtr<nsIStyleContext> newContext;
|
||||
|
||||
|
@ -3541,6 +3544,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
aPresContext->IsPaginated(&isPaginated);
|
||||
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext(do_QueryInterface(aPresContext));
|
||||
|
||||
nsIFrame* rootFrame = nsnull;
|
||||
nsIAtom* rootPseudo;
|
||||
|
||||
|
@ -3572,13 +3577,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
// for print-preview, but not when printing), then create a scroll frame that
|
||||
// will act as the scrolling mechanism for the viewport.
|
||||
// XXX Do we even need a viewport when printing to a printer?
|
||||
PRBool isScrollable = PR_TRUE;
|
||||
if (aPresContext) {
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
if (NS_SUCCEEDED(aPresContext->IsPaginated(&isPaginated))) {
|
||||
isScrollable = !isPaginated;
|
||||
}
|
||||
}
|
||||
PRBool isScrollable = PR_TRUE;
|
||||
|
||||
//isScrollable = PR_FALSE;
|
||||
|
||||
|
@ -3623,6 +3622,19 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
}
|
||||
}
|
||||
|
||||
if (aPresContext) {
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
if (NS_SUCCEEDED(aPresContext->IsPaginated(&isPaginated))) {
|
||||
if (isPaginated) {
|
||||
if (printPreviewContext) { // print preview
|
||||
aPresContext->GetPaginatedScrolling(&isScrollable);
|
||||
} else {
|
||||
isScrollable = PR_FALSE; // we are printing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame* newFrame = rootFrame;
|
||||
nsCOMPtr<nsIStyleContext> rootPseudoStyle;
|
||||
// we must create a state because if the scrollbars are GFX it needs the
|
||||
|
@ -3636,7 +3648,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
nsIFrame* parentFrame = viewportFrame;
|
||||
|
||||
// If paginated, make sure we don't put scrollbars in
|
||||
if (isPaginated)
|
||||
if (isPaginated && !printPreviewContext)
|
||||
aPresContext->ResolvePseudoStyleContextFor(nsnull, rootPseudo,
|
||||
viewportPseudoStyle, PR_FALSE,
|
||||
getter_AddRefs(rootPseudoStyle));
|
||||
|
@ -3733,7 +3745,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
|
||||
rootFrame->Init(aPresContext, nsnull, parentFrame, rootPseudoStyle, nsnull);
|
||||
|
||||
if (!isPaginated) {
|
||||
if (!isPaginated || (isPaginated && printPreviewContext)) {
|
||||
if (isScrollable) {
|
||||
FinishBuildingScrollFrame(aPresContext,
|
||||
state,
|
||||
|
@ -3749,7 +3761,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
parentFrame->SetInitialChildList(aPresContext, nsnull, rootFrame);
|
||||
}
|
||||
}
|
||||
} else { // paginated
|
||||
}
|
||||
|
||||
if (isPaginated) { // paginated
|
||||
// Create the first page
|
||||
nsIFrame* pageFrame;
|
||||
NS_NewPageFrame(aPresShell, &pageFrame);
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1311,6 +1311,38 @@ nsPresContext::GetTwipsToPixels(float* aResult) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
float app2dev = 1.0f;
|
||||
if (mDeviceContext) {
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// If an alternative DC is available we want to use
|
||||
// it to get the scaling factor for fonts. Usually, the AltDC
|
||||
// is a printing DC so therefore we need to get the printers
|
||||
// scaling values for calculating the font heights
|
||||
nsCOMPtr<nsIDeviceContext> altDC;
|
||||
mDeviceContext->GetAltDevice(getter_AddRefs(altDC));
|
||||
if (altDC) {
|
||||
altDC->GetAppUnitsToDevUnits(app2dev);
|
||||
} else {
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
}
|
||||
#else
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
#endif
|
||||
}
|
||||
*aResult = app2dev;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPresContext::GetScaledPixelsToTwips(float* aResult) const
|
||||
{
|
||||
|
|
|
@ -367,6 +367,18 @@ public:
|
|||
*/
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Sets whether the presentation context can scroll for a paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) = 0;
|
||||
|
||||
/**
|
||||
* Return true if this presentation context can scroll for paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Gets the rect for the page Dimimensions,
|
||||
* this includes X,Y Offsets which are used to determine
|
||||
|
@ -391,6 +403,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetTwipsToPixels(float* aResult) const = 0;
|
||||
|
||||
NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0;
|
||||
|
||||
//XXX this is probably not an ideal name. MMP
|
||||
/**
|
||||
* Do pixels to twips conversion taking into account
|
||||
|
|
|
@ -124,6 +124,7 @@
|
|||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIFocusController.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
#include "nsWidgetsCID.h"
|
||||
|
@ -3444,6 +3445,11 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const
|
|||
if (NS_SUCCEEDED(rv) && (nsnull != scrollable)) {
|
||||
// if it is then get the scrolled frame
|
||||
scrollable->GetScrolledFrame(nsnull, child);
|
||||
} else {
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(mPresContext);
|
||||
if (ppContext) {
|
||||
child->FirstChild(mPresContext, nsnull, &child);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the child is a pageSequence
|
||||
|
|
|
@ -26,6 +26,7 @@ nsIPresContext.h
|
|||
nsIPresShell.h
|
||||
nsIPresState.h
|
||||
nsIPrintContext.h
|
||||
nsIPrintPreviewContext.h
|
||||
nsIReflowCallback.h
|
||||
nsIReflowCommand.h
|
||||
nsIScrollableFrame.h
|
||||
|
|
|
@ -50,6 +50,7 @@ EXPORTS = \
|
|||
nsIPresShell.h \
|
||||
nsIPresState.h \
|
||||
nsIPrintContext.h \
|
||||
nsIPrintPreviewContext.h \
|
||||
nsIReflowCallback.h \
|
||||
nsIReflowCommand.h \
|
||||
nsIScrollableFrame.h \
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "nsRect.h"
|
||||
|
||||
class nsIPresContext;
|
||||
class nsIPrintOptions;
|
||||
class nsIPrintOptions;
|
||||
|
||||
// IID for the nsIPageSequenceFrame interface
|
||||
// a6cf90d2-15b3-11d2-932e-00805f8add32
|
||||
|
@ -151,7 +151,8 @@ public:
|
|||
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) = 0;
|
||||
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup) = 0;
|
||||
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize) = 0;
|
||||
|
||||
NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) = 0;
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
|
||||
|
|
|
@ -367,6 +367,18 @@ public:
|
|||
*/
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Sets whether the presentation context can scroll for a paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) = 0;
|
||||
|
||||
/**
|
||||
* Return true if this presentation context can scroll for paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Gets the rect for the page Dimimensions,
|
||||
* this includes X,Y Offsets which are used to determine
|
||||
|
@ -391,6 +403,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetTwipsToPixels(float* aResult) const = 0;
|
||||
|
||||
NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0;
|
||||
|
||||
//XXX this is probably not an ideal name. MMP
|
||||
/**
|
||||
* Do pixels to twips conversion taking into account
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef nsIPrintPreviewContext_h___
|
||||
#define nsIPrintPreviewContext_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
#define NS_IPRINTPREVIEWCONTEXT_IID \
|
||||
{ 0xdfd92dd, 0x19ff, 0x4e62, \
|
||||
{ 0x83, 0x16, 0x8e, 0x44, 0x3, 0x1a, 0x19, 0x62 } }
|
||||
|
||||
|
||||
// An interface for presentation printing contexts
|
||||
class nsIPrintPreviewContext : public nsISupports {
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTPREVIEWCONTEXT_IID)
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Factory method to create a "paginated" presentation context for
|
||||
// printing
|
||||
extern NS_EXPORT nsresult
|
||||
NS_NewPrintPreviewContext(nsIPrintPreviewContext** aInstancePtrResult);
|
||||
|
||||
#endif
|
|
@ -367,6 +367,18 @@ public:
|
|||
*/
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Sets whether the presentation context can scroll for a paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) = 0;
|
||||
|
||||
/**
|
||||
* Return true if this presentation context can scroll for paginated
|
||||
* context.
|
||||
*/
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Gets the rect for the page Dimimensions,
|
||||
* this includes X,Y Offsets which are used to determine
|
||||
|
@ -391,6 +403,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetTwipsToPixels(float* aResult) const = 0;
|
||||
|
||||
NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const = 0;
|
||||
|
||||
//XXX this is probably not an ideal name. MMP
|
||||
/**
|
||||
* Do pixels to twips conversion taking into account
|
||||
|
|
|
@ -46,6 +46,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetMedium(nsIAtom** aMedium);
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult);
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) { return NS_ERROR_FAILURE; }
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult);
|
||||
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
|
||||
NS_IMETHOD SetPageDim(nsRect* aRect);
|
||||
};
|
||||
|
@ -81,6 +83,14 @@ GalleyContext::IsPaginated(PRBool* aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GalleyContext::GetPaginatedScrolling(PRBool* aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GalleyContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
|
||||
{
|
||||
|
|
|
@ -1311,6 +1311,38 @@ nsPresContext::GetTwipsToPixels(float* aResult) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
float app2dev = 1.0f;
|
||||
if (mDeviceContext) {
|
||||
#ifdef NS_PRINT_PREVIEW
|
||||
// If an alternative DC is available we want to use
|
||||
// it to get the scaling factor for fonts. Usually, the AltDC
|
||||
// is a printing DC so therefore we need to get the printers
|
||||
// scaling values for calculating the font heights
|
||||
nsCOMPtr<nsIDeviceContext> altDC;
|
||||
mDeviceContext->GetAltDevice(getter_AddRefs(altDC));
|
||||
if (altDC) {
|
||||
altDC->GetAppUnitsToDevUnits(app2dev);
|
||||
} else {
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
}
|
||||
#else
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
#endif
|
||||
}
|
||||
*aResult = app2dev;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPresContext::GetScaledPixelsToTwips(float* aResult) const
|
||||
{
|
||||
|
|
|
@ -149,10 +149,13 @@ public:
|
|||
NS_IMETHOD GetVisibleArea(nsRect& aResult);
|
||||
NS_IMETHOD SetVisibleArea(const nsRect& r);
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) = 0;
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult) = 0;
|
||||
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0;
|
||||
NS_IMETHOD SetPageDim(nsRect* aRect) = 0;
|
||||
NS_IMETHOD GetPixelsToTwips(float* aResult) const;
|
||||
NS_IMETHOD GetTwipsToPixels(float* aResult) const;
|
||||
NS_IMETHOD GetTwipsToPixelsForFonts(float* aResult) const;
|
||||
NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const;
|
||||
NS_IMETHOD GetDeviceContext(nsIDeviceContext** aResult) const;
|
||||
NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager);
|
||||
|
|
|
@ -60,6 +60,8 @@ public:
|
|||
NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags);
|
||||
NS_IMETHOD GetMedium(nsIAtom** aMedium);
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult);
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) { return NS_ERROR_FAILURE; }
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult);
|
||||
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
|
||||
NS_IMETHOD SetPageDim(nsRect* aRect);
|
||||
protected:
|
||||
|
@ -118,6 +120,14 @@ PrintContext::IsPaginated(PRBool* aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PrintContext::GetPaginatedScrolling(PRBool* aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PrintContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
|
||||
{
|
||||
|
@ -144,6 +154,7 @@ PrintContext::SetPageDim(nsRect* aPageDim)
|
|||
NS_EXPORT nsresult
|
||||
NS_NewPrintContext(nsIPrintContext** aInstancePtrResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIView.h"
|
||||
|
@ -54,36 +55,26 @@ public:
|
|||
PrintPreviewContext();
|
||||
~PrintPreviewContext();
|
||||
|
||||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE macro used is for classes that inherit from
|
||||
// another class. Only the base class should use NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD GetMedium(nsIAtom** aMedium);
|
||||
NS_IMETHOD IsPaginated(PRBool* aResult);
|
||||
NS_IMETHOD SetPaginatedScrolling(PRBool aResult) { mCanPaginatedScroll = aResult; return NS_OK; }
|
||||
NS_IMETHOD GetPaginatedScrolling(PRBool* aResult);
|
||||
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
|
||||
NS_IMETHOD SetPageDim(nsRect* aRect);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool UseFakePageSize();
|
||||
#endif
|
||||
protected:
|
||||
nsRect mPageDim;
|
||||
PRBool mCanPaginatedScroll;
|
||||
};
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool
|
||||
PrintPreviewContext::UseFakePageSize()
|
||||
{
|
||||
static PRLogModuleInfo* pageSizeLM;
|
||||
static PRBool useFakePageSize = PR_FALSE;
|
||||
if (nsnull == pageSizeLM) {
|
||||
pageSizeLM = PR_NewLogModule("pagesize");
|
||||
if (nsnull != pageSizeLM) {
|
||||
useFakePageSize = 0 != pageSizeLM->level;
|
||||
}
|
||||
}
|
||||
return useFakePageSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
PrintPreviewContext::PrintPreviewContext() :
|
||||
mPageDim(-1,-1,-1,-1)
|
||||
mPageDim(-1,-1,-1,-1),
|
||||
mCanPaginatedScroll(PR_TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -91,6 +82,23 @@ PrintPreviewContext::~PrintPreviewContext()
|
|||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(PrintPreviewContext,nsPresContext)
|
||||
NS_IMPL_RELEASE_INHERITED(PrintPreviewContext,nsPresContext)
|
||||
|
||||
//---------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
PrintPreviewContext::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIPrintPreviewContext))) {
|
||||
*aInstancePtr = (void *)((nsIPrintPreviewContext*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsPresContext::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PrintPreviewContext::GetMedium(nsIAtom** aResult)
|
||||
{
|
||||
|
@ -108,68 +116,25 @@ PrintPreviewContext::IsPaginated(PRBool* aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PrintPreviewContext::GetPaginatedScrolling(PRBool* aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = mCanPaginatedScroll;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PrintPreviewContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aActualRect);
|
||||
NS_ENSURE_ARG_POINTER(aAdjRect);
|
||||
|
||||
// XXX maybe we get the size of the default printer instead
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrintOptions> printService =
|
||||
do_GetService(kPrintOptionsCID, &rv);
|
||||
// Setting what would be the "default" case here, because
|
||||
// getting the PrintService could fail
|
||||
aActualRect->width = (nscoord) NS_INCHES_TO_TWIPS(8.5);
|
||||
aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(11);
|
||||
if (NS_SUCCEEDED(rv) && printService) {
|
||||
PRInt32 paperSize = nsIPrintOptions::kLetterPaperSize;
|
||||
printService->GetPaperSize(&paperSize);
|
||||
switch (paperSize) {
|
||||
case nsIPrintOptions::kLegalPaperSize :
|
||||
aActualRect->width = (nscoord) NS_INCHES_TO_TWIPS(8.5);
|
||||
aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(14);
|
||||
break;
|
||||
|
||||
case nsIPrintOptions::kExecutivePaperSize :
|
||||
aActualRect->width = (nscoord) NS_INCHES_TO_TWIPS(7.5);
|
||||
aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(10.5);
|
||||
break;
|
||||
|
||||
case nsIPrintOptions::kA3PaperSize :
|
||||
aActualRect->width = (nscoord) NS_MILLIMETERS_TO_TWIPS(297);
|
||||
aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(420);
|
||||
break;
|
||||
|
||||
case nsIPrintOptions::kA4PaperSize :
|
||||
aActualRect->width = (nscoord) NS_MILLIMETERS_TO_TWIPS(210);
|
||||
aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(297);
|
||||
break;
|
||||
|
||||
} // switch
|
||||
PRInt32 orientation = nsIPrintOptions::kPortraitOrientation;
|
||||
printService->GetOrientation(&orientation);
|
||||
if (orientation == nsIPrintOptions::kLandscapeOrientation) {
|
||||
// swap
|
||||
nscoord temp;
|
||||
temp = aActualRect->width;
|
||||
aActualRect->width = aActualRect->height;
|
||||
aActualRect->height = temp;
|
||||
}
|
||||
PRInt32 width,height;
|
||||
if (NS_SUCCEEDED(mDeviceContext->GetDeviceSurfaceDimensions(width, height))) {
|
||||
aActualRect->SetRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
if (UseFakePageSize()) {
|
||||
// For testing purposes make the page width smaller than the visible area
|
||||
float sbWidth, sbHeight;
|
||||
mDeviceContext->GetScrollBarDimensions(sbWidth, sbHeight);
|
||||
nscoord sbar = NSToCoordRound(sbWidth);
|
||||
aActualRect->width = mVisibleArea.width - sbar - 2*100;
|
||||
aActualRect->height = mVisibleArea.height * 60 / 100;
|
||||
}
|
||||
#endif
|
||||
*aAdjRect = mPageDim;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ protected:
|
|||
}
|
||||
|
||||
PRBool HaveOutsideBullet() const {
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_X
|
||||
if(mState & NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET) {
|
||||
NS_ASSERTION(mBullet,"NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET flag set and no mBullet");
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include "nsIScrollable.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIPrintContext.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
|
@ -260,6 +261,8 @@ friend class nsHTMLFrameOuterFrame;
|
|||
protected:
|
||||
nsresult CreateDocShell(nsIPresContext* aPresContext);
|
||||
nsresult DoLoadURL(nsIPresContext* aPresContext);
|
||||
nsresult CreateViewAndWidget(nsIPresContext* aPresContext,
|
||||
nsIWidget*& aWidget);
|
||||
|
||||
virtual ~nsHTMLFrameInnerFrame();
|
||||
|
||||
|
@ -1131,45 +1134,12 @@ nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext)
|
|||
}
|
||||
}
|
||||
|
||||
float t2p;
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// create, init, set the parent of the view
|
||||
nsIView* view;
|
||||
rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView),
|
||||
(void **)&view);
|
||||
if (NS_OK != rv) {
|
||||
NS_ASSERTION(0, "Could not create view for nsHTMLFrame");
|
||||
nsIWidget* widget;
|
||||
rv = CreateViewAndWidget(aPresContext, widget);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIView* parView;
|
||||
nsPoint origin;
|
||||
GetOffsetFromView(aPresContext, origin, &parView);
|
||||
nsRect viewBounds(origin.x, origin.y, 10, 10);
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
presShell->GetViewManager(getter_AddRefs(viewMan));
|
||||
rv = view->Init(viewMan, viewBounds, parView);
|
||||
viewMan->InsertChild(parView, view, 0);
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.clipChildren = PR_TRUE;
|
||||
initData.clipSiblings = PR_TRUE;
|
||||
|
||||
rv = view->CreateWidget(kCChildCID, &initData);
|
||||
SetView(aPresContext, view);
|
||||
|
||||
// if the visibility is hidden, reflect that in the view
|
||||
const nsStyleVisibility* vis;
|
||||
GetStyleData(eStyleStruct_Visibility, ((const nsStyleStruct *&)vis));
|
||||
if (!vis->IsVisible()) {
|
||||
view->SetVisibility(nsViewVisibility_kHide);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
view->GetWidget(*getter_AddRefs(widget));
|
||||
|
||||
mSubShell->InitWindow(nsnull, widget, 0, 0, 10, 10);
|
||||
mSubShell->Create();
|
||||
|
||||
|
@ -1350,6 +1320,57 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext)
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext,
|
||||
nsIWidget*& aWidget)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPresContext);
|
||||
NS_ENSURE_ARG_POINTER(aWidget);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
if (!presShell) return NS_ERROR_FAILURE;
|
||||
|
||||
float t2p;
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// create, init, set the parent of the view
|
||||
nsIView* view;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView),
|
||||
(void **)&view);
|
||||
if (NS_OK != rv) {
|
||||
NS_ASSERTION(0, "Could not create view for nsHTMLFrame");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIView* parView;
|
||||
nsPoint origin;
|
||||
GetOffsetFromView(aPresContext, origin, &parView);
|
||||
nsRect viewBounds(origin.x, origin.y, 10, 10);
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
presShell->GetViewManager(getter_AddRefs(viewMan));
|
||||
rv = view->Init(viewMan, viewBounds, parView);
|
||||
viewMan->InsertChild(parView, view, 0);
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.clipChildren = PR_TRUE;
|
||||
initData.clipSiblings = PR_TRUE;
|
||||
|
||||
rv = view->CreateWidget(kCChildCID, &initData);
|
||||
SetView(aPresContext, view);
|
||||
|
||||
// if the visibility is hidden, reflect that in the view
|
||||
const nsStyleVisibility* vis;
|
||||
GetStyleData(eStyleStruct_Visibility, ((const nsStyleStruct *&)vis));
|
||||
if (!vis->IsVisible()) {
|
||||
view->SetVisibility(nsViewVisibility_kHide);
|
||||
}
|
||||
view->GetWidget(aWidget);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
|
@ -1368,6 +1389,20 @@ nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext,
|
|||
// we are printing
|
||||
shouldCreateDoc = PR_FALSE;
|
||||
}
|
||||
|
||||
// for print preview we want to create the view and widget but
|
||||
// we do not want to load the document, it is alerady loaded.
|
||||
nsCOMPtr<nsIPrintPreviewContext> thePrintPreviewContext = do_QueryInterface(aPresContext);
|
||||
if (thePrintPreviewContext) {
|
||||
nsIWidget* widget;
|
||||
rv = CreateViewAndWidget(aPresContext, widget);
|
||||
NS_IF_RELEASE(widget);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
// we are in PrintPreview
|
||||
shouldCreateDoc = PR_FALSE;
|
||||
}
|
||||
|
||||
if (!mCreatingViewer && shouldCreateDoc) {
|
||||
// create the web shell
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "nsRect.h"
|
||||
|
||||
class nsIPresContext;
|
||||
class nsIPrintOptions;
|
||||
class nsIPrintOptions;
|
||||
|
||||
// IID for the nsIPageSequenceFrame interface
|
||||
// a6cf90d2-15b3-11d2-932e-00805f8add32
|
||||
|
@ -151,7 +151,8 @@ public:
|
|||
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) = 0;
|
||||
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup) = 0;
|
||||
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize) = 0;
|
||||
|
||||
NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) = 0;
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
|
||||
|
|
|
@ -48,6 +48,13 @@
|
|||
#include "nsIPresShell.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
#include "nsIView.h" // view flags for clipping
|
||||
|
||||
#include "nsHTMLContainerFrame.h" // view creation
|
||||
|
||||
#include "nsSimplePageSequence.h" // for nsSharedPageData
|
||||
|
||||
// for page number localization formatting
|
||||
#include "nsTextFormatter.h"
|
||||
|
@ -61,14 +68,8 @@
|
|||
#include "nsIServiceManager.h"
|
||||
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
||||
|
||||
// static data members
|
||||
PRUnichar * nsPageFrame::mDateTimeStr = nsnull;
|
||||
nsFont * nsPageFrame::mHeadFootFont = nsnull;
|
||||
PRUnichar * nsPageFrame::mPageNumFormat = nsnull;
|
||||
PRUnichar * nsPageFrame::mPageNumAndTotalsFormat = nsnull;
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
#define DEBUG_PRINTING
|
||||
//#define DEBUG_PRINTING
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PRINTING
|
||||
|
@ -85,6 +86,7 @@ PRUnichar * nsPageFrame::mPageNumAndTotalsFormat = nsnull;
|
|||
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
|
||||
#endif
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
{
|
||||
|
@ -103,49 +105,50 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|||
nsPageFrame::nsPageFrame() :
|
||||
mSupressHF(PR_FALSE),
|
||||
mClipRect(-1, -1, -1, -1)
|
||||
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
mDebugFD = stdout;
|
||||
#endif
|
||||
nsresult rv;
|
||||
mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
|
||||
|
||||
if (mHeadFootFont == nsnull) {
|
||||
mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
}
|
||||
// now get the default font form the print options
|
||||
mPrintOptions->GetDefaultFont(*mHeadFootFont);
|
||||
}
|
||||
|
||||
nsPageFrame::~nsPageFrame()
|
||||
{
|
||||
if (mHeadFootFont != nsnull) {
|
||||
delete mHeadFootFont;
|
||||
mHeadFootFont = nsnull;
|
||||
}
|
||||
|
||||
if (mDateTimeStr) {
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
mDateTimeStr = nsnull;
|
||||
}
|
||||
|
||||
if (mPageNumFormat) {
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
mPageNumFormat = nsnull;
|
||||
}
|
||||
|
||||
if (mPageNumAndTotalsFormat) {
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
mPageNumAndTotalsFormat = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
NS_IMETHODIMP
|
||||
nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
||||
nsIAtom* aListName,
|
||||
nsIFrame* aChildList)
|
||||
{
|
||||
// only create a view for the area frame if we are printing the selection
|
||||
// (Also skip it if we are doing PrintPreview)
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
if (!ppContext) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;
|
||||
printService->GetPrintRange(&printRangeType);
|
||||
// make sure we are printing the selection
|
||||
if (printRangeType == nsIPrintOptions::kRangeSelection) {
|
||||
nsIView* view;
|
||||
aChildList->GetView(aPresContext, &view);
|
||||
if (view == nsnull) {
|
||||
nsCOMPtr<nsIStyleContext> styleContext;
|
||||
aChildList->GetStyleContext(getter_AddRefs(styleContext));
|
||||
nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList,
|
||||
styleContext, nsnull, PR_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
DO_GLOBAL_REFLOW_COUNT("nsPageFrame", aReflowState.reason);
|
||||
DISPLAY_REFLOW(this, aReflowState, aDesiredSize, aStatus);
|
||||
|
@ -209,13 +212,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
|||
// XXX Pay attention to the page's border and padding...
|
||||
if (mFrames.NotEmpty()) {
|
||||
nsIFrame* frame = mFrames.FirstChild();
|
||||
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame,
|
||||
maxSize);
|
||||
nsSize maxSize(mPD->mReflowRect.width - mPD->mReflowMargin.right - mPD->mReflowMargin.left,
|
||||
mPD->mReflowRect.height - mPD->mReflowMargin.top - mPD->mReflowMargin.bottom);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
|
||||
kidReflowState.isTopOfPage = PR_TRUE;
|
||||
kidReflowState.availableWidth = maxSize.width;
|
||||
kidReflowState.availableHeight = maxSize.height;
|
||||
|
||||
// Get the child's desired size
|
||||
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
||||
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, mPD->mReflowMargin.left, mPD->mReflowMargin.top, 0, aStatus);
|
||||
|
||||
// Make sure the child is at least as tall as our max size (the containing window)
|
||||
if (aDesiredSize.height < aReflowState.availableHeight) {
|
||||
|
@ -223,7 +228,7 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
|||
}
|
||||
|
||||
// Place and size the child
|
||||
FinishReflowChild(frame, aPresContext, aDesiredSize, 0, 0, 0);
|
||||
FinishReflowChild(frame, aPresContext, aDesiredSize, mPD->mReflowMargin.left, mPD->mReflowMargin.top, 0);
|
||||
|
||||
// Is the frame complete?
|
||||
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
||||
|
@ -306,8 +311,8 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
PRUnichar * kDate = GetUStr("&D");
|
||||
if (kDate != nsnull) {
|
||||
if (aStr.Find(kDate) > -1) {
|
||||
if (mDateTimeStr != nsnull) {
|
||||
aNewStr.ReplaceSubstring(kDate, mDateTimeStr);
|
||||
if (mPD->mDateTimeStr != nsnull) {
|
||||
aNewStr.ReplaceSubstring(kDate, mPD->mDateTimeStr);
|
||||
} else {
|
||||
aNewStr.ReplaceSubstring(kDate, NS_LITERAL_STRING("").get());
|
||||
}
|
||||
|
@ -324,7 +329,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
PRUnichar * kPage = GetUStr("&PT");
|
||||
if (kPage != nsnull) {
|
||||
if (aStr.Find(kPage) > -1) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPage, uStr);
|
||||
nsMemory::Free(uStr);
|
||||
nsMemory::Free(kPage);
|
||||
|
@ -338,7 +343,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
kPage = GetUStr("&P");
|
||||
if (kPage != nsnull) {
|
||||
if (aStr.Find(kPage) > -1) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPageNumFormat, mPageNum);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
|
||||
aNewStr.ReplaceSubstring(kPage, uStr);
|
||||
nsMemory::Free(uStr);
|
||||
nsMemory::Free(kPage);
|
||||
|
@ -351,7 +356,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
if (kTitle != nsnull) {
|
||||
if (aStr.Find(kTitle) > -1) {
|
||||
PRUnichar * uTitle;
|
||||
mPrintOptions->GetTitle(&uTitle); // creates memory
|
||||
mPD->mPrintOptions->GetTitle(&uTitle); // creates memory
|
||||
SubstValueForCode(aNewStr, kTitle, uTitle);
|
||||
nsMemory::Free(uTitle);
|
||||
nsMemory::Free(kTitle);
|
||||
|
@ -364,7 +369,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
if (kDocURL != nsnull) {
|
||||
if (aStr.Find(kDocURL) > -1) {
|
||||
PRUnichar * uDocURL;
|
||||
mPrintOptions->GetDocURL(&uDocURL); // creates memory
|
||||
mPD->mPrintOptions->GetDocURL(&uDocURL); // creates memory
|
||||
SubstValueForCode(aNewStr, kDocURL, uDocURL);
|
||||
nsMemory::Free(uDocURL);
|
||||
nsMemory::Free(kDocURL);
|
||||
|
@ -491,23 +496,18 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
|
|||
|
||||
// cacl the x and y positions of the text
|
||||
nsRect rect(aRect);
|
||||
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
|
||||
rect.Deflate(quarterInch,0);
|
||||
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
|
||||
nscoord y;
|
||||
if (aHeaderFooter == eHeader) {
|
||||
nscoord offset = ((mMargin.top - aHeight) / 2);
|
||||
y = rect.y - offset - aHeight;
|
||||
rect.Inflate(0, offset + aHeight);
|
||||
y = rect.y;
|
||||
} else {
|
||||
nscoord offset = ((mMargin.bottom - aHeight) / 2);
|
||||
y = rect.y + rect.height + offset;
|
||||
rect.height += offset + aHeight;
|
||||
y = rect.y + rect.height - aHeight;
|
||||
}
|
||||
|
||||
// set up new clip and draw the text
|
||||
PRBool clipEmpty;
|
||||
aRenderingContext.PushState();
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
||||
aRenderingContext.DrawString(str, x, y + aAscent);
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
@ -545,7 +545,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
|
||||
nsRect rect;
|
||||
PRBool clipEmpty;
|
||||
if (mClipRect.width != -1 || mClipRect.height != -1) {
|
||||
PRBool specialClipIsSet = mClipRect.width != -1 || mClipRect.height != -1;
|
||||
|
||||
if (specialClipIsSet) {
|
||||
#ifdef DEBUG_PRINTING
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
||||
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
|
||||
|
@ -559,12 +561,85 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
rect = mRect;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINTING
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
aRenderingContext.FillRect(rect);
|
||||
nsRect pr = rect;
|
||||
pr.x = 0;
|
||||
pr.y = 0;
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
nsRect pageSize;
|
||||
nsRect adjSize;
|
||||
aPresContext->GetPageDim(&pageSize, &adjSize);
|
||||
if (ppContext && pageSize == adjSize) {
|
||||
pr.width -= mPD->mShadowSize.width;
|
||||
pr.height -= mPD->mShadowSize.height;
|
||||
|
||||
// paint just the page
|
||||
aRenderingContext.SetColor(NS_RGB(192,208,240));
|
||||
aRenderingContext.FillRect(pr);
|
||||
pr.Deflate(mPD->mReflowMargin);
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
aRenderingContext.FillRect(pr);
|
||||
} else {
|
||||
nsRect pr = rect;
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
pr.x = 0;
|
||||
pr.y = 0;
|
||||
aRenderingContext.FillRect(rect);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
mPD->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
rect.Deflate(mMargin);
|
||||
aRenderingContext.DrawRect(mRect);
|
||||
}
|
||||
|
||||
if (mPD->mShadowSize.width > 0 && mPD->mShadowSize.height > 0) {
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
nsRect r(0,0, mRect.width, mRect.height);
|
||||
nsRect shadowRect;
|
||||
shadowRect.x = r.x + r.width - mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + mPD->mShadowSize.height;
|
||||
shadowRect.width = mPD->mShadowSize.width;
|
||||
shadowRect.height = r.height - mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
|
||||
shadowRect.x = r.x + mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + r.height - mPD->mShadowSize.height;
|
||||
shadowRect.width = r.width - mPD->mShadowSize.width;
|
||||
shadowRect.height = mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
if (ppContext) {
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.width -= mPD->mShadowSize.width;
|
||||
rect.height -= mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
if (mPD->mShadowSize.width > 0 && mPD->mShadowSize.height > 0) {
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
nsRect r(0,0, mRect.width, mRect.height);
|
||||
nsRect shadowRect;
|
||||
shadowRect.x = r.x + r.width - mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + mPD->mShadowSize.height;
|
||||
shadowRect.width = mPD->mShadowSize.width;
|
||||
shadowRect.height = r.height - mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
|
||||
shadowRect.x = r.x + mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + r.height - mPD->mShadowSize.height;
|
||||
shadowRect.width = r.width - mPD->mShadowSize.width;
|
||||
shadowRect.height = mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
|
||||
|
@ -573,32 +648,35 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
nsRect r;
|
||||
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
|
||||
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
|
||||
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
|
||||
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
|
||||
// get the current margin
|
||||
mPrintOptions->GetMarginInTwips(mMargin);
|
||||
mPD->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
|
||||
nsRect rect(0,0,mRect.width, mRect.height);
|
||||
rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height);
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
{
|
||||
nsRect rct(0, 0, mRect.width, mRect.height);
|
||||
// XXX Paint a one-pixel border around the page so it's easy to see where
|
||||
// each page begins and ends when we're
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
rct.Deflate(mMargin);
|
||||
//float p2t;
|
||||
//aPresContext->GetPixelsToTwips(&p2t);
|
||||
//rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
||||
aRenderingContext.DrawRect(rect);
|
||||
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
aRenderingContext.DrawRect(rct);
|
||||
//rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
fprintf(mDebugFD, "PageFr::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
|
||||
}
|
||||
#endif
|
||||
|
||||
// use the whole page
|
||||
rect.width += mMargin.left + mMargin.right;
|
||||
rect.x -= mMargin.left;
|
||||
|
||||
aRenderingContext.SetFont(*mHeadFootFont);
|
||||
|
||||
aRenderingContext.SetFont(*mPD->mHeadFootFont);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
// Get the FontMetrics to determine width.height of strings
|
||||
|
@ -606,7 +684,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
aPresContext->GetDeviceContext(getter_AddRefs(deviceContext));
|
||||
NS_ASSERTION(deviceContext, "Couldn't get the device context");
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
deviceContext->GetMetricsFor(*mHeadFootFont, *getter_AddRefs(fontMet));
|
||||
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, *getter_AddRefs(fontMet));
|
||||
nscoord ascent = 0;
|
||||
nscoord visibleHeight = 0;
|
||||
if (fontMet) {
|
||||
|
@ -616,9 +694,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
|
||||
// print document headers and footers
|
||||
PRUnichar * headers[3];
|
||||
mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory
|
||||
mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory
|
||||
mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory
|
||||
DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustLeft,
|
||||
nsAutoString(headers[0]), nsAutoString(headers[1]), nsAutoString(headers[2]),
|
||||
rect, ascent, visibleHeight);
|
||||
|
@ -626,9 +704,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
for (i=0;i<3;i++) nsMemory::Free(headers[i]);
|
||||
|
||||
PRUnichar * footers[3];
|
||||
mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory
|
||||
mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory
|
||||
mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory
|
||||
DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintOptions::kJustRight,
|
||||
nsAutoString(footers[0]), nsAutoString(footers[1]), nsAutoString(footers[2]),
|
||||
rect, ascent, visibleHeight);
|
||||
|
@ -637,23 +715,10 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
}
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPrintOptions(nsIPrintOptions * aPrintOptions)
|
||||
{
|
||||
NS_ASSERTION(aPrintOptions != nsnull, "Print Options can not be null!");
|
||||
|
||||
mPrintOptions = aPrintOptions;
|
||||
// create a default font
|
||||
mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
// now get the default font form the print options
|
||||
mPrintOptions->GetDefaultFont(*mHeadFootFont);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
||||
|
@ -663,33 +728,3 @@ nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
|||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
||||
{
|
||||
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
||||
|
||||
if (aForPageNumOnly) {
|
||||
if (mPageNumFormat != nsnull) {
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
}
|
||||
mPageNumFormat = aFormatStr;
|
||||
} else {
|
||||
if (mPageNumAndTotalsFormat != nsnull) {
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
}
|
||||
mPageNumAndTotalsFormat = aFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
||||
{
|
||||
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
||||
|
||||
if (mDateTimeStr != nsnull) {
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
}
|
||||
mDateTimeStr = aDateTimeStr;
|
||||
}
|
||||
|
|
|
@ -40,12 +40,19 @@
|
|||
#include "nsContainerFrame.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
class nsSharedPageData;
|
||||
|
||||
// Page frame class used by the simple page sequence frame
|
||||
class nsPageFrame : public nsContainerFrame {
|
||||
|
||||
public:
|
||||
friend nsresult NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
|
||||
|
||||
// nsIFrame
|
||||
NS_IMETHOD SetInitialChildList(nsIPresContext* aPresContext,
|
||||
nsIAtom* aListName,
|
||||
nsIFrame* aChildList);
|
||||
|
||||
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aMaxSize,
|
||||
|
@ -77,19 +84,13 @@ public:
|
|||
// For Printing
|
||||
//////////////////
|
||||
|
||||
// Set the print options object into the page for printing
|
||||
virtual void SetPrintOptions(nsIPrintOptions * aPrintOptions);
|
||||
|
||||
// Tell the page which page number it is out of how many
|
||||
virtual void SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages);
|
||||
|
||||
virtual void SuppressHeadersAndFooters(PRBool aDoSup) { mSupressHF = aDoSup; }
|
||||
virtual void SetClipRect(nsRect* aClipRect) { mClipRect = *aClipRect; }
|
||||
|
||||
static void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
|
||||
// This is class is now responsible for freeing the memory
|
||||
static void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
|
||||
virtual SetSharedPageData(nsSharedPageData* aPD) { mPD = aPD; }
|
||||
|
||||
protected:
|
||||
nsPageFrame();
|
||||
|
@ -136,10 +137,7 @@ protected:
|
|||
PRPackedBool mSupressHF;
|
||||
nsRect mClipRect;
|
||||
|
||||
static PRUnichar * mDateTimeStr;
|
||||
static nsFont * mHeadFootFont;
|
||||
static PRUnichar * mPageNumFormat;
|
||||
static PRUnichar * mPageNumAndTotalsFormat;
|
||||
nsSharedPageData* mPD;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsIFontMetrics.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
#include "nsPageFrame.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
// DateTime Includes
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
|
@ -94,6 +95,28 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
|||
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
|
||||
#endif
|
||||
|
||||
// This object a shared by all the nsPageFrames
|
||||
// parented to a SimplePageSequenceFrame
|
||||
nsSharedPageData::nsSharedPageData() :
|
||||
mDateTimeStr(nsnull),
|
||||
mHeadFootFont(nsnull),
|
||||
mPageNumFormat(nsnull),
|
||||
mPageNumAndTotalsFormat(nsnull),
|
||||
mReflowRect(0,0,0,0),
|
||||
mReflowMargin(0,0,0,0),
|
||||
mShadowSize(0,0),
|
||||
mExtraMargin(0,0,0,0)
|
||||
{
|
||||
}
|
||||
|
||||
nsSharedPageData::~nsSharedPageData()
|
||||
{
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
if (mHeadFootFont) delete mHeadFootFont;
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
{
|
||||
|
@ -110,7 +133,9 @@ NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|||
}
|
||||
|
||||
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
||||
mIsPrintingSelection(PR_FALSE)
|
||||
mIsPrintingSelection(PR_FALSE),
|
||||
mSelectionHeight(-1),
|
||||
mYSelOffset(0)
|
||||
{
|
||||
mStartOffset = OFFSET_NOT_SET;
|
||||
mEndOffset = OFFSET_NOT_SET;
|
||||
|
@ -118,22 +143,36 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
|||
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
|
||||
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
||||
|
||||
mPageData = new nsSharedPageData();
|
||||
NS_ASSERTION(mPageData != nsnull, "Can't be null!");
|
||||
if (mPageData->mHeadFootFont == nsnull) {
|
||||
mPageData->mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
}
|
||||
|
||||
// XXX this code and the object data member "mIsPrintingSelection" is only needed
|
||||
// for the hack for printing selection where we make the page the max size
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrintOptions> printService =
|
||||
do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && printService) {
|
||||
mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && mPageData->mPrintOptions) {
|
||||
PRInt16 printType;
|
||||
printService->GetPrintRange(&printType);
|
||||
mPageData->mPrintOptions->GetPrintRange(&printType);
|
||||
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType;
|
||||
printService->GetMarginInTwips(mMargin);
|
||||
mPageData->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
|
||||
// now get the default font form the print options
|
||||
mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont);
|
||||
}
|
||||
mSkipPageBegin = PR_FALSE;
|
||||
mSkipPageEnd = PR_FALSE;
|
||||
mPrintThisPage = PR_FALSE;
|
||||
mOffsetX = 0;
|
||||
mOffsetY = 0;
|
||||
|
||||
// Doing this here so we only have to go get these formats once
|
||||
SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE);
|
||||
SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mDebugFD = stdout;
|
||||
#endif
|
||||
|
@ -141,6 +180,7 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
|||
|
||||
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
|
||||
{
|
||||
if (mPageData) delete mPageData;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -299,12 +339,53 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
|
||||
aStatus = NS_FRAME_COMPLETE; // we're always complete
|
||||
|
||||
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
|
||||
// *** Special Override ***
|
||||
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
||||
// and if this Document is in the upper left hand corner
|
||||
// we need to suppress the top margin or it will reflow too small
|
||||
// Start by getting the actual printer page dimensions to see if we are not a whole page
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
||||
nscoord width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
|
||||
// Compute the size of each page and the x coordinate that each page will
|
||||
// be placed at
|
||||
nsRect pageSize;
|
||||
nsRect adjSize;
|
||||
aPresContext->GetPageDim(&pageSize, &adjSize);
|
||||
|
||||
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
|
||||
nsMargin extraMargin(0,0,0,0);
|
||||
nsSize shadowSize(0,0);
|
||||
if (ppContext) {
|
||||
if (adjSize.width == width && adjSize.height == height) {
|
||||
extraMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
nscoord fourPixels = NSIntPixelsToTwips(4, p2t);
|
||||
shadowSize.SizeTo(fourPixels, fourPixels);
|
||||
}
|
||||
}
|
||||
|
||||
// absolutely ignore all other types of reflows
|
||||
// we only want to have done the Initial Reflow
|
||||
if (eReflowReason_Resize == aReflowState.reason ||
|
||||
eReflowReason_Incremental == aReflowState.reason ||
|
||||
eReflowReason_StyleChange == aReflowState.reason ||
|
||||
eReflowReason_Dirty == aReflowState.reason) {
|
||||
// Return our desired size
|
||||
aDesiredSize.height = mSize.height;
|
||||
aDesiredSize.width = mSize.width;
|
||||
aDesiredSize.ascent = aDesiredSize.height;
|
||||
aDesiredSize.descent = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool suppressLeftMargin = PR_FALSE;
|
||||
PRBool suppressRightMargin = PR_FALSE;
|
||||
PRBool suppressTopMargin = PR_FALSE;
|
||||
|
@ -332,22 +413,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
// (see also nsDocumentViewer.cpp)
|
||||
if (mIsPrintingSelection) {
|
||||
pageSize.height = NS_UNCONSTRAINEDSIZE;
|
||||
suppressLeftMargin = PR_FALSE;
|
||||
suppressTopMargin = PR_FALSE;
|
||||
suppressRightMargin = PR_FALSE;
|
||||
suppressBottomMargin = PR_FALSE;
|
||||
}
|
||||
|
||||
// *** Special Override ***
|
||||
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
||||
// and if this Document is in the upper left hand corner
|
||||
// we need to suppress the top margin or it will reflow too small
|
||||
// Start by getting the actual printer page dimensions to see if we are not a whole page
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
||||
nscoord width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
|
||||
if (adjSize.x == 0 && adjSize.y == 0 && (pageSize.width != width || pageSize.height != height)) {
|
||||
suppressTopMargin = PR_TRUE;
|
||||
}
|
||||
|
||||
// only use this local margin for sizing,
|
||||
// not for positioning
|
||||
|
@ -356,33 +427,40 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
suppressRightMargin?0:mMargin.right,
|
||||
suppressBottomMargin?0:mMargin.bottom);
|
||||
|
||||
nscoord x = mMargin.left;
|
||||
nscoord y = mMargin.top;// Running y-offset for each page
|
||||
nscoord x = extraMargin.left;
|
||||
nscoord y = extraMargin.top;// Running y-offset for each page
|
||||
|
||||
// See if it's an incremental reflow command
|
||||
if (eReflowReason_Incremental == aReflowState.reason) {
|
||||
// XXX Skip Incremental reflow,
|
||||
// in fact, all we want is the initial reflow
|
||||
//IncrementalReflow(aPresContext, aReflowState, pageSize, x, y);
|
||||
|
||||
y = mRect.height;
|
||||
} else {
|
||||
nsReflowReason reflowReason = aReflowState.reason;
|
||||
|
||||
SetPageSizes(pageSize, margin);
|
||||
|
||||
// Tile the pages vertically
|
||||
nsHTMLReflowMetrics kidSize(nsnull);
|
||||
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
|
||||
// Reflow the page
|
||||
nsSize availSize(pageSize.width, pageSize.height);
|
||||
nsSize availSize(pageSize.width+extraMargin.right+extraMargin.left+shadowSize.width,
|
||||
pageSize.height+extraMargin.top+extraMargin.bottom+shadowSize.height);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
|
||||
availSize, reflowReason);
|
||||
nsReflowStatus status;
|
||||
kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
|
||||
kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
|
||||
kidReflowState.availableWidth = availSize.width;
|
||||
kidReflowState.availableHeight = availSize.height;
|
||||
|
||||
kidReflowState.mComputedWidth = kidReflowState.availableWidth;
|
||||
//kidReflowState.mComputedHeight = kidReflowState.availableHeight;
|
||||
PRINT_DEBUG_MSG3("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight);
|
||||
|
||||
// Set the shared data into the page frame before reflow
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, kidFrame);
|
||||
pf->SetSharedPageData(mPageData);
|
||||
|
||||
// Place and size the page. If the page is narrower than our
|
||||
// max width then center it horizontally
|
||||
ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status);
|
||||
|
@ -390,16 +468,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
FinishReflowChild(kidFrame, aPresContext, kidSize, x, y, 0);
|
||||
y += kidSize.height;
|
||||
|
||||
nsIView* view;
|
||||
kidFrame->GetView(aPresContext, &view);
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
nsRect rect;
|
||||
kidFrame->GetRect(rect);
|
||||
nsRect viewRect;
|
||||
view->GetBounds(viewRect);
|
||||
|
||||
// Leave a slight gap between the pages
|
||||
y += mMargin.top + mMargin.bottom;
|
||||
y += quarterInch;
|
||||
|
||||
// Is the page complete?
|
||||
nsIFrame* kidNextInFlow;
|
||||
|
@ -429,12 +499,14 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
pageTot++;
|
||||
}
|
||||
|
||||
mPageData->mShadowSize = shadowSize;
|
||||
mPageData->mExtraMargin = extraMargin;
|
||||
|
||||
// Set Page Number Info
|
||||
PRInt32 pageNum = 1;
|
||||
for (page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, page);
|
||||
if (pf != nsnull) {
|
||||
//pf->SetPrintOptions(aPrintOptions);
|
||||
pf->SetPageNumInfo(pageNum, pageTot);
|
||||
}
|
||||
pageNum++;
|
||||
|
@ -458,7 +530,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
time( <ime );
|
||||
if (NS_SUCCEEDED(dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString))) {
|
||||
PRUnichar * uStr = ToNewUnicode(dateString);
|
||||
nsPageFrame::SetDateTimeStr(uStr); // nsPageFrame will own memory
|
||||
SetDateTimeStr(uStr); // memory will be freed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -468,10 +540,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
|
||||
// Return our desired size
|
||||
aDesiredSize.height = y;
|
||||
aDesiredSize.width = pageSize.width;
|
||||
aDesiredSize.width = pageSize.width+extraMargin.left+shadowSize.width;
|
||||
aDesiredSize.ascent = aDesiredSize.height;
|
||||
aDesiredSize.descent = 0;
|
||||
|
||||
// cache the size so we can set the desired size
|
||||
// for the other reflows that happen
|
||||
mSize.width = aDesiredSize.width;
|
||||
mSize.height = aDesiredSize.height;
|
||||
|
||||
NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -582,7 +659,7 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
|
|||
// Sets the format into a static data memeber which will own the memory and free it
|
||||
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
||||
if (uStr != nsnull) {
|
||||
nsPageFrame::SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
||||
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -668,10 +745,9 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
|
|||
// we must make sure that the page is sized correctly before printing.
|
||||
PRInt32 width,height;
|
||||
dc->GetDeviceSurfaceDimensions(width,height);
|
||||
height -= mMargin.top + mMargin.bottom;
|
||||
|
||||
PRInt32 pageNum = 1;
|
||||
nscoord y = mMargin.top;
|
||||
nscoord y = 0;//mMargin.top;
|
||||
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
||||
nsIView* view;
|
||||
page->GetView(aPresContext, &view);
|
||||
|
@ -743,8 +819,6 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
|
|||
mTotalPages = totalPages;
|
||||
mCurrentPageFrame = mFrames.FirstChild();
|
||||
|
||||
//rv = PrintNextPage(aPresContext, aPrintOptions);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -824,39 +898,87 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
|
||||
// cast the frame to be a page frame
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, mCurrentPageFrame);
|
||||
if (pf != nsnull) {
|
||||
pf->SetPrintOptions(aPrintOptions);
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
// XXX This is temporary fix for printing more than one page of a selection
|
||||
// This does a poor man's "dump" pagination (see Bug 89353)
|
||||
// It has laid out as one long page and now we are just moving or view up/down
|
||||
// one page at a time and printing the contents of what is exposed by the rect.
|
||||
// currently this does not work for IFrames
|
||||
// I will soon improve this to work with IFrames
|
||||
PRBool continuePrinting = PR_TRUE;
|
||||
nscoord selectionHeight = mSelectionHeight;
|
||||
PRInt32 width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
nsRect clipRect(0, 0, width, height);
|
||||
height -= mMargin.top + mMargin.bottom;
|
||||
width -= mMargin.left + mMargin.right;
|
||||
nscoord selectionY = height;
|
||||
nsIView* containerView = nsnull;
|
||||
nsRect containerRect;
|
||||
if (mSelectionHeight > -1) {
|
||||
nsIFrame* childFrame = mFrames.FirstChild();
|
||||
nsIFrame* conFrame;
|
||||
childFrame->FirstChild(aPresContext, nsnull, &conFrame);
|
||||
conFrame->GetView(aPresContext, &containerView);
|
||||
containerView->GetBounds(containerRect);
|
||||
containerRect.y -= mYSelOffset;
|
||||
containerRect.height = height-mYSelOffset;
|
||||
containerView->SetBounds(containerRect, PR_FALSE);
|
||||
clipRect.SetRect(mMargin.left, mMargin.right, width, height);
|
||||
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, childFrame);
|
||||
nsRect nullClipRect(-1,-1,-1,-1);
|
||||
pf->SetClipRect(&nullClipRect);
|
||||
}
|
||||
|
||||
// Print the page
|
||||
nsIView* view;
|
||||
mCurrentPageFrame->GetView(aPresContext, &view);
|
||||
while (continuePrinting) {
|
||||
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
// cast the frame to be a page frame
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, mCurrentPageFrame);
|
||||
if (pf != nsnull) {
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
pf->SetSharedPageData(mPageData);
|
||||
}
|
||||
|
||||
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
|
||||
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
// Print the page
|
||||
nsIView* view;
|
||||
mCurrentPageFrame->GetView(aPresContext, &view);
|
||||
|
||||
view->SetContentTransparency(PR_FALSE);
|
||||
vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
|
||||
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
|
||||
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
|
||||
// this view was printed and since display set the origin
|
||||
// 0,0 there is a danger that this view can be printed again
|
||||
// If it is a sibling to another page/view. Setting the visibility
|
||||
// to hide will keep this page from printing again - dwc
|
||||
//
|
||||
// XXX Doesn't seem like we need to do this anymore
|
||||
//view->SetVisibility(nsViewVisibility_kHide);
|
||||
view->SetContentTransparency(PR_FALSE);
|
||||
|
||||
if (!mSkipPageEnd) {
|
||||
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
|
||||
rv = dc->EndPage();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
vm->Display(view, mOffsetX, mOffsetY, clipRect);
|
||||
|
||||
// this view was printed and since display set the origin
|
||||
// 0,0 there is a danger that this view can be printed again
|
||||
// If it is a sibling to another page/view. Setting the visibility
|
||||
// to hide will keep this page from printing again - dwc
|
||||
//
|
||||
// XXX Doesn't seem like we need to do this anymore
|
||||
//view->SetVisibility(nsViewVisibility_kHide);
|
||||
|
||||
if (!mSkipPageEnd) {
|
||||
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
|
||||
rv = dc->EndPage();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (mSelectionHeight > -1 && selectionY < mSelectionHeight) {
|
||||
selectionY += height;
|
||||
|
||||
mPrintedPageNum++;
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
containerRect.y -= height;
|
||||
containerRect.height += height;
|
||||
containerView->SetBounds(containerRect, PR_FALSE);
|
||||
|
||||
} else {
|
||||
continuePrinting = PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -971,3 +1093,52 @@ nsSimplePageSequenceFrame::Paint(nsIPresContext* aPresContext,
|
|||
aRenderingContext.PopState(clipEmpty);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSimplePageSequenceFrame::SizeTo(nsIPresContext* aPresContext, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
return nsFrame::SizeTo(aPresContext, aWidth, aHeight);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
||||
{
|
||||
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
if (aForPageNumOnly) {
|
||||
if (mPageData->mPageNumFormat != nsnull) {
|
||||
nsMemory::Free(mPageData->mPageNumFormat);
|
||||
}
|
||||
mPageData->mPageNumFormat = aFormatStr;
|
||||
} else {
|
||||
if (mPageData->mPageNumAndTotalsFormat != nsnull) {
|
||||
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
||||
}
|
||||
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
||||
{
|
||||
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
if (mPageData->mDateTimeStr != nsnull) {
|
||||
nsMemory::Free(mPageData->mDateTimeStr);
|
||||
}
|
||||
mPageData->mDateTimeStr = aDateTimeStr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect)
|
||||
{
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
mPageData->mReflowRect = aRect;
|
||||
mPageData->mReflowMargin = aMarginRect;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,28 @@
|
|||
#include "nsContainerFrame.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
//-----------------------------------------------
|
||||
// This class maintains all the data that
|
||||
// is used by all the page frame
|
||||
// It lives while the nsSimplePageSequenceFrame lives
|
||||
class nsSharedPageData {
|
||||
public:
|
||||
nsSharedPageData();
|
||||
~nsSharedPageData();
|
||||
|
||||
PRUnichar * mDateTimeStr;
|
||||
nsFont * mHeadFootFont;
|
||||
PRUnichar * mPageNumFormat;
|
||||
PRUnichar * mPageNumAndTotalsFormat;
|
||||
|
||||
nsRect mReflowRect;
|
||||
nsMargin mReflowMargin;
|
||||
nsSize mShadowSize;
|
||||
nsMargin mExtraMargin;
|
||||
|
||||
nsCOMPtr<nsIPrintOptions> mPrintOptions;
|
||||
};
|
||||
|
||||
// Simple page sequence frame class. Used when we're in paginated mode
|
||||
class nsSimplePageSequenceFrame : public nsContainerFrame,
|
||||
public nsIPageSequenceFrame {
|
||||
|
@ -67,6 +89,7 @@ public:
|
|||
nsIPrintStatusCallback* aStatusCallback);
|
||||
NS_IMETHOD SetOffsets(nscoord aStartOffset, nscoord aEndOffset);
|
||||
NS_IMETHOD SetPageNo(PRInt32 aPageNo) { return NS_OK;}
|
||||
NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
|
||||
|
||||
// Async Printing
|
||||
NS_IMETHOD StartPrint(nsIPresContext* aPresContext,
|
||||
|
@ -85,6 +108,9 @@ public:
|
|||
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup);
|
||||
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize);
|
||||
|
||||
NS_IMETHOD SizeTo(nsIPresContext* aPresContext,
|
||||
nscoord aWidth,
|
||||
nscoord aHeight);
|
||||
#ifdef NS_DEBUG
|
||||
// Debugging
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
||||
|
@ -108,6 +134,11 @@ protected:
|
|||
|
||||
void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly);
|
||||
|
||||
// SharedPageData Helper methods
|
||||
void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
|
||||
void SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect);
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();}
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();}
|
||||
|
||||
|
@ -134,6 +165,14 @@ protected:
|
|||
nscoord mOffsetX;
|
||||
nscoord mOffsetY;
|
||||
|
||||
nsSize mSize;
|
||||
nsSharedPageData* mPageData; // data shared by all the nsPageFrames
|
||||
|
||||
// Selection Printing Info
|
||||
nscoord mSelectionHeight;
|
||||
nscoord mYSelOffset;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsSimplePageSequence_h___ */
|
||||
|
|
|
@ -226,7 +226,7 @@ protected:
|
|||
}
|
||||
|
||||
PRBool HaveOutsideBullet() const {
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_X
|
||||
if(mState & NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET) {
|
||||
NS_ASSERTION(mBullet,"NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET flag set and no mBullet");
|
||||
}
|
||||
|
|
|
@ -48,6 +48,13 @@
|
|||
#include "nsIPresShell.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
#include "nsIView.h" // view flags for clipping
|
||||
|
||||
#include "nsHTMLContainerFrame.h" // view creation
|
||||
|
||||
#include "nsSimplePageSequence.h" // for nsSharedPageData
|
||||
|
||||
// for page number localization formatting
|
||||
#include "nsTextFormatter.h"
|
||||
|
@ -61,14 +68,8 @@
|
|||
#include "nsIServiceManager.h"
|
||||
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
||||
|
||||
// static data members
|
||||
PRUnichar * nsPageFrame::mDateTimeStr = nsnull;
|
||||
nsFont * nsPageFrame::mHeadFootFont = nsnull;
|
||||
PRUnichar * nsPageFrame::mPageNumFormat = nsnull;
|
||||
PRUnichar * nsPageFrame::mPageNumAndTotalsFormat = nsnull;
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
#define DEBUG_PRINTING
|
||||
//#define DEBUG_PRINTING
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_PRINTING
|
||||
|
@ -85,6 +86,7 @@ PRUnichar * nsPageFrame::mPageNumAndTotalsFormat = nsnull;
|
|||
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
|
||||
#endif
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
{
|
||||
|
@ -103,49 +105,50 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|||
nsPageFrame::nsPageFrame() :
|
||||
mSupressHF(PR_FALSE),
|
||||
mClipRect(-1, -1, -1, -1)
|
||||
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
mDebugFD = stdout;
|
||||
#endif
|
||||
nsresult rv;
|
||||
mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
|
||||
|
||||
if (mHeadFootFont == nsnull) {
|
||||
mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
}
|
||||
// now get the default font form the print options
|
||||
mPrintOptions->GetDefaultFont(*mHeadFootFont);
|
||||
}
|
||||
|
||||
nsPageFrame::~nsPageFrame()
|
||||
{
|
||||
if (mHeadFootFont != nsnull) {
|
||||
delete mHeadFootFont;
|
||||
mHeadFootFont = nsnull;
|
||||
}
|
||||
|
||||
if (mDateTimeStr) {
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
mDateTimeStr = nsnull;
|
||||
}
|
||||
|
||||
if (mPageNumFormat) {
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
mPageNumFormat = nsnull;
|
||||
}
|
||||
|
||||
if (mPageNumAndTotalsFormat) {
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
mPageNumAndTotalsFormat = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
NS_IMETHODIMP
|
||||
nsPageFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
||||
nsIAtom* aListName,
|
||||
nsIFrame* aChildList)
|
||||
{
|
||||
// only create a view for the area frame if we are printing the selection
|
||||
// (Also skip it if we are doing PrintPreview)
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
if (!ppContext) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;
|
||||
printService->GetPrintRange(&printRangeType);
|
||||
// make sure we are printing the selection
|
||||
if (printRangeType == nsIPrintOptions::kRangeSelection) {
|
||||
nsIView* view;
|
||||
aChildList->GetView(aPresContext, &view);
|
||||
if (view == nsnull) {
|
||||
nsCOMPtr<nsIStyleContext> styleContext;
|
||||
aChildList->GetStyleContext(getter_AddRefs(styleContext));
|
||||
nsHTMLContainerFrame::CreateViewForFrame(aPresContext, aChildList,
|
||||
styleContext, nsnull, PR_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
DO_GLOBAL_REFLOW_COUNT("nsPageFrame", aReflowState.reason);
|
||||
DISPLAY_REFLOW(this, aReflowState, aDesiredSize, aStatus);
|
||||
|
@ -209,13 +212,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
|||
// XXX Pay attention to the page's border and padding...
|
||||
if (mFrames.NotEmpty()) {
|
||||
nsIFrame* frame = mFrames.FirstChild();
|
||||
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame,
|
||||
maxSize);
|
||||
nsSize maxSize(mPD->mReflowRect.width - mPD->mReflowMargin.right - mPD->mReflowMargin.left,
|
||||
mPD->mReflowRect.height - mPD->mReflowMargin.top - mPD->mReflowMargin.bottom);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
|
||||
kidReflowState.isTopOfPage = PR_TRUE;
|
||||
kidReflowState.availableWidth = maxSize.width;
|
||||
kidReflowState.availableHeight = maxSize.height;
|
||||
|
||||
// Get the child's desired size
|
||||
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
||||
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, mPD->mReflowMargin.left, mPD->mReflowMargin.top, 0, aStatus);
|
||||
|
||||
// Make sure the child is at least as tall as our max size (the containing window)
|
||||
if (aDesiredSize.height < aReflowState.availableHeight) {
|
||||
|
@ -223,7 +228,7 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
|||
}
|
||||
|
||||
// Place and size the child
|
||||
FinishReflowChild(frame, aPresContext, aDesiredSize, 0, 0, 0);
|
||||
FinishReflowChild(frame, aPresContext, aDesiredSize, mPD->mReflowMargin.left, mPD->mReflowMargin.top, 0);
|
||||
|
||||
// Is the frame complete?
|
||||
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
||||
|
@ -306,8 +311,8 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
PRUnichar * kDate = GetUStr("&D");
|
||||
if (kDate != nsnull) {
|
||||
if (aStr.Find(kDate) > -1) {
|
||||
if (mDateTimeStr != nsnull) {
|
||||
aNewStr.ReplaceSubstring(kDate, mDateTimeStr);
|
||||
if (mPD->mDateTimeStr != nsnull) {
|
||||
aNewStr.ReplaceSubstring(kDate, mPD->mDateTimeStr);
|
||||
} else {
|
||||
aNewStr.ReplaceSubstring(kDate, NS_LITERAL_STRING("").get());
|
||||
}
|
||||
|
@ -324,7 +329,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
PRUnichar * kPage = GetUStr("&PT");
|
||||
if (kPage != nsnull) {
|
||||
if (aStr.Find(kPage) > -1) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
||||
aNewStr.ReplaceSubstring(kPage, uStr);
|
||||
nsMemory::Free(uStr);
|
||||
nsMemory::Free(kPage);
|
||||
|
@ -338,7 +343,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
kPage = GetUStr("&P");
|
||||
if (kPage != nsnull) {
|
||||
if (aStr.Find(kPage) > -1) {
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPageNumFormat, mPageNum);
|
||||
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
|
||||
aNewStr.ReplaceSubstring(kPage, uStr);
|
||||
nsMemory::Free(uStr);
|
||||
nsMemory::Free(kPage);
|
||||
|
@ -351,7 +356,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
if (kTitle != nsnull) {
|
||||
if (aStr.Find(kTitle) > -1) {
|
||||
PRUnichar * uTitle;
|
||||
mPrintOptions->GetTitle(&uTitle); // creates memory
|
||||
mPD->mPrintOptions->GetTitle(&uTitle); // creates memory
|
||||
SubstValueForCode(aNewStr, kTitle, uTitle);
|
||||
nsMemory::Free(uTitle);
|
||||
nsMemory::Free(kTitle);
|
||||
|
@ -364,7 +369,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|||
if (kDocURL != nsnull) {
|
||||
if (aStr.Find(kDocURL) > -1) {
|
||||
PRUnichar * uDocURL;
|
||||
mPrintOptions->GetDocURL(&uDocURL); // creates memory
|
||||
mPD->mPrintOptions->GetDocURL(&uDocURL); // creates memory
|
||||
SubstValueForCode(aNewStr, kDocURL, uDocURL);
|
||||
nsMemory::Free(uDocURL);
|
||||
nsMemory::Free(kDocURL);
|
||||
|
@ -491,23 +496,18 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
|
|||
|
||||
// cacl the x and y positions of the text
|
||||
nsRect rect(aRect);
|
||||
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
|
||||
rect.Deflate(quarterInch,0);
|
||||
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
|
||||
nscoord y;
|
||||
if (aHeaderFooter == eHeader) {
|
||||
nscoord offset = ((mMargin.top - aHeight) / 2);
|
||||
y = rect.y - offset - aHeight;
|
||||
rect.Inflate(0, offset + aHeight);
|
||||
y = rect.y;
|
||||
} else {
|
||||
nscoord offset = ((mMargin.bottom - aHeight) / 2);
|
||||
y = rect.y + rect.height + offset;
|
||||
rect.height += offset + aHeight;
|
||||
y = rect.y + rect.height - aHeight;
|
||||
}
|
||||
|
||||
// set up new clip and draw the text
|
||||
PRBool clipEmpty;
|
||||
aRenderingContext.PushState();
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
||||
aRenderingContext.DrawString(str, x, y + aAscent);
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
@ -545,7 +545,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
|
||||
nsRect rect;
|
||||
PRBool clipEmpty;
|
||||
if (mClipRect.width != -1 || mClipRect.height != -1) {
|
||||
PRBool specialClipIsSet = mClipRect.width != -1 || mClipRect.height != -1;
|
||||
|
||||
if (specialClipIsSet) {
|
||||
#ifdef DEBUG_PRINTING
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
||||
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
|
||||
|
@ -559,12 +561,85 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
rect = mRect;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINTING
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
aRenderingContext.FillRect(rect);
|
||||
nsRect pr = rect;
|
||||
pr.x = 0;
|
||||
pr.y = 0;
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
nsRect pageSize;
|
||||
nsRect adjSize;
|
||||
aPresContext->GetPageDim(&pageSize, &adjSize);
|
||||
if (ppContext && pageSize == adjSize) {
|
||||
pr.width -= mPD->mShadowSize.width;
|
||||
pr.height -= mPD->mShadowSize.height;
|
||||
|
||||
// paint just the page
|
||||
aRenderingContext.SetColor(NS_RGB(192,208,240));
|
||||
aRenderingContext.FillRect(pr);
|
||||
pr.Deflate(mPD->mReflowMargin);
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
aRenderingContext.FillRect(pr);
|
||||
} else {
|
||||
nsRect pr = rect;
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
pr.x = 0;
|
||||
pr.y = 0;
|
||||
aRenderingContext.FillRect(rect);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
mPD->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
rect.Deflate(mMargin);
|
||||
aRenderingContext.DrawRect(mRect);
|
||||
}
|
||||
|
||||
if (mPD->mShadowSize.width > 0 && mPD->mShadowSize.height > 0) {
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
nsRect r(0,0, mRect.width, mRect.height);
|
||||
nsRect shadowRect;
|
||||
shadowRect.x = r.x + r.width - mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + mPD->mShadowSize.height;
|
||||
shadowRect.width = mPD->mShadowSize.width;
|
||||
shadowRect.height = r.height - mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
|
||||
shadowRect.x = r.x + mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + r.height - mPD->mShadowSize.height;
|
||||
shadowRect.width = r.width - mPD->mShadowSize.width;
|
||||
shadowRect.height = mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
if (ppContext) {
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.width -= mPD->mShadowSize.width;
|
||||
rect.height -= mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
if (mPD->mShadowSize.width > 0 && mPD->mShadowSize.height > 0) {
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
nsRect r(0,0, mRect.width, mRect.height);
|
||||
nsRect shadowRect;
|
||||
shadowRect.x = r.x + r.width - mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + mPD->mShadowSize.height;
|
||||
shadowRect.width = mPD->mShadowSize.width;
|
||||
shadowRect.height = r.height - mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
|
||||
shadowRect.x = r.x + mPD->mShadowSize.width;
|
||||
shadowRect.y = r.y + r.height - mPD->mShadowSize.height;
|
||||
shadowRect.width = r.width - mPD->mShadowSize.width;
|
||||
shadowRect.height = mPD->mShadowSize.height;
|
||||
aRenderingContext.FillRect(shadowRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
|
||||
|
@ -573,32 +648,35 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
nsRect r;
|
||||
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
|
||||
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
|
||||
fprintf(stdout, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
|
||||
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
|
||||
// get the current margin
|
||||
mPrintOptions->GetMarginInTwips(mMargin);
|
||||
mPD->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
|
||||
nsRect rect(0,0,mRect.width, mRect.height);
|
||||
rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height);
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
{
|
||||
nsRect rct(0, 0, mRect.width, mRect.height);
|
||||
// XXX Paint a one-pixel border around the page so it's easy to see where
|
||||
// each page begins and ends when we're
|
||||
float p2t;
|
||||
aPresContext->GetPixelsToTwips(&p2t);
|
||||
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
rct.Deflate(mMargin);
|
||||
//float p2t;
|
||||
//aPresContext->GetPixelsToTwips(&p2t);
|
||||
//rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
||||
aRenderingContext.DrawRect(rect);
|
||||
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
aRenderingContext.DrawRect(rct);
|
||||
//rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
||||
fprintf(mDebugFD, "PageFr::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
|
||||
}
|
||||
#endif
|
||||
|
||||
// use the whole page
|
||||
rect.width += mMargin.left + mMargin.right;
|
||||
rect.x -= mMargin.left;
|
||||
|
||||
aRenderingContext.SetFont(*mHeadFootFont);
|
||||
|
||||
aRenderingContext.SetFont(*mPD->mHeadFootFont);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
// Get the FontMetrics to determine width.height of strings
|
||||
|
@ -606,7 +684,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
aPresContext->GetDeviceContext(getter_AddRefs(deviceContext));
|
||||
NS_ASSERTION(deviceContext, "Couldn't get the device context");
|
||||
nsCOMPtr<nsIFontMetrics> fontMet;
|
||||
deviceContext->GetMetricsFor(*mHeadFootFont, *getter_AddRefs(fontMet));
|
||||
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, *getter_AddRefs(fontMet));
|
||||
nscoord ascent = 0;
|
||||
nscoord visibleHeight = 0;
|
||||
if (fontMet) {
|
||||
|
@ -616,9 +694,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
|
||||
// print document headers and footers
|
||||
PRUnichar * headers[3];
|
||||
mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory
|
||||
mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory
|
||||
mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrLeft(&headers[0]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrCenter(&headers[1]); // creates memory
|
||||
mPD->mPrintOptions->GetHeaderStrRight(&headers[2]); // creates memory
|
||||
DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustLeft,
|
||||
nsAutoString(headers[0]), nsAutoString(headers[1]), nsAutoString(headers[2]),
|
||||
rect, ascent, visibleHeight);
|
||||
|
@ -626,9 +704,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
for (i=0;i<3;i++) nsMemory::Free(headers[i]);
|
||||
|
||||
PRUnichar * footers[3];
|
||||
mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory
|
||||
mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory
|
||||
mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrLeft(&footers[0]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrCenter(&footers[1]); // creates memory
|
||||
mPD->mPrintOptions->GetFooterStrRight(&footers[2]); // creates memory
|
||||
DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintOptions::kJustRight,
|
||||
nsAutoString(footers[0]), nsAutoString(footers[1]), nsAutoString(footers[2]),
|
||||
rect, ascent, visibleHeight);
|
||||
|
@ -637,23 +715,10 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|||
}
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPrintOptions(nsIPrintOptions * aPrintOptions)
|
||||
{
|
||||
NS_ASSERTION(aPrintOptions != nsnull, "Print Options can not be null!");
|
||||
|
||||
mPrintOptions = aPrintOptions;
|
||||
// create a default font
|
||||
mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
// now get the default font form the print options
|
||||
mPrintOptions->GetDefaultFont(*mHeadFootFont);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
||||
|
@ -663,33 +728,3 @@ nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
|||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
||||
{
|
||||
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
||||
|
||||
if (aForPageNumOnly) {
|
||||
if (mPageNumFormat != nsnull) {
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
}
|
||||
mPageNumFormat = aFormatStr;
|
||||
} else {
|
||||
if (mPageNumAndTotalsFormat != nsnull) {
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
}
|
||||
mPageNumAndTotalsFormat = aFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsPageFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
||||
{
|
||||
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
||||
|
||||
if (mDateTimeStr != nsnull) {
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
}
|
||||
mDateTimeStr = aDateTimeStr;
|
||||
}
|
||||
|
|
|
@ -40,12 +40,19 @@
|
|||
#include "nsContainerFrame.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
class nsSharedPageData;
|
||||
|
||||
// Page frame class used by the simple page sequence frame
|
||||
class nsPageFrame : public nsContainerFrame {
|
||||
|
||||
public:
|
||||
friend nsresult NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
|
||||
|
||||
// nsIFrame
|
||||
NS_IMETHOD SetInitialChildList(nsIPresContext* aPresContext,
|
||||
nsIAtom* aListName,
|
||||
nsIFrame* aChildList);
|
||||
|
||||
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aMaxSize,
|
||||
|
@ -77,19 +84,13 @@ public:
|
|||
// For Printing
|
||||
//////////////////
|
||||
|
||||
// Set the print options object into the page for printing
|
||||
virtual void SetPrintOptions(nsIPrintOptions * aPrintOptions);
|
||||
|
||||
// Tell the page which page number it is out of how many
|
||||
virtual void SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages);
|
||||
|
||||
virtual void SuppressHeadersAndFooters(PRBool aDoSup) { mSupressHF = aDoSup; }
|
||||
virtual void SetClipRect(nsRect* aClipRect) { mClipRect = *aClipRect; }
|
||||
|
||||
static void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
|
||||
// This is class is now responsible for freeing the memory
|
||||
static void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
|
||||
virtual SetSharedPageData(nsSharedPageData* aPD) { mPD = aPD; }
|
||||
|
||||
protected:
|
||||
nsPageFrame();
|
||||
|
@ -136,10 +137,7 @@ protected:
|
|||
PRPackedBool mSupressHF;
|
||||
nsRect mClipRect;
|
||||
|
||||
static PRUnichar * mDateTimeStr;
|
||||
static nsFont * mHeadFootFont;
|
||||
static PRUnichar * mPageNumFormat;
|
||||
static PRUnichar * mPageNumAndTotalsFormat;
|
||||
nsSharedPageData* mPD;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@
|
|||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIFocusController.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
#include "nsWidgetsCID.h"
|
||||
|
@ -3444,6 +3445,11 @@ PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const
|
|||
if (NS_SUCCEEDED(rv) && (nsnull != scrollable)) {
|
||||
// if it is then get the scrolled frame
|
||||
scrollable->GetScrolledFrame(nsnull, child);
|
||||
} else {
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(mPresContext);
|
||||
if (ppContext) {
|
||||
child->FirstChild(mPresContext, nsnull, &child);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the child is a pageSequence
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "nsIFontMetrics.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
#include "nsPageFrame.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
// DateTime Includes
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
|
@ -94,6 +95,28 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
|||
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
|
||||
#endif
|
||||
|
||||
// This object a shared by all the nsPageFrames
|
||||
// parented to a SimplePageSequenceFrame
|
||||
nsSharedPageData::nsSharedPageData() :
|
||||
mDateTimeStr(nsnull),
|
||||
mHeadFootFont(nsnull),
|
||||
mPageNumFormat(nsnull),
|
||||
mPageNumAndTotalsFormat(nsnull),
|
||||
mReflowRect(0,0,0,0),
|
||||
mReflowMargin(0,0,0,0),
|
||||
mShadowSize(0,0),
|
||||
mExtraMargin(0,0,0,0)
|
||||
{
|
||||
}
|
||||
|
||||
nsSharedPageData::~nsSharedPageData()
|
||||
{
|
||||
nsMemory::Free(mDateTimeStr);
|
||||
if (mHeadFootFont) delete mHeadFootFont;
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
{
|
||||
|
@ -110,7 +133,9 @@ NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|||
}
|
||||
|
||||
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
||||
mIsPrintingSelection(PR_FALSE)
|
||||
mIsPrintingSelection(PR_FALSE),
|
||||
mSelectionHeight(-1),
|
||||
mYSelOffset(0)
|
||||
{
|
||||
mStartOffset = OFFSET_NOT_SET;
|
||||
mEndOffset = OFFSET_NOT_SET;
|
||||
|
@ -118,22 +143,36 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
|||
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
|
||||
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
||||
|
||||
mPageData = new nsSharedPageData();
|
||||
NS_ASSERTION(mPageData != nsnull, "Can't be null!");
|
||||
if (mPageData->mHeadFootFont == nsnull) {
|
||||
mPageData->mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
}
|
||||
|
||||
// XXX this code and the object data member "mIsPrintingSelection" is only needed
|
||||
// for the hack for printing selection where we make the page the max size
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrintOptions> printService =
|
||||
do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && printService) {
|
||||
mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && mPageData->mPrintOptions) {
|
||||
PRInt16 printType;
|
||||
printService->GetPrintRange(&printType);
|
||||
mPageData->mPrintOptions->GetPrintRange(&printType);
|
||||
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType;
|
||||
printService->GetMarginInTwips(mMargin);
|
||||
mPageData->mPrintOptions->GetMarginInTwips(mMargin);
|
||||
|
||||
// now get the default font form the print options
|
||||
mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont);
|
||||
}
|
||||
mSkipPageBegin = PR_FALSE;
|
||||
mSkipPageEnd = PR_FALSE;
|
||||
mPrintThisPage = PR_FALSE;
|
||||
mOffsetX = 0;
|
||||
mOffsetY = 0;
|
||||
|
||||
// Doing this here so we only have to go get these formats once
|
||||
SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE);
|
||||
SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mDebugFD = stdout;
|
||||
#endif
|
||||
|
@ -141,6 +180,7 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
|||
|
||||
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
|
||||
{
|
||||
if (mPageData) delete mPageData;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -299,12 +339,53 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
|
||||
aStatus = NS_FRAME_COMPLETE; // we're always complete
|
||||
|
||||
|
||||
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
||||
|
||||
// *** Special Override ***
|
||||
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
||||
// and if this Document is in the upper left hand corner
|
||||
// we need to suppress the top margin or it will reflow too small
|
||||
// Start by getting the actual printer page dimensions to see if we are not a whole page
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
||||
nscoord width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
|
||||
// Compute the size of each page and the x coordinate that each page will
|
||||
// be placed at
|
||||
nsRect pageSize;
|
||||
nsRect adjSize;
|
||||
aPresContext->GetPageDim(&pageSize, &adjSize);
|
||||
|
||||
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
|
||||
nsMargin extraMargin(0,0,0,0);
|
||||
nsSize shadowSize(0,0);
|
||||
if (ppContext) {
|
||||
if (adjSize.width == width && adjSize.height == height) {
|
||||
extraMargin.SizeTo(quarterInch, quarterInch, quarterInch, quarterInch);
|
||||
float p2t;
|
||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
nscoord fourPixels = NSIntPixelsToTwips(4, p2t);
|
||||
shadowSize.SizeTo(fourPixels, fourPixels);
|
||||
}
|
||||
}
|
||||
|
||||
// absolutely ignore all other types of reflows
|
||||
// we only want to have done the Initial Reflow
|
||||
if (eReflowReason_Resize == aReflowState.reason ||
|
||||
eReflowReason_Incremental == aReflowState.reason ||
|
||||
eReflowReason_StyleChange == aReflowState.reason ||
|
||||
eReflowReason_Dirty == aReflowState.reason) {
|
||||
// Return our desired size
|
||||
aDesiredSize.height = mSize.height;
|
||||
aDesiredSize.width = mSize.width;
|
||||
aDesiredSize.ascent = aDesiredSize.height;
|
||||
aDesiredSize.descent = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool suppressLeftMargin = PR_FALSE;
|
||||
PRBool suppressRightMargin = PR_FALSE;
|
||||
PRBool suppressTopMargin = PR_FALSE;
|
||||
|
@ -332,22 +413,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
// (see also nsDocumentViewer.cpp)
|
||||
if (mIsPrintingSelection) {
|
||||
pageSize.height = NS_UNCONSTRAINEDSIZE;
|
||||
suppressLeftMargin = PR_FALSE;
|
||||
suppressTopMargin = PR_FALSE;
|
||||
suppressRightMargin = PR_FALSE;
|
||||
suppressBottomMargin = PR_FALSE;
|
||||
}
|
||||
|
||||
// *** Special Override ***
|
||||
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
||||
// and if this Document is in the upper left hand corner
|
||||
// we need to suppress the top margin or it will reflow too small
|
||||
// Start by getting the actual printer page dimensions to see if we are not a whole page
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
||||
nscoord width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
|
||||
if (adjSize.x == 0 && adjSize.y == 0 && (pageSize.width != width || pageSize.height != height)) {
|
||||
suppressTopMargin = PR_TRUE;
|
||||
}
|
||||
|
||||
// only use this local margin for sizing,
|
||||
// not for positioning
|
||||
|
@ -356,33 +427,40 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
suppressRightMargin?0:mMargin.right,
|
||||
suppressBottomMargin?0:mMargin.bottom);
|
||||
|
||||
nscoord x = mMargin.left;
|
||||
nscoord y = mMargin.top;// Running y-offset for each page
|
||||
nscoord x = extraMargin.left;
|
||||
nscoord y = extraMargin.top;// Running y-offset for each page
|
||||
|
||||
// See if it's an incremental reflow command
|
||||
if (eReflowReason_Incremental == aReflowState.reason) {
|
||||
// XXX Skip Incremental reflow,
|
||||
// in fact, all we want is the initial reflow
|
||||
//IncrementalReflow(aPresContext, aReflowState, pageSize, x, y);
|
||||
|
||||
y = mRect.height;
|
||||
} else {
|
||||
nsReflowReason reflowReason = aReflowState.reason;
|
||||
|
||||
SetPageSizes(pageSize, margin);
|
||||
|
||||
// Tile the pages vertically
|
||||
nsHTMLReflowMetrics kidSize(nsnull);
|
||||
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
|
||||
// Reflow the page
|
||||
nsSize availSize(pageSize.width, pageSize.height);
|
||||
nsSize availSize(pageSize.width+extraMargin.right+extraMargin.left+shadowSize.width,
|
||||
pageSize.height+extraMargin.top+extraMargin.bottom+shadowSize.height);
|
||||
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
|
||||
availSize, reflowReason);
|
||||
nsReflowStatus status;
|
||||
kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
|
||||
kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
|
||||
kidReflowState.availableWidth = availSize.width;
|
||||
kidReflowState.availableHeight = availSize.height;
|
||||
|
||||
kidReflowState.mComputedWidth = kidReflowState.availableWidth;
|
||||
//kidReflowState.mComputedHeight = kidReflowState.availableHeight;
|
||||
PRINT_DEBUG_MSG3("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight);
|
||||
|
||||
// Set the shared data into the page frame before reflow
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, kidFrame);
|
||||
pf->SetSharedPageData(mPageData);
|
||||
|
||||
// Place and size the page. If the page is narrower than our
|
||||
// max width then center it horizontally
|
||||
ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status);
|
||||
|
@ -390,16 +468,8 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
FinishReflowChild(kidFrame, aPresContext, kidSize, x, y, 0);
|
||||
y += kidSize.height;
|
||||
|
||||
nsIView* view;
|
||||
kidFrame->GetView(aPresContext, &view);
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
nsRect rect;
|
||||
kidFrame->GetRect(rect);
|
||||
nsRect viewRect;
|
||||
view->GetBounds(viewRect);
|
||||
|
||||
// Leave a slight gap between the pages
|
||||
y += mMargin.top + mMargin.bottom;
|
||||
y += quarterInch;
|
||||
|
||||
// Is the page complete?
|
||||
nsIFrame* kidNextInFlow;
|
||||
|
@ -429,12 +499,14 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
pageTot++;
|
||||
}
|
||||
|
||||
mPageData->mShadowSize = shadowSize;
|
||||
mPageData->mExtraMargin = extraMargin;
|
||||
|
||||
// Set Page Number Info
|
||||
PRInt32 pageNum = 1;
|
||||
for (page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, page);
|
||||
if (pf != nsnull) {
|
||||
//pf->SetPrintOptions(aPrintOptions);
|
||||
pf->SetPageNumInfo(pageNum, pageTot);
|
||||
}
|
||||
pageNum++;
|
||||
|
@ -458,7 +530,7 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
time( <ime );
|
||||
if (NS_SUCCEEDED(dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString))) {
|
||||
PRUnichar * uStr = ToNewUnicode(dateString);
|
||||
nsPageFrame::SetDateTimeStr(uStr); // nsPageFrame will own memory
|
||||
SetDateTimeStr(uStr); // memory will be freed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -468,10 +540,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
|||
|
||||
// Return our desired size
|
||||
aDesiredSize.height = y;
|
||||
aDesiredSize.width = pageSize.width;
|
||||
aDesiredSize.width = pageSize.width+extraMargin.left+shadowSize.width;
|
||||
aDesiredSize.ascent = aDesiredSize.height;
|
||||
aDesiredSize.descent = 0;
|
||||
|
||||
// cache the size so we can set the desired size
|
||||
// for the other reflows that happen
|
||||
mSize.width = aDesiredSize.width;
|
||||
mSize.height = aDesiredSize.height;
|
||||
|
||||
NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -582,7 +659,7 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
|
|||
// Sets the format into a static data memeber which will own the memory and free it
|
||||
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
||||
if (uStr != nsnull) {
|
||||
nsPageFrame::SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
||||
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -668,10 +745,9 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
|
|||
// we must make sure that the page is sized correctly before printing.
|
||||
PRInt32 width,height;
|
||||
dc->GetDeviceSurfaceDimensions(width,height);
|
||||
height -= mMargin.top + mMargin.bottom;
|
||||
|
||||
PRInt32 pageNum = 1;
|
||||
nscoord y = mMargin.top;
|
||||
nscoord y = 0;//mMargin.top;
|
||||
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
||||
nsIView* view;
|
||||
page->GetView(aPresContext, &view);
|
||||
|
@ -743,8 +819,6 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
|
|||
mTotalPages = totalPages;
|
||||
mCurrentPageFrame = mFrames.FirstChild();
|
||||
|
||||
//rv = PrintNextPage(aPresContext, aPrintOptions);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -824,39 +898,87 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
|
||||
// cast the frame to be a page frame
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, mCurrentPageFrame);
|
||||
if (pf != nsnull) {
|
||||
pf->SetPrintOptions(aPrintOptions);
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
// XXX This is temporary fix for printing more than one page of a selection
|
||||
// This does a poor man's "dump" pagination (see Bug 89353)
|
||||
// It has laid out as one long page and now we are just moving or view up/down
|
||||
// one page at a time and printing the contents of what is exposed by the rect.
|
||||
// currently this does not work for IFrames
|
||||
// I will soon improve this to work with IFrames
|
||||
PRBool continuePrinting = PR_TRUE;
|
||||
nscoord selectionHeight = mSelectionHeight;
|
||||
PRInt32 width, height;
|
||||
dc->GetDeviceSurfaceDimensions(width, height);
|
||||
nsRect clipRect(0, 0, width, height);
|
||||
height -= mMargin.top + mMargin.bottom;
|
||||
width -= mMargin.left + mMargin.right;
|
||||
nscoord selectionY = height;
|
||||
nsIView* containerView = nsnull;
|
||||
nsRect containerRect;
|
||||
if (mSelectionHeight > -1) {
|
||||
nsIFrame* childFrame = mFrames.FirstChild();
|
||||
nsIFrame* conFrame;
|
||||
childFrame->FirstChild(aPresContext, nsnull, &conFrame);
|
||||
conFrame->GetView(aPresContext, &containerView);
|
||||
containerView->GetBounds(containerRect);
|
||||
containerRect.y -= mYSelOffset;
|
||||
containerRect.height = height-mYSelOffset;
|
||||
containerView->SetBounds(containerRect, PR_FALSE);
|
||||
clipRect.SetRect(mMargin.left, mMargin.right, width, height);
|
||||
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, childFrame);
|
||||
nsRect nullClipRect(-1,-1,-1,-1);
|
||||
pf->SetClipRect(&nullClipRect);
|
||||
}
|
||||
|
||||
// Print the page
|
||||
nsIView* view;
|
||||
mCurrentPageFrame->GetView(aPresContext, &view);
|
||||
while (continuePrinting) {
|
||||
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
// cast the frame to be a page frame
|
||||
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, mCurrentPageFrame);
|
||||
if (pf != nsnull) {
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
pf->SetSharedPageData(mPageData);
|
||||
}
|
||||
|
||||
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
|
||||
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
// Print the page
|
||||
nsIView* view;
|
||||
mCurrentPageFrame->GetView(aPresContext, &view);
|
||||
|
||||
view->SetContentTransparency(PR_FALSE);
|
||||
vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
NS_ASSERTION(nsnull != view, "no page view");
|
||||
|
||||
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
|
||||
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
||||
|
||||
// this view was printed and since display set the origin
|
||||
// 0,0 there is a danger that this view can be printed again
|
||||
// If it is a sibling to another page/view. Setting the visibility
|
||||
// to hide will keep this page from printing again - dwc
|
||||
//
|
||||
// XXX Doesn't seem like we need to do this anymore
|
||||
//view->SetVisibility(nsViewVisibility_kHide);
|
||||
view->SetContentTransparency(PR_FALSE);
|
||||
|
||||
if (!mSkipPageEnd) {
|
||||
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
|
||||
rv = dc->EndPage();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
vm->Display(view, mOffsetX, mOffsetY, clipRect);
|
||||
|
||||
// this view was printed and since display set the origin
|
||||
// 0,0 there is a danger that this view can be printed again
|
||||
// If it is a sibling to another page/view. Setting the visibility
|
||||
// to hide will keep this page from printing again - dwc
|
||||
//
|
||||
// XXX Doesn't seem like we need to do this anymore
|
||||
//view->SetVisibility(nsViewVisibility_kHide);
|
||||
|
||||
if (!mSkipPageEnd) {
|
||||
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
|
||||
rv = dc->EndPage();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (mSelectionHeight > -1 && selectionY < mSelectionHeight) {
|
||||
selectionY += height;
|
||||
|
||||
mPrintedPageNum++;
|
||||
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
||||
containerRect.y -= height;
|
||||
containerRect.height += height;
|
||||
containerView->SetBounds(containerRect, PR_FALSE);
|
||||
|
||||
} else {
|
||||
continuePrinting = PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -971,3 +1093,52 @@ nsSimplePageSequenceFrame::Paint(nsIPresContext* aPresContext,
|
|||
aRenderingContext.PopState(clipEmpty);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSimplePageSequenceFrame::SizeTo(nsIPresContext* aPresContext, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
return nsFrame::SizeTo(aPresContext, aWidth, aHeight);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
||||
{
|
||||
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
if (aForPageNumOnly) {
|
||||
if (mPageData->mPageNumFormat != nsnull) {
|
||||
nsMemory::Free(mPageData->mPageNumFormat);
|
||||
}
|
||||
mPageData->mPageNumFormat = aFormatStr;
|
||||
} else {
|
||||
if (mPageData->mPageNumAndTotalsFormat != nsnull) {
|
||||
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
||||
}
|
||||
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
||||
{
|
||||
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
if (mPageData->mDateTimeStr != nsnull) {
|
||||
nsMemory::Free(mPageData->mDateTimeStr);
|
||||
}
|
||||
mPageData->mDateTimeStr = aDateTimeStr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
nsSimplePageSequenceFrame::SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect)
|
||||
{
|
||||
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
||||
|
||||
mPageData->mReflowRect = aRect;
|
||||
mPageData->mReflowMargin = aMarginRect;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,28 @@
|
|||
#include "nsContainerFrame.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
//-----------------------------------------------
|
||||
// This class maintains all the data that
|
||||
// is used by all the page frame
|
||||
// It lives while the nsSimplePageSequenceFrame lives
|
||||
class nsSharedPageData {
|
||||
public:
|
||||
nsSharedPageData();
|
||||
~nsSharedPageData();
|
||||
|
||||
PRUnichar * mDateTimeStr;
|
||||
nsFont * mHeadFootFont;
|
||||
PRUnichar * mPageNumFormat;
|
||||
PRUnichar * mPageNumAndTotalsFormat;
|
||||
|
||||
nsRect mReflowRect;
|
||||
nsMargin mReflowMargin;
|
||||
nsSize mShadowSize;
|
||||
nsMargin mExtraMargin;
|
||||
|
||||
nsCOMPtr<nsIPrintOptions> mPrintOptions;
|
||||
};
|
||||
|
||||
// Simple page sequence frame class. Used when we're in paginated mode
|
||||
class nsSimplePageSequenceFrame : public nsContainerFrame,
|
||||
public nsIPageSequenceFrame {
|
||||
|
@ -67,6 +89,7 @@ public:
|
|||
nsIPrintStatusCallback* aStatusCallback);
|
||||
NS_IMETHOD SetOffsets(nscoord aStartOffset, nscoord aEndOffset);
|
||||
NS_IMETHOD SetPageNo(PRInt32 aPageNo) { return NS_OK;}
|
||||
NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
|
||||
|
||||
// Async Printing
|
||||
NS_IMETHOD StartPrint(nsIPresContext* aPresContext,
|
||||
|
@ -85,6 +108,9 @@ public:
|
|||
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup);
|
||||
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize);
|
||||
|
||||
NS_IMETHOD SizeTo(nsIPresContext* aPresContext,
|
||||
nscoord aWidth,
|
||||
nscoord aHeight);
|
||||
#ifdef NS_DEBUG
|
||||
// Debugging
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
||||
|
@ -108,6 +134,11 @@ protected:
|
|||
|
||||
void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly);
|
||||
|
||||
// SharedPageData Helper methods
|
||||
void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
|
||||
void SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect);
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();}
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();}
|
||||
|
||||
|
@ -134,6 +165,14 @@ protected:
|
|||
nscoord mOffsetX;
|
||||
nscoord mOffsetY;
|
||||
|
||||
nsSize mSize;
|
||||
nsSharedPageData* mPageData; // data shared by all the nsPageFrames
|
||||
|
||||
// Selection Printing Info
|
||||
nscoord mSelectionHeight;
|
||||
nscoord mYSelOffset;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsSimplePageSequence_h___ */
|
||||
|
|
|
@ -395,4 +395,10 @@ input[type="submit"][disabled] {
|
|||
color: GrayText;
|
||||
}
|
||||
|
||||
@media print {
|
||||
input, textarea, select, button {
|
||||
-moz-user-focus: none !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -478,13 +478,25 @@ noembed, noscript, param {
|
|||
|
||||
@media print {
|
||||
|
||||
/* undo floats on aligned tables since we cannot print them correctly: see bug 74738 and bug 85768 */
|
||||
table[align="left"] {
|
||||
float: none;
|
||||
}
|
||||
/* undo floats on aligned tables since we cannot print them correctly: see bug 74738 and bug 85768 */
|
||||
table[align="left"] {
|
||||
float: none;
|
||||
}
|
||||
|
||||
table[align="right"] {
|
||||
float: none;
|
||||
}
|
||||
table[align="right"] {
|
||||
float: none;
|
||||
}
|
||||
|
||||
* {
|
||||
cursor: default !important;
|
||||
}
|
||||
|
||||
*|*:viewport, *|*:viewport-scroll, *|*:canvas {
|
||||
background-color: #A0A0A0 !important;
|
||||
}
|
||||
|
||||
*|*:-moz-any-link, *|*:-moz-any-link img, img[usemap], object[usemap],
|
||||
img[usemap], object[usemap], object, embed, applet, iframe {
|
||||
-moz-user-focus: none !important;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include "nsIScrollable.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIPrintContext.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
|
@ -260,6 +261,8 @@ friend class nsHTMLFrameOuterFrame;
|
|||
protected:
|
||||
nsresult CreateDocShell(nsIPresContext* aPresContext);
|
||||
nsresult DoLoadURL(nsIPresContext* aPresContext);
|
||||
nsresult CreateViewAndWidget(nsIPresContext* aPresContext,
|
||||
nsIWidget*& aWidget);
|
||||
|
||||
virtual ~nsHTMLFrameInnerFrame();
|
||||
|
||||
|
@ -1131,45 +1134,12 @@ nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext)
|
|||
}
|
||||
}
|
||||
|
||||
float t2p;
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// create, init, set the parent of the view
|
||||
nsIView* view;
|
||||
rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView),
|
||||
(void **)&view);
|
||||
if (NS_OK != rv) {
|
||||
NS_ASSERTION(0, "Could not create view for nsHTMLFrame");
|
||||
nsIWidget* widget;
|
||||
rv = CreateViewAndWidget(aPresContext, widget);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIView* parView;
|
||||
nsPoint origin;
|
||||
GetOffsetFromView(aPresContext, origin, &parView);
|
||||
nsRect viewBounds(origin.x, origin.y, 10, 10);
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
presShell->GetViewManager(getter_AddRefs(viewMan));
|
||||
rv = view->Init(viewMan, viewBounds, parView);
|
||||
viewMan->InsertChild(parView, view, 0);
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.clipChildren = PR_TRUE;
|
||||
initData.clipSiblings = PR_TRUE;
|
||||
|
||||
rv = view->CreateWidget(kCChildCID, &initData);
|
||||
SetView(aPresContext, view);
|
||||
|
||||
// if the visibility is hidden, reflect that in the view
|
||||
const nsStyleVisibility* vis;
|
||||
GetStyleData(eStyleStruct_Visibility, ((const nsStyleStruct *&)vis));
|
||||
if (!vis->IsVisible()) {
|
||||
view->SetVisibility(nsViewVisibility_kHide);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
view->GetWidget(*getter_AddRefs(widget));
|
||||
|
||||
mSubShell->InitWindow(nsnull, widget, 0, 0, 10, 10);
|
||||
mSubShell->Create();
|
||||
|
||||
|
@ -1350,6 +1320,57 @@ nsHTMLFrameInnerFrame::DoLoadURL(nsIPresContext* aPresContext)
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLFrameInnerFrame::CreateViewAndWidget(nsIPresContext* aPresContext,
|
||||
nsIWidget*& aWidget)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPresContext);
|
||||
NS_ENSURE_ARG_POINTER(aWidget);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
if (!presShell) return NS_ERROR_FAILURE;
|
||||
|
||||
float t2p;
|
||||
aPresContext->GetTwipsToPixels(&t2p);
|
||||
|
||||
// create, init, set the parent of the view
|
||||
nsIView* view;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, NS_GET_IID(nsIView),
|
||||
(void **)&view);
|
||||
if (NS_OK != rv) {
|
||||
NS_ASSERTION(0, "Could not create view for nsHTMLFrame");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIView* parView;
|
||||
nsPoint origin;
|
||||
GetOffsetFromView(aPresContext, origin, &parView);
|
||||
nsRect viewBounds(origin.x, origin.y, 10, 10);
|
||||
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
presShell->GetViewManager(getter_AddRefs(viewMan));
|
||||
rv = view->Init(viewMan, viewBounds, parView);
|
||||
viewMan->InsertChild(parView, view, 0);
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.clipChildren = PR_TRUE;
|
||||
initData.clipSiblings = PR_TRUE;
|
||||
|
||||
rv = view->CreateWidget(kCChildCID, &initData);
|
||||
SetView(aPresContext, view);
|
||||
|
||||
// if the visibility is hidden, reflect that in the view
|
||||
const nsStyleVisibility* vis;
|
||||
GetStyleData(eStyleStruct_Visibility, ((const nsStyleStruct *&)vis));
|
||||
if (!vis->IsVisible()) {
|
||||
view->SetVisibility(nsViewVisibility_kHide);
|
||||
}
|
||||
view->GetWidget(aWidget);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
|
@ -1368,6 +1389,20 @@ nsHTMLFrameInnerFrame::Init(nsIPresContext* aPresContext,
|
|||
// we are printing
|
||||
shouldCreateDoc = PR_FALSE;
|
||||
}
|
||||
|
||||
// for print preview we want to create the view and widget but
|
||||
// we do not want to load the document, it is alerady loaded.
|
||||
nsCOMPtr<nsIPrintPreviewContext> thePrintPreviewContext = do_QueryInterface(aPresContext);
|
||||
if (thePrintPreviewContext) {
|
||||
nsIWidget* widget;
|
||||
rv = CreateViewAndWidget(aPresContext, widget);
|
||||
NS_IF_RELEASE(widget);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
// we are in PrintPreview
|
||||
shouldCreateDoc = PR_FALSE;
|
||||
}
|
||||
|
||||
if (!mCreatingViewer && shouldCreateDoc) {
|
||||
// create the web shell
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
#include "nsObjectFrame.h"
|
||||
#include "nsRuleNode.h"
|
||||
#include "nsIXULDocument.h"
|
||||
#include "nsIPrintPreviewContext.h"
|
||||
|
||||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
||||
|
@ -3259,10 +3260,12 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
|
|||
PRBool isScrollable = IsScrollable(aPresContext, display);
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
aPresContext->IsPaginated(&isPaginated);
|
||||
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext(do_QueryInterface(aPresContext));
|
||||
|
||||
nsIFrame* scrollFrame = nsnull;
|
||||
|
||||
// build a scrollframe
|
||||
if (!isPaginated && isScrollable) {
|
||||
if ((!isPaginated || (isPaginated && printPreviewContext)) && isScrollable) {
|
||||
nsIFrame* newScrollFrame = nsnull;
|
||||
nsCOMPtr<nsIStyleContext> newContext;
|
||||
|
||||
|
@ -3541,6 +3544,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
aPresContext->IsPaginated(&isPaginated);
|
||||
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext(do_QueryInterface(aPresContext));
|
||||
|
||||
nsIFrame* rootFrame = nsnull;
|
||||
nsIAtom* rootPseudo;
|
||||
|
||||
|
@ -3572,13 +3577,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
// for print-preview, but not when printing), then create a scroll frame that
|
||||
// will act as the scrolling mechanism for the viewport.
|
||||
// XXX Do we even need a viewport when printing to a printer?
|
||||
PRBool isScrollable = PR_TRUE;
|
||||
if (aPresContext) {
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
if (NS_SUCCEEDED(aPresContext->IsPaginated(&isPaginated))) {
|
||||
isScrollable = !isPaginated;
|
||||
}
|
||||
}
|
||||
PRBool isScrollable = PR_TRUE;
|
||||
|
||||
//isScrollable = PR_FALSE;
|
||||
|
||||
|
@ -3623,6 +3622,19 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
}
|
||||
}
|
||||
|
||||
if (aPresContext) {
|
||||
PRBool isPaginated = PR_FALSE;
|
||||
if (NS_SUCCEEDED(aPresContext->IsPaginated(&isPaginated))) {
|
||||
if (isPaginated) {
|
||||
if (printPreviewContext) { // print preview
|
||||
aPresContext->GetPaginatedScrolling(&isScrollable);
|
||||
} else {
|
||||
isScrollable = PR_FALSE; // we are printing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame* newFrame = rootFrame;
|
||||
nsCOMPtr<nsIStyleContext> rootPseudoStyle;
|
||||
// we must create a state because if the scrollbars are GFX it needs the
|
||||
|
@ -3636,7 +3648,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
nsIFrame* parentFrame = viewportFrame;
|
||||
|
||||
// If paginated, make sure we don't put scrollbars in
|
||||
if (isPaginated)
|
||||
if (isPaginated && !printPreviewContext)
|
||||
aPresContext->ResolvePseudoStyleContextFor(nsnull, rootPseudo,
|
||||
viewportPseudoStyle, PR_FALSE,
|
||||
getter_AddRefs(rootPseudoStyle));
|
||||
|
@ -3733,7 +3745,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
|
||||
rootFrame->Init(aPresContext, nsnull, parentFrame, rootPseudoStyle, nsnull);
|
||||
|
||||
if (!isPaginated) {
|
||||
if (!isPaginated || (isPaginated && printPreviewContext)) {
|
||||
if (isScrollable) {
|
||||
FinishBuildingScrollFrame(aPresContext,
|
||||
state,
|
||||
|
@ -3749,7 +3761,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
|
|||
parentFrame->SetInitialChildList(aPresContext, nsnull, rootFrame);
|
||||
}
|
||||
}
|
||||
} else { // paginated
|
||||
}
|
||||
|
||||
if (isPaginated) { // paginated
|
||||
// Create the first page
|
||||
nsIFrame* pageFrame;
|
||||
NS_NewPageFrame(aPresShell, &pageFrame);
|
||||
|
|
|
@ -395,4 +395,10 @@ input[type="submit"][disabled] {
|
|||
color: GrayText;
|
||||
}
|
||||
|
||||
@media print {
|
||||
input, textarea, select, button {
|
||||
-moz-user-focus: none !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -478,13 +478,25 @@ noembed, noscript, param {
|
|||
|
||||
@media print {
|
||||
|
||||
/* undo floats on aligned tables since we cannot print them correctly: see bug 74738 and bug 85768 */
|
||||
table[align="left"] {
|
||||
float: none;
|
||||
}
|
||||
/* undo floats on aligned tables since we cannot print them correctly: see bug 74738 and bug 85768 */
|
||||
table[align="left"] {
|
||||
float: none;
|
||||
}
|
||||
|
||||
table[align="right"] {
|
||||
float: none;
|
||||
}
|
||||
table[align="right"] {
|
||||
float: none;
|
||||
}
|
||||
|
||||
* {
|
||||
cursor: default !important;
|
||||
}
|
||||
|
||||
*|*:viewport, *|*:viewport-scroll, *|*:canvas {
|
||||
background-color: #A0A0A0 !important;
|
||||
}
|
||||
|
||||
*|*:-moz-any-link, *|*:-moz-any-link img, img[usemap], object[usemap],
|
||||
img[usemap], object[usemap], object, embed, applet, iframe {
|
||||
-moz-user-focus: none !important;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -811,6 +811,11 @@ PluginViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintList
|
|||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PluginViewerImpl::PrintPreview()
|
||||
{
|
||||
return NS_OK; // XXX: hey, plug in guys! implement me!
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PluginViewerImpl::GetPrintable(PRBool *aPrintable)
|
||||
|
|
|
@ -10,3 +10,4 @@ nsIViewObserver.h
|
|||
nsIClipView.h
|
||||
nsIScrollPositionListener.h
|
||||
nsICompositeListener.h
|
||||
nsIEventProcessor.h
|
||||
|
|
|
@ -37,6 +37,7 @@ EXPORTS = \
|
|||
nsIClipView.h \
|
||||
nsIScrollPositionListener.h \
|
||||
nsICompositeListener.h \
|
||||
nsIEventProcessor.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
|
|
@ -24,7 +24,7 @@ DEPTH=..\..
|
|||
|
||||
DEFINES=-D_IMPL_NS_UI
|
||||
EXPORTS=nsIView.h nsIViewManager.h nsIScrollableView.h nsViewsCID.h nsIViewObserver.h \
|
||||
nsIClipView.h nsIScrollPositionListener.h nsICompositeListener.h
|
||||
nsIClipView.h nsIScrollPositionListener.h nsICompositeListener.h nsIEventProcessor.h
|
||||
MODULE=view
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -53,6 +53,7 @@ class nsIWidget;
|
|||
class nsICompositeListener;
|
||||
struct nsRect;
|
||||
class nsIDeviceContext;
|
||||
class nsIEventProcessor;
|
||||
|
||||
enum nsContentQuality {
|
||||
nsContentQuality_kGood = 0,
|
||||
|
@ -438,7 +439,7 @@ public:
|
|||
/**
|
||||
* Display the specified view. Used when printing.
|
||||
*/
|
||||
NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY) = 0;
|
||||
NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY, const nsRect& aClipRect) = 0;
|
||||
|
||||
/**
|
||||
* Add a listener to the view manager's composite listener list.
|
||||
|
@ -561,6 +562,14 @@ public:
|
|||
* @returns PR_TRUE if the rect is visible, PR_FALSE otherwise.
|
||||
*/
|
||||
NS_IMETHOD IsRectVisible(nsIView *aView, const nsRect &aRect, PRBool aMustBeFullyVisible, PRBool *isVisible)=0;
|
||||
|
||||
/**
|
||||
* Installs an event process that indicates whether the event should be disacrded or not
|
||||
* (see nsIEventProcessor.h)
|
||||
* @param aEventProcessor The event process to be installed and addref'ed,
|
||||
* pass in nsnull to clear it
|
||||
*/
|
||||
NS_IMETHOD SetEventProcessor(nsIEventProcessor* aEventProcessor)=0;
|
||||
};
|
||||
|
||||
//when the refresh happens, should it be double buffered?
|
||||
|
|
|
@ -1861,6 +1861,27 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS
|
|||
{
|
||||
*aStatus = nsEventStatus_eIgnore;
|
||||
|
||||
if (mEventProcessor) {
|
||||
// For mouse event we see if the event is in
|
||||
// the content area (not the scrollbars),
|
||||
// for other events we just pass true
|
||||
PRBool isInRect = PR_TRUE;
|
||||
if (NS_IS_MOUSE_EVENT(aEvent)) {
|
||||
nsRect visRect;
|
||||
GetVisibleRect(visRect);
|
||||
float p2t;
|
||||
mContext->GetDevUnitsToAppUnits(p2t);
|
||||
nsPoint pnt(NSIntPixelsToTwips(aEvent->point.x, p2t),
|
||||
NSIntPixelsToTwips(aEvent->point.y, p2t));
|
||||
isInRect = visRect.Contains(pnt);
|
||||
}
|
||||
|
||||
if (NS_FAILED(mEventProcessor->ProcessEvent(aEvent, isInRect, aStatus))) {
|
||||
// means we should discard event
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
switch(aEvent->message)
|
||||
{
|
||||
case NS_SIZE:
|
||||
|
@ -2992,7 +3013,7 @@ NS_IMETHODIMP nsViewManager::GetRootScrollableView(nsIScrollableView **aScrollab
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsViewManager::Display(nsIView* aView, nscoord aX, nscoord aY)
|
||||
NS_IMETHODIMP nsViewManager::Display(nsIView* aView, nscoord aX, nscoord aY, const nsRect& aClipRect)
|
||||
{
|
||||
nsIRenderingContext *localcx = nsnull;
|
||||
nsRect trect;
|
||||
|
@ -3020,7 +3041,7 @@ NS_IMETHODIMP nsViewManager::Display(nsIView* aView, nscoord aX, nscoord aY)
|
|||
PRBool result;
|
||||
|
||||
trect.x = trect.y = 0;
|
||||
localcx->SetClipRect(trect, nsClipCombine_kReplace, result);
|
||||
localcx->SetClipRect(aClipRect, nsClipCombine_kReplace, result);
|
||||
|
||||
// Paint the view. The clipping rect was set above set don't clip again.
|
||||
//aView->Paint(*localcx, trect, NS_VIEW_FLAG_CLIP_SET, result);
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "nsIRegion.h"
|
||||
#include "nsIBlender.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIEventProcessor.h"
|
||||
|
||||
class nsISupportsArray;
|
||||
struct DisplayListElement2;
|
||||
|
@ -154,7 +155,7 @@ public:
|
|||
|
||||
nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext, nsRect& aBounds);
|
||||
|
||||
NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY);
|
||||
NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY, const nsRect& aClipRect);
|
||||
|
||||
NS_IMETHOD AddCompositeListener(nsICompositeListener *aListener);
|
||||
NS_IMETHOD RemoveCompositeListener(nsICompositeListener *aListener);
|
||||
|
@ -274,6 +275,12 @@ private:
|
|||
*/
|
||||
NS_IMETHOD IsRectVisible(nsIView *aView, const nsRect &aRect, PRBool aMustBeFullyVisible, PRBool *isVisible);
|
||||
|
||||
/**
|
||||
* Installs event processor
|
||||
*/
|
||||
NS_IMETHOD SetEventProcessor(nsIEventProcessor* aEventProcessor) { mEventProcessor = aEventProcessor; return NS_OK; }
|
||||
|
||||
|
||||
nsresult ProcessWidgetChanges(nsIView* aView);
|
||||
|
||||
// Utilities used to size the offscreen drawing surface
|
||||
|
@ -393,6 +400,8 @@ protected:
|
|||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
void PostInvalidateEvent();
|
||||
|
||||
nsCOMPtr<nsIEventProcessor> mEventProcessor;
|
||||
|
||||
#ifdef NS_VM_PERF_METRICS
|
||||
MOZ_TIMER_DECLARE(mWatch) // Measures compositing+paint time for current document
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,8 @@ class nsIContentViewerFile : public nsISupports {
|
|||
*/
|
||||
NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener = nsnull) = 0;
|
||||
|
||||
NS_IMETHOD PrintPreview() = 0;
|
||||
|
||||
/* [noscript] void PrintContent (in nsIWebShell parent, in nsIDeviceContext DContext, in nsIDOMWindow aDOMWin, PRBool aIsSubDoc); */
|
||||
NS_IMETHOD PrintContent(nsIWebShell * aParent,
|
||||
nsIDeviceContext * aDContext,
|
||||
|
@ -57,6 +59,7 @@ class nsIContentViewerFile : public nsISupports {
|
|||
NS_IMETHOD Save(void); \
|
||||
NS_IMETHOD GetSaveable(PRBool *aSaveable); \
|
||||
NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener); \
|
||||
NS_IMETHOD PrintPreview(); \
|
||||
NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext, nsIDOMWindow * aDOMWin, PRBool aIsSubDoc); \
|
||||
NS_IMETHOD GetPrintable(PRBool *aPrintable);
|
||||
|
||||
|
@ -65,6 +68,7 @@ class nsIContentViewerFile : public nsISupports {
|
|||
NS_IMETHOD Save(void) { return _to ## Save(); } \
|
||||
NS_IMETHOD GetSaveable(PRBool *aSaveable) { return _to ## GetSaveable(aSaveable); } \
|
||||
NS_IMETHOD Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) { return _to ## Print(); } \
|
||||
NS_IMETHOD PrintPreview() { return _to ## Print(); } \
|
||||
NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext, nsIDOMWindow * aDOMWin, PRBool aIsSubDoc) { return _to ## PrintContent(parent, DContext, aDOMWin, aIsSubDoc); } \
|
||||
NS_IMETHOD GetPrintable(PRBool *aPrintable) { return _to ## GetPrintable(aPrintable); }
|
||||
|
||||
|
|
|
@ -2193,43 +2193,15 @@ nsBrowserWindow::DoPaste()
|
|||
void
|
||||
nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
|
||||
{
|
||||
static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID);
|
||||
nsIContentViewer* cv = nsnull;
|
||||
if (nsnull != mDocShell) {
|
||||
if ((NS_OK == mDocShell->GetContentViewer(&cv)) && (nsnull != cv)) {
|
||||
nsIDocumentViewer* docv = nsnull;
|
||||
if (NS_OK == cv->QueryInterface(kIDocumentViewerIID, (void**)&docv)) {
|
||||
nsIPresContext* printContext;
|
||||
nsresult rv =
|
||||
nsComponentManager::CreateInstance(kPrintPreviewContextCID,
|
||||
nsnull,
|
||||
kIPresContextIID,
|
||||
(void **)&printContext);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Prepare new printContext for print-preview
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
nsIPresContext* presContext;
|
||||
docv->GetPresContext(presContext);
|
||||
presContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
printContext->Init(dc);
|
||||
NS_RELEASE(presContext);
|
||||
nsCOMPtr <nsIContentViewer> viewer;
|
||||
|
||||
// Make a window using that content viewer
|
||||
// XXX Some piece of code needs to properly hold the reference to this
|
||||
// browser window. For the time being the reference is released by the
|
||||
// browser event handling code during processing of the NS_DESTROY event...
|
||||
nsBrowserWindow* bw = new nsNativeBrowserWindow;
|
||||
bw->SetApp(mApp);
|
||||
bw->Init(mAppShell, nsRect(0, 0, 600, 400),
|
||||
nsIWebBrowserChrome::CHROME_MENUBAR, PR_TRUE, docv, printContext);
|
||||
bw->SetVisibility(PR_TRUE);
|
||||
mDocShell->GetContentViewer(getter_AddRefs(viewer));
|
||||
|
||||
NS_RELEASE(printContext);
|
||||
}
|
||||
NS_RELEASE(docv);
|
||||
}
|
||||
NS_RELEASE(cv);
|
||||
if (viewer)
|
||||
{
|
||||
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
|
||||
if (viewerFile) {
|
||||
viewerFile->PrintPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -852,9 +852,18 @@ function BrowserEditBookmarks()
|
|||
|
||||
function BrowserPrintPreview()
|
||||
{
|
||||
// implement me
|
||||
// using _content.print() until printing becomes scriptable on docShell
|
||||
try {
|
||||
_content.printPreview();
|
||||
} catch (e) {
|
||||
// Pressing cancel is expressed as an NS_ERROR_FAILURE return value,
|
||||
// causing an exception to be thrown which we catch here.
|
||||
// Unfortunately this will also consume helpful failures, so add a
|
||||
// dump(e); // if you need to debug
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function BrowserPrintSetup()
|
||||
{
|
||||
goPageSetup(); // from utilityOverlay.js
|
||||
|
|
|
@ -105,14 +105,14 @@
|
|||
<command id="cmd_newEditor"/>
|
||||
<!-- NOT IMPLEMENTED
|
||||
<command id="cmd_newEditorTemplate"/>
|
||||
<command id="cmd_newEditorDraft"/>
|
||||
<command id="Browser:PrintPreview" disabled="true" oncommand=""/> -->
|
||||
<command id="cmd_newEditorDraft"/> -->
|
||||
<command id="Browser:OpenFile" oncommand="BrowserOpenFileWindow();"/>
|
||||
<command id="Browser:SavePage" oncommand="savePage();"/>
|
||||
<command id="Browser:EditPage" oncommand="editPage(window._content.location.href,window, false);"/>
|
||||
<command id="Browser:Open" oncommand="BrowserOpenWindow();"/>
|
||||
<command id="cmd_printSetup" oncommand="goPageSetup();"/>
|
||||
<command id="Browser:Print" oncommand="BrowserPrint();"/>
|
||||
<command id="Browser:PrintPreview" oncommand="BrowserPrintPreview();"/>
|
||||
<command id="cmd_quit"/>
|
||||
<command id="cmd_close" oncommand="BrowserCloseTabOrWindow()"/>
|
||||
<command id="cmd_closeWindow" oncommand="BrowserCloseWindow()"/>
|
||||
|
@ -191,6 +191,7 @@
|
|||
<menuitem label="&editPageCmd.label;" accesskey="&editPageCmd.accesskey;" key="key_editPage" command="Browser:EditPage" />
|
||||
<menuseparator/>
|
||||
<!-- Page setup gets inserted here on some platforms -->
|
||||
<menuitem id="printPreviewMenuItem" label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;" command="Browser:PrintPreview"/>
|
||||
<menuitem id="printMenuItem" label="&printCmd.label;" accesskey="&printCmd.accesskey;" key="printKb" command="Browser:Print"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="offlineGoOfflineCmd"/>
|
||||
|
|
Загрузка…
Ссылка в новой задаче