Merge back out of changeset 86e8ec17e532 (bug 584193).

This commit is contained in:
Timothy Nikkel 2010-08-08 16:58:59 -05:00
commit e3a4bc82b8
7 changed files with 86 additions and 53 deletions

View File

@ -326,13 +326,6 @@ public:
// nsIDocumentViewer interface...
NS_IMETHOD GetPresShell(nsIPresShell** aResult);
NS_IMETHOD GetPresContext(nsPresContext** aResult);
/**
* Find the view to use as the container view for MakeWindow. Returns
* null if this will be the root of a view manager hierarchy. In that
* case, if mParentWidget is null then this document should not even
* be displayed.
*/
virtual nsIView* FindContainerView();
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
@ -368,6 +361,14 @@ private:
*/
nsresult MakeWindow(const nsSize& aSize, nsIView* aContainerView);
/**
* Find the view to use as the container view for MakeWindow. Returns
* null if this will be the root of a view manager hierarchy. In that
* case, if mParentWidget is null then this document should not even
* be displayed.
*/
nsIView* FindContainerView();
/**
* Create our device context
*/
@ -381,6 +382,7 @@ private:
nsISupports *aState,
const nsIntRect& aBounds,
PRBool aDoCreation,
PRBool aInPrintPreview,
PRBool aNeedMakeCX = PR_TRUE);
/**
* @param aDoInitialReflow set to true if you want to kick off the initial
@ -690,7 +692,7 @@ NS_IMETHODIMP
DocumentViewerImpl::Init(nsIWidget* aParentWidget,
const nsIntRect& aBounds)
{
return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE);
return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE, PR_FALSE);
}
nsresult
@ -832,6 +834,7 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
nsISupports *aState,
const nsIntRect& aBounds,
PRBool aDoCreation,
PRBool aInPrintPreview,
PRBool aNeedMakeCX /*= PR_TRUE*/)
{
// We don't want any scripts to run here. That can cause flushing,
@ -941,18 +944,20 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
mPresContext->SetLinkHandler(linkHandler);
}
// Set script-context-owner in the document
if (!aInPrintPreview) {
// Set script-context-owner in the document
nsCOMPtr<nsPIDOMWindow> window;
requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
getter_AddRefs(window));
nsCOMPtr<nsPIDOMWindow> window;
requestor->GetInterface(NS_GET_IID(nsPIDOMWindow),
getter_AddRefs(window));
if (window) {
nsCOMPtr<nsIDocument> curDoc =
do_QueryInterface(window->GetExtantDocument());
if (!mIsPageMode || curDoc != mDocument) {
window->SetNewDocument(mDocument, aState);
nsJSContext::LoadStart();
if (window) {
nsCOMPtr<nsIDocument> curDoc =
do_QueryInterface(window->GetExtantDocument());
if (!mIsPageMode || curDoc != mDocument) {
window->SetNewDocument(mDocument, aState);
nsJSContext::LoadStart();
}
}
}
}
@ -1354,7 +1359,7 @@ DocumentViewerImpl::Open(nsISupports *aState, nsISHEntry *aSHEntry)
if (mDocument)
mDocument->SetContainer(nsCOMPtr<nsISupports>(do_QueryReferent(mContainer)));
nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE);
nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
if (mPresShell)
@ -1878,6 +1883,13 @@ DocumentViewerImpl::SetBounds(const nsIntRect& aBounds)
if (mPreviousViewer)
mPreviousViewer->SetBounds(aBounds);
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
if (GetIsPrintPreview() && !mPrintEngine->GetIsCreatingPrintPreview()) {
mPrintEngine->GetPrintPreviewWindow()->Resize(aBounds.x, aBounds.y,
aBounds.width, aBounds.height,
PR_FALSE);
}
#endif
return NS_OK;
}
@ -3647,6 +3659,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
float(mDeviceContext->AppUnitsPerInch()) /
float(mDeviceContext->AppUnitsPerDevPixel()) /
mPageZoom,
mParentWidget,
#ifdef NS_DEBUG
mDebugFile
#else
@ -3696,8 +3709,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
NS_ASSERTION(docShell, "This has to be a docshell");
if (!docShell || !mDeviceContext) {
PR_PL(("Can't Print Preview without device context and docshell"));
if (!docShell ||! mDeviceContext || !mParentWidget) {
PR_PL(("Can't Print Preview without device context, docshell etc"));
return NS_ERROR_FAILURE;
}
@ -3714,6 +3727,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
float(mDeviceContext->AppUnitsPerInch()) /
float(mDeviceContext->AppUnitsPerDevPixel()) /
mPageZoom,
mParentWidget,
#ifdef NS_DEBUG
mDebugFile
#else
@ -4276,7 +4290,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetPageMode(PRBool aPageMode, nsIPrintSettings
nsresult rv = mPresContext->Init(mDeviceContext);
NS_ENSURE_SUCCESS(rv, rv);
}
InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE);
InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE, PR_FALSE);
Show();
return NS_OK;
@ -4319,7 +4333,8 @@ DocumentViewerImpl::InitializeForPrintPreview()
}
void
DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
DocumentViewerImpl::SetPrintPreviewPresentation(nsIWidget* aWidget,
nsIViewManager* aViewManager,
nsPresContext* aPresContext,
nsIPresShell* aPresShell)
{
@ -4327,7 +4342,7 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
DestroyPresShell();
}
mWindow = nsnull;
mWindow = aWidget;
mViewManager = aViewManager;
mPresContext = aPresContext;
mPresShell = aPresShell;

