From 1e648d27d648895d7debd7f0073b591dc81bb7ed Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Fri, 19 Nov 1999 07:35:27 +0000 Subject: [PATCH] moved content-specific data and methods from nsIWebShell to appropriate content viewer interface no bug number, this is for webshell redesign work r=rickg, travis git-svn-id: svn://10.0.0.236/trunk@53979 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 830 ++++++-- .../html/document/src/nsHTMLContentSink.cpp | 12 +- .../html/document/src/nsHTMLDocument.cpp | 186 +- .../xml/document/src/nsXMLDocument.cpp | 40 +- mozilla/docshell/base/makefile.win | 3 + mozilla/docshell/base/nsDocShell.cpp | 337 +--- mozilla/docshell/base/nsDocShell.h | 30 +- mozilla/docshell/base/nsDocShellBase.cpp | 1724 +++++++++++++++++ mozilla/docshell/base/nsIDocShell.idl | 51 +- mozilla/docshell/base/nsWebShell.cpp | 258 ++- mozilla/dom/src/base/nsGlobalWindow.cpp | 30 +- mozilla/editor/base/nsEditorShell.cpp | 17 +- mozilla/editor/composer/src/nsEditorShell.cpp | 17 +- mozilla/layout/base/nsDocumentViewer.cpp | 830 ++++++-- mozilla/layout/base/src/nsDocumentViewer.cpp | 830 ++++++-- mozilla/layout/base/src/nsPluginViewer.cpp | 144 +- mozilla/layout/generic/nsFrameFrame.cpp | 16 +- .../layout/html/document/src/nsFrameFrame.cpp | 16 +- .../html/document/src/nsHTMLContentSink.cpp | 12 +- .../html/document/src/nsHTMLDocument.cpp | 186 +- .../layout/xml/document/src/nsXMLDocument.cpp | 40 +- .../plugin/base/src/nsPluginViewer.cpp | 144 +- .../modules/plugin/nglsrc/nsPluginViewer.cpp | 144 +- mozilla/webshell/public/MANIFEST | 3 + mozilla/webshell/public/Makefile.in | 3 + mozilla/webshell/public/makefile.win | 3 + mozilla/webshell/public/nsIContentViewer.h | 20 - .../webshell/public/nsIContentViewerEdit.h | 81 + .../webshell/public/nsIContentViewerFile.h | 58 + .../webshell/public/nsIMarkupDocumentViewer.h | 90 + mozilla/webshell/public/nsIWebShell.h | 32 +- mozilla/webshell/src/nsWebShell.cpp | 258 ++- .../webshell/tests/viewer/nsBrowserWindow.cpp | 6 +- .../xpfe/browser/src/nsBrowserInstance.cpp | 38 +- 34 files changed, 4996 insertions(+), 1493 deletions(-) create mode 100644 mozilla/docshell/base/nsDocShellBase.cpp create mode 100644 mozilla/webshell/public/nsIContentViewerEdit.h create mode 100644 mozilla/webshell/public/nsIContentViewerFile.h create mode 100644 mozilla/webshell/public/nsIMarkupDocumentViewer.h diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 3fc6e2f19fe..47599f9427e 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -24,6 +24,8 @@ #include "nsCRT.h" #include "nsString.h" #include "nsISupports.h" +#include "nsIContent.h" +#include "nsIContentViewerContainer.h" #include "nsIDocumentViewer.h" #include "nsIImageGroup.h" @@ -54,6 +56,9 @@ #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIInterfaceRequestor.h" @@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); #endif class DocumentViewerImpl : public nsIDocumentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile, + public nsIMarkupDocumentViewer, public nsIImageGroupObserver { public: @@ -97,8 +105,6 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(void); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); @@ -110,6 +116,15 @@ public: NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + + // nsIMarkupDocumentViewer + NS_DECL_NSIMARKUPDOCUMENTVIEWER + // nsIImageGroupObserver interface... virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -166,6 +181,17 @@ protected: nsIViewManager *mPrintVM; nsIView *mPrintView; + // document management data + // these items are specific to markup documents (html and xml) + // may consider splitting these out into a subclass + PRBool mAllowPlugins; + PRPackedBool mIsFrame; + /* character set member data */ + nsString mDefaultCharacterSet; + nsString mHintCharset; + nsCharsetSource mHintCharsetSource; + nsString mForceCharacterSet; + }; // Class IDs @@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) : mPresContext(dont_QueryInterface(aPresContext)) { NS_INIT_REFCNT(); + mHintCharset = ""; + mHintCharsetSource = kCharsetUninitialized; + mForceCharacterSet = ""; + mAllowPlugins = PR_TRUE; + mIsFrame = PR_FALSE; } // ISupports implementation... @@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) { + nsIMarkupDocumentViewer* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { nsIContentViewer* tmp1 = this; nsISupports* tmp2 = tmp1; @@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void) return NS_OK; } -static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); -static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); - - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ -NS_IMETHODIMP -DocumentViewerImpl::Print(void) -{ -nsCOMPtr webContainer; -nsCOMPtr factory; -PRInt32 width,height; -nsCOMPtr prefs; - - nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, - nsnull, - kIDeviceContextSpecFactoryIID, - (void **)getter_AddRefs(factory)); - - if (factory) { - -#ifdef DEBUG_dcone - printf("PRINT JOB STARTING\n"); -#endif - - nsIDeviceContextSpec *devspec = nsnull; - nsCOMPtr dx; - mPrintDC = nsnull; - - factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); - if (nsnull != devspec) { - mPresContext->GetDeviceContext(getter_AddRefs(dx)); - nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); - if (NS_SUCCEEDED(rv)) { - - NS_RELEASE(devspec); - - // Get the webshell for this documentviewer - 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)){ - return rv; - } - - mPrintDC->GetDeviceSurfaceDimensions(width,height); - mPresContext->GetPrefs(getter_AddRefs(prefs)); - mPrintPC->Init(mPrintDC,prefs); - CreateStyleSet(mDocument,&mPrintSS); - - rv = NS_NewPresShell(&mPrintPS); - if(NS_FAILED(rv)){ - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); - if(NS_FAILED(rv)) { - return rv; - } - - rv = mPrintVM->Init(mPrintDC); - if(NS_FAILED(rv)) { - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); - if(NS_FAILED(rv)) { - return rv; - } - - nsRect tbounds = nsRect(0,0,width,height); - rv = mPrintView->Init(mPrintVM,tbounds,nsnull); - if(NS_FAILED(rv)) { - return rv; - } - - // setup hierarchical relationship in view manager - mPrintVM->SetRootView(mPrintView); - mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); - - nsCOMPtr imageGroup; - mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); - if (imageGroup) { - imageGroup->AddObserver(this); - } - - mPrintPS->InitialReflow(width,height); - -#ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; - - printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); - - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - - - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrintDC); - mPrintDC->GetDevUnitsToTwips(a1); - mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrintDC->GetAppUnitsToDevUnits(a1); - mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - -#endif - // - // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the - // InitialReflow... - // - if(!mIsPrinting){ - DocumentReadyForPrinting(); -#ifdef DEBUG_dcone - printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); -#endif - } else { - // use the observer mechanism to finish the printing -#ifdef DEBUG_dcone - printf("PRINTING OBSERVER STARTED\n"); -#endif - } - } - } - } - } - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ NS_IMETHODIMP DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) { -nsCOMPtr ss; -nsCOMPtr prefs; -nsCOMPtr vm; -PRInt32 width, height; -nsIView *view; -nsresult rv; -PRInt32 count,i; -nsIWebShell *childWebShell; -nsIContentViewer *viewer; - + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + nsCOMPtr ss; + nsCOMPtr prefs; + nsCOMPtr vm; + PRInt32 width, height; + nsIView *view; + nsresult rv; + PRInt32 count,i; + nsCOMPtr childWebShell; + nsCOMPtr viewer; aParent->GetChildCount(count); if(count> 0) { for(i=0;iChildAt(i,childWebShell); - childWebShell->GetContentViewer(&viewer); - viewer->PrintContent(childWebShell,aDContext); - NS_RELEASE(childWebShell); - NS_RELEASE(viewer); + aParent->ChildAt(i, *(getter_AddRefs(childWebShell))); + childWebShell->GetContentViewer(getter_AddRefs(viewer)); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE); + } } } else { aDContext->BeginDocument(); @@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting() // // Send the document to the printer... // - PrintContent(webContainer,mPrintDC); + nsresult rv = PrintContent(webContainer, mPrintDC); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent"); // printing is complete, clean up now mIsPrinting = PR_FALSE; @@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting() } } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP DocumentViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +DocumentViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); +static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); + + +/** --------------------------------------------------- + * See documentation above in the DocumentViewerImpl class definition + * @update 07/09/99 dwc + */ +NS_IMETHODIMP +DocumentViewerImpl::Print() +{ +nsCOMPtr webContainer; +nsCOMPtr factory; +PRInt32 width,height; +nsCOMPtr prefs; + + nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, + nsnull, + kIDeviceContextSpecFactoryIID, + (void **)getter_AddRefs(factory)); + + if (factory) { + +#ifdef DEBUG_dcone + printf("PRINT JOB STARTING\n"); +#endif + + nsIDeviceContextSpec *devspec = nsnull; + nsCOMPtr dx; + mPrintDC = nsnull; + + factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); + if (nsnull != devspec) { + mPresContext->GetDeviceContext(getter_AddRefs(dx)); + nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); + if (NS_SUCCEEDED(rv)) { + + NS_RELEASE(devspec); + + // Get the webshell for this documentviewer + 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)){ + return rv; + } + + mPrintDC->GetDeviceSurfaceDimensions(width,height); + mPresContext->GetPrefs(getter_AddRefs(prefs)); + mPrintPC->Init(mPrintDC,prefs); + CreateStyleSet(mDocument,&mPrintSS); + + rv = NS_NewPresShell(&mPrintPS); + if(NS_FAILED(rv)){ + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); + if(NS_FAILED(rv)) { + return rv; + } + + rv = mPrintVM->Init(mPrintDC); + if(NS_FAILED(rv)) { + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); + if(NS_FAILED(rv)) { + return rv; + } + + nsRect tbounds = nsRect(0,0,width,height); + rv = mPrintView->Init(mPrintVM,tbounds,nsnull); + if(NS_FAILED(rv)) { + return rv; + } + + // setup hierarchical relationship in view manager + mPrintVM->SetRootView(mPrintView); + mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); + + nsCOMPtr imageGroup; + mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); + if (imageGroup) { + imageGroup->AddObserver(this); + } + + mPrintPS->InitialReflow(width,height); + +#ifdef DEBUG_dcone + float a1,a2; + PRInt32 i1,i2; + + printf("CRITICAL PRINTING INFORMATION\n"); + printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", + mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); + + // DEVICE CONTEXT INFORMATION from PresContext + printf("DeviceContext of Presentation Context(%x)\n",dx); + dx->GetDevUnitsToTwips(a1); + dx->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + dx->GetAppUnitsToDevUnits(a1); + dx->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + dx->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + dx->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + dx->GetZoom(a1); + printf(" Zoom = %f\n",a1); + dx->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + dx->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + + + // DEVICE CONTEXT INFORMATION + printf("DeviceContext created for print(%x)\n",mPrintDC); + mPrintDC->GetDevUnitsToTwips(a1); + mPrintDC->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + mPrintDC->GetAppUnitsToDevUnits(a1); + mPrintDC->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + mPrintDC->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + mPrintDC->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + mPrintDC->GetZoom(a1); + printf(" Zoom = %f\n",a1); + mPrintDC->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + mPrintDC->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + +#endif + // + // The mIsPrinting flag is set when the ImageGroup observer is + // notified that images must be loaded as a result of the + // InitialReflow... + // + if(!mIsPrinting){ + DocumentReadyForPrinting(); +#ifdef DEBUG_dcone + printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); +#endif + } else { + // use the observer mechanism to finish the printing +#ifdef DEBUG_dcone + printf("PRINTING OBSERVER STARTED\n"); +#endif + } + } + } + } + } + return NS_OK; +} + + +NS_IMETHODIMP +DocumentViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_TRUE; + return NS_OK; +} + + +//***************************************************************************** +// nsIMarkupDocumentViewer +//***************************************************************************** + +NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) +{ + NS_ENSURE_ARG(aNode); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + + // Get the nsIContent interface, because that's what we need to + // get the primary frame + + nsCOMPtr content(do_QueryInterface(aNode)); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + + // Get the primary frame + nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their + // own special little world. + + NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), + NS_ERROR_FAILURE); + + // tell the pres shell to scroll to the frame + NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, + NS_PRESSHELL_SCROLL_TOP, + NS_PRESSHELL_SCROLL_ANYWHERE), + NS_ERROR_FAILURE); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) +{ + NS_ENSURE_ARG_POINTER(aAllowPlugins); + + *aAllowPlugins = mAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) +{ + mAllowPlugins = aAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame) +{ + NS_ENSURE_ARG_POINTER(aIsFrame); + + *aIsFrame = mIsFrame; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame) +{ + mIsFrame = aIsFrame; + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aDefaultCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); + NS_ENSURE_STATE(mContainer); + + static char *gDefCharset = nsnull; // XXX: memory leak! + + if (0 == mDefaultCharacterSet.Length()) + { + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + { + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr prefs; + NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE); + if(prefs) + prefs->CopyCharPref("intl.charset.default", &gDefCharset); + } + } + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + mDefaultCharacterSet = "ISO-8859-1"; + else + mDefaultCharacterSet = gDefCharset; + } + *aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) +{ + mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet + // now set the default char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aForceCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aForceCharacterSet); + + nsAutoString emptyStr; + if (mForceCharacterSet.Equals(emptyStr)) { + *aForceCharacterSet = nsnull; + } + else { + *aForceCharacterSet = mForceCharacterSet.ToNewUnicode(); + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) +{ + mForceCharacterSet = aForceCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetForceCharacterSet(aForceCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aHintCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSet); + + if(kCharsetUninitialized == mHintCharsetSource) { + *aHintCharacterSet = nsnull; + } else { + *aHintCharacterSet = mHintCharset.ToNewUnicode(); + // this can't possibly be right. we can't set a value just because somebody got a related value! + //mHintCharsetSource = kCharsetUninitialized; + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); + + *aHintCharacterSetSource = mHintCharsetSource; + return NS_OK; +} + + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) +{ + mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); + } + } + } + } + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) +{ + mHintCharset = aHintCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSet(aHintCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: poor error checking +NS_IMETHODIMP DocumentViewerImpl::SizeToContent() +{ + + // XXX: for now, just call the webshell's SizeToContent + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + return webShell->SizeToContent(); + } + else { + return NS_ERROR_FAILURE; + } + +#ifdef NEW_DOCSHELL_INTERFACES + + // get the presentation shell + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + nsRect shellArea; + PRInt32 width, height; + float pixelScale; + NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE), + NS_ERROR_FAILURE); + + // so how big is it? + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); + presContext->GetVisibleArea(shellArea); + presContext->GetTwipsToPixels(&pixelScale); + width = PRInt32((float)shellArea.width*pixelScale); + height = PRInt32((float)shellArea.height*pixelScale); + + // if we're the outermost webshell for this window, size the window + /* XXX: how do we do this now? + if (mContainer) + { + nsCOMPtr browser = do_QueryInterface(mContainer); + if (browser) + { + nsCOMPtr browserWebShell; + PRInt32 oldX, oldY, oldWidth, oldHeight, + widthDelta, heightDelta; + nsRect windowBounds; + + GetBounds(oldX, oldY, oldWidth, oldHeight); + widthDelta = width - oldWidth; + heightDelta = height - oldHeight; + browser->GetWindowBounds(windowBounds); + browser->SizeWindowTo(windowBounds.width + widthDelta, + windowBounds.height + heightDelta); + } + } + */ + NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; + //return NS_OK; + +#endif + +} diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 5f71ab07968..0a055c9c5a2 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -33,6 +33,7 @@ #include "nsIPresContext.h" #include "nsIViewManager.h" #include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsHTMLTokens.h" #include "nsHTMLEntities.h" #include "nsCRT.h" @@ -2694,7 +2695,16 @@ HTMLContentSink::StartLayout() } else if (mBody) { PRBool isFrameDoc = PR_FALSE; - mWebShell->GetIsFrame(isFrameDoc); + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) + { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) + { + muCV->GetIsFrame(&isFrameDoc); + } + } // a webshell will have its scrolling set by the parent nsFramesetFrame. // a webshell is reset here just for safety. if (!isFrameDoc) { diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 940649d1b31..d0dae82c3f1 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -49,6 +49,9 @@ #include "nsIIOService.h" #include "nsIURL.h" #include "nsNeckoUtil.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIWebShell.h" #include "nsIWebShellServices.h" #include "nsIDocumentLoader.h" @@ -392,7 +395,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, return rv; } - nsIWebShell* webShell; + nsCOMPtr webShell; nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error nsCharsetSource charsetSource = kCharsetFromWeakDocTypeDefault; @@ -503,7 +506,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, if (NS_OK == rv) { nsIHTMLContentSink* sink; - const PRUnichar* requestCharset = nsnull; + PRUnichar* requestCharset = nsnull; nsCharsetSource requestCharsetSource = kCharsetUninitialized; nsIParserFilter *cdetflt = nsnull; @@ -513,104 +516,123 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0); #else NS_PRECONDITION(nsnull != aContainer, "No content viewer container"); - aContainer->QueryInterface(kIWebShellIID, (void**)&webShell); + aContainer->QueryInterface(kIWebShellIID, getter_AddRefs(webShell)); rv = NS_NewHTMLContentSink(&sink, this, aURL, webShell); - if (NS_SUCCEEDED(rv)) { - if(kCharsetFromUserDefault > charsetSource) { - const PRUnichar* defaultCharsetFromWebShell = NULL; - rv = webShell->GetDefaultCharacterSet(&defaultCharsetFromWebShell); - if(NS_SUCCEEDED(rv)) { - charset = defaultCharsetFromWebShell; - charsetSource = kCharsetFromUserDefault; - } - } - // for html, we need to find out the Meta tag from the hint. - rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource); - if(NS_SUCCEEDED(rv)) { - if(requestCharsetSource > charsetSource) - { - charsetSource = requestCharsetSource; - charset = requestCharset; - } - } - if(kCharsetFromPreviousLoading > charsetSource) - { - const PRUnichar* forceCharsetFromWebShell = NULL; - rv = webShell->GetForceCharacterSet(&forceCharsetFromWebShell); - if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) { - charset = forceCharsetFromWebShell; - //TODO: we should define appropriate constant for force charset - charsetSource = kCharsetFromPreviousLoading; - } - } - nsresult rv_detect = NS_OK; - if(! gInitDetector) - { - nsIPref* pref = nsnull; - if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref) - { - - char* detector_name = nsnull; - if(NS_SUCCEEDED( + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr muCV; + nsCOMPtr cv; + webShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + muCV = do_QueryInterface(cv); + } + if(kCharsetFromUserDefault > charsetSource) + { + PRUnichar* defaultCharsetFromWebShell = NULL; + if (muCV) { + rv = muCV->GetDefaultCharacterSet(&defaultCharsetFromWebShell); + } + if(NS_SUCCEEDED(rv)) { + charset = defaultCharsetFromWebShell; + Recycle(defaultCharsetFromWebShell); + charsetSource = kCharsetFromUserDefault; + } + // for html, we need to find out the Meta tag from the hint. + if (muCV) { + rv = muCV->GetHintCharacterSet(&requestCharset); + if(NS_SUCCEEDED(rv)) { + rv = muCV->GetHintCharacterSetSource((PRInt32*)(&requestCharsetSource)); + } + } + if(NS_SUCCEEDED(rv)) + { + if(requestCharsetSource > charsetSource) + { + charsetSource = requestCharsetSource; + charset = requestCharset; + Recycle(requestCharset); + } + } + if(kCharsetFromPreviousLoading > charsetSource) + { + PRUnichar* forceCharsetFromWebShell = NULL; + if (muCV) { + rv = muCV->GetForceCharacterSet(&forceCharsetFromWebShell); + } + if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) + { + charset = forceCharsetFromWebShell; + Recycle(forceCharsetFromWebShell); + //TODO: we should define appropriate constant for force charset + charsetSource = kCharsetFromPreviousLoading; + } + } + nsresult rv_detect = NS_OK; + if(! gInitDetector) + { + nsIPref* pref = nsnull; + if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref) + { + char* detector_name = nsnull; + if(NS_SUCCEEDED( rv_detect = pref->CopyCharPref("intl.charset.detector", &detector_name))) - { - PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX); - PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX); - gPlugDetector = PR_TRUE; - PR_FREEIF(detector_name); - } - pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull); - } - NS_IF_RELEASE(pref); - gInitDetector = PR_TRUE; - } + { + PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX); + PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX); + gPlugDetector = PR_TRUE; + PR_FREEIF(detector_name); + } + pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull); + } + NS_IF_RELEASE(pref); + gInitDetector = PR_TRUE; + } - if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector) - { - // we could do charset detection - - nsICharsetDetector *cdet = nsnull; - nsIWebShellServices *wss = nsnull; - nsICharsetDetectionAdaptor *adp = nsnull; + if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector) + { + // we could do charset detection + nsICharsetDetector *cdet = nsnull; + nsIWebShellServices *wss = nsnull; + nsICharsetDetectionAdaptor *adp = nsnull; - if(NS_SUCCEEDED( rv_detect = + if(NS_SUCCEEDED( rv_detect = nsComponentManager::CreateInstance(g_detector_progid, nsnull, nsICharsetDetector::GetIID(), (void**)&cdet))) - { - - if(NS_SUCCEEDED( rv_detect = + { + if(NS_SUCCEEDED( rv_detect = nsComponentManager::CreateInstance( NS_CHARSET_DETECTION_ADAPTOR_PROGID, nsnull, kIParserFilterIID, (void**)&cdetflt))) - { - if(cdetflt && + { + if(cdetflt && NS_SUCCEEDED( rv_detect= cdetflt->QueryInterface( nsICharsetDetectionAdaptor::GetIID(),(void**) &adp))) - { - if( NS_SUCCEEDED( rv_detect= + { + if( NS_SUCCEEDED( rv_detect= webShell->QueryInterface( nsIWebShellServices::GetIID(),(void**) &wss))) - { - rv_detect = adp->Init(wss, cdet, aCommand); - } - } + { + rv_detect = adp->Init(wss, cdet, aCommand); + } } - } else { - // IF we cannot create the detector, don't bother to - // create one next time. - - gPlugDetector = PR_FALSE; - } - NS_IF_RELEASE(wss); - NS_IF_RELEASE(cdet); - NS_IF_RELEASE(adp); - // NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter - } + } + } + else + { + // IF we cannot create the detector, don't bother to + // create one next time. + gPlugDetector = PR_FALSE; + } + NS_IF_RELEASE(wss); + NS_IF_RELEASE(cdet); + NS_IF_RELEASE(adp); + // NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter + } + } } - NS_IF_RELEASE(webShell); #endif if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index c633af515bb..670e693c612 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -29,7 +29,10 @@ #include "nsIXMLContentSink.h" #include "nsIPresShell.h" #include "nsIPresContext.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" #include "nsIWebShell.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIDocumentLoader.h" #include "nsIHTMLContent.h" #include "nsHTMLParts.h" @@ -263,20 +266,31 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, rv = aContainer->QueryInterface(kIWebShellIID, (void**)&webShell); if(NS_SUCCEEDED(rv) && (nsnull != webShell)) { - if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source - const PRUnichar* hintCharset = nsnull; - nsCharsetSource hintSource = kCharsetUninitialized; - rv = webShell->GetCharacterSetHint(&hintCharset, &hintSource); - if(NS_SUCCEEDED(rv)) { - if(hintSource > charsetSource) { - charset = hintCharset; - charsetSource = hintSource; + nsCOMPtr cv; + webShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) { + if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source + PRUnichar* hintCharset = nsnull; + nsCharsetSource hintSource = kCharsetUninitialized; + rv = muCV->GetHintCharacterSet(&hintCharset); + if(NS_SUCCEEDED(rv)) { + rv = muCV->GetHintCharacterSetSource((PRInt32 *)(&hintSource)); + if(NS_SUCCEEDED(rv)) { + if(hintSource > charsetSource) { + charset = hintCharset; + Recycle(hintCharset); + charsetSource = hintSource; + } } - } - } - if(NS_SUCCEEDED(rv)) - rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell); - NS_IF_RELEASE(webShell); + } + } + } + } + if(NS_SUCCEEDED(rv)) + rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell); + NS_IF_RELEASE(webShell); } if (NS_OK == rv) { diff --git a/mozilla/docshell/base/makefile.win b/mozilla/docshell/base/makefile.win index a6974f7b661..ed03540bb37 100644 --- a/mozilla/docshell/base/makefile.win +++ b/mozilla/docshell/base/makefile.win @@ -28,6 +28,9 @@ XPIDLSRCS= \ .\nsIDocShellContainer.idl \ .\nsIDocShellFile.idl \ .\nsIDocShellEdit.idl \ + .\nsIContentViewerEdit.idl \ + .\nsIContentViewerFile.idl \ + .\nsIMarkupDocumentViewer.idl \ .\nsIScrollable.idl \ .\nsITextScroll.idl \ $(NULL) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 7166d7a6761..d7c634a317e 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -34,7 +34,7 @@ #include "nsRect.h" #include "prprf.h" #include "nsIFrame.h" -#include "nsIContent.h" +#include "nsIMarkupDocumentViewer.h" #ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging #define WEB_TRACE(_bit,_args) \ @@ -54,11 +54,11 @@ //*** nsDocShell: Object Management //***************************************************************************** -nsDocShell::nsDocShell() : mCreated(PR_FALSE), mContentListener(nsnull), - //XXX Remove HTML Specific ones - mAllowPlugins(PR_TRUE), mMarginWidth(0), mMarginHeight(0), - mIsFrame(PR_FALSE) - +nsDocShell::nsDocShell() : + mCreated(PR_FALSE), + mContentListener(nsnull), + mMarginWidth(0), + mMarginHeight(0) { NS_INIT_REFCNT(); } @@ -103,9 +103,6 @@ NS_IMPL_RELEASE(nsDocShell) NS_IMPL_QUERY_HEAD(nsDocShell) NS_IMPL_QUERY_BODY(nsIDocShell) - NS_IMPL_QUERY_BODY(nsIHTMLDocShell) - NS_IMPL_QUERY_BODY(nsIDocShellEdit) - NS_IMPL_QUERY_BODY(nsIDocShellFile) NS_IMPL_QUERY_BODY(nsIBaseWindow) NS_IMPL_QUERY_BODY(nsIScrollable) NS_IMPL_QUERY_BODY(nsITextScroll) @@ -459,6 +456,42 @@ nsDocShell::SetDocLoaderObserver(nsIDocumentLoaderObserver * aDocLoaderObserver) return NS_OK; } +NS_IMETHODIMP +nsDocShell::GetMarginWidth(PRInt32* aWidth) +{ + NS_ENSURE_ARG_POINTER(aWidth); + + *aWidth = mMarginWidth; + return NS_OK; +} + +NS_IMETHODIMP +nsDocShell::SetMarginWidth(PRInt32 aWidth) +{ + mMarginWidth = aWidth; + return NS_OK; +} + +NS_IMETHODIMP +nsDocShell::GetMarginHeight(PRInt32* aHeight) +{ + NS_ENSURE_ARG_POINTER(aHeight); + + *aHeight = mMarginHeight; + return NS_OK; +} + +NS_IMETHODIMP +nsDocShell::SetMarginHeight(PRInt32 aHeight) +{ + mMarginHeight = aHeight; + return NS_OK; +} + + + +// the following code is to be removed. It will show up on content viewer classes +#if 0 //***************************************************************************** // nsDocShell::nsIDocShellEdit //***************************************************************************** @@ -686,6 +719,7 @@ NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable) *printable = PR_FALSE; return NS_OK; } +#endif //***************************************************************************** // nsDocShell::nsIDocShellContainer @@ -700,26 +734,38 @@ NS_IMETHODIMP nsDocShell::GetChildCount(PRInt32 *aChildCount) NS_IMETHODIMP nsDocShell::AddChild(nsIDocShell *aChild) { - NS_ENSURE_ARG_POINTER(aChild); + NS_ENSURE_ARG_POINTER(aChild); - NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); - mChildren.AppendElement(aChild); - NS_ADDREF(aChild); + NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); + mChildren.AppendElement(aChild); + NS_ADDREF(aChild); - //XXX HTML Specifics need to be moved out. - nsCOMPtr childAsHTMLDocShell = do_QueryInterface(aChild); - if (childAsHTMLDocShell) + PRUnichar *defaultCharset=nsnull; + PRUnichar *forceCharset=nsnull; + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); + } + nsCOMPtr childCV; + NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE); + if (childCV) + { + nsCOMPtr childmuDV = do_QueryInterface(cv); + if (childmuDV) { - PRUnichar *defaultCharset=nsnull; - NS_ENSURE_SUCCESS(GetDefaultCharacterSet(&defaultCharset), - NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetDefaultCharacterSet( - defaultCharset), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetForceCharacterSet( - mForceCharacterSet.GetUnicode()), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(childmuDV->SetDefaultCharacterSet(defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(childmuDV->SetForceCharacterSet(forceCharset), NS_ERROR_FAILURE); } + } + } - return NS_OK; + return NS_OK; } // tiny semantic change from webshell. aChild is only effected if it was actually a child of this docshell @@ -730,7 +776,7 @@ NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShell *aChild) PRBool childRemoved = mChildren.RemoveElement(aChild); if (PR_TRUE==childRemoved) { - aChild->SetParent(nsnull); + NS_ENSURE_SUCCESS(aChild->SetParent(nsnull), NS_ERROR_FAILURE); NS_RELEASE(aChild); } return NS_OK; @@ -1320,246 +1366,6 @@ NS_IMETHODIMP nsDocShell::ScrollByPages(PRInt32 numPages) return NS_OK; } -//***************************************************************************** -// nsDocShell::nsIHTMLDocShell -//***************************************************************************** - -NS_IMETHODIMP nsDocShell::ScrollToNode(nsIDOMNode* aNode) -{ - NS_ENSURE_ARG(aNode); - NS_ENSURE_STATE(mContentViewer); - nsCOMPtr presShell; - NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); - - // Get the nsIContent interface, because that's what we need to - // get the primary frame - - nsCOMPtr content(do_QueryInterface(aNode)); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - - // Get the primary frame - nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their - // own special little world. - - NS_ENSURE_SUCCESS(GetPrimaryFrameFor(content, &frame), - NS_ERROR_FAILURE); - - // tell the pres shell to scroll to the frame - NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, - NS_PRESSHELL_SCROLL_TOP, NS_PRESSHELL_SCROLL_ANYWHERE), NS_ERROR_FAILURE); - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::GetAllowPlugins(PRBool* aAllowPlugins) -{ - NS_ENSURE_ARG_POINTER(aAllowPlugins); - - *aAllowPlugins = mAllowPlugins; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetAllowPlugins(PRBool aAllowPlugins) -{ - mAllowPlugins = aAllowPlugins; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::GetMarginWidth(PRInt32* aMarginWidth) -{ - NS_ENSURE_ARG_POINTER(aMarginWidth); - - *aMarginWidth = mMarginWidth; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetMarginWidth(PRInt32 aMarginWidth) -{ - mMarginWidth = aMarginWidth; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::GetMarginHeight(PRInt32* aMarginHeight) -{ - NS_ENSURE_ARG_POINTER(aMarginHeight); - - *aMarginHeight = mMarginHeight; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetMarginHeight(PRInt32 aMarginHeight) -{ - mMarginHeight = aMarginHeight; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::GetIsFrame(PRBool* aIsFrame) -{ - NS_ENSURE_ARG_POINTER(aIsFrame); - - *aIsFrame = mIsFrame; - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetIsFrame(PRBool aIsFrame) -{ - mIsFrame = aIsFrame; - return NS_OK; -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aDefaultCharacterSet) -NS_IMETHODIMP nsDocShell::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); - - static char *gDefCharset = nsnull; // XXX: memory leak! - - if (0 == mDefaultCharacterSet.Length()) - { - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - { - if(mPrefs) - mPrefs->CopyCharPref("intl.charset.default", &gDefCharset); - } - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - mDefaultCharacterSet = "ISO-8859-1"; - else - mDefaultCharacterSet = gDefCharset; - } - *aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode(); - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) -{ - mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) - { - nsIDocShell* child = (nsIDocShell*) mChildren.ElementAt(i); - NS_WARN_IF_FALSE(child, "null child in docshell"); - if (child) - { - nsCOMPtr childAsHTMLDocShell = do_QueryInterface(child); - if (childAsHTMLDocShell) { - childAsHTMLDocShell->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - } - return NS_OK; -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aForceCharacterSet) -NS_IMETHODIMP nsDocShell::GetForceCharacterSet(PRUnichar** aForceCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aForceCharacterSet); - - nsAutoString emptyStr; - if (mForceCharacterSet.Equals(emptyStr)) { - *aForceCharacterSet = nsnull; - } - else { - *aForceCharacterSet = mForceCharacterSet.ToNewUnicode(); - } - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) -{ - mForceCharacterSet = aForceCharacterSet; - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - nsIDocShell* child = (nsIDocShell*) mChildren.ElementAt(i); - NS_WARN_IF_FALSE(child, "null child in docshell"); - if (child) - { - nsCOMPtr childAsHTMLDocShell = do_QueryInterface(child); - if (childAsHTMLDocShell) { - childAsHTMLDocShell->SetForceCharacterSet(aForceCharacterSet); - } - } - } - return NS_OK; -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aHintCharacterSet) -NS_IMETHODIMP nsDocShell::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aHintCharacterSet); - - if(kCharsetUninitialized == mHintCharsetSource) { - *aHintCharacterSet = nsnull; - } else { - *aHintCharacterSet = mHintCharset.ToNewUnicode(); - mHintCharsetSource = kCharsetUninitialized; - } - return NS_OK; -} - -NS_IMETHODIMP nsDocShell::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) -{ - NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); - - *aHintCharacterSetSource = mHintCharsetSource; - return NS_OK; -} - -// XXX: poor error checking -NS_IMETHODIMP nsDocShell::SizeToContent() -{ - - // get the presentation shell - nsCOMPtr presShell; - NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - - nsRect shellArea; - PRInt32 width, height; - float pixelScale; - NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE), - NS_ERROR_FAILURE); - - // so how big is it? - nsCOMPtr presContext; - NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), - NS_ERROR_FAILURE); - NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - presContext->GetVisibleArea(shellArea); - presContext->GetTwipsToPixels(&pixelScale); - width = PRInt32((float)shellArea.width*pixelScale); - height = PRInt32((float)shellArea.height*pixelScale); - - // if we're the outermost webshell for this window, size the window - /* XXX: how do we do this now? - if (mContainer) - { - nsCOMPtr browser = do_QueryInterface(mContainer); - if (browser) - { - nsCOMPtr browserWebShell; - PRInt32 oldX, oldY, oldWidth, oldHeight, - widthDelta, heightDelta; - nsRect windowBounds; - - GetBounds(oldX, oldY, oldWidth, oldHeight); - widthDelta = width - oldWidth; - heightDelta = height - oldHeight; - browser->GetWindowBounds(windowBounds); - browser->SizeWindowTo(windowBounds.width + widthDelta, - windowBounds.height + heightDelta); - } - } - */ - NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; - //return NS_OK; -} - //***************************************************************************** // nsDocShell::nsIContentViewerContainer //***************************************************************************** @@ -2007,3 +1813,4 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& anIID, void** aSink) { return QueryInterface(anIID, aSink); } + diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index b8a96a0229d..51f8676a526 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -59,14 +59,11 @@ public: }; class nsDocShell : public nsIDocShell, - public nsIDocShellEdit, - public nsIDocShellFile, - public nsIDocShellContainer, - public nsIBaseWindow, - public nsIScrollable, - public nsITextScroll, - public nsIContentViewerContainer, - public nsIHTMLDocShell + public nsIDocShellContainer, + public nsIBaseWindow, + public nsIScrollable, + public nsITextScroll, + public nsIContentViewerContainer { friend class nsDSURIContentListener; @@ -74,13 +71,10 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIDOCSHELL - NS_DECL_NSIDOCSHELLEDIT - NS_DECL_NSIDOCSHELLFILE NS_DECL_NSIDOCSHELLCONTAINER NS_DECL_NSIBASEWINDOW NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL - NS_DECL_NSIHTMLDOCSHELL NS_DECL_NSIINTERFACEREQUESTOR // XXX: move to a macro @@ -145,6 +139,8 @@ protected: nsCOMPtr mScriptGlobal; nsCOMPtr mScriptContext; nsCOMPtr mLoadCookie; + PRInt32 mMarginWidth; + PRInt32 mMarginHeight; /* Note this can not be nsCOMPtr as that that would cause an addref on the parent thus a cycle. A weak reference would work, but not required as the @@ -152,18 +148,6 @@ protected: releasing the interface.*/ nsIDocShell* mParent; - /* - XXX HTML Specific stuff - */ - PRBool mAllowPlugins; - PRInt32 mMarginWidth; - PRInt32 mMarginHeight; - PRBool mIsFrame; - /* character set member data */ - nsString mDefaultCharacterSet; - nsString mHintCharset; - nsCharsetSource mHintCharsetSource; - nsString mForceCharacterSet; }; #endif /* nsDocShell_h__ */ diff --git a/mozilla/docshell/base/nsDocShellBase.cpp b/mozilla/docshell/base/nsDocShellBase.cpp new file mode 100644 index 00000000000..e498a389124 --- /dev/null +++ b/mozilla/docshell/base/nsDocShellBase.cpp @@ -0,0 +1,1724 @@ +/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + */ + +#include "nsDocShellBase.h" +#include "nsIComponentManager.h" +#include "nsIContent.h" +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" +#include "nsIDocumentViewer.h" +#include "nsIDeviceContext.h" +#include "nsCURILoader.h" +#include "nsLayoutCID.h" +#include "nsNeckoUtil.h" +#include "nsRect.h" + +#ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging +#define WEB_TRACE(_bit,_args) \ + PR_BEGIN_MACRO \ + if (WEB_LOG_TEST(gLogModule,_bit)) { \ + PR_LogPrint _args; \ + } \ + PR_END_MACRO +#else +#define WEB_TRACE(_bit,_args) +#endif + + + + +//***************************************************************************** +//*** nsDocShellBase: Object Management +//***************************************************************************** + +nsDocShellBase::nsDocShellBase() : mCreated(PR_FALSE), mContentListener(nsnull) +{ + NS_INIT_REFCNT(); + mBaseInitInfo = new nsDocShellInitInfo(); +} + +nsDocShellBase::~nsDocShellBase() +{ + if(mBaseInitInfo) + { + delete mBaseInitInfo; + mBaseInitInfo = nsnull; + } + + if(mContentListener) + { + mContentListener->Release(); + mContentListener = nsnull; + } +} + +//***************************************************************************** +// nsDocShellBase::nsISupports +//***************************************************************************** + +NS_IMPL_ISUPPORTS6(nsDocShellBase, nsIDocShell, nsIDocShellEdit, + nsIDocShellFile, nsIGenericWindow, nsIScrollable, nsITextScroll) + +//***************************************************************************** +// nsDocShellBase::nsIDocShell +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::LoadURI(nsIURI* aUri, + nsIPresContext* presContext) +{ + //NS_ENSURE_ARG(aUri); // Done in LoadURIVia for us. + + return LoadURIVia(aUri, presContext, 0); +} + +NS_IMETHODIMP nsDocShellBase::LoadURIVia(nsIURI* aUri, + nsIPresContext* aPresContext, PRUint32 aAdapterBinding) +{ + NS_ENSURE_ARG(aUri); + + nsCOMPtr uriLoader = do_CreateInstance(NS_URI_LOADER_PROGID); + NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE); + mContentListener->SetPresContext(aPresContext); + + NS_ENSURE_SUCCESS(uriLoader->OpenURI(aUri, nsnull, nsnull, mContentListener, + nsnull, nsnull, getter_AddRefs(mLoadCookie)), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetDocument(nsIDOMDocument** aDocument) +{ + NS_ENSURE_ARG_POINTER(aDocument); + NS_ENSURE_STATE(mContentViewer); + + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); + + nsCOMPtrdoc; + NS_ENSURE_SUCCESS(presShell->GetDocument(getter_AddRefs(doc)), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER); + + // the result's addref comes from this QueryInterface call + NS_ENSURE_SUCCESS(CallQueryInterface(doc, aDocument), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetCurrentURI(nsIURI** aURI) +{ + NS_ENSURE_ARG_POINTER(aURI); + + *aURI = mCurrentURI; + NS_IF_ADDREF(*aURI); + + return NS_OK; +} + +// SetDocument is only meaningful for doc shells that support DOM documents. Not all do. +NS_IMETHODIMP +nsDocShellBase::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode) +{ + + // The tricky part is bypassing the normal load process and just putting a document into + // the webshell. This is particularly nasty, since webshells don't normally even know + // about their documents + + // (1) Create a document viewer + nsCOMPtr documentViewer; + nsCOMPtr docFactory; + static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); + NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull, + nsIDocumentLoaderFactory::GetIID(), + (void**)getter_AddRefs(docFactory)), + NS_ERROR_FAILURE); + + nsCOMPtr doc = do_QueryInterface(aDOMDoc); + if (!doc) { return NS_ERROR_NULL_POINTER; } + NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(this, + doc, + "view", + getter_AddRefs(documentViewer)), + NS_ERROR_FAILURE); + + // (2) Feed the docshell to the content viewer + NS_ENSURE_SUCCESS(documentViewer->SetContainer(this), NS_ERROR_FAILURE); + + // (3) Tell the content viewer container to embed the content viewer. + // (This step causes everything to be set up for an initial flow.) + NS_ENSURE_SUCCESS(Embed(documentViewer, "view", nsnull), NS_ERROR_FAILURE); + + // XXX: It would be great to get rid of this dummy channel! + const nsAutoString uriString = "about:blank"; + nsCOMPtr uri; + NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), uriString), NS_ERROR_FAILURE); + if (!uri) { return NS_ERROR_OUT_OF_MEMORY; } + + nsCOMPtr dummyChannel; + NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE); + + // (4) fire start document load notification + nsIStreamListener* outStreamListener=nsnull; // a valid pointer is required for the returned stream listener + NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view", dummyChannel, nsnull, this, &outStreamListener), + NS_ERROR_FAILURE); + NS_IF_RELEASE(outStreamListener); + NS_ENSURE_SUCCESS(FireStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE); + + // (5) hook up the document and its content + nsCOMPtr rootContent = do_QueryInterface(aRootNode); + if (!doc) { return NS_ERROR_OUT_OF_MEMORY; } + NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE); + doc->SetRootContent(rootContent); + + // (6) reflow the document + + /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + this is wrong, evil, bad. docshell shouldn't know anything about any of this stuff + this should all be the responsibility of the content viewer. + */ + + //XXX: SetScrolling doesn't make any sense + //SetScrolling(-1, PR_FALSE); + PRInt32 i; + PRInt32 ns = doc->GetNumberOfShells(); + for (i = 0; i < ns; i++) + { + nsCOMPtr shell(dont_AddRef(doc->GetShellAt(i))); + if (shell) + { + // Make shell an observer for next time + NS_ENSURE_SUCCESS(shell->BeginObservingDocument(), NS_ERROR_FAILURE); + + // Resize-reflow this time + nsCOMPtr docViewer = do_QueryInterface(documentViewer); + if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; } + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); + if (!presContext) { return NS_ERROR_OUT_OF_MEMORY; } + float p2t; + presContext->GetScaledPixelsToTwips(&p2t); + + nsRect r; + NS_ENSURE_SUCCESS(GetPosition(&r.x, &r.y), NS_ERROR_FAILURE);; + NS_ENSURE_SUCCESS(GetSize(&r.width, &r.height), NS_ERROR_FAILURE);; + NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE); + + // Now trigger a refresh + nsCOMPtr vm; + NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE); + if (vm) + { + PRBool enabled; + documentViewer->GetEnableRendering(&enabled); + if (enabled) { + vm->EnableRefresh(); + } + NS_ENSURE_SUCCESS(vm->SetWindowDimensions(NSToCoordRound(r.width * p2t), + NSToCoordRound(r.height * p2t)), + NS_ERROR_FAILURE); + } + } + } + + // (7) fire end document load notification + nsresult rv = NS_OK; + nsCOMPtr dlObserver; + // XXX: this was just "this", and webshell container relied on getting a webshell + // through this interface. No one else uses it anywhere afaict + //if (!dlObserver) { return NS_ERROR_NO_INTERFACE; } + NS_ENSURE_SUCCESS(FireEndDocumentLoad(mDocLoader, dummyChannel, rv, dlObserver), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately + + return NS_OK; +} + + + +// caller is responsible for calling nsString::Recycle(*aName); +NS_IMETHODIMP nsDocShellBase::GetName(PRUnichar** aName) +{ + NS_ENSURE_ARG_POINTER(aName); + *aName = nsnull; + if(0 != mName.Length()) + *aName = mName.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetName(const PRUnichar* aName) +{ + if (aName) { + mName = aName; // this does a copy of aName + } + else { + mName = ""; + } + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetPresContext(nsIPresContext** aPresContext) +{ + NS_ENSURE_ARG_POINTER(aPresContext); + + if(!mContentViewer) + { + *aPresContext = nsnull; + return NS_OK; + } + + nsCOMPtr docv(do_QueryInterface(mContentViewer)); + NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(docv->GetPresContext(*aPresContext), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetParent(nsIDocShell** parent) +{ + NS_ENSURE_ARG_POINTER(parent); + + *parent = mParent; + NS_IF_ADDREF(*parent); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetParent(nsIDocShell* aParent) +{ + // null aParent is ok + /* + Note this doesn't do an addref on purpose. This is because the parent + is an implied lifetime. We don't want to create a cycle by refcounting + the parent. + */ + mParent = aParent; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetParentURIContentListener(nsIURIContentListener** + aParent) +{ + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE); + + mContentListener->GetParentContentListener(aParent); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetParentURIContentListener(nsIURIContentListener* + aParent) +{ + NS_ENSURE_SUCCESS(EnsureContentListener(), NS_ERROR_FAILURE); + + mContentListener->SetParentContentListener(aParent); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::CanHandleContentType(const PRUnichar* contentType, + PRBool* canHandle) +{ + NS_ENSURE_ARG_POINTER(canHandle); + + NS_WARN_IF_FALSE(PR_FALSE, "Subclasses should override this method!!!!"); + + *canHandle = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetPrefs(nsIPref** aPrefs) +{ + NS_ENSURE_ARG_POINTER(aPrefs); + + *aPrefs = mPrefs; + NS_IF_ADDREF(*aPrefs); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetPrefs(nsIPref* aPrefs) +{ + // null aPrefs is ok + mPrefs = aPrefs; // this assignment does an addref + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetRootDocShell(nsIDocShell** aRootDocShell) +{ + NS_ENSURE_ARG_POINTER(aRootDocShell); + *aRootDocShell = this; + + nsCOMPtr parent; + NS_ENSURE_TRUE(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + while (parent) + { + *aRootDocShell = parent; + NS_ENSURE_TRUE(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + } + NS_IF_ADDREF(*aRootDocShell); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetZoom(float* zoom) +{ + NS_ENSURE_ARG_POINTER(zoom); + NS_ENSURE_STATE(mContentViewer); + + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), + NS_ERROR_FAILURE); + + nsCOMPtr deviceContext; + NS_ENSURE_SUCCESS(presContext->GetDeviceContext(getter_AddRefs(deviceContext)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(deviceContext->GetZoom(*zoom), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetZoom(float zoom) +{ + NS_ENSURE_STATE(mContentViewer); + + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), + NS_ERROR_FAILURE); + + nsCOMPtr deviceContext; + NS_ENSURE_SUCCESS(presContext->GetDeviceContext(getter_AddRefs(deviceContext)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(deviceContext->SetZoom(zoom), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP +nsDocShellBase::GetDocLoaderObserver(nsIDocumentLoaderObserver * *aDocLoaderObserver) +{ + NS_ENSURE_ARG_POINTER(aDocLoaderObserver); + + *aDocLoaderObserver = mDocLoaderObserver; + NS_IF_ADDREF(*aDocLoaderObserver); + return NS_OK; +} + +NS_IMETHODIMP +nsDocShellBase::SetDocLoaderObserver(nsIDocumentLoaderObserver * aDocLoaderObserver) +{ + // it's legal for aDocLoaderObserver to be null. + mDocLoaderObserver = aDocLoaderObserver; + return NS_OK; +} + +//***************************************************************************** +// nsDocShellBase::nsIDocShellEdit +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::Search() +{ + NS_WARN_IF_FALSE(PR_FALSE, "Subclasses should override this method!!!!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsDocShellBase::GetSearchable(PRBool* aSearchable) +{ + NS_ENSURE_ARG_POINTER(aSearchable); + *aSearchable = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::ClearSelection() +{ + NS_ENSURE_STATE(mContentViewer); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); + + nsCOMPtr selection; + NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL, + getter_AddRefs(selection)), NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(selection->ClearSelection(), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SelectAll() +{ + NS_WARN_IF_FALSE(PR_FALSE, "Subclasses should override this method!!!!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsDocShellBase::CopySelection() +{ + NS_ENSURE_STATE(mContentViewer); + PRBool copyable; + NS_ENSURE_SUCCESS(GetCopyable(©able), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(copyable, NS_ERROR_UNEXPECTED); + + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); + + // the pres shell knows how to copy, so let it do the work + NS_ENSURE_SUCCESS(presShell->DoCopy(), NS_ERROR_FAILURE); + return NS_OK; +} + +/* the docShell is "copyable" if it has a selection and the selection is not + * collapsed (that is, at least one token is selected, a character or a node + */ +NS_IMETHODIMP nsDocShellBase::GetCopyable(PRBool *aCopyable) +{ + NS_ENSURE_ARG_POINTER(aCopyable); + NS_ENSURE_STATE(mContentViewer); + + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); + + nsCOMPtr selection; + NS_ENSURE_SUCCESS(presShell->GetSelection(SELECTION_NORMAL, + getter_AddRefs(selection)), NS_ERROR_FAILURE); + + if(!selection) + { + *aCopyable = PR_FALSE; + return NS_OK; + } + + PRBool isCollapsed; + NS_ENSURE_SUCCESS(selection->GetIsCollapsed(&isCollapsed), NS_ERROR_FAILURE); + *aCopyable = !isCollapsed; + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::CutSelection() +{ + NS_ENSURE_STATE(mContentViewer); + PRBool cutable; + NS_ENSURE_SUCCESS(GetCutable(&cutable), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(cutable, NS_ERROR_UNEXPECTED); + + + + //XXX Implement + //Should check to find the current focused object. Then cut the contents. + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetCutable(PRBool* aCutable) +{ + NS_ENSURE_ARG_POINTER(aCutable); + //XXX Implement + //Should check to find the current focused object. Then see if it can + //be cut out of. For now the answer is always no since CutSelection() + // has not been implemented. + *aCutable = PR_FALSE; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::Paste() +{ + NS_ENSURE_STATE(mContentViewer); + PRBool pasteable; + NS_ENSURE_SUCCESS(GetPasteable(&pasteable), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(pasteable, NS_ERROR_UNEXPECTED); + + //XXX Implement + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetPasteable(PRBool* aPasteable) +{ + NS_ENSURE_ARG_POINTER(aPasteable); + + //XXX Implement + //Should check to find the current focused object. Then see if it can + //be pasted into. For now the answer is always no since Paste() + // has not been implemented. + *aPasteable = PR_FALSE; + return NS_OK; +} + +//***************************************************************************** +// nsDocShellBase::nsIDocShellFile +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::Save() +{ + NS_ENSURE_STATE(mContentViewer); + PRBool saveable; + NS_ENSURE_SUCCESS(GetSaveable(&saveable), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(saveable, NS_ERROR_UNEXPECTED); + + //XXX First Check + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetSaveable(PRBool* saveable) +{ + NS_ENSURE_ARG_POINTER(saveable); + //XXX First Check + // XXX Implement + // Should check if a doc is loaded and if it is in a state that that is + // ready to save. For now the answer is always no since saving isn't + // implemented. + + *saveable = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::Print() +{ + NS_ENSURE_STATE(mContentViewer); + PRBool printable; + NS_ENSURE_SUCCESS(GetPrintable(&printable), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(printable, NS_ERROR_UNEXPECTED); + + //XXX First Check + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetPrintable(PRBool* printable) +{ + NS_ENSURE_ARG_POINTER(printable); + // XXX Implement + // Should check if a doc is loaded and if it is in a state that that is + // ready to print. For now the answer is always no since printing isn't + // implemented. + + *printable = PR_FALSE; + return NS_OK; +} + + + +//***************************************************************************** +// nsDocShellBase::nsIDocShellContainer +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::GetChildCount(PRInt32 *aChildCount) +{ + NS_ENSURE_ARG_POINTER(aChildCount); + *aChildCount = mChildren.Count(); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::AddChild(nsIDocShell *aChild) +{ + NS_ENSURE_ARG_POINTER(aChild); + + NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); + mChildren.AppendElement(aChild); + NS_ADDREF(aChild); + return NS_OK; +} + +// XXX: tiny semantic change from webshell. aChild is only effected if it was actually a child of this docshell +NS_IMETHODIMP nsDocShellBase::RemoveChild(nsIDocShell *aChild) +{ + NS_ENSURE_ARG_POINTER(aChild); + + PRBool childRemoved = mChildren.RemoveElement(aChild); + if (PR_TRUE==childRemoved) + { + aChild->SetParent(nsnull); + NS_RELEASE(aChild); + } + return NS_OK; +} + +/* readonly attribute nsIEnumerator childEnumerator; */ +NS_IMETHODIMP nsDocShellBase::GetChildEnumerator(nsIEnumerator * *aChildEnumerator) +{ + NS_ENSURE_ARG_POINTER(aChildEnumerator); + + return NS_OK; +} + +/* depth-first search for a child shell with aName */ +NS_IMETHODIMP nsDocShellBase::FindChildWithName(const PRUnichar *aName, nsIDocShell **_retval) +{ + NS_ENSURE_ARG_POINTER(aName); + NS_ENSURE_ARG_POINTER(_retval); + + *_retval = nsnull; // if we don't find one, we return NS_OK and a null result + nsAutoString name(aName); + PRUnichar *childName; + PRInt32 i, n = mChildren.Count(); + for (i = 0; i < n; i++) + { + nsIDocShell* child = (nsIDocShell*) mChildren.ElementAt(i); // doesn't addref the result + if (nsnull != child) { + child->GetName(&childName); + if (name.Equals(childName)) { + *_retval = child; + NS_ADDREF(child); + break; + } + + // See if child contains the shell with the given name + nsCOMPtr childAsContainer = do_QueryInterface(child); + if (child) + { + NS_ENSURE_SUCCESS(childAsContainer->FindChildWithName(name.GetUnicode(), _retval), NS_ERROR_FAILURE); + } + if (_retval) { // found it + break; + } + } + } + return NS_OK; +} + + +//***************************************************************************** +// nsDocShellBase::nsIGenericWindow +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::InitWindow(nativeWindow parentNativeWindow, + nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) +{ + NS_ENSURE_ARG(parentWidget); // DocShells must get a widget for a parent + NS_ENSURE_STATE(!mCreated && mBaseInitInfo); + + mParentWidget = parentWidget; + mBaseInitInfo->x = x; + mBaseInitInfo->y = y; + mBaseInitInfo->cx = cx; + mBaseInitInfo->cy = cy; + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::Create() +{ + NS_ENSURE_STATE(!mCreated); + + // Use mBaseInitInfo to do create + // Then delete mBaseInitInfo + //XXX First Check + /* + Tells the window that intialization and setup is complete. When this is + called the window can actually create itself based on the setup + information handed to it. + */ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::Destroy() +{ + // We don't support the dynamic destroy and recreate on the object. Just + // create a new object! + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsDocShellBase::SetPosition(PRInt32 x, PRInt32 y) +{ + if(!mCreated) + { + mBaseInitInfo->x = x; + mBaseInitInfo->y = y; + } + else + { + /* XXX Implement below is code from old webShell + We don't have a heavy-weight window, we want to talk to our view I think. + We also don't want to duplicate the bounds locally. No need, let the + view keep up with that. + + PRInt32 w, h; + nsresult rv = GetSize(w, h); + if (NS_FAILED(rv)) { return rv; } + + PRInt32 borderWidth = 0; + PRInt32 borderHeight = 0; + if (mWindow) + { + mWindow->GetBorderSize(borderWidth, borderHeight); + // Don't have the widget repaint. Layout will generate repaint requests + // during reflow + mWindow->Resize(aX, aY, w, h, PR_FALSE); + } + + mBounds.SetRect(aX,aY,w,h); // set the webshells bounds + + return rv; + */ + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetPosition(PRInt32* x, PRInt32* y) +{ + NS_ENSURE_ARG_POINTER(x && y); + + if(!mCreated) + { + *x = mBaseInitInfo->x; + *y = mBaseInitInfo->y; + } + else + { + /* XXX Implement below is code from old webShell + We don't have a heavy-weight window, we want to talk to our view I think. + We also don't want to duplicate the bounds locally. No need, let the + view keep up with that. + + nsRect result; + if (nsnull != mWindow) { + mWindow->GetClientBounds(result); + } else { + result = mBounds; + } + + *aX = result.x; + *aY = result.y; + + return NS_OK; + */ + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint) +{ + if(!mCreated) + { + mBaseInitInfo->cx = cx; + mBaseInitInfo->cy = cy; + } + else + { + /* XXX Implement below is code from old webShell + We don't have a heavy-weight window, we want to talk to our view I think. + We also don't want to duplicate the bounds locally. No need, let the + view keep up with that. + + + PRInt32 x, y; + nsresult rv = GetPosition(x, y); + if (NS_FAILED(rv)) { return rv; } + + PRInt32 borderWidth = 0; + PRInt32 borderHeight = 0; + if (mWindow) + { + mWindow->GetBorderSize(borderWidth, borderHeight); + // Don't have the widget repaint. Layout will generate repaint requests + // during reflow + mWindow->Resize(x, y, aCX, aCY, PR_FALSE); + } + + mBounds.SetRect(x, y, aCX, aCY); // set the webshells bounds --dwc0001 + + // Set the size of the content area, which is the size of the window + // minus the borders + if (nsnull != mContentViewer) { + nsRect rr(0, 0, aCX-(borderWidth*2), aCY-(borderHeight*2)); + mContentViewer->SetBounds(rr); + } + return rv; + */ + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetSize(PRInt32* cx, PRInt32* cy) +{ + NS_ENSURE_ARG_POINTER(cx && cy); + + if(!mCreated) + { + *cx = mBaseInitInfo->cx; + *cy = mBaseInitInfo->cy; + } + else + { + /* XXX Implement below is code from old webShell + We don't have a heavy-weight window, we want to talk to our view I think. + We also don't want to duplicate the bounds locally. No need, let the + view keep up with that. + + nsRect result; + if (nsnull != mWindow) { + mWindow->GetClientBounds(result); + } else { + result = mBounds; + } + + *aCX = result.width; + *aCY = result.height; + + return NS_OK; + */ + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, + PRInt32 cy, PRBool fRepaint) +{ + if(!mCreated) + { + mBaseInitInfo->x = x; + mBaseInitInfo->y = y; + mBaseInitInfo->cx = cx; + mBaseInitInfo->cy = cy; + } + else + { + // XXX Do normal size and position stuff. Could just call + // Size and then Position, but underlying control probably supports + // some optimized setting of both like this. + + /* XXX Implement below is code from old webShell + We don't have a heavy-weight window, we want to talk to our view I think. + We also don't want to duplicate the bounds locally. No need, let the + view keep up with that. + + PRInt32 borderWidth = 0; + PRInt32 borderHeight = 0; + if (mWindow) + { + mWindow->GetBorderSize(borderWidth, borderHeight); + // Don't have the widget repaint. Layout will generate repaint requests + // during reflow + mWindow->Resize(aX, aY, aCX, aCY, PR_FALSE); + } + + mBounds.SetRect(aX, aY, aCX, aCY); // set the webshells bounds --dwc0001 + + // Set the size of the content area, which is the size of the window + // minus the borders + if (nsnull != mContentViewer) { + nsRect rr(0, 0, aCX-(borderWidth*2), aCY-(borderHeight*2)); + mContentViewer->SetBounds(rr); + } + return rv; + */ + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::Repaint(PRBool fForce) +{ + //XXX First Check + /** + * Tell the window to repaint itself + * @param aForce - if true, repaint immediately + * if false, the window may defer repainting as it sees fit. + */ + + /* XXX Implement Tell our view to repaint + + if (mWindow) { + mWindow->Invalidate(aForce); + } + + nsresult rv; + nsCOMPtr viewManager; + rv = GetViewManager(getter_AddRefs(viewManager)); + if (NS_FAILED(rv)) { return rv; } + if (!viewManager) { return NS_ERROR_NULL_POINTER; } + + //XXX: what about aForce? + rv = viewManager->UpdateAllViews(0); + return rv; + + */ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetParentWidget(nsIWidget** parentWidget) +{ + NS_ENSURE_ARG_POINTER(parentWidget); + + *parentWidget = mParentWidget; + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetParentWidget(nsIWidget* parentWidget) +{ + NS_ENSURE_STATE(!mCreated); + + mParentWidget = parentWidget; + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetParentNativeWindow(nativeWindow* parentNativeWindow) +{ + NS_ENSURE_ARG_POINTER(parentNativeWindow); + + if(mParentWidget) + *parentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); + else + *parentNativeWindow = nsnull; + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetParentNativeWindow(nativeWindow parentNativeWindow) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsDocShellBase::GetVisibility(PRBool* aVisibility) +{ + NS_ENSURE_ARG_POINTER(aVisibility); + + if(!mCreated) { + *aVisibility = mBaseInitInfo->visible; + } + else + { + // get the pres shell + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + // get the view manager + nsCOMPtr vm; + NS_ENSURE_SUCCESS(presShell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); + + // get the root view + nsIView *rootView=nsnull; // views are not ref counted + NS_ENSURE_SUCCESS(vm->GetRootView(rootView), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + + // convert the view's visibility attribute to a bool + nsViewVisibility vis; + NS_ENSURE_TRUE(rootView->GetVisibility(vis), NS_ERROR_FAILURE); + if (nsViewVisibility_kHide==vis) { + *aVisibility = PR_FALSE; + } + else { + *aVisibility = PR_TRUE; + } + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetVisibility(PRBool visibility) +{ + if(!mCreated) + mBaseInitInfo->visible = visibility; + else + { + // XXX Set underlying control visibility + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetMainWidget(nsIWidget** mainWidget) +{ + NS_ENSURE_ARG_POINTER(mainWidget); + + // For now we don't create our own widget, so simply return the parent one. + *mainWidget = mParentWidget; + NS_IF_ADDREF(*mainWidget); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetFocus() +{ + //XXX First Check + /** + * Give the window focus. + */ + + /* XXX implement + + if (mWindow) { + mWindow->SetFocus(); + } + + return NS_OK; + + */ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetTitle(PRUnichar** title) +{ + NS_ENSURE_ARG_POINTER(title); + + //XXX First Check + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::SetTitle(const PRUnichar* title) +{ + //XXX First Check + return NS_ERROR_FAILURE; +} + +//***************************************************************************** +// nsDocShellBase::nsIScrollable +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::GetCurScrollPos(PRInt32 scrollOrientation, + PRInt32* curPos) +{ + NS_ENSURE_ARG_POINTER(curPos); + + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + nscoord x, y; + NS_ENSURE_SUCCESS(scrollView->GetScrollPosition(x, y), NS_ERROR_FAILURE); + + switch(scrollOrientation) + { + case ScrollOrientation_X: + *curPos = x; + return NS_OK; + + case ScrollOrientation_Y: + *curPos = y; + return NS_OK; + + default: + NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG); + } + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::SetCurScrollPos(PRInt32 scrollOrientation, + PRInt32 curPos) +{ + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + PRInt32 other; + PRInt32 x; + PRInt32 y; + + GetCurScrollPos(scrollOrientation, &other); + + switch(scrollOrientation) + { + case ScrollOrientation_X: + x = curPos; + y = other; + break; + + case ScrollOrientation_Y: + x = other; + y = curPos; + break; + + default: + NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG); + } + + NS_ENSURE_SUCCESS(scrollView->ScrollTo(x, y, NS_VMREFRESH_IMMEDIATE), + NS_ERROR_FAILURE); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetCurScrollPosEx(PRInt32 curHorizontalPos, + PRInt32 curVerticalPos) +{ + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(scrollView->ScrollTo(curHorizontalPos, curVerticalPos, + NS_VMREFRESH_IMMEDIATE), NS_ERROR_FAILURE); + return NS_OK; +} + +// XXX This is wrong +NS_IMETHODIMP nsDocShellBase::GetScrollRange(PRInt32 scrollOrientation, + PRInt32* minPos, PRInt32* maxPos) +{ + NS_ENSURE_ARG_POINTER(minPos && maxPos); + + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + PRInt32 cx; + PRInt32 cy; + + NS_ENSURE_SUCCESS(scrollView->GetContainerSize(&cx, &cy), NS_ERROR_FAILURE); + *minPos = 0; + + switch(scrollOrientation) + { + case ScrollOrientation_X: + *maxPos = cx; + return NS_OK; + + case ScrollOrientation_Y: + *maxPos = cy; + return NS_OK; + + default: + NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::SetScrollRange(PRInt32 scrollOrientation, + PRInt32 minPos, PRInt32 maxPos) +{ + //XXX First Check + /* + Retrieves or Sets the valid ranges for the thumb. When maxPos is set to + something less than the current thumb position, curPos is set = to maxPos. + + @return NS_OK - Setting or Getting completed successfully. + NS_ERROR_INVALID_ARG - returned when curPos is not within the + minPos and maxPos. + */ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::SetScrollRangeEx(PRInt32 minHorizontalPos, + PRInt32 maxHorizontalPos, PRInt32 minVerticalPos, PRInt32 maxVerticalPos) +{ + //XXX First Check + /* + Retrieves or Sets the valid ranges for the thumb. When maxPos is set to + something less than the current thumb position, curPos is set = to maxPos. + + @return NS_OK - Setting or Getting completed successfully. + NS_ERROR_INVALID_ARG - returned when curPos is not within the + minPos and maxPos. + */ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsDocShellBase::GetScrollbarPreferences(PRInt32 scrollOrientation, + PRInt32* scrollbarPref) +{ + NS_ENSURE_ARG_POINTER(scrollbarPref); + + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + // XXX This is all evil, we need to convert. We don't know our prefs + // are the same as this interfaces. + /* nsScrollPreference scrollPref; + + NS_ENSURE_SUCCESS(scrollView->GetScrollPreference(scrollPref), + NS_ERROR_FAILURE); + + *scrollbarPref = scrollPref; */ + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::SetScrollbarPreferences(PRInt32 scrollOrientation, + PRInt32 scrollbarPref) +{ + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + // XXX This is evil. We should do a mapping, we don't know our prefs + // are the same as this interface. In fact it doesn't compile + /* nsScrollPreference scrollPref = scrollbarPref; + NS_ENSURE_SUCCESS(scrollView->SetScrollPreference(scrollPref), + NS_ERROR_FAILURE); */ + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetScrollbarVisibility(PRBool* verticalVisible, + PRBool* horizontalVisible) +{ + nsCOMPtr scrollView; + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + PRBool vertVisible; + PRBool horizVisible; + + NS_ENSURE_SUCCESS(scrollView->GetScrollbarVisibility(&vertVisible, + &horizVisible), NS_ERROR_FAILURE); + + if(verticalVisible) + *verticalVisible = vertVisible; + if(horizontalVisible) + *horizontalVisible = horizVisible; + + return NS_OK; +} + +//***************************************************************************** +// nsDocShellBase::nsITextScroll +//***************************************************************************** + +NS_IMETHODIMP nsDocShellBase::ScrollByLines(PRInt32 numLines) +{ + nsCOMPtr scrollView; + + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(scrollView->ScrollByLines(numLines), NS_ERROR_FAILURE); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::ScrollByPages(PRInt32 numPages) +{ + nsCOMPtr scrollView; + + NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(scrollView->ScrollByPages(numPages), NS_ERROR_FAILURE); + + return NS_OK; +} + +//***************************************************************************** +// nsDocShellBase::nsIContentViewerContainer +//***************************************************************************** +NS_IMETHODIMP nsDocShellBase::QueryCapability(const nsIID &aIID, void** aResult) +{ + NS_ENSURE_SUCCESS(PR_FALSE, NS_ERROR_NOT_IMPLEMENTED); + return NS_OK; +}; + +NS_IMETHODIMP nsDocShellBase::Embed(nsIContentViewer* aContentViewer, + const char * aCommand, + nsISupports * aExtraInfo) +{ + NS_ENSURE_ARG_POINTER(aContentViewer); + // null aCommand is ok + // null aExtraInfo is ok + + WEB_TRACE(WEB_TRACE_CALLS, + ("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p", + this, aContentViewer, aCommand ? aCommand : "", aExtraInfo)); + + nsRect bounds; + // (1) reset state, clean up any left-over data from previous embedding + mContentViewer = nsnull; + if (nsnull != mScriptContext) { + mScriptContext->GC(); + } + + // (2) set the new content viewer + mContentViewer = aContentViewer; + + // XXX: comment from webshell code -- + // check to see if we have a window to embed into --dwc0001 + /* Note we also need to check for the presence of a native widget. If the + webshell is hidden before it's embedded, which can happen in an onload + handler, the native widget is destroyed before this code is run. This + appears to be mostly harmless except on Windows, where the subsequent + attempt to create a child window without a parent is met with disdain + by the OS. It's handy, then, that GetNativeData on Windows returns + null in this case. */ + /* XXX native window + if(mWindow && mWindow->GetNativeData(NS_NATIVE_WIDGET)) + { + mWindow->GetClientBounds(bounds); + bounds.x = bounds.y = 0; + rv = mContentViewer->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET), + mDeviceContext, + mPrefs, + bounds, + mScrollPref); + + // If the history state has been set by session history, + // set it on the pres shell now that we have a content + // viewer. + + //XXX: history, should be removed + if (mContentViewer && mHistoryState) { + nsCOMPtr docv = do_QueryInterface(mContentViewer); + if (nsnull != docv) { + nsCOMPtr shell; + rv = docv->GetPresShell(*getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv)) { + rv = shell->SetHistoryState((nsILayoutHistoryState*) mHistoryState); + } + } + } + + if (NS_SUCCEEDED(rv)) { + mContentViewer->Show(); + } + } else { + mContentViewer = nsnull; + } + */ + + // Now that we have switched documents, forget all of our children + DestroyChildren(); + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::GetContentViewer(nsIContentViewer** aContentViewer) +{ + NS_ENSURE_ARG_POINTER(aContentViewer); + + *aContentViewer = mContentViewer; + NS_IF_ADDREF(*aContentViewer); + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::HandleUnknownContentType(nsIDocumentLoader* aLoader, + nsIChannel* channel, + const char *aContentType, + const char *aCommand) +{ + NS_ENSURE_SUCCESS(PR_FALSE, NS_ERROR_NOT_IMPLEMENTED); + return NS_OK; +} + + + + + +//***************************************************************************** +// nsDocShellBase: Helper Routines +//***************************************************************************** + +nsresult nsDocShellBase::GetChildOffset(nsIDOMNode *aChild, nsIDOMNode* aParent, + PRInt32* aOffset) +{ + NS_ENSURE_ARG_POINTER(aChild || aParent); + + nsCOMPtr childNodes; + NS_ENSURE_SUCCESS(aParent->GetChildNodes(getter_AddRefs(childNodes)), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(childNodes, NS_ERROR_FAILURE); + + PRInt32 i=0; + + for( ; PR_TRUE; i++) + { + nsCOMPtr childNode; + NS_ENSURE_SUCCESS(childNodes->Item(i, getter_AddRefs(childNode)), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(childNode, NS_ERROR_FAILURE); + + if(childNode.get() == aChild) + { + *aOffset = i; + return NS_OK; + } + } + + return NS_ERROR_FAILURE; +} + +nsresult nsDocShellBase::GetRootScrollableView(nsIScrollableView** aOutScrollView) +{ + NS_ENSURE_ARG_POINTER(aOutScrollView); + + nsCOMPtr viewManager; + + //XXX Get ViewManager Somewhere. + + NS_ENSURE_SUCCESS(viewManager->GetRootScrollableView(aOutScrollView), + NS_ERROR_FAILURE); + + return NS_OK; +} + +nsresult nsDocShellBase::GetPresShell(nsIPresShell** aPresShell) +{ + NS_ENSURE_ARG_POINTER(aPresShell); + + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), + NS_ERROR_FAILURE); + + NS_ENSURE_SUCCESS(presContext->GetShell(aPresShell), NS_ERROR_FAILURE); + + return NS_OK; +} + +nsresult nsDocShellBase::EnsureContentListener() +{ + if(mContentListener) + return NS_OK; + + mContentListener = new nsDSURIContentListener(); + NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY); + + mContentListener->AddRef(); + mContentListener->DocShellBase(this); + + return NS_OK; +} + +void nsDocShellBase::SetCurrentURI(nsIURI* aUri) +{ + mCurrentURI = aUri; //This assignment addrefs +} + +NS_IMETHODIMP +nsDocShellBase::FireStartDocumentLoad(nsIDocumentLoader* aLoader, + nsIURI * aURL, //XXX: should be the channel? + const char * aCommand) +{ + NS_ENSURE_ARG_POINTER(aLoader); + NS_ENSURE_ARG_POINTER(aURL); + NS_ENSURE_ARG_POINTER(aCommand); + + nsCOMPtr docViewer; + if (mScriptGlobal && (aLoader == mDocLoader)) + { + docViewer = do_QueryInterface(mContentViewer); + if (docViewer) + { + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); + if (presContext) + { + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_PAGE_UNLOAD; + NS_ENSURE_SUCCESS(mScriptGlobal->HandleDOMEvent(*presContext, + &event, + nsnull, + NS_EVENT_FLAG_INIT, + status), + NS_ERROR_FAILURE); + } + } + } + + if (aLoader == mDocLoader) + { + nsCOMPtr dlObserver; + + if (!mDocLoaderObserver && mParent) + { + /* If this is a frame (in which case it would have a parent && doesn't + * have a documentloaderObserver, get it from the rootWebShell + */ + nsCOMPtr root; + NS_ENSURE_SUCCESS(GetRootDocShell(getter_AddRefs(root)), NS_ERROR_FAILURE); + + if (root) + NS_ENSURE_SUCCESS(root->GetDocLoaderObserver(getter_AddRefs(dlObserver)), NS_ERROR_FAILURE); + } + else + { + dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref + } + /* + * Fire the OnStartDocumentLoad of the webshell observer + */ + /* XXX This code means "notify dlObserver only if we're the top level webshell. + I don't know why that would be, can't subdocument have doc loader observers? + */ + if (/*(nsnull != mContainer) && */(nsnull != dlObserver)) + { + NS_ENSURE_SUCCESS(dlObserver->OnStartDocumentLoad(mDocLoader, aURL, aCommand), + NS_ERROR_FAILURE); + } + } + + return NS_OK; +} + + + +NS_IMETHODIMP +nsDocShellBase::FireEndDocumentLoad(nsIDocumentLoader* aLoader, + nsIChannel * aChannel, + nsresult aStatus, + nsIDocumentLoaderObserver * aDocLoadObserver) +{ +#ifdef MOZ_PERF_METRICS + RAPTOR_STOPWATCH_DEBUGTRACE(("Stop: nsWebShell::OnEndDocumentLoad(), this=%p\n", this)); + NS_STOP_STOPWATCH(mTotalTime) + RAPTOR_STOPWATCH_TRACE(("Total (Layout + Page Load) Time (webshell=%p): ", this)); + mTotalTime.Print(); + RAPTOR_STOPWATCH_TRACE(("\n")); +#endif + + NS_ENSURE_ARG_POINTER(aLoader); + NS_ENSURE_ARG_POINTER(aChannel); + // null aDocLoadObserver is legal + + nsCOMPtr aURL; + NS_ENSURE_SUCCESS(aChannel->GetURI(getter_AddRefs(aURL)), NS_ERROR_FAILURE); + + if (aLoader == mDocLoader) + { + if (mScriptGlobal && mContentViewer) + { + nsCOMPtr docViewer; + docViewer = do_QueryInterface(mContentViewer); + if (docViewer) + { + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE); + if (presContext) + { + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event; + event.eventStructType = NS_EVENT; + event.message = NS_PAGE_LOAD; + NS_ENSURE_SUCCESS(mScriptGlobal->HandleDOMEvent(*presContext, + &event, + nsnull, + NS_EVENT_FLAG_INIT, + status), + NS_ERROR_FAILURE); + } + } + } + + // Fire the EndLoadURL of the web shell container + /* XXX: what replaces mContainer? + if (nsnull != aURL) + { + nsAutoString urlString; + char* spec; + rv = aURL->GetSpec(&spec); + if (NS_SUCCEEDED(rv)) + { + urlString = spec; + if (nsnull != mContainer) { + rv = mContainer->EndLoadURL(this, urlString.GetUnicode(), 0); + } + nsCRT::free(spec); + } + } + */ + + nsCOMPtr dlObserver; + if (!mDocLoaderObserver && mParent) + { + // If this is a frame (in which case it would have a parent && doesn't + // have a documentloaderObserver, get it from the rootWebShell + nsCOMPtr root; + NS_ENSURE_SUCCESS(GetRootDocShell(getter_AddRefs(root)), NS_ERROR_FAILURE); + + if (root) + NS_ENSURE_SUCCESS(root->GetDocLoaderObserver(getter_AddRefs(dlObserver)), NS_ERROR_FAILURE); + } + else + { + /* Take care of the Trailing slash situation */ +/* XXX: session history stuff, should be taken care of external to the docshell + if (mSHist) + CheckForTrailingSlash(aURL); +*/ + dlObserver = do_QueryInterface(mDocLoaderObserver); // we need this to addref + } + + /* + * Fire the OnEndDocumentLoad of the DocLoaderobserver + */ + if (dlObserver && aURL) { + NS_ENSURE_SUCCESS(dlObserver->OnEndDocumentLoad(mDocLoader, aChannel, aStatus, aDocLoadObserver), + NS_ERROR_FAILURE); + } + + /* put the new document in the doc tree */ + NS_ENSURE_SUCCESS(InsertDocumentInDocTree(), NS_ERROR_FAILURE); + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::InsertDocumentInDocTree() +{ + nsCOMPtr parent; + NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + // null parent is legal. If we have a parent, hook up our doc to the parent's doc + if (parent) + { + // Get the document object for the parent + nsCOMPtr parentAsContentViewerContainer; + parentAsContentViewerContainer = do_QueryInterface(parent); + NS_ENSURE_TRUE(parentAsContentViewerContainer, NS_ERROR_FAILURE); + nsCOMPtr parentContentViewer; + NS_ENSURE_SUCCESS(parentAsContentViewerContainer->GetContentViewer(getter_AddRefs(parentContentViewer)), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(parentContentViewer, NS_ERROR_FAILURE); + nsCOMPtr parentDocViewer; + parentDocViewer = do_QueryInterface(parentContentViewer); + NS_ENSURE_TRUE(parentDocViewer, NS_ERROR_FAILURE); + + nsCOMPtr parentDoc; + NS_ENSURE_SUCCESS(parentDocViewer->GetDocument(*getter_AddRefs(parentDoc)), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(parentDoc, NS_ERROR_FAILURE); + + // Get the document object for this + nsCOMPtr docViewer; + docViewer = do_QueryInterface(mContentViewer); + NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE); + + nsCOMPtr doc; + NS_ENSURE_SUCCESS(docViewer->GetDocument(*getter_AddRefs(doc)), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + + doc->SetParentDocument(parentDoc); + parentDoc->AddSubDocument(doc); + } + return NS_OK; +} + +NS_IMETHODIMP nsDocShellBase::DestroyChildren() +{ + PRInt32 i, n = mChildren.Count(); + for (i = 0; i < n; i++) + { + nsIDocShell* shell = (nsIDocShell*) mChildren.ElementAt(i); + NS_WARN_IF_FALSE(shell, "docshell has null child"); + if (shell) + { + shell->SetParent(nsnull); + // XXX: will shells have a separate Destroy? See webshell::Destroy for what it does + //shell->Destroy(); + NS_RELEASE(shell); + } + } + mChildren.Clear(); + return NS_OK; +} + diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl index 8a7c4c7b508..2ac596ec0e4 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -161,22 +161,7 @@ interface nsIDocShell : nsISupports * no zoom. */ attribute float zoom; -}; -/** - * The nsIHTMLDocShell - XXX This is going away. - */ - -[scriptable, uuid(69E5DE03-7B8B-11d3-AF61-00A024FFC08C)] -interface nsIHTMLDocShell : nsISupports -{ - /* - Scrolls to a given DOM content node. - */ - void scrollToNode(in nsIDOMNode node); - - /** if true, plugins are allowed within the doc shell. default = true */ - attribute boolean allowPlugins; /* XXX Comment here! @@ -187,39 +172,5 @@ interface nsIHTMLDocShell : nsISupports XXX Comment here! */ attribute long marginHeight; - - /* - XXX Comment here! - */ - attribute boolean isFrame; - - /* - XXX Comment here! - */ - attribute wstring defaultCharacterSet; - - /* - XXX Comment here! - */ - attribute wstring forceCharacterSet; - - /* - XXX Comment here! - */ - readonly attribute wstring hintCharacterSet; - - /* - XXX Comment here! - */ - readonly attribute PRInt32 hintCharacterSetSource; - - /* the following is the hacky access method - Commented out as nsCharsetSource should be something IDL like - void GetCharacterSetHint(in wstring hintCharset, in nsCharsetSource charsetSource); - */ - - /** - * Tell the window to shrink-to-fit or grow-to-fit its contents - */ - void sizeToContent(); }; + diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 8208a23c61c..a6b3bf28553 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -24,6 +24,7 @@ #include "nsIDocumentLoader.h" #include "nsIContentViewer.h" #include "nsIDocumentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIClipboardCommands.h" #include "nsIDeviceContext.h" #include "nsILinkHandler.h" @@ -225,14 +226,14 @@ public: NS_IMETHOD GetContainingChromeElement(nsIContent** aResult); NS_IMETHOD SetContainingChromeElement(nsIContent* aChromeElement); - NS_IMETHOD GetMarginWidth (PRInt32& aWidth); - NS_IMETHOD SetMarginWidth (PRInt32 aWidth); - NS_IMETHOD GetMarginHeight(PRInt32& aWidth); - NS_IMETHOD SetMarginHeight(PRInt32 aHeight); NS_IMETHOD GetScrolling(PRInt32& aScrolling); NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE); - NS_IMETHOD GetIsFrame(PRBool& aIsFrame); - NS_IMETHOD SetIsFrame(PRBool aIsFrame); + + NS_IMETHOD GetMarginWidth (PRInt32* aWidth); + NS_IMETHOD SetMarginWidth (PRInt32 aWidth); + NS_IMETHOD GetMarginHeight(PRInt32* aWidth); + NS_IMETHOD SetMarginHeight(PRInt32 aHeight); + NS_IMETHOD SetZoom(float aZoom); NS_IMETHOD GetZoom(float *aZoom); @@ -402,13 +403,6 @@ public: nsresult DestroyPluginHost(void); NS_IMETHOD IsBusy(PRBool& aResult); - NS_IMETHOD GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet); - NS_IMETHOD SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet); - - NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet); - NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet); - - NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource); NS_IMETHOD SetSessionHistory(nsISessionHistory * aSHist); NS_IMETHOD GetSessionHistory(nsISessionHistory *& aResult); @@ -464,12 +458,13 @@ protected: nsString mOverTarget; PRPackedBool mIsInSHist; - PRPackedBool mIsFrame; PRPackedBool mFailedToLoadHistoryService; nsScrollPreference mScrollPref; + PRInt32 mMarginWidth; PRInt32 mMarginHeight; + PRInt32 mScrolling[2]; nsVoidArray mRefreshments; @@ -507,11 +502,14 @@ protected: PRBool mProcessedEndDocumentLoad; // XXX store mHintCharset and mHintCharsetSource here untill we find out a good cood path + /* nsString mHintCharset; nsCharsetSource mHintCharsetSource; - PRBool mViewSource; nsString mForceCharacterSet; + */ + PRBool mViewSource; + // if there is no mWindow, this will keep track of the bounds --dwc0001 nsRect mBounds; @@ -657,7 +655,6 @@ nsWebShell::nsWebShell() mScriptContext = nsnull; mThreadEventQueue = nsnull; InitFrameData(PR_TRUE); - mIsFrame = PR_FALSE; mWebShellType = nsWebShellContent; mChromeElement = nsnull; mSHist = nsnull; @@ -665,11 +662,8 @@ nsWebShell::nsWebShell() mFailedToLoadHistoryService = PR_FALSE; mDefaultCharacterSet = ""; mProcessedEndDocumentLoad = PR_FALSE; - mHintCharset = ""; - mHintCharsetSource = kCharsetUninitialized; mCharsetReloadState = eCharsetReloadInit; mViewSource=PR_FALSE; - mForceCharacterSet = ""; mHistoryService = nsnull; mHistoryState = nsnull; mParentContentListener = nsnull; @@ -713,7 +707,6 @@ nsWebShell::~nsWebShell() } InitFrameData(PR_TRUE); - mIsFrame = PR_FALSE; // XXX Because we hold references to the children and they hold references // to us we never get destroyed. See Destroy() instead... @@ -747,8 +740,8 @@ void nsWebShell::InitFrameData(PRBool aCompleteInitScrolling) if (aCompleteInitScrolling) { mScrolling[0] = -1; mScrolling[1] = -1; - mMarginWidth = -1; - mMarginHeight = -1; + SetMarginWidth(-1); + SetMarginHeight(-1); } else { mScrolling[1] = mScrolling[0]; @@ -838,6 +831,41 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer, ("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p", this, aContentViewer, aCommand ? aCommand : "", aExtraInfo)); + if (mContentViewer && (eCharsetReloadInit!=mCharsetReloadState)) + { // get any interesting state from the old content viewer + // XXX: it would be far better to just reuse the document viewer , + // since we know we're just displaying the same document as before + PRUnichar *defaultCharset=nsnull; + PRUnichar *forceCharset=nsnull; + PRUnichar *hintCharset=nsnull; + PRInt32 hintCharsetSource; + + nsCOMPtr oldMUDV = do_QueryInterface(mContentViewer); + nsCOMPtr newMUDV = do_QueryInterface(aContentViewer); + if (oldMUDV && newMUDV) + { + NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE); + + // set the old state onto the new content viewer + NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE); + + if (defaultCharSet) { + Recycle(defaultCharSet); + } + if (forceCharset) { + Recycle(forceCharset); + } + if (hintCharset) { + Recycle(hintCharset); + } + } + } NS_IF_RELEASE(mContentViewer); if (nsnull != mScriptContext) { mScriptContext->GC(); @@ -1586,10 +1614,30 @@ nsWebShell::AddChild(nsIWebShell* aChild) } mChildren.AppendElement(aChild); aChild->SetParent(this); - const PRUnichar *defaultCharset=nsnull; - if(NS_SUCCEEDED(this->GetDefaultCharacterSet (&defaultCharset))) - aChild->SetDefaultCharacterSet(defaultCharset); - aChild->SetForceCharacterSet(mForceCharacterSet.GetUnicode()); + PRUnichar *defaultCharset=nsnull; + PRUnichar *forceCharset=nsnull; + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); + } + nsCOMPtr childCV; + NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE); + if (childCV) + { + nsCOMPtr childmuDV = do_QueryInterface(cv); + if (childmuDV) + { + childmuDV->SetDefaultCharacterSet(defaultCharset); + childmuDV->SetForceCharacterSet(forceCharset); + } + } + } NS_ADDREF(aChild); return NS_OK; @@ -1736,9 +1784,11 @@ nsWebShell::SetContainingChromeElement(nsIContent* aChromeElement) } NS_IMETHODIMP -nsWebShell::GetMarginWidth(PRInt32& aWidth) +nsWebShell::GetMarginWidth(PRInt32* aWidth) { - aWidth = mMarginWidth; + NS_ENSURE_ARG_POINTER(aWidth); + + *aWidth = mMarginWidth; return NS_OK; } @@ -1750,9 +1800,11 @@ nsWebShell::SetMarginWidth(PRInt32 aWidth) } NS_IMETHODIMP -nsWebShell::GetMarginHeight(PRInt32& aHeight) +nsWebShell::GetMarginHeight(PRInt32* aHeight) { - aHeight = mMarginHeight; + NS_ENSURE_ARG_POINTER(aHeight); + + *aHeight = mMarginHeight; return NS_OK; } @@ -1780,20 +1832,6 @@ nsWebShell::SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial) return NS_OK; } -NS_IMETHODIMP -nsWebShell::GetIsFrame(PRBool& aIsFrame) -{ - aIsFrame = mIsFrame; - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::SetIsFrame(PRBool aIsFrame) -{ - mIsFrame = aIsFrame; - return NS_OK; -} - NS_IMETHODIMP nsWebShell::SetZoom(float aZoom) { @@ -1944,6 +1982,7 @@ nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode) if (!doc) { return NS_ERROR_OUT_OF_MEMORY; } NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE); doc->SetRootContent(rootContent); + rootContent->SetDocument(doc, PR_TRUE); // (6) reflow the document SetScrolling(-1, PR_FALSE); @@ -2960,16 +2999,27 @@ nsWebShell::LoadDocument(const char* aURL, nsCharsetSource aSource) { // XXX hack. kee the aCharset and aSource wait to pick it up - if( aSource > mHintCharsetSource ) { - mHintCharset = aCharset; - mHintCharsetSource = aSource; - if(eCharsetReloadRequested != mCharsetReloadState) + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) { - - mCharsetReloadState = eCharsetReloadRequested; - - nsAutoString url(aURL); - LoadURL(url.GetUnicode()); + nsCharsetSource hint; + muDV->GetHintCharacterSetSource((PRInt32 *)(&hint)); + if( aSource > hint ) + { + nsAutoString inputCharSet(aCharset); + muDV->SetHintCharacterSet(inputCharSet.GetUnicode()); + muDV->SetHintCharacterSetSource((PRInt32)aSource); + if(eCharsetReloadRequested != mCharsetReloadState) + { + mCharsetReloadState = eCharsetReloadRequested; + nsAutoString url(aURL); + LoadURL(url.GetUnicode()); + } + } } } return NS_OK; @@ -2982,15 +3032,28 @@ nsWebShell::ReloadDocument(const char* aCharset, { // XXX hack. kee the aCharset and aSource wait to pick it up - if( aSource > mHintCharsetSource ) { - mHintCharset = aCharset; - mHintCharsetSource = aSource; - mViewSource = (0==PL_strcmp("view-source", aCmd)); - if(eCharsetReloadRequested != mCharsetReloadState) - { - mCharsetReloadState = eCharsetReloadRequested; - return Reload(nsIChannel::LOAD_NORMAL); - } + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + nsCharsetSource hint; + muDV->GetHintCharacterSetSource((PRInt32 *)(&hint)); + if( aSource > hint ) + { + nsAutoString inputCharSet(aCharset); + muDV->SetHintCharacterSet(inputCharSet.GetUnicode()); + muDV->SetHintCharacterSetSource((PRInt32)aSource); + mViewSource = (0==PL_strcmp("view-source", aCmd)); + if(eCharsetReloadRequested != mCharsetReloadState) + { + mCharsetReloadState = eCharsetReloadRequested; + return Reload(nsIChannel::LOAD_NORMAL); + } + } + } } return NS_OK; } @@ -4185,77 +4248,6 @@ nsWebShell::SelectNone(void) return NS_ERROR_FAILURE; } -static char *gDefCharset = nsnull; - -NS_IMETHODIMP -nsWebShell::GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet) -{ - if (0 == mDefaultCharacterSet.Length()) { - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) { - if(mPrefs) - mPrefs->CopyCharPref("intl.charset.default", &gDefCharset); - } - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - mDefaultCharacterSet = "ISO-8859-1"; - else - mDefaultCharacterSet = gDefCharset; - } - *aDefaultCharacterSet = mDefaultCharacterSet.GetUnicode(); - return NS_OK; -} -NS_IMETHODIMP -nsWebShell::SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet) -{ - mDefaultCharacterSet = aDefaultCharacterSet; - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i); - if (nsnull != child) { - child->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::GetForceCharacterSet (const PRUnichar** aForceCharacterSet) -{ - nsAutoString emptyStr; - if (mForceCharacterSet.Equals(emptyStr)) { - *aForceCharacterSet = nsnull; - } - else { - *aForceCharacterSet = mForceCharacterSet.GetUnicode(); - } - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::SetForceCharacterSet (const PRUnichar* aForceCharacterSet) -{ - mForceCharacterSet = aForceCharacterSet; - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i); - if (nsnull != child) { - child->SetForceCharacterSet(aForceCharacterSet); - } - } - return NS_OK; -} - -NS_IMETHODIMP nsWebShell::GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource) -{ - *oSource = mHintCharsetSource; - if(kCharsetUninitialized == mHintCharsetSource) { - *oHintCharset = nsnull; - } else { - *oHintCharset = mHintCharset.GetUnicode(); - mHintCharsetSource = kCharsetUninitialized; - } - return NS_OK; -} - //---------------------------------------------------- NS_IMETHODIMP diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index fe1ef7feb24..5a1abe86935 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -62,6 +62,7 @@ #include "nsRect.h" #include "nsIPrompt.h" #include "nsIContentViewer.h" +#include "nsIContentViewerFile.h" #include "nsIDocumentViewer.h" #include "nsIPresShell.h" #include "nsIScrollableView.h" @@ -1411,13 +1412,13 @@ GlobalWindowImpl::Print() { nsresult result = NS_OK; if (nsnull != mWebShell) { - nsIContentViewer *viewer = nsnull; - - mWebShell->GetContentViewer(&viewer); - + nsCOMPtr viewer; + mWebShell->GetContentViewer(getter_AddRefs(viewer)); if (nsnull != viewer) { - result = viewer->Print(); - NS_RELEASE(viewer); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + result = viewerFile->Print(); + } } } @@ -2616,18 +2617,19 @@ GlobalWindowImpl::GetBrowserWindowInterface( nsIBrowserWindow*& aBrowser, nsIWebShell *aWebShell) { - aBrowser = nsnull; + aBrowser = nsnull; - if (nsnull == aWebShell) + if (nsnull == aWebShell) aWebShell = mWebShell; - NS_ENSURE_TRUE(aWebShell, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(aWebShell, NS_ERROR_UNEXPECTED); - nsCOMPtr topLevelWindow; + nsCOMPtr topLevelWindow; + NS_ENSURE_SUCCESS(aWebShell->GetTopLevelWindow( + getter_AddRefs(topLevelWindow)), NS_ERROR_FAILURE); - aWebShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow)); - if(!topLevelWindow) - return NS_ERROR_FAILURE; - return topLevelWindow->QueryInterface(NS_GET_IID(nsIBrowserWindow), (void**)&aBrowser); + if(!topLevelWindow) + return NS_ERROR_FAILURE; + return topLevelWindow->QueryInterface(NS_GET_IID(nsIBrowserWindow), (void**)&aBrowser); } PRBool diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 6c6879c208b..7f694aa4ac4 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -25,6 +25,7 @@ #include "nsEditorShell.h" #include "nsIBrowserWindow.h" #include "nsIWebShell.h" +#include "nsIContentViewerFile.h" #include "pratom.h" #include "prprf.h" #include "nsIComponentManager.h" @@ -1570,16 +1571,18 @@ nsEditorShell::Print() if (!mContentAreaWebShell) return NS_ERROR_NOT_INITIALIZED; - nsIContentViewer *viewer = nsnull; - - mContentAreaWebShell->GetContentViewer(&viewer); - - if (nsnull != viewer) { - viewer->Print(); - NS_RELEASE(viewer); + nsCOMPtr viewer; + mContentAreaWebShell->GetContentViewer(getter_AddRefs(viewer)); + if (nsnull != viewer) + { + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE); + } } return NS_OK; } + // NO LONGER CALLED Global JS method goQuitApplication() is called instead NS_IMETHODIMP nsEditorShell::Exit() diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 6c6879c208b..7f694aa4ac4 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -25,6 +25,7 @@ #include "nsEditorShell.h" #include "nsIBrowserWindow.h" #include "nsIWebShell.h" +#include "nsIContentViewerFile.h" #include "pratom.h" #include "prprf.h" #include "nsIComponentManager.h" @@ -1570,16 +1571,18 @@ nsEditorShell::Print() if (!mContentAreaWebShell) return NS_ERROR_NOT_INITIALIZED; - nsIContentViewer *viewer = nsnull; - - mContentAreaWebShell->GetContentViewer(&viewer); - - if (nsnull != viewer) { - viewer->Print(); - NS_RELEASE(viewer); + nsCOMPtr viewer; + mContentAreaWebShell->GetContentViewer(getter_AddRefs(viewer)); + if (nsnull != viewer) + { + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE); + } } return NS_OK; } + // NO LONGER CALLED Global JS method goQuitApplication() is called instead NS_IMETHODIMP nsEditorShell::Exit() diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 3fc6e2f19fe..47599f9427e 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -24,6 +24,8 @@ #include "nsCRT.h" #include "nsString.h" #include "nsISupports.h" +#include "nsIContent.h" +#include "nsIContentViewerContainer.h" #include "nsIDocumentViewer.h" #include "nsIImageGroup.h" @@ -54,6 +56,9 @@ #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIInterfaceRequestor.h" @@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); #endif class DocumentViewerImpl : public nsIDocumentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile, + public nsIMarkupDocumentViewer, public nsIImageGroupObserver { public: @@ -97,8 +105,6 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(void); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); @@ -110,6 +116,15 @@ public: NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + + // nsIMarkupDocumentViewer + NS_DECL_NSIMARKUPDOCUMENTVIEWER + // nsIImageGroupObserver interface... virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -166,6 +181,17 @@ protected: nsIViewManager *mPrintVM; nsIView *mPrintView; + // document management data + // these items are specific to markup documents (html and xml) + // may consider splitting these out into a subclass + PRBool mAllowPlugins; + PRPackedBool mIsFrame; + /* character set member data */ + nsString mDefaultCharacterSet; + nsString mHintCharset; + nsCharsetSource mHintCharsetSource; + nsString mForceCharacterSet; + }; // Class IDs @@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) : mPresContext(dont_QueryInterface(aPresContext)) { NS_INIT_REFCNT(); + mHintCharset = ""; + mHintCharsetSource = kCharsetUninitialized; + mForceCharacterSet = ""; + mAllowPlugins = PR_TRUE; + mIsFrame = PR_FALSE; } // ISupports implementation... @@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) { + nsIMarkupDocumentViewer* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { nsIContentViewer* tmp1 = this; nsISupports* tmp2 = tmp1; @@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void) return NS_OK; } -static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); -static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); - - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ -NS_IMETHODIMP -DocumentViewerImpl::Print(void) -{ -nsCOMPtr webContainer; -nsCOMPtr factory; -PRInt32 width,height; -nsCOMPtr prefs; - - nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, - nsnull, - kIDeviceContextSpecFactoryIID, - (void **)getter_AddRefs(factory)); - - if (factory) { - -#ifdef DEBUG_dcone - printf("PRINT JOB STARTING\n"); -#endif - - nsIDeviceContextSpec *devspec = nsnull; - nsCOMPtr dx; - mPrintDC = nsnull; - - factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); - if (nsnull != devspec) { - mPresContext->GetDeviceContext(getter_AddRefs(dx)); - nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); - if (NS_SUCCEEDED(rv)) { - - NS_RELEASE(devspec); - - // Get the webshell for this documentviewer - 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)){ - return rv; - } - - mPrintDC->GetDeviceSurfaceDimensions(width,height); - mPresContext->GetPrefs(getter_AddRefs(prefs)); - mPrintPC->Init(mPrintDC,prefs); - CreateStyleSet(mDocument,&mPrintSS); - - rv = NS_NewPresShell(&mPrintPS); - if(NS_FAILED(rv)){ - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); - if(NS_FAILED(rv)) { - return rv; - } - - rv = mPrintVM->Init(mPrintDC); - if(NS_FAILED(rv)) { - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); - if(NS_FAILED(rv)) { - return rv; - } - - nsRect tbounds = nsRect(0,0,width,height); - rv = mPrintView->Init(mPrintVM,tbounds,nsnull); - if(NS_FAILED(rv)) { - return rv; - } - - // setup hierarchical relationship in view manager - mPrintVM->SetRootView(mPrintView); - mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); - - nsCOMPtr imageGroup; - mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); - if (imageGroup) { - imageGroup->AddObserver(this); - } - - mPrintPS->InitialReflow(width,height); - -#ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; - - printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); - - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - - - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrintDC); - mPrintDC->GetDevUnitsToTwips(a1); - mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrintDC->GetAppUnitsToDevUnits(a1); - mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - -#endif - // - // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the - // InitialReflow... - // - if(!mIsPrinting){ - DocumentReadyForPrinting(); -#ifdef DEBUG_dcone - printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); -#endif - } else { - // use the observer mechanism to finish the printing -#ifdef DEBUG_dcone - printf("PRINTING OBSERVER STARTED\n"); -#endif - } - } - } - } - } - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ NS_IMETHODIMP DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) { -nsCOMPtr ss; -nsCOMPtr prefs; -nsCOMPtr vm; -PRInt32 width, height; -nsIView *view; -nsresult rv; -PRInt32 count,i; -nsIWebShell *childWebShell; -nsIContentViewer *viewer; - + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + nsCOMPtr ss; + nsCOMPtr prefs; + nsCOMPtr vm; + PRInt32 width, height; + nsIView *view; + nsresult rv; + PRInt32 count,i; + nsCOMPtr childWebShell; + nsCOMPtr viewer; aParent->GetChildCount(count); if(count> 0) { for(i=0;iChildAt(i,childWebShell); - childWebShell->GetContentViewer(&viewer); - viewer->PrintContent(childWebShell,aDContext); - NS_RELEASE(childWebShell); - NS_RELEASE(viewer); + aParent->ChildAt(i, *(getter_AddRefs(childWebShell))); + childWebShell->GetContentViewer(getter_AddRefs(viewer)); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE); + } } } else { aDContext->BeginDocument(); @@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting() // // Send the document to the printer... // - PrintContent(webContainer,mPrintDC); + nsresult rv = PrintContent(webContainer, mPrintDC); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent"); // printing is complete, clean up now mIsPrinting = PR_FALSE; @@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting() } } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP DocumentViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +DocumentViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); +static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); + + +/** --------------------------------------------------- + * See documentation above in the DocumentViewerImpl class definition + * @update 07/09/99 dwc + */ +NS_IMETHODIMP +DocumentViewerImpl::Print() +{ +nsCOMPtr webContainer; +nsCOMPtr factory; +PRInt32 width,height; +nsCOMPtr prefs; + + nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, + nsnull, + kIDeviceContextSpecFactoryIID, + (void **)getter_AddRefs(factory)); + + if (factory) { + +#ifdef DEBUG_dcone + printf("PRINT JOB STARTING\n"); +#endif + + nsIDeviceContextSpec *devspec = nsnull; + nsCOMPtr dx; + mPrintDC = nsnull; + + factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); + if (nsnull != devspec) { + mPresContext->GetDeviceContext(getter_AddRefs(dx)); + nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); + if (NS_SUCCEEDED(rv)) { + + NS_RELEASE(devspec); + + // Get the webshell for this documentviewer + 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)){ + return rv; + } + + mPrintDC->GetDeviceSurfaceDimensions(width,height); + mPresContext->GetPrefs(getter_AddRefs(prefs)); + mPrintPC->Init(mPrintDC,prefs); + CreateStyleSet(mDocument,&mPrintSS); + + rv = NS_NewPresShell(&mPrintPS); + if(NS_FAILED(rv)){ + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); + if(NS_FAILED(rv)) { + return rv; + } + + rv = mPrintVM->Init(mPrintDC); + if(NS_FAILED(rv)) { + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); + if(NS_FAILED(rv)) { + return rv; + } + + nsRect tbounds = nsRect(0,0,width,height); + rv = mPrintView->Init(mPrintVM,tbounds,nsnull); + if(NS_FAILED(rv)) { + return rv; + } + + // setup hierarchical relationship in view manager + mPrintVM->SetRootView(mPrintView); + mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); + + nsCOMPtr imageGroup; + mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); + if (imageGroup) { + imageGroup->AddObserver(this); + } + + mPrintPS->InitialReflow(width,height); + +#ifdef DEBUG_dcone + float a1,a2; + PRInt32 i1,i2; + + printf("CRITICAL PRINTING INFORMATION\n"); + printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", + mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); + + // DEVICE CONTEXT INFORMATION from PresContext + printf("DeviceContext of Presentation Context(%x)\n",dx); + dx->GetDevUnitsToTwips(a1); + dx->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + dx->GetAppUnitsToDevUnits(a1); + dx->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + dx->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + dx->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + dx->GetZoom(a1); + printf(" Zoom = %f\n",a1); + dx->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + dx->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + + + // DEVICE CONTEXT INFORMATION + printf("DeviceContext created for print(%x)\n",mPrintDC); + mPrintDC->GetDevUnitsToTwips(a1); + mPrintDC->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + mPrintDC->GetAppUnitsToDevUnits(a1); + mPrintDC->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + mPrintDC->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + mPrintDC->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + mPrintDC->GetZoom(a1); + printf(" Zoom = %f\n",a1); + mPrintDC->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + mPrintDC->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + +#endif + // + // The mIsPrinting flag is set when the ImageGroup observer is + // notified that images must be loaded as a result of the + // InitialReflow... + // + if(!mIsPrinting){ + DocumentReadyForPrinting(); +#ifdef DEBUG_dcone + printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); +#endif + } else { + // use the observer mechanism to finish the printing +#ifdef DEBUG_dcone + printf("PRINTING OBSERVER STARTED\n"); +#endif + } + } + } + } + } + return NS_OK; +} + + +NS_IMETHODIMP +DocumentViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_TRUE; + return NS_OK; +} + + +//***************************************************************************** +// nsIMarkupDocumentViewer +//***************************************************************************** + +NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) +{ + NS_ENSURE_ARG(aNode); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + + // Get the nsIContent interface, because that's what we need to + // get the primary frame + + nsCOMPtr content(do_QueryInterface(aNode)); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + + // Get the primary frame + nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their + // own special little world. + + NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), + NS_ERROR_FAILURE); + + // tell the pres shell to scroll to the frame + NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, + NS_PRESSHELL_SCROLL_TOP, + NS_PRESSHELL_SCROLL_ANYWHERE), + NS_ERROR_FAILURE); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) +{ + NS_ENSURE_ARG_POINTER(aAllowPlugins); + + *aAllowPlugins = mAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) +{ + mAllowPlugins = aAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame) +{ + NS_ENSURE_ARG_POINTER(aIsFrame); + + *aIsFrame = mIsFrame; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame) +{ + mIsFrame = aIsFrame; + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aDefaultCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); + NS_ENSURE_STATE(mContainer); + + static char *gDefCharset = nsnull; // XXX: memory leak! + + if (0 == mDefaultCharacterSet.Length()) + { + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + { + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr prefs; + NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE); + if(prefs) + prefs->CopyCharPref("intl.charset.default", &gDefCharset); + } + } + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + mDefaultCharacterSet = "ISO-8859-1"; + else + mDefaultCharacterSet = gDefCharset; + } + *aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) +{ + mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet + // now set the default char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aForceCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aForceCharacterSet); + + nsAutoString emptyStr; + if (mForceCharacterSet.Equals(emptyStr)) { + *aForceCharacterSet = nsnull; + } + else { + *aForceCharacterSet = mForceCharacterSet.ToNewUnicode(); + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) +{ + mForceCharacterSet = aForceCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetForceCharacterSet(aForceCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aHintCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSet); + + if(kCharsetUninitialized == mHintCharsetSource) { + *aHintCharacterSet = nsnull; + } else { + *aHintCharacterSet = mHintCharset.ToNewUnicode(); + // this can't possibly be right. we can't set a value just because somebody got a related value! + //mHintCharsetSource = kCharsetUninitialized; + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); + + *aHintCharacterSetSource = mHintCharsetSource; + return NS_OK; +} + + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) +{ + mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); + } + } + } + } + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) +{ + mHintCharset = aHintCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSet(aHintCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: poor error checking +NS_IMETHODIMP DocumentViewerImpl::SizeToContent() +{ + + // XXX: for now, just call the webshell's SizeToContent + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + return webShell->SizeToContent(); + } + else { + return NS_ERROR_FAILURE; + } + +#ifdef NEW_DOCSHELL_INTERFACES + + // get the presentation shell + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + nsRect shellArea; + PRInt32 width, height; + float pixelScale; + NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE), + NS_ERROR_FAILURE); + + // so how big is it? + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); + presContext->GetVisibleArea(shellArea); + presContext->GetTwipsToPixels(&pixelScale); + width = PRInt32((float)shellArea.width*pixelScale); + height = PRInt32((float)shellArea.height*pixelScale); + + // if we're the outermost webshell for this window, size the window + /* XXX: how do we do this now? + if (mContainer) + { + nsCOMPtr browser = do_QueryInterface(mContainer); + if (browser) + { + nsCOMPtr browserWebShell; + PRInt32 oldX, oldY, oldWidth, oldHeight, + widthDelta, heightDelta; + nsRect windowBounds; + + GetBounds(oldX, oldY, oldWidth, oldHeight); + widthDelta = width - oldWidth; + heightDelta = height - oldHeight; + browser->GetWindowBounds(windowBounds); + browser->SizeWindowTo(windowBounds.width + widthDelta, + windowBounds.height + heightDelta); + } + } + */ + NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; + //return NS_OK; + +#endif + +} diff --git a/mozilla/layout/base/src/nsDocumentViewer.cpp b/mozilla/layout/base/src/nsDocumentViewer.cpp index 3fc6e2f19fe..47599f9427e 100644 --- a/mozilla/layout/base/src/nsDocumentViewer.cpp +++ b/mozilla/layout/base/src/nsDocumentViewer.cpp @@ -24,6 +24,8 @@ #include "nsCRT.h" #include "nsString.h" #include "nsISupports.h" +#include "nsIContent.h" +#include "nsIContentViewerContainer.h" #include "nsIDocumentViewer.h" #include "nsIImageGroup.h" @@ -54,6 +56,9 @@ #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIInterfaceRequestor.h" @@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); #endif class DocumentViewerImpl : public nsIDocumentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile, + public nsIMarkupDocumentViewer, public nsIImageGroupObserver { public: @@ -97,8 +105,6 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(void); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); @@ -110,6 +116,15 @@ public: NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + + // nsIMarkupDocumentViewer + NS_DECL_NSIMARKUPDOCUMENTVIEWER + // nsIImageGroupObserver interface... virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -166,6 +181,17 @@ protected: nsIViewManager *mPrintVM; nsIView *mPrintView; + // document management data + // these items are specific to markup documents (html and xml) + // may consider splitting these out into a subclass + PRBool mAllowPlugins; + PRPackedBool mIsFrame; + /* character set member data */ + nsString mDefaultCharacterSet; + nsString mHintCharset; + nsCharsetSource mHintCharsetSource; + nsString mForceCharacterSet; + }; // Class IDs @@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) : mPresContext(dont_QueryInterface(aPresContext)) { NS_INIT_REFCNT(); + mHintCharset = ""; + mHintCharsetSource = kCharsetUninitialized; + mForceCharacterSet = ""; + mAllowPlugins = PR_TRUE; + mIsFrame = PR_FALSE; } // ISupports implementation... @@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) { + nsIMarkupDocumentViewer* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { nsIContentViewer* tmp1 = this; nsISupports* tmp2 = tmp1; @@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void) return NS_OK; } -static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); -static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); - - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ -NS_IMETHODIMP -DocumentViewerImpl::Print(void) -{ -nsCOMPtr webContainer; -nsCOMPtr factory; -PRInt32 width,height; -nsCOMPtr prefs; - - nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, - nsnull, - kIDeviceContextSpecFactoryIID, - (void **)getter_AddRefs(factory)); - - if (factory) { - -#ifdef DEBUG_dcone - printf("PRINT JOB STARTING\n"); -#endif - - nsIDeviceContextSpec *devspec = nsnull; - nsCOMPtr dx; - mPrintDC = nsnull; - - factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); - if (nsnull != devspec) { - mPresContext->GetDeviceContext(getter_AddRefs(dx)); - nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); - if (NS_SUCCEEDED(rv)) { - - NS_RELEASE(devspec); - - // Get the webshell for this documentviewer - 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)){ - return rv; - } - - mPrintDC->GetDeviceSurfaceDimensions(width,height); - mPresContext->GetPrefs(getter_AddRefs(prefs)); - mPrintPC->Init(mPrintDC,prefs); - CreateStyleSet(mDocument,&mPrintSS); - - rv = NS_NewPresShell(&mPrintPS); - if(NS_FAILED(rv)){ - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); - if(NS_FAILED(rv)) { - return rv; - } - - rv = mPrintVM->Init(mPrintDC); - if(NS_FAILED(rv)) { - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); - if(NS_FAILED(rv)) { - return rv; - } - - nsRect tbounds = nsRect(0,0,width,height); - rv = mPrintView->Init(mPrintVM,tbounds,nsnull); - if(NS_FAILED(rv)) { - return rv; - } - - // setup hierarchical relationship in view manager - mPrintVM->SetRootView(mPrintView); - mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); - - nsCOMPtr imageGroup; - mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); - if (imageGroup) { - imageGroup->AddObserver(this); - } - - mPrintPS->InitialReflow(width,height); - -#ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; - - printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); - - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - - - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrintDC); - mPrintDC->GetDevUnitsToTwips(a1); - mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrintDC->GetAppUnitsToDevUnits(a1); - mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - -#endif - // - // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the - // InitialReflow... - // - if(!mIsPrinting){ - DocumentReadyForPrinting(); -#ifdef DEBUG_dcone - printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); -#endif - } else { - // use the observer mechanism to finish the printing -#ifdef DEBUG_dcone - printf("PRINTING OBSERVER STARTED\n"); -#endif - } - } - } - } - } - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation above in the DocumentViewerImpl class definition - * @update 07/09/99 dwc - */ NS_IMETHODIMP DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) { -nsCOMPtr ss; -nsCOMPtr prefs; -nsCOMPtr vm; -PRInt32 width, height; -nsIView *view; -nsresult rv; -PRInt32 count,i; -nsIWebShell *childWebShell; -nsIContentViewer *viewer; - + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + nsCOMPtr ss; + nsCOMPtr prefs; + nsCOMPtr vm; + PRInt32 width, height; + nsIView *view; + nsresult rv; + PRInt32 count,i; + nsCOMPtr childWebShell; + nsCOMPtr viewer; aParent->GetChildCount(count); if(count> 0) { for(i=0;iChildAt(i,childWebShell); - childWebShell->GetContentViewer(&viewer); - viewer->PrintContent(childWebShell,aDContext); - NS_RELEASE(childWebShell); - NS_RELEASE(viewer); + aParent->ChildAt(i, *(getter_AddRefs(childWebShell))); + childWebShell->GetContentViewer(getter_AddRefs(viewer)); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE); + } } } else { aDContext->BeginDocument(); @@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting() // // Send the document to the printer... // - PrintContent(webContainer,mPrintDC); + nsresult rv = PrintContent(webContainer, mPrintDC); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent"); // printing is complete, clean up now mIsPrinting = PR_FALSE; @@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting() } } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP DocumentViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +DocumentViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID); +static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); + + +/** --------------------------------------------------- + * See documentation above in the DocumentViewerImpl class definition + * @update 07/09/99 dwc + */ +NS_IMETHODIMP +DocumentViewerImpl::Print() +{ +nsCOMPtr webContainer; +nsCOMPtr factory; +PRInt32 width,height; +nsCOMPtr prefs; + + nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, + nsnull, + kIDeviceContextSpecFactoryIID, + (void **)getter_AddRefs(factory)); + + if (factory) { + +#ifdef DEBUG_dcone + printf("PRINT JOB STARTING\n"); +#endif + + nsIDeviceContextSpec *devspec = nsnull; + nsCOMPtr dx; + mPrintDC = nsnull; + + factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE); + if (nsnull != devspec) { + mPresContext->GetDeviceContext(getter_AddRefs(dx)); + nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC); + if (NS_SUCCEEDED(rv)) { + + NS_RELEASE(devspec); + + // Get the webshell for this documentviewer + 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)){ + return rv; + } + + mPrintDC->GetDeviceSurfaceDimensions(width,height); + mPresContext->GetPrefs(getter_AddRefs(prefs)); + mPrintPC->Init(mPrintDC,prefs); + CreateStyleSet(mDocument,&mPrintSS); + + rv = NS_NewPresShell(&mPrintPS); + if(NS_FAILED(rv)){ + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM); + if(NS_FAILED(rv)) { + return rv; + } + + rv = mPrintVM->Init(mPrintDC); + if(NS_FAILED(rv)) { + return rv; + } + + rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView); + if(NS_FAILED(rv)) { + return rv; + } + + nsRect tbounds = nsRect(0,0,width,height); + rv = mPrintView->Init(mPrintVM,tbounds,nsnull); + if(NS_FAILED(rv)) { + return rv; + } + + // setup hierarchical relationship in view manager + mPrintVM->SetRootView(mPrintView); + mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); + + nsCOMPtr imageGroup; + mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); + if (imageGroup) { + imageGroup->AddObserver(this); + } + + mPrintPS->InitialReflow(width,height); + +#ifdef DEBUG_dcone + float a1,a2; + PRInt32 i1,i2; + + printf("CRITICAL PRINTING INFORMATION\n"); + printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", + mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); + + // DEVICE CONTEXT INFORMATION from PresContext + printf("DeviceContext of Presentation Context(%x)\n",dx); + dx->GetDevUnitsToTwips(a1); + dx->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + dx->GetAppUnitsToDevUnits(a1); + dx->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + dx->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + dx->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + dx->GetZoom(a1); + printf(" Zoom = %f\n",a1); + dx->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + dx->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + + + // DEVICE CONTEXT INFORMATION + printf("DeviceContext created for print(%x)\n",mPrintDC); + mPrintDC->GetDevUnitsToTwips(a1); + mPrintDC->GetTwipsToDevUnits(a2); + printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); + mPrintDC->GetAppUnitsToDevUnits(a1); + mPrintDC->GetDevUnitsToAppUnits(a2); + printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); + mPrintDC->GetCanonicalPixelScale(a1); + printf(" GetCanonicalPixelScale = %f\n",a1); + mPrintDC->GetScrollBarDimensions(a1, a2); + printf(" ScrollBar x = %f y = %f\n",a1,a2); + mPrintDC->GetZoom(a1); + printf(" Zoom = %f\n",a1); + mPrintDC->GetDepth((PRUint32&)i1); + printf(" Depth = %d\n",i1); + mPrintDC->GetDeviceSurfaceDimensions(i1,i2); + printf(" DeviceDimension w = %d h = %d\n",i1,i2); + +#endif + // + // The mIsPrinting flag is set when the ImageGroup observer is + // notified that images must be loaded as a result of the + // InitialReflow... + // + if(!mIsPrinting){ + DocumentReadyForPrinting(); +#ifdef DEBUG_dcone + printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); +#endif + } else { + // use the observer mechanism to finish the printing +#ifdef DEBUG_dcone + printf("PRINTING OBSERVER STARTED\n"); +#endif + } + } + } + } + } + return NS_OK; +} + + +NS_IMETHODIMP +DocumentViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_TRUE; + return NS_OK; +} + + +//***************************************************************************** +// nsIMarkupDocumentViewer +//***************************************************************************** + +NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) +{ + NS_ENSURE_ARG(aNode); + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + + // Get the nsIContent interface, because that's what we need to + // get the primary frame + + nsCOMPtr content(do_QueryInterface(aNode)); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + + // Get the primary frame + nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their + // own special little world. + + NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), + NS_ERROR_FAILURE); + + // tell the pres shell to scroll to the frame + NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, + NS_PRESSHELL_SCROLL_TOP, + NS_PRESSHELL_SCROLL_ANYWHERE), + NS_ERROR_FAILURE); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) +{ + NS_ENSURE_ARG_POINTER(aAllowPlugins); + + *aAllowPlugins = mAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) +{ + mAllowPlugins = aAllowPlugins; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame) +{ + NS_ENSURE_ARG_POINTER(aIsFrame); + + *aIsFrame = mIsFrame; + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame) +{ + mIsFrame = aIsFrame; + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aDefaultCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); + NS_ENSURE_STATE(mContainer); + + static char *gDefCharset = nsnull; // XXX: memory leak! + + if (0 == mDefaultCharacterSet.Length()) + { + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + { + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr prefs; + NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE); + if(prefs) + prefs->CopyCharPref("intl.charset.default", &gDefCharset); + } + } + if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) + mDefaultCharacterSet = "ISO-8859-1"; + else + mDefaultCharacterSet = gDefCharset; + } + *aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) +{ + mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet + // now set the default char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aForceCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aForceCharacterSet); + + nsAutoString emptyStr; + if (mForceCharacterSet.Equals(emptyStr)) { + *aForceCharacterSet = nsnull; + } + else { + *aForceCharacterSet = mForceCharacterSet.ToNewUnicode(); + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) +{ + mForceCharacterSet = aForceCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetForceCharacterSet(aForceCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: SEMANTIC CHANGE! +// returns a copy of the string. Caller is responsible for freeing result +// using Recycle(aHintCharacterSet) +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSet); + + if(kCharsetUninitialized == mHintCharsetSource) { + *aHintCharacterSet = nsnull; + } else { + *aHintCharacterSet = mHintCharset.ToNewUnicode(); + // this can't possibly be right. we can't set a value just because somebody got a related value! + //mHintCharsetSource = kCharsetUninitialized; + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) +{ + NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); + + *aHintCharacterSetSource = mHintCharsetSource; + return NS_OK; +} + + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) +{ + mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); + } + } + } + } + } + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) +{ + mHintCharset = aHintCharacterSet; + // now set the force char set on all children of mContainer + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + nsCOMPtr childWebShell; + PRInt32 i; + PRInt32 n; + webShell->GetChildCount(n); + for (i=0; i < n; i++) + { + webShell->ChildAt(i, *(getter_AddRefs(childWebShell))); + NS_WARN_IF_FALSE(childWebShell, "null child in docshell"); + if (childWebShell) + { + nsCOMPtr childCV; + childWebShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + markupCV->SetHintCharacterSet(aHintCharacterSet); + } + } + } + } + } + return NS_OK; +} + +// XXX: poor error checking +NS_IMETHODIMP DocumentViewerImpl::SizeToContent() +{ + + // XXX: for now, just call the webshell's SizeToContent + nsCOMPtr webShell; + webShell = do_QueryInterface(mContainer); + if (webShell) + { + return webShell->SizeToContent(); + } + else { + return NS_ERROR_FAILURE; + } + +#ifdef NEW_DOCSHELL_INTERFACES + + // get the presentation shell + nsCOMPtr presShell; + NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + nsRect shellArea; + PRInt32 width, height; + float pixelScale; + NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE), + NS_ERROR_FAILURE); + + // so how big is it? + nsCOMPtr presContext; + NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))), + NS_ERROR_FAILURE); + NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); + presContext->GetVisibleArea(shellArea); + presContext->GetTwipsToPixels(&pixelScale); + width = PRInt32((float)shellArea.width*pixelScale); + height = PRInt32((float)shellArea.height*pixelScale); + + // if we're the outermost webshell for this window, size the window + /* XXX: how do we do this now? + if (mContainer) + { + nsCOMPtr browser = do_QueryInterface(mContainer); + if (browser) + { + nsCOMPtr browserWebShell; + PRInt32 oldX, oldY, oldWidth, oldHeight, + widthDelta, heightDelta; + nsRect windowBounds; + + GetBounds(oldX, oldY, oldWidth, oldHeight); + widthDelta = width - oldWidth; + heightDelta = height - oldHeight; + browser->GetWindowBounds(windowBounds); + browser->SizeWindowTo(windowBounds.width + widthDelta, + windowBounds.height + heightDelta); + } + } + */ + NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; + //return NS_OK; + +#endif + +} diff --git a/mozilla/layout/base/src/nsPluginViewer.cpp b/mozilla/layout/base/src/nsPluginViewer.cpp index 2238533c8e6..20726f093e0 100644 --- a/mozilla/layout/base/src/nsPluginViewer.cpp +++ b/mozilla/layout/base/src/nsPluginViewer.cpp @@ -33,6 +33,8 @@ #include "nsWidgetsCID.h" #include "nsILinkHandler.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" #include "nsIBrowserWindow.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -110,7 +112,9 @@ private: PluginViewerImpl *mViewer; //we do not addref this... }; -class PluginViewerImpl : public nsIContentViewer +class PluginViewerImpl : public nsIContentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile { public: PluginViewerImpl(const char* aCommand); @@ -136,11 +140,15 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + virtual ~PluginViewerImpl(); nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, @@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } if (aIID.Equals(kISupportsIID)) { - nsISupports* tmp = this; - *aInstancePtr = (void*)tmp; + nsIContentViewer* tmp1 = this; + nsISupports* tmp2 = tmp1; + *aInstancePtr = (void*) tmp2; NS_ADDREF_THIS(); return NS_OK; } @@ -489,23 +498,6 @@ PluginViewerImpl::Hide() return NS_OK; } -NS_IMETHODIMP -PluginViewerImpl::Print(void) -{ - // need to call the plugin from here somehow - - return NS_OK; -} - - -NS_IMETHODIMP -PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) -{ - - return NS_OK; -} - - NS_IMETHODIMP PluginViewerImpl::SetEnableRendering(PRBool aOn) { @@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument) return NS_OK; } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP PluginViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +PluginViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::Print() +{ + return NS_OK; // XXX: hey, plug in guys! implement me! +} + + +NS_IMETHODIMP +PluginViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me! + return NS_OK; +} + + +NS_IMETHODIMP +PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext) +{ + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + return NS_OK; +} + + //---------------------------------------------------------------------- PluginListener::PluginListener(PluginViewerImpl* aViewer) diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 5b5ed08856c..7f8a070b16b 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -24,6 +24,8 @@ #include "nsHTMLContainerFrame.h" #include "nsIHTMLContent.h" #include "nsIWebShell.h" +#include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsHTMLIIDs.h" @@ -692,8 +694,6 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, nsCompatibility mode; aPresContext.GetCompatibilityMode(&mode); mWebShell->SetScrolling(GetScrolling(content, mode)); - mWebShell->SetIsFrame(PR_TRUE); - nsString frameName; if (GetName(content, frameName)) { mWebShell->SetName(frameName.GetUnicode()); @@ -875,6 +875,18 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext& aPresContext, TempMakeAbsURL(content, url, absURL); rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data + if (NS_SUCCEEDED(rv)) + { // tell the content viewer that it's an HTML frame + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) + { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) { + muCV->SetIsFrame(PR_TRUE); + } + } + } } } else { mCreatingViewer = PR_TRUE; diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 5b5ed08856c..7f8a070b16b 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -24,6 +24,8 @@ #include "nsHTMLContainerFrame.h" #include "nsIHTMLContent.h" #include "nsIWebShell.h" +#include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsHTMLIIDs.h" @@ -692,8 +694,6 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, nsCompatibility mode; aPresContext.GetCompatibilityMode(&mode); mWebShell->SetScrolling(GetScrolling(content, mode)); - mWebShell->SetIsFrame(PR_TRUE); - nsString frameName; if (GetName(content, frameName)) { mWebShell->SetName(frameName.GetUnicode()); @@ -875,6 +875,18 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext& aPresContext, TempMakeAbsURL(content, url, absURL); rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data + if (NS_SUCCEEDED(rv)) + { // tell the content viewer that it's an HTML frame + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) + { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) { + muCV->SetIsFrame(PR_TRUE); + } + } + } } } else { mCreatingViewer = PR_TRUE; diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 5f71ab07968..0a055c9c5a2 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -33,6 +33,7 @@ #include "nsIPresContext.h" #include "nsIViewManager.h" #include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsHTMLTokens.h" #include "nsHTMLEntities.h" #include "nsCRT.h" @@ -2694,7 +2695,16 @@ HTMLContentSink::StartLayout() } else if (mBody) { PRBool isFrameDoc = PR_FALSE; - mWebShell->GetIsFrame(isFrameDoc); + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) + { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) + { + muCV->GetIsFrame(&isFrameDoc); + } + } // a webshell will have its scrolling set by the parent nsFramesetFrame. // a webshell is reset here just for safety. if (!isFrameDoc) { diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 940649d1b31..d0dae82c3f1 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -49,6 +49,9 @@ #include "nsIIOService.h" #include "nsIURL.h" #include "nsNeckoUtil.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIWebShell.h" #include "nsIWebShellServices.h" #include "nsIDocumentLoader.h" @@ -392,7 +395,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, return rv; } - nsIWebShell* webShell; + nsCOMPtr webShell; nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error nsCharsetSource charsetSource = kCharsetFromWeakDocTypeDefault; @@ -503,7 +506,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, if (NS_OK == rv) { nsIHTMLContentSink* sink; - const PRUnichar* requestCharset = nsnull; + PRUnichar* requestCharset = nsnull; nsCharsetSource requestCharsetSource = kCharsetUninitialized; nsIParserFilter *cdetflt = nsnull; @@ -513,104 +516,123 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0); #else NS_PRECONDITION(nsnull != aContainer, "No content viewer container"); - aContainer->QueryInterface(kIWebShellIID, (void**)&webShell); + aContainer->QueryInterface(kIWebShellIID, getter_AddRefs(webShell)); rv = NS_NewHTMLContentSink(&sink, this, aURL, webShell); - if (NS_SUCCEEDED(rv)) { - if(kCharsetFromUserDefault > charsetSource) { - const PRUnichar* defaultCharsetFromWebShell = NULL; - rv = webShell->GetDefaultCharacterSet(&defaultCharsetFromWebShell); - if(NS_SUCCEEDED(rv)) { - charset = defaultCharsetFromWebShell; - charsetSource = kCharsetFromUserDefault; - } - } - // for html, we need to find out the Meta tag from the hint. - rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource); - if(NS_SUCCEEDED(rv)) { - if(requestCharsetSource > charsetSource) - { - charsetSource = requestCharsetSource; - charset = requestCharset; - } - } - if(kCharsetFromPreviousLoading > charsetSource) - { - const PRUnichar* forceCharsetFromWebShell = NULL; - rv = webShell->GetForceCharacterSet(&forceCharsetFromWebShell); - if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) { - charset = forceCharsetFromWebShell; - //TODO: we should define appropriate constant for force charset - charsetSource = kCharsetFromPreviousLoading; - } - } - nsresult rv_detect = NS_OK; - if(! gInitDetector) - { - nsIPref* pref = nsnull; - if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref) - { - - char* detector_name = nsnull; - if(NS_SUCCEEDED( + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr muCV; + nsCOMPtr cv; + webShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + muCV = do_QueryInterface(cv); + } + if(kCharsetFromUserDefault > charsetSource) + { + PRUnichar* defaultCharsetFromWebShell = NULL; + if (muCV) { + rv = muCV->GetDefaultCharacterSet(&defaultCharsetFromWebShell); + } + if(NS_SUCCEEDED(rv)) { + charset = defaultCharsetFromWebShell; + Recycle(defaultCharsetFromWebShell); + charsetSource = kCharsetFromUserDefault; + } + // for html, we need to find out the Meta tag from the hint. + if (muCV) { + rv = muCV->GetHintCharacterSet(&requestCharset); + if(NS_SUCCEEDED(rv)) { + rv = muCV->GetHintCharacterSetSource((PRInt32*)(&requestCharsetSource)); + } + } + if(NS_SUCCEEDED(rv)) + { + if(requestCharsetSource > charsetSource) + { + charsetSource = requestCharsetSource; + charset = requestCharset; + Recycle(requestCharset); + } + } + if(kCharsetFromPreviousLoading > charsetSource) + { + PRUnichar* forceCharsetFromWebShell = NULL; + if (muCV) { + rv = muCV->GetForceCharacterSet(&forceCharsetFromWebShell); + } + if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) + { + charset = forceCharsetFromWebShell; + Recycle(forceCharsetFromWebShell); + //TODO: we should define appropriate constant for force charset + charsetSource = kCharsetFromPreviousLoading; + } + } + nsresult rv_detect = NS_OK; + if(! gInitDetector) + { + nsIPref* pref = nsnull; + if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref) + { + char* detector_name = nsnull; + if(NS_SUCCEEDED( rv_detect = pref->CopyCharPref("intl.charset.detector", &detector_name))) - { - PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX); - PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX); - gPlugDetector = PR_TRUE; - PR_FREEIF(detector_name); - } - pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull); - } - NS_IF_RELEASE(pref); - gInitDetector = PR_TRUE; - } + { + PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX); + PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX); + gPlugDetector = PR_TRUE; + PR_FREEIF(detector_name); + } + pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull); + } + NS_IF_RELEASE(pref); + gInitDetector = PR_TRUE; + } - if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector) - { - // we could do charset detection - - nsICharsetDetector *cdet = nsnull; - nsIWebShellServices *wss = nsnull; - nsICharsetDetectionAdaptor *adp = nsnull; + if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector) + { + // we could do charset detection + nsICharsetDetector *cdet = nsnull; + nsIWebShellServices *wss = nsnull; + nsICharsetDetectionAdaptor *adp = nsnull; - if(NS_SUCCEEDED( rv_detect = + if(NS_SUCCEEDED( rv_detect = nsComponentManager::CreateInstance(g_detector_progid, nsnull, nsICharsetDetector::GetIID(), (void**)&cdet))) - { - - if(NS_SUCCEEDED( rv_detect = + { + if(NS_SUCCEEDED( rv_detect = nsComponentManager::CreateInstance( NS_CHARSET_DETECTION_ADAPTOR_PROGID, nsnull, kIParserFilterIID, (void**)&cdetflt))) - { - if(cdetflt && + { + if(cdetflt && NS_SUCCEEDED( rv_detect= cdetflt->QueryInterface( nsICharsetDetectionAdaptor::GetIID(),(void**) &adp))) - { - if( NS_SUCCEEDED( rv_detect= + { + if( NS_SUCCEEDED( rv_detect= webShell->QueryInterface( nsIWebShellServices::GetIID(),(void**) &wss))) - { - rv_detect = adp->Init(wss, cdet, aCommand); - } - } + { + rv_detect = adp->Init(wss, cdet, aCommand); + } } - } else { - // IF we cannot create the detector, don't bother to - // create one next time. - - gPlugDetector = PR_FALSE; - } - NS_IF_RELEASE(wss); - NS_IF_RELEASE(cdet); - NS_IF_RELEASE(adp); - // NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter - } + } + } + else + { + // IF we cannot create the detector, don't bother to + // create one next time. + gPlugDetector = PR_FALSE; + } + NS_IF_RELEASE(wss); + NS_IF_RELEASE(cdet); + NS_IF_RELEASE(adp); + // NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter + } + } } - NS_IF_RELEASE(webShell); #endif if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/layout/xml/document/src/nsXMLDocument.cpp b/mozilla/layout/xml/document/src/nsXMLDocument.cpp index c633af515bb..670e693c612 100644 --- a/mozilla/layout/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/layout/xml/document/src/nsXMLDocument.cpp @@ -29,7 +29,10 @@ #include "nsIXMLContentSink.h" #include "nsIPresShell.h" #include "nsIPresContext.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" #include "nsIWebShell.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIDocumentLoader.h" #include "nsIHTMLContent.h" #include "nsHTMLParts.h" @@ -263,20 +266,31 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, rv = aContainer->QueryInterface(kIWebShellIID, (void**)&webShell); if(NS_SUCCEEDED(rv) && (nsnull != webShell)) { - if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source - const PRUnichar* hintCharset = nsnull; - nsCharsetSource hintSource = kCharsetUninitialized; - rv = webShell->GetCharacterSetHint(&hintCharset, &hintSource); - if(NS_SUCCEEDED(rv)) { - if(hintSource > charsetSource) { - charset = hintCharset; - charsetSource = hintSource; + nsCOMPtr cv; + webShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + nsCOMPtr muCV = do_QueryInterface(cv); + if (muCV) { + if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source + PRUnichar* hintCharset = nsnull; + nsCharsetSource hintSource = kCharsetUninitialized; + rv = muCV->GetHintCharacterSet(&hintCharset); + if(NS_SUCCEEDED(rv)) { + rv = muCV->GetHintCharacterSetSource((PRInt32 *)(&hintSource)); + if(NS_SUCCEEDED(rv)) { + if(hintSource > charsetSource) { + charset = hintCharset; + Recycle(hintCharset); + charsetSource = hintSource; + } } - } - } - if(NS_SUCCEEDED(rv)) - rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell); - NS_IF_RELEASE(webShell); + } + } + } + } + if(NS_SUCCEEDED(rv)) + rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell); + NS_IF_RELEASE(webShell); } if (NS_OK == rv) { diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 2238533c8e6..20726f093e0 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -33,6 +33,8 @@ #include "nsWidgetsCID.h" #include "nsILinkHandler.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" #include "nsIBrowserWindow.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -110,7 +112,9 @@ private: PluginViewerImpl *mViewer; //we do not addref this... }; -class PluginViewerImpl : public nsIContentViewer +class PluginViewerImpl : public nsIContentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile { public: PluginViewerImpl(const char* aCommand); @@ -136,11 +140,15 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + virtual ~PluginViewerImpl(); nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, @@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } if (aIID.Equals(kISupportsIID)) { - nsISupports* tmp = this; - *aInstancePtr = (void*)tmp; + nsIContentViewer* tmp1 = this; + nsISupports* tmp2 = tmp1; + *aInstancePtr = (void*) tmp2; NS_ADDREF_THIS(); return NS_OK; } @@ -489,23 +498,6 @@ PluginViewerImpl::Hide() return NS_OK; } -NS_IMETHODIMP -PluginViewerImpl::Print(void) -{ - // need to call the plugin from here somehow - - return NS_OK; -} - - -NS_IMETHODIMP -PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) -{ - - return NS_OK; -} - - NS_IMETHODIMP PluginViewerImpl::SetEnableRendering(PRBool aOn) { @@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument) return NS_OK; } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP PluginViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +PluginViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::Print() +{ + return NS_OK; // XXX: hey, plug in guys! implement me! +} + + +NS_IMETHODIMP +PluginViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me! + return NS_OK; +} + + +NS_IMETHODIMP +PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext) +{ + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + return NS_OK; +} + + //---------------------------------------------------------------------- PluginListener::PluginListener(PluginViewerImpl* aViewer) diff --git a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp index 2238533c8e6..20726f093e0 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginViewer.cpp @@ -33,6 +33,8 @@ #include "nsWidgetsCID.h" #include "nsILinkHandler.h" #include "nsIWebShell.h" +#include "nsIContentViewerEdit.h" +#include "nsIContentViewerFile.h" #include "nsIBrowserWindow.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -110,7 +112,9 @@ private: PluginViewerImpl *mViewer; //we do not addref this... }; -class PluginViewerImpl : public nsIContentViewer +class PluginViewerImpl : public nsIContentViewer, + public nsIContentViewerEdit, + public nsIContentViewerFile { public: PluginViewerImpl(const char* aCommand); @@ -136,11 +140,15 @@ public: NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Show(); NS_IMETHOD Hide(); - NS_IMETHOD Print(); - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext); NS_IMETHOD SetEnableRendering(PRBool aOn); NS_IMETHOD GetEnableRendering(PRBool* aResult); + // nsIContentViewerEdit + NS_DECL_NSICONTENTVIEWEREDIT + + // nsIContentViewerFile + NS_DECL_NSICONTENTVIEWERFILE + virtual ~PluginViewerImpl(); nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, @@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } if (aIID.Equals(kISupportsIID)) { - nsISupports* tmp = this; - *aInstancePtr = (void*)tmp; + nsIContentViewer* tmp1 = this; + nsISupports* tmp2 = tmp1; + *aInstancePtr = (void*) tmp2; NS_ADDREF_THIS(); return NS_OK; } @@ -489,23 +498,6 @@ PluginViewerImpl::Hide() return NS_OK; } -NS_IMETHODIMP -PluginViewerImpl::Print(void) -{ - // need to call the plugin from here somehow - - return NS_OK; -} - - -NS_IMETHODIMP -PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) -{ - - return NS_OK; -} - - NS_IMETHODIMP PluginViewerImpl::SetEnableRendering(PRBool aOn) { @@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument) return NS_OK; } +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ + +NS_IMETHODIMP PluginViewerImpl::Search() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::ClearSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::SelectAll() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CopySelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::CutSelection() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::Paste() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* ======================================================================================== + * nsIContentViewerEdit + * ======================================================================================== */ +NS_IMETHODIMP +PluginViewerImpl::Save() +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::GetSaveable(PRBool *aSaveable) +{ + NS_ASSERTION(0, "NOT IMPLEMENTED"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +PluginViewerImpl::Print() +{ + return NS_OK; // XXX: hey, plug in guys! implement me! +} + + +NS_IMETHODIMP +PluginViewerImpl::GetPrintable(PRBool *aPrintable) +{ + NS_ENSURE_ARG_POINTER(aPrintable); + + *aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me! + return NS_OK; +} + + +NS_IMETHODIMP +PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext) +{ + NS_ENSURE_ARG_POINTER(aParent); + NS_ENSURE_ARG_POINTER(aDContext); + + return NS_OK; +} + + //---------------------------------------------------------------------- PluginListener::PluginListener(PluginViewerImpl* aViewer) diff --git a/mozilla/webshell/public/MANIFEST b/mozilla/webshell/public/MANIFEST index 89524f31c8e..e50772daad9 100644 --- a/mozilla/webshell/public/MANIFEST +++ b/mozilla/webshell/public/MANIFEST @@ -15,3 +15,6 @@ nsIUrlDispatcher.h nsIWebShell.h nsIWebShellServices.h nsweb.h +nsIContentViewerEdit.h +nsIContentViewerFile.h +nsIMarkupDocumentViewer.h diff --git a/mozilla/webshell/public/Makefile.in b/mozilla/webshell/public/Makefile.in index a5e191a4131..7a29ce0d01a 100644 --- a/mozilla/webshell/public/Makefile.in +++ b/mozilla/webshell/public/Makefile.in @@ -42,6 +42,9 @@ EXPORTS = \ nsIWebShellServices.h \ nsweb.h \ nsIRefreshURI.h \ + nsIContentViewerEdit.h \ + nsIContentViewerFile.h \ + nsIMarkupDocumentViewer.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/webshell/public/makefile.win b/mozilla/webshell/public/makefile.win index 7467ac6517a..a79143dc528 100644 --- a/mozilla/webshell/public/makefile.win +++ b/mozilla/webshell/public/makefile.win @@ -43,6 +43,9 @@ EXPORTS = \ !ifdef NECKO nsIRefreshURI.h \ !endif + nsIContentViewerEdit.h \ + nsIContentViewerFile.h \ + nsIMarkupDocumentViewer.h \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/webshell/public/nsIContentViewer.h b/mozilla/webshell/public/nsIContentViewer.h index edad4bb3b4e..4fd2d46252f 100644 --- a/mozilla/webshell/public/nsIContentViewer.h +++ b/mozilla/webshell/public/nsIContentViewer.h @@ -79,26 +79,6 @@ public: NS_IMETHOD Hide(void) = 0; - /** - * Top lever print for the Content viewer, - * this is called by the chrome, etc for printing this Content view - * @update 05/13/99 dwc - * @return Success or failure of the routine - */ - NS_IMETHOD Print(void) = 0; - - /** - * Prints the actual content only if the container WebShell is a leaf.. - * If it is not a leaf node, it will visit all the childern and call the PrintConent for each child. - * this method should only be called by the Print or PrintContext, so it is not really used by any - * embedding application or object, etc. - * @update 05/13/99 dwc - * @param aParent -- Parent WebShell of this ContentViewer - * @param aDCContext -- The device context to use for printing. - * @return Success or failure of the routine - */ - NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) = 0; - NS_IMETHOD SetEnableRendering(PRBool aOn) = 0; NS_IMETHOD GetEnableRendering(PRBool* aResult) = 0; diff --git a/mozilla/webshell/public/nsIContentViewerEdit.h b/mozilla/webshell/public/nsIContentViewerEdit.h new file mode 100644 index 00000000000..4f182480f31 --- /dev/null +++ b/mozilla/webshell/public/nsIContentViewerEdit.h @@ -0,0 +1,81 @@ +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIContentViewerEdit.idl + */ + +#ifndef __gen_nsIContentViewerEdit_h__ +#define __gen_nsIContentViewerEdit_h__ + +#include "nsISupports.h" +#include "nsrootidl.h" + +/* starting interface: nsIContentViewerEdit */ + +#define NS_ICONTENTVIEWEREDIT_IID_STR "42d5215c-9bc7-11d3-bccc-0060b0fc76bd" + +#define NS_ICONTENTVIEWEREDIT_IID \ + {0x42d5215c, 0x9bc7, 0x11d3, \ + { 0xbc, 0xcc, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xbd }} + +class nsIContentViewerEdit : public nsISupports { + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTVIEWEREDIT_IID) + + /* void Search (); */ + NS_IMETHOD Search(void) = 0; + + /* readonly attribute boolean searchable; */ + NS_IMETHOD GetSearchable(PRBool *aSearchable) = 0; + + /* void ClearSelection (); */ + NS_IMETHOD ClearSelection(void) = 0; + + /* void SelectAll (); */ + NS_IMETHOD SelectAll(void) = 0; + + /* void CopySelection (); */ + NS_IMETHOD CopySelection(void) = 0; + + /* readonly attribute boolean copyable; */ + NS_IMETHOD GetCopyable(PRBool *aCopyable) = 0; + + /* void CutSelection (); */ + NS_IMETHOD CutSelection(void) = 0; + + /* readonly attribute boolean cutable; */ + NS_IMETHOD GetCutable(PRBool *aCutable) = 0; + + /* void Paste (); */ + NS_IMETHOD Paste(void) = 0; + + /* readonly attribute boolean pasteable; */ + NS_IMETHOD GetPasteable(PRBool *aPasteable) = 0; +}; + +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSICONTENTVIEWEREDIT \ + NS_IMETHOD Search(void); \ + NS_IMETHOD GetSearchable(PRBool *aSearchable); \ + NS_IMETHOD ClearSelection(void); \ + NS_IMETHOD SelectAll(void); \ + NS_IMETHOD CopySelection(void); \ + NS_IMETHOD GetCopyable(PRBool *aCopyable); \ + NS_IMETHOD CutSelection(void); \ + NS_IMETHOD GetCutable(PRBool *aCutable); \ + NS_IMETHOD Paste(void); \ + NS_IMETHOD GetPasteable(PRBool *aPasteable); + +/* Use this macro to declare functions that forward the behavior of this interface to another object. */ +#define NS_FORWARD_NSICONTENTVIEWEREDIT(_to) \ + NS_IMETHOD Search(void) { return _to ## Search(); } \ + NS_IMETHOD GetSearchable(PRBool *aSearchable) { return _to ## GetSearchable(aSearchable); } \ + NS_IMETHOD ClearSelection(void) { return _to ## ClearSelection(); } \ + NS_IMETHOD SelectAll(void) { return _to ## SelectAll(); } \ + NS_IMETHOD CopySelection(void) { return _to ## CopySelection(); } \ + NS_IMETHOD GetCopyable(PRBool *aCopyable) { return _to ## GetCopyable(aCopyable); } \ + NS_IMETHOD CutSelection(void) { return _to ## CutSelection(); } \ + NS_IMETHOD GetCutable(PRBool *aCutable) { return _to ## GetCutable(aCutable); } \ + NS_IMETHOD Paste(void) { return _to ## Paste(); } \ + NS_IMETHOD GetPasteable(PRBool *aPasteable) { return _to ## GetPasteable(aPasteable); } + + +#endif /* __gen_nsIContentViewerEdit_h__ */ diff --git a/mozilla/webshell/public/nsIContentViewerFile.h b/mozilla/webshell/public/nsIContentViewerFile.h new file mode 100644 index 00000000000..a07ef4c3dba --- /dev/null +++ b/mozilla/webshell/public/nsIContentViewerFile.h @@ -0,0 +1,58 @@ +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIContentViewerFile.idl + */ + +#ifndef __gen_nsIContentViewerFile_h__ +#define __gen_nsIContentViewerFile_h__ + +#include "nsISupports.h" +#include "nsrootidl.h" +#include "nsIWebShell.h" +#include "nsIDeviceContext.h" + +/* starting interface: nsIContentViewerFile */ + +#define NS_ICONTENTVIEWERFILE_IID_STR "6317f32c-9bc7-11d3-bccc-0060b0fc76bd" + +#define NS_ICONTENTVIEWERFILE_IID \ + {0x6317f32c, 0x9bc7, 0x11d3, \ + { 0xbc, 0xcc, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xbd }} + +class nsIContentViewerFile : public nsISupports { + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTVIEWERFILE_IID) + + /* void Save (); */ + NS_IMETHOD Save(void) = 0; + + /* readonly attribute boolean saveable; */ + NS_IMETHOD GetSaveable(PRBool *aSaveable) = 0; + + /* void Print (); */ + NS_IMETHOD Print(void) = 0; + + /* [noscript] void PrintContent (in nsIWebShell parent, in nsIDeviceContext DContext); */ + NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext) = 0; + + /* readonly attribute boolean printable; */ + NS_IMETHOD GetPrintable(PRBool *aPrintable) = 0; +}; + +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSICONTENTVIEWERFILE \ + NS_IMETHOD Save(void); \ + NS_IMETHOD GetSaveable(PRBool *aSaveable); \ + NS_IMETHOD Print(void); \ + NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext); \ + NS_IMETHOD GetPrintable(PRBool *aPrintable); + +/* Use this macro to declare functions that forward the behavior of this interface to another object. */ +#define NS_FORWARD_NSICONTENTVIEWERFILE(_to) \ + NS_IMETHOD Save(void) { return _to ## Save(); } \ + NS_IMETHOD GetSaveable(PRBool *aSaveable) { return _to ## GetSaveable(aSaveable); } \ + NS_IMETHOD Print(void) { return _to ## Print(); } \ + NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext) { return _to ## PrintContent(parent, DContext); } \ + NS_IMETHOD GetPrintable(PRBool *aPrintable) { return _to ## GetPrintable(aPrintable); } + + +#endif /* __gen_nsIContentViewerFile_h__ */ diff --git a/mozilla/webshell/public/nsIMarkupDocumentViewer.h b/mozilla/webshell/public/nsIMarkupDocumentViewer.h new file mode 100644 index 00000000000..02a1bcb8d3e --- /dev/null +++ b/mozilla/webshell/public/nsIMarkupDocumentViewer.h @@ -0,0 +1,90 @@ +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIMarkupDocumentViewer.idl + */ + +#ifndef __gen_nsIMarkupDocumentViewer_h__ +#define __gen_nsIMarkupDocumentViewer_h__ + +#include "nsISupports.h" +#include "domstubs.h" +#include "nsrootidl.h" + +/* starting interface: nsIMarkupDocumentViewer */ + +#define NS_IMARKUPDOCUMENTVIEWER_IID_STR "69e5de03-7b8b-11d3-af61-00a024ffc08c" + +#define NS_IMARKUPDOCUMENTVIEWER_IID \ + {0x69e5de03, 0x7b8b, 0x11d3, \ + { 0xaf, 0x61, 0x00, 0xa0, 0x24, 0xff, 0xc0, 0x8c }} + +class nsIMarkupDocumentViewer : public nsISupports { + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMARKUPDOCUMENTVIEWER_IID) + + /* void scrollToNode (in nsIDOMNode node); */ + NS_IMETHOD ScrollToNode(nsIDOMNode *node) = 0; + + /* attribute boolean allowPlugins; */ + NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins) = 0; + NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins) = 0; + + /* attribute boolean isFrame; */ + NS_IMETHOD GetIsFrame(PRBool *aIsFrame) = 0; + NS_IMETHOD SetIsFrame(PRBool aIsFrame) = 0; + + /* attribute wstring defaultCharacterSet; */ + NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet) = 0; + NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet) = 0; + + /* attribute wstring forceCharacterSet; */ + NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet) = 0; + NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet) = 0; + + /* attribute wstring hintCharacterSet; */ + NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet) = 0; + NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet) = 0; + + /* attribute PRInt32 hintCharacterSetSource; */ + NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) = 0; + NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) = 0; + + /* void sizeToContent (); */ + NS_IMETHOD SizeToContent(void) = 0; +}; + +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSIMARKUPDOCUMENTVIEWER \ + NS_IMETHOD ScrollToNode(nsIDOMNode *node); \ + NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins); \ + NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins); \ + NS_IMETHOD GetIsFrame(PRBool *aIsFrame); \ + NS_IMETHOD SetIsFrame(PRBool aIsFrame); \ + NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet); \ + NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet); \ + NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet); \ + NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet); \ + NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet); \ + NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet); \ + NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource); \ + NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource); \ + NS_IMETHOD SizeToContent(void); + +/* Use this macro to declare functions that forward the behavior of this interface to another object. */ +#define NS_FORWARD_NSIMARKUPDOCUMENTVIEWER(_to) \ + NS_IMETHOD ScrollToNode(nsIDOMNode *node) { return _to ## ScrollToNode(node); } \ + NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins) { return _to ## GetAllowPlugins(aAllowPlugins); } \ + NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins) { return _to ## SetAllowPlugins(aAllowPlugins); } \ + NS_IMETHOD GetIsFrame(PRBool *aIsFrame) { return _to ## GetIsFrame(aIsFrame); } \ + NS_IMETHOD SetIsFrame(PRBool aIsFrame) { return _to ## SetIsFrame(aIsFrame); } \ + NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet) { return _to ## GetDefaultCharacterSet(aDefaultCharacterSet); } \ + NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet) { return _to ## SetDefaultCharacterSet(aDefaultCharacterSet); } \ + NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet) { return _to ## GetForceCharacterSet(aForceCharacterSet); } \ + NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet) { return _to ## SetForceCharacterSet(aForceCharacterSet); } \ + NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet) { return _to ## GetHintCharacterSet(aHintCharacterSet); } \ + NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet) { return _to ## SetHintCharacterSet(aHintCharacterSet); } \ + NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) { return _to ## GetHintCharacterSetSource(aHintCharacterSetSource); } \ + NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) { return _to ## SetHintCharacterSetSource(aHintCharacterSetSource); } \ + NS_IMETHOD SizeToContent(void) { return _to ## SizeToContent(); } + + +#endif /* __gen_nsIMarkupDocumentViewer_h__ */ diff --git a/mozilla/webshell/public/nsIWebShell.h b/mozilla/webshell/public/nsIWebShell.h index a7dc13e82a1..7735030c0eb 100644 --- a/mozilla/webshell/public/nsIWebShell.h +++ b/mozilla/webshell/public/nsIWebShell.h @@ -24,11 +24,11 @@ #include "nsweb.h" #include "nsIWidget.h" +#include "nsIParser.h" #include "nsIScrollableView.h" #include "nsIContentViewerContainer.h" #include "nsIChannel.h" #include "nsIScrollableView.h" -#include "nsIParser.h" // for nsCharsetSource only #include "nsISessionHistory.h" #include "nsIUrlDispatcher.h" @@ -175,11 +175,6 @@ public: */ NS_IMETHOD SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) = 0; - /** - * Shrink-to-fit the WebShell to its contents - */ - NS_IMETHOD SizeToContent() = 0; - NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY) = 0; /** @@ -423,13 +418,20 @@ public: // SetStatusBar NS_IMETHOD SetContentViewer(nsIContentViewer* aViewer) = 0; - // XXX these are here until there a better way to pass along info to a sub doc - NS_IMETHOD GetMarginWidth (PRInt32& aWidth) = 0; - NS_IMETHOD SetMarginWidth (PRInt32 aWidth) = 0; - NS_IMETHOD GetMarginHeight(PRInt32& aWidth) = 0; - NS_IMETHOD SetMarginHeight(PRInt32 aHeight) = 0; NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE) = 0; NS_IMETHOD GetScrolling(PRInt32& aScrolling) = 0; + + + + // XXX these are here until there a better way to pass along info to a sub doc + NS_IMETHOD GetMarginWidth (PRInt32* aWidth) = 0; + NS_IMETHOD SetMarginWidth (PRInt32 aWidth) = 0; + NS_IMETHOD GetMarginHeight(PRInt32* aWidth) = 0; + NS_IMETHOD SetMarginHeight(PRInt32 aHeight) = 0; + + /* ============ moved to nsIMarkupDocumentViewer =================== */ + /* + NS_IMETHOD SetIsFrame(PRBool aIsFrame) = 0; NS_IMETHOD GetIsFrame(PRBool& aIsFrame) = 0; @@ -439,9 +441,15 @@ public: NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet) = 0; NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet) = 0; - /* the following is the hacky access method */ + // the following is the hacky access method NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource) = 0; + + */ + + // XXX this will go away, replaced by a new content viewer method + NS_IMETHOD SizeToContent() = 0; + /** * Set/Get the document scale factor */ diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 8208a23c61c..a6b3bf28553 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -24,6 +24,7 @@ #include "nsIDocumentLoader.h" #include "nsIContentViewer.h" #include "nsIDocumentViewer.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIClipboardCommands.h" #include "nsIDeviceContext.h" #include "nsILinkHandler.h" @@ -225,14 +226,14 @@ public: NS_IMETHOD GetContainingChromeElement(nsIContent** aResult); NS_IMETHOD SetContainingChromeElement(nsIContent* aChromeElement); - NS_IMETHOD GetMarginWidth (PRInt32& aWidth); - NS_IMETHOD SetMarginWidth (PRInt32 aWidth); - NS_IMETHOD GetMarginHeight(PRInt32& aWidth); - NS_IMETHOD SetMarginHeight(PRInt32 aHeight); NS_IMETHOD GetScrolling(PRInt32& aScrolling); NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE); - NS_IMETHOD GetIsFrame(PRBool& aIsFrame); - NS_IMETHOD SetIsFrame(PRBool aIsFrame); + + NS_IMETHOD GetMarginWidth (PRInt32* aWidth); + NS_IMETHOD SetMarginWidth (PRInt32 aWidth); + NS_IMETHOD GetMarginHeight(PRInt32* aWidth); + NS_IMETHOD SetMarginHeight(PRInt32 aHeight); + NS_IMETHOD SetZoom(float aZoom); NS_IMETHOD GetZoom(float *aZoom); @@ -402,13 +403,6 @@ public: nsresult DestroyPluginHost(void); NS_IMETHOD IsBusy(PRBool& aResult); - NS_IMETHOD GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet); - NS_IMETHOD SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet); - - NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet); - NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet); - - NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource); NS_IMETHOD SetSessionHistory(nsISessionHistory * aSHist); NS_IMETHOD GetSessionHistory(nsISessionHistory *& aResult); @@ -464,12 +458,13 @@ protected: nsString mOverTarget; PRPackedBool mIsInSHist; - PRPackedBool mIsFrame; PRPackedBool mFailedToLoadHistoryService; nsScrollPreference mScrollPref; + PRInt32 mMarginWidth; PRInt32 mMarginHeight; + PRInt32 mScrolling[2]; nsVoidArray mRefreshments; @@ -507,11 +502,14 @@ protected: PRBool mProcessedEndDocumentLoad; // XXX store mHintCharset and mHintCharsetSource here untill we find out a good cood path + /* nsString mHintCharset; nsCharsetSource mHintCharsetSource; - PRBool mViewSource; nsString mForceCharacterSet; + */ + PRBool mViewSource; + // if there is no mWindow, this will keep track of the bounds --dwc0001 nsRect mBounds; @@ -657,7 +655,6 @@ nsWebShell::nsWebShell() mScriptContext = nsnull; mThreadEventQueue = nsnull; InitFrameData(PR_TRUE); - mIsFrame = PR_FALSE; mWebShellType = nsWebShellContent; mChromeElement = nsnull; mSHist = nsnull; @@ -665,11 +662,8 @@ nsWebShell::nsWebShell() mFailedToLoadHistoryService = PR_FALSE; mDefaultCharacterSet = ""; mProcessedEndDocumentLoad = PR_FALSE; - mHintCharset = ""; - mHintCharsetSource = kCharsetUninitialized; mCharsetReloadState = eCharsetReloadInit; mViewSource=PR_FALSE; - mForceCharacterSet = ""; mHistoryService = nsnull; mHistoryState = nsnull; mParentContentListener = nsnull; @@ -713,7 +707,6 @@ nsWebShell::~nsWebShell() } InitFrameData(PR_TRUE); - mIsFrame = PR_FALSE; // XXX Because we hold references to the children and they hold references // to us we never get destroyed. See Destroy() instead... @@ -747,8 +740,8 @@ void nsWebShell::InitFrameData(PRBool aCompleteInitScrolling) if (aCompleteInitScrolling) { mScrolling[0] = -1; mScrolling[1] = -1; - mMarginWidth = -1; - mMarginHeight = -1; + SetMarginWidth(-1); + SetMarginHeight(-1); } else { mScrolling[1] = mScrolling[0]; @@ -838,6 +831,41 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer, ("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p", this, aContentViewer, aCommand ? aCommand : "", aExtraInfo)); + if (mContentViewer && (eCharsetReloadInit!=mCharsetReloadState)) + { // get any interesting state from the old content viewer + // XXX: it would be far better to just reuse the document viewer , + // since we know we're just displaying the same document as before + PRUnichar *defaultCharset=nsnull; + PRUnichar *forceCharset=nsnull; + PRUnichar *hintCharset=nsnull; + PRInt32 hintCharsetSource; + + nsCOMPtr oldMUDV = do_QueryInterface(mContentViewer); + nsCOMPtr newMUDV = do_QueryInterface(aContentViewer); + if (oldMUDV && newMUDV) + { + NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE); + + // set the old state onto the new content viewer + NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE); + + if (defaultCharSet) { + Recycle(defaultCharSet); + } + if (forceCharset) { + Recycle(forceCharset); + } + if (hintCharset) { + Recycle(hintCharset); + } + } + } NS_IF_RELEASE(mContentViewer); if (nsnull != mScriptContext) { mScriptContext->GC(); @@ -1586,10 +1614,30 @@ nsWebShell::AddChild(nsIWebShell* aChild) } mChildren.AppendElement(aChild); aChild->SetParent(this); - const PRUnichar *defaultCharset=nsnull; - if(NS_SUCCEEDED(this->GetDefaultCharacterSet (&defaultCharset))) - aChild->SetDefaultCharacterSet(defaultCharset); - aChild->SetForceCharacterSet(mForceCharacterSet.GetUnicode()); + PRUnichar *defaultCharset=nsnull; + PRUnichar *forceCharset=nsnull; + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE); + } + nsCOMPtr childCV; + NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE); + if (childCV) + { + nsCOMPtr childmuDV = do_QueryInterface(cv); + if (childmuDV) + { + childmuDV->SetDefaultCharacterSet(defaultCharset); + childmuDV->SetForceCharacterSet(forceCharset); + } + } + } NS_ADDREF(aChild); return NS_OK; @@ -1736,9 +1784,11 @@ nsWebShell::SetContainingChromeElement(nsIContent* aChromeElement) } NS_IMETHODIMP -nsWebShell::GetMarginWidth(PRInt32& aWidth) +nsWebShell::GetMarginWidth(PRInt32* aWidth) { - aWidth = mMarginWidth; + NS_ENSURE_ARG_POINTER(aWidth); + + *aWidth = mMarginWidth; return NS_OK; } @@ -1750,9 +1800,11 @@ nsWebShell::SetMarginWidth(PRInt32 aWidth) } NS_IMETHODIMP -nsWebShell::GetMarginHeight(PRInt32& aHeight) +nsWebShell::GetMarginHeight(PRInt32* aHeight) { - aHeight = mMarginHeight; + NS_ENSURE_ARG_POINTER(aHeight); + + *aHeight = mMarginHeight; return NS_OK; } @@ -1780,20 +1832,6 @@ nsWebShell::SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial) return NS_OK; } -NS_IMETHODIMP -nsWebShell::GetIsFrame(PRBool& aIsFrame) -{ - aIsFrame = mIsFrame; - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::SetIsFrame(PRBool aIsFrame) -{ - mIsFrame = aIsFrame; - return NS_OK; -} - NS_IMETHODIMP nsWebShell::SetZoom(float aZoom) { @@ -1944,6 +1982,7 @@ nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode) if (!doc) { return NS_ERROR_OUT_OF_MEMORY; } NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE); doc->SetRootContent(rootContent); + rootContent->SetDocument(doc, PR_TRUE); // (6) reflow the document SetScrolling(-1, PR_FALSE); @@ -2960,16 +2999,27 @@ nsWebShell::LoadDocument(const char* aURL, nsCharsetSource aSource) { // XXX hack. kee the aCharset and aSource wait to pick it up - if( aSource > mHintCharsetSource ) { - mHintCharset = aCharset; - mHintCharsetSource = aSource; - if(eCharsetReloadRequested != mCharsetReloadState) + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) { - - mCharsetReloadState = eCharsetReloadRequested; - - nsAutoString url(aURL); - LoadURL(url.GetUnicode()); + nsCharsetSource hint; + muDV->GetHintCharacterSetSource((PRInt32 *)(&hint)); + if( aSource > hint ) + { + nsAutoString inputCharSet(aCharset); + muDV->SetHintCharacterSet(inputCharSet.GetUnicode()); + muDV->SetHintCharacterSetSource((PRInt32)aSource); + if(eCharsetReloadRequested != mCharsetReloadState) + { + mCharsetReloadState = eCharsetReloadRequested; + nsAutoString url(aURL); + LoadURL(url.GetUnicode()); + } + } } } return NS_OK; @@ -2982,15 +3032,28 @@ nsWebShell::ReloadDocument(const char* aCharset, { // XXX hack. kee the aCharset and aSource wait to pick it up - if( aSource > mHintCharsetSource ) { - mHintCharset = aCharset; - mHintCharsetSource = aSource; - mViewSource = (0==PL_strcmp("view-source", aCmd)); - if(eCharsetReloadRequested != mCharsetReloadState) - { - mCharsetReloadState = eCharsetReloadRequested; - return Reload(nsIChannel::LOAD_NORMAL); - } + nsCOMPtr cv; + NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); + if (cv) + { + nsCOMPtr muDV = do_QueryInterface(cv); + if (muDV) + { + nsCharsetSource hint; + muDV->GetHintCharacterSetSource((PRInt32 *)(&hint)); + if( aSource > hint ) + { + nsAutoString inputCharSet(aCharset); + muDV->SetHintCharacterSet(inputCharSet.GetUnicode()); + muDV->SetHintCharacterSetSource((PRInt32)aSource); + mViewSource = (0==PL_strcmp("view-source", aCmd)); + if(eCharsetReloadRequested != mCharsetReloadState) + { + mCharsetReloadState = eCharsetReloadRequested; + return Reload(nsIChannel::LOAD_NORMAL); + } + } + } } return NS_OK; } @@ -4185,77 +4248,6 @@ nsWebShell::SelectNone(void) return NS_ERROR_FAILURE; } -static char *gDefCharset = nsnull; - -NS_IMETHODIMP -nsWebShell::GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet) -{ - if (0 == mDefaultCharacterSet.Length()) { - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) { - if(mPrefs) - mPrefs->CopyCharPref("intl.charset.default", &gDefCharset); - } - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - mDefaultCharacterSet = "ISO-8859-1"; - else - mDefaultCharacterSet = gDefCharset; - } - *aDefaultCharacterSet = mDefaultCharacterSet.GetUnicode(); - return NS_OK; -} -NS_IMETHODIMP -nsWebShell::SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet) -{ - mDefaultCharacterSet = aDefaultCharacterSet; - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i); - if (nsnull != child) { - child->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::GetForceCharacterSet (const PRUnichar** aForceCharacterSet) -{ - nsAutoString emptyStr; - if (mForceCharacterSet.Equals(emptyStr)) { - *aForceCharacterSet = nsnull; - } - else { - *aForceCharacterSet = mForceCharacterSet.GetUnicode(); - } - return NS_OK; -} - -NS_IMETHODIMP -nsWebShell::SetForceCharacterSet (const PRUnichar* aForceCharacterSet) -{ - mForceCharacterSet = aForceCharacterSet; - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i); - if (nsnull != child) { - child->SetForceCharacterSet(aForceCharacterSet); - } - } - return NS_OK; -} - -NS_IMETHODIMP nsWebShell::GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource) -{ - *oSource = mHintCharsetSource; - if(kCharsetUninitialized == mHintCharsetSource) { - *oHintCharset = nsnull; - } else { - *oHintCharset = mHintCharset.GetUnicode(); - mHintCharsetSource = kCharsetUninitialized; - } - return NS_OK; -} - //---------------------------------------------------- NS_IMETHODIMP diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index 0b779f4b3c3..668941e7750 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -56,6 +56,7 @@ #include "nsLayoutCID.h" #include "nsIDocumentViewer.h" #include "nsIContentViewer.h" +#include "nsIContentViewerFile.h" #include "nsIPresShell.h" #include "nsIPresContext.h" #include "nsIDocument.h" @@ -2373,7 +2374,10 @@ void nsBrowserWindow::DoPrint(void) if (viewer) { - viewer->Print(); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + viewerFile->Print(); + } } } diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index cd3cd860613..e421aefd7c5 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -26,6 +26,7 @@ #include "nsIBrowserWindow.h" #include "nsIWebShell.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIClipboardCommands.h" #include "pratom.h" #include "prprf.h" @@ -94,6 +95,7 @@ static NS_DEFINE_IID(kWalletServiceCID, NS_WALLETSERVICE_CID); #include "nsIXULWindowCallbacks.h" #include "nsIDocumentObserver.h" #include "nsIContent.h" +#include "nsIContentViewerFile.h" #include "nsINameSpaceManager.h" #include "nsFileStream.h" @@ -167,6 +169,7 @@ nsBrowserAppCore::~nsBrowserAppCore() NS_IMPL_ADDREF(nsBrowserAppCore) NS_IMPL_RELEASE(nsBrowserAppCore) + NS_IMPL_QUERY_HEAD(nsBrowserAppCore) NS_IMPL_QUERY_BODY(nsIBrowserInstance) NS_IMPL_QUERY_BODY(nsIDocumentLoaderObserver) @@ -174,6 +177,7 @@ NS_IMPL_QUERY_HEAD(nsBrowserAppCore) NS_IMPL_QUERY_BODY(nsIURIContentListener) NS_IMPL_QUERY_TAIL(nsIBrowserInstance) + static nsIPresShell* GetPresShellFor(nsIWebShell* aWebShell) @@ -237,14 +241,20 @@ nsBrowserAppCore::SetDocumentCharset(const PRUnichar *aCharset) return NS_ERROR_FAILURE; } - nsIWebShell * webShell; - globalObj->GetWebShell(&webShell); - if (nsnull != webShell) { - webShell->SetDefaultCharacterSet( aCharset ); - - NS_RELEASE(webShell); + nsCOMPtr webShell; + globalObj->GetWebShell(getter_AddRefs(webShell)); + if (webShell) + { + nsCOMPtr childCV; + NS_ENSURE_SUCCESS(webShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + NS_ENSURE_SUCCESS(markupCV->SetDefaultCharacterSet(aCharset), NS_ERROR_FAILURE); + } + } } - return NS_OK; } @@ -1904,14 +1914,14 @@ nsBrowserAppCore::Copy() NS_IMETHODIMP nsBrowserAppCore::Print() { - if (nsnull != mContentAreaWebShell) { - nsIContentViewer *viewer = nsnull; - - mContentAreaWebShell->GetContentViewer(&viewer); - + if (mContentAreaWebShell) { + nsCOMPtr viewer; + mWebShell->GetContentViewer(getter_AddRefs(viewer)); if (nsnull != viewer) { - viewer->Print(); - NS_RELEASE(viewer); + nsCOMPtr viewerFile = do_QueryInterface(viewer); + if (viewerFile) { + NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE); + } } } return NS_OK;