DocShell cleanup. Removed the implementation of the unused nsIDocSHell::SetDocument() method and moved the implementation responsibility to the nsIContentViewer

This commit is contained in:
rpotts%netscape.com 2000-06-22 05:38:07 +00:00
Родитель be4230ee79
Коммит cf3e824449
11 изменённых файлов: 180 добавлений и 557 удалений

Просмотреть файл

@ -192,7 +192,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget,
return rv;
}
NS_IMETHODIMP
DocumentViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Stop(void)
{
@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument.get(), aResult);
}
NS_IMETHODIMP
DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet)
{

Просмотреть файл

@ -268,109 +268,11 @@ NS_IMETHODIMP nsDocShell::StopLoad()
return NS_OK;
}
// SetDocument is only meaningful for doc shells that support DOM documents. Not all do.
NS_IMETHODIMP
nsDocShell::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<nsIContentViewer> documentViewer;
nsCOMPtr<nsIDocumentLoaderFactory> docFactory;
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull,
NS_GET_IID(nsIDocumentLoaderFactory),
(void**)getter_AddRefs(docFactory)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, this),
doc,
"view",
getter_AddRefs(documentViewer)),
NS_ERROR_FAILURE);
// (2) Feed the docshell to the content viewer
NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIDocShell*)this),
NS_ERROR_FAILURE);
// (3) Tell the content viewer container to setup the content viewer.
// (This step causes everything to be set up for an initial flow.)
NS_ENSURE_SUCCESS(SetupNewViewer(documentViewer), NS_ERROR_FAILURE);
// XXX: It would be great to get rid of this dummy channel!
nsCOMPtr<nsIURI> uri;
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIChannel> dummyChannel;
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE);
// (4) fire start document load notification
nsCOMPtr<nsIStreamListener> outStreamListener;
NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view", dummyChannel, nsnull,
NS_STATIC_CAST(nsIContentViewerContainer*, this),
getter_AddRefs(outStreamListener), PR_TRUE), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(FireStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE);
// (5) hook up the document and its content
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(aRootNode);
NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE);
doc->SetRootContent(rootContent);
// (6) reflow the document
PRInt32 i;
PRInt32 ns = doc->GetNumberOfShells();
for (i = 0; i < ns; i++)
{
nsCOMPtr<nsIPresShell> 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<nsIDocumentViewer> docViewer = do_QueryInterface(documentViewer);
NS_ENSURE_TRUE(docViewer, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(docViewer->GetPresContext(*(getter_AddRefs(presContext))), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presContext, 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<nsIViewManager> vm;
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE);
if (vm)
{
PRBool enabled;
documentViewer->GetEnableRendering(&enabled);
if (enabled) {
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
}
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;
NS_ENSURE_SUCCESS(FireEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately
return NS_OK;
/* XXX: This method is obsolete and will be removed. */
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocShell::GetCurrentURI(nsIURI** aURI)
@ -1207,17 +1109,7 @@ NS_IMETHODIMP nsDocShell::GetDocument(nsIDOMDocument** aDocument)
NS_ENSURE_ARG_POINTER(aDocument);
NS_ENSURE_STATE(mContentViewer);
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument>doc;
NS_ENSURE_SUCCESS(docv->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.get(), aDocument), NS_ERROR_FAILURE);
return NS_OK;
return mContentViewer->GetDOMDocument(aDocument);
}
NS_IMETHODIMP nsDocShell::GetCurrentURI(PRUnichar** aCurrentURI)
@ -3702,206 +3594,6 @@ NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment()
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::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<nsIDocumentViewer> docViewer;
if (mScriptGlobal && (aLoader == mDocLoader.get()))
{
docViewer = do_QueryInterface(mContentViewer);
if (docViewer)
{
nsCOMPtr<nsIPresContext> 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.get())
{
nsCOMPtr<nsIDocumentLoaderObserver> 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<nsIDocShellTreeItem> rootTreeItem;
NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> rootAsDocShell(do_QueryInterface(rootTreeItem));
if(rootAsDocShell)
NS_ENSURE_SUCCESS(rootAsDocShell->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
nsDocShell::FireEndDocumentLoad(nsIDocumentLoader* aLoader,
nsIChannel * aChannel,
nsresult aStatus)
{
NS_ENSURE_ARG_POINTER(aLoader);
NS_ENSURE_ARG_POINTER(aChannel);
nsCOMPtr<nsIURI> aURL;
NS_ENSURE_SUCCESS(aChannel->GetURI(getter_AddRefs(aURL)), NS_ERROR_FAILURE);
if (aLoader == mDocLoader.get())
{
if (mScriptGlobal && mContentViewer)
{
nsCOMPtr<nsIDocumentViewer> docViewer;
docViewer = do_QueryInterface(mContentViewer);
if (docViewer)
{
nsCOMPtr<nsIPresContext> 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<nsIDocumentLoaderObserver> 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<nsIDocShellTreeItem> rootTreeItem;
NS_ENSURE_SUCCESS(GetSameTypeRootTreeItem(getter_AddRefs(rootTreeItem)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> rootAsDocShell(do_QueryInterface(rootTreeItem));
if(rootAsDocShell)
NS_ENSURE_SUCCESS(rootAsDocShell->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),
NS_ERROR_FAILURE);
}
/* put the new document in the doc tree */
NS_ENSURE_SUCCESS(InsertDocumentInDocTree(), NS_ERROR_FAILURE);
}
return NS_OK;
}
NS_IMETHODIMP nsDocShell::InsertDocumentInDocTree()
{
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(mParent));
if(parent)
{
// Get the document object for the parent
nsCOMPtr<nsIContentViewer> parentContentViewer;
NS_ENSURE_SUCCESS(parent->GetContentViewer(getter_AddRefs(parentContentViewer)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(parentContentViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentViewer> parentDocViewer;
parentDocViewer = do_QueryInterface(parentContentViewer);
NS_ENSURE_TRUE(parentDocViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> 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<nsIDocumentViewer> docViewer;
docViewer = do_QueryInterface(mContentViewer);
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> 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;
}
PRBool nsDocShell::IsFrame()
{
if(mParent)

Просмотреть файл

@ -235,17 +235,6 @@ protected:
NS_IMETHOD EnsureContentListener();
NS_IMETHOD EnsureScriptEnvironment();
NS_IMETHOD FireStartDocumentLoad(nsIDocumentLoader* aLoader,
nsIURI* aURL,
const char* aCommand);
NS_IMETHOD FireEndDocumentLoad(nsIDocumentLoader* aLoader,
nsIChannel* aChannel,
nsresult aStatus);
NS_IMETHOD InsertDocumentInDocTree();
PRBool IsFrame();
protected:

Просмотреть файл

@ -280,9 +280,6 @@ public:
NS_IMETHOD GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
PRInt32* cy);
// nsIDocShell
NS_IMETHOD SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode);
// nsWebShell
nsIEventQueue* GetEventQueue(void);
void HandleLinkClickEvent(nsIContent *aContent,
@ -1617,119 +1614,6 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* x, PRInt32* y,
}
//*****************************************************************************
// nsWebShell::nsIDocShell
//*****************************************************************************
NS_IMETHODIMP nsWebShell::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<nsIContentViewer> documentViewer;
nsCOMPtr<nsIDocumentLoaderFactory> docFactory;
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull,
NS_GET_IID(nsIDocumentLoaderFactory),
(void**)getter_AddRefs(docFactory)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
if (!doc) { return NS_ERROR_NULL_POINTER; }
NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
doc,
"view",
getter_AddRefs(documentViewer)),
NS_ERROR_FAILURE);
// (2) Feed the webshell to the content viewer
NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIWebShell*)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(SetupNewViewer(documentViewer), NS_ERROR_FAILURE);
// XXX: It would be great to get rid of this dummy channel!
nsCOMPtr<nsIURI> uri;
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE);
if (!uri) { return NS_ERROR_OUT_OF_MEMORY; }
nsCOMPtr<nsIChannel> dummyChannel;
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE);
// (4) fire start document load notification
nsCOMPtr<nsIStreamListener> outStreamListener; // a valid pointer is required for the returned stream listener
// XXX: warning: magic cookie! should get string "view delayedContentLoad"
// from somewhere, maybe nsIHTMLDocument?
NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view delayedContentLoad",
dummyChannel,
nsnull,
NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
getter_AddRefs(outStreamListener),
PR_TRUE),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(OnStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE);
// (5) hook up the document and its content
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(aRootNode);
if (!doc) { return NS_ERROR_OUT_OF_MEMORY; }
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE);
doc->SetRootContent(rootContent);
rootContent->SetDocument(doc, PR_TRUE, PR_TRUE);
// (6) reflow the document
PRInt32 i;
PRInt32 ns = doc->GetNumberOfShells();
for (i = 0; i < ns; i++)
{
nsCOMPtr<nsIPresShell> 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<nsIDocumentViewer> docViewer = do_QueryInterface(documentViewer);
if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; }
nsCOMPtr<nsIPresContext> 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;
GetPositionAndSize(&r.x, &r.y, &r.width, &r.height);
NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE);
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE);
if (vm)
{
PRBool enabled;
documentViewer->GetEnableRendering(&enabled);
if (enabled) {
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
}
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;
NS_ENSURE_SUCCESS(OnEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately
return NS_OK;
}
//----------------------------------------------------------------------
// Factory code for creating nsWebShell's

Просмотреть файл

@ -192,7 +192,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget,
return rv;
}
NS_IMETHODIMP
DocumentViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Stop(void)
{
@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument.get(), aResult);
}
NS_IMETHODIMP
DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet)
{

Просмотреть файл

@ -192,7 +192,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -621,6 +625,18 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget,
return rv;
}
NS_IMETHODIMP
DocumentViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::Stop(void)
{
@ -634,6 +650,18 @@ DocumentViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument.get(), aResult);
}
NS_IMETHODIMP
DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet)
{

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIWebBrowserChrome.h"
#include "nsIDOMDocument.h"
// Class IDs
static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID);
@ -133,7 +134,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument, aResult);
}
NS_IMETHODIMP
PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
static nsEventStatus PR_CALLBACK
HandlePluginEvent(nsGUIEvent *aEvent)
{
return nsEventStatus_eIgnore;
}
nsresult
PluginViewerImpl::MakeWindow(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext,

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIWebBrowserChrome.h"
#include "nsIDOMDocument.h"
// Class IDs
static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID);
@ -133,7 +134,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument, aResult);
}
NS_IMETHODIMP
PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
static nsEventStatus PR_CALLBACK
HandlePluginEvent(nsGUIEvent *aEvent)
{
return nsEventStatus_eIgnore;
}
nsresult
PluginViewerImpl::MakeWindow(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext,

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIWebBrowserChrome.h"
#include "nsIDOMDocument.h"
// Class IDs
static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID);
@ -133,7 +134,11 @@ public:
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsISupports* aContainer);
NS_IMETHOD GetContainer(nsISupports** aContainerResult);
NS_IMETHOD LoadComplete(nsresult aStatus);
NS_IMETHOD Destroy(void);
NS_IMETHOD Stop(void);
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult);
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetBounds(nsRect& aResult);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -382,12 +387,35 @@ PluginViewerImpl::Stop(void)
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::LoadComplete(nsresult aStatus)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::Destroy(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
PluginViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
return CallQueryInterface(mDocument, aResult);
}
NS_IMETHODIMP
PluginViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
return NS_ERROR_FAILURE;
}
static nsEventStatus PR_CALLBACK
HandlePluginEvent(nsGUIEvent *aEvent)
{
return nsEventStatus_eIgnore;
}
nsresult
PluginViewerImpl::MakeWindow(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext,

Просмотреть файл

@ -31,6 +31,7 @@ class nsIDeviceContext;
class nsString;
struct nsRect;
class nsIContentViewerContainer;
class nsIDOMDocument;
// IID for the nsIContentViewer interface
#define NS_ICONTENT_VIEWER_IID \
@ -61,8 +62,13 @@ public:
NS_IMETHOD GetContainer(nsISupports** aContainerResult) = 0;
NS_IMETHOD LoadComplete(nsresult aStatus) = 0;
NS_IMETHOD Destroy(void) = 0;
NS_IMETHOD Stop(void) = 0;
NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult) = 0;
NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument) = 0;
NS_IMETHOD GetBounds(nsRect& aBounds) = 0;
NS_IMETHOD SetBounds(const nsRect& aBounds) = 0;