View File

@ -46,12 +46,10 @@ class nsIDocument;
class nsPresContext;
class nsIPresShell;
class nsIStyleSheet;
class nsIView;
#define NS_IDOCUMENT_VIEWER_IID \
{ 0x79c0bdbf, 0xf508, 0x4970, \
{ 0x94, 0x65, 0x03, 0x5e, 0xda, 0x2c, 0x02, 0x72 } }
{ 0xf29e5537, 0x0763, 0x4977, \
{ 0x83, 0xc2, 0x3c, 0x93, 0x6c, 0x66, 0xa9, 0xfc } }
/**
* A document viewer is a kind of content viewer that uses NGLayout
* to manage the presentation of the content.
@ -64,8 +62,6 @@ public:
NS_IMETHOD GetPresShell(nsIPresShell** aResult) = 0;
NS_IMETHOD GetPresContext(nsPresContext** aResult) = 0;
virtual nsIView* FindContainerView() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewer, NS_IDOCUMENT_VIEWER_IID)

View File

@ -90,7 +90,8 @@ public:
/**
* Replaces the current presentation with print preview presentation.
*/
virtual void SetPrintPreviewPresentation(nsIViewManager* aViewManager,
virtual void SetPrintPreviewPresentation(nsIWidget* aWidget,
nsIViewManager* aViewManager,
nsPresContext* aPresContext,
nsIPresShell* aPresShell) = 0;
};
@ -110,7 +111,8 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
virtual void OnDonePrinting(); \
virtual PRBool IsInitializedForPrintPreview(); \
virtual void InitializeForPrintPreview(); \
virtual void SetPrintPreviewPresentation(nsIViewManager* aViewManager, \
virtual void SetPrintPreviewPresentation(nsIWidget* aWidget, \
nsIViewManager* aViewManager, \
nsPresContext* aPresContext, \
nsIPresShell* aPresShell);

View File

@ -155,7 +155,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsIDOMHTMLImageElement.h"
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
#include "nsPIDOMWindow.h"
@ -267,6 +266,7 @@ nsPrintEngine::nsPrintEngine() :
mPrt(nsnull),
mPagePrintTimer(nsnull),
mPageSeqFrame(nsnull),
mParentWidget(nsnull),
mPrtPreview(nsnull),
mOldPrtPreview(nsnull),
mDebugFile(nsnull)
@ -321,6 +321,7 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIDocument* aDocument,
float aScreenDPI,
nsIWidget* aParentWidget,
FILE* aDebugFile)
{
NS_ENSURE_ARG_POINTER(aDocViewerPrint);
@ -331,6 +332,7 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
mContainer = aContainer; // weak reference
mDocument = aDocument;
mScreenDPI = aScreenDPI;
mParentWidget = aParentWidget;
mDebugFile = aDebugFile; // ok to be NULL
@ -1883,14 +1885,12 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
nsSize adjSize;
PRBool documentIsTopLevel;
nsIFrame* frame = nsnull;
if (!aPO->IsPrintable())
return NS_OK;
PRBool canCreateScrollbars = PR_TRUE;
nsIView* parentView = nsnull;
if (aPO->mParent && aPO->mParent->IsPrintable()) {
nsIFrame* frame = aPO->mContent->GetPrimaryFrame();
frame = aPO->mContent->GetPrimaryFrame();
// Without a frame, this document can't be displayed; therefore, there is no
// point to reflowing it
if (!frame) {
@ -1904,16 +1904,6 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
adjSize = frame->GetContentRect().Size();
documentIsTopLevel = PR_FALSE;
// presshell exists because parent is printable
// the top nsPrintObject's widget will always have scrollbars
if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) {
nsIView* view = frame->GetView();
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
view = view->GetFirstChild();
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
parentView = view;
canCreateScrollbars = PR_FALSE;
}
} else {
nscoord pageWidth, pageHeight;
mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
@ -1932,17 +1922,31 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
adjSize = nsSize(pageWidth, pageHeight);
#endif // XP_UNIX && !XP_MACOSX
documentIsTopLevel = PR_TRUE;
}
nsCOMPtr<nsIDocumentViewer> dv = do_QueryInterface(mDocViewerPrint);
if (dv) {
parentView = dv->FindContainerView();
}
// Here we decide whether we need scrollbars and
// what the parent will be of the widget
// How this logic presently works: Print Preview is always as-is (as far
// as I can tell; not sure how it would work in other cases); only the root
// is not eIFrame or eFrame. The child documents get a parent widget from
// logic in nsFrameFrame. In any case, a child widget is created for the root
// view of the document.
PRBool canCreateScrollbars = PR_TRUE;
nsIView* parentView = nsnull;
// the top nsPrintObject's widget will always have scrollbars
if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) {
nsIView* view = frame->GetView();
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
view = view->GetFirstChild();
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
parentView = view;
canCreateScrollbars = PR_FALSE;
}
NS_ASSERTION(!aPO->mPresContext, "Recreating prescontext");
// create the PresContext
aPO->mPresContext = new nsPresContext(aPO->mDocument,
aPO->mPresContext = new nsRootPresContext(aPO->mDocument,
mIsCreatingPrintPreview ? nsPresContext::eContext_PrintPreview:
nsPresContext::eContext_Print);
NS_ENSURE_TRUE(aPO->mPresContext, NS_ERROR_OUT_OF_MEMORY);
@ -1992,6 +1996,14 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
// unnecessary and unexpected
// Also, no widget should be needed except for the top-level document
if (mIsCreatingPrintPreview && documentIsTopLevel) {
nsNativeWidget widget = nsnull;
if (!frame)
widget = mParentWidget->GetNativeData(NS_NATIVE_WIDGET);
rv = rootView->CreateWidget(kWidgetCID, nsnull,
widget, PR_TRUE, PR_TRUE,
eContentTypeContent);
NS_ENSURE_SUCCESS(rv, rv);
aPO->mWindow = rootView->GetWidget();
aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars);
}
@ -2014,7 +2026,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI);
if (mIsCreatingPrintPreview && documentIsTopLevel) {
mDocViewerPrint->SetPrintPreviewPresentation(aPO->mViewManager,
mDocViewerPrint->SetPrintPreviewPresentation(aPO->mWindow,
aPO->mViewManager,
aPO->mPresContext,
aPO->mPresShell);
}

View File

@ -105,6 +105,7 @@ public:
nsISupports* aContainer,
nsIDocument* aDocument,
float aScreenDPI,
nsIWidget* aParentWidget,
FILE* aDebugFile);
nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount);
@ -194,6 +195,8 @@ public:
PRBool CheckBeforeDestroy();
nsresult Cancelled();
nsIWidget* GetPrintPreviewWindow() {return mPrtPreview->mPrintObject->mWindow;}
nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;}
float GetPrintPreviewScale() { return mPrtPreview->mPrintObject->
@ -288,6 +291,7 @@ protected:
nsIPageSequenceFrame* mPageSeqFrame;
// Print Preview
nsCOMPtr<nsIWidget> mParentWidget;
nsPrintData* mPrtPreview;
nsPrintData* mOldPrtPreview;

View File

@ -122,6 +122,7 @@ nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
void
nsPrintObject::DestroyPresentation()
{
mWindow = nsnull;
mPresContext = nsnull;
if (mPresShell) {
mPresShell->EndObservingDocument();

View File

@ -45,6 +45,7 @@
#include "nsIViewManager.h"
#include "nsIDocShell.h"
#include "nsIDocument.h"
#include "nsIWidget.h"
class nsPresContext;
@ -75,6 +76,7 @@ public:
nsRefPtr<nsPresContext> mPresContext;
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIViewManager> mViewManager;
nsCOMPtr<nsIWidget> mWindow;
nsCOMPtr<nsIContent> mContent;
PrintObjectType mFrameType;