diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 2acda513009..9c0708aa20c 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -38,7 +38,7 @@ class nsIURL; class nsIViewManager; class nsString; class nsIScriptContextOwner; -class nsIWebWidget; +class nsIViewerContainer; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; @@ -72,7 +72,7 @@ public: virtual nsIArena* GetArena() = 0; NS_IMETHOD StartDocumentLoad(nsIURL *aUrl, - nsIWebWidget* aWebWidget, + nsIViewerContainer* aContainer, nsIStreamListener **aDocListener) = 0; /** diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 25d61368d08..c8ca6113133 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -22,8 +22,7 @@ #include "nsIHTMLDocument.h" class nsIHTMLStyleSheet; -class nsIViewDocument; -class nsIWebWidget; +class nsIViewerContainer; class nsHTMLDocument : public nsDocument { public: @@ -33,7 +32,7 @@ public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD StartDocumentLoad(nsIURL* aUrl, - nsIWebWidget* aWebWidget, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener); NS_IMETHOD SetTitle(const nsString& aTitle); diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index 2acda513009..9c0708aa20c 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.h @@ -38,7 +38,7 @@ class nsIURL; class nsIViewManager; class nsString; class nsIScriptContextOwner; -class nsIWebWidget; +class nsIViewerContainer; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; @@ -72,7 +72,7 @@ public: virtual nsIArena* GetArena() = 0; NS_IMETHOD StartDocumentLoad(nsIURL *aUrl, - nsIWebWidget* aWebWidget, + nsIViewerContainer* aContainer, nsIStreamListener **aDocListener) = 0; /** diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h index 25d61368d08..c8ca6113133 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsHTMLDocument.h @@ -22,8 +22,7 @@ #include "nsIHTMLDocument.h" class nsIHTMLStyleSheet; -class nsIViewDocument; -class nsIWebWidget; +class nsIViewerContainer; class nsHTMLDocument : public nsDocument { public: @@ -33,7 +32,7 @@ public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD StartDocumentLoad(nsIURL* aUrl, - nsIWebWidget* aWebWidget, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener); NS_IMETHOD SetTitle(const nsString& aTitle); diff --git a/mozilla/layout/html/tests/TestAttributes.cpp b/mozilla/layout/html/tests/TestAttributes.cpp index 029d7bd5cdd..188cc3124a8 100644 --- a/mozilla/layout/html/tests/TestAttributes.cpp +++ b/mozilla/layout/html/tests/TestAttributes.cpp @@ -29,7 +29,7 @@ #include "nsISupportsArray.h" #include "nsDocument.h" #include "nsIURL.h" -#include "nsIWebWidget.h" +#include "nsIDocumentWidget.h" void testAttributes(nsIHTMLContent* content) { nsIAtom* sBORDER = NS_NewAtom("BORDER"); @@ -169,7 +169,7 @@ class MyDocument : public nsDocument { public: MyDocument(); NS_IMETHOD StartDocumentLoad(nsIURL *aUrl, - nsIWebWidget* aWebWidget, + nsIViewerContainer* aContainer, nsIStreamListener **aDocListener) { return NS_OK; diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index 5012097aaef..20a548d2c96 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -90,9 +90,10 @@ public: NS_IMETHOD CreateInstance(nsIURL* aURL, const char* aContentType, - const char *aCommand, + const char* aCommand, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener, - nsIDocumentWidget** aDocViewer); + nsIContentViewer** aDocViewer); }; @@ -113,12 +114,13 @@ NS_IMETHODIMP nsDocFactoryImpl::CreateInstance(nsIURL* aURL, const char* aContentType, const char *aCommand, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener, - nsIDocumentWidget** aDocViewer) + nsIContentViewer** aDocViewer) { nsresult rv; nsIDocument* doc = nsnull; - nsIWebWidget* ww = nsnull; + nsIWebWidgetViewer* ww = nsnull; int typeIndex=0; while(gValidTypes[typeIndex]) { @@ -140,7 +142,7 @@ nextstep: /* * Create the HTML Content Viewer... */ - rv = NS_NewWebWidget(&ww); + rv = NS_NewContentViewer(&ww); if (NS_OK != rv) { goto done; } @@ -151,7 +153,7 @@ nextstep: * An nsIStreamListener connected to the parser is returned in * aDocListener. */ - rv = doc->StartDocumentLoad(aURL, ww, aDocListener); + rv = doc->StartDocumentLoad(aURL, aContainer, aDocListener); if (NS_OK != rv) { goto done; } @@ -403,7 +405,7 @@ NS_METHOD nsDocumentBindInfo::OnProgress(nsIURL* aURL, PRInt32 aProgress, NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentType) { nsresult rv = NS_OK; - nsIDocumentWidget* viewer = nsnull; + nsIContentViewer* viewer = nsnull; /* * Now that the content type is available, create a document (and viewer) @@ -413,6 +415,7 @@ NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentT rv = m_DocLoader->m_DocFactory->CreateInstance(m_Url, aContentType, m_Command, + m_Container, &m_NextStream, &viewer); } else { @@ -426,6 +429,8 @@ NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentT /* * Give the document container the new viewer... */ + viewer->SetContainer(m_Container); + rv = m_Container->Embed(viewer, m_Command, m_ExtraInfo); if (NS_OK != rv) { goto done; diff --git a/mozilla/webshell/public/nsIDocumentLoader.h b/mozilla/webshell/public/nsIDocumentLoader.h index 8b523b3f73f..1ed9a7dbcc2 100644 --- a/mozilla/webshell/public/nsIDocumentLoader.h +++ b/mozilla/webshell/public/nsIDocumentLoader.h @@ -29,7 +29,8 @@ class nsString; class nsIURL; class nsIFactory; class nsIPostData; -class nsIDocumentWidget; +class nsIContentViewer; +class nsIViewerContainer; class nsIStreamListener; class nsIStreamObserver; @@ -49,8 +50,9 @@ public: NS_IMETHOD CreateInstance(nsIURL* aURL, const char* aContentType, const char *aCommand, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener, - nsIDocumentWidget** aDocViewer) = 0; + nsIContentViewer** aDocViewer) = 0; }; @@ -68,7 +70,9 @@ class nsIViewerContainer : public nsISupports { public: - NS_IMETHOD Embed(nsIDocumentWidget* aDocViewer, + NS_IMETHOD QueryCapability(const nsIID &aIID, void** aResult) = 0; + + NS_IMETHOD Embed(nsIContentViewer* aDocViewer, const char* aCommand, nsISupports* aExtraInfo) = 0; }; diff --git a/mozilla/webshell/public/nsIDocumentWidget.h b/mozilla/webshell/public/nsIDocumentWidget.h index f550b024097..86d8240f470 100644 --- a/mozilla/webshell/public/nsIDocumentWidget.h +++ b/mozilla/webshell/public/nsIDocumentWidget.h @@ -18,15 +18,20 @@ #ifndef nsIDocumentWidget_h___ #define nsIDocumentWidget_h___ -#include "nsIWidget.h" +#include "nsweb.h" #include "nsRect.h" +#include "nsIWidget.h" #include "nsIScrollableView.h" // Forward declarations... -class nsIPostData; -class nsIStreamObserver; +class nsIDeviceContext; class nsString; +class nsIDocument; +class nsIPresContext; +class nsIStyleSheet; +class nsIViewerContainer; + // IID for the nsIDocumentWidget interface // a7d1b8b0-0b1c-11d2-beba-00805f8a66dc #define NS_IDOCUMENTWIDGET_IID \ @@ -35,17 +40,18 @@ class nsString; // Interface to the web widget. The web widget is a container for web // content. -class nsIDocumentWidget : public nsISupports { +class nsIContentViewer : public nsISupports { public: // Create a native window for this web widget; may be called once NS_IMETHOD Init(nsNativeWidget aNativeParent, + nsIDeviceContext* aDeviceContext, const nsRect& aBounds, nsScrollPreference aScrolling = nsScrollPreference_kAuto) = 0; - NS_IMETHOD BindToDocument(nsISupports *aDoc, const char *aCommand) = 0; + NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand) = 0; + NS_IMETHOD SetContainer(nsIViewerContainer* aContainer) = 0; virtual nsRect GetBounds() = 0; - virtual void SetBounds(const nsRect& aBounds) = 0; virtual void Move(PRInt32 aX, PRInt32 aY) = 0; @@ -53,12 +59,36 @@ public: virtual void Show() = 0; virtual void Hide() = 0; - - NS_IMETHOD LoadURL(const nsString& aURLSpec, - nsIStreamObserver* aListener, - nsIPostData* aPostData = 0) = 0; - - virtual nsIWidget* GetWWWindow() = 0; }; + + + +/* 30d26b00-176d-11d2-bec0-00805f8a66dc */ +#define NS_IWEBWIDGETVIEWER_IID \ + { 0x30d26b00, 0x176d, 0x11d2, \ + {0xbe, 0xc0, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} } + + +class nsIWebWidgetViewer : public nsIContentViewer { +public: + NS_IMETHOD Init(nsNativeWidget aNativeParent, + nsIDeviceContext* aDeviceContext, + const nsRect& aBounds, + nsScrollPreference aScrolling = nsScrollPreference_kAuto) = 0; + + NS_IMETHOD Init(nsNativeWidget aParent, + const nsRect& aBounds, + nsIDocument* aDocument, + nsIPresContext* aPresContext, + nsScrollPreference aScrolling = nsScrollPreference_kAuto) = 0; + + NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) = 0; + + virtual nsIPresContext* GetPresContext() = 0; +}; + +extern "C" NS_WEB nsresult NS_NewContentViewer(nsIWebWidgetViewer** aViewer); + + #endif /* nsIDocumentWidget_h___ */ diff --git a/mozilla/webshell/public/nsIWebWidget.h b/mozilla/webshell/public/nsIWebWidget.h index 656b5dc4819..e9352a14057 100644 --- a/mozilla/webshell/public/nsIWebWidget.h +++ b/mozilla/webshell/public/nsIWebWidget.h @@ -19,7 +19,6 @@ #define nsIWebWidget_h___ #include "nsweb.h" -#include "nsIDocumentWidget.h" #include "nsIScrollableView.h" // Forward declarations... @@ -28,6 +27,11 @@ class nsIDOMDocument; class nsILinkHandler; class nsIPresContext; class nsIStyleSet; +class nsIStyleSheet; + +class nsIStreamObserver; +class nsIPostData; +class nsIDeviceContext; // IID for the nsWebWidget interface #define NS_IWEBWIDGET_IID \ @@ -42,9 +46,14 @@ class nsIStyleSet; // Interface to the web widget. The web widget is a container for web // content. -class nsIWebWidget : public nsIDocumentWidget { +class nsIWebWidget : public nsISupports { public: +NS_IMETHOD LoadURL(const nsString& aURLSpec, + nsIStreamObserver* aObserver, + nsIPostData* aPostData=nsnull) = 0; + + // Create a native window for this web widget; may be called once NS_IMETHOD Init(nsNativeWidget aNativeParent, const nsRect& aBounds, @@ -82,6 +91,16 @@ public: NS_IMETHOD GetLinkHandler(nsILinkHandler** aResult) = 0; + virtual nsRect GetBounds() = 0; + + virtual void SetBounds(const nsRect& aBounds) = 0; + + virtual void Move(PRInt32 aX, PRInt32 aY) = 0; + + virtual void Show() = 0; + + virtual void Hide() = 0; + virtual nsIDocument* GetDocument() = 0; virtual void DumpContent(FILE* out = nsnull) = 0; @@ -102,6 +121,9 @@ public: virtual nsIPresContext* GetPresContext() = 0; + // Temporary until the parser is re-enterant... + virtual nsIStyleSheet* GetUAStyleSheet() = 0; + NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) = 0; }; // Create a new web widget that uses the default (galley) presentation diff --git a/mozilla/webshell/src/Makefile b/mozilla/webshell/src/Makefile index 7364e80a521..9eff44a568f 100644 --- a/mozilla/webshell/src/Makefile +++ b/mozilla/webshell/src/Makefile @@ -32,12 +32,14 @@ DEFINES = -D_IMPL_NS_WEB CPPSRCS= \ nsDocLoader.cpp \ + nsContentViewer.cpp \ nsWebWidget.cpp \ nsLinkHandler.cpp \ $(NULL) CPP_OBJS= \ ./$(OBJDIR)/nsDocLoader.o \ + ./$(OBJDIR)/nsContentViewer.o \ ./$(OBJDIR)/nsWebWidget.o \ ./$(OBJDIR)/nsLinkHandler.o \ $(NULL) diff --git a/mozilla/webshell/src/makefile.win b/mozilla/webshell/src/makefile.win index 19964e77ebf..bcbf270a1ad 100644 --- a/mozilla/webshell/src/makefile.win +++ b/mozilla/webshell/src/makefile.win @@ -22,12 +22,14 @@ DEFINES=-D_IMPL_NS_WEB -DWIN32_LEAN_AND_MEAN MODULE=raptor CPPSRCS= \ + nsContentViewer.cpp \ nsLinkHandler.cpp \ nsWebWidget.cpp \ nsDocLoader.cpp \ $(NULL) CPP_OBJS= \ + .\$(OBJDIR)\nsContentViewer.obj \ .\$(OBJDIR)\nsLinkHandler.obj \ .\$(OBJDIR)\nsWebWidget.obj \ .\$(OBJDIR)\nsDocLoader.obj \ diff --git a/mozilla/webshell/src/nsContentViewer.cpp b/mozilla/webshell/src/nsContentViewer.cpp new file mode 100644 index 00000000000..c91ac6c109f --- /dev/null +++ b/mozilla/webshell/src/nsContentViewer.cpp @@ -0,0 +1,484 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nscore.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsISupports.h" +#include "nsIDocumentWidget.h" +#include "nsIDocumentLoader.h" + +#include "nsIDocument.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsIStyleSet.h" +#include "nsIStyleSheet.h" + +#include "nsILinkHandler.h" + +#include "nsViewsCID.h" +#include "nsWidgetsCID.h" +#include "nsIDeviceContext.h" +#include "nsIViewManager.h" +#include "nsIView.h" + +#include "nsIURL.h" + +class ContentViewerImpl : public nsIWebWidgetViewer +{ +public: + ContentViewerImpl(); + + void* operator new(size_t sz) { + void* rv = new char[sz]; + nsCRT::zero(rv, sz); + return rv; + } + + // nsISupports interface... + NS_DECL_ISUPPORTS + + // nsIContentViewer interface... + NS_IMETHOD Init(nsNativeWidget aParent, + nsIDeviceContext* aDeviceContext, + const nsRect& aBounds, + nsScrollPreference aScrolling = nsScrollPreference_kAuto); + + NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); + NS_IMETHOD SetContainer(nsIViewerContainer* aContainer); + + virtual nsRect GetBounds(); + virtual void SetBounds(const nsRect& aBounds); + virtual void Move(PRInt32 aX, PRInt32 aY); + virtual void Show(); + virtual void Hide(); + + + // nsIWebWidgetViewer interface... + NS_IMETHOD Init(nsNativeWidget aParent, + const nsRect& aBounds, + nsIDocument* aDocument, + nsIPresContext* aPresContext, + nsScrollPreference aScrolling = nsScrollPreference_kAuto); + + NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet); + + virtual nsIPresContext* GetPresContext(); + + +protected: + virtual ~ContentViewerImpl(); + +private: + void ForceRefresh(void); + nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); + nsresult MakeWindow(nsNativeWidget aNativeParent, + const nsRect& aBounds, + nsScrollPreference aScrolling); + +protected: + nsIViewManager* mViewManager; + nsIView* mView; + nsIWidget* mWindow; + nsIViewerContainer* mContainer; + + nsIDocument* mDocument; + nsIPresContext* mPresContext; + nsIPresShell* mPresShell; + nsIStyleSheet* mUAStyleSheet; + +}; + +//Class IDs +static NS_DEFINE_IID(kViewManagerCID, NS_VIEW_MANAGER_CID); +static NS_DEFINE_IID(kScrollingViewCID, NS_SCROLLING_VIEW_CID); +static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID); + + +// Interface IDs +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); +static NS_DEFINE_IID(kIViewManagerIID, NS_IVIEWMANAGER_IID); +static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); +static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID); +static NS_DEFINE_IID(kIDocumentWidgetIID, NS_IDOCUMENTWIDGET_IID); +static NS_DEFINE_IID(kIWebWidgetViewerIID, NS_IWEBWIDGETVIEWER_IID); +static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID); + + +// Note: operator new zeros our memory +ContentViewerImpl::ContentViewerImpl() +{ + NS_INIT_REFCNT(); +} + +// ISupports implementation... +NS_IMPL_ADDREF(ContentViewerImpl) +NS_IMPL_RELEASE(ContentViewerImpl) + +nsresult ContentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + if (aIID.Equals(kIDocumentWidgetIID)) { + *aInstancePtr = (void*)(nsIContentViewer*)this; + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIWebWidgetViewerIID)) { + *aInstancePtr = (void*)(nsIWebWidgetViewer*)this; + AddRef(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)(nsIContentViewer*)this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + + +ContentViewerImpl::~ContentViewerImpl() +{ + // Release windows and views + if (nsnull != mViewManager) { + mViewManager->SetRootView(nsnull); + mViewManager->SetRootWindow(nsnull); + NS_RELEASE(mViewManager); + } + NS_IF_RELEASE(mWindow); + NS_IF_RELEASE(mView); + + NS_IF_RELEASE(mDocument); + + // Note: release context then shell + NS_IF_RELEASE(mPresContext); + if (nsnull != mPresShell) { + // Break circular reference first + mPresShell->EndObservingDocument(); + + // Then release the shell + NS_RELEASE(mPresShell); + } + + NS_IF_RELEASE(mUAStyleSheet); + NS_IF_RELEASE(mContainer); +} + + + +/* + * This method is called by the Document Loader once a document has been created + * for a particular data stream... The content viewer must cache this document + * for later use when Init(...) is called. + */ +NS_IMETHODIMP +ContentViewerImpl::BindToDocument(nsISupports *aDoc, const char *aCommand) +{ + nsresult rv; + + NS_PRECONDITION(nsnull == mDocument, "Viewer is already bound to a document!"); + +#ifdef NS_DEBUG + printf("ContentViewerImpl::BindToDocument\n"); +#endif + + rv = aDoc->QueryInterface(kIDocumentIID, (void**)&mDocument); + return rv; + +} + +NS_IMETHODIMP +ContentViewerImpl::SetContainer(nsIViewerContainer* aContainer) +{ + NS_IF_RELEASE(mContainer); + mContainer = aContainer; + NS_IF_ADDREF(mContainer); + + return NS_OK; +} + + +NS_IMETHODIMP +ContentViewerImpl::Init(nsNativeWidget aNativeParent, + nsIDeviceContext* aDeviceContext, + const nsRect& aBounds, + nsScrollPreference aScrolling) +{ + nsresult rv; + + if (nsnull == mDocument) { + return NS_ERROR_NULL_POINTER; + } + + // Create presentation context + rv = NS_NewGalleyContext(&mPresContext); + if (NS_OK != rv) { + return rv; + } + + mPresContext->Init(aDeviceContext); + rv = Init(aNativeParent, aBounds, mDocument, mPresContext, aScrolling); + + // Init(...) will addref the Presentation Context... + if (NS_OK == rv) { + mPresContext->Release(); + } + return rv; +} + + +NS_IMETHODIMP +ContentViewerImpl::Init(nsNativeWidget aNativeParent, + const nsRect& aBounds, + nsIDocument* aDocument, + nsIPresContext* aPresContext, + nsScrollPreference aScrolling) +{ + nsresult rv; + nsRect bounds; + + NS_PRECONDITION(nsnull != aPresContext, "null ptr"); + NS_PRECONDITION(nsnull != aDocument, "null ptr"); + if ((nsnull == aPresContext) || (nsnull == aDocument)) { + rv = NS_ERROR_NULL_POINTER; + goto done; + } + + mPresContext = aPresContext; + NS_ADDREF(mPresContext); + + if (nsnull != mContainer) { + nsILinkHandler* linkHandler = nsnull; + + mContainer->QueryCapability(kILinkHandlerIID, (void**)&linkHandler); + mPresContext->SetContainer(mContainer); + mPresContext->SetLinkHandler(linkHandler); + NS_IF_RELEASE(linkHandler); + } + + // Create the ViewManager and Root View... + MakeWindow(aNativeParent, aBounds, aScrolling); + + // Create the style set... + nsIStyleSet* styleSet; + rv = CreateStyleSet(aDocument, &styleSet); + if (NS_OK != rv) { + goto done; + } + + // Now make the shell for the document + rv = aDocument->CreateShell(mPresContext, mViewManager, styleSet, + &mPresShell); + NS_RELEASE(styleSet); + if (NS_OK != rv) { + goto done; + } + + // Now that we have a presentation shell trigger a reflow so we + // create a frame model + mWindow->GetBounds(bounds); + if (nsnull != mPresShell) { + nscoord width = bounds.width; + nscoord height = bounds.height; + width = NS_TO_INT_ROUND(width * mPresContext->GetPixelsToTwips()); + height = NS_TO_INT_ROUND(height * mPresContext->GetPixelsToTwips()); + mViewManager->SetWindowDimensions(width, height); + } + ForceRefresh(); + +done: + return rv; +} + +NS_IMETHODIMP +ContentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) +{ + NS_IF_RELEASE(mUAStyleSheet); + mUAStyleSheet = aUAStyleSheet; + NS_IF_ADDREF(mUAStyleSheet); + + return NS_OK; +} + + +nsIPresContext* ContentViewerImpl::GetPresContext() +{ + NS_IF_ADDREF(mPresContext); + return mPresContext; +} + + +nsRect ContentViewerImpl::GetBounds() +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + nsRect zr(0, 0, 0, 0); + if (nsnull != mWindow) { + mWindow->GetBounds(zr); + } + return zr; +} + + +void ContentViewerImpl::SetBounds(const nsRect& aBounds) +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + if (nsnull != mWindow) { + // Don't have the widget repaint. Layout will generate repaint requests + // during reflow + mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height, PR_FALSE); + } +} + + +void ContentViewerImpl::Move(PRInt32 aX, PRInt32 aY) +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + if (nsnull != mWindow) { + mWindow->Move(aX, aY); + } +} + +void ContentViewerImpl::Show() +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + if (nsnull != mWindow) { + mWindow->Show(PR_TRUE); + } +} + +void ContentViewerImpl::Hide() +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + if (nsnull != mWindow) { + mWindow->Show(PR_FALSE); + } +} + + + +void ContentViewerImpl::ForceRefresh() +{ + mWindow->Invalidate(PR_TRUE); +} + +nsresult ContentViewerImpl::CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) +{ // this should eventually get expanded to allow for creating different sets for different media + nsresult rv; + + if (nsnull == mUAStyleSheet) { + NS_WARNING("unable to load UA style sheet"); + } + + rv = NS_NewStyleSet(aStyleSet); + if (NS_OK == rv) { + PRInt32 count = aDocument->GetNumberOfStyleSheets(); + + for (PRInt32 index = 0; index < count; index++) { + nsIStyleSheet* sheet = aDocument->GetStyleSheetAt(index); + (*aStyleSet)->AppendDocStyleSheet(sheet); + NS_RELEASE(sheet); + } + if (nsnull != mUAStyleSheet) { + (*aStyleSet)->AppendBackstopStyleSheet(mUAStyleSheet); + } + } + return rv; +} + + +nsresult ContentViewerImpl::MakeWindow(nsNativeWidget aNativeParent, + const nsRect& aBounds, + nsScrollPreference aScrolling) +{ + nsresult rv; + + rv = NSRepository::CreateInstance(kViewManagerCID, + nsnull, + kIViewManagerIID, + (void **)&mViewManager); + + if ((NS_OK != rv) || (NS_OK != mViewManager->Init(mPresContext))) { + return rv; + } + + nsRect tbounds = aBounds; + tbounds *= mPresContext->GetPixelsToTwips(); + + // Create a child window of the parent that is our "root view/window" + // Create a view + rv = NSRepository::CreateInstance(kScrollingViewCID, + nsnull, + kIViewIID, + (void **)&mView); + static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID); + if ((NS_OK != rv) || (NS_OK != mView->Init(mViewManager, + tbounds, + nsnull, + &kWidgetCID, + nsnull, + aNativeParent))) { + return rv; + } + + nsIScrollableView* scrollView; + rv = mView->QueryInterface(kScrollViewIID, (void**)&scrollView); + if (NS_OK == rv) { + scrollView->SetScrollPreference(aScrolling); + NS_RELEASE(scrollView); + } + else { + NS_ASSERTION(0, "invalid scrolling view"); + return rv; + } + + // Setup hierarchical relationship in view manager + mViewManager->SetRootView(mView); + mWindow = mView->GetWidget(); + if (nsnull != mWindow) { + mViewManager->SetRootWindow(mWindow); + } + + //set frame rate to 25 fps + mViewManager->SetFrameRate(25); + + return rv; +} + + + +extern "C" NS_WEB nsresult NS_NewContentViewer(nsIWebWidgetViewer** aViewer) +{ + if (nsnull == aViewer) { + return NS_ERROR_NULL_POINTER; + } + + *aViewer = new ContentViewerImpl(); + if (nsnull == *aViewer) { + return NS_ERROR_OUT_OF_MEMORY; + } + NS_ADDREF(*aViewer); + + return NS_OK; +} + + diff --git a/mozilla/webshell/src/nsDocLoader.cpp b/mozilla/webshell/src/nsDocLoader.cpp index 5012097aaef..20a548d2c96 100644 --- a/mozilla/webshell/src/nsDocLoader.cpp +++ b/mozilla/webshell/src/nsDocLoader.cpp @@ -90,9 +90,10 @@ public: NS_IMETHOD CreateInstance(nsIURL* aURL, const char* aContentType, - const char *aCommand, + const char* aCommand, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener, - nsIDocumentWidget** aDocViewer); + nsIContentViewer** aDocViewer); }; @@ -113,12 +114,13 @@ NS_IMETHODIMP nsDocFactoryImpl::CreateInstance(nsIURL* aURL, const char* aContentType, const char *aCommand, + nsIViewerContainer* aContainer, nsIStreamListener** aDocListener, - nsIDocumentWidget** aDocViewer) + nsIContentViewer** aDocViewer) { nsresult rv; nsIDocument* doc = nsnull; - nsIWebWidget* ww = nsnull; + nsIWebWidgetViewer* ww = nsnull; int typeIndex=0; while(gValidTypes[typeIndex]) { @@ -140,7 +142,7 @@ nextstep: /* * Create the HTML Content Viewer... */ - rv = NS_NewWebWidget(&ww); + rv = NS_NewContentViewer(&ww); if (NS_OK != rv) { goto done; } @@ -151,7 +153,7 @@ nextstep: * An nsIStreamListener connected to the parser is returned in * aDocListener. */ - rv = doc->StartDocumentLoad(aURL, ww, aDocListener); + rv = doc->StartDocumentLoad(aURL, aContainer, aDocListener); if (NS_OK != rv) { goto done; } @@ -403,7 +405,7 @@ NS_METHOD nsDocumentBindInfo::OnProgress(nsIURL* aURL, PRInt32 aProgress, NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentType) { nsresult rv = NS_OK; - nsIDocumentWidget* viewer = nsnull; + nsIContentViewer* viewer = nsnull; /* * Now that the content type is available, create a document (and viewer) @@ -413,6 +415,7 @@ NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentT rv = m_DocLoader->m_DocFactory->CreateInstance(m_Url, aContentType, m_Command, + m_Container, &m_NextStream, &viewer); } else { @@ -426,6 +429,8 @@ NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentT /* * Give the document container the new viewer... */ + viewer->SetContainer(m_Container); + rv = m_Container->Embed(viewer, m_Command, m_ExtraInfo); if (NS_OK != rv) { goto done; diff --git a/mozilla/webshell/src/nsWebWidget.cpp b/mozilla/webshell/src/nsWebWidget.cpp index 98db9d1bb07..e3a813c0a22 100644 --- a/mozilla/webshell/src/nsWebWidget.cpp +++ b/mozilla/webshell/src/nsWebWidget.cpp @@ -52,12 +52,15 @@ // XXX: a copy exists in nsPresShell.cpp!!! #define UA_CSS_URL "resource:/res/ua.css" +#include "nsIDocumentWidget.h" #define GET_OUTER() \ ((nsWebWidget*) ((char*)this - nsWebWidget::GetOuterOffset())) // Machine independent implementation portion of the web widget -class WebWidgetImpl : public nsIWebWidget { +class WebWidgetImpl : public nsIWebWidget, + public nsIViewerContainer +{ public: WebWidgetImpl(); ~WebWidgetImpl(); @@ -70,9 +73,18 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD Init(nsNativeWidget aParent, - const nsRect& aBounds, - nsScrollPreference aScrolling = nsScrollPreference_kAuto); + NS_IMETHOD QueryCapability(const nsIID &aIID, void** aResult); + + NS_IMETHOD Embed(nsIContentViewer* aDocViewer, + const char* aCommand, + nsISupports* aExtraInfo); + + NS_IMETHOD SetContainer(nsIViewerContainer* aContainer); + + NS_IMETHOD Init(nsNativeWidget aNativeParent, + const nsRect& aBounds, + nsScrollPreference aScrolling); + NS_IMETHOD Init(nsNativeWidget aParent, const nsRect& aBounds, nsIDocument* aDocument, @@ -105,10 +117,7 @@ public: NS_IMETHOD GetLinkHandler(nsILinkHandler** aResult); NS_IMETHOD LoadURL(const nsString& aURLSpec, nsIStreamObserver* aObserver, - nsIPostData* aPostData) { - NS_NOTREACHED("invalid call to WebWidget LoadURL"); - return NS_ERROR_NULL_POINTER; - } + nsIPostData* aPostData); virtual nsIDocument* GetDocument(); @@ -124,18 +133,23 @@ public: NS_IMETHOD BindToDocument(nsISupports *aDoc, const char *aCommand); + nsIStyleSheet* GetUAStyleSheet(); + NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet); + private: nsresult ProvideDefaultHandlers(); void ForceRefresh(); - nsresult MakeWindow(nsNativeWidget aParent, const nsRect& aBounds, - nsScrollPreference aScrolling); nsresult InitUAStyleSheet(void); nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); void ReleaseChildren(); + static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent); + + + nsIWebWidgetViewer* mContentViewer; + nsIWidget* mWindow; nsIView *mView; - nsIViewManager *mViewManager; nsIPresContext* mPresContext; nsIPresShell* mPresShell; nsIStyleSheet* mUAStyleSheet; @@ -143,6 +157,8 @@ private: nsISupports* mContainer; nsIDocument* mDocument; + nsIDocumentLoader* mDocLoader; + nsVoidArray mChildren; //static nsIWebWidget* gRootWebWidget; nsString* mName; @@ -150,7 +166,6 @@ private: }; //---------------------------------------------------------------------- - #ifdef NS_DEBUG /** * Note: the log module is created during initialization which @@ -175,9 +190,18 @@ static PRLogModuleInfo* gLogModule = PR_NewLogModule("webwidget"); #endif //---------------------------------------------------------------------- +static NS_DEFINE_IID(kChildCID, NS_CHILD_CID); +static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); +static NS_DEFINE_IID(kCDocumentLoaderCID, NS_DOCUMENTLOADER_CID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); static NS_DEFINE_IID(kIWebWidgetIID, NS_IWEBWIDGET_IID); +static NS_DEFINE_IID(kIWebWidgetViewerIID, NS_IWEBWIDGETVIEWER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); +static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID); +static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); + NS_WEB nsresult NS_NewWebWidget(nsIWebWidget** aInstancePtrResult) @@ -196,9 +220,11 @@ NS_NewWebWidget(nsIWebWidget** aInstancePtrResult) // Note: operator new zeros our memory WebWidgetImpl::WebWidgetImpl() { + NS_INIT_REFCNT(); + + NSRepository::CreateInstance(kCDocumentLoaderCID, nsnull, kIDocumentLoaderIID, (void**)&mDocLoader); WEB_TRACE(WEB_TRACE_CALLS, ("WebWidgetImpl::WebWidgetImpl: this=%p")); - NS_INIT_REFCNT(); } nsresult WebWidgetImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) @@ -206,17 +232,11 @@ nsresult WebWidgetImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } - static NS_DEFINE_IID(kIDocumentWidgetIID, NS_IDOCUMENTWIDGET_IID); if (aIID.Equals(kIWebWidgetIID)) { *aInstancePtr = (void*)(nsIWebWidget*)this; AddRef(); return NS_OK; } - if (aIID.Equals(kIDocumentWidgetIID)) { - *aInstancePtr = (void*)(nsIDocumentWidget*)this; - AddRef(); - return NS_OK; - } if (aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*)(nsISupports*)(nsIWebWidget*)this; AddRef(); @@ -236,14 +256,6 @@ WebWidgetImpl::~WebWidgetImpl() ReleaseChildren(); mContainer = nsnull; - // Release windows and views - if (nsnull != mViewManager) - { - mViewManager->SetRootView(nsnull); - mViewManager->SetRootWindow(nsnull); - NS_RELEASE(mViewManager); - } - NS_IF_RELEASE(mWindow); NS_IF_RELEASE(mView); @@ -265,8 +277,52 @@ WebWidgetImpl::~WebWidgetImpl() NS_IF_RELEASE(mUAStyleSheet); NS_IF_RELEASE(mDeviceContext); + + NS_IF_RELEASE(mContentViewer); } + +NS_IMETHODIMP +WebWidgetImpl::QueryCapability(const nsIID &aIID, void** aInstancePtr) +{ + if (nsnull == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + if (aIID.Equals(kILinkHandlerIID)) { + if (nsnull != mLinkHandler) { + *aInstancePtr = mLinkHandler; + mLinkHandler->AddRef(); + return NS_OK; + } + } + return NS_NOINTERFACE; +} + +NS_IMETHODIMP +WebWidgetImpl::SetContainer(nsIViewerContainer* aContainer) +{ + NS_ASSERTION(0, "Not implemented..."); + + return NS_ERROR_FAILURE; +} + + + +void Check(WebWidgetImpl* ww) +{ + PRInt32 foo = ww->GetNumChildren(); + for (int i = 0; i < foo; i++) { + nsIWebWidget* child; + ww->GetChildAt(i, &child); + if (child == 0) { + printf("hello"); + } + } +} + + + void WebWidgetImpl::ReleaseChildren() { @@ -376,105 +432,45 @@ nsIWebWidget* WebWidgetImpl::GetTarget(const nsString& aName) } -nsresult WebWidgetImpl::MakeWindow(nsNativeWidget aNativeParent, - const nsRect& aBounds, - nsScrollPreference aScrolling) -{ - nsresult rv; - static NS_DEFINE_IID(kViewManagerCID, NS_VIEW_MANAGER_CID); - static NS_DEFINE_IID(kIViewManagerIID, NS_IVIEWMANAGER_IID); - - rv = NSRepository::CreateInstance(kViewManagerCID, - nsnull, - kIViewManagerIID, - (void **)&mViewManager); - - if ((NS_OK != rv) || (NS_OK != mViewManager->Init(mPresContext))) { - return rv; - } - - nsRect tbounds = aBounds; - tbounds *= mPresContext->GetPixelsToTwips(); - - // Create a child window of the parent that is our "root view/window" - // Create a view - static NS_DEFINE_IID(kScrollingViewCID, NS_SCROLLING_VIEW_CID); - static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); - - rv = NSRepository::CreateInstance(kScrollingViewCID, - nsnull, - kIViewIID, - (void **)&mView); - static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID); - if ((NS_OK != rv) || (NS_OK != mView->Init(mViewManager, - tbounds, - nsnull, - &kWidgetCID, - nsnull, - aNativeParent))) { - return rv; - } - - static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID); - nsIScrollableView* scrollView; - rv = mView->QueryInterface(kScrollViewIID, (void**)&scrollView); - if (NS_OK == rv) { - scrollView->SetScrollPreference(aScrolling); - NS_RELEASE(scrollView); - } - else { - NS_ASSERTION(0, "invalid scrolling view"); - return rv; - } - - // Setup hierarchical relationship in view manager - mViewManager->SetRootView(mView); - mWindow = mView->GetWidget(); - if (mWindow) { - mViewManager->SetRootWindow(mWindow); - } - - //set frame rate to 25 fps - mViewManager->SetFrameRate(25); - - return rv; -} - NS_IMETHODIMP WebWidgetImpl::Init(nsNativeWidget aNativeParent, const nsRect& aBounds, nsScrollPreference aScrolling) { - if (nsnull == mDocument) { - return NS_ERROR_NULL_POINTER; + nsresult rv = NS_OK; + + NS_PRECONDITION(nsnull != aNativeParent, "null Parent Window"); + if (nsnull == aNativeParent) { + rv = NS_ERROR_NULL_POINTER; + goto done; } - // Create presentation context - - static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); - static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); - - nsresult rv = NSRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&mDeviceContext); - - if (NS_OK == rv) { - mDeviceContext->Init(aNativeParent); - mDeviceContext->SetDevUnitsToAppUnits(mDeviceContext->GetDevUnitsToTwips()); - mDeviceContext->SetAppUnitsToDevUnits(mDeviceContext->GetTwipsToDevUnits()); - mDeviceContext->SetGamma(1.7f); - - NS_ADDREF(mDeviceContext); - } - - rv = NS_NewGalleyContext(&mPresContext); + // Create device context + rv = NSRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&mDeviceContext); if (NS_OK != rv) { - return rv; + goto done; } + mDeviceContext->Init(aNativeParent); + mDeviceContext->SetDevUnitsToAppUnits(mDeviceContext->GetDevUnitsToTwips()); + mDeviceContext->SetAppUnitsToDevUnits(mDeviceContext->GetTwipsToDevUnits()); + mDeviceContext->SetGamma(1.7f); + - mPresContext->Init(mDeviceContext); - rv = Init(aNativeParent, aBounds, mDocument, mPresContext, aScrolling); + // Create a Native window for the WebWidget container... + rv = NSRepository::CreateInstance(kChildCID, nsnull, kIWidgetIID, (void**)&mWindow); + if (NS_OK != rv) { + goto done; + } + mWindow->Create(aNativeParent, aBounds, WebWidgetImpl::HandleEvent, mDeviceContext, nsnull); + + // Create a Style Sheet... + rv = InitUAStyleSheet(); + +done: return rv; } + nsresult WebWidgetImpl::InitUAStyleSheet(void) { nsresult rv = NS_OK; @@ -523,46 +519,21 @@ WebWidgetImpl::Init(nsNativeWidget aNativeParent, nsIPresContext* aPresContext, nsScrollPreference aScrolling) { - NS_PRECONDITION(nsnull != aPresContext, "null ptr"); - NS_PRECONDITION(nsnull != aDocument, "null ptr"); - if ((nsnull == aPresContext) || (nsnull == aDocument)) { - return NS_ERROR_NULL_POINTER; + nsresult rv; + + NS_PRECONDITION(nsnull != aNativeParent, "null Parent Window"); + if (nsnull == aNativeParent) { + rv = NS_ERROR_NULL_POINTER; + } else { } - mPresContext = aPresContext; - NS_ADDREF(aPresContext); + rv = InitUAStyleSheet(); +/// if (nsnull != mContentViewer) { +/// rv = mContentViewer->Init(aNativeParent, aBounds, aDocument, aPresContext, aScrolling); +/// } else { +/// rv = NS_ERROR_NULL_POINTER; +/// } - nsresult rv = MakeWindow(aNativeParent, aBounds, aScrolling); - if (NS_OK != rv) { - return rv; - } - - nsIStyleSet* styleSet; - rv = CreateStyleSet(aDocument, &styleSet); - if (NS_OK != rv) { - return rv; - } - - // Now make the shell for the document - rv = aDocument->CreateShell(mPresContext, mViewManager, styleSet, - &mPresShell); - NS_RELEASE(styleSet); - if (NS_OK != rv) { - return rv; - } - - // Now that we have a presentation shell trigger a reflow so we - // create a frame model - nsRect bounds; - mWindow->GetBounds(bounds); - if (nsnull != mPresShell) { - nscoord width = bounds.width; - nscoord height = bounds.height; - width = NS_TO_INT_ROUND(width * mPresContext->GetPixelsToTwips()); - height = NS_TO_INT_ROUND(height * mPresContext->GetPixelsToTwips()); - mViewManager->SetWindowDimensions(width, height); - } - ForceRefresh(); return rv; } @@ -578,8 +549,13 @@ nsRect WebWidgetImpl::GetBounds() nsIPresContext* WebWidgetImpl::GetPresContext() { - NS_IF_ADDREF(mPresContext); - return mPresContext; + nsIPresContext* presContext = nsnull; + + if (nsnull != mContentViewer) { + presContext = mContentViewer->GetPresContext(); + } + + return presContext; } void WebWidgetImpl::SetBounds(const nsRect& aBounds) @@ -590,6 +566,11 @@ void WebWidgetImpl::SetBounds(const nsRect& aBounds) // during reflow mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height, PR_FALSE); } + + if (nsnull != mContentViewer) { + nsRect rr(0, 0, aBounds.width, aBounds.height); + mContentViewer->SetBounds(rr); + } } void WebWidgetImpl::Move(PRInt32 aX, PRInt32 aY) @@ -606,6 +587,10 @@ void WebWidgetImpl::Show() if (nsnull != mWindow) { mWindow->Show(PR_TRUE); } + + if (nsnull != mContentViewer) { + mContentViewer->Show(); + } } void WebWidgetImpl::Hide() @@ -614,6 +599,10 @@ void WebWidgetImpl::Hide() if (nsnull != mWindow) { mWindow->Show(PR_FALSE); } + + if (nsnull != mContentViewer) { + mContentViewer->Hide(); + } } nsresult WebWidgetImpl::ProvideDefaultHandlers() @@ -635,20 +624,84 @@ nsresult WebWidgetImpl::ProvideDefaultHandlers() return NS_OK; } -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); NS_IMETHODIMP WebWidgetImpl::BindToDocument(nsISupports* aDoc, const char* aCommand) { + nsresult rv = NS_ERROR_FAILURE; + WEB_TRACE(WEB_TRACE_CALLS, ("WebWidgetImpl::BindToDocument: this=%p aDoc=%p aCommand=%s", this, aDoc, aCommand ? aCommand : "")); - nsresult rv; - rv = aDoc->QueryInterface(kIDocumentIID, (void**)&mDocument); + NS_PRECONDITION(nsnull != mContentViewer, "null Content Viewer"); + if (nsnull != mContentViewer) { + rv = mContentViewer->BindToDocument(aDoc, aCommand); + } + return rv; } +NS_IMETHODIMP +WebWidgetImpl::Embed(nsIContentViewer* aDocViewer, + const char* aCommand, + nsISupports* aExtraInfo) +{ + nsresult rv; + nsRect bounds; + + WEB_TRACE(WEB_TRACE_CALLS, + ("WebWidgetImpl::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p", + this, aDocViewer, aCommand ? aCommand : "", aExtraInfo)); + + NS_IF_RELEASE(mContentViewer); + + + rv = aDocViewer->QueryInterface(kIWebWidgetViewerIID, (void**)&mContentViewer); + + if (NS_OK == rv) { + mContentViewer->SetUAStyleSheet(mUAStyleSheet); + + mWindow->GetBounds(bounds); + bounds.y = bounds.y = 0; + rv = mContentViewer->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET), + mDeviceContext, + bounds); + } + + +/// nsIURL* aURL = aDoc->GetDocumentURL(); +/// if (aURL) { +/// mURL = aURL->GetSpec(); +/// } +/// NS_IF_RELEASE(aURL); + + if (NS_OK == rv) { + mContentViewer->Show(); + } + + return rv; +} + + +NS_IMETHODIMP +WebWidgetImpl::LoadURL(const nsString& aURLSpec, + nsIStreamObserver* anObserver, + nsIPostData* aPostData) +{ + nsresult rv; + + rv = mDocLoader->LoadURL(aURLSpec, // URL string + nsnull, // Command + this, // Container + aPostData, // Post Data + nsnull, // Extra Info... + anObserver); // Observer + + return rv; +} + + nsIDocument* WebWidgetImpl::GetDocument() { if (nsnull != mPresShell) { @@ -775,6 +828,13 @@ nsIWebWidget* WebWidgetImpl::GetRootWebWidget() return this; } + +nsEventStatus PR_CALLBACK WebWidgetImpl::HandleEvent(nsGUIEvent *aEvent) +{ + return nsEventStatus_eIgnore; +} + + //---------------------------------------------------------------------- // Debugging methods @@ -947,6 +1007,22 @@ nsresult WebWidgetImpl::GetDOMDocument(nsIDOMDocument** aDocument) return res; } +nsIStyleSheet* WebWidgetImpl::GetUAStyleSheet() +{ + return mUAStyleSheet; +} + +NS_IMETHODIMP +WebWidgetImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) +{ + NS_IF_RELEASE(mUAStyleSheet); + mUAStyleSheet = aUAStyleSheet; + NS_IF_ADDREF(mUAStyleSheet); + + return NS_OK; +} + + /******************************************* * nsWebWidgetFactory *******************************************/ diff --git a/mozilla/webshell/tests/viewer/nsDocLoader.cpp b/mozilla/webshell/tests/viewer/nsDocLoader.cpp index 1bddcbbff43..24de6c1ed36 100644 --- a/mozilla/webshell/tests/viewer/nsDocLoader.cpp +++ b/mozilla/webshell/tests/viewer/nsDocLoader.cpp @@ -22,14 +22,11 @@ #include "nsVoidArray.h" #include "plstr.h" #include "nsRepository.h" -#include "nsIDocumentLoader.h" +#include "nsIWebWidget.h" #include "resources.h" #include "nsString.h" #include "nsViewer.h" -static NS_DEFINE_IID(kCDocumentLoaderCID, NS_DOCUMENTLOADER_CID); -static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); - /* This class loads creates and loads URLs until finished. When the doc counter reaches zero, the DocLoader (optionally) @@ -37,19 +34,18 @@ static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); */ -nsDocLoader::nsDocLoader(nsIViewerContainer* aContainer, nsViewer* aViewer, PRInt32 aSeconds, PRBool aPostExit) +nsDocLoader::nsDocLoader(nsIWebWidget* aWebWidget, nsViewer* aViewer, PRInt32 aSeconds, PRBool aPostExit) { + NS_INIT_REFCNT(); + mStart = PR_FALSE; mDelay = aSeconds; mPostExit = aPostExit; mDocNum = 0; - mContainer = aContainer; + mWebWidget = aWebWidget; mViewer = aViewer; mTimers = new nsVoidArray(); mURLList = new nsVoidArray(); - - NSRepository::CreateInstance(kCDocumentLoaderCID, nsnull, kIDocumentLoaderIID, (void**)&mDocLoader); - NS_INIT_REFCNT(); } nsDocLoader::~nsDocLoader() @@ -72,7 +68,7 @@ nsDocLoader::~nsDocLoader() mTimers = nsnull; } - NS_RELEASE(mDocLoader); + NS_RELEASE(mWebWidget); } static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); @@ -156,12 +152,9 @@ nsDocLoader::LoadDoc(PRInt32 aDocNum, PRBool aObserveIt) { nsString* url = (nsString*)mURLList->ElementAt(aDocNum); if (url) { - mDocLoader->LoadURL(*url, // URL string - nsnull, // Command - mContainer, // Container - nsnull, // Post Data - nsnull, // Extra Info... - aObserveIt ? this : nsnull); // Observer + mWebWidget->LoadURL(*url, // URL string + aObserveIt ? this : nsnull, // Observer + nsnull); // Post Data } } diff --git a/mozilla/webshell/tests/viewer/nsDocLoader.h b/mozilla/webshell/tests/viewer/nsDocLoader.h index 4e4ba8397c5..22b077519a8 100644 --- a/mozilla/webshell/tests/viewer/nsDocLoader.h +++ b/mozilla/webshell/tests/viewer/nsDocLoader.h @@ -22,8 +22,7 @@ #include "nsIStreamListener.h" #include "nsString.h" -class nsIViewerContainer; -class nsIDocumentLoader; +class nsIWebWidget; class nsITimer; class nsVoidArray; class nsViewer; @@ -34,9 +33,10 @@ class nsViewer; posts an exit application message */ -class nsDocLoader : public nsIStreamObserver { +class nsDocLoader : public nsIStreamObserver +{ public: - nsDocLoader(nsIViewerContainer* aContainer, nsViewer* aViewer, + nsDocLoader(nsIWebWidget* aWebWidget, nsViewer* aViewer, PRInt32 aSeconds=1, PRBool aPostExit=PR_TRUE); // nsISupports @@ -96,8 +96,7 @@ protected: PRBool mStart; PRInt32 mDelay; PRBool mPostExit; - nsIViewerContainer* mContainer; - nsIDocumentLoader* mDocLoader; + nsIWebWidget* mWebWidget; nsViewer* mViewer; nsString mURL; nsVoidArray* mURLList; diff --git a/mozilla/webshell/tests/viewer/nsViewer.cpp b/mozilla/webshell/tests/viewer/nsViewer.cpp index 1d5f33c8d20..cf459de4555 100644 --- a/mozilla/webshell/tests/viewer/nsViewer.cpp +++ b/mozilla/webshell/tests/viewer/nsViewer.cpp @@ -541,9 +541,10 @@ DocObserver::OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg) return NS_OK; } +#if 0 NS_IMETHODIMP -DocObserver::Embed(nsIDocumentWidget* aDocViewer, - const char* aCommand, +DocObserver::Embed(nsIDocumentWidget* aDocViewer, + const char* aCommand, nsISupports* aExtraInfo) { nsresult rv; @@ -583,6 +584,7 @@ DocObserver::Embed(nsIDocumentWidget* aDocViewer, return NS_OK; } +#endif NS_IMETHODIMP DocObserver::Init(nsIWebWidget* aWidget) @@ -615,7 +617,7 @@ DocObserver::HandleLinkClickEvent(const nsString& aURLSpec, { if (nsnull != mDocLoader) { if (nsnull != mViewer) { - mViewer->GoTo(aURLSpec, nsnull, this, aPostData, nsnull, this); + mViewer->GoTo(aURLSpec, nsnull, mWebWidget, aPostData, nsnull, this); } } } @@ -1558,8 +1560,7 @@ nsViewer::Back() mHistoryIndex--; if (nsnull != mWD && nsnull != mWD->observer) { nsString* s = (nsString*) mHistory.ElementAt(mHistoryIndex); - mWD->observer->LoadURL(*s, nsnull, mWD->observer, - nsnull, nsnull, mWD->observer); + mWD->observer->mWebWidget->LoadURL(*s, mWD->observer, nsnull); } ShowHistory(); } @@ -1583,8 +1584,7 @@ nsViewer::Forward() mHistoryIndex++; if (nsnull != mWD && nsnull != mWD->observer) { nsString* s = (nsString*) mHistory.ElementAt(mHistoryIndex); - mWD->observer->LoadURL(*s, nsnull, mWD->observer, - nsnull, nsnull, mWD->observer); + mWD->observer->mWebWidget->LoadURL(*s, mWD->observer, nsnull); } ShowHistory(); } @@ -1608,7 +1608,7 @@ nsEventStatus PR_CALLBACK HandleLocationEvent(nsGUIEvent *aEvent) nsresult nsViewer::GoTo(const nsString& aURLSpec, const char* aCommand, - nsIViewerContainer* aContainer, + nsIWebWidget* aWebWidget, nsIPostData* aPostData, nsISupports* aExtraInfo, nsIStreamObserver* anObserver) @@ -1620,14 +1620,10 @@ nsViewer::GoTo(const nsString& aURLSpec, printf("goto: "); fputs(aURLSpec, stdout); printf("\n"); + mLocation->RemoveText(); mLocation->SetText(aURLSpec); - rv = mWD->observer->LoadURL(aURLSpec, // URL string - aCommand, // Command - aContainer, // Container - aPostData, // Post Data - aExtraInfo, // Extra Info... - anObserver); // Observer + rv = aWebWidget->LoadURL(aURLSpec, anObserver, aPostData); } return rv; } @@ -1795,24 +1791,22 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg wd->mViewer = this; // Now embed the web widget in it - nsIWebWidget* ww; - nsresult rv = NS_NewWebWidget(&ww); + nsresult rv = NS_NewWebWidget(&(wd->ww)); nsRect rr(WEBWIDGET_LEFT_INSET, BUTTON_HEIGHT+WEBWIDGET_TOP_INSET, bounds.width - WEBWIDGET_LEFT_INSET - WEBWIDGET_RIGHT_INSET, bounds.height - BUTTON_HEIGHT - WEBWIDGET_TOP_INSET - WEBWIDGET_BOTTOM_INSET); - rv = ww->Init(wd->windowWidget->GetNativeData(NS_NATIVE_WIDGET), rr); -/// ww->Show(); - wd->observer = NewObserver(wd->windowWidget, ww); + rv = wd->ww->Init(wd->windowWidget->GetNativeData(NS_NATIVE_WIDGET), rr); + wd->ww->Show(); + wd->observer = NewObserver(wd->windowWidget, wd->ww); wd->observer->mViewer = this; mWD = wd; - NS_RELEASE(ww); // Determine if we should run the purify test nsDocLoader* dl = nsnull; if (gDoPurify) { - dl = new nsDocLoader(wd->observer, this, gDelay); + dl = new nsDocLoader(wd->ww, this, gDelay); dl->AddRef(); // Add the documents to the loader @@ -1823,7 +1817,7 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg dl->StartTimedLoading(); } else if (gLoadTestFromFile) { - dl = new nsDocLoader(wd->observer, this, gDelay); + dl = new nsDocLoader(wd->ww, this, gDelay); dl->AddRef(); for (PRInt32 i=0; iobserver, + return GoTo(aURLSpec, nsnull, mWD->ww, nsnull, nsnull, mWD->observer); }