Просмотреть файл

@ -280,9 +280,6 @@ public:
NS_IMETHOD GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx,
PRInt32* cy);
// nsIDocShell
NS_IMETHOD SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode);
// nsWebShell
nsIEventQueue* GetEventQueue(void);
void HandleLinkClickEvent(nsIContent *aContent,
@ -1617,119 +1614,6 @@ NS_IMETHODIMP nsWebShell::GetPositionAndSize(PRInt32* x, PRInt32* y,
}
//*****************************************************************************
// nsWebShell::nsIDocShell
//*****************************************************************************
NS_IMETHODIMP nsWebShell::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<nsIContentViewer> documentViewer;
nsCOMPtr<nsIDocumentLoaderFactory> docFactory;
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull,
NS_GET_IID(nsIDocumentLoaderFactory),
(void**)getter_AddRefs(docFactory)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
if (!doc) { return NS_ERROR_NULL_POINTER; }
NS_ENSURE_SUCCESS(docFactory->CreateInstanceForDocument(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
doc,
"view",
getter_AddRefs(documentViewer)),
NS_ERROR_FAILURE);
// (2) Feed the webshell to the content viewer
NS_ENSURE_SUCCESS(documentViewer->SetContainer((nsIWebShell*)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(SetupNewViewer(documentViewer), NS_ERROR_FAILURE);
// XXX: It would be great to get rid of this dummy channel!
nsCOMPtr<nsIURI> uri;
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_ConvertASCIItoUCS2("about:blank")), NS_ERROR_FAILURE);
if (!uri) { return NS_ERROR_OUT_OF_MEMORY; }
nsCOMPtr<nsIChannel> dummyChannel;
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(dummyChannel), uri, nsnull), NS_ERROR_FAILURE);
// (4) fire start document load notification
nsCOMPtr<nsIStreamListener> outStreamListener; // a valid pointer is required for the returned stream listener
// XXX: warning: magic cookie! should get string "view delayedContentLoad"
// from somewhere, maybe nsIHTMLDocument?
NS_ENSURE_SUCCESS(doc->StartDocumentLoad("view delayedContentLoad",
dummyChannel,
nsnull,
NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this),
getter_AddRefs(outStreamListener),
PR_TRUE),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(OnStartDocumentLoad(mDocLoader, uri, "load"), NS_ERROR_FAILURE);
// (5) hook up the document and its content
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(aRootNode);
if (!doc) { return NS_ERROR_OUT_OF_MEMORY; }
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE, PR_TRUE), NS_ERROR_FAILURE);
doc->SetRootContent(rootContent);
rootContent->SetDocument(doc, PR_TRUE, PR_TRUE);
// (6) reflow the document
PRInt32 i;
PRInt32 ns = doc->GetNumberOfShells();
for (i = 0; i < ns; i++)
{
nsCOMPtr<nsIPresShell> 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<nsIDocumentViewer> docViewer = do_QueryInterface(documentViewer);
if (!docViewer) { return NS_ERROR_OUT_OF_MEMORY; }
nsCOMPtr<nsIPresContext> 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;
GetPositionAndSize(&r.x, &r.y, &r.width, &r.height);
NS_ENSURE_SUCCESS(shell->InitialReflow(NSToCoordRound(r.width * p2t), NSToCoordRound(r.height * p2t)), NS_ERROR_FAILURE);
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
NS_ENSURE_SUCCESS(shell->GetViewManager(getter_AddRefs(vm)), NS_ERROR_FAILURE);
if (vm)
{
PRBool enabled;
documentViewer->GetEnableRendering(&enabled);
if (enabled) {
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
}
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;
NS_ENSURE_SUCCESS(OnEndDocumentLoad(mDocLoader, dummyChannel, rv), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // test the resulting out-param separately
return NS_OK;
}
//----------------------------------------------------------------------
// Factory code for creating nsWebShell's