diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 7e494afb5117..263d972366ad 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -79,7 +79,7 @@ #include "nsLayoutAtoms.h" #include "nsIDOMHTMLFrameSetElement.h" #include "nsIFrameManager.h" - +#include "nsIPrintContext.h" #include "nsIChromeRegistry.h" @@ -935,7 +935,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // print any child documents // like frameset frames or iframes parentAsNode->GetChildCount(&count); - if(count> 0) { + if(count< 0) { // DC EXPERIMENT for(i=0;i child; parentAsNode->GetChildAt(i, getter_AddRefs(child)); @@ -951,14 +951,21 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // now complete printing the rest of the document // if it doesn't contain any framesets + doesContainFrameSet = PR_FALSE; // DC EXPERIMENT if (!doesContainFrameSet) { NS_ENSURE_SUCCESS( aDContext->BeginDocument(), NS_ERROR_FAILURE ); aDContext->GetDeviceSurfaceDimensions(width, height); nsCOMPtr cx; - rv = NS_NewPrintContext(getter_AddRefs(cx)); + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), getter_AddRefs(cx)); + if (NS_FAILED(rv)) { + return rv; + } } cx->Init(aDContext); @@ -1569,10 +1576,17 @@ PRInt32 width,height; webContainer = do_QueryInterface(mContainer); if(webContainer) { // load the document and do the initial reflow on the entire document - rv = NS_NewPrintContext(&mPrintPC); - if(NS_FAILED(rv)){ + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); + if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrintPC); + if (NS_FAILED(rv)) { + return rv; + } } + mPrintDC->GetDeviceSurfaceDimensions(width,height); mPrintPC->Init(mPrintDC); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 7e494afb5117..263d972366ad 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -79,7 +79,7 @@ #include "nsLayoutAtoms.h" #include "nsIDOMHTMLFrameSetElement.h" #include "nsIFrameManager.h" - +#include "nsIPrintContext.h" #include "nsIChromeRegistry.h" @@ -935,7 +935,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // print any child documents // like frameset frames or iframes parentAsNode->GetChildCount(&count); - if(count> 0) { + if(count< 0) { // DC EXPERIMENT for(i=0;i child; parentAsNode->GetChildAt(i, getter_AddRefs(child)); @@ -951,14 +951,21 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // now complete printing the rest of the document // if it doesn't contain any framesets + doesContainFrameSet = PR_FALSE; // DC EXPERIMENT if (!doesContainFrameSet) { NS_ENSURE_SUCCESS( aDContext->BeginDocument(), NS_ERROR_FAILURE ); aDContext->GetDeviceSurfaceDimensions(width, height); nsCOMPtr cx; - rv = NS_NewPrintContext(getter_AddRefs(cx)); + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), getter_AddRefs(cx)); + if (NS_FAILED(rv)) { + return rv; + } } cx->Init(aDContext); @@ -1569,10 +1576,17 @@ PRInt32 width,height; webContainer = do_QueryInterface(mContainer); if(webContainer) { // load the document and do the initial reflow on the entire document - rv = NS_NewPrintContext(&mPrintPC); - if(NS_FAILED(rv)){ + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); + if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrintPC); + if (NS_FAILED(rv)) { + return rv; + } } + mPrintDC->GetDeviceSurfaceDimensions(width,height); mPrintPC->Init(mPrintDC); diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 0525779a1212..996b8688301c 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -377,10 +377,6 @@ extern NS_LAYOUT nsresult extern NS_LAYOUT nsresult NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// printing -extern NS_LAYOUT nsresult - NS_NewPrintContext(nsIPresContext** aInstancePtrResult); #ifdef MOZ_REFLOW_PERF diff --git a/layout/base/public/makefile.win b/layout/base/public/makefile.win index 96851826cd8b..723c1aabcdf0 100644 --- a/layout/base/public/makefile.win +++ b/layout/base/public/makefile.win @@ -84,6 +84,7 @@ EXPORTS = \ nsIContentSerializer.h \ nsIHTMLToTextSink.h \ nsIScrollableViewProvider.h \ + nsIPrintContext.h \ $(NULL) MODULE=layout_base diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index 0525779a1212..996b8688301c 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -377,10 +377,6 @@ extern NS_LAYOUT nsresult extern NS_LAYOUT nsresult NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// printing -extern NS_LAYOUT nsresult - NS_NewPrintContext(nsIPresContext** aInstancePtrResult); #ifdef MOZ_REFLOW_PERF diff --git a/layout/base/public/nsIPrintContext.h b/layout/base/public/nsIPrintContext.h new file mode 100644 index 000000000000..985abcd8615a --- /dev/null +++ b/layout/base/public/nsIPrintContext.h @@ -0,0 +1,56 @@ +/* -*- 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): + * + * This Original Code has been modified by IBM Corporation. + * Modifications made by IBM described herein are + * Copyright (c) International Business Machines + * Corporation, 2000 + * + */ +#ifndef nsIPrintContext_h___ +#define nsIPrintContext_h___ + +#include "nsISupports.h" +#include "nscore.h" + + +#define NS_IPRINTCONTEXT_IID \ +{ 0xa05e0e40, 0xe1bf, 0x11d4, \ + { 0xa8, 0x5d, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } } + + +// An interface for presentation printing contexts +class nsIPrintContext : public nsISupports { + +public: +NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTCONTEXT_IID) + + + +}; + + +// Factory method to create a "paginated" presentation context for +// printing +extern NS_LAYOUT nsresult + NS_NewPrintContext(nsIPrintContext** aInstancePtrResult); + +#endif \ No newline at end of file diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index 0525779a1212..996b8688301c 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -377,10 +377,6 @@ extern NS_LAYOUT nsresult extern NS_LAYOUT nsresult NS_NewPrintPreviewContext(nsIPresContext** aInstancePtrResult); -// Factory method to create a "paginated" presentation context for -// printing -extern NS_LAYOUT nsresult - NS_NewPrintContext(nsIPresContext** aInstancePtrResult); #ifdef MOZ_REFLOW_PERF diff --git a/layout/base/src/nsDocumentViewer.cpp b/layout/base/src/nsDocumentViewer.cpp index 7e494afb5117..263d972366ad 100644 --- a/layout/base/src/nsDocumentViewer.cpp +++ b/layout/base/src/nsDocumentViewer.cpp @@ -79,7 +79,7 @@ #include "nsLayoutAtoms.h" #include "nsIDOMHTMLFrameSetElement.h" #include "nsIFrameManager.h" - +#include "nsIPrintContext.h" #include "nsIChromeRegistry.h" @@ -935,7 +935,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // print any child documents // like frameset frames or iframes parentAsNode->GetChildCount(&count); - if(count> 0) { + if(count< 0) { // DC EXPERIMENT for(i=0;i child; parentAsNode->GetChildAt(i, getter_AddRefs(child)); @@ -951,14 +951,21 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, // now complete printing the rest of the document // if it doesn't contain any framesets + doesContainFrameSet = PR_FALSE; // DC EXPERIMENT if (!doesContainFrameSet) { NS_ENSURE_SUCCESS( aDContext->BeginDocument(), NS_ERROR_FAILURE ); aDContext->GetDeviceSurfaceDimensions(width, height); nsCOMPtr cx; - rv = NS_NewPrintContext(getter_AddRefs(cx)); + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), getter_AddRefs(cx)); + if (NS_FAILED(rv)) { + return rv; + } } cx->Init(aDContext); @@ -1569,10 +1576,17 @@ PRInt32 width,height; webContainer = do_QueryInterface(mContainer); if(webContainer) { // load the document and do the initial reflow on the entire document - rv = NS_NewPrintContext(&mPrintPC); - if(NS_FAILED(rv)){ + nsCOMPtr printcon; + rv = NS_NewPrintContext(getter_AddRefs(printcon)); + if (NS_FAILED(rv)) { return rv; + } else { + rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrintPC); + if (NS_FAILED(rv)) { + return rv; + } } + mPrintDC->GetDeviceSurfaceDimensions(width,height); mPrintPC->Init(mPrintDC); diff --git a/layout/base/src/nsPrintContext.cpp b/layout/base/src/nsPrintContext.cpp index 9e7bdb544a9b..d48333375dfa 100644 --- a/layout/base/src/nsPrintContext.cpp +++ b/layout/base/src/nsPrintContext.cpp @@ -20,6 +20,7 @@ * Contributor(s): */ #include "nsPresContext.h" +#include "nsIPrintContext.h" #include "nsIDeviceContext.h" #include "nsUnitConversion.h" #include "nsIView.h" @@ -28,8 +29,16 @@ #include "nsLayoutAtoms.h" -class PrintContext : public nsPresContext { +class PrintContext : public nsPresContext , nsIPrintContext{ public: + //NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRINTCONTEXT_IID) + +//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 + + PrintContext(); ~PrintContext(); @@ -47,6 +56,27 @@ PrintContext::~PrintContext() { } +NS_IMPL_ADDREF_INHERITED(PrintContext,nsPresContext) + + +NS_IMPL_RELEASE_INHERITED(PrintContext,nsPresContext) + +//--------------------------------------------------------- +NS_IMETHODIMP +PrintContext::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + + if (aIID.Equals(NS_GET_IID(nsIPrintContext))) { + *aInstancePtr = (void *)((nsIPrintContext*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsPresContext::QueryInterface(aIID, aInstancePtr); +} + + + NS_IMETHODIMP PrintContext::GetMedium(nsIAtom** aResult) { @@ -105,8 +135,9 @@ PRInt32 width,height; } NS_LAYOUT nsresult -NS_NewPrintContext(nsIPresContext** aInstancePtrResult) +NS_NewPrintContext(nsIPrintContext** aInstancePtrResult) { + if (aInstancePtrResult == nsnull) { return NS_ERROR_NULL_POINTER; } @@ -117,5 +148,5 @@ NS_NewPrintContext(nsIPresContext** aInstancePtrResult) return NS_ERROR_OUT_OF_MEMORY; } - return it->QueryInterface(NS_GET_IID(nsIPresContext), (void **) aInstancePtrResult); + return it->QueryInterface(NS_GET_IID(nsIPrintContext), (void **) aInstancePtrResult); } diff --git a/layout/build/dlldeps.cpp b/layout/build/dlldeps.cpp index f448d174f7fb..ac9b7cfe57fc 100644 --- a/layout/build/dlldeps.cpp +++ b/layout/build/dlldeps.cpp @@ -25,6 +25,7 @@ #include "nsString.h" #include "nsIPresShell.h" +#include "nsIPrintContext.h" #include "nsIPresContext.h" #include "nsIStyleSet.h" #include "nsIDocument.h" @@ -36,9 +37,10 @@ void XXXNeverCalled() nsIPresShell* ps; NS_NewPresShell(&ps); nsIPresContext* cx; + nsIPrintContext *px; NS_NewGalleyContext(&cx); NS_NewPrintPreviewContext(&cx); - NS_NewPrintContext(&cx); + NS_NewPrintContext(&px); nsIStyleSet* ss; NS_NewStyleSet(&ss); nsIDocument* doc; diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp index e38103a8134a..fec6f71b78ec 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -63,6 +63,7 @@ #include "nsXPIDLString.h" #include "nsIScrollable.h" #include "nsINameSpaceManager.h" +#include "nsIPrintContext.h" #ifdef INCLUDE_XUL #include "nsIDOMXULElement.h" @@ -1010,6 +1011,15 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, nsresult rv = NS_OK; // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size + + // determine if we are a printcontext + + nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); + if (thePrinterContext) { + // we are printing + } + + if (!mCreatingViewer) { // create the web shell // we do this even if the size is not positive (bug 11762) diff --git a/layout/html/document/src/nsFrameFrame.cpp b/layout/html/document/src/nsFrameFrame.cpp index e38103a8134a..fec6f71b78ec 100644 --- a/layout/html/document/src/nsFrameFrame.cpp +++ b/layout/html/document/src/nsFrameFrame.cpp @@ -63,6 +63,7 @@ #include "nsXPIDLString.h" #include "nsIScrollable.h" #include "nsINameSpaceManager.h" +#include "nsIPrintContext.h" #ifdef INCLUDE_XUL #include "nsIDOMXULElement.h" @@ -1010,6 +1011,15 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, nsresult rv = NS_OK; // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size + + // determine if we are a printcontext + + nsCOMPtr thePrinterContext = do_QueryInterface(aPresContext); + if (thePrinterContext) { + // we are printing + } + + if (!mCreatingViewer) { // create the web shell // we do this even if the size is not positive (bug 11762)