2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 16:52:41 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-17 15:52:48 +00:00
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
* 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/
|
1998-12-17 15:52:48 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
1998-12-17 15:52:48 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 16:52:41 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 16:52:41 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 16:52:41 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-12-17 15:52:48 +00:00
|
|
|
#include "prmem.h"
|
|
|
|
|
|
|
|
#include "nsXPBaseWindow.h"
|
|
|
|
|
1999-12-01 03:43:17 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-07-01 19:30:20 +00:00
|
|
|
#include "nsIPrompt.h"
|
1998-12-17 15:52:48 +00:00
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-17 15:52:48 +00:00
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsViewerApp.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIWindowListener.h"
|
1999-12-01 03:43:17 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
2000-03-29 10:16:58 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-01-27 16:58:15 +00:00
|
|
|
#include "nsIViewManager.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
1998-12-17 15:52:48 +00:00
|
|
|
|
2000-03-11 00:20:07 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocShellTreeNode.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2000-03-11 00:20:07 +00:00
|
|
|
|
1999-04-05 20:48:43 +00:00
|
|
|
#include <ctype.h> // tolower
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
// XXX For font setting below
|
|
|
|
#include "nsFont.h"
|
|
|
|
//#include "nsUnitConversion.h"
|
|
|
|
//#include "nsIDeviceContext.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
|
|
|
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
|
|
|
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsXPBaseWindow::nsXPBaseWindow() :
|
|
|
|
mContentRoot(nsnull),
|
1999-02-12 17:45:58 +00:00
|
|
|
mWindowListener(nsnull),
|
1999-01-06 21:59:17 +00:00
|
|
|
mDocIsLoaded(PR_FALSE),
|
2000-03-02 07:13:02 +00:00
|
|
|
mAppShell(nsnull)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsXPBaseWindow::~nsXPBaseWindow()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mContentRoot);
|
|
|
|
NS_IF_RELEASE(mAppShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMPL_ADDREF(nsXPBaseWindow)
|
|
|
|
NS_IMPL_RELEASE(nsXPBaseWindow)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = NULL;
|
|
|
|
|
|
|
|
if (aIID.Equals(kIXPBaseWindowIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIXPBaseWindow*)this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIWebShellContainerIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIWebShellContainer*)this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
|
|
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
|
|
|
*aInstancePtrResult = (void *)((nsIDOMMouseListener*)this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
*aInstancePtrResult = (void*) ((nsISupports*)((nsIXPBaseWindow*)this));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleXPDialogEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsXPBaseWindow* baseWin;
|
|
|
|
aEvent->widget->GetClientData(((void*&)baseWin));
|
|
|
|
|
|
|
|
if (nsnull != baseWin) {
|
|
|
|
nsSizeEvent* sizeEvent;
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_SIZE:
|
|
|
|
sizeEvent = (nsSizeEvent*)aEvent;
|
|
|
|
baseWin->Layout(sizeEvent->windowSize->width,
|
|
|
|
sizeEvent->windowSize->height);
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_DESTROY: {
|
|
|
|
//nsViewerApp* app = baseWin->mApp;
|
|
|
|
result = nsEventStatus_eConsumeDoDefault;
|
|
|
|
baseWin->Close();
|
|
|
|
NS_RELEASE(baseWin);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//NS_RELEASE(baseWin);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::Init(nsXPBaseWindowType aType,
|
|
|
|
nsIAppShell* aAppShell,
|
|
|
|
const nsString& aDialogURL,
|
|
|
|
const nsString& aTitle,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRUint32 aChromeMask,
|
|
|
|
PRBool aAllowPlugins)
|
|
|
|
{
|
|
|
|
mAllowPlugins = aAllowPlugins;
|
|
|
|
mWindowType = aType;
|
|
|
|
mAppShell = aAppShell;
|
|
|
|
NS_IF_ADDREF(mAppShell);
|
|
|
|
|
|
|
|
// Create top level window
|
|
|
|
nsresult rv;
|
1999-06-10 22:03:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
|
1998-12-17 15:52:48 +00:00
|
|
|
(void**)&mWindow);
|
|
|
|
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWindow->SetClientData(this);
|
|
|
|
|
|
|
|
nsWidgetInitData initData;
|
1999-07-27 04:27:17 +00:00
|
|
|
initData.mWindowType = eWindowType_toplevel;
|
|
|
|
initData.mBorderStyle = eBorderStyle_default;
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
nsRect r(0, 0, aBounds.width, aBounds.height);
|
|
|
|
mWindow->Create((nsIWidget*)NULL, r, HandleXPDialogEvent,
|
|
|
|
nsnull, aAppShell, nsnull, &initData);
|
|
|
|
mWindow->GetBounds(r);
|
|
|
|
|
|
|
|
// Create web shell
|
1999-03-09 09:44:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kWebShellCID, nsnull,
|
1998-12-17 15:52:48 +00:00
|
|
|
kIWebShellIID,
|
|
|
|
(void**)&mWebShell);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
r.x = r.y = 0;
|
2000-03-11 00:20:07 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
docShell->SetAllowPlugins(aAllowPlugins);
|
|
|
|
nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(mWebShell));
|
|
|
|
|
|
|
|
rv = docShellWin->InitWindow(nsnull, mWindow, r.x, r.y, r.width, r.height);
|
|
|
|
docShellWin->Create();
|
1998-12-17 15:52:48 +00:00
|
|
|
mWebShell->SetContainer((nsIWebShellContainer*) this);
|
2000-03-11 00:20:07 +00:00
|
|
|
docShellWin->SetVisibility(PR_TRUE);
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
// Now lay it all out
|
|
|
|
Layout(r.width, r.height);
|
|
|
|
|
|
|
|
// Load URL to Load GUI
|
|
|
|
mDialogURL = aDialogURL;
|
|
|
|
LoadURL(mDialogURL);
|
|
|
|
|
2001-06-30 11:02:25 +00:00
|
|
|
SetTitle(aTitle.get());
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void nsXPBaseWindow::ForceRefresh()
|
|
|
|
{
|
|
|
|
nsIPresShell* shell;
|
|
|
|
GetPresShell(shell);
|
|
|
|
if (nsnull != shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
2004-05-17 16:29:13 +00:00
|
|
|
nsIView* root;
|
|
|
|
vm->GetRootView(root);
|
|
|
|
if (nsnull != root) {
|
|
|
|
vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void nsXPBaseWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
|
|
|
|
{
|
|
|
|
nsRect rr(0, 0, aWidth, aHeight);
|
1999-12-01 03:43:17 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
|
|
|
|
webShellWin->SetPositionAndSize(rr.x, rr.y, rr.width, rr.height, PR_FALSE);
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::SetLocation(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mWindow->Move(aX, aY);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::SetDimensions(PRInt32 aWidth, PRInt32 aHeight)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
|
|
|
|
// XXX We want to do this in one shot
|
|
|
|
mWindow->Resize(aWidth, aHeight, PR_FALSE);
|
|
|
|
Layout(aWidth, aHeight);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::GetBounds(nsRect& aBounds)
|
|
|
|
{
|
|
|
|
mWindow->GetBounds(aBounds);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPBaseWindow::GetWindowBounds(nsRect& aBounds)
|
|
|
|
{
|
|
|
|
//XXX This needs to be non-client bounds when it exists.
|
|
|
|
mWindow->GetBounds(aBounds);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::SetVisible(PRBool aIsVisible)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mWindow->Show(aIsVisible);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::Close()
|
|
|
|
{
|
|
|
|
if (nsnull != mWindowListener) {
|
|
|
|
mWindowListener->Destroy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mWebShell) {
|
1999-12-01 03:43:17 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
|
|
|
|
webShellWin->Destroy();
|
1998-12-17 15:52:48 +00:00
|
|
|
NS_RELEASE(mWebShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mWindow) {
|
|
|
|
nsIWidget* w = mWindow;
|
|
|
|
NS_RELEASE(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::GetWebShell(nsIWebShell*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mWebShell;
|
|
|
|
NS_IF_ADDREF(mWebShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::SetTitle(const PRUnichar* aTitle)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mTitle = aTitle;
|
|
|
|
nsAutoString newTitle(aTitle);
|
2000-08-20 00:45:05 +00:00
|
|
|
mWindow->SetTitle(newTitle);
|
1998-12-17 15:52:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
1999-02-14 06:35:01 +00:00
|
|
|
NS_IMETHODIMP nsXPBaseWindow::GetTitle(const PRUnichar** aResult)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
2001-09-29 08:28:41 +00:00
|
|
|
*aResult = ToNewUnicode(mTitle);
|
1998-12-17 15:52:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::LoadURL(const nsString& aURL)
|
|
|
|
{
|
2000-03-29 10:16:58 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebShell));
|
2001-11-30 22:35:33 +00:00
|
|
|
webNav->LoadURI(aURL.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
|
2000-03-29 10:16:58 +00:00
|
|
|
return NS_OK;
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
1999-08-05 01:28:30 +00:00
|
|
|
NS_IMETHODIMP nsXPBaseWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
|
|
|
// Find the Root Conent Node for this Window
|
|
|
|
nsIPresShell* shell;
|
|
|
|
GetPresShell(shell);
|
|
|
|
if (nsnull != shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
shell->GetDocument(getter_AddRefs(doc));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (doc) {
|
2003-10-22 06:09:48 +00:00
|
|
|
NS_IF_ADDREF(mContentRoot = doc->GetRootContent());
|
1998-12-17 15:52:48 +00:00
|
|
|
mDocIsLoaded = PR_TRUE;
|
|
|
|
if (nsnull != mWindowListener) {
|
|
|
|
mWindowListener->Initialize(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
1999-10-29 02:06:33 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPBaseWindow::FindWebShellWithName(const PRUnichar* aName,
|
|
|
|
nsIWebShell*& aResult)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
|
|
|
aResult = nsnull;
|
1999-10-29 02:06:33 +00:00
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
nsString aNameStr(aName);
|
|
|
|
|
1999-10-29 02:06:33 +00:00
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
GetWebShell(*getter_AddRefs(webShell));
|
2000-03-11 00:20:07 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(webShell));
|
1999-10-29 02:06:33 +00:00
|
|
|
if (webShell) {
|
2000-03-11 00:20:07 +00:00
|
|
|
nsXPIDLString name;
|
|
|
|
if (NS_SUCCEEDED(docShellAsItem->GetName(getter_Copies(name)))) {
|
2001-06-29 18:28:39 +00:00
|
|
|
if (aNameStr.Equals(name)) {
|
1999-10-29 02:06:33 +00:00
|
|
|
aResult = webShell;
|
1998-12-17 15:52:48 +00:00
|
|
|
NS_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-11 00:20:07 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(webShell));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> result;
|
|
|
|
if (NS_OK == docShellAsNode->FindChildWithName(aName, PR_TRUE, PR_FALSE,
|
|
|
|
nsnull, getter_AddRefs(result))) {
|
|
|
|
if (result) {
|
|
|
|
CallQueryInterface(result, &aResult);
|
1999-10-29 02:06:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-12 21:25:08 +00:00
|
|
|
NS_IMETHODIMP nsXPBaseWindow::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::AddEventListener(nsIDOMNode * aNode)
|
|
|
|
{
|
|
|
|
nsIDOMEventReceiver * receiver;
|
|
|
|
|
1999-01-11 19:46:09 +00:00
|
|
|
NS_PRECONDITION(nsnull != aNode, "adding event listener to null node");
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
|
1999-03-28 22:27:38 +00:00
|
|
|
receiver->AddEventListenerByIID((nsIDOMMouseListener*)this, kIDOMMouseListenerIID);
|
1998-12-17 15:52:48 +00:00
|
|
|
NS_RELEASE(receiver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::RemoveEventListener(nsIDOMNode * aNode)
|
|
|
|
{
|
|
|
|
nsIDOMEventReceiver * receiver;
|
|
|
|
|
1999-01-11 19:46:09 +00:00
|
|
|
NS_PRECONDITION(nsnull != aNode, "removing event listener from null node");
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
|
1999-03-28 22:27:38 +00:00
|
|
|
receiver->RemoveEventListenerByIID(this, kIDOMMouseListenerIID);
|
1998-12-17 15:52:48 +00:00
|
|
|
NS_RELEASE(receiver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::AddWindowListener(nsIWindowListener * aWindowListener)
|
|
|
|
{
|
1999-01-06 21:59:17 +00:00
|
|
|
if (nsnull != mWindowListener) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
mWindowListener = aWindowListener;
|
|
|
|
if (mDocIsLoaded && nsnull != mWindowListener) {
|
|
|
|
mWindowListener->Initialize(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// Get the HTML Document
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::GetDocument(nsIDOMHTMLDocument *& aDocument)
|
|
|
|
{
|
|
|
|
nsIDOMHTMLDocument *htmlDoc = nsnull;
|
|
|
|
nsIPresShell *shell = nsnull;
|
|
|
|
GetPresShell(shell);
|
|
|
|
if (nsnull != shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
shell->GetDocument(getter_AddRefs(doc));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (doc) {
|
1999-02-12 17:45:58 +00:00
|
|
|
doc->QueryInterface(kIDOMHTMLDocumentIID,(void **)&htmlDoc);
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
aDocument = htmlDoc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::NewWebShell(PRUint32 aChromeMask,
|
|
|
|
PRBool aVisible,
|
|
|
|
nsIWebShell*& aNewWebShell)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Create new window. By default, the refcnt will be 1 because of
|
|
|
|
// the registration of the browser window in gBrowsers.
|
|
|
|
nsXPBaseWindow* dialogWindow;
|
|
|
|
NS_NEWXPCOM(dialogWindow, nsXPBaseWindow);
|
|
|
|
|
|
|
|
if (nsnull != dialogWindow) {
|
|
|
|
nsRect bounds;
|
|
|
|
GetBounds(bounds);
|
|
|
|
|
2000-03-02 07:13:02 +00:00
|
|
|
rv = dialogWindow->Init(mWindowType, mAppShell, mDialogURL, mTitle, bounds, aChromeMask, mAllowPlugins);
|
1998-12-17 15:52:48 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
if (aVisible) {
|
|
|
|
dialogWindow->SetVisible(PR_TRUE);
|
|
|
|
}
|
|
|
|
nsIWebShell *shell;
|
|
|
|
rv = dialogWindow->GetWebShell(shell);
|
|
|
|
aNewWebShell = shell;
|
|
|
|
} else {
|
|
|
|
dialogWindow->Close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-19 21:08:44 +00:00
|
|
|
NS_IMETHODIMP
|
1999-05-04 23:33:55 +00:00
|
|
|
nsXPBaseWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
|
1999-04-19 21:08:44 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsXPBaseWindow::GetPresShell(nsIPresShell*& aPresShell)
|
|
|
|
{
|
|
|
|
aPresShell = nsnull;
|
|
|
|
|
2000-03-11 00:20:07 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
if (docShell) {
|
1998-12-17 15:52:48 +00:00
|
|
|
nsIContentViewer* cv = nsnull;
|
2000-03-11 00:20:07 +00:00
|
|
|
docShell->GetContentViewer(&cv);
|
1998-12-17 15:52:48 +00:00
|
|
|
if (nsnull != cv) {
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
|
|
|
|
if (nsnull != docv) {
|
2003-06-13 20:10:01 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
docv->GetPresContext(getter_AddRefs(cx));
|
1998-12-17 15:52:48 +00:00
|
|
|
if (nsnull != cx) {
|
2003-12-21 05:36:36 +00:00
|
|
|
NS_IF_ADDREF(aPresShell = cx->GetPresShell());
|
1998-12-17 15:52:48 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(docv);
|
|
|
|
}
|
|
|
|
NS_RELEASE(cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
//-- nsIDOMMouseListener
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
1999-03-28 22:27:38 +00:00
|
|
|
nsresult nsXPBaseWindow::HandleEvent(nsIDOMEvent* aEvent)
|
1998-12-17 15:52:48 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
if (nsnull != mWindowListener) {
|
|
|
|
PRBool status;
|
|
|
|
mWindowListener->MouseClick(aMouseEvent, this, status);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseOver(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
nsresult nsXPBaseWindow::MouseOut(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Factory code for creating nsXPBaseWindow's
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class nsXPBaseWindowFactory : public nsIFactory
|
|
|
|
{
|
|
|
|
public:
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFACTORY
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
nsXPBaseWindowFactory();
|
1999-04-30 00:12:17 +00:00
|
|
|
virtual ~nsXPBaseWindowFactory();
|
1998-12-17 15:52:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsXPBaseWindowFactory::nsXPBaseWindowFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsXPBaseWindowFactory::~nsXPBaseWindowFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsXPBaseWindowFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aResult == NULL) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aResult = (void *)(nsISupports*)this;
|
|
|
|
} else if (aIID.Equals(kIFactoryIID)) {
|
|
|
|
*aResult = (void *)(nsIFactory*)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*aResult == NULL) {
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-08 00:31:50 +00:00
|
|
|
NS_IMPL_ADDREF(nsXPBaseWindowFactory)
|
|
|
|
NS_IMPL_RELEASE(nsXPBaseWindowFactory)
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsXPBaseWindowFactory::CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsXPBaseWindow *inst;
|
|
|
|
|
|
|
|
if (aResult == NULL) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = NULL;
|
|
|
|
if (nsnull != aOuter) {
|
|
|
|
rv = NS_ERROR_NO_AGGREGATION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NEWXPCOM(inst, nsXPBaseWindow);
|
|
|
|
if (inst == NULL) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsXPBaseWindowFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
// Not implemented in simplest case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
NS_NewXPBaseWindowFactory(nsIFactory** aFactory)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsXPBaseWindowFactory* inst;
|
|
|
|
NS_NEWXPCOM(inst, nsXPBaseWindowFactory);
|
|
|
|
if (nsnull == inst) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
}
|
|
|
|
*aFactory = inst;
|
|
|
|
return rv;
|
|
|
|
}
|