1998-12-03 01:35:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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 "nsWebShellWindow.h"
|
|
|
|
|
1999-05-16 10:02:19 +00:00
|
|
|
#include "nsLayoutCID.h"
|
1999-08-12 22:08:17 +00:00
|
|
|
#include "nsIWeakReference.h"
|
1999-05-18 08:04:37 +00:00
|
|
|
#include "nsIDocumentLoader.h"
|
1999-05-16 10:02:19 +00:00
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-30 00:03:52 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1998-12-03 01:35:53 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
#endif // NECKO
|
1999-03-16 07:25:43 +00:00
|
|
|
#include "nsIPref.h"
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-04-20 22:35:11 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-05-27 20:36:15 +00:00
|
|
|
#include "nsEscape.h"
|
1999-04-19 22:05:49 +00:00
|
|
|
#include "nsVoidArray.h"
|
1999-04-20 22:35:11 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
1999-05-18 09:03:26 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMFocusListener.h"
|
1999-04-19 22:05:49 +00:00
|
|
|
|
1999-05-16 08:10:27 +00:00
|
|
|
#include "nsIXULParentDocument.h"
|
1999-05-18 09:03:26 +00:00
|
|
|
#include "nsIXULPopupListener.h"
|
|
|
|
#include "nsIXULChildDocument.h"
|
1999-05-21 02:34:03 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
1999-05-18 09:03:26 +00:00
|
|
|
#include "nsRDFCID.h"
|
1999-05-16 08:10:27 +00:00
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIAppShell.h"
|
1999-02-26 02:22:42 +00:00
|
|
|
#include "nsIXULWindowCallbacks.h"
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1998-12-30 00:03:52 +00:00
|
|
|
#include "nsIAppShellService.h"
|
1999-01-21 07:24:01 +00:00
|
|
|
#include "nsAppShellCIDs.h"
|
1998-12-30 00:03:52 +00:00
|
|
|
|
1999-02-11 15:14:34 +00:00
|
|
|
#include "nsXULCommand.h"
|
1999-01-27 04:02:33 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-02-15 05:38:15 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
1999-01-26 15:58:58 +00:00
|
|
|
|
1999-01-27 10:51:28 +00:00
|
|
|
#include "nsIMenuBar.h"
|
|
|
|
#include "nsIMenu.h"
|
|
|
|
#include "nsIMenuItem.h"
|
1999-02-04 02:42:07 +00:00
|
|
|
#include "nsIMenuListener.h"
|
1999-05-14 22:28:00 +00:00
|
|
|
#include "nsIContextMenu.h"
|
1999-01-27 10:51:28 +00:00
|
|
|
|
1999-02-18 05:01:03 +00:00
|
|
|
// For JS Execution
|
|
|
|
#include "nsIScriptContextOwner.h"
|
|
|
|
|
1999-03-20 04:13:09 +00:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "plevent.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
|
1999-01-21 07:24:01 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIDocument.h"
|
1999-02-04 02:42:07 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNode.h"
|
1999-01-26 15:58:58 +00:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocumentLoader.h"
|
1999-06-08 20:59:41 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "prprf.h"
|
1999-02-21 21:04:21 +00:00
|
|
|
//#include "nsIDOMHTMLInputElement.h"
|
|
|
|
//#include "nsIDOMHTMLImageElement.h"
|
|
|
|
|
|
|
|
#include "nsIContent.h" // for menus
|
1998-12-30 00:03:52 +00:00
|
|
|
|
1999-02-12 15:56:54 +00:00
|
|
|
// For calculating size
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
|
1999-04-08 04:29:37 +00:00
|
|
|
// HACK for M4, should be removed by M5
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#include <Menus.h>
|
|
|
|
#endif
|
1999-07-02 23:57:29 +00:00
|
|
|
#include "nsIMenuItem.h"
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
// End hack
|
|
|
|
|
1999-05-19 03:21:19 +00:00
|
|
|
#include "nsIWindowMediator.h"
|
1999-02-12 15:56:54 +00:00
|
|
|
|
1999-07-10 00:15:04 +00:00
|
|
|
// This is to bring up a MsgCompose window when a mailto link is clicked.
|
|
|
|
// This is a temporary hack for M8 until NECKO lands when I can use their
|
|
|
|
// Protocol registry
|
|
|
|
#include "nsIDOMToolkitCore.h"
|
|
|
|
#include "nsAppCoresCIDs.h"
|
|
|
|
|
1999-08-19 22:11:12 +00:00
|
|
|
#include "nsIPopupSetFrame.h"
|
1999-07-04 23:41:32 +00:00
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
/* Define Class IDs */
|
|
|
|
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
|
|
|
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
1998-12-30 00:03:52 +00:00
|
|
|
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
1999-03-20 04:13:09 +00:00
|
|
|
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-05-14 22:28:00 +00:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-01-27 10:51:28 +00:00
|
|
|
static NS_DEFINE_IID(kMenuBarCID, NS_MENUBAR_CID);
|
|
|
|
static NS_DEFINE_IID(kMenuCID, NS_MENU_CID);
|
|
|
|
static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID);
|
1999-05-14 22:28:00 +00:00
|
|
|
static NS_DEFINE_IID(kContextMenuCID, NS_CONTEXTMENU_CID);
|
1999-01-27 10:51:28 +00:00
|
|
|
|
1999-03-16 07:25:43 +00:00
|
|
|
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
1999-03-20 04:13:09 +00:00
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-07-10 00:15:04 +00:00
|
|
|
static NS_DEFINE_IID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
|
1999-03-16 07:25:43 +00:00
|
|
|
|
1999-05-19 03:21:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
|
|
|
|
|
1999-05-18 08:04:37 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderFactoryIID, NS_IDOCUMENTLOADERFACTORY_IID);
|
|
|
|
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
|
1999-07-05 00:53:20 +00:00
|
|
|
|
|
|
|
#ifndef NECKO
|
1999-07-06 14:51:33 +00:00
|
|
|
#ifdef MOZ_MAIL_NEWS
|
1999-07-04 23:41:32 +00:00
|
|
|
static NS_DEFINE_CID(kMsgComposeServiceCID, NS_MSGCOMPOSESERVICE_CID);
|
1999-07-06 14:51:33 +00:00
|
|
|
#endif /* MOZ_MAIL_NEWS */
|
1999-07-05 00:53:20 +00:00
|
|
|
#endif /* NECKO */
|
1999-03-16 07:25:43 +00:00
|
|
|
|
1999-05-19 03:21:19 +00:00
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
/* Define Interface IDs */
|
1999-01-21 07:24:01 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
1999-02-10 16:32:55 +00:00
|
|
|
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
|
1999-01-21 07:24:01 +00:00
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
1999-06-09 19:03:24 +00:00
|
|
|
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
|
1999-04-16 18:40:27 +00:00
|
|
|
|
1999-01-21 07:24:01 +00:00
|
|
|
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
|
1999-03-20 04:13:09 +00:00
|
|
|
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
1999-01-26 15:58:58 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
1999-01-27 04:02:33 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
|
1999-02-21 21:04:21 +00:00
|
|
|
//static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
|
|
|
|
//static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID);
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-05-14 22:28:00 +00:00
|
|
|
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
|
|
|
static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
|
|
|
|
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
|
|
|
|
static NS_DEFINE_IID(kIContextMenuIID, NS_ICONTEXTMENU_IID);
|
|
|
|
static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID);
|
|
|
|
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
1999-03-20 04:13:09 +00:00
|
|
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-05-19 03:21:19 +00:00
|
|
|
static NS_DEFINE_IID(kIWindowMediatorIID,NS_IWINDOWMEDIATOR_IID);
|
|
|
|
|
1999-05-18 09:03:26 +00:00
|
|
|
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
|
|
|
|
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
|
1999-07-04 23:41:32 +00:00
|
|
|
static NS_DEFINE_IID(kIUrlDispatcherIID, NS_IURLDISPATCHER_IID);
|
1999-05-19 03:21:19 +00:00
|
|
|
|
1999-03-26 11:34:21 +00:00
|
|
|
#ifdef DEBUG_rods
|
1999-02-21 21:04:21 +00:00
|
|
|
#define DEBUG_MENUSDEL 1
|
1999-03-26 11:34:21 +00:00
|
|
|
#endif
|
1999-08-11 03:05:25 +00:00
|
|
|
#include "nsICommonDialogs.h"
|
|
|
|
static NS_DEFINE_CID( kCommonDialogsCID, NS_CommonDialog_CID );
|
|
|
|
static NS_DEFINE_IID( kIPromptIID, NS_IPROMPT_IID );
|
1998-12-03 01:35:53 +00:00
|
|
|
#include "nsIWebShell.h"
|
|
|
|
|
1999-01-27 15:15:21 +00:00
|
|
|
const char * kThrobberOnStr = "resource:/res/throbber/anims07.gif";
|
|
|
|
const char * kThrobberOffStr = "resource:/res/throbber/anims00.gif";
|
1999-06-26 21:48:29 +00:00
|
|
|
const char * kPrimaryContentTypeValue = "content-primary";
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-03-20 04:13:09 +00:00
|
|
|
struct ThreadedWindowEvent {
|
|
|
|
PLEvent event;
|
|
|
|
nsWebShellWindow *window;
|
|
|
|
};
|
|
|
|
|
1999-04-19 22:05:49 +00:00
|
|
|
// The web shell info object is used to hold information about content areas that will
|
|
|
|
// subsequently be filled in when we receive a webshell added notification.
|
|
|
|
struct nsWebShellInfo {
|
|
|
|
nsString id; // The identifier of the iframe or frame node in the XUL tree.
|
1999-06-26 21:48:29 +00:00
|
|
|
PRBool primary; // whether it's considered a/the primary content
|
1999-04-20 22:35:11 +00:00
|
|
|
nsIWebShell* child; // The child web shell that will end up being used for the content area.
|
1999-04-19 22:05:49 +00:00
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
nsWebShellInfo(const nsString& anID, PRBool aPrimary, nsIWebShell* aChildShell)
|
1999-04-19 22:05:49 +00:00
|
|
|
{
|
1999-05-04 23:36:42 +00:00
|
|
|
id = anID;
|
1999-06-26 21:48:29 +00:00
|
|
|
primary = aPrimary;
|
1999-04-20 22:35:11 +00:00
|
|
|
child = aChildShell;
|
|
|
|
NS_IF_ADDREF(aChildShell);
|
1999-04-19 22:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~nsWebShellInfo()
|
|
|
|
{
|
1999-04-20 22:35:11 +00:00
|
|
|
NS_IF_RELEASE(child);
|
1999-04-19 22:05:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
nsWebShellWindow::nsWebShellWindow()
|
|
|
|
{
|
1998-12-30 00:03:52 +00:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
mWebShell = nsnull;
|
|
|
|
mWindow = nsnull;
|
1999-02-26 02:22:42 +00:00
|
|
|
mCallbacks = nsnull;
|
1999-03-20 04:13:09 +00:00
|
|
|
mContinueModalLoop = PR_FALSE;
|
1999-04-06 21:01:51 +00:00
|
|
|
mChromeInitialized = PR_FALSE;
|
1999-05-19 04:11:54 +00:00
|
|
|
mLockedUntilChromeLoad = PR_FALSE;
|
1999-04-19 22:05:49 +00:00
|
|
|
mContentShells = nsnull;
|
1999-05-19 04:11:54 +00:00
|
|
|
mChromeMask = NS_CHROME_ALL_CHROME;
|
1999-07-04 04:09:54 +00:00
|
|
|
mIntrinsicallySized = PR_FALSE;
|
1999-07-20 14:40:55 +00:00
|
|
|
mCreatedVisible = PR_TRUE;
|
1999-08-16 22:23:19 +00:00
|
|
|
mLoadDefaultPage = PR_TRUE;
|
1998-12-03 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsWebShellWindow::~nsWebShellWindow()
|
|
|
|
{
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
mWebShell->Destroy();
|
|
|
|
NS_RELEASE(mWebShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mWindow);
|
1999-02-26 02:22:42 +00:00
|
|
|
NS_IF_RELEASE(mCallbacks);
|
1999-04-19 22:05:49 +00:00
|
|
|
|
|
|
|
// Delete any remaining content shells.
|
|
|
|
PRInt32 count;
|
|
|
|
if (mContentShells && ((count = mContentShells->Count()) > 0)) {
|
|
|
|
for (PRInt32 i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
nsWebShellInfo* webInfo = (nsWebShellInfo*)(mContentShells->ElementAt(i));
|
|
|
|
delete webInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mContentShells;
|
|
|
|
}
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
1999-06-19 22:07:13 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsWebShellWindow::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
|
|
|
++mRefCnt;
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-06-19 22:07:13 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsWebShellWindow::Release(void)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
|
|
--mRefCnt;
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
NS_DELETEXPCOM(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
1998-12-30 00:03:52 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWebShellWindow::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-02-10 16:32:55 +00:00
|
|
|
if ( aIID.Equals(kIWebShellWindowIID) ) {
|
|
|
|
*aInstancePtr = (void*) ((nsIWebShellWindow*)this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-21 07:24:01 +00:00
|
|
|
if (aIID.Equals(kIWebShellContainerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIWebShellContainer*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-26 15:58:58 +00:00
|
|
|
if (aIID.Equals(kIDocumentLoaderObserverIID)) {
|
|
|
|
*aInstancePtr = (void*) ((nsIDocumentLoaderObserver*)this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
1999-04-16 18:40:27 +00:00
|
|
|
}
|
1999-08-12 22:08:17 +00:00
|
|
|
if (aIID.Equals(kIBrowserWindowIID)) {
|
1999-04-16 18:40:27 +00:00
|
|
|
*aInstancePtr = (void*) (nsIBrowserWindow*) this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
1999-01-26 15:58:58 +00:00
|
|
|
}
|
1999-08-12 22:08:17 +00:00
|
|
|
if (aIID.Equals(kIUrlDispatcherIID)) {
|
1999-07-04 23:41:32 +00:00
|
|
|
*aInstancePtr = (void*) (nsIUrlDispatcher*) this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-12 22:08:17 +00:00
|
|
|
if (aIID.Equals(kIPromptIID )) {
|
1999-08-11 03:05:25 +00:00
|
|
|
*aInstancePtr = (void*)(nsIPrompt*)this;
|
1999-07-28 02:52:14 +00:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-12 22:08:17 +00:00
|
|
|
if (aIID.Equals(nsIModalWindowSupport::GetIID())) {
|
|
|
|
*aInstancePtr = (void*)NS_STATIC_CAST(nsIModalWindowSupport*, this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(nsISupportsWeakReference::GetIID())) {
|
|
|
|
*aInstancePtr = (void*)NS_STATIC_CAST(nsISupportsWeakReference *, this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-30 00:03:52 +00:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1999-01-26 15:58:58 +00:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)(nsIWebShellContainer*)this;
|
1998-12-30 00:03:52 +00:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-03-20 04:13:09 +00:00
|
|
|
nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIAppShell* aShell, nsIURI* aUrl,
|
1999-07-20 14:40:55 +00:00
|
|
|
PRBool aCreatedVisible,
|
1999-08-16 22:23:19 +00:00
|
|
|
PRBool aLoadDefaultPage,
|
1999-02-26 02:22:42 +00:00
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
1999-07-01 02:50:53 +00:00
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
|
|
|
|
nsWidgetInitData& widgetInitData)
|
1998-12-03 01:35:53 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-08-19 14:44:31 +00:00
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
1999-07-20 14:40:55 +00:00
|
|
|
|
|
|
|
mCreatedVisible = aCreatedVisible;
|
1999-08-16 22:23:19 +00:00
|
|
|
mLoadDefaultPage = aLoadDefaultPage;
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
// XXX: need to get the default window size from prefs...
|
1999-07-20 14:40:55 +00:00
|
|
|
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
1999-02-18 21:52:27 +00:00
|
|
|
nsRect r(0, 0, aInitialWidth, aInitialHeight);
|
1998-12-03 01:35:53 +00:00
|
|
|
|
|
|
|
// Create top level window
|
1999-03-09 09:44:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
|
1998-12-03 01:35:53 +00:00
|
|
|
(void**)&mWindow);
|
|
|
|
if (NS_OK != rv) {
|
1999-02-21 21:04:21 +00:00
|
|
|
return rv;
|
1998-12-03 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
1999-08-12 22:08:17 +00:00
|
|
|
/* This next bit is troublesome. We carry two different versions of a pointer
|
|
|
|
to our parent window. One is the parent window's widget, which is passed
|
|
|
|
to our own widget. The other is a weak reference we keep here to our
|
|
|
|
parent WebShellWindow. The former is useful to the widget, and we can't
|
|
|
|
trust its treatment of the parent reference because they're platform-
|
|
|
|
specific. The latter is useful to this class.
|
|
|
|
A better implementation would be one in which the parent keeps strong
|
|
|
|
references to its children and closes them before it allows itself
|
|
|
|
to be closed. This would mimic the behaviour of OSes that support
|
|
|
|
top-level child windows in OSes that do not. Later.
|
|
|
|
*/
|
|
|
|
if (aParent) {
|
1999-08-19 14:44:31 +00:00
|
|
|
aParent->GetWidget(*getter_AddRefs(parentWidget));
|
1999-08-12 22:08:17 +00:00
|
|
|
mParentWindow = getter_AddRefs(NS_GetWeakReference(aParent));
|
|
|
|
}
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
mWindow->SetClientData(this);
|
1999-08-19 16:57:32 +00:00
|
|
|
mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
|
1998-12-03 01:35:53 +00:00
|
|
|
r, // Widget dimensions
|
|
|
|
nsWebShellWindow::HandleEvent, // Event handler function
|
|
|
|
nsnull, // Device context
|
|
|
|
aShell, // Application shell
|
|
|
|
nsnull, // nsIToolkit
|
1999-07-01 02:50:53 +00:00
|
|
|
&widgetInitData); // Widget initialization data
|
1998-12-03 01:35:53 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
|
|
|
mWindow->SetBackgroundColor(NS_RGB(192,192,192));
|
|
|
|
|
|
|
|
// Create web shell
|
1999-03-09 09:44:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kWebShellCID, nsnull,
|
1998-12-03 01:35:53 +00:00
|
|
|
kIWebShellIID,
|
|
|
|
(void**)&mWebShell);
|
|
|
|
if (NS_OK != rv) {
|
1999-02-21 21:04:21 +00:00
|
|
|
return rv;
|
1998-12-03 01:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r.x = r.y = 0;
|
|
|
|
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
|
|
|
|
r.x, r.y, r.width, r.height,
|
1998-12-30 00:03:52 +00:00
|
|
|
nsScrollPreference_kNeverScroll,
|
1998-12-03 01:35:53 +00:00
|
|
|
PR_TRUE, // Allow Plugins
|
|
|
|
PR_TRUE);
|
1999-01-21 07:24:01 +00:00
|
|
|
mWebShell->SetContainer(this);
|
1999-04-06 21:01:51 +00:00
|
|
|
mWebShell->SetDocLoaderObserver(this);
|
1999-03-16 07:25:43 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
// The outermost web shell is always considered to be chrome.
|
|
|
|
mWebShell->SetWebShellType(nsWebShellChrome);
|
1999-04-16 08:12:44 +00:00
|
|
|
|
1999-03-16 07:25:43 +00:00
|
|
|
/*
|
|
|
|
* XXX: How should preferences be supplied to the nsWebShellWindow?
|
|
|
|
* Should there be the notion of a global preferences service?
|
|
|
|
* Or should there be many preferences components based on
|
|
|
|
* the user profile...
|
|
|
|
*/
|
|
|
|
// Initialize the webshell with the preferences service
|
|
|
|
nsIPref *prefs;
|
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(kPrefCID,
|
|
|
|
nsIPref::GetIID(),
|
|
|
|
(nsISupports **)&prefs);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-06-08 06:05:53 +00:00
|
|
|
// Set the prefs in the outermost webshell.
|
1999-03-16 07:25:43 +00:00
|
|
|
mWebShell->SetPrefs(prefs);
|
|
|
|
nsServiceManager::ReleaseService(kPrefCID, prefs);
|
|
|
|
}
|
1998-12-03 01:35:53 +00:00
|
|
|
|
1999-02-26 02:22:42 +00:00
|
|
|
NS_IF_RELEASE(mCallbacks);
|
|
|
|
mCallbacks = aCallbacks;
|
|
|
|
NS_IF_ADDREF(mCallbacks);
|
|
|
|
|
1999-02-10 16:32:55 +00:00
|
|
|
if (nsnull != aUrl) {
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
char *tmpStr = NULL;
|
|
|
|
#else
|
1999-05-27 20:36:15 +00:00
|
|
|
const char *tmpStr = NULL;
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-09-09 20:44:17 +00:00
|
|
|
nsAutoString urlString;
|
1999-05-27 20:36:15 +00:00
|
|
|
|
|
|
|
aUrl->GetSpec(&tmpStr);
|
|
|
|
urlString = tmpStr;
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(tmpStr);
|
|
|
|
#endif
|
1999-04-22 00:05:59 +00:00
|
|
|
mWebShell->LoadURL(urlString.GetUnicode());
|
1999-02-10 16:32:55 +00:00
|
|
|
}
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-18 19:08:36 +00:00
|
|
|
/*
|
|
|
|
* Close the window
|
|
|
|
*/
|
|
|
|
NS_METHOD
|
|
|
|
nsWebShellWindow::Close()
|
|
|
|
{
|
1999-03-20 04:13:09 +00:00
|
|
|
ExitModalLoop();
|
1999-05-19 04:11:54 +00:00
|
|
|
if (mWebShell) {
|
1999-04-30 09:04:36 +00:00
|
|
|
mWebShell->Destroy();
|
1999-05-19 04:11:54 +00:00
|
|
|
NS_RELEASE(mWebShell);
|
1999-04-30 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
1999-03-18 19:08:36 +00:00
|
|
|
NS_IF_RELEASE(mWindow);
|
1999-03-27 00:09:04 +00:00
|
|
|
nsIAppShellService* appShell;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kAppShellServiceCID,
|
|
|
|
kIAppShellServiceIID,
|
|
|
|
(nsISupports**)&appShell);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = appShell->UnregisterTopLevelWindow(this);
|
1999-09-11 06:25:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
|
1999-05-08 23:07:10 +00:00
|
|
|
|
1999-03-27 00:09:04 +00:00
|
|
|
return rv;
|
1999-03-18 19:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
/*
|
|
|
|
* Event handler function...
|
|
|
|
*
|
|
|
|
* This function is called to process events for the nsIWidget of the
|
|
|
|
* nsWebShellWindow...
|
|
|
|
*/
|
|
|
|
nsEventStatus PR_CALLBACK
|
|
|
|
nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
nsIWebShell* webShell = nsnull;
|
|
|
|
|
|
|
|
// Get the WebShell instance...
|
|
|
|
if (nsnull != aEvent->widget) {
|
|
|
|
void* data;
|
|
|
|
|
|
|
|
aEvent->widget->GetClientData(data);
|
|
|
|
if (nsnull != data) {
|
|
|
|
webShell = ((nsWebShellWindow*)data)->mWebShell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != webShell) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
/*
|
|
|
|
* For size events, the WebShell must be resized to fill the entire
|
|
|
|
* client area of the window...
|
|
|
|
*/
|
|
|
|
case NS_SIZE: {
|
|
|
|
nsSizeEvent* sizeEvent = (nsSizeEvent*)aEvent;
|
|
|
|
webShell->SetBounds(0, 0, sizeEvent->windowSize->width, sizeEvent->windowSize->height);
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Notify the ApplicationShellService that the window is being closed...
|
|
|
|
*/
|
1998-12-30 00:03:52 +00:00
|
|
|
case NS_DESTROY: {
|
1999-03-27 00:09:04 +00:00
|
|
|
void* data;
|
|
|
|
aEvent->widget->GetClientData(data);
|
|
|
|
if (data)
|
|
|
|
((nsWebShellWindow *)data)->Close();
|
1998-12-03 01:35:53 +00:00
|
|
|
break;
|
1998-12-30 00:03:52 +00:00
|
|
|
}
|
1999-05-29 19:36:55 +00:00
|
|
|
|
1999-07-02 19:43:26 +00:00
|
|
|
case NS_GOTFOCUS: {
|
|
|
|
void* data;
|
|
|
|
aEvent->widget->GetClientData(data);
|
|
|
|
if (data) {
|
1999-08-24 00:43:31 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
1999-07-02 19:43:26 +00:00
|
|
|
nsCOMPtr<nsIWebShell> contentShell;
|
|
|
|
((nsWebShellWindow *)data)->GetContentWebShell(getter_AddRefs(contentShell));
|
|
|
|
if (contentShell) {
|
1999-08-24 00:43:31 +00:00
|
|
|
|
1999-07-02 19:43:26 +00:00
|
|
|
if (NS_SUCCEEDED(((nsWebShellWindow *)data)->
|
|
|
|
ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
|
|
|
domWindow->Focus();
|
|
|
|
}
|
|
|
|
}
|
1999-08-24 00:43:31 +00:00
|
|
|
else if (webShell && NS_SUCCEEDED(((nsWebShellWindow *)data)->
|
|
|
|
ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow)))) {
|
|
|
|
domWindow->Focus();
|
|
|
|
}
|
1999-07-02 19:43:26 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-29 19:36:55 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
1998-12-03 01:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
1999-01-21 07:24:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
|
|
|
|
nsLoadType aReason)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
|
|
|
{
|
1999-04-08 06:58:13 +00:00
|
|
|
// If loading a new root .xul document, then redo chrome.
|
1999-05-19 04:11:54 +00:00
|
|
|
if (aShell == mWebShell) {
|
1999-04-08 06:58:13 +00:00
|
|
|
mChromeInitialized = PR_FALSE;
|
|
|
|
}
|
1999-01-21 07:24:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
|
|
|
|
PRInt32 aProgress, PRInt32 aProgressMax)
|
|
|
|
{
|
1999-01-27 04:02:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-10 16:32:55 +00:00
|
|
|
nsWebShellWindow::EndLoadURL(nsIWebShell* aWebShell, const PRUnichar* aURL,
|
1999-08-05 01:28:30 +00:00
|
|
|
nsresult aStatus)
|
1999-01-27 04:02:33 +00:00
|
|
|
{
|
1999-01-21 07:24:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-06 21:01:51 +00:00
|
|
|
|
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
//----------------------------------------
|
|
|
|
nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedParentFromDoc(nsIDOMDocument * aDomDoc, const nsString &aName)
|
1999-01-26 15:58:58 +00:00
|
|
|
{
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node; // result.
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aDomDoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
if (!element)
|
|
|
|
return node;
|
1999-02-12 15:56:54 +00:00
|
|
|
|
1999-02-17 02:08:00 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> parent(do_QueryInterface(element));
|
1999-01-30 00:39:25 +00:00
|
|
|
if (!parent)
|
|
|
|
return node;
|
1999-02-12 15:56:54 +00:00
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
parent->GetFirstChild(getter_AddRefs(node));
|
|
|
|
while (node) {
|
|
|
|
nsString name;
|
|
|
|
node->GetNodeName(name);
|
1999-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_rods
|
1999-02-12 15:56:54 +00:00
|
|
|
printf("Looking for [%s] [%s]\n", aName.ToNewCString(), name.ToNewCString()); // this leaks
|
1999-03-26 11:34:21 +00:00
|
|
|
#endif
|
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
if (name.Equals(aName))
|
|
|
|
return node;
|
|
|
|
nsCOMPtr<nsIDOMNode> oldNode(node);
|
|
|
|
oldNode->GetNextSibling(getter_AddRefs(node));
|
1999-01-26 15:58:58 +00:00
|
|
|
}
|
1999-02-19 12:27:19 +00:00
|
|
|
node = do_QueryInterface(nsnull);
|
1999-01-30 00:39:25 +00:00
|
|
|
return node;
|
1999-01-26 15:58:58 +00:00
|
|
|
}
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::CreateMenu(nsIMenuBar * aMenuBar,
|
|
|
|
nsIDOMNode * aMenuNode,
|
|
|
|
nsString & aMenuName)
|
|
|
|
{
|
|
|
|
// Create nsMenu
|
|
|
|
nsIMenu * pnsMenu = nsnull;
|
1999-03-09 09:44:27 +00:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kMenuCID, nsnull, kIMenuIID, (void**)&pnsMenu);
|
1999-02-21 21:04:21 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Call Create
|
1999-03-20 02:56:03 +00:00
|
|
|
nsISupports * supports = nsnull;
|
|
|
|
aMenuBar->QueryInterface(kISupportsIID, (void**) &supports);
|
|
|
|
pnsMenu->Create(supports, aMenuName);
|
|
|
|
NS_RELEASE(supports);
|
1999-02-21 21:04:21 +00:00
|
|
|
|
|
|
|
// Set nsMenu Name
|
|
|
|
pnsMenu->SetLabel(aMenuName);
|
|
|
|
// Make nsMenu a child of nsMenuBar
|
1999-02-23 07:52:14 +00:00
|
|
|
aMenuBar->AddMenu(pnsMenu);
|
1999-02-21 21:04:21 +00:00
|
|
|
|
1999-06-04 22:52:35 +00:00
|
|
|
// Open the node so that the contents are visible.
|
|
|
|
nsCOMPtr<nsIDOMElement> menuElement = do_QueryInterface(aMenuNode);
|
|
|
|
if (menuElement)
|
|
|
|
menuElement->SetAttribute("open", "true");
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
// Begin menuitem inner loop
|
1999-07-31 07:15:20 +00:00
|
|
|
|
|
|
|
// Now get the kids. Retrieve our menupopup child.
|
|
|
|
nsCOMPtr<nsIDOMNode> menuPopupNode;
|
|
|
|
aMenuNode->GetFirstChild(getter_AddRefs(menuPopupNode));
|
|
|
|
while (menuPopupNode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> menuPopupElement(do_QueryInterface(menuPopupNode));
|
|
|
|
if (menuPopupElement) {
|
|
|
|
nsString menuPopupNodeType;
|
|
|
|
menuPopupElement->GetNodeName(menuPopupNodeType);
|
|
|
|
if (menuPopupNodeType.Equals("menupopup"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> oldMenuPopupNode(menuPopupNode);
|
|
|
|
oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menuPopupNode)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> menuitemNode;
|
1999-07-31 07:15:20 +00:00
|
|
|
menuPopupNode->GetFirstChild(getter_AddRefs(menuitemNode));
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
while (menuitemNode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> menuitemElement(do_QueryInterface(menuitemNode));
|
|
|
|
if (menuitemElement) {
|
|
|
|
nsString menuitemNodeType;
|
|
|
|
nsString menuitemName;
|
|
|
|
menuitemElement->GetNodeName(menuitemNodeType);
|
|
|
|
if (menuitemNodeType.Equals("menuitem")) {
|
1999-02-23 07:52:14 +00:00
|
|
|
// LoadMenuItem
|
|
|
|
LoadMenuItem(pnsMenu, menuitemElement, menuitemNode);
|
1999-08-02 08:59:35 +00:00
|
|
|
} else if (menuitemNodeType.Equals("menuseparator")) {
|
1999-02-21 21:04:21 +00:00
|
|
|
pnsMenu->AddSeparator();
|
1999-02-23 07:52:14 +00:00
|
|
|
} else if (menuitemNodeType.Equals("menu")) {
|
|
|
|
// Load a submenu
|
|
|
|
LoadSubMenu(pnsMenu, menuitemElement, menuitemNode);
|
1999-02-21 21:04:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> oldmenuitemNode(menuitemNode);
|
|
|
|
oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode));
|
|
|
|
} // end menu item innner loop
|
1999-04-27 09:09:44 +00:00
|
|
|
// The parent owns us, so we can release
|
|
|
|
NS_RELEASE(pnsMenu);
|
1999-02-21 21:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
//----------------------------------------
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::LoadMenuItem(
|
|
|
|
nsIMenu * pParentMenu,
|
|
|
|
nsIDOMElement * menuitemElement,
|
|
|
|
nsIDOMNode * menuitemNode)
|
|
|
|
{
|
|
|
|
nsString menuitemName;
|
|
|
|
nsString menuitemCmd;
|
|
|
|
|
1999-08-01 04:21:50 +00:00
|
|
|
menuitemElement->GetAttribute(nsAutoString("value"), menuitemName);
|
1999-02-23 07:52:14 +00:00
|
|
|
menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd);
|
|
|
|
// Create nsMenuItem
|
|
|
|
nsIMenuItem * pnsMenuItem = nsnull;
|
1999-03-09 09:44:27 +00:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem);
|
1999-02-23 07:52:14 +00:00
|
|
|
if (NS_OK == rv) {
|
1999-07-02 23:57:29 +00:00
|
|
|
// Create MenuDelegate - this is the intermediator inbetween
|
|
|
|
// the DOM node and the nsIMenuItem
|
|
|
|
// The nsWebShellWindow wacthes for Document changes and then notifies the
|
|
|
|
// the appropriate nsMenuDelegate object
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(menuitemNode));
|
|
|
|
if (!domElement) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-02-26 02:50:09 +00:00
|
|
|
pnsMenuItem->Create(pParentMenu, menuitemName, 0);
|
1999-02-23 07:52:14 +00:00
|
|
|
// Set nsMenuItem Name
|
1999-02-26 02:50:09 +00:00
|
|
|
//pnsMenuItem->SetLabel(menuitemName);
|
1999-07-02 23:57:29 +00:00
|
|
|
|
|
|
|
// Set key shortcut and modifiers
|
|
|
|
nsAutoString keyAtom("key");
|
|
|
|
nsString keyValue;
|
|
|
|
domElement->GetAttribute(keyAtom, keyValue);
|
|
|
|
|
|
|
|
// Try to find the key node.
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(domElement);
|
|
|
|
if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the document.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn the document into a XUL document so we can use getElementById
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);
|
|
|
|
if (xulDocument == nsnull) {
|
|
|
|
NS_ERROR("not XUL!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMElement * keyElement = nsnull;
|
|
|
|
xulDocument->GetElementById(keyValue, &keyElement);
|
|
|
|
|
|
|
|
if(keyElement){
|
|
|
|
PRUint8 modifiers = knsMenuItemNoModifier;
|
|
|
|
nsAutoString shiftAtom("shift");
|
|
|
|
nsAutoString altAtom("alt");
|
|
|
|
nsAutoString commandAtom("command");
|
|
|
|
nsString shiftValue;
|
|
|
|
nsString altValue;
|
|
|
|
nsString commandValue;
|
|
|
|
nsString keyChar = " ";
|
|
|
|
|
|
|
|
keyElement->GetAttribute(keyAtom, keyChar);
|
|
|
|
keyElement->GetAttribute(shiftAtom, shiftValue);
|
|
|
|
keyElement->GetAttribute(altAtom, altValue);
|
|
|
|
keyElement->GetAttribute(commandAtom, commandValue);
|
|
|
|
|
|
|
|
if(keyChar != " ")
|
|
|
|
pnsMenuItem->SetShortcutChar(keyChar);
|
|
|
|
|
|
|
|
if(shiftValue == "true")
|
1999-07-03 00:31:23 +00:00
|
|
|
modifiers |= knsMenuItemShiftModifier;
|
1999-07-02 23:57:29 +00:00
|
|
|
|
|
|
|
if(altValue == "true")
|
1999-07-03 00:31:23 +00:00
|
|
|
modifiers |= knsMenuItemAltModifier;
|
1999-07-02 23:57:29 +00:00
|
|
|
|
|
|
|
if(commandValue == "false")
|
1999-07-03 00:31:23 +00:00
|
|
|
modifiers |= knsMenuItemCommandModifier;
|
1999-07-02 23:57:29 +00:00
|
|
|
|
|
|
|
pnsMenuItem->SetModifiers(modifiers);
|
|
|
|
}
|
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
// Make nsMenuItem a child of nsMenu
|
1999-03-20 02:56:03 +00:00
|
|
|
nsISupports * supports = nsnull;
|
|
|
|
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
|
|
|
|
pParentMenu->AddItem(supports);
|
|
|
|
NS_RELEASE(supports);
|
1999-02-23 07:52:14 +00:00
|
|
|
|
1999-07-02 23:57:29 +00:00
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
|
1999-08-02 08:55:15 +00:00
|
|
|
nsAutoString cmdAtom("onaction");
|
1999-02-23 07:52:14 +00:00
|
|
|
nsString cmdName;
|
|
|
|
|
|
|
|
domElement->GetAttribute(cmdAtom, cmdName);
|
|
|
|
|
|
|
|
nsXULCommand * menuDelegate = new nsXULCommand();
|
1999-08-25 23:15:37 +00:00
|
|
|
if ( menuDelegate ) {
|
|
|
|
menuDelegate->SetCommand(cmdName);
|
|
|
|
menuDelegate->SetWebShell(mWebShell);
|
|
|
|
menuDelegate->SetDOMElement(domElement);
|
|
|
|
menuDelegate->SetMenuItem(pnsMenuItem);
|
|
|
|
} else {
|
|
|
|
NS_RELEASE( pnsMenuItem );
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-07-02 23:57:29 +00:00
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
nsIXULCommand * icmd;
|
|
|
|
if (NS_OK == menuDelegate->QueryInterface(kIXULCommandIID, (void**) &icmd)) {
|
|
|
|
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menuDelegate));
|
1999-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
if (listener)
|
|
|
|
{
|
1999-02-23 07:52:14 +00:00
|
|
|
pnsMenuItem->AddMenuListener(listener);
|
1999-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_MENUSDEL
|
|
|
|
printf("Adding menu listener to [%s]\n", menuitemName.ToNewCString());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_MENUSDEL
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("*** NOT Adding menu listener to [%s]\n", menuitemName.ToNewCString());
|
1999-02-23 07:52:14 +00:00
|
|
|
}
|
1999-03-26 11:34:21 +00:00
|
|
|
#endif
|
1999-04-27 09:38:56 +00:00
|
|
|
NS_RELEASE(icmd);
|
1999-02-23 07:52:14 +00:00
|
|
|
}
|
1999-04-27 09:09:44 +00:00
|
|
|
|
|
|
|
// The parent owns us, so we can release
|
|
|
|
NS_RELEASE(pnsMenuItem);
|
1999-08-25 23:15:37 +00:00
|
|
|
}
|
1999-02-23 07:52:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
void nsWebShellWindow::LoadSubMenu(
|
|
|
|
nsIMenu * pParentMenu,
|
|
|
|
nsIDOMElement * menuElement,
|
|
|
|
nsIDOMNode * menuNode)
|
|
|
|
{
|
|
|
|
nsString menuName;
|
1999-08-01 04:21:50 +00:00
|
|
|
menuElement->GetAttribute(nsAutoString("value"), menuName);
|
1999-02-23 07:52:14 +00:00
|
|
|
//printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks
|
|
|
|
|
|
|
|
// Create nsMenu
|
|
|
|
nsIMenu * pnsMenu = nsnull;
|
1999-03-09 09:44:27 +00:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kMenuCID, nsnull, kIMenuIID, (void**)&pnsMenu);
|
1999-02-23 07:52:14 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Call Create
|
1999-03-20 02:56:03 +00:00
|
|
|
nsISupports * supports = nsnull;
|
|
|
|
pParentMenu->QueryInterface(kISupportsIID, (void**) &supports);
|
|
|
|
pnsMenu->Create(supports, menuName);
|
|
|
|
NS_RELEASE(supports); // Balance QI
|
1999-02-23 07:52:14 +00:00
|
|
|
|
1999-07-07 00:48:06 +00:00
|
|
|
// Open the node so that the contents are visible.
|
|
|
|
menuElement->SetAttribute("open", "true");
|
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
// Set nsMenu Name
|
|
|
|
pnsMenu->SetLabel(menuName);
|
|
|
|
// Make nsMenu a child of parent nsMenu
|
1999-03-20 02:56:03 +00:00
|
|
|
//pParentMenu->AddMenu(pnsMenu);
|
|
|
|
supports = nsnull;
|
|
|
|
pnsMenu->QueryInterface(kISupportsIID, (void**) &supports);
|
|
|
|
pParentMenu->AddItem(supports);
|
|
|
|
NS_RELEASE(supports);
|
1999-02-23 07:52:14 +00:00
|
|
|
|
|
|
|
// Begin menuitem inner loop
|
1999-07-31 07:15:20 +00:00
|
|
|
|
|
|
|
// Now get the kids. Retrieve our menupopup child.
|
|
|
|
nsCOMPtr<nsIDOMNode> menuPopupNode;
|
|
|
|
menuNode->GetFirstChild(getter_AddRefs(menuPopupNode));
|
|
|
|
while (menuPopupNode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> menuPopupElement(do_QueryInterface(menuPopupNode));
|
|
|
|
if (menuPopupElement) {
|
|
|
|
nsString menuPopupNodeType;
|
|
|
|
menuPopupElement->GetNodeName(menuPopupNodeType);
|
|
|
|
if (menuPopupNodeType.Equals("menupopup"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> oldMenuPopupNode(menuPopupNode);
|
|
|
|
oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menuPopupNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> menuitemNode;
|
|
|
|
menuPopupNode->GetFirstChild(getter_AddRefs(menuitemNode));
|
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
while (menuitemNode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> menuitemElement(do_QueryInterface(menuitemNode));
|
|
|
|
if (menuitemElement) {
|
|
|
|
nsString menuitemNodeType;
|
|
|
|
menuitemElement->GetNodeName(menuitemNodeType);
|
1999-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_saari
|
1999-08-02 08:59:56 +00:00
|
|
|
printf("Type [%s] %d\n", menuitemNodeType.ToNewCString(), menuitemNodeType.Equals("menuseparator"));
|
1999-03-26 11:34:21 +00:00
|
|
|
#endif
|
|
|
|
|
1999-02-23 07:52:14 +00:00
|
|
|
if (menuitemNodeType.Equals("menuitem")) {
|
|
|
|
// Load a menuitem
|
|
|
|
LoadMenuItem(pnsMenu, menuitemElement, menuitemNode);
|
1999-08-02 08:59:35 +00:00
|
|
|
} else if (menuitemNodeType.Equals("menuseparator")) {
|
1999-02-23 07:52:14 +00:00
|
|
|
pnsMenu->AddSeparator();
|
|
|
|
} else if (menuitemNodeType.Equals("menu")) {
|
|
|
|
// Add a submenu
|
|
|
|
LoadSubMenu(pnsMenu, menuitemElement, menuitemNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> oldmenuitemNode(menuitemNode);
|
|
|
|
oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode));
|
|
|
|
} // end menu item innner loop
|
1999-04-27 09:09:44 +00:00
|
|
|
|
|
|
|
// The parent owns us, so we can release
|
|
|
|
NS_RELEASE(pnsMenu);
|
1999-02-23 07:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-19 08:23:18 +00:00
|
|
|
//----------------------------------------
|
|
|
|
void nsWebShellWindow::DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow)
|
|
|
|
{
|
1999-07-07 22:33:26 +00:00
|
|
|
nsRect oldRect;
|
|
|
|
mWindow->GetClientBounds(oldRect);
|
|
|
|
|
1999-04-19 08:23:18 +00:00
|
|
|
// locate the window element which holds toolbars and menus and commands
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aDOMDoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> window(do_QueryInterface(element));
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
int endCount = 0;
|
|
|
|
nsCOMPtr<nsIDOMNode> menubarNode(FindNamedDOMNode(nsAutoString("menubar"), window, endCount, 1));
|
|
|
|
if (menubarNode) {
|
|
|
|
nsIMenuBar * pnsMenuBar = nsnull;
|
|
|
|
rv = nsComponentManager::CreateInstance(kMenuBarCID, nsnull, kIMenuBarIID, (void**)&pnsMenuBar);
|
|
|
|
if (NS_OK == rv) {
|
1999-04-27 09:09:44 +00:00
|
|
|
if (nsnull != pnsMenuBar) {
|
1999-04-19 08:23:18 +00:00
|
|
|
// set pnsMenuBar as a nsMenuListener on aParentWindow
|
|
|
|
nsCOMPtr<nsIMenuListener> menuListener;
|
|
|
|
pnsMenuBar->QueryInterface(kIMenuListenerIID, getter_AddRefs(menuListener));
|
|
|
|
|
|
|
|
//fake event
|
|
|
|
nsMenuEvent fake;
|
|
|
|
menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mWebShell);
|
1999-05-03 19:04:16 +00:00
|
|
|
|
1999-08-09 19:14:38 +00:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#else
|
1999-07-07 22:33:26 +00:00
|
|
|
// Resize around the menu.
|
1999-05-29 19:36:55 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
1999-05-03 19:04:16 +00:00
|
|
|
|
1999-07-07 22:33:26 +00:00
|
|
|
// do a resize
|
1999-05-03 19:04:16 +00:00
|
|
|
nsCOMPtr<nsIContentViewerContainer> contentViewerContainer;
|
|
|
|
contentViewerContainer = do_QueryInterface(mWebShell);
|
|
|
|
if (!contentViewerContainer) {
|
|
|
|
NS_ERROR("Webshell doesn't support the content viewer container interface");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) {
|
|
|
|
NS_ERROR("Unable to retrieve content viewer.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer;
|
|
|
|
docViewer = do_QueryInterface(contentViewer);
|
|
|
|
if (!docViewer) {
|
|
|
|
NS_ERROR("Document viewer interface not supported by the content viewer.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the doc viewer's presentation context.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (NS_FAILED(rv = presContext->GetShell(getter_AddRefs(presShell)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the shell from the presentation context.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = mWindow->GetClientBounds(rect))) {
|
|
|
|
NS_ERROR("Failed to get web shells bounds");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-07 22:33:26 +00:00
|
|
|
// Resize the browser window by the difference.
|
|
|
|
PRInt32 heightDelta = oldRect.height - rect.height;
|
|
|
|
nsRect currentBounds;
|
|
|
|
GetWindowBounds(currentBounds);
|
|
|
|
SizeWindowTo(currentBounds.width, currentBounds.height + heightDelta);
|
1999-05-03 19:04:16 +00:00
|
|
|
// END REFLOW CODE
|
1999-08-09 19:14:38 +00:00
|
|
|
#endif
|
1999-04-19 08:23:18 +00:00
|
|
|
|
|
|
|
} // end if ( nsnull != pnsMenuBar )
|
|
|
|
}
|
|
|
|
} // end if (menuBar)
|
1999-07-07 00:48:06 +00:00
|
|
|
} // nsWebShellWindow::DynamicLoadMenus
|
1999-04-19 08:23:18 +00:00
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
//----------------------------------------
|
1999-01-27 10:51:28 +00:00
|
|
|
void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow)
|
|
|
|
{
|
1999-01-28 00:21:12 +00:00
|
|
|
// locate the window element which holds toolbars and menus and commands
|
1999-02-12 15:56:54 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aDOMDoc->GetDocumentElement(getter_AddRefs(element));
|
1999-02-21 21:04:21 +00:00
|
|
|
if (!element) {
|
1999-01-28 00:21:12 +00:00
|
|
|
return;
|
1999-02-21 21:04:21 +00:00
|
|
|
}
|
1999-02-17 02:08:00 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> window(do_QueryInterface(element));
|
1999-01-28 00:21:12 +00:00
|
|
|
|
1999-01-27 10:51:28 +00:00
|
|
|
nsresult rv;
|
1999-01-28 01:30:38 +00:00
|
|
|
int endCount = 0;
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> menubarNode(FindNamedDOMNode(nsAutoString("menubar"), window, endCount, 1));
|
1999-01-28 02:26:27 +00:00
|
|
|
if (menubarNode) {
|
1999-01-27 10:51:28 +00:00
|
|
|
nsIMenuBar * pnsMenuBar = nsnull;
|
1999-03-09 09:44:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kMenuBarCID, nsnull, kIMenuBarIID, (void**)&pnsMenuBar);
|
1999-02-21 21:04:21 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
if (nsnull != pnsMenuBar) {
|
|
|
|
pnsMenuBar->Create(aParentWindow);
|
1999-02-04 02:42:07 +00:00
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
// set pnsMenuBar as a nsMenuListener on aParentWindow
|
|
|
|
nsCOMPtr<nsIMenuListener> menuListener;
|
|
|
|
pnsMenuBar->QueryInterface(kIMenuListenerIID, getter_AddRefs(menuListener));
|
1999-02-28 11:14:34 +00:00
|
|
|
aParentWindow->AddMenuListener(menuListener);
|
1999-02-21 21:04:21 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> menuNode;
|
|
|
|
menubarNode->GetFirstChild(getter_AddRefs(menuNode));
|
|
|
|
while (menuNode) {
|
|
|
|
nsCOMPtr<nsIDOMElement> menuElement(do_QueryInterface(menuNode));
|
|
|
|
if (menuElement) {
|
|
|
|
nsString menuNodeType;
|
|
|
|
nsString menuName;
|
|
|
|
menuElement->GetNodeName(menuNodeType);
|
|
|
|
if (menuNodeType.Equals("menu")) {
|
1999-07-31 07:15:20 +00:00
|
|
|
menuElement->GetAttribute(nsAutoString("value"), menuName);
|
1999-03-26 11:34:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_rods
|
1999-02-21 21:04:21 +00:00
|
|
|
printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks
|
1999-03-26 11:34:21 +00:00
|
|
|
#endif
|
1999-02-21 21:04:21 +00:00
|
|
|
CreateMenu(pnsMenuBar, menuNode, menuName);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> oldmenuNode(menuNode);
|
|
|
|
oldmenuNode->GetNextSibling(getter_AddRefs(menuNode));
|
|
|
|
} // end while (nsnull != menuNode)
|
1999-01-30 00:39:25 +00:00
|
|
|
|
1999-04-27 09:09:44 +00:00
|
|
|
// Give the aParentWindow this nsMenuBar to own.
|
1999-02-28 11:14:34 +00:00
|
|
|
aParentWindow->SetMenuBar(pnsMenuBar);
|
1999-02-04 02:42:07 +00:00
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
// HACK: force a paint for now
|
|
|
|
pnsMenuBar->Paint();
|
1999-04-08 04:29:37 +00:00
|
|
|
|
|
|
|
// HACK for M4, should be removed by M5
|
1999-07-31 07:15:20 +00:00
|
|
|
#ifdef XP_MAC
|
1999-04-08 04:29:37 +00:00
|
|
|
Handle tempMenuBar = ::GetMenuBar(); // Get a copy of the menu list
|
|
|
|
pnsMenuBar->SetNativeData((void*)tempMenuBar);
|
1999-07-31 07:15:20 +00:00
|
|
|
#endif
|
1999-04-27 09:09:44 +00:00
|
|
|
|
|
|
|
// The parent owns the menubar, so we can release it
|
|
|
|
NS_RELEASE(pnsMenuBar);
|
1999-01-27 10:51:28 +00:00
|
|
|
} // end if ( nsnull != pnsMenuBar )
|
1999-02-21 21:04:21 +00:00
|
|
|
}
|
|
|
|
} // end if (menuBar)
|
1999-01-27 10:51:28 +00:00
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
} // nsWebShellWindow::LoadMenus
|
|
|
|
|
1999-05-14 22:28:00 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void nsWebShellWindow::DoContextMenu(
|
|
|
|
nsMenuEvent * aMenuEvent,
|
|
|
|
nsIDOMNode * aMenuNode,
|
|
|
|
nsIWidget * aParentWindow,
|
|
|
|
PRInt32 aX,
|
1999-06-09 09:24:10 +00:00
|
|
|
PRInt32 aY,
|
1999-06-09 10:13:46 +00:00
|
|
|
const nsString& aPopupAlignment,
|
|
|
|
const nsString& aAnchorAlignment)
|
1999-05-14 22:28:00 +00:00
|
|
|
{
|
|
|
|
if (aMenuNode) {
|
|
|
|
nsIContextMenu * pnsContextMenu;
|
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kContextMenuCID, nsnull, kIContextMenuIID, (void**)&pnsContextMenu);
|
|
|
|
if (NS_SUCCEEDED(rv) && pnsContextMenu) {
|
|
|
|
nsISupports * supports;
|
|
|
|
aParentWindow->QueryInterface(kISupportsIID, (void**) &supports);
|
1999-06-09 10:13:46 +00:00
|
|
|
pnsContextMenu->Create(supports, aPopupAlignment, aAnchorAlignment);
|
1999-05-14 22:28:00 +00:00
|
|
|
NS_RELEASE(supports);
|
|
|
|
pnsContextMenu->SetLocation(aX,aY);
|
|
|
|
// Set webshell
|
1999-05-14 23:10:46 +00:00
|
|
|
pnsContextMenu->SetWebShell( mWebShell );
|
|
|
|
|
1999-05-14 22:28:00 +00:00
|
|
|
// Set DOM node
|
|
|
|
pnsContextMenu->SetDOMNode( aMenuNode );
|
|
|
|
|
|
|
|
// Construct and show menu
|
|
|
|
nsIMenuListener * listener;
|
|
|
|
pnsContextMenu->QueryInterface(kIMenuListenerIID, (void**) &listener);
|
|
|
|
|
|
|
|
// Dynamically construct and track the menu
|
|
|
|
listener->MenuSelected(*aMenuEvent);
|
|
|
|
|
|
|
|
// Destroy the menu
|
|
|
|
listener->MenuDeselected(*aMenuEvent);
|
|
|
|
|
|
|
|
// The parent owns the context menu, so we can release it
|
|
|
|
NS_RELEASE(listener);
|
1999-05-15 02:53:43 +00:00
|
|
|
NS_RELEASE(pnsContextMenu);
|
1999-05-14 22:28:00 +00:00
|
|
|
}
|
|
|
|
} // end if (aMenuNode)
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
1999-05-04 23:36:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::GetContentShellById(const nsString& aID, nsIWebShell** aChildShell)
|
|
|
|
{
|
|
|
|
// Set to null just to be certain
|
|
|
|
*aChildShell = nsnull;
|
|
|
|
|
|
|
|
// If we don't have a content array, we just don't care.
|
|
|
|
if (mContentShells == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Find out if the id in question is one that we have web shell info for.
|
|
|
|
PRInt32 count = mContentShells->Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
nsWebShellInfo* webInfo = (nsWebShellInfo*)(mContentShells->ElementAt(i));
|
|
|
|
if (webInfo->id == aID)
|
|
|
|
{
|
|
|
|
// We have a match!
|
|
|
|
*aChildShell = webInfo->child;
|
|
|
|
NS_ADDREF(*aChildShell);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-04-20 22:35:11 +00:00
|
|
|
|
1999-05-14 22:28:00 +00:00
|
|
|
//------------------------------------------------------------------------------
|
1999-04-20 22:35:11 +00:00
|
|
|
NS_IMETHODIMP
|
1999-05-04 23:36:42 +00:00
|
|
|
nsWebShellWindow::AddWebShellInfo(const nsString& aID,
|
1999-06-26 21:48:29 +00:00
|
|
|
PRBool aPrimary,
|
1999-04-20 22:35:11 +00:00
|
|
|
nsIWebShell* aChildShell)
|
|
|
|
{
|
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
nsWebShellInfo* webShellInfo = new nsWebShellInfo(aID, aPrimary,
|
1999-05-04 23:36:42 +00:00
|
|
|
aChildShell);
|
1999-04-20 22:35:11 +00:00
|
|
|
|
|
|
|
if (mContentShells == nsnull)
|
|
|
|
mContentShells = new nsVoidArray();
|
|
|
|
|
|
|
|
mContentShells->AppendElement((void*)webShellInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindow** aDOMWindow)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScriptContextOwner> newContextOwner;
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> newGlobalObject;
|
|
|
|
nsCOMPtr<nsIDOMWindow> newDOMWindow;
|
|
|
|
|
|
|
|
newContextOwner = do_QueryInterface(aShell);
|
|
|
|
if (newContextOwner)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(rv = newContextOwner->GetScriptGlobalObject(getter_AddRefs(newGlobalObject)))) {
|
|
|
|
NS_ERROR("Unable to retrieve global object.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newGlobalObject) {
|
|
|
|
newDOMWindow = do_QueryInterface(newGlobalObject);
|
|
|
|
*aDOMWindow = newDOMWindow.get();
|
|
|
|
NS_ADDREF(*aDOMWindow);
|
|
|
|
}
|
|
|
|
else return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-14 22:41:09 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-19 22:11:12 +00:00
|
|
|
nsWebShellWindow::GetPresShell(nsIPresShell** aPresShell)
|
1999-05-14 22:41:09 +00:00
|
|
|
{
|
1999-05-14 23:11:49 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-06-08 05:20:04 +00:00
|
|
|
nsCOMPtr<nsIContentViewerContainer> contentViewerContainer;
|
|
|
|
contentViewerContainer = do_QueryInterface(mWebShell);
|
|
|
|
if (!contentViewerContainer) {
|
|
|
|
NS_ERROR("Webshell doesn't support the content viewer container interface");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) {
|
|
|
|
NS_ERROR("Unable to retrieve content viewer.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer;
|
|
|
|
docViewer = do_QueryInterface(contentViewer);
|
|
|
|
if (!docViewer) {
|
|
|
|
NS_ERROR("Document viewer interface not supported by the content viewer.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the doc viewer's presentation context.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-06-09 09:02:35 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (NS_FAILED(rv = presContext->GetShell(getter_AddRefs(presShell)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the pres shell.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-08-19 22:11:12 +00:00
|
|
|
*aPresShell = presShell.get();
|
|
|
|
NS_IF_ADDREF(*aPresShell);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupContent,
|
|
|
|
PRInt32 aXPos, PRInt32 aYPos,
|
|
|
|
const nsString& aPopupType, const nsString& anAnchorAlignment,
|
|
|
|
const nsString& aPopupAlignment,
|
|
|
|
nsIDOMWindow* aWindow, nsIDOMWindow** outPopup)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// First we need to obtain the popup set frame that encapsulates the target popup.
|
|
|
|
// Without a popup set, we're dead in the water.
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (NS_FAILED(GetPresShell(getter_AddRefs(presShell)))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the parent of the popup content.
|
|
|
|
nsCOMPtr<nsIDOMNode> popupSet;
|
|
|
|
aPopupContent->GetParentNode(getter_AddRefs(popupSet));
|
|
|
|
if (!popupSet)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Do a sanity check to ensure we have a popup set element.
|
|
|
|
nsString tagName;
|
|
|
|
nsCOMPtr<nsIDOMElement> popupSetElement = do_QueryInterface(popupSet);
|
|
|
|
popupSetElement->GetTagName(tagName);
|
1999-09-10 08:56:26 +00:00
|
|
|
if (tagName != "popupset")
|
1999-08-19 22:11:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Now obtain the popup set frame.
|
|
|
|
nsCOMPtr<nsIContent> popupSetContent = do_QueryInterface(popupSet);
|
|
|
|
nsIFrame* frame;
|
|
|
|
presShell->GetPrimaryFrameFor(popupSetContent, &frame);
|
|
|
|
if (!frame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Retrieve the frame that corresponds to the element that the popup
|
|
|
|
// is attached to.
|
|
|
|
nsIFrame* elementFrame;
|
|
|
|
nsCOMPtr<nsIContent> elementContent = do_QueryInterface(aElement);
|
|
|
|
presShell->GetPrimaryFrameFor(elementContent, &elementFrame);
|
|
|
|
if (!elementFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Pass this all off to the popup set frame.
|
|
|
|
nsCOMPtr<nsIPopupSetFrame> popupSetFrame = do_QueryInterface(frame);
|
|
|
|
nsCOMPtr<nsIContent> popupContent = do_QueryInterface(aPopupContent);
|
|
|
|
popupSetFrame->CreatePopup(elementFrame, popupContent, aXPos, aYPos,
|
|
|
|
aPopupType, anAnchorAlignment,
|
|
|
|
aPopupAlignment);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// clear out result param up front. It's an error if a legal place to
|
|
|
|
// stick the result isn't provided.
|
|
|
|
if ( !outPopup ) {
|
|
|
|
NS_ERROR ( "Invalid param -- need to provide a place for result" );
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
*outPopup = nsnull;
|
|
|
|
|
|
|
|
|
1999-06-09 09:02:35 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
|
|
|
if (anAnchorAlignment != "none") {
|
|
|
|
// We need to compute our screen coordinates.
|
|
|
|
nsIFrame* primaryFrame;
|
|
|
|
presShell->GetPrimaryFrameFor(content, &primaryFrame);
|
|
|
|
if (primaryFrame) {
|
|
|
|
// Get the coordinates within the view.
|
|
|
|
nsRect rect;
|
|
|
|
nsIView * view;
|
|
|
|
nsPoint pnt;
|
|
|
|
primaryFrame->GetOffsetFromView(pnt, &view);
|
|
|
|
primaryFrame->GetRect(rect);
|
|
|
|
rect.x = pnt.x;
|
|
|
|
rect.y = pnt.y;
|
|
|
|
|
|
|
|
float t2p;
|
|
|
|
presContext->GetTwipsToPixels(&t2p);
|
|
|
|
rect.x = NSToCoordRound((float)(rect.x)*t2p);
|
|
|
|
rect.y = NSToCoordRound((float)(rect.y)*t2p);
|
|
|
|
rect.width = NSToCoordRound((float)(rect.width)*t2p);
|
|
|
|
rect.height = NSToCoordRound((float)(rect.height)*t2p);
|
|
|
|
|
|
|
|
if (anAnchorAlignment == "topleft") {
|
|
|
|
aXPos = rect.x + aXPos;
|
|
|
|
aYPos = rect.y + aYPos;
|
|
|
|
}
|
|
|
|
else if (anAnchorAlignment == "topright") {
|
|
|
|
aXPos = rect.x + rect.width + aXPos;
|
|
|
|
aYPos = rect.y + aYPos;
|
|
|
|
}
|
|
|
|
else if (anAnchorAlignment == "bottomleft") {
|
|
|
|
aXPos = rect.x + aXPos;
|
1999-06-09 09:05:53 +00:00
|
|
|
aYPos = rect.y + rect.height + aYPos;
|
1999-06-09 09:02:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aXPos = rect.x + rect.width + aXPos;
|
|
|
|
aYPos = rect.y + rect.height + aYPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-18 08:04:37 +00:00
|
|
|
nsCOMPtr<nsIContent> popupContent = do_QueryInterface(aPopupContent);
|
1999-07-01 00:07:41 +00:00
|
|
|
if ( !popupContent )
|
|
|
|
return NS_OK; // It's ok. Really.
|
1999-06-08 05:20:04 +00:00
|
|
|
|
1999-07-26 09:19:45 +00:00
|
|
|
// Fire the create DOM event to give JS/C++ a chance to build the popup
|
1999-07-06 23:21:23 +00:00
|
|
|
// dynamically. After we fire off the event, make sure we check the result
|
|
|
|
// for |nsEventStatus_eConsumeNoDefault| which translates into an event
|
|
|
|
// handler returning false. If that happens, abort creating the popup.
|
1999-06-08 05:20:04 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
1999-07-26 09:19:45 +00:00
|
|
|
event.message = NS_MENU_CREATE;
|
1999-06-08 05:20:04 +00:00
|
|
|
rv = popupContent->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1999-07-06 23:21:23 +00:00
|
|
|
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
|
1999-06-08 05:20:04 +00:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Find out if we're a menu.
|
1999-05-18 08:04:37 +00:00
|
|
|
PRInt32 childCount;
|
|
|
|
popupContent->ChildCount(childCount);
|
|
|
|
if (childCount == 0)
|
|
|
|
return NS_OK;
|
1999-05-14 23:11:49 +00:00
|
|
|
|
1999-05-18 08:04:37 +00:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
if (NS_FAILED(popupContent->ChildAt(0, *getter_AddRefs(rootContent))))
|
|
|
|
return NS_OK; // Doesn't matter. Don't report it.
|
|
|
|
|
|
|
|
nsString tagName;
|
1999-07-01 00:07:41 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(rootContent);
|
|
|
|
if ( !rootElement || NS_FAILED(rootElement->GetTagName(tagName)))
|
1999-05-18 08:04:37 +00:00
|
|
|
return NS_OK; // It's ok. Really.
|
|
|
|
|
|
|
|
if (tagName == "menu") {
|
|
|
|
|
|
|
|
// XXX Need to distinguish between popup menus and context menus?
|
1999-06-09 10:13:46 +00:00
|
|
|
DoContextMenu(nsnull, rootElement, mWindow, aXPos, aYPos, aPopupAlignment, anAnchorAlignment);
|
1999-05-18 08:04:37 +00:00
|
|
|
|
1999-07-26 09:19:45 +00:00
|
|
|
// Fire the destroy DOM event to give JS/C++ a chance to destroy the popup contents
|
1999-08-07 02:51:03 +00:00
|
|
|
status = nsEventStatus_eIgnore;
|
1999-06-08 05:20:04 +00:00
|
|
|
event.eventStructType = NS_EVENT;
|
1999-07-26 09:19:45 +00:00
|
|
|
event.message = NS_MENU_DESTROY;
|
1999-06-08 05:20:04 +00:00
|
|
|
rv = popupContent->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
return rv;
|
1999-05-14 23:11:49 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 08:04:37 +00:00
|
|
|
if (tagName != "window")
|
|
|
|
return NS_OK; // I promise. It really is ok. Stop whining.
|
|
|
|
|
1999-05-16 05:51:35 +00:00
|
|
|
// Handle the arbitrary popup XUL case.
|
|
|
|
|
|
|
|
// (1) Create a top-level chromeless window. The size of the window can be specified
|
|
|
|
// on the window tag contained inside. Retrieve the webshell from the new nsWebShellWindow.
|
1999-05-16 07:52:02 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebShellWindow> newWindow;
|
1999-07-01 02:50:53 +00:00
|
|
|
|
|
|
|
nsWebShellWindow* window = new nsWebShellWindow();
|
|
|
|
if (nsnull == window) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsWidgetInitData widgetInitData;
|
1999-07-27 04:27:17 +00:00
|
|
|
widgetInitData.mWindowType = eWindowType_popup;
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_default;
|
1999-07-01 02:50:53 +00:00
|
|
|
|
1999-07-05 23:45:24 +00:00
|
|
|
window->SetIntrinsicallySized(PR_TRUE);
|
1999-07-01 02:50:53 +00:00
|
|
|
rv = window->Initialize((nsIWebShellWindow *) nsnull, nsnull, nsnull,
|
1999-08-16 22:23:19 +00:00
|
|
|
PR_TRUE, PR_TRUE, nsnull, nsnull,
|
1999-07-05 23:45:24 +00:00
|
|
|
1, 1, widgetInitData);
|
1999-07-20 14:40:55 +00:00
|
|
|
|
1999-07-01 02:50:53 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
newWindow = window;
|
|
|
|
|
1999-05-16 07:52:02 +00:00
|
|
|
// Move the window to aXPos and aYPos
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browserWindow = do_QueryInterface(newWindow);
|
|
|
|
browserWindow->MoveTo(aXPos, aYPos);
|
|
|
|
|
1999-05-18 10:29:48 +00:00
|
|
|
// (2) Get the webshell
|
1999-05-16 07:52:02 +00:00
|
|
|
nsCOMPtr<nsIWebShell> newShell;
|
|
|
|
newWindow->GetWebShell(*getter_AddRefs(newShell));
|
1999-05-16 05:51:35 +00:00
|
|
|
|
1999-05-16 07:52:02 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(newShell, getter_AddRefs(domWindow)))) {
|
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-18 10:29:48 +00:00
|
|
|
|
1999-05-16 05:51:35 +00:00
|
|
|
// (3) We need to create a new document that clones the original document's popup
|
|
|
|
// content. This new document must use the different root and a different global script
|
|
|
|
// context (window object) but everything else about it is the same (namespaces, URLs,
|
|
|
|
// stylesheets).
|
1999-05-16 08:10:27 +00:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
content->GetDocument(*getter_AddRefs(document));
|
|
|
|
if (document == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIXULParentDocument> parentDocument = do_QueryInterface(document);
|
|
|
|
if (parentDocument == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> popupDocument;
|
1999-05-18 09:03:26 +00:00
|
|
|
if (NS_FAILED(rv = parentDocument->CreatePopupDocument(rootContent, getter_AddRefs(popupDocument)))) {
|
1999-05-16 08:10:27 +00:00
|
|
|
NS_ERROR("Unable to create the child popup document.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-16 05:51:35 +00:00
|
|
|
|
|
|
|
// The tricky part now 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
|
|
|
|
// (4) Create a document viewer
|
1999-05-16 10:02:19 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> documentViewer;
|
1999-05-18 08:04:37 +00:00
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docFactory;
|
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull,
|
|
|
|
kIDocumentLoaderFactoryIID,
|
|
|
|
(void**)getter_AddRefs(docFactory)))) {
|
|
|
|
NS_ERROR("Unable to instantiate layout's doc loader factory.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-16 10:02:19 +00:00
|
|
|
nsCOMPtr<nsIContentViewerContainer> cvContainer = do_QueryInterface(newShell);
|
1999-05-18 09:03:26 +00:00
|
|
|
if (NS_FAILED(rv = docFactory->CreateInstanceForDocument(cvContainer,
|
1999-05-18 08:04:37 +00:00
|
|
|
popupDocument,
|
|
|
|
"view",
|
1999-05-18 09:03:26 +00:00
|
|
|
getter_AddRefs(documentViewer)))) {
|
|
|
|
NS_ERROR("I couldn't get a document viewer for the popup document.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (5) Feed the webshell to the content viewer
|
|
|
|
documentViewer->SetContainer(cvContainer);
|
1999-05-18 08:04:37 +00:00
|
|
|
|
|
|
|
// (6) Tell the content viewer container to embed the content viewer.
|
1999-05-16 05:51:35 +00:00
|
|
|
// (This step causes everything to be set up for an initial flow.)
|
1999-05-18 09:03:26 +00:00
|
|
|
if (NS_FAILED(rv = cvContainer->Embed(documentViewer, "view", nsnull))) {
|
|
|
|
NS_ERROR("Unable to embed the viewer in the container.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-16 05:51:35 +00:00
|
|
|
|
1999-05-18 08:04:37 +00:00
|
|
|
// (7) Hook up a blur handler to the window that will cause it to close.
|
1999-05-18 09:03:26 +00:00
|
|
|
nsCOMPtr<nsIXULPopupListener> popupListener;
|
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kXULPopupListenerCID,
|
|
|
|
nsnull,
|
|
|
|
kIXULPopupListenerIID,
|
|
|
|
(void**) getter_AddRefs(popupListener)))) {
|
|
|
|
NS_ERROR("Unable to create an instance of the popup listener object.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsIContent* popupRoot = popupDocument->GetRootContent();
|
|
|
|
nsCOMPtr<nsIDOMElement> popupRootElement = do_QueryInterface(popupRoot);
|
|
|
|
if (NS_FAILED(rv = popupListener->Init(popupRootElement, eXULPopupType_blur))) {
|
|
|
|
NS_ERROR("Unable to initialize our blur listener.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(popupRoot);
|
|
|
|
nsCOMPtr<nsIDOMFocusListener> blurListener = do_QueryInterface(popupListener);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> targetWindow = do_QueryInterface(domWindow);
|
1999-07-19 19:54:34 +00:00
|
|
|
targetWindow->AddEventListener("blur", blurListener, PR_FALSE);
|
1999-05-18 10:29:48 +00:00
|
|
|
|
|
|
|
// (8) Set up the opener property
|
|
|
|
domWindow->SetOpener(aWindow);
|
|
|
|
|
1999-07-01 00:07:41 +00:00
|
|
|
// (9) Show the window. Don't give the focus yet because we may not want to.
|
|
|
|
// For example, popup windows want focus, but tooltips do not.
|
1999-05-18 09:03:26 +00:00
|
|
|
newWindow->Show(PR_TRUE);
|
1999-05-16 05:51:35 +00:00
|
|
|
|
1999-05-18 10:29:48 +00:00
|
|
|
// (10) Do some layout.
|
1999-05-18 09:03:26 +00:00
|
|
|
nsCOMPtr<nsIXULChildDocument> popupChild = do_QueryInterface(popupDocument);
|
|
|
|
popupChild->LayoutPopupDocument();
|
1999-05-16 05:51:35 +00:00
|
|
|
|
1999-07-01 00:07:41 +00:00
|
|
|
// return the popup.
|
|
|
|
*outPopup = domWindow;
|
|
|
|
NS_ADDREF(*outPopup);
|
1999-08-19 22:11:12 +00:00
|
|
|
*/
|
|
|
|
|
1999-05-14 23:11:49 +00:00
|
|
|
return rv;
|
1999-05-14 22:41:09 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 01:51:37 +00:00
|
|
|
NS_IMETHODIMP
|
1999-05-04 23:36:42 +00:00
|
|
|
nsWebShellWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
|
1999-04-20 01:51:37 +00:00
|
|
|
{
|
1999-05-04 23:36:42 +00:00
|
|
|
// Find out the id of the frameNode in question
|
1999-06-26 21:48:29 +00:00
|
|
|
nsIAtom *idAtom = NS_NewAtom("id");
|
|
|
|
nsIAtom *typeAtom = NS_NewAtom("type");
|
|
|
|
PRBool isPrimary;
|
1999-05-04 23:36:42 +00:00
|
|
|
nsAutoString value;
|
1999-06-26 21:48:29 +00:00
|
|
|
|
|
|
|
// right now, any webshell with type "content" or "content-XXX" is
|
|
|
|
// considered a content webshell. but only "content-primary" is
|
|
|
|
// considered primary.
|
|
|
|
frameNode->GetAttribute(kNameSpaceID_None, typeAtom, value);
|
|
|
|
isPrimary = value.EqualsIgnoreCase(kPrimaryContentTypeValue) ? PR_TRUE : PR_FALSE;
|
|
|
|
frameNode->GetAttribute(kNameSpaceID_None, idAtom, value);
|
|
|
|
|
|
|
|
AddWebShellInfo(value, isPrimary, aChildShell);
|
|
|
|
|
1999-07-04 23:41:32 +00:00
|
|
|
// For some reason nsCOMPtr and do_queryInterface fail here
|
|
|
|
if (aChildShell) {
|
|
|
|
nsIUrlDispatcher * ud = nsnull;
|
|
|
|
QueryInterface(kIUrlDispatcherIID, (void **)&ud);
|
|
|
|
aChildShell->SetUrlDispatcher(ud);
|
|
|
|
NS_RELEASE(ud);
|
|
|
|
}
|
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
NS_RELEASE(typeAtom);
|
1999-04-20 22:35:11 +00:00
|
|
|
NS_RELEASE(idAtom);
|
1999-04-20 01:51:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-21 07:24:01 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
|
|
|
|
nsIWebShell *&aNewWebShell)
|
1999-04-19 21:09:07 +00:00
|
|
|
{
|
1999-05-12 23:17:40 +00:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebShellWindow> newWindow;
|
|
|
|
|
1999-07-05 19:38:43 +00:00
|
|
|
// XXX Check modal chrome flag to run a modal dialog!
|
|
|
|
|
1999-05-12 23:17:40 +00:00
|
|
|
if ((aChromeMask & NS_CHROME_OPEN_AS_CHROME) != 0) {
|
|
|
|
// Just do a nice normal create of a web shell and
|
1999-07-05 19:38:43 +00:00
|
|
|
// return it immediately.
|
1999-08-12 22:08:17 +00:00
|
|
|
|
|
|
|
nsIWebShellWindow *parent = aChromeMask & NS_CHROME_DEPENDENT ? this : nsnull;
|
1999-08-16 22:23:19 +00:00
|
|
|
rv = appShell->CreateTopLevelWindow(parent, nsnull, PR_FALSE, PR_FALSE,
|
|
|
|
aChromeMask, nsnull,
|
|
|
|
NS_SIZETOCONTENT, NS_SIZETOCONTENT,
|
1999-07-27 06:34:25 +00:00
|
|
|
getter_AddRefs(newWindow));
|
1999-05-19 04:11:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser(do_QueryInterface(newWindow));
|
|
|
|
if (browser)
|
|
|
|
browser->SetChrome(aChromeMask);
|
|
|
|
newWindow->GetWebShell(aNewWebShell); // GetWebShell does the addref.
|
|
|
|
}
|
|
|
|
return rv;
|
1999-05-12 23:17:40 +00:00
|
|
|
}
|
|
|
|
|
1999-05-10 18:31:42 +00:00
|
|
|
// We need to create a new top level window and then enter a nested
|
|
|
|
// loop. Eventually the new window will be told that it has loaded,
|
|
|
|
// at which time we know it is safe to spin out of the nested loop
|
|
|
|
// and allow the opening code to proceed.
|
|
|
|
|
|
|
|
// First push a nested event queue for event processing from netlib
|
|
|
|
// onto our UI thread queue stack.
|
1999-08-04 23:26:21 +00:00
|
|
|
appShell->PushThreadEventQueue();
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsCOMPtr<nsIURI> urlObj;
|
1999-06-18 17:34:08 +00:00
|
|
|
char * urlStr = "chrome://navigator/content/";
|
|
|
|
#ifndef NECKO
|
|
|
|
rv = NS_NewURL(getter_AddRefs(urlObj), urlStr);
|
|
|
|
#else
|
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsIURI *uri = nsnull;
|
|
|
|
rv = service->NewURI(urlStr, nsnull, &uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
rv = uri->QueryInterface(nsIURI::GetIID(), (void**)&urlObj);
|
1999-06-18 17:34:08 +00:00
|
|
|
NS_RELEASE(uri);
|
|
|
|
#endif // NECKO
|
1999-04-16 18:40:27 +00:00
|
|
|
|
1999-07-05 19:38:43 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-08-16 22:23:19 +00:00
|
|
|
rv = appShell->CreateTopLevelWindow(nsnull, urlObj, PR_FALSE, PR_FALSE,
|
|
|
|
aChromeMask, nsnull, 615, 480,
|
1999-07-27 06:34:25 +00:00
|
|
|
getter_AddRefs(newWindow));
|
1999-07-05 19:38:43 +00:00
|
|
|
}
|
1999-04-16 18:40:27 +00:00
|
|
|
|
1999-05-10 18:31:42 +00:00
|
|
|
nsIAppShell *subshell;
|
1999-05-19 04:11:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser(do_QueryInterface(newWindow));
|
|
|
|
if (browser)
|
|
|
|
browser->SetChrome(aChromeMask);
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
// Spin into the modal loop.
|
|
|
|
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, (void**)&subshell);
|
|
|
|
}
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
subshell->Create(0, nsnull);
|
|
|
|
subshell->Spinup(); // Spin up
|
|
|
|
|
|
|
|
// Specify that we want the window to remain locked until the chrome has loaded.
|
|
|
|
newWindow->LockUntilChromeLoad();
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
PRBool locked = PR_FALSE;
|
|
|
|
nsresult looprv = NS_OK;
|
1999-05-10 18:31:42 +00:00
|
|
|
newWindow->GetLockedState(locked);
|
1999-05-19 04:11:54 +00:00
|
|
|
while (NS_SUCCEEDED(looprv) && locked) {
|
|
|
|
void *data;
|
|
|
|
PRBool isRealEvent;
|
|
|
|
|
|
|
|
looprv = subshell->GetNativeEvent(isRealEvent, data);
|
|
|
|
subshell->DispatchNativeEvent(isRealEvent, data);
|
|
|
|
|
|
|
|
newWindow->GetLockedState(locked);
|
|
|
|
}
|
1999-04-19 22:05:49 +00:00
|
|
|
|
1999-08-04 23:26:21 +00:00
|
|
|
// Get rid of the nested UI thread queue used for netlib
|
|
|
|
appShell->PopThreadEventQueue();
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
subshell->Spindown();
|
|
|
|
NS_RELEASE(subshell);
|
|
|
|
}
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-05-10 18:31:42 +00:00
|
|
|
// We're out of the nested loop.
|
1999-05-04 23:36:42 +00:00
|
|
|
// During the layout of the new window, all content shells were located and placed
|
1999-05-10 18:31:42 +00:00
|
|
|
// into the new window's content shell array. Locate the "content area" content
|
|
|
|
// shell.
|
1999-05-19 04:11:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = newWindow->GetContentShellById("content", &aNewWebShell);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Unable to obtain a browser content shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-10 18:31:42 +00:00
|
|
|
}
|
1999-04-19 22:05:49 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
return rv;
|
1999-01-21 07:24:01 +00:00
|
|
|
}
|
|
|
|
|
1999-08-08 01:20:28 +00:00
|
|
|
|
1999-08-05 23:59:00 +00:00
|
|
|
/**
|
|
|
|
* FindWebShellWithName - recursively search for any open window
|
|
|
|
* containing a webshell with the given name.
|
|
|
|
* @param aName - the name of the webshell to find. I believe this cannot
|
|
|
|
* be null. Hard to tell. If zero-length, the find will
|
|
|
|
* always fail (returning NS_OK).
|
|
|
|
* @param aResult - the webshell, returned, addrefed. null on failure to
|
|
|
|
* locate the desired webshell.
|
|
|
|
* @return an error indication. Can be NS_OK even if no match was found.
|
|
|
|
*/
|
1999-01-21 07:24:01 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::FindWebShellWithName(const PRUnichar* aName,
|
|
|
|
nsIWebShell*& aResult)
|
|
|
|
{
|
1999-04-08 06:58:13 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-06-22 01:38:28 +00:00
|
|
|
nsString nameStr(aName);
|
1999-04-08 06:58:13 +00:00
|
|
|
|
|
|
|
// Zero result (in case we fail).
|
1999-01-21 07:24:01 +00:00
|
|
|
aResult = nsnull;
|
1999-04-08 06:58:13 +00:00
|
|
|
|
1999-08-05 23:59:00 +00:00
|
|
|
// first, special cases
|
|
|
|
if (nameStr.Length() == 0)
|
|
|
|
return NS_OK;
|
1999-09-15 00:40:06 +00:00
|
|
|
if (nameStr.EqualsIgnoreCase("_blank"))
|
|
|
|
return NS_OK;
|
1999-08-05 23:59:00 +00:00
|
|
|
if (nameStr.EqualsIgnoreCase("_content"))
|
|
|
|
return GetContentWebShell(&aResult);
|
|
|
|
|
1999-06-22 01:38:28 +00:00
|
|
|
// look for open windows with the given name
|
1999-06-27 00:35:21 +00:00
|
|
|
/* Note: this function arguably works as expected, but the end effect
|
|
|
|
is wrong. The webshell that catches the name given from a JavaScript
|
|
|
|
window.open call is the content, not the chrome, so a window whose
|
|
|
|
location is redirected will have its content replaced, not its chrome.
|
|
|
|
That may be the right choice; maybe not. Also, there's a visual problem
|
|
|
|
where the window position is reset.
|
1999-06-22 01:38:28 +00:00
|
|
|
So when two or three bad things get cleared up, this next bit will be
|
|
|
|
helpful. As it is, it's not too. */
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)))) {
|
|
|
|
PRBool more;
|
|
|
|
|
|
|
|
// get the (main) webshell for each window in the enumerator
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (NS_SUCCEEDED(rv) && protoWindow) {
|
1999-08-05 01:50:25 +00:00
|
|
|
// it's supposed to be an nsIDOMWindow, so it's one of these, too
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> whatever(do_QueryInterface(protoWindow));
|
|
|
|
if (whatever) {
|
|
|
|
nsCOMPtr<nsIWebShell> webshell;
|
|
|
|
whatever->GetWebShell(getter_AddRefs(webshell));
|
|
|
|
if (webshell) {
|
1999-06-22 01:38:28 +00:00
|
|
|
// check the webshell, and then its children, for a name match
|
|
|
|
const PRUnichar *name;
|
|
|
|
if (NS_SUCCEEDED(webshell->GetName(&name)) && nameStr.Equals(name)) {
|
|
|
|
aResult = webshell;
|
|
|
|
NS_ADDREF(aResult);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Search for named frame within our root webshell. This will
|
|
|
|
// bypass the .xul document (and rightfully so). We need to be
|
|
|
|
// careful not to give that documents child frames names!
|
|
|
|
if (NS_SUCCEEDED(webshell->FindChildWithName(aName, aResult)) && aResult)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
1999-06-27 00:35:21 +00:00
|
|
|
// should be redundant, but left in for now
|
1999-06-22 01:38:28 +00:00
|
|
|
if (mWebShell)
|
|
|
|
rv = mWebShell->FindChildWithName(aName, aResult);
|
1999-04-08 06:58:13 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-01-21 07:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-04-12 21:25:08 +00:00
|
|
|
nsWebShellWindow::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken)
|
1999-01-21 07:24:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-10 16:32:55 +00:00
|
|
|
//----------------------------------------
|
|
|
|
// nsIWebShellWindow methods...
|
|
|
|
//----------------------------------------
|
1999-02-15 05:38:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::Show(PRBool aShow)
|
|
|
|
{
|
|
|
|
mWebShell->Show(); // crimminy -- it doesn't take a parameter!
|
|
|
|
mWindow->Show(aShow);
|
1999-06-22 03:04:11 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED(rv) )
|
|
|
|
{
|
|
|
|
windowMediator->UpdateWindowTimeStamp( this );
|
|
|
|
}
|
1999-02-15 05:38:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-20 04:13:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ShowModal()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = ShowModalInternal();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ShowModalInternal()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIAppShell *subshell;
|
|
|
|
|
|
|
|
// spin up a new application shell: event loops live there
|
|
|
|
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, (void**)&subshell);
|
1999-03-24 05:42:21 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-03-20 04:13:09 +00:00
|
|
|
|
1999-03-24 05:42:21 +00:00
|
|
|
subshell->Create(0, nsnull);
|
|
|
|
subshell->Spinup();
|
1999-03-20 04:13:09 +00:00
|
|
|
|
|
|
|
nsIWidget *window = GetWidget();
|
1999-06-13 20:56:08 +00:00
|
|
|
window->SetModal();
|
1999-03-24 05:42:21 +00:00
|
|
|
NS_ADDREF(window);
|
1999-03-20 04:13:09 +00:00
|
|
|
mContinueModalLoop = PR_TRUE;
|
|
|
|
while (NS_SUCCEEDED(rv) && mContinueModalLoop == PR_TRUE) {
|
|
|
|
void *data;
|
1999-03-24 05:42:21 +00:00
|
|
|
PRBool isRealEvent,
|
|
|
|
processEvent;
|
|
|
|
|
|
|
|
rv = subshell->GetNativeEvent(isRealEvent, data);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
subshell->EventIsForModalWindow(isRealEvent, data, window, &processEvent);
|
|
|
|
if (processEvent == PR_TRUE)
|
|
|
|
subshell->DispatchNativeEvent(isRealEvent, data);
|
|
|
|
}
|
1999-03-20 04:13:09 +00:00
|
|
|
}
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-03-24 05:42:21 +00:00
|
|
|
subshell->Spindown();
|
|
|
|
NS_RELEASE(window);
|
|
|
|
NS_RELEASE(subshell);
|
1999-03-20 04:13:09 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-12 22:08:17 +00:00
|
|
|
// yes, this one's name and ShowModal are a confusing pair. plan is to merge
|
|
|
|
// the two someday.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ShowModally(PRBool aPrepare)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (aPrepare && NS_FAILED(appShell->PushThreadEventQueue()))
|
|
|
|
aPrepare = PR_FALSE;
|
|
|
|
|
1999-08-13 23:00:58 +00:00
|
|
|
parentWidget = do_QueryReferent(mParentWindow);
|
1999-08-12 22:08:17 +00:00
|
|
|
if (parentWidget)
|
|
|
|
parentWidget->Enable(PR_FALSE);
|
|
|
|
rv = ShowModal();
|
|
|
|
if (parentWidget)
|
|
|
|
parentWidget->Enable(PR_TRUE);
|
|
|
|
|
|
|
|
if (aPrepare)
|
|
|
|
appShell->PopThreadEventQueue();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
/* return the main, outermost webshell in this window */
|
1999-02-10 16:32:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell)
|
|
|
|
{
|
|
|
|
aWebShell = mWebShell;
|
|
|
|
NS_ADDREF(mWebShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
/* return the webshell intended to hold (html) content. In a simple
|
|
|
|
browser window, that would be the main content area. If no such
|
|
|
|
webshell was found for any reason, the outermost webshell will be
|
|
|
|
returned. (Note that is the main chrome webshell, and probably
|
|
|
|
not what you wanted, but at least it's a webshell.)
|
|
|
|
Also note that if no content webshell was marked "primary,"
|
|
|
|
we return the chrome webshell, even if (non-primary) content webshells
|
|
|
|
do exist. Thas was done intentionally. The selection would be
|
|
|
|
nondeterministic, and it seems dangerous to set a precedent like that.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::GetContentWebShell(nsIWebShell **aResult)
|
|
|
|
{
|
|
|
|
nsIWebShell *content;
|
|
|
|
|
|
|
|
content = nsnull;
|
1999-07-22 22:48:23 +00:00
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
// first, try looking in the webshell list
|
|
|
|
// (note this list isn't dynamic: it's set up when the webshell is added,
|
|
|
|
// but not updated when its attributes are poked. could be a problem...)
|
|
|
|
if (mContentShells) {
|
|
|
|
PRInt32 count = mContentShells->Count();
|
|
|
|
for (PRInt32 ctr = 0; ctr < count; ctr++) {
|
|
|
|
nsWebShellInfo* webInfo = (nsWebShellInfo*)(mContentShells->ElementAt(ctr));
|
|
|
|
if (webInfo->primary) {
|
|
|
|
content = webInfo->child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-22 22:48:23 +00:00
|
|
|
NS_IF_ADDREF(content);
|
1999-06-26 21:48:29 +00:00
|
|
|
*aResult = content;
|
1999-07-22 22:48:23 +00:00
|
|
|
return NS_OK;
|
1999-06-26 21:48:29 +00:00
|
|
|
}
|
|
|
|
|
1999-02-10 16:32:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::GetWidget(nsIWidget *& aWidget)
|
|
|
|
{
|
|
|
|
aWidget = mWindow;
|
1999-09-17 19:56:53 +00:00
|
|
|
NS_IF_ADDREF(mWindow);
|
1999-02-10 16:32:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-26 15:58:58 +00:00
|
|
|
|
1999-03-20 04:13:09 +00:00
|
|
|
void *
|
|
|
|
nsWebShellWindow::HandleModalDialogEvent(PLEvent *aEvent)
|
|
|
|
{
|
|
|
|
ThreadedWindowEvent *event = (ThreadedWindowEvent *) aEvent;
|
|
|
|
|
|
|
|
event->window->ShowModalInternal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWebShellWindow::DestroyModalDialogEvent(PLEvent *aEvent)
|
|
|
|
{
|
|
|
|
PR_Free(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-06 21:01:51 +00:00
|
|
|
|
1999-01-26 15:58:58 +00:00
|
|
|
//----------------------------------------
|
|
|
|
// nsIDocumentLoaderObserver implementation
|
|
|
|
//----------------------------------------
|
1999-03-29 09:21:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL, const char* aCommand)
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
1999-08-05 01:28:30 +00:00
|
|
|
nsIChannel* channel, nsresult aStatus,
|
1999-06-28 10:35:57 +00:00
|
|
|
nsIDocumentLoaderObserver * aDocObserver)
|
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL, PRInt32 aStatus,
|
1999-06-28 10:35:57 +00:00
|
|
|
nsIDocumentLoaderObserver * aDocObserver)
|
|
|
|
#endif
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
1999-04-06 21:01:51 +00:00
|
|
|
#ifdef DEBUG_MENUSDEL
|
|
|
|
printf("OnEndDocumentLoad\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We get notified every time a page/Frame is loaded. But we need to
|
|
|
|
* Load the menus, run the startup script etc.. only once. So, Use
|
|
|
|
* the mChrome Initialized member to check whether chrome should be
|
|
|
|
* initialized or not - Radha
|
|
|
|
*/
|
1999-04-08 06:58:13 +00:00
|
|
|
if (mChromeInitialized)
|
1999-04-06 21:01:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mChromeInitialized = PR_TRUE;
|
|
|
|
|
1999-08-12 22:08:17 +00:00
|
|
|
mLockedUntilChromeLoad = PR_FALSE;
|
1999-05-04 23:36:42 +00:00
|
|
|
|
1999-07-31 21:08:10 +00:00
|
|
|
#ifdef XP_MAC // Anyone still using native menus should add themselves here.
|
1999-04-06 21:01:51 +00:00
|
|
|
// register as document listener
|
|
|
|
// this is needed for menus
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mWebShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
|
|
|
if (!docv)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
docv->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
doc->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
|
|
|
}
|
1999-07-31 21:08:10 +00:00
|
|
|
#endif
|
1999-04-06 21:01:51 +00:00
|
|
|
|
|
|
|
ExecuteStartupCode();
|
|
|
|
|
1999-07-31 21:08:10 +00:00
|
|
|
#ifdef XP_MAC // Anyone still using native menus should add themselves here.
|
1999-04-06 21:01:51 +00:00
|
|
|
///////////////////////////////
|
|
|
|
// Find the Menubar DOM and Load the menus, hooking them up to the loaded commands
|
|
|
|
///////////////////////////////
|
|
|
|
nsCOMPtr<nsIDOMDocument> menubarDOMDoc(GetNamedDOMDoc(nsAutoString("this"))); // XXX "this" is a small kludge for code reused
|
|
|
|
if (menubarDOMDoc)
|
1999-04-19 08:23:18 +00:00
|
|
|
{
|
1999-08-09 19:14:38 +00:00
|
|
|
#ifdef SOME_PLATFORM // Anyone using native non-dynamic menus should add themselves here.
|
1999-04-06 21:01:51 +00:00
|
|
|
LoadMenus(menubarDOMDoc, mWindow);
|
1999-05-14 22:28:00 +00:00
|
|
|
// Context Menu test
|
1999-05-19 04:11:54 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
menubarDOMDoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
nsCOMPtr<nsIDOMNode> window(do_QueryInterface(element));
|
1999-05-14 22:28:00 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
int endCount = 0;
|
|
|
|
contextMenuTest = FindNamedDOMNode(nsAutoString("contextmenu"), window, endCount, 1);
|
1999-05-14 22:28:00 +00:00
|
|
|
// End Context Menu test
|
1999-07-31 07:15:20 +00:00
|
|
|
#else
|
1999-07-23 02:37:14 +00:00
|
|
|
DynamicLoadMenus(menubarDOMDoc, mWindow);
|
1999-08-09 19:14:38 +00:00
|
|
|
#endif
|
1999-04-19 08:23:18 +00:00
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
#endif // XP_MAC
|
1999-04-06 21:01:51 +00:00
|
|
|
|
|
|
|
SetTitleFromXUL();
|
1999-05-19 04:11:54 +00:00
|
|
|
ShowAppropriateChrome();
|
1999-05-27 20:36:15 +00:00
|
|
|
LoadContentAreas();
|
1999-07-04 04:09:54 +00:00
|
|
|
|
1999-07-20 14:40:55 +00:00
|
|
|
// Here's where we service the "show" request initially given in Initialize()
|
|
|
|
if (mCreatedVisible)
|
|
|
|
Show(PR_TRUE);
|
1999-04-06 21:01:51 +00:00
|
|
|
|
1999-07-26 15:02:19 +00:00
|
|
|
nsCOMPtr<nsIWebShell> contentShell;
|
|
|
|
GetContentWebShell(getter_AddRefs(contentShell));
|
|
|
|
if (contentShell) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
if (NS_SUCCEEDED(ConvertWebShellToDOMWindow(contentShell,
|
|
|
|
getter_AddRefs(domWindow)))) {
|
|
|
|
domWindow->Focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-10 16:32:55 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::OnStartURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
|
|
|
nsIContentViewer* aViewer)
|
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnStartURLLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1999-04-28 06:47:40 +00:00
|
|
|
const char* aContentType,
|
|
|
|
nsIContentViewer* aViewer)
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-01-26 15:58:58 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-29 09:21:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::OnProgressURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
|
|
|
PRUint32 aProgress,
|
|
|
|
PRUint32 aProgressMax)
|
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnProgressURLLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1999-04-28 06:47:40 +00:00
|
|
|
PRUint32 aProgress,
|
1999-03-29 09:21:01 +00:00
|
|
|
PRUint32 aProgressMax)
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel, nsString& aMsg)
|
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnStatusURLLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL, nsString& aMsg)
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::OnEndURLLoad(nsIDocumentLoader* loader,
|
1999-08-05 01:28:30 +00:00
|
|
|
nsIChannel* channel, nsresult aStatus)
|
1999-06-28 10:35:57 +00:00
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::OnEndURLLoad(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL, PRInt32 aStatus)
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-03-29 09:21:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-08 04:21:15 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsWebShellWindow::HandleUnknownContentType(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel,
|
|
|
|
const char *aContentType,
|
|
|
|
const char *aCommand )
|
|
|
|
#else
|
1999-04-28 06:47:40 +00:00
|
|
|
nsWebShellWindow::HandleUnknownContentType(nsIDocumentLoader* loader,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1999-04-08 04:21:15 +00:00
|
|
|
const char *aContentType,
|
|
|
|
const char *aCommand )
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-04-08 04:21:15 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-26 15:58:58 +00:00
|
|
|
|
|
|
|
//----------------------------------------
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedDOMNode(const nsString &aName, nsIDOMNode * aParent, PRInt32 & aCount, PRInt32 aEndCount)
|
1999-01-26 15:58:58 +00:00
|
|
|
{
|
1999-07-04 02:43:58 +00:00
|
|
|
if(!aParent)
|
|
|
|
return nsnull;
|
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
aParent->GetFirstChild(getter_AddRefs(node));
|
|
|
|
while (node) {
|
1999-01-27 04:02:33 +00:00
|
|
|
nsString name;
|
|
|
|
node->GetNodeName(name);
|
1999-02-12 15:56:54 +00:00
|
|
|
//printf("FindNamedDOMNode[%s]==[%s] %d == %d\n", aName.ToNewCString(), name.ToNewCString(), aCount+1, aEndCount); //this leaks
|
1999-01-27 04:02:33 +00:00
|
|
|
if (name.Equals(aName)) {
|
|
|
|
aCount++;
|
1999-01-30 00:39:25 +00:00
|
|
|
if (aCount == aEndCount)
|
1999-01-27 04:02:33 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
PRBool hasChildren;
|
|
|
|
node->HasChildNodes(&hasChildren);
|
|
|
|
if (hasChildren) {
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> found(FindNamedDOMNode(aName, node, aCount, aEndCount));
|
|
|
|
if (found)
|
1999-01-27 04:02:33 +00:00
|
|
|
return found;
|
|
|
|
}
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> oldNode = node;
|
|
|
|
oldNode->GetNextSibling(getter_AddRefs(node));
|
1999-01-27 04:02:33 +00:00
|
|
|
}
|
1999-02-19 12:27:19 +00:00
|
|
|
node = do_QueryInterface(nsnull);
|
1999-01-30 00:39:25 +00:00
|
|
|
return node;
|
1999-01-26 15:58:58 +00:00
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
} // nsWebShellWindow::FindNamedDOMNode
|
1999-01-27 04:02:33 +00:00
|
|
|
|
|
|
|
//----------------------------------------
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> nsWebShellWindow::GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc)
|
1999-01-27 04:02:33 +00:00
|
|
|
{
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node; // null
|
|
|
|
|
1999-01-27 04:02:33 +00:00
|
|
|
if (nsnull == aDOMDoc) {
|
1999-01-30 00:39:25 +00:00
|
|
|
return node;
|
1999-01-27 04:02:33 +00:00
|
|
|
}
|
|
|
|
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aDOMDoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
if (element)
|
1999-02-17 02:08:00 +00:00
|
|
|
return nsCOMPtr<nsIDOMNode>(do_QueryInterface(element));
|
1999-01-27 04:02:33 +00:00
|
|
|
return node;
|
1999-01-30 00:39:25 +00:00
|
|
|
} // nsWebShellWindow::GetParentNodeFromDOMDoc
|
1999-01-27 04:02:33 +00:00
|
|
|
|
|
|
|
//----------------------------------------
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> nsWebShellWindow::GetNamedDOMDoc(const nsString & aWebShellName)
|
1999-01-27 04:02:33 +00:00
|
|
|
{
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc; // result == nsnull;
|
1999-01-26 15:58:58 +00:00
|
|
|
|
1999-01-26 18:01:38 +00:00
|
|
|
// first get the toolbar child WebShell
|
1999-01-30 00:39:25 +00:00
|
|
|
nsCOMPtr<nsIWebShell> childWebShell;
|
1999-02-18 16:32:44 +00:00
|
|
|
if (aWebShellName.Equals("this")) { // XXX small kludge for code reused
|
1999-02-19 12:27:19 +00:00
|
|
|
childWebShell = do_QueryInterface(mWebShell);
|
1999-02-18 16:32:44 +00:00
|
|
|
} else {
|
1999-04-22 00:05:59 +00:00
|
|
|
mWebShell->FindChildWithName(aWebShellName.GetUnicode(), *getter_AddRefs(childWebShell));
|
1999-02-18 16:32:44 +00:00
|
|
|
if (!childWebShell)
|
|
|
|
return domDoc;
|
|
|
|
}
|
1999-01-30 00:39:25 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
childWebShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (!cv)
|
|
|
|
return domDoc;
|
|
|
|
|
1999-02-17 02:08:00 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
1999-01-30 00:39:25 +00:00
|
|
|
if (!docv)
|
|
|
|
return domDoc;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
docv->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc)
|
1999-02-17 02:08:00 +00:00
|
|
|
return nsCOMPtr<nsIDOMDocument>(do_QueryInterface(doc));
|
1999-01-30 00:39:25 +00:00
|
|
|
|
1999-01-27 04:02:33 +00:00
|
|
|
return domDoc;
|
1999-01-30 00:39:25 +00:00
|
|
|
} // nsWebShellWindow::GetNamedDOMDoc
|
1999-01-27 04:02:33 +00:00
|
|
|
|
1999-02-12 15:56:54 +00:00
|
|
|
//----------------------------------------
|
|
|
|
PRInt32 nsWebShellWindow::GetDocHeight(nsIDocument * aDoc)
|
|
|
|
{
|
|
|
|
nsIPresShell * presShell = aDoc->GetShellAt(0);
|
1999-03-29 23:57:18 +00:00
|
|
|
if (!presShell)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
presShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
if (presContext) {
|
|
|
|
nsRect rect;
|
|
|
|
presContext->GetVisibleArea(rect);
|
|
|
|
nsIFrame * rootFrame;
|
|
|
|
nsSize size;
|
|
|
|
presShell->GetRootFrame(&rootFrame);
|
|
|
|
if (rootFrame) {
|
|
|
|
rootFrame->GetSize(size);
|
|
|
|
float t2p;
|
|
|
|
presContext->GetTwipsToPixels(&t2p);
|
|
|
|
printf("Doc size %d,%d\n", PRInt32((float)size.width*t2p),
|
|
|
|
PRInt32((float)size.height*t2p));
|
|
|
|
//return rect.height;
|
|
|
|
return PRInt32((float)rect.height*t2p);
|
|
|
|
//return PRInt32((float)size.height*presContext->GetTwipsToPixels());
|
1999-02-12 15:56:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-03-29 23:57:18 +00:00
|
|
|
NS_RELEASE(presShell);
|
1999-02-12 15:56:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-27 04:02:33 +00:00
|
|
|
//----------------------------------------
|
1999-01-26 18:01:38 +00:00
|
|
|
|
1999-02-15 05:38:15 +00:00
|
|
|
/**
|
1999-02-26 02:22:42 +00:00
|
|
|
* Get nsIDOMNode corresponding to a given webshell
|
1999-02-15 05:38:15 +00:00
|
|
|
* @param aShell the given webshell
|
|
|
|
* @return the corresponding DOM element, null if for some reason there is none
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIDOMNode>
|
|
|
|
nsWebShellWindow::GetDOMNodeFromWebShell(nsIWebShell *aShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
aShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
1999-02-17 02:08:00 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
1999-02-15 05:38:15 +00:00
|
|
|
if (docv) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
docv->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
1999-02-17 02:08:00 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc));
|
1999-02-15 05:38:15 +00:00
|
|
|
if (domdoc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
domdoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
if (element)
|
1999-02-17 02:08:00 +00:00
|
|
|
node = do_QueryInterface(element);
|
1999-02-15 05:38:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-31 22:48:28 +00:00
|
|
|
* XXX Hack for XUL Window callbacks. MUST GO AWAY!!!!
|
1999-02-15 05:38:15 +00:00
|
|
|
*/
|
1999-02-18 05:01:03 +00:00
|
|
|
void nsWebShellWindow::ExecuteStartupCode()
|
1999-02-15 05:38:15 +00:00
|
|
|
{
|
1999-02-18 05:01:03 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
|
1999-02-26 02:22:42 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> webshellElement;
|
1999-02-18 05:01:03 +00:00
|
|
|
|
1999-02-26 02:22:42 +00:00
|
|
|
if (webshellNode)
|
|
|
|
webshellElement = do_QueryInterface(webshellNode);
|
1999-02-15 05:38:15 +00:00
|
|
|
|
1999-02-26 02:22:42 +00:00
|
|
|
if (mCallbacks)
|
|
|
|
mCallbacks->ConstructBeforeJavaScript(mWebShell);
|
|
|
|
|
1999-03-05 20:23:19 +00:00
|
|
|
// Execute the string in the onLoad attribute of the webshellElement.
|
1999-02-18 05:01:03 +00:00
|
|
|
nsString startupCode;
|
1999-07-31 21:08:10 +00:00
|
|
|
|
1999-02-26 02:22:42 +00:00
|
|
|
if (mCallbacks)
|
|
|
|
mCallbacks->ConstructAfterJavaScript(mWebShell);
|
1999-02-15 05:38:15 +00:00
|
|
|
}
|
1999-02-21 21:04:21 +00:00
|
|
|
|
|
|
|
|
1999-03-29 23:57:18 +00:00
|
|
|
|
|
|
|
void nsWebShellWindow::SetTitleFromXUL()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
|
|
|
|
nsIWidget *windowWidget = GetWidget();
|
|
|
|
nsCOMPtr<nsIDOMElement> webshellElement;
|
|
|
|
nsString windowTitle;
|
|
|
|
|
|
|
|
if (webshellNode)
|
|
|
|
webshellElement = do_QueryInterface(webshellNode);
|
|
|
|
if (webshellElement && windowWidget &&
|
1999-08-05 02:16:16 +00:00
|
|
|
NS_SUCCEEDED(webshellElement->GetAttribute("title", windowTitle)) &&
|
|
|
|
windowTitle != "")
|
|
|
|
SetTitle(windowTitle.GetUnicode());
|
1999-03-29 23:57:18 +00:00
|
|
|
} // SetTitleFromXUL
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
// show/hide contents according to the current chrome mask
|
|
|
|
void nsWebShellWindow::ShowAppropriateChrome()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> rootElement;
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulRoot;
|
|
|
|
nsCOMPtr<nsIDOMDocument> chromeDoc;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
1999-08-07 02:51:03 +00:00
|
|
|
PRUint32 chromeMask;
|
1999-05-19 04:11:54 +00:00
|
|
|
|
|
|
|
// get this window's document
|
|
|
|
if (NS_FAILED(ConvertWebShellToDOMWindow(mWebShell, getter_AddRefs(domWindow))))
|
|
|
|
return;
|
1999-05-20 02:24:31 +00:00
|
|
|
if (NS_FAILED(domWindow->GetDocument(getter_AddRefs(chromeDoc))) || !chromeDoc)
|
1999-05-19 04:11:54 +00:00
|
|
|
return;
|
1999-05-20 02:24:31 +00:00
|
|
|
if (NS_FAILED(chromeDoc->GetDocumentElement(getter_AddRefs(rootElement))) || !rootElement)
|
1999-05-19 04:11:54 +00:00
|
|
|
return;
|
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
// calculate a special version of the chrome mask. we store the actual
|
|
|
|
// value sent, but we make local changes depending on whether defaults
|
|
|
|
// were asked for. Note that only internal (not OS-) chrome matters
|
|
|
|
// at this point, so the OS chrome is not calculated.
|
|
|
|
chromeMask = mChromeMask;
|
|
|
|
if (chromeMask & NS_CHROME_DEFAULT_CHROME)
|
|
|
|
if (chromeMask & NS_CHROME_OPEN_AS_DIALOG)
|
|
|
|
chromeMask &= ~(NS_CHROME_MENU_BAR_ON | NS_CHROME_TOOL_BAR_ON |
|
|
|
|
NS_CHROME_LOCATION_BAR_ON | NS_CHROME_STATUS_BAR_ON |
|
1999-09-18 03:24:34 +00:00
|
|
|
NS_CHROME_PERSONAL_TOOLBAR_ON | NS_CHROME_SCROLLBARS_ON |NS_CHROME_EXTRACHROME_ON);
|
1999-08-07 02:51:03 +00:00
|
|
|
else
|
|
|
|
// theoretically, this won't happen (only dialogs can have defaults)
|
|
|
|
// but, we cover this case anyway
|
|
|
|
chromeMask |= NS_CHROME_ALL_CHROME;
|
|
|
|
|
1999-06-10 01:27:47 +00:00
|
|
|
// special treatment for the menubar
|
|
|
|
ShowMenuBar(mChromeMask & NS_CHROME_MENU_BAR_ON ? PR_TRUE : PR_FALSE);
|
|
|
|
|
1999-05-19 04:11:54 +00:00
|
|
|
// get a list of this document's elements with the chromeclass attribute specified
|
|
|
|
xulRoot = do_QueryInterface(rootElement);
|
|
|
|
if (xulRoot) { // todo (maybe) the longer, straight DOM (not RDF) version?
|
|
|
|
nsCOMPtr<nsIDOMNodeList> chromeNodes;
|
|
|
|
if (NS_SUCCEEDED(xulRoot->GetElementsByAttribute("chromeclass", "*",
|
|
|
|
getter_AddRefs(chromeNodes)))) {
|
|
|
|
PRUint32 nodeCtr, nodeCount;
|
|
|
|
chromeNodes->GetLength(&nodeCount);
|
|
|
|
for (nodeCtr = 0; nodeCtr < nodeCount; nodeCtr++) {
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode;
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
chromeNodes->Item(nodeCtr, getter_AddRefs(domNode));
|
|
|
|
domElement = do_QueryInterface(domNode);
|
|
|
|
if (domElement) {
|
|
|
|
nsAutoString chromeClass;
|
|
|
|
PRBool makeChange;
|
|
|
|
PRUint32 flag;
|
|
|
|
// show or hide the element according to its chromeclass and the chromemask
|
|
|
|
domElement->GetAttribute("chromeclass", chromeClass);
|
|
|
|
makeChange = PR_FALSE;
|
1999-08-07 02:51:03 +00:00
|
|
|
if (chromeClass == "menubar") {
|
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_MENU_BAR_ON;
|
|
|
|
} else if (chromeClass == "toolbar") {
|
1999-06-10 01:27:47 +00:00
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_TOOL_BAR_ON;
|
1999-06-04 04:01:20 +00:00
|
|
|
} else if (chromeClass == "location") {
|
1999-05-19 04:11:54 +00:00
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_LOCATION_BAR_ON;
|
1999-06-10 01:27:47 +00:00
|
|
|
} else if (chromeClass == "directories") {
|
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_PERSONAL_TOOLBAR_ON;
|
1999-05-19 04:11:54 +00:00
|
|
|
} else if (chromeClass == "status") {
|
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_STATUS_BAR_ON;
|
1999-09-18 03:24:34 +00:00
|
|
|
}else if (chromeClass == "extrachrome") {
|
|
|
|
makeChange = PR_TRUE;
|
|
|
|
flag = mChromeMask & NS_CHROME_EXTRACHROME_ON;
|
1999-05-19 04:11:54 +00:00
|
|
|
}
|
1999-06-10 01:27:47 +00:00
|
|
|
if (makeChange)
|
1999-05-19 07:51:48 +00:00
|
|
|
if (flag)
|
|
|
|
domElement->RemoveAttribute("chromehidden");
|
|
|
|
else
|
1999-06-10 01:27:47 +00:00
|
|
|
domElement->SetAttribute("chromehidden", "T");
|
1999-05-19 04:11:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-27 20:36:15 +00:00
|
|
|
// if the main document URL specified URLs for any content areas, start them loading
|
|
|
|
void nsWebShellWindow::LoadContentAreas() {
|
|
|
|
|
|
|
|
nsAutoString searchSpec;
|
|
|
|
|
|
|
|
// fetch the chrome document URL
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
mWebShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (contentViewer) {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(contentViewer);
|
|
|
|
if (docViewer) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
docViewer->GetDocument(*getter_AddRefs(doc));
|
1999-06-23 03:29:44 +00:00
|
|
|
nsCOMPtr<nsIURI> mainURL = getter_AddRefs(doc->GetDocumentURL());
|
1999-05-27 20:36:15 +00:00
|
|
|
if (mainURL) {
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
char *search = nsnull;
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mainURL);
|
|
|
|
if (url)
|
|
|
|
url->GetQuery(&search);
|
|
|
|
#else
|
1999-05-27 20:36:15 +00:00
|
|
|
const char *search;
|
|
|
|
mainURL->GetSearch(&search);
|
1999-06-28 10:35:57 +00:00
|
|
|
#endif
|
1999-05-27 20:36:15 +00:00
|
|
|
searchSpec = search;
|
1999-06-28 10:35:57 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(search);
|
|
|
|
#endif
|
1999-05-27 20:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// content URLs are specified in the search part of the URL
|
|
|
|
// as <contentareaID>=<escapedURL>[;(repeat)]
|
|
|
|
if (searchSpec.Length() > 0) {
|
|
|
|
PRInt32 begPos,
|
|
|
|
eqPos,
|
|
|
|
endPos;
|
|
|
|
nsString contentAreaID,
|
|
|
|
contentURL;
|
|
|
|
char *urlChar;
|
|
|
|
nsIWebShell *contentShell;
|
|
|
|
nsresult rv;
|
|
|
|
for (endPos = 0; endPos < searchSpec.Length(); ) {
|
|
|
|
// extract contentAreaID and URL substrings
|
|
|
|
begPos = endPos;
|
1999-07-26 00:51:00 +00:00
|
|
|
eqPos = searchSpec.FindChar('=', PR_FALSE,begPos);
|
1999-05-27 20:36:15 +00:00
|
|
|
if (eqPos < 0)
|
|
|
|
break;
|
|
|
|
|
1999-07-26 00:51:00 +00:00
|
|
|
endPos = searchSpec.FindChar(';', PR_FALSE,eqPos);
|
1999-05-27 20:36:15 +00:00
|
|
|
if (endPos < 0)
|
|
|
|
endPos = searchSpec.Length();
|
|
|
|
searchSpec.Mid(contentAreaID, begPos, eqPos-begPos);
|
|
|
|
searchSpec.Mid(contentURL, eqPos+1, endPos-eqPos-1);
|
|
|
|
endPos++;
|
|
|
|
|
|
|
|
// see if we have a webshell with a matching contentAreaID
|
|
|
|
rv = GetContentShellById(contentAreaID, &contentShell);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
urlChar = contentURL.ToNewCString();
|
|
|
|
if (urlChar) {
|
|
|
|
nsUnescape(urlChar);
|
|
|
|
contentURL = urlChar;
|
|
|
|
contentShell->LoadURL(contentURL.GetUnicode());
|
|
|
|
delete [] urlChar;
|
|
|
|
}
|
|
|
|
NS_RELEASE(contentShell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
//-- nsIDocumentObserver
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::BeginUpdate(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::EndUpdate(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::BeginLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::EndLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::EndReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// nsIDocumentObserver
|
|
|
|
// this is needed for menu changes
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-27 08:34:06 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 00:06:58 +00:00
|
|
|
nsWebShellWindow::ContentStatesChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2)
|
1999-02-27 08:34:06 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-21 21:04:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
//printf("AttributeChanged\n");
|
|
|
|
PRInt32 i;
|
|
|
|
for (i=0;i<mMenuDelegates.Count();i++) {
|
|
|
|
nsIXULCommand * cmd = (nsIXULCommand *)mMenuDelegates[i];
|
|
|
|
nsIDOMElement * node;
|
|
|
|
cmd->GetDOMElement(&node);
|
|
|
|
//nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
|
|
|
// Doing this for the must speed
|
|
|
|
nsIContent * content;
|
|
|
|
if (NS_OK == node->QueryInterface(kIContentIID, (void**) &content)) {
|
|
|
|
if (content == aContent) {
|
|
|
|
nsAutoString attr;
|
|
|
|
aAttribute->ToString(attr);
|
|
|
|
cmd->AttributeHasBeenSet(attr);
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ContentReplaced(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-16 18:40:27 +00:00
|
|
|
|
|
|
|
/**************** nsIBrowserWindow interface ********************/
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::Init(nsIAppShell* aAppShell,
|
|
|
|
nsIPref* aPrefs,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRUint32 aChromeMask,
|
|
|
|
PRBool aAllowPlugins)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsCOMPtr<nsIURI> urlObj;
|
1999-06-18 17:34:08 +00:00
|
|
|
char * urlStr = "chrome://navigator/content/";
|
1999-04-16 18:40:27 +00:00
|
|
|
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
|
|
|
rv = NS_NewURL(getter_AddRefs(urlObj), urlStr);
|
|
|
|
#else
|
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsIURI *uri = nsnull;
|
|
|
|
rv = service->NewURI(urlStr, nsnull, &uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
rv = uri->QueryInterface(nsIURI::GetIID(), (void**)&urlObj);
|
1999-06-18 17:34:08 +00:00
|
|
|
NS_RELEASE(uri);
|
|
|
|
#endif // NECKO
|
1999-04-16 18:40:27 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Note: null nsIStreamObserver means this window won't be able to answer FE_callback-type
|
|
|
|
// questions from netlib. Observers are generally appcores. We'll have to supply
|
|
|
|
// a generic browser appcore here someday.
|
1999-07-01 02:50:53 +00:00
|
|
|
nsWidgetInitData widgetInitData;
|
1999-07-27 04:27:17 +00:00
|
|
|
widgetInitData.mWindowType = eWindowType_child;
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_default;
|
1999-07-01 02:50:53 +00:00
|
|
|
|
1999-08-16 22:23:19 +00:00
|
|
|
rv = Initialize(nsnull, aAppShell, urlObj, PR_TRUE, PR_TRUE,
|
1999-10-05 04:04:16 +00:00
|
|
|
nsnull, aBounds.width, aBounds.height, widgetInitData);
|
1999-05-19 04:11:54 +00:00
|
|
|
mChromeMask = aChromeMask;
|
1999-04-16 18:40:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
MoveTo(aBounds.x, aBounds.y);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::MoveTo(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
mWindow->Move(aX, aY);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight)
|
1999-04-16 18:40:27 +00:00
|
|
|
{
|
1999-07-04 04:09:54 +00:00
|
|
|
// XXX We have to look at the delta between our content shell's
|
|
|
|
// size and the size passed in and then resize ourselves based on that
|
|
|
|
// delta.
|
|
|
|
mIntrinsicallySized = PR_FALSE; // We got changed. No more intrinsic sizing here.
|
1999-04-16 18:40:27 +00:00
|
|
|
mWindow->Resize(aWidth, aHeight, PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight)
|
1999-04-16 18:40:27 +00:00
|
|
|
{
|
1999-08-31 00:20:11 +00:00
|
|
|
nsCOMPtr<nsIWebShell> content;
|
|
|
|
GetContentWebShell(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
PRInt32 x, y, width, height,
|
|
|
|
widthDelta, heightDelta;
|
|
|
|
content->GetBounds(x,y,width,height);
|
|
|
|
widthDelta = aWidth - width;
|
|
|
|
heightDelta = aHeight - height;
|
1999-07-04 04:09:54 +00:00
|
|
|
|
1999-08-31 00:20:11 +00:00
|
|
|
nsRect windowBounds;
|
|
|
|
mWindow->GetBounds(windowBounds);
|
|
|
|
mWindow->Resize(windowBounds.width + widthDelta,
|
|
|
|
windowBounds.height + heightDelta,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
1999-04-16 18:40:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-04 04:09:54 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetContentBounds(nsRect& aResult)
|
|
|
|
{
|
|
|
|
// Should return the size of the content webshell.
|
|
|
|
nsCOMPtr<nsIWebShell> contentShell;
|
|
|
|
GetContentWebShell(getter_AddRefs(contentShell));
|
|
|
|
if (!contentShell) {
|
|
|
|
NS_ERROR("Attempt to retrieve the content bounds for a window with no content.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 x,y,width,height;
|
|
|
|
contentShell->GetBounds(x,y,width,height);
|
|
|
|
aResult.x = x;
|
|
|
|
aResult.y = y;
|
|
|
|
aResult.width = width;
|
|
|
|
aResult.height = height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-16 18:40:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetWindowBounds(nsRect& aResult)
|
|
|
|
{
|
|
|
|
mWindow->GetBounds(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::SetChrome(PRUint32 aNewChromeMask)
|
|
|
|
{
|
1999-05-19 04:11:54 +00:00
|
|
|
mChromeMask = aNewChromeMask;
|
|
|
|
ShowAppropriateChrome();
|
1999-04-16 18:40:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetChrome(PRUint32& aChromeMaskResult)
|
|
|
|
{
|
1999-05-19 04:11:54 +00:00
|
|
|
aChromeMaskResult = mChromeMask;
|
1999-04-16 18:40:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::SetTitle(const PRUnichar* aTitle)
|
|
|
|
{
|
|
|
|
nsIWidget *windowWidget = GetWidget();
|
1999-05-19 03:21:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Get window modifier
|
|
|
|
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
|
|
|
|
nsCOMPtr<nsIDOMElement> webshellElement;
|
|
|
|
nsString windowTitleModifier;
|
1999-09-14 21:45:12 +00:00
|
|
|
nsString titleSeparator;
|
|
|
|
nsString titlePreface;
|
1999-05-19 03:21:19 +00:00
|
|
|
if (webshellNode)
|
|
|
|
webshellElement = do_QueryInterface(webshellNode);
|
|
|
|
if (webshellElement )
|
1999-06-22 01:38:28 +00:00
|
|
|
{
|
1999-06-22 03:04:11 +00:00
|
|
|
webshellElement->GetAttribute("titlemodifier", windowTitleModifier );
|
1999-09-14 21:45:12 +00:00
|
|
|
webshellElement->GetAttribute("titlemenuseparator", titleSeparator );
|
|
|
|
webshellElement->GetAttribute("titlepreface", titlePreface );
|
1999-06-22 01:38:28 +00:00
|
|
|
}
|
1999-09-14 21:45:12 +00:00
|
|
|
nsString title;
|
|
|
|
nsString docTitle( aTitle );
|
1999-06-22 03:04:11 +00:00
|
|
|
|
1999-09-14 21:45:12 +00:00
|
|
|
if( docTitle.Length() > 0 ) {
|
|
|
|
if ( titlePreface.Length() > 0 ) {
|
|
|
|
// Title will be: Preface: Doc Title - Mozilla
|
|
|
|
title = titlePreface + docTitle;
|
|
|
|
} else {
|
|
|
|
// Title will be: Doc Title - Mozilla
|
|
|
|
title = docTitle;
|
|
|
|
}
|
|
|
|
title += titleSeparator + windowTitleModifier;
|
|
|
|
} else {
|
|
|
|
// Title will be just plain: Mozilla
|
|
|
|
title = windowTitleModifier;
|
|
|
|
}
|
1999-06-22 03:04:11 +00:00
|
|
|
if (windowWidget)
|
|
|
|
windowWidget->SetTitle(title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tell the window mediator that a title has changed
|
|
|
|
#if 1
|
|
|
|
{
|
|
|
|
nsIWindowMediator* service;
|
|
|
|
if (NS_FAILED(nsServiceManager::GetService(kWindowMediatorCID, kIWindowMediatorIID, (nsISupports**) &service ) ) )
|
|
|
|
return NS_OK;
|
|
|
|
service->UpdateWindowTitle( this, title.GetUnicode() );
|
|
|
|
nsServiceManager::ReleaseService(kWindowMediatorCID, service);
|
|
|
|
}
|
|
|
|
#endif // Window Mediation
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-04-16 18:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetTitle(const PRUnichar** aResult)
|
|
|
|
{
|
|
|
|
// no, we didn't store the title for you. why so nosy?
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-06-08 20:59:41 +00:00
|
|
|
|
|
|
|
// This should rightfully be somebody's PROGID?
|
|
|
|
// Will switch when the "app shell browser component" arrives.
|
|
|
|
static const char *prefix = "component://netscape/appshell/component/browser/window";
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWebShellWindow::NotifyObservers( const nsString &aTopic, const nsString &someData ) {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// Get observer service.
|
|
|
|
nsIObserverService *svc = 0;
|
|
|
|
rv = nsServiceManager::GetService( NS_OBSERVERSERVICE_PROGID,
|
|
|
|
nsIObserverService::GetIID(),
|
|
|
|
(nsISupports**)&svc );
|
|
|
|
if ( NS_SUCCEEDED( rv ) && svc ) {
|
|
|
|
// Notify observers as instructed; the subject is "this" web shell window.
|
1999-09-09 20:44:17 +00:00
|
|
|
nsAutoString topic(prefix);
|
1999-06-08 20:59:41 +00:00
|
|
|
topic += ";";
|
|
|
|
topic += aTopic;
|
|
|
|
rv = svc->Notify( (nsIWebShellWindow*)this, topic.GetUnicode(), someData.GetUnicode() );
|
|
|
|
// Release the service.
|
|
|
|
nsServiceManager::ReleaseService( NS_OBSERVERSERVICE_PROGID, svc );
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-04-16 18:40:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::SetStatus(const PRUnichar* aStatus)
|
|
|
|
{
|
1999-06-08 20:59:41 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-07-26 15:02:19 +00:00
|
|
|
// Store status text unless empty string was set, then use defaultStatus
|
1999-06-08 20:59:41 +00:00
|
|
|
mStatus = aStatus;
|
1999-07-26 15:02:19 +00:00
|
|
|
if (mStatus.Length() == 0) {
|
|
|
|
mStatus = mDefaultStatus;
|
|
|
|
}
|
1999-06-08 20:59:41 +00:00
|
|
|
// Broadcast status text change to interested parties.
|
1999-09-09 20:44:17 +00:00
|
|
|
nsAutoString statusName("status");
|
|
|
|
nsAutoString statusValue(aStatus);
|
|
|
|
rv = NotifyObservers( statusName, statusValue );
|
1999-06-08 20:59:41 +00:00
|
|
|
return rv;
|
1999-04-16 18:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetStatus(const PRUnichar** aResult)
|
|
|
|
{
|
1999-06-08 20:59:41 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if ( aResult ) {
|
|
|
|
// Semantics are ill-defined: How to allocate? Who frees it?
|
|
|
|
*aResult = mStatus.ToNewUnicode();
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-04-16 18:40:27 +00:00
|
|
|
}
|
|
|
|
|
1999-07-26 15:02:19 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::SetDefaultStatus(const PRUnichar* aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// Store status text.
|
|
|
|
mDefaultStatus = aStatus;
|
|
|
|
// Broadcast status text change to interested parties.
|
|
|
|
rv = NotifyObservers( "defaultStatus", aStatus );
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::GetDefaultStatus(const PRUnichar** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if ( aResult ) {
|
|
|
|
// Semantics are ill-defined: How to allocate? Who frees it?
|
|
|
|
*aResult = mDefaultStatus.ToNewUnicode();
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-16 18:40:27 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::SetProgress(PRInt32 aProgress, PRInt32 aProgressMax)
|
|
|
|
{
|
1999-06-08 20:59:41 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Encode progress report in topic (there is no GetProgress for observers
|
|
|
|
// to query it).
|
|
|
|
char topic[32];
|
|
|
|
PR_snprintf( topic,
|
|
|
|
sizeof topic,
|
|
|
|
"%ld %ld",
|
|
|
|
(long)aProgress,
|
|
|
|
(long)aProgressMax );
|
|
|
|
|
|
|
|
// Broadcast progress info to interested parties.
|
|
|
|
rv = NotifyObservers( "progress", topic );
|
|
|
|
|
|
|
|
return rv;
|
1999-04-16 20:22:21 +00:00
|
|
|
}
|
1999-06-09 19:03:24 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::ShowMenuBar(PRBool aShow)
|
|
|
|
{
|
1999-06-10 01:27:47 +00:00
|
|
|
if (aShow)
|
|
|
|
mChromeMask |= NS_CHROME_MENU_BAR_ON;
|
|
|
|
else
|
|
|
|
mChromeMask &= ~NS_CHROME_MENU_BAR_ON;
|
1999-06-09 19:03:24 +00:00
|
|
|
return mWindow->ShowMenuBar(aShow);
|
|
|
|
}
|
|
|
|
|
1999-07-04 23:41:32 +00:00
|
|
|
//nsIUrlDispatcher methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-03 20:51:41 +00:00
|
|
|
nsWebShellWindow::HandleUrl(const PRUnichar * aCommand,
|
|
|
|
const PRUnichar * aURLSpec,
|
|
|
|
nsIInputStream * aPostDataStream)
|
1999-07-05 23:45:24 +00:00
|
|
|
{
|
1999-07-04 23:41:32 +00:00
|
|
|
/* Make the topic to observe. The topic will be of the format
|
1999-09-15 19:33:46 +00:00
|
|
|
* linkclick:<prototocol>. Note that this is a totally made up thing.
|
1999-07-04 23:41:32 +00:00
|
|
|
* Things are going to change later
|
|
|
|
*/
|
1999-09-15 19:33:46 +00:00
|
|
|
nsAutoString topic(aCommand);
|
1999-07-04 23:41:32 +00:00
|
|
|
topic += ":";
|
|
|
|
nsAutoString url(aURLSpec);
|
1999-09-15 19:33:46 +00:00
|
|
|
PRInt32 urllen = url.Length();
|
1999-07-10 00:15:04 +00:00
|
|
|
nsresult rv;
|
1999-07-04 23:41:32 +00:00
|
|
|
|
1999-07-26 00:51:00 +00:00
|
|
|
PRInt32 offset = url.FindChar(':');
|
1999-07-04 23:41:32 +00:00
|
|
|
if (offset <= 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-07-22 22:34:28 +00:00
|
|
|
PRInt32 offset2= url.Find("mailto:", PR_TRUE);
|
1999-07-04 23:41:32 +00:00
|
|
|
if (offset2 == 0) {
|
|
|
|
topic += "mailto";
|
|
|
|
|
1999-09-15 19:33:46 +00:00
|
|
|
/* I know about all that is going on regarding using window.open
|
1999-07-10 00:15:04 +00:00
|
|
|
* instead of showWindowWithArgs(). But, I really don't have another
|
|
|
|
* option in this case to invoke the messenger compose window.
|
|
|
|
* This piece of code will eventually go away when I start using the
|
|
|
|
* protocol registries in NECKO
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIDOMToolkitCore, toolkitCore, kToolkitCoreCID, &rv)
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-09-15 19:33:46 +00:00
|
|
|
/* Messenger doesn't understand to:xyz@domain.com,subject="xyz" yet.
|
|
|
|
* So, just pass the type and mode info
|
|
|
|
*/
|
|
|
|
nsCAutoString urlcstr(url);
|
|
|
|
urlcstr.ReplaceChar('&', ',');
|
|
|
|
urlcstr.ReplaceChar('?', ',');
|
|
|
|
|
|
|
|
nsAutoString args("format=0,");
|
|
|
|
nsCAutoString tailpiece;
|
|
|
|
urlcstr.Right(tailpiece, urllen-7);
|
|
|
|
args += "to=";
|
|
|
|
args += tailpiece;
|
|
|
|
rv = toolkitCore->ShowWindowWithArgs("chrome://messengercompose/content",
|
1999-07-10 00:15:04 +00:00
|
|
|
nsnull,
|
1999-09-15 19:33:46 +00:00
|
|
|
args);
|
1999-07-10 00:15:04 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-07-04 23:41:32 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
topic += "browser";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
1999-07-06 18:53:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::IsIntrinsicallySized(PRBool& aResult)
|
|
|
|
{
|
|
|
|
aResult = mIntrinsicallySized;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-28 02:52:14 +00:00
|
|
|
|
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
// nsIPrompt
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::Alert(const PRUnichar *text)
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
|
|
|
{
|
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv = dialog->Alert( domWindow, NULL,text );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
1999-07-28 02:52:14 +00:00
|
|
|
}
|
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::Confirm(const PRUnichar *text, PRBool *_retval)
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
|
|
|
{
|
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-28 02:52:14 +00:00
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv = dialog->Confirm( domWindow, NULL, text, _retval );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
1999-07-28 02:52:14 +00:00
|
|
|
}
|
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::ConfirmCheck(const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv =dialog->ConfirmCheck( domWindow,NULL, text, checkMsg, checkValue, _retval );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
1999-07-28 02:52:14 +00:00
|
|
|
}
|
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::Prompt(const PRUnichar *text, const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv = dialog->Prompt( domWindow, NULL, text, defaultText, result, _retval );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-07-28 02:52:14 +00:00
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::PromptUsernameAndPassword(const PRUnichar *text, PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
|
|
|
{
|
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv = dialog->PromptUsernameAndPassword( domWindow, NULL, text, user, pwd, _retval );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
1999-07-28 02:52:14 +00:00
|
|
|
}
|
|
|
|
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_IMETHODIMP nsWebShellWindow::PromptPassword(const PRUnichar *text, PRUnichar **pwd, PRBool *_retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
nsIWebShell* tempWebShell;
|
|
|
|
GetWebShell(tempWebShell );
|
|
|
|
nsCOMPtr<nsIWebShell> webShell( dont_AddRef(tempWebShell) );
|
|
|
|
if (NS_FAILED(rv = ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow))))
|
1999-07-28 02:52:14 +00:00
|
|
|
{
|
1999-08-11 03:05:25 +00:00
|
|
|
NS_ERROR("Unable to retrieve the DOM window from the new web shell.");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
1999-09-02 00:18:54 +00:00
|
|
|
rv = dialog->PromptPassword( domWindow, NULL, text, pwd, _retval );
|
1999-08-11 03:05:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::ConfirmYN(const PRUnichar *text, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::ConfirmCheckYN(const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-08-12 01:53:17 +00:00
|
|
|
}
|
1999-08-12 22:08:17 +00:00
|
|
|
|
|
|
|
// nsIModalWindowSupport interface
|
|
|
|
nsresult nsWebShellWindow::PrepareModality()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return appShell->PushThreadEventQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsWebShellWindow::FinishModality()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return appShell->PopThreadEventQueue();
|
|
|
|
}
|
|
|
|
|