Bug 369834: Get rid of SetAltDevice and friends (and fix print preview). r+sr=roc.

This commit is contained in:
sharparrow1%yahoo.com 2007-02-13 22:36:59 +00:00
parent c1ae573626
commit a8f437abc4
11 changed files with 74 additions and 182 deletions

View File

@ -121,12 +121,6 @@ public:
PRUnichar* aPrintToFileName) { return NS_OK; }
NS_IMETHOD AbortDocument(void) { return NS_OK; }
#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);
#endif
NS_IMETHOD PrepareNativeWidget(nsIWidget *aWidget, void **aOut);
NS_IMETHOD ClearCachedSystemFonts();
@ -150,11 +144,6 @@ protected:
nsCOMPtr<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
nsHashtable* mFontAliasTable;
#ifdef NS_PRINT_PREVIEW
nsCOMPtr<nsIDeviceContext> mAltDC;
PRUint8 mUseAltDC;
#endif
public:
nsNativeWidget mWidget;
#ifdef NS_DEBUG

View File

@ -469,25 +469,6 @@ public:
*/
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 retrieved
* via the alt device context
*/
NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn) = 0;
#endif
/**
* Clear cached system fonts (refresh from theme when
* requested). This method is effectively static,

View File

@ -49,7 +49,7 @@
#include "nsIServiceManager.h"
#include "nsUnicharUtils.h"
#include "nsCRT.h"
#include "nsIRenderingContext.h"
NS_IMPL_ISUPPORTS3(DeviceContextImpl, nsIDeviceContext, nsIObserver, nsISupportsWeakReference)
@ -61,9 +61,6 @@ DeviceContextImpl::DeviceContextImpl()
mWidget = nsnull;
mFontAliasTable = nsnull;
#ifdef NS_PRINT_PREVIEW
mUseAltDC = kUseAltDCFor_NONE;
#endif
#ifdef NS_DEBUG
mInitialized = PR_FALSE;
#endif
@ -128,14 +125,7 @@ void DeviceContextImpl::CommonInit(void)
NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext)
{
#ifdef NS_PRINT_PREVIEW
// AltDC NEVER use widgets to create their DCs
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATERC_PAINT)) {
return mAltDC->CreateRenderingContext(aContext);
}
#endif
nsresult rv;
nsresult rv;
aContext = nsnull;
nsCOMPtr<nsIRenderingContext> pContext;
@ -153,13 +143,6 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRende
NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext)
{
#ifdef NS_PRINT_PREVIEW
// AltDC NEVER use widgets to create their DCs
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATERC_PAINT)) {
return mAltDC->CreateRenderingContext(aContext);
}
#endif /* NS_PRINT_PREVIEW */
nsresult rv;
aContext = nsnull;
@ -180,15 +163,6 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIWidget *aWidget, nsIR
{
nsresult rv;
#ifdef NS_PRINT_PREVIEW
// AltDC NEVER use widgets to create their DCs
// NOTE: The mAltDC will call it;s own init
// so we can return here
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW)) {
return mAltDC->CreateRenderingContext(aContext);
}
#endif
aContext = nsnull;
nsCOMPtr<nsIRenderingContext> pContext;
rv = CreateRenderingContextInstance(*getter_AddRefs(pContext));
@ -218,32 +192,12 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContextInstance(nsIRenderingCont
nsresult DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
{
#ifdef NS_PRINT_PREVIEW
// there are a couple of cases where the kUseAltDCFor_CREATERC_xxx flag has been turned off
// but we still need to initialize with the Alt DC
if (mAltDC) {
return aContext->Init(mAltDC, aWin);
} else {
return aContext->Init(this, aWin);
}
#else
return aContext->Init(this, aWin);
#endif
}
nsresult DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aContext, nsIDrawingSurface* aSurface)
{
#ifdef NS_PRINT_PREVIEW
// there are a couple of cases where the kUseAltDCFor_CREATERC_xxx flag has been turned off
// but we still need to initialize with the Alt DC
if (mAltDC) {
return aContext->Init(mAltDC, aSurface);
} else {
return aContext->Init(this, aSurface);
}
#else
return aContext->Init(this, aSurface);
#endif /* NS_PRINT_PREVIEW */
}
NS_IMETHODIMP DeviceContextImpl::CreateFontCache()
@ -281,13 +235,6 @@ DeviceContextImpl::GetLocaleLangGroup(void)
NS_IMETHODIMP DeviceContextImpl::GetMetricsFor(const nsFont& aFont,
nsIAtom* aLangGroup, nsIFontMetrics*& aMetrics)
{
#ifdef NS_PRINT_PREVIEW
// Defer to Alt when there is one
if (mAltDC != nsnull && (mUseAltDC & kUseAltDCFor_FONTMETRICS)) {
return mAltDC->GetMetricsFor(aFont, aLangGroup, aMetrics);
}
#endif
if (nsnull == mFontCache) {
nsresult rv = CreateFontCache();
if (NS_FAILED(rv)) {
@ -308,13 +255,6 @@ NS_IMETHODIMP DeviceContextImpl::GetMetricsFor(const nsFont& aFont,
NS_IMETHODIMP DeviceContextImpl::GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics)
{
#ifdef NS_PRINT_PREVIEW
// Defer to Alt when there is one
if (mAltDC != nsnull && (mUseAltDC & kUseAltDCFor_FONTMETRICS)) {
return mAltDC->GetMetricsFor(aFont, aMetrics);
}
#endif
if (nsnull == mFontCache) {
nsresult rv = CreateFontCache();
if (NS_FAILED(rv)) {
@ -515,29 +455,6 @@ NS_IMETHODIMP DeviceContextImpl::FlushFontCache(void)
return NS_OK;
}
#ifdef NS_PRINT_PREVIEW
NS_IMETHODIMP DeviceContextImpl::SetAltDevice(nsIDeviceContext* aAltDC)
{
mAltDC = aAltDC;
// Can't use it if it isn't there
if (aAltDC == nsnull) {
mUseAltDC = kUseAltDCFor_NONE;
}
return NS_OK;
}
NS_IMETHODIMP DeviceContextImpl::SetUseAltDC(PRUint8 aValue, PRBool aOn)
{
if (aOn) {
mUseAltDC |= aValue;
} else {
mUseAltDC &= ~aValue;
}
return NS_OK;
}
#endif
/////////////////////////////////////////////////////////////
nsFontCache::nsFontCache()

View File

@ -584,28 +584,6 @@ nsThebesDeviceContext::EndPage(void)
return NS_OK;
}
NS_IMETHODIMP
nsThebesDeviceContext::SetAltDevice(nsIDeviceContext* aAltDC)
{
return NS_OK;
}
NS_IMETHODIMP
nsThebesDeviceContext::GetAltDevice(nsIDeviceContext** aAltDC)
{
*aAltDC = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsThebesDeviceContext::SetUseAltDC(PRUint8 aValue, PRBool aOn)
{
return NS_OK;
}
/** End printing methods **/
int

View File

@ -108,9 +108,6 @@ public:
NS_IMETHOD AbortDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC);
NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC);
NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn);
/* end printing goop */
static void DebugShowCairoSurface (const char *aName, cairo_surface_t *aSurface);

View File

@ -794,13 +794,6 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
mDeviceContext = aDeviceContext;
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Clear PrintPreview Alternate Device
if (mDeviceContext) {
mDeviceContext->SetAltDevice(nsnull);
}
#endif
PRBool makeCX = PR_FALSE;
if (aDoCreation) {
if (aParentWidget && !mPresContext) {
@ -857,9 +850,10 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
// In fact I'm just adding a line that makes this block
// get compiled *less* often.
mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(devctx));
mDeviceContext->SetAltDevice(devctx);
mDeviceContext->SetUseAltDC(kUseAltDCFor_SURFACE_DIM, PR_TRUE);
//Get paper dims:
// XXX I'm breaking this code; I'm not sure I really want to mess with
// the document viewer at the moment to get the right device context
// (this won't break anyone, since page layout mode was never really
// usable)
PRInt32 pageWidth, pageHeight;
devctx->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
mPresContext->SetPageSize(nsSize(pageWidth, pageHeight));
@ -1980,13 +1974,6 @@ DocumentViewerImpl::Show(void)
mDeviceContext = mParentWidget->GetDeviceContext();
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Clear PrintPreview Alternate Device
if (mDeviceContext) {
mDeviceContext->SetAltDevice(nsnull);
}
#endif
// Create presentation context
NS_ASSERTION(!mPresContext, "Shouldn't have a prescontext if we have no shell!");
mPresContext = new nsPresContext(mDocument, nsPresContext::eContext_Galley);

View File

@ -178,7 +178,8 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, 0, 0),
mCanPaginatedScroll(PR_FALSE),
mIsRootPaginatedDocument(PR_FALSE)
mIsRootPaginatedDocument(PR_FALSE),
mPPScale(1.0f)
{
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
// bother initializing members to 0.

View File

@ -434,7 +434,16 @@ public:
float GetPageScale() { return mPageScale; }
void SetPageScale(float aScale) { mPageScale = aScale; }
/**
* Get/set the scaling facor to use when rendering the pages for print preview.
* Only safe to get after print preview set up; safe to set anytime.
* This is a scaling factor for the display of the print preview. It
* does not affect layout. It only affects the size of the onscreen pages
* in print preview.
* XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
*/
float GetPrintPreviewScale() { return mPPScale; }
void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
nsIDeviceContext* DeviceContext() { return mDeviceContext; }
nsIEventStateManager* EventStateManager() { return mEventManager; }
@ -775,6 +784,7 @@ protected:
nsRect mVisibleArea;
nsSize mPageSize;
float mPageScale;
float mPPScale;
nscolor mDefaultColor;
nscolor mBackgroundColor;

View File

@ -369,8 +369,10 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
#endif
// Return our desired size
aDesiredSize.height = y; // includes page heights and dead space
aDesiredSize.width = x + availSize.width + deadSpaceGap;
// Adjustr the reflow size by PrintPreviewScale so the scrollbars end up the
// correct size
aDesiredSize.height = y * GetPresContext()->GetPrintPreviewScale(); // includes page heights and dead space
aDesiredSize.width = (x + availSize.width + deadSpaceGap) * GetPresContext()->GetPrintPreviewScale();
aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width,
aDesiredSize.height);
@ -743,7 +745,43 @@ nsSimplePageSequenceFrame::DoPageEnd()
return rv;
}
static void PaintPageSequence(nsIFrame* aFrame, nsIRenderingContext* aCtx,
const nsRect& aDirtyRect, nsPoint aPt)
{
NS_STATIC_CAST(nsSimplePageSequenceFrame*, aFrame)->PaintPageSequence(*aCtx, aDirtyRect, aPt);
}
//------------------------------------------------------------------------------
void
nsSimplePageSequenceFrame::PaintPageSequence(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsPoint aPt) {
nsRect rect = aDirtyRect;
float scale = GetPresContext()->GetPrintPreviewScale();
aRenderingContext.PushState();
nsPoint framePos = aPt;
aRenderingContext.Translate(framePos.x, framePos.y);
rect -= framePos;
aRenderingContext.Scale(scale, scale);
rect.ScaleRoundOut(1.0f / scale);
// Now the rect and the rendering coordinates are are relative to this frame.
// Loop over the pages and paint them.
nsIFrame* child = GetFirstChild(nsnull);
while (child) {
nsPoint pt = child->GetPosition();
// The rendering context has to be translated before each call to PaintFrame
aRenderingContext.PushState();
aRenderingContext.Translate(pt.x, pt.y);
nsLayoutUtils::PaintFrame(&aRenderingContext, child,
nsRegion(rect - pt), NS_RGBA(0,0,0,0));
aRenderingContext.PopState();
child = child->GetNextSibling();
}
aRenderingContext.PopState();
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
@ -752,10 +790,11 @@ nsSimplePageSequenceFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
NS_ENSURE_SUCCESS(rv, rv);
// Treat each page as a psuedo-stack so everything goes in the Content() list.
return
BuildDisplayListForNonBlockChildren(aBuilder, aDirtyRect, aLists,
DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT);
rv = aLists.Content()->AppendNewToTop(new (aBuilder)
nsDisplayGeneric(this, ::PaintPageSequence, "PageSequence"));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsIAtom*

View File

@ -131,6 +131,9 @@ public:
NS_IMETHOD GetFrameName(nsAString& aResult) const;
#endif
void PaintPageSequence(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsPoint aPt);
protected:
nsSimplePageSequenceFrame(nsStyleContext* aContext);
@ -175,9 +178,6 @@ protected:
// I18N date formatter service which we'll want to cache locally.
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
private:
void CacheBackground(nsPresContext* aPresContext);
};
#endif /* nsSimplePageSequence_h___ */

View File

@ -926,9 +926,6 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
rv = devspec->Init(mParentWidget, mPrt->mPrintSettings, PR_TRUE);
if (NS_SUCCEEDED(rv)) {
rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC));
if (NS_SUCCEEDED(rv)) {
mDeviceContext->SetAltDevice(ppDC);
}
}
}
@ -938,13 +935,7 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
// we want to view every page in PrintPreview each time
mPrt->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
mPrt->mPrintDC = mDeviceContext;
if (mDeviceContext) {
mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_TRUE);
mDeviceContext->SetUseAltDC(kUseAltDCFor_CREATERC_REFLOW, PR_TRUE);
mDeviceContext->SetUseAltDC(kUseAltDCFor_SURFACE_DIM, PR_TRUE);
}
mPrt->mPrintDC = ppDC ? ppDC : mDeviceContext;
if (aWebProgressListener != nsnull) {
mPrt->mPrintProgressListeners.AppendObject(aWebProgressListener);
@ -2163,6 +2154,12 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
aPO->mPresContext->SetPageSize(adjSize);
aPO->mPresContext->SetIsRootPaginatedDocument(documentIsTopLevel);
aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
// Calculate scale factor from printer to screen
PRInt32 printDPI = mPrt->mPrintDC->AppUnitsPerInch() /
mPrt->mPrintDC->AppUnitsPerDevPixel();
PRInt32 screenDPI = mDeviceContext->AppUnitsPerInch() /
mDeviceContext->AppUnitsPerDevPixel();
aPO->mPresContext->SetPrintPreviewScale(float(screenDPI) / float(printDPI));
rv = aPO->mPresShell->InitialReflow(adjSize.width, adjSize.height);
@ -3267,10 +3264,6 @@ nsPrintEngine::FinishPrintPreview()
SetIsCreatingPrintPreview(PR_FALSE);
if (mPrt->mPrintDC) {
mPrt->mPrintDC->SetAltDevice(nsnull);
}
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
/* cleanup done, let's fire-up an error dialog to notify the user