Added nsIPrintContext interface.

Added this so you can now tell if your laying out to a printer.
r=attinasi sr=buster
This commit is contained in:
dcone%netscape.com 2001-01-08 20:26:05 +00:00
parent e838b42d99
commit 0f7ab3cd10
12 changed files with 171 additions and 31 deletions

View File

@ -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<count;i++) {
nsCOMPtr<nsIDocShellTreeItem> 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<nsIPresContext> cx;
rv = NS_NewPrintContext(getter_AddRefs(cx));
nsCOMPtr<nsIPrintContext> 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<nsIPrintContext> 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);

View File

@ -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<count;i++) {
nsCOMPtr<nsIDocShellTreeItem> 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<nsIPresContext> cx;
rv = NS_NewPrintContext(getter_AddRefs(cx));
nsCOMPtr<nsIPrintContext> 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<nsIPrintContext> 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);

View File

@ -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

View File

@ -84,6 +84,7 @@ EXPORTS = \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
nsIScrollableViewProvider.h \
nsIPrintContext.h \
$(NULL)
MODULE=layout_base

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<count;i++) {
nsCOMPtr<nsIDocShellTreeItem> 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<nsIPresContext> cx;
rv = NS_NewPrintContext(getter_AddRefs(cx));
nsCOMPtr<nsIPrintContext> 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<nsIPrintContext> 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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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<nsIPrintContext> 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)

View File

@ -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<nsIPrintContext> 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)