1998-07-20 16:19:22 +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.
|
|
|
|
*/
|
1998-09-23 23:02:54 +00:00
|
|
|
#include "nsIPref.h"
|
1998-11-03 08:07:24 +00:00
|
|
|
#include "prmem.h"
|
1998-09-23 23:02:54 +00:00
|
|
|
|
1998-07-29 23:43:22 +00:00
|
|
|
#ifdef XP_MAC
|
1998-07-20 21:16:38 +00:00
|
|
|
#include "nsBrowserWindow.h"
|
1998-07-29 21:06:19 +00:00
|
|
|
#define NS_IMPL_IDS
|
1998-07-29 23:43:22 +00:00
|
|
|
#else
|
|
|
|
#define NS_IMPL_IDS
|
|
|
|
#include "nsBrowserWindow.h"
|
|
|
|
#endif
|
1998-07-20 16:19:22 +00:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsITextWidget.h"
|
|
|
|
#include "nsIButton.h"
|
|
|
|
#include "nsIImageGroup.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsIThrobber.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1998-07-21 16:45:21 +00:00
|
|
|
#include "nsIFileWidget.h"
|
1998-09-01 21:08:32 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
1998-07-20 16:19:22 +00:00
|
|
|
#include "nsRepository.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
1998-07-20 21:16:38 +00:00
|
|
|
#include "nsViewerApp.h"
|
1998-07-21 16:45:21 +00:00
|
|
|
#include "prprf.h"
|
1998-07-30 22:42:27 +00:00
|
|
|
#include "nsRepository.h"
|
|
|
|
#include "nsParserCIID.h"
|
1998-12-03 10:12:30 +00:00
|
|
|
#include "nsIEnumerator.h"
|
1999-01-05 22:59:02 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-07-20 21:16:38 +00:00
|
|
|
|
1998-07-31 16:53:45 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsXIFDTD.h"
|
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsHTMLContentSinkStream.h"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsEditorMode.h"
|
1998-07-31 16:53:45 +00:00
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
// Needed for "Find" GUI
|
|
|
|
#include "nsIDialog.h"
|
|
|
|
#include "nsICheckButton.h"
|
|
|
|
#include "nsIRadioButton.h"
|
|
|
|
#include "nsILabel.h"
|
1998-09-14 20:46:42 +00:00
|
|
|
#include "nsWidgetSupport.h"
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
#include "nsXPBaseWindow.h"
|
|
|
|
#include "nsFindDialog.h"
|
|
|
|
|
1998-12-11 16:36:21 +00:00
|
|
|
#include "nsIContentConnector.h"
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
#include "resources.h"
|
1998-07-27 21:10:02 +00:00
|
|
|
|
|
|
|
#if defined(WIN32)
|
1998-07-27 18:17:07 +00:00
|
|
|
#include <strstrea.h>
|
1998-07-29 21:21:08 +00:00
|
|
|
#else
|
1999-01-28 23:44:41 +00:00
|
|
|
#include <strstream.h>
|
1998-07-30 03:38:37 +00:00
|
|
|
#endif
|
1998-07-27 18:17:07 +00:00
|
|
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
1998-10-06 02:54:00 +00:00
|
|
|
#if defined (XP_MAC)
|
1999-01-28 22:58:52 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
1998-10-06 02:54:00 +00:00
|
|
|
#include <Scrap.h>
|
|
|
|
#include <TextEdit.h>
|
|
|
|
#endif
|
|
|
|
|
1999-01-21 21:51:21 +00:00
|
|
|
// For Copy
|
|
|
|
#include "nsISelection.h"
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-07-24 16:03:11 +00:00
|
|
|
// XXX For font setting below
|
|
|
|
#include "nsFont.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
|
1999-01-26 19:09:22 +00:00
|
|
|
#define THROBBING_N
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
// XXX greasy constants
|
1998-11-23 03:30:24 +00:00
|
|
|
#ifdef THROBBING_N
|
1998-07-20 16:19:22 +00:00
|
|
|
#define THROBBER_WIDTH 32
|
|
|
|
#define THROBBER_HEIGHT 32
|
1998-11-23 03:30:24 +00:00
|
|
|
#define THROBBER_AT "resource:/res/throbber/anims%02d.gif"
|
|
|
|
#define THROB_NUM 14
|
|
|
|
#else
|
|
|
|
#define THROBBER_WIDTH 42
|
|
|
|
#define THROBBER_HEIGHT 42
|
|
|
|
#define THROBBER_AT "resource:/res/throbber/LargeAnimation%02d.gif"
|
|
|
|
#define THROB_NUM 38
|
|
|
|
#endif
|
1998-07-20 16:19:22 +00:00
|
|
|
#define BUTTON_WIDTH 90
|
|
|
|
#define BUTTON_HEIGHT THROBBER_HEIGHT
|
1998-09-01 22:49:16 +00:00
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
#ifdef INSET_WEBSHELL
|
|
|
|
#define WEBSHELL_LEFT_INSET 5
|
|
|
|
#define WEBSHELL_RIGHT_INSET 5
|
|
|
|
#define WEBSHELL_TOP_INSET 5
|
|
|
|
#define WEBSHELL_BOTTOM_INSET 5
|
|
|
|
#else
|
|
|
|
#define WEBSHELL_LEFT_INSET 0
|
|
|
|
#define WEBSHELL_RIGHT_INSET 0
|
|
|
|
#define WEBSHELL_TOP_INSET 0
|
|
|
|
#define WEBSHELL_BOTTOM_INSET 0
|
|
|
|
#endif
|
|
|
|
|
1998-09-01 21:08:32 +00:00
|
|
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
1998-07-20 16:19:22 +00:00
|
|
|
static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID);
|
|
|
|
static NS_DEFINE_IID(kButtonCID, NS_BUTTON_CID);
|
1998-07-21 16:45:21 +00:00
|
|
|
static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID);
|
1998-07-20 16:19:22 +00:00
|
|
|
static NS_DEFINE_IID(kTextFieldCID, NS_TEXTFIELD_CID);
|
|
|
|
static NS_DEFINE_IID(kThrobberCID, NS_THROBBER_CID);
|
|
|
|
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
|
|
|
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
1998-08-28 16:14:37 +00:00
|
|
|
static NS_DEFINE_IID(kDialogCID, NS_DIALOG_CID);
|
|
|
|
static NS_DEFINE_IID(kCheckButtonCID, NS_CHECKBUTTON_CID);
|
|
|
|
static NS_DEFINE_IID(kRadioButtonCID, NS_RADIOBUTTON_CID);
|
|
|
|
static NS_DEFINE_IID(kLabelCID, NS_LABEL_CID);
|
1998-12-17 15:52:48 +00:00
|
|
|
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-09-01 21:08:32 +00:00
|
|
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
1998-07-20 16:19:22 +00:00
|
|
|
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
|
|
|
|
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
1998-07-21 16:45:21 +00:00
|
|
|
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
1998-07-20 16:19:22 +00:00
|
|
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIThrobberIID, NS_ITHROBBER_IID);
|
1998-12-11 16:36:21 +00:00
|
|
|
static NS_DEFINE_IID(kIContentConnectorIID, NS_ICONTENTCONNECTOR_IID);
|
1998-12-03 10:12:30 +00:00
|
|
|
static NS_DEFINE_IID(kCTreeViewCID, NS_TREEVIEW_CID);
|
1999-01-05 22:59:02 +00:00
|
|
|
static NS_DEFINE_IID(kCToolboxCID, NS_TOOLBARMANAGER_CID);
|
1998-07-20 16:19:22 +00:00
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
1998-10-29 14:06:26 +00:00
|
|
|
static NS_DEFINE_IID(kIWindowIID, NS_IWINDOW_IID);
|
1998-08-28 16:14:37 +00:00
|
|
|
static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID);
|
|
|
|
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
|
|
|
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
|
|
|
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
|
1998-11-03 08:07:24 +00:00
|
|
|
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
|
1998-11-11 22:22:18 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
1998-12-17 15:52:48 +00:00
|
|
|
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-08-21 18:28:48 +00:00
|
|
|
|
|
|
|
static const char* gsAOLFormat = "AOLMAIL";
|
|
|
|
static const char* gsHTMLFormat = "text/html";
|
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
// prototypes
|
1998-08-31 19:09:55 +00:00
|
|
|
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
|
1998-09-14 20:46:42 +00:00
|
|
|
static void* GetItemsNativeData(nsISupports* aObject);
|
1998-08-31 19:09:55 +00:00
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-11-11 22:22:18 +00:00
|
|
|
nsIPresShell*
|
|
|
|
GetPresShellFor(nsIWebShell* aWebShell)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = nsnull;
|
|
|
|
if (nsnull != aWebShell) {
|
|
|
|
nsIContentViewer* cv = nsnull;
|
1999-01-14 06:49:59 +00:00
|
|
|
aWebShell->GetContentViewer(&cv);
|
1998-11-11 22:22:18 +00:00
|
|
|
if (nsnull != cv) {
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
|
|
|
|
if (nsnull != docv) {
|
|
|
|
nsIPresContext* cx;
|
|
|
|
docv->GetPresContext(cx);
|
|
|
|
if (nsnull != cx) {
|
|
|
|
shell = cx->GetShell();
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docv);
|
|
|
|
}
|
|
|
|
NS_RELEASE(cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return shell;
|
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
nsVoidArray nsBrowserWindow::gBrowsers;
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
nsBrowserWindow*
|
|
|
|
nsBrowserWindow::FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
1998-08-06 02:21:23 +00:00
|
|
|
nsIWidget* widget;
|
|
|
|
nsBrowserWindow* result = nsnull;
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
PRInt32 i, n = gBrowsers.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(i);
|
|
|
|
if (nsnull != bw) {
|
|
|
|
switch (aWhich) {
|
|
|
|
case FIND_WINDOW:
|
1998-12-08 01:57:40 +00:00
|
|
|
bw->mWindow->QueryInterface(kIWidgetIID, (void**) &widget);
|
|
|
|
if (widget == aWidget) {
|
|
|
|
result = bw;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
case FIND_BACK:
|
1998-12-08 01:57:40 +00:00
|
|
|
if (bw->mBack) {
|
|
|
|
bw->mBack->QueryInterface(kIWidgetIID, (void**) &widget);
|
|
|
|
if (widget == aWidget) {
|
|
|
|
result = bw;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
}
|
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
case FIND_FORWARD:
|
1998-12-08 01:57:40 +00:00
|
|
|
if (bw->mForward) {
|
|
|
|
bw->mForward->QueryInterface(kIWidgetIID, (void**) &widget);
|
|
|
|
if (widget == aWidget) {
|
|
|
|
result = bw;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
}
|
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
case FIND_LOCATION:
|
1998-12-08 01:57:40 +00:00
|
|
|
if (bw->mLocation) {
|
|
|
|
bw->mLocation->QueryInterface(kIWidgetIID, (void**) &widget);
|
|
|
|
if (widget == aWidget) {
|
|
|
|
result = bw;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
}
|
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
if (nsnull != result) {
|
|
|
|
NS_ADDREF(result);
|
|
|
|
}
|
1998-08-06 02:21:23 +00:00
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::AddBrowser(nsBrowserWindow* aBrowser)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
gBrowsers.AppendElement(aBrowser);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF(aBrowser);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::RemoveBrowser(nsBrowserWindow* aBrowser)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsViewerApp* app = aBrowser->mApp;
|
1998-07-20 16:19:22 +00:00
|
|
|
gBrowsers.RemoveElement(aBrowser);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_RELEASE(aBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::CloseAllWindows()
|
|
|
|
{
|
|
|
|
while (0 != gBrowsers.Count()) {
|
|
|
|
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(0);
|
|
|
|
NS_ADDREF(bw);
|
|
|
|
bw->Close();
|
|
|
|
NS_RELEASE(bw);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
gBrowsers.Clear();
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleBrowserEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
1998-07-20 21:16:38 +00:00
|
|
|
nsBrowserWindow* bw =
|
|
|
|
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_WINDOW);
|
1998-09-15 00:16:12 +00:00
|
|
|
if (nsnull != bw) {
|
|
|
|
nsSizeEvent* sizeEvent;
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_SIZE:
|
|
|
|
sizeEvent = (nsSizeEvent*)aEvent;
|
|
|
|
bw->Layout(sizeEvent->windowSize->width,
|
1998-10-26 18:07:14 +00:00
|
|
|
sizeEvent->windowSize->height);
|
1998-09-15 00:16:12 +00:00
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_DESTROY:
|
|
|
|
{
|
1998-10-26 18:07:14 +00:00
|
|
|
nsViewerApp* app = bw->mApp;
|
|
|
|
result = nsEventStatus_eConsumeDoDefault;
|
|
|
|
bw->Close();
|
|
|
|
NS_RELEASE(bw);
|
|
|
|
|
1998-10-29 14:06:26 +00:00
|
|
|
#ifndef XP_MAC
|
1998-10-26 18:07:14 +00:00
|
|
|
// XXX Really shouldn't just exit, we should just notify somebody...
|
|
|
|
if (0 == nsBrowserWindow::gBrowsers.Count()) {
|
|
|
|
app->Exit();
|
|
|
|
}
|
1998-10-29 14:06:26 +00:00
|
|
|
#endif
|
1998-09-15 00:16:12 +00:00
|
|
|
}
|
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-09-15 00:16:12 +00:00
|
|
|
case NS_MENU_SELECTED:
|
1998-10-07 20:17:14 +00:00
|
|
|
result = bw->DispatchMenuItem(((nsMenuEvent*)aEvent)->mCommand);
|
1998-09-15 00:16:12 +00:00
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1998-09-15 00:16:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-08-10 18:20:20 +00:00
|
|
|
NS_RELEASE(bw);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleBackEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
1998-07-20 21:16:38 +00:00
|
|
|
nsBrowserWindow* bw =
|
|
|
|
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_BACK);
|
1998-09-15 00:16:12 +00:00
|
|
|
if (nsnull != bw) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
bw->Back();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(bw);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleForwardEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
1998-07-20 21:16:38 +00:00
|
|
|
nsBrowserWindow* bw =
|
|
|
|
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_FORWARD);
|
1998-09-15 00:16:12 +00:00
|
|
|
if (nsnull != bw) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
bw->Forward();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(bw);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleLocationEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
1998-07-20 21:16:38 +00:00
|
|
|
nsBrowserWindow* bw =
|
|
|
|
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_LOCATION);
|
1998-09-15 00:16:12 +00:00
|
|
|
if (nsnull != bw) {
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_KEY_UP:
|
|
|
|
if (NS_VK_RETURN == ((nsKeyEvent*)aEvent)->keyCode) {
|
1998-10-26 18:07:14 +00:00
|
|
|
nsAutoString text;
|
|
|
|
PRUint32 size;
|
|
|
|
bw->mLocation->GetText(text, 1000, size);
|
|
|
|
bw->GoTo(text);
|
1998-09-15 00:16:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_RELEASE(bw);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 00:16:12 +00:00
|
|
|
return result;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
1998-07-20 22:13:11 +00:00
|
|
|
nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
1999-01-23 07:10:37 +00:00
|
|
|
nsEventStatus result;
|
1998-07-20 22:45:35 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-01-23 07:10:37 +00:00
|
|
|
result = DispatchDebugMenu(aID);
|
1998-07-20 22:13:11 +00:00
|
|
|
if (nsEventStatus_eIgnore != result) {
|
|
|
|
return result;
|
|
|
|
}
|
1998-07-20 22:45:35 +00:00
|
|
|
#endif
|
1999-01-23 07:10:37 +00:00
|
|
|
result = DispatchStyleMenu(aID);
|
|
|
|
if (nsEventStatus_eIgnore != result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-07-20 22:13:11 +00:00
|
|
|
switch (aID) {
|
|
|
|
case VIEWER_EXIT:
|
|
|
|
mApp->Exit();
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
1998-09-04 00:47:15 +00:00
|
|
|
case VIEWER_WINDOW_OPEN:
|
|
|
|
mApp->OpenWindow();
|
|
|
|
break;
|
|
|
|
|
1998-07-21 16:45:21 +00:00
|
|
|
case VIEWER_FILE_OPEN:
|
|
|
|
DoFileOpen();
|
|
|
|
break;
|
1998-11-11 20:31:45 +00:00
|
|
|
|
|
|
|
case VIEW_SOURCE:
|
|
|
|
{
|
|
|
|
PRInt32 theIndex;
|
|
|
|
mWebShell->GetHistoryIndex(theIndex);
|
|
|
|
PRUnichar* theURL;
|
|
|
|
mWebShell->GetURL(theIndex,&theURL);
|
|
|
|
nsAutoString theString(theURL);
|
|
|
|
mApp->ViewSource(theString);
|
|
|
|
//XXX Find out how the string is allocated, and perhaps delete it...
|
|
|
|
}
|
|
|
|
break;
|
1998-07-27 18:17:07 +00:00
|
|
|
|
|
|
|
case VIEWER_EDIT_COPY:
|
|
|
|
DoCopy();
|
|
|
|
break;
|
1998-07-21 16:45:21 +00:00
|
|
|
|
1998-08-03 22:32:34 +00:00
|
|
|
case VIEWER_EDIT_SELECTALL:
|
|
|
|
DoSelectAll();
|
|
|
|
break;
|
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
case VIEWER_EDIT_FINDINPAGE:
|
|
|
|
DoFind();
|
|
|
|
break;
|
|
|
|
|
1998-07-20 22:13:11 +00:00
|
|
|
case VIEWER_DEMO0:
|
|
|
|
case VIEWER_DEMO1:
|
|
|
|
case VIEWER_DEMO2:
|
|
|
|
case VIEWER_DEMO3:
|
|
|
|
case VIEWER_DEMO4:
|
|
|
|
case VIEWER_DEMO5:
|
|
|
|
case VIEWER_DEMO6:
|
|
|
|
case VIEWER_DEMO7:
|
|
|
|
case VIEWER_DEMO8:
|
|
|
|
case VIEWER_DEMO9:
|
1998-10-26 18:07:14 +00:00
|
|
|
case VIEWER_DEMO10:
|
1999-02-03 17:16:11 +00:00
|
|
|
case VIEWER_DEMO11:
|
|
|
|
case VIEWER_DEMO12:
|
1998-07-20 22:13:11 +00:00
|
|
|
{
|
|
|
|
PRIntn ix = aID - VIEWER_DEMO0;
|
|
|
|
nsAutoString url(SAMPLES_BASE_URL);
|
|
|
|
url.Append("/test");
|
|
|
|
url.Append(ix, 10);
|
|
|
|
url.Append(".html");
|
1998-09-09 01:19:11 +00:00
|
|
|
mWebShell->LoadURL(url);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
1998-07-20 22:13:11 +00:00
|
|
|
break;
|
1998-08-07 04:45:03 +00:00
|
|
|
case JS_CONSOLE:
|
|
|
|
DoJSConsole();
|
|
|
|
break;
|
|
|
|
|
1998-09-22 00:57:54 +00:00
|
|
|
case VIEWER_PREFS:
|
|
|
|
DoPrefs();
|
|
|
|
break;
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
case EDITOR_MODE:
|
1998-08-14 01:51:00 +00:00
|
|
|
DoEditorMode(mWebShell);
|
1998-08-07 04:45:03 +00:00
|
|
|
break;
|
1998-10-15 23:23:04 +00:00
|
|
|
|
|
|
|
case VIEWER_ONE_COLUMN:
|
|
|
|
case VIEWER_TWO_COLUMN:
|
|
|
|
case VIEWER_THREE_COLUMN:
|
|
|
|
ShowPrintPreview(aID);
|
|
|
|
break;
|
1998-11-14 01:58:34 +00:00
|
|
|
|
|
|
|
case VIEWER_PRINT:
|
|
|
|
DoPrint();
|
|
|
|
break;
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
case VIEWER_PRINT_SETUP:
|
|
|
|
DoPrintSetup();
|
|
|
|
break;
|
|
|
|
|
1999-01-06 21:59:17 +00:00
|
|
|
case VIEWER_TABLE_INSPECTOR:
|
|
|
|
DoTableInspector();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_IMAGE_INSPECTOR:
|
|
|
|
DoImageInspector();
|
|
|
|
break;
|
|
|
|
|
1998-12-03 17:59:25 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_MAC)
|
1998-12-03 10:12:30 +00:00
|
|
|
case VIEWER_TREEVIEW:
|
|
|
|
// Instantiate a tree widget
|
|
|
|
DoTreeView();
|
|
|
|
break;
|
1999-01-05 22:59:02 +00:00
|
|
|
#endif
|
|
|
|
#if defined(XP_WIN) || defined(XP_MAC)
|
|
|
|
case VIEWER_TOOLBARDEMO:
|
|
|
|
// Instantiate a tree widget
|
|
|
|
DoToolbarDemo();
|
|
|
|
break;
|
1998-12-03 10:12:30 +00:00
|
|
|
#endif
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::Back()
|
|
|
|
{
|
1998-07-22 11:26:18 +00:00
|
|
|
mWebShell->Back();
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::Forward()
|
|
|
|
{
|
1998-07-22 11:26:18 +00:00
|
|
|
mWebShell->Forward();
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-11 20:31:45 +00:00
|
|
|
nsBrowserWindow::GoTo(const PRUnichar* aURL,const char* aCommand)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
1998-11-11 20:31:45 +00:00
|
|
|
mWebShell->LoadURL(aURL, aCommand, nsnull);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-07-21 16:45:21 +00:00
|
|
|
#define FILE_PROTOCOL "file://"
|
|
|
|
|
|
|
|
static PRBool GetFileNameFromFileSelector(nsIWidget* aParentWindow,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsString* aFileName)
|
1998-07-21 16:45:21 +00:00
|
|
|
{
|
|
|
|
PRBool selectedFileName = PR_FALSE;
|
|
|
|
nsIFileWidget *fileWidget;
|
|
|
|
nsString title("Open HTML");
|
1998-09-01 00:26:28 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kFileWidgetCID,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsnull,
|
|
|
|
kIFileWidgetIID,
|
|
|
|
(void**)&fileWidget);
|
1998-07-21 16:45:21 +00:00
|
|
|
if (NS_OK == rv) {
|
1999-01-07 02:06:44 +00:00
|
|
|
nsString titles[] = {"All Readable Files", "HTML Files",
|
|
|
|
"XML Files", "Image Files", "All Files"};
|
|
|
|
nsString filters[] = {"*.htm; *.html; *.xml; *.gif; *.jpg; *.jpeg; *.png",
|
|
|
|
"*.htm; *.html",
|
|
|
|
"*.xml",
|
|
|
|
"*.gif; *.jpg; *.jpeg; *.png",
|
|
|
|
"*.*"};
|
|
|
|
fileWidget->SetFilterList(5, titles, filters);
|
1998-07-21 16:45:21 +00:00
|
|
|
fileWidget->Create(aParentWindow,
|
1998-10-26 18:07:14 +00:00
|
|
|
title,
|
|
|
|
eMode_load,
|
|
|
|
nsnull,
|
|
|
|
nsnull);
|
1998-07-21 16:45:21 +00:00
|
|
|
|
|
|
|
PRUint32 result = fileWidget->Show();
|
|
|
|
if (result) {
|
|
|
|
fileWidget->GetFile(*aFileName);
|
|
|
|
selectedFileName = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(fileWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DoFileOpen()
|
|
|
|
{
|
|
|
|
nsAutoString fileName;
|
|
|
|
char szFile[1000];
|
|
|
|
if (GetFileNameFromFileSelector(mWindow, &fileName)) {
|
|
|
|
fileName.ToCString(szFile, sizeof(szFile));
|
|
|
|
PRInt32 len = strlen(szFile);
|
|
|
|
PRInt32 sum = len + sizeof(FILE_PROTOCOL);
|
|
|
|
char* lpszFileURL = new char[sum];
|
|
|
|
|
|
|
|
// Translate '\' to '/'
|
|
|
|
for (PRInt32 i = 0; i < len; i++) {
|
|
|
|
if (szFile[i] == '\\') {
|
1998-10-26 18:07:14 +00:00
|
|
|
szFile[i] = '/';
|
1998-07-21 16:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the file URL
|
|
|
|
PR_snprintf(lpszFileURL, sum, "%s%s", FILE_PROTOCOL, szFile);
|
|
|
|
|
|
|
|
// Ask the Web widget to load the file URL
|
1998-09-09 01:19:11 +00:00
|
|
|
mWebShell->LoadURL(nsString(lpszFileURL));
|
1998-11-04 06:37:28 +00:00
|
|
|
delete [] lpszFileURL;
|
1999-01-19 03:12:18 +00:00
|
|
|
Show();
|
1998-07-21 16:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
#define DIALOG_FONT "Helvetica"
|
|
|
|
#define DIALOG_FONT_SIZE 10
|
|
|
|
|
|
|
|
/**--------------------------------------------------------------------------------
|
|
|
|
* Main Handler
|
|
|
|
*--------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
//printf("HandleEvent aEvent->message %d\n", aEvent->message);
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
if (aEvent == nsnull || aEvent->widget == nsnull) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->message == 301 || aEvent->message == 302) {
|
|
|
|
int x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * data;
|
|
|
|
aEvent->widget->GetClientData(data);
|
|
|
|
|
|
|
|
if (data == nsnull) {
|
|
|
|
nsIWidget * parent = aEvent->widget->GetParent();
|
|
|
|
if (parent != nsnull) {
|
|
|
|
parent->GetClientData(data);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data != nsnull) {
|
|
|
|
nsBrowserWindow * browserWindow = (nsBrowserWindow *)data;
|
|
|
|
result = browserWindow->ProcessDialogEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
static void* GetItemsNativeData(nsISupports* aObject)
|
|
|
|
{
|
1998-10-26 18:07:14 +00:00
|
|
|
void* result = nsnull;
|
|
|
|
nsIWidget* widget;
|
1998-09-14 20:46:42 +00:00
|
|
|
if (NS_OK == aObject->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
|
|
|
result = widget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-11-02 19:11:43 +00:00
|
|
|
//---------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBrowserWindow::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
PRBool foundIt = PR_FALSE;
|
|
|
|
doc->FindNext(aSearchStr, aMatchCase, aSearchDown, aIsFound);
|
|
|
|
if (!aIsFound) {
|
|
|
|
// Display Dialog here
|
|
|
|
}
|
|
|
|
ForceRefresh();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBrowserWindow::ForceRefresh()
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
|
|
|
if (nsnull != vm) {
|
|
|
|
nsIView* root;
|
|
|
|
vm->GetRootView(root);
|
|
|
|
if (nsnull != root) {
|
|
|
|
vm->UpdateView(root, (nsIRegion*)nsnull, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
/**--------------------------------------------------------------------------------
|
|
|
|
* Main Handler
|
|
|
|
*--------------------------------------------------------------------------------
|
|
|
|
*/
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
//printf("aEvent->message %d\n", aEvent->message);
|
|
|
|
switch(aEvent->message) {
|
|
|
|
|
1998-10-26 18:07:14 +00:00
|
|
|
case NS_KEY_DOWN: {
|
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
|
|
|
if (NS_VK_RETURN == keyEvent->keyCode) {
|
|
|
|
PRBool matchCase = PR_FALSE;
|
|
|
|
mMatchCheckBtn->GetState(matchCase);
|
|
|
|
PRBool findDwn = PR_FALSE;
|
|
|
|
mDwnRadioBtn->GetState(findDwn);
|
|
|
|
nsString searchStr;
|
|
|
|
PRUint32 actualSize;
|
|
|
|
mTextField->GetText(searchStr, 255,actualSize);
|
1998-11-02 19:11:43 +00:00
|
|
|
PRBool foundIt;
|
|
|
|
FindNext(searchStr, matchCase, findDwn, foundIt);
|
1998-10-26 18:07:14 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP: {
|
|
|
|
nsIWidget* dialogWidget = nsnull;
|
|
|
|
if (NS_OK != mDialog->QueryInterface(kIWidgetIID,(void**)&dialogWidget))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mCancelBtn)) {
|
|
|
|
dialogWidget->Show(PR_FALSE);
|
|
|
|
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mFindBtn)) {
|
|
|
|
|
|
|
|
PRBool matchCase = PR_FALSE;
|
|
|
|
mMatchCheckBtn->GetState(matchCase);
|
|
|
|
PRBool findDwn = PR_FALSE;
|
|
|
|
mDwnRadioBtn->GetState(findDwn);
|
|
|
|
PRUint32 actualSize;
|
|
|
|
nsString searchStr;
|
|
|
|
mTextField->GetText(searchStr, 255,actualSize);
|
|
|
|
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
PRBool foundIt = PR_FALSE;
|
|
|
|
doc->FindNext(searchStr, matchCase, findDwn, foundIt);
|
|
|
|
if (!foundIt) {
|
|
|
|
// Display Dialog here
|
|
|
|
}
|
|
|
|
ForceRefresh();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mUpRadioBtn)) {
|
|
|
|
mUpRadioBtn->SetState(PR_TRUE);
|
|
|
|
mDwnRadioBtn->SetState(PR_FALSE);
|
|
|
|
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDwnRadioBtn)) {
|
|
|
|
mDwnRadioBtn->SetState(PR_TRUE);
|
|
|
|
mUpRadioBtn->SetState(PR_FALSE);
|
|
|
|
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mMatchCheckBtn)) {
|
|
|
|
PRBool state = PR_FALSE;
|
|
|
|
mMatchCheckBtn->GetState(state);
|
|
|
|
mMatchCheckBtn->SetState(!state);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NS_PAINT:
|
1998-08-28 16:14:37 +00:00
|
|
|
#ifndef XP_UNIX
|
1998-10-26 18:07:14 +00:00
|
|
|
// paint the background
|
|
|
|
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDialog)) {
|
|
|
|
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
|
|
|
|
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
|
|
|
|
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
1998-08-28 16:14:37 +00:00
|
|
|
#endif
|
1998-10-26 18:07:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = nsEventStatus_eIgnore;
|
1998-08-28 16:14:37 +00:00
|
|
|
}
|
|
|
|
//printf("result: %d = %d\n", result, PR_FALSE);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-12-03 10:12:30 +00:00
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleTreeWindowEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
if (NS_SIZE == aEvent->message)
|
|
|
|
{
|
|
|
|
nsIEnumerator* pEnumerator = aEvent->widget->GetChildren();
|
|
|
|
pEnumerator->First();
|
|
|
|
|
|
|
|
// HACK! Resize the tree view window.
|
|
|
|
nsISupports* pTree;
|
|
|
|
pEnumerator->CurrentItem(&pTree);
|
|
|
|
nsIWidget* widget;
|
|
|
|
|
|
|
|
if (NS_OK == pTree->QueryInterface(kIWidgetIID, (void**)&widget))
|
|
|
|
{
|
|
|
|
nsRect r;
|
1998-12-03 19:13:53 +00:00
|
|
|
aEvent->widget->GetClientBounds(r);
|
1998-12-03 10:12:30 +00:00
|
|
|
widget->Resize(0, 0, r.width, r.height, PR_TRUE);
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pEnumerator);
|
|
|
|
NS_IF_RELEASE(pTree);
|
|
|
|
}
|
1998-12-03 23:57:44 +00:00
|
|
|
#ifdef XP_MAC
|
1998-12-03 22:05:17 +00:00
|
|
|
else if ( aEvent->message == NS_DESTROY ) {
|
|
|
|
NS_IF_RELEASE(aEvent->widget);
|
|
|
|
result = nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
1998-12-03 23:57:44 +00:00
|
|
|
#endif
|
1998-12-03 22:05:17 +00:00
|
|
|
|
1998-12-03 10:12:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-12-08 05:10:35 +00:00
|
|
|
|
1999-01-05 22:59:02 +00:00
|
|
|
static nsEventStatus PR_CALLBACK
|
|
|
|
HandleToolbarDemoWindowEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
if (NS_SIZE == aEvent->message)
|
|
|
|
{
|
|
|
|
nsIEnumerator* pEnumerator = aEvent->widget->GetChildren();
|
|
|
|
pEnumerator->First();
|
|
|
|
|
|
|
|
// HACK! Resize the tree view window.
|
|
|
|
nsISupports* pTree;
|
|
|
|
pEnumerator->CurrentItem(&pTree);
|
|
|
|
nsIWidget* widget;
|
|
|
|
|
|
|
|
if (NS_OK == pTree->QueryInterface(kIWidgetIID, (void**)&widget))
|
|
|
|
{
|
|
|
|
nsRect r;
|
|
|
|
aEvent->widget->GetClientBounds(r);
|
|
|
|
widget->Resize(0, 0, r.width, r.height, PR_TRUE);
|
|
|
|
NS_IF_RELEASE(widget);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pEnumerator);
|
|
|
|
NS_IF_RELEASE(pTree);
|
|
|
|
}
|
|
|
|
#ifdef XP_MAC
|
|
|
|
else if ( aEvent->message == NS_DESTROY ) {
|
|
|
|
NS_IF_RELEASE(aEvent->widget);
|
|
|
|
result = nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1998-12-08 05:10:35 +00:00
|
|
|
// XXX This is a hack to get tree widget/RDF testing alive. It should
|
|
|
|
// most definitely go away ASAP. It creates the bookmark data source,
|
|
|
|
// attaches it to an RDF document, and sets the document's root
|
|
|
|
// resource to be the top-level bookmark node.
|
|
|
|
#include "nsRDFCID.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFContentModelBuilder.h"
|
1998-12-08 05:10:35 +00:00
|
|
|
#include "nsIRDFDocument.h"
|
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1998-12-08 05:10:35 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
rdf_CreateBookmarkDocument(nsIDocument*& result)
|
|
|
|
{
|
|
|
|
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
1999-01-12 19:41:06 +00:00
|
|
|
static NS_DEFINE_CID(kRDFDocumentCID, NS_RDFDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
1998-12-08 05:10:35 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIRDFDocument* doc = nsnull;
|
1999-01-12 19:41:06 +00:00
|
|
|
nsIRDFContentModelBuilder* builder = nsnull;
|
1999-01-05 03:53:15 +00:00
|
|
|
nsIRDFService* service = nsnull;
|
1999-01-14 10:55:08 +00:00
|
|
|
nsIURL* uri = nsnull;
|
1998-12-18 05:38:59 +00:00
|
|
|
nsIRDFResource* root = nsnull;
|
1998-12-08 05:10:35 +00:00
|
|
|
|
|
|
|
result = nsnull; // reasonable default
|
|
|
|
|
1999-01-05 03:53:15 +00:00
|
|
|
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
|
|
|
|
kIRDFServiceIID,
|
|
|
|
(nsISupports**) &service)))
|
1998-12-08 05:10:35 +00:00
|
|
|
goto done;
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFDocumentCID,
|
1998-12-08 05:10:35 +00:00
|
|
|
nsnull,
|
|
|
|
kIRDFDocumentIID,
|
|
|
|
(void**) &doc)))
|
|
|
|
goto done;
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFTreeBuilderCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFContentModelBuilderIID,
|
|
|
|
(void**) &builder)))
|
|
|
|
goto done;
|
|
|
|
|
1999-02-01 22:35:17 +00:00
|
|
|
if (NS_FAILED(rv = doc->SetContentModelBuilder(builder)))
|
1998-12-08 05:10:35 +00:00
|
|
|
goto done;
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
if (NS_FAILED(rv = NS_NewURL(&uri, "resource://res/rdf/LocalStore.rdf")))
|
1998-12-08 05:10:35 +00:00
|
|
|
goto done;
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
if (NS_FAILED(rv = doc->QueryInterface(kIDocumentIID, (void**) &result)))
|
1998-12-08 05:10:35 +00:00
|
|
|
goto done;
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
if (NS_FAILED(rv = result->StartDocumentLoad(uri, nsnull, nsnull, nsnull)))
|
1998-12-08 05:10:35 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
// implicit addref on "result" from the QI
|
|
|
|
|
|
|
|
done:
|
|
|
|
NS_IF_RELEASE(root);
|
1999-01-14 10:55:08 +00:00
|
|
|
NS_IF_RELEASE(uri);
|
1999-01-05 03:53:15 +00:00
|
|
|
if (service) {
|
|
|
|
nsServiceManager::ReleaseService(kRDFServiceCID, service);
|
|
|
|
service = nsnull;
|
1998-12-08 05:10:35 +00:00
|
|
|
}
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IF_RELEASE(builder);
|
1998-12-08 05:10:35 +00:00
|
|
|
NS_IF_RELEASE(doc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-03 10:12:30 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoTreeView()
|
|
|
|
{
|
|
|
|
// Create top level window
|
|
|
|
nsIWidget* pTreeWindow;
|
|
|
|
|
1998-12-08 05:10:35 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWindowIID,
|
|
|
|
(void**)&pTreeWindow);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
nsWidgetInitData initData;
|
|
|
|
initData.mBorderStyle = eBorderStyle_dialog;
|
1998-12-03 10:12:30 +00:00
|
|
|
nsRect r;
|
|
|
|
|
|
|
|
mWindow->GetClientBounds(r);
|
1998-12-03 19:13:53 +00:00
|
|
|
|
1998-12-08 05:10:35 +00:00
|
|
|
pTreeWindow->Create((nsIWidget*)NULL, r, HandleTreeWindowEvent,
|
|
|
|
nsnull, mAppShell, nsnull, &initData);
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-12-03 19:13:53 +00:00
|
|
|
pTreeWindow->SetTitle("Tree Widget Tester");
|
1998-12-03 10:12:30 +00:00
|
|
|
|
|
|
|
// Create and place a tree view.
|
1998-12-03 19:13:53 +00:00
|
|
|
pTreeWindow->GetClientBounds(r);
|
|
|
|
|
|
|
|
r = nsRect(0,0,r.width,r.height);
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-12-11 16:36:21 +00:00
|
|
|
rv = nsRepository::CreateInstance(kCTreeViewCID, nsnull, kIContentConnectorIID,
|
|
|
|
(void**)&mTreeView);
|
1998-12-03 10:12:30 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIWidget* widget;
|
|
|
|
|
|
|
|
if (NS_OK == mTreeView->QueryInterface(kIWidgetIID, (void**)&widget))
|
1998-12-08 05:10:35 +00:00
|
|
|
{
|
1998-12-03 10:12:30 +00:00
|
|
|
widget->Create(pTreeWindow, r, nsnull, nsnull);
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
NS_IF_RELEASE(widget);
|
1998-12-08 05:10:35 +00:00
|
|
|
}
|
1998-12-03 10:12:30 +00:00
|
|
|
|
|
|
|
pTreeWindow->Show(PR_TRUE);
|
1998-12-08 05:10:35 +00:00
|
|
|
|
|
|
|
nsIDocument* doc;
|
|
|
|
if (NS_SUCCEEDED(rv = rdf_CreateBookmarkDocument(doc))) {
|
|
|
|
nsIContent* root = doc->GetRootContent();
|
|
|
|
if (root) {
|
1998-12-10 08:29:14 +00:00
|
|
|
// XXX Dump the content model that the tree is going to be built
|
|
|
|
// on.
|
|
|
|
root->List();
|
|
|
|
|
1998-12-08 05:10:35 +00:00
|
|
|
// XXX do whatever here. Note that the RDF nsIContent currently
|
|
|
|
// doesn't refcount the document in which it lives, so you'll
|
|
|
|
// need to keep a pointer to *both* the document and the
|
|
|
|
// content.
|
1998-12-09 19:56:30 +00:00
|
|
|
mTreeView->SetContentRoot(root);
|
1998-12-08 05:10:35 +00:00
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
NS_RELEASE(doc); // i.e., unless you've refcounted "doc", root dies _now_
|
|
|
|
}
|
1998-12-03 10:12:30 +00:00
|
|
|
}
|
1998-08-28 16:14:37 +00:00
|
|
|
|
1999-01-05 22:59:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// DoToolbarDemo
|
|
|
|
//
|
|
|
|
// Creates a standalone window for testing the toolbar and toolbox widgets. This
|
|
|
|
// is a hack, and will leak the window.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DoToolbarDemo()
|
|
|
|
{
|
|
|
|
// Create top level window
|
|
|
|
nsCOMPtr<nsIWidget> pToolbarWindow;
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWindowIID,
|
|
|
|
getter_AddRefs(pToolbarWindow));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// hack to get toolbar window to stick around after this exits. I know this sucks.
|
|
|
|
nsIWidget* hack = pToolbarWindow;
|
|
|
|
NS_ADDREF(hack);
|
|
|
|
|
|
|
|
nsWidgetInitData initData;
|
|
|
|
initData.mBorderStyle = eBorderStyle_dialog;
|
|
|
|
nsRect r(0, 0, 400, 100);
|
|
|
|
|
|
|
|
pToolbarWindow->Create((nsIWidget*)NULL, r, HandleToolbarDemoWindowEvent,
|
|
|
|
nsnull, mAppShell, nsnull, &initData);
|
|
|
|
|
|
|
|
pToolbarWindow->SetTitle("Toolbar Widget Tester");
|
|
|
|
|
|
|
|
// Create and place a tree view.
|
|
|
|
pToolbarWindow->GetClientBounds(r);
|
|
|
|
rv = nsRepository::CreateInstance(kCToolboxCID, nsnull, kIContentConnectorIID,
|
|
|
|
(void**)&mToolbox);
|
|
|
|
if (NS_OK != rv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget(mToolbox);
|
|
|
|
if ( widget ) {
|
1999-01-08 01:43:32 +00:00
|
|
|
widget->Create((nsIWidget *)pToolbarWindow, r, nsnull, nsnull);
|
1999-01-05 22:59:02 +00:00
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
pToolbarWindow->Show(PR_TRUE);
|
|
|
|
|
|
|
|
#if NO_DOM_CONNECT_YET
|
|
|
|
nsIDocument* doc;
|
|
|
|
if (NS_SUCCEEDED(rv = rdf_CreateBookmarkDocument(doc))) {
|
|
|
|
nsIContent* root = doc->GetRootContent();
|
|
|
|
if (root) {
|
|
|
|
// XXX Dump the content model that the tree is going to be built
|
|
|
|
// on.
|
|
|
|
root->List();
|
|
|
|
|
|
|
|
// XXX do whatever here. Note that the RDF nsIContent currently
|
|
|
|
// doesn't refcount the document in which it lives, so you'll
|
|
|
|
// need to keep a pointer to *both* the document and the
|
|
|
|
// content.
|
|
|
|
mTreeView->SetContentRoot(root);
|
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
NS_RELEASE(doc); // i.e., unless you've refcounted "doc", root dies _now_
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // DoToolbarDemo
|
|
|
|
|
1998-08-28 16:14:37 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoFind()
|
|
|
|
{
|
1998-12-17 15:52:48 +00:00
|
|
|
if (mXPDialog) {
|
|
|
|
NS_RELEASE(mXPDialog);
|
|
|
|
//mXPDialog->SetVisible(PR_TRUE);
|
|
|
|
//return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString findHTML("resource:/res/samples/find.html");
|
|
|
|
//nsString findHTML("resource:/res/samples/find-table.html");
|
|
|
|
nsRect rect(0, 0, 510, 170);
|
|
|
|
//nsRect rect(0, 0, 470, 126);
|
|
|
|
nsString title("Find");
|
|
|
|
|
|
|
|
nsXPBaseWindow * dialog = nsnull;
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
|
|
|
|
kIXPBaseWindowIID,
|
|
|
|
(void**) &dialog);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
dialog->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, findHTML, title, rect, PRUint32(~0), PR_FALSE);
|
|
|
|
dialog->SetVisible(PR_TRUE);
|
|
|
|
if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**) &mXPDialog)) {
|
1998-09-14 20:46:42 +00:00
|
|
|
}
|
1998-09-01 21:08:32 +00:00
|
|
|
}
|
1998-12-17 15:52:48 +00:00
|
|
|
|
|
|
|
nsFindDialog * findDialog = new nsFindDialog(this);
|
|
|
|
if (nsnull != findDialog) {
|
|
|
|
dialog->AddWindowListener(findDialog);
|
1998-12-15 03:04:22 +00:00
|
|
|
}
|
1998-12-17 15:52:48 +00:00
|
|
|
//NS_IF_RELEASE(dialog);
|
1998-08-28 16:14:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-08-04 20:04:55 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoSelectAll()
|
|
|
|
{
|
|
|
|
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
doc->SelectAll();
|
|
|
|
ForceRefresh();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Note: operator new zeros our memory
|
|
|
|
nsBrowserWindow::nsBrowserWindow()
|
|
|
|
{
|
|
|
|
AddBrowser(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserWindow::~nsBrowserWindow()
|
|
|
|
{
|
1998-10-15 23:23:04 +00:00
|
|
|
NS_IF_RELEASE(mPrefs);
|
|
|
|
NS_IF_RELEASE(mAppShell);
|
1998-12-11 16:36:21 +00:00
|
|
|
NS_IF_RELEASE(mTreeView);
|
1999-01-06 21:59:17 +00:00
|
|
|
NS_IF_RELEASE(mTableInspectorDialog);
|
|
|
|
NS_IF_RELEASE(mImageInspectorDialog);
|
|
|
|
|
|
|
|
if (nsnull != mTableInspector) {
|
|
|
|
delete mTableInspector;
|
|
|
|
}
|
|
|
|
if (nsnull != mImageInspector) {
|
|
|
|
delete mImageInspector;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsBrowserWindow)
|
|
|
|
NS_IMPL_RELEASE(nsBrowserWindow)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBrowserWindow::QueryInterface(const nsIID& aIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
void** aInstancePtrResult)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
|
|
|
|
*aInstancePtrResult = NULL;
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
if (aIID.Equals(kIBrowserWindowIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIBrowserWindow*)this);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIStreamObserverIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStreamObserver*)this);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIWebShellContainerIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIWebShellContainer*)this);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
if (aIID.Equals(kINetSupportIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsINetSupport*)this);
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 00:26:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsISupports*)((nsIBrowserWindow*)this));
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
nsresult
|
|
|
|
nsBrowserWindow::Init(nsIAppShell* aAppShell,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsIPref* aPrefs,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRUint32 aChromeMask,
|
|
|
|
PRBool aAllowPlugins)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
mChromeMask = aChromeMask;
|
1998-08-19 21:00:51 +00:00
|
|
|
mAppShell = aAppShell;
|
1998-10-15 23:23:04 +00:00
|
|
|
NS_IF_ADDREF(mAppShell);
|
1998-08-19 21:00:51 +00:00
|
|
|
mPrefs = aPrefs;
|
1998-10-15 23:23:04 +00:00
|
|
|
NS_IF_ADDREF(mPrefs);
|
1998-11-18 05:31:03 +00:00
|
|
|
mAllowPlugins = aAllowPlugins;
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
// Create top level window
|
1998-10-29 14:06:26 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWindowIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
(void**)&mWindow);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-02 19:11:43 +00:00
|
|
|
nsWidgetInitData initData;
|
|
|
|
initData.mBorderStyle = eBorderStyle_dialog;
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
nsRect r(0, 0, aBounds.width, aBounds.height);
|
|
|
|
mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent,
|
1998-11-02 19:11:43 +00:00
|
|
|
nsnull, aAppShell, nsnull, &initData);
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
// Create web shell
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kWebShellCID, nsnull,
|
1998-10-26 18:07:14 +00:00
|
|
|
kIWebShellIID,
|
|
|
|
(void**)&mWebShell);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
r.x = r.y = 0;
|
1998-08-14 23:08:54 +00:00
|
|
|
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
|
1998-10-26 18:07:14 +00:00
|
|
|
r.x, r.y, r.width, r.height,
|
1998-11-04 21:46:00 +00:00
|
|
|
nsScrollPreference_kAuto, aAllowPlugins, PR_TRUE);
|
1998-07-20 16:19:22 +00:00
|
|
|
mWebShell->SetContainer((nsIWebShellContainer*) this);
|
1998-07-22 11:26:18 +00:00
|
|
|
mWebShell->SetObserver((nsIStreamObserver*)this);
|
1998-07-31 06:01:45 +00:00
|
|
|
mWebShell->SetPrefs(aPrefs);
|
1998-07-20 16:19:22 +00:00
|
|
|
mWebShell->Show();
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
if (NS_CHROME_MENU_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateMenuBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
1998-07-20 21:16:38 +00:00
|
|
|
r.x = r.y = 0;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
if (NS_CHROME_TOOL_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateToolBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
if (NS_CHROME_STATUS_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateStatusBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
|
1999-01-27 05:20:43 +00:00
|
|
|
// Give the embedding app a chance to do platforms-specific window setup
|
|
|
|
InitNativeWindow();
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
// Now lay it all out
|
1998-07-20 16:19:22 +00:00
|
|
|
Layout(r.width, r.height);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-15 23:23:04 +00:00
|
|
|
nsresult
|
|
|
|
nsBrowserWindow::Init(nsIAppShell* aAppShell,
|
1998-12-08 01:57:40 +00:00
|
|
|
nsIPref* aPrefs,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
PRUint32 aChromeMask,
|
|
|
|
PRBool aAllowPlugins,
|
|
|
|
nsIDocumentViewer* aDocumentViewer,
|
|
|
|
nsIPresContext* aPresContext)
|
1998-10-15 23:23:04 +00:00
|
|
|
{
|
|
|
|
mChromeMask = aChromeMask;
|
|
|
|
mAppShell = aAppShell;
|
1998-11-18 05:31:03 +00:00
|
|
|
NS_IF_ADDREF(mAppShell);
|
1998-10-15 23:23:04 +00:00
|
|
|
mPrefs = aPrefs;
|
1998-11-18 05:31:03 +00:00
|
|
|
NS_IF_ADDREF(mPrefs);
|
1998-10-15 23:23:04 +00:00
|
|
|
mAllowPlugins = aAllowPlugins;
|
|
|
|
|
|
|
|
// Create top level window
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
|
1998-12-08 01:57:40 +00:00
|
|
|
(void**)&mWindow);
|
1998-10-15 23:23:04 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsRect r(0, 0, aBounds.width, aBounds.height);
|
|
|
|
mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent,
|
1998-12-08 01:57:40 +00:00
|
|
|
nsnull, aAppShell);
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
1998-10-15 23:23:04 +00:00
|
|
|
|
|
|
|
// Create web shell
|
|
|
|
rv = nsRepository::CreateInstance(kWebShellCID, nsnull,
|
1998-12-08 01:57:40 +00:00
|
|
|
kIWebShellIID,
|
|
|
|
(void**)&mWebShell);
|
1998-10-15 23:23:04 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
r.x = r.y = 0;
|
|
|
|
nsRect ws = r;
|
|
|
|
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
|
1998-12-08 01:57:40 +00:00
|
|
|
r.x, r.y, r.width, r.height,
|
|
|
|
nsScrollPreference_kAuto, aAllowPlugins);
|
1998-10-15 23:23:04 +00:00
|
|
|
mWebShell->SetContainer((nsIWebShellContainer*) this);
|
|
|
|
mWebShell->SetObserver((nsIStreamObserver*)this);
|
|
|
|
mWebShell->SetPrefs(aPrefs);
|
|
|
|
|
|
|
|
if (NS_CHROME_MENU_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateMenuBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
1998-10-15 23:23:04 +00:00
|
|
|
r.x = r.y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_CHROME_TOOL_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateToolBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_CHROME_STATUS_BAR_ON & aChromeMask) {
|
|
|
|
rv = CreateStatusBar(r.width);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-27 05:20:43 +00:00
|
|
|
// Give the embedding app a chance to do platforms-specific window setup
|
|
|
|
InitNativeWindow();
|
|
|
|
|
1998-10-15 23:23:04 +00:00
|
|
|
// Now lay it all out
|
|
|
|
Layout(r.width, r.height);
|
|
|
|
|
|
|
|
// Create a document viewer and bind it to the webshell
|
|
|
|
nsIDocumentViewer* docv;
|
|
|
|
aDocumentViewer->CreateDocumentViewerUsing(aPresContext, docv);
|
|
|
|
mWebShell->Embed(docv, "duh", nsnull);
|
|
|
|
mWebShell->Show();
|
|
|
|
NS_RELEASE(docv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-24 16:03:11 +00:00
|
|
|
// XXX This sort of thing should be in a resource
|
|
|
|
#define TOOL_BAR_FONT "Helvetica"
|
1998-07-31 06:01:45 +00:00
|
|
|
#define TOOL_BAR_FONT_SIZE 12
|
1998-07-24 16:03:11 +00:00
|
|
|
#define STATUS_BAR_FONT "Helvetica"
|
1998-07-31 06:01:45 +00:00
|
|
|
#define STATUS_BAR_FONT_SIZE 10
|
1998-07-24 16:03:11 +00:00
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
nsresult
|
|
|
|
nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1998-07-24 16:03:11 +00:00
|
|
|
nsIDeviceContext* dc = mWindow->GetDeviceContext();
|
1998-08-27 05:05:03 +00:00
|
|
|
float t2d;
|
|
|
|
dc->GetTwipsToDevUnits(t2d);
|
1998-07-24 16:03:11 +00:00
|
|
|
nsFont font(TOOL_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
1998-10-26 18:07:14 +00:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0,
|
|
|
|
nscoord(t2d * NSIntPointsToTwips(TOOL_BAR_FONT_SIZE)));
|
1998-07-24 16:03:11 +00:00
|
|
|
NS_RELEASE(dc);
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
// Create and place back button
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID,
|
1998-12-08 01:57:40 +00:00
|
|
|
(void**)&mBack);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsRect r(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
nsIWidget* widget = nsnull;
|
|
|
|
|
|
|
|
NS_CreateButton(mWindow,mBack,r,HandleBackEvent,&font);
|
|
|
|
if (NS_OK == mBack->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
|
|
|
mBack->SetLabel("Back");
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
// Create and place forward button
|
|
|
|
r.SetRect(BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
(void**)&mForward);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
if (NS_OK == mForward->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
1998-10-09 19:06:19 +00:00
|
|
|
widget->Create(mWindow, r, HandleForwardEvent, NULL);
|
1998-09-14 20:46:42 +00:00
|
|
|
widget->SetFont(font);
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
mForward->SetLabel("Forward");
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
// Create and place location bar
|
|
|
|
r.SetRect(2*BUTTON_WIDTH, 0,
|
1998-10-26 18:07:14 +00:00
|
|
|
aWidth - 2*BUTTON_WIDTH - THROBBER_WIDTH,
|
|
|
|
BUTTON_HEIGHT);
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
(void**)&mLocation);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
NS_CreateTextWidget(mWindow,mLocation,r,HandleLocationEvent,&font);
|
|
|
|
if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
|
|
|
widget->SetForegroundColor(NS_RGB(0, 0, 0));
|
|
|
|
widget->SetBackgroundColor(NS_RGB(255, 255, 255));
|
|
|
|
PRUint32 size;
|
|
|
|
mLocation->SetText("",size);
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
// Create and place throbber
|
|
|
|
r.SetRect(aWidth - THROBBER_WIDTH, 0,
|
1998-10-26 18:07:14 +00:00
|
|
|
THROBBER_WIDTH, THROBBER_HEIGHT);
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kThrobberCID, nsnull, kIThrobberIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
(void**)&mThrobber);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-23 03:30:24 +00:00
|
|
|
nsString throbberURL(THROBBER_AT);
|
|
|
|
mThrobber->Init(mWindow, r, throbberURL, THROB_NUM);
|
1998-07-20 16:19:22 +00:00
|
|
|
mThrobber->Show();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBrowserWindow::CreateStatusBar(PRInt32 aWidth)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1998-07-24 16:03:11 +00:00
|
|
|
nsIDeviceContext* dc = mWindow->GetDeviceContext();
|
1998-08-27 05:05:03 +00:00
|
|
|
float t2d;
|
|
|
|
dc->GetTwipsToDevUnits(t2d);
|
1998-07-24 16:03:11 +00:00
|
|
|
nsFont font(STATUS_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
1998-10-26 18:07:14 +00:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0,
|
|
|
|
nscoord(t2d * NSIntPointsToTwips(STATUS_BAR_FONT_SIZE)));
|
1998-07-24 16:03:11 +00:00
|
|
|
NS_RELEASE(dc);
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
nsRect r(0, 0, aWidth, THROBBER_HEIGHT);
|
1998-09-01 00:26:28 +00:00
|
|
|
rv = nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
|
1998-10-26 18:07:14 +00:00
|
|
|
(void**)&mStatus);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
|
|
|
|
nsIWidget* widget = nsnull;
|
|
|
|
NS_CreateTextWidget(mWindow,mStatus,r,HandleLocationEvent,&font);
|
|
|
|
if (NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
|
|
|
widget->SetForegroundColor(NS_RGB(0, 0, 0));
|
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText("",size);
|
1999-01-16 00:29:07 +00:00
|
|
|
|
|
|
|
nsITextWidget* textWidget = nsnull;
|
|
|
|
if (NS_OK == mStatus->QueryInterface(kITextWidgetIID,(void**)&textWidget))
|
|
|
|
{
|
|
|
|
PRBool wasReadOnly;
|
|
|
|
textWidget->SetReadOnly(PR_TRUE, wasReadOnly);
|
|
|
|
NS_RELEASE(textWidget);
|
|
|
|
}
|
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
|
|
|
|
{
|
1998-09-01 22:49:16 +00:00
|
|
|
nscoord txtHeight;
|
|
|
|
nsILookAndFeel * lookAndFeel;
|
|
|
|
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight);
|
1998-09-12 19:30:09 +00:00
|
|
|
NS_RELEASE(lookAndFeel);
|
1998-09-01 22:49:16 +00:00
|
|
|
} else {
|
|
|
|
txtHeight = 24;
|
|
|
|
}
|
|
|
|
|
1998-09-15 21:31:58 +00:00
|
|
|
nsRect rr(0, 0, aWidth, aHeight);
|
1998-09-01 22:49:16 +00:00
|
|
|
|
1998-09-16 23:16:37 +00:00
|
|
|
// position location bar (it's stretchy)
|
1998-12-08 01:57:40 +00:00
|
|
|
if (NS_CHROME_TOOL_BAR_ON & mChromeMask) {
|
|
|
|
nsIWidget* locationWidget = nsnull;
|
|
|
|
if (mLocation &&
|
|
|
|
NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID,
|
|
|
|
(void**)&locationWidget))) {
|
1998-09-16 23:16:37 +00:00
|
|
|
if (mThrobber) {
|
1998-11-04 21:46:00 +00:00
|
|
|
locationWidget->Resize(2*BUTTON_WIDTH, 0,
|
1998-12-08 01:57:40 +00:00
|
|
|
aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH),
|
|
|
|
BUTTON_HEIGHT,
|
|
|
|
PR_TRUE);
|
1998-11-04 21:46:00 +00:00
|
|
|
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, 0);
|
1998-09-14 20:46:42 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-11-04 21:46:00 +00:00
|
|
|
locationWidget->Resize(2*BUTTON_WIDTH, 0,
|
1998-12-08 01:57:40 +00:00
|
|
|
aWidth - 2*BUTTON_WIDTH,
|
|
|
|
BUTTON_HEIGHT,
|
|
|
|
PR_TRUE);
|
1998-09-14 20:46:42 +00:00
|
|
|
}
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-09-16 23:16:37 +00:00
|
|
|
locationWidget->Show(PR_TRUE);
|
1998-12-08 01:57:40 +00:00
|
|
|
NS_RELEASE(locationWidget);
|
1998-09-16 23:16:37 +00:00
|
|
|
}
|
1998-12-08 01:57:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIWidget* w = nsnull;
|
|
|
|
if (mLocation &&
|
|
|
|
NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID, (void**)&w))) {
|
|
|
|
w->Show(PR_FALSE);
|
|
|
|
NS_RELEASE(w);
|
|
|
|
}
|
|
|
|
if (mBack &&
|
|
|
|
NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
|
|
|
|
w->Show(PR_FALSE);
|
|
|
|
NS_RELEASE(w);
|
|
|
|
}
|
|
|
|
if (mForward &&
|
|
|
|
NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
|
|
|
|
w->Show(PR_FALSE);
|
|
|
|
NS_RELEASE(w);
|
|
|
|
}
|
|
|
|
if (mThrobber) {
|
|
|
|
mThrobber->Hide();
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 21:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* statusWidget = nsnull;
|
1998-09-14 20:46:42 +00:00
|
|
|
|
1998-09-16 23:16:37 +00:00
|
|
|
if (mStatus && NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&statusWidget)) {
|
|
|
|
if (mChromeMask & NS_CHROME_STATUS_BAR_ON) {
|
|
|
|
statusWidget->Resize(0, aHeight - txtHeight,
|
1998-10-26 18:07:14 +00:00
|
|
|
aWidth, txtHeight,
|
|
|
|
PR_TRUE);
|
1998-09-16 23:16:37 +00:00
|
|
|
rr.height -= txtHeight;
|
|
|
|
statusWidget->Show(PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
statusWidget->Show(PR_FALSE);
|
1998-09-14 20:46:42 +00:00
|
|
|
}
|
1998-10-06 02:00:54 +00:00
|
|
|
NS_RELEASE(statusWidget);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-15 21:31:58 +00:00
|
|
|
|
|
|
|
// inset the web widget
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-12-08 01:57:40 +00:00
|
|
|
if (NS_CHROME_TOOL_BAR_ON & mChromeMask) {
|
|
|
|
rr.height -= BUTTON_HEIGHT;
|
|
|
|
rr.y += BUTTON_HEIGHT;
|
|
|
|
}
|
1998-12-03 10:12:30 +00:00
|
|
|
|
1998-09-15 21:31:58 +00:00
|
|
|
rr.x += WEBSHELL_LEFT_INSET;
|
|
|
|
rr.y += WEBSHELL_TOP_INSET;
|
|
|
|
rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET;
|
|
|
|
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET;
|
|
|
|
mWebShell->SetBounds(rr.x, rr.y, rr.width, rr.height);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::MoveTo(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mWindow->Move(aX, aY);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
|
|
|
|
// XXX We want to do this in one shot
|
|
|
|
mWindow->Resize(aWidth, aHeight, PR_FALSE);
|
|
|
|
Layout(aWidth, aHeight);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::GetBounds(nsRect& aBounds)
|
|
|
|
{
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(aBounds);
|
1998-07-21 00:48:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-01 22:23:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::GetWindowBounds(nsRect& aBounds)
|
|
|
|
{
|
|
|
|
mWindow->GetBounds(aBounds);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::Show()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mWindow->Show(PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::Hide()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mWindow->Show(PR_FALSE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-04 00:47:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::Close()
|
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
RemoveBrowser(this);
|
|
|
|
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
mWebShell->Destroy();
|
|
|
|
NS_RELEASE(mWebShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NS_IF_RELEASE(mWindow);
|
|
|
|
if (nsnull != mWindow) {
|
|
|
|
nsIWidget* w = mWindow;
|
|
|
|
NS_RELEASE(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mBack);
|
|
|
|
NS_IF_RELEASE(mForward);
|
|
|
|
NS_IF_RELEASE(mLocation);
|
|
|
|
NS_IF_RELEASE(mThrobber);
|
|
|
|
NS_IF_RELEASE(mStatus);
|
|
|
|
|
1998-09-04 00:47:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-09 01:19:11 +00:00
|
|
|
nsBrowserWindow::SetChrome(PRUint32 aChromeMask)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
mChromeMask = aChromeMask;
|
1998-09-15 21:31:58 +00:00
|
|
|
nsRect r;
|
1998-11-04 21:46:00 +00:00
|
|
|
mWindow->GetClientBounds(r);
|
1998-09-15 21:31:58 +00:00
|
|
|
Layout(r.width, r.height);
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::GetChrome(PRUint32& aChromeMaskResult)
|
|
|
|
{
|
|
|
|
aChromeMaskResult = mChromeMask;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::GetWebShell(nsIWebShell*& aResult)
|
|
|
|
{
|
|
|
|
aResult = mWebShell;
|
|
|
|
NS_IF_ADDREF(mWebShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::SetTitle(const PRUnichar* aTitle)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mWindow, "null window");
|
|
|
|
mTitle = aTitle;
|
1998-10-22 22:29:46 +00:00
|
|
|
nsAutoString newTitle(aTitle);
|
|
|
|
newTitle.Append(" - Raptor");
|
|
|
|
mWindow->SetTitle(newTitle.GetUnicode());
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::GetTitle(PRUnichar** aResult)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
1998-08-14 23:08:54 +00:00
|
|
|
*aResult = mTitle;
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 18:22:27 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::SetStatus(const PRUnichar* aStatus)
|
1998-07-31 18:22:27 +00:00
|
|
|
{
|
1998-08-07 04:45:03 +00:00
|
|
|
if (nsnull != mStatus) {
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(aStatus,size);
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1998-07-31 18:22:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::GetStatus(PRUnichar** aResult)
|
1998-07-31 18:22:27 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-12 00:22:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::SetProgress(PRInt32 aProgress, PRInt32 aProgressMax)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
if (mStatus) {
|
|
|
|
nsAutoString url("Connecting to ");
|
|
|
|
url.Append(aURL);
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(url,size);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-08-14 23:08:54 +00:00
|
|
|
nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
if (mThrobber) {
|
|
|
|
mThrobber->Start();
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mLocation->SetText(aURL,size);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-20 18:25:29 +00:00
|
|
|
nsBrowserWindow::ProgressLoadURL(nsIWebShell* aShell,
|
|
|
|
const PRUnichar* aURL,
|
|
|
|
PRInt32 aProgress,
|
|
|
|
PRInt32 aProgressMax)
|
1998-08-14 23:08:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-20 18:25:29 +00:00
|
|
|
nsBrowserWindow::EndLoadURL(nsIWebShell* aShell,
|
|
|
|
const PRUnichar* aURL,
|
|
|
|
PRInt32 aStatus)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
if (mThrobber) {
|
|
|
|
mThrobber->Stop();
|
|
|
|
}
|
1998-10-09 05:53:41 +00:00
|
|
|
if (nsnull != mStatus) {
|
|
|
|
nsAutoString msg(aURL);
|
|
|
|
PRUint32 size;
|
|
|
|
|
|
|
|
msg.Append(" done.");
|
|
|
|
|
|
|
|
mStatus->SetText(msg, size);
|
|
|
|
}
|
1998-11-20 18:25:29 +00:00
|
|
|
if (nsnull != mApp) {
|
|
|
|
mApp->EndLoadURL(aShell, aURL, aStatus);
|
|
|
|
}
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
1998-08-14 23:08:54 +00:00
|
|
|
}
|
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
|
1998-08-19 21:00:51 +00:00
|
|
|
NS_IMETHODIMP
|
1998-12-08 01:57:40 +00:00
|
|
|
nsBrowserWindow::NewWebShell(PRUint32 aChromeMask,
|
|
|
|
PRBool aVisible,
|
|
|
|
nsIWebShell*& aNewWebShell)
|
1998-08-19 21:00:51 +00:00
|
|
|
{
|
1998-09-15 00:16:12 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Create new window. By default, the refcnt will be 1 because of
|
|
|
|
// the registration of the browser window in gBrowsers.
|
|
|
|
nsNativeBrowserWindow* browser;
|
|
|
|
NS_NEWXPCOM(browser, nsNativeBrowserWindow);
|
1998-08-19 21:00:51 +00:00
|
|
|
|
|
|
|
if (nsnull != browser)
|
|
|
|
{
|
|
|
|
nsRect bounds;
|
|
|
|
GetBounds(bounds);
|
|
|
|
|
|
|
|
browser->SetApp(mApp);
|
1998-12-08 01:57:40 +00:00
|
|
|
|
|
|
|
// Assume no controls for now
|
|
|
|
rv = browser->Init(mAppShell, mPrefs, bounds, aChromeMask, mAllowPlugins);
|
1998-08-19 21:00:51 +00:00
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
1998-12-08 01:57:40 +00:00
|
|
|
// Default is to startup hidden
|
|
|
|
if (aVisible) {
|
|
|
|
browser->Show();
|
|
|
|
}
|
1998-08-19 21:00:51 +00:00
|
|
|
nsIWebShell *shell;
|
|
|
|
rv = browser->GetWebShell(shell);
|
|
|
|
aNewWebShell = shell;
|
|
|
|
}
|
|
|
|
else
|
1998-09-15 00:16:12 +00:00
|
|
|
{
|
|
|
|
browser->Close();
|
|
|
|
}
|
1998-08-19 21:00:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-18 00:35:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
|
|
|
|
{
|
|
|
|
PRInt32 i, n = gBrowsers.Count();
|
|
|
|
|
|
|
|
aResult = nsnull;
|
|
|
|
nsString aNameStr(aName);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(i);
|
|
|
|
nsIWebShell *ws;
|
|
|
|
|
|
|
|
if (NS_OK == bw->GetWebShell(ws)) {
|
|
|
|
PRUnichar *name;
|
|
|
|
if (NS_OK == ws->GetName(&name)) {
|
1998-10-26 18:07:14 +00:00
|
|
|
if (aNameStr.Equals(name)) {
|
|
|
|
aResult = ws;
|
|
|
|
NS_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-18 00:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_OK == ws->FindChildWithName(aName, aResult)) {
|
|
|
|
if (nsnull != aResult) {
|
1998-10-26 18:07:14 +00:00
|
|
|
return NS_OK;
|
1998-09-18 00:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-06 01:30:07 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::FocusAvailable(nsIWebShell* aFocusedWebShell)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// Stream observer implementation
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::OnProgress(nsIURL* aURL,
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUint32 aProgress,
|
|
|
|
PRUint32 aProgressMax)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
if (mStatus) {
|
1998-07-24 10:02:50 +00:00
|
|
|
nsAutoString url;
|
|
|
|
if (nsnull != aURL) {
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUnichar* str;
|
|
|
|
aURL->ToString(&str);
|
|
|
|
url = str;
|
|
|
|
delete str;
|
1998-07-24 10:02:50 +00:00
|
|
|
}
|
|
|
|
url.Append(": progress ");
|
|
|
|
url.Append(aProgress, 10);
|
|
|
|
if (0 != aProgressMax) {
|
|
|
|
url.Append(" (out of ");
|
|
|
|
url.Append(aProgressMax, 10);
|
|
|
|
url.Append(")");
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(url,size);
|
1998-07-24 10:02:50 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-16 05:40:20 +00:00
|
|
|
nsBrowserWindow::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
|
1998-07-24 10:02:50 +00:00
|
|
|
{
|
|
|
|
if (mStatus) {
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(aMsg,size);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::OnStartBinding(nsIURL* aURL, const char *aContentType)
|
|
|
|
{
|
|
|
|
if (mStatus) {
|
|
|
|
nsAutoString url;
|
|
|
|
if (nsnull != aURL) {
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUnichar* str;
|
|
|
|
aURL->ToString(&str);
|
|
|
|
url = str;
|
|
|
|
delete str;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
url.Append(": start");
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(url,size);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBrowserWindow::OnStopBinding(nsIURL* aURL,
|
1998-12-16 05:40:20 +00:00
|
|
|
nsresult status,
|
|
|
|
const PRUnichar* aMsg)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
if (mStatus) {
|
|
|
|
nsAutoString url;
|
|
|
|
if (nsnull != aURL) {
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUnichar* str;
|
|
|
|
aURL->ToString(&str);
|
|
|
|
url = str;
|
|
|
|
delete str;
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
url.Append(": stop");
|
1998-09-14 20:46:42 +00:00
|
|
|
PRUint32 size;
|
|
|
|
mStatus->SetText(url,size);
|
1998-07-20 16:19:22 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-22 00:26:23 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsBrowserWindow::Alert(const nsString &aText)
|
|
|
|
{
|
1998-11-03 08:07:24 +00:00
|
|
|
char* msg = nsnull;
|
|
|
|
|
|
|
|
msg = aText.ToNewCString();
|
|
|
|
if (nsnull != msg) {
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cBrowser Window Alert: %s\n", '\007', msg);
|
1998-11-03 08:07:24 +00:00
|
|
|
PR_Free(msg);
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsBrowserWindow::Confirm(const nsString &aText)
|
|
|
|
{
|
1998-11-03 08:07:24 +00:00
|
|
|
char* msg= nsnull;
|
|
|
|
|
|
|
|
msg = aText.ToNewCString();
|
|
|
|
if (nsnull != msg) {
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cBrowser Window Confirm: %s (y/n)? ", msg);
|
1998-11-03 08:07:24 +00:00
|
|
|
PR_Free(msg);
|
1998-11-18 04:35:47 +00:00
|
|
|
char c;
|
|
|
|
for (;;) {
|
|
|
|
c = getchar();
|
|
|
|
if (tolower(c) == 'y') {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (tolower(c) == 'n') {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-11-03 08:07:24 +00:00
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsBrowserWindow::Prompt(const nsString &aText,
|
1998-10-26 18:07:14 +00:00
|
|
|
const nsString &aDefault,
|
|
|
|
nsString &aResult)
|
1998-07-22 00:26:23 +00:00
|
|
|
{
|
1998-11-03 08:07:24 +00:00
|
|
|
char* msg = nsnull;
|
1998-07-22 00:26:23 +00:00
|
|
|
char buf[256];
|
1998-11-03 08:07:24 +00:00
|
|
|
|
|
|
|
msg = aText.ToNewCString();
|
|
|
|
if (nsnull != msg) {
|
|
|
|
printf("Browser Window: %s\n", msg);
|
|
|
|
PR_Free(msg);
|
|
|
|
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cPrompt: ", '\007');
|
1998-11-03 08:07:24 +00:00
|
|
|
scanf("%s", buf);
|
|
|
|
aResult = buf;
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
|
|
|
|
return (aResult.Length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsBrowserWindow::PromptUserAndPassword(const nsString &aText,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsString &aUser,
|
|
|
|
nsString &aPassword)
|
1998-07-22 00:26:23 +00:00
|
|
|
{
|
1998-11-03 08:07:24 +00:00
|
|
|
char* msg = nsnull;
|
1998-07-22 00:26:23 +00:00
|
|
|
char buf[256];
|
1998-11-03 08:07:24 +00:00
|
|
|
|
|
|
|
msg = aText.ToNewCString();
|
|
|
|
if (nsnull != msg) {
|
|
|
|
printf("Browser Window: %s\n", msg);
|
|
|
|
PR_Free(msg);
|
|
|
|
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cUser: ", '\007');
|
1998-11-03 08:07:24 +00:00
|
|
|
scanf("%s", buf);
|
|
|
|
aUser = buf;
|
|
|
|
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cPassword: ", '\007');
|
1998-11-03 08:07:24 +00:00
|
|
|
scanf("%s", buf);
|
|
|
|
aPassword = buf;
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
return (aUser.Length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsBrowserWindow::PromptPassword(const nsString &aText,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsString &aPassword)
|
1998-07-22 00:26:23 +00:00
|
|
|
{
|
1998-11-03 08:07:24 +00:00
|
|
|
char* msg = nsnull;
|
1998-07-22 00:26:23 +00:00
|
|
|
char buf[256];
|
1998-11-03 08:07:24 +00:00
|
|
|
|
|
|
|
msg = aText.ToNewCString();
|
|
|
|
if (nsnull != msg) {
|
|
|
|
printf("Browser Window: %s\n", msg);
|
1998-11-18 04:35:47 +00:00
|
|
|
printf("%cPassword: ", '\007');
|
1998-11-03 08:07:24 +00:00
|
|
|
scanf("%s", buf);
|
|
|
|
aPassword = buf;
|
|
|
|
}
|
1998-07-22 00:26:23 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// Toolbar support
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::StartThrobber()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::StopThrobber()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::LoadThrobberImages()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DestroyThrobberImages()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
nsIPresShell*
|
|
|
|
nsBrowserWindow::GetPresShell()
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
return GetPresShellFor(mWebShell);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
|
1998-08-21 18:28:48 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
void PlaceHTMLOnClipboard(PRUint32 aFormat, char* aData, int aLength)
|
|
|
|
{
|
|
|
|
HGLOBAL hGlobalMemory;
|
|
|
|
PSTR pGlobalMemory;
|
|
|
|
|
|
|
|
PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat);
|
|
|
|
PRUint32 cf_html = RegisterClipboardFormat(gsHTMLFormat);
|
|
|
|
|
|
|
|
char* preamble = "";
|
|
|
|
char* postamble = "";
|
|
|
|
|
|
|
|
if (aFormat == cf_aol || aFormat == CF_TEXT)
|
|
|
|
{
|
|
|
|
preamble = "<HTML>";
|
|
|
|
postamble = "</HTML>";
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 size = aLength + 1 + strlen(preamble) + strlen(postamble);
|
|
|
|
|
|
|
|
|
|
|
|
if (aLength)
|
|
|
|
{
|
|
|
|
// Copy text to Global Memory Area
|
|
|
|
hGlobalMemory = (HGLOBAL)GlobalAlloc(GHND, size);
|
|
|
|
if (hGlobalMemory != NULL)
|
|
|
|
{
|
|
|
|
pGlobalMemory = (PSTR) GlobalLock(hGlobalMemory);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// AOL requires HTML prefix/postamble
|
|
|
|
char* s = preamble;
|
|
|
|
PRInt32 len = strlen(s);
|
|
|
|
for (i=0; i < len; i++)
|
|
|
|
{
|
1998-10-26 18:07:14 +00:00
|
|
|
*pGlobalMemory++ = *s++;
|
1998-08-21 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = aData;
|
|
|
|
len = aLength;
|
|
|
|
for (i=0;i< len;i++) {
|
1998-10-26 18:07:14 +00:00
|
|
|
*pGlobalMemory++ = *s++;
|
1998-08-21 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s = postamble;
|
|
|
|
len = strlen(s);
|
|
|
|
for (i=0; i < len; i++)
|
|
|
|
{
|
1998-10-26 18:07:14 +00:00
|
|
|
*pGlobalMemory++ = *s++;
|
1998-08-21 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put data on Clipboard
|
|
|
|
GlobalUnlock(hGlobalMemory);
|
|
|
|
SetClipboardData(aFormat, hGlobalMemory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-07-31 16:53:45 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoCopy()
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
nsString buffer;
|
1999-01-21 21:51:21 +00:00
|
|
|
|
|
|
|
nsISelection* sel = nsnull;
|
|
|
|
shell->GetSelection(&sel);
|
|
|
|
|
|
|
|
if (sel != nsnull)
|
|
|
|
doc->CreateXIF(buffer,sel);
|
|
|
|
NS_IF_RELEASE(sel);
|
1998-07-31 16:53:45 +00:00
|
|
|
|
|
|
|
nsIParser* parser;
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
|
|
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
|
|
|
1998-09-01 00:26:28 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kCParserCID,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsnull,
|
|
|
|
kCParserIID,
|
|
|
|
(void **)&parser);
|
1998-07-31 16:53:45 +00:00
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
1998-10-26 18:07:14 +00:00
|
|
|
nsIHTMLContentSink* sink = nsnull;
|
|
|
|
|
|
|
|
rv = NS_New_HTML_ContentSinkStream(&sink,PR_FALSE,PR_FALSE);
|
|
|
|
|
1999-01-28 22:58:52 +00:00
|
|
|
// ifdef hell: ostrstream doesn't seem to work on mac (it's
|
|
|
|
// been deprecated too), but stringstream doesn't seem to
|
|
|
|
// work in VC 5, so for the moment we have ifdefs
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
stringstream data;
|
|
|
|
#else
|
1998-10-26 18:07:14 +00:00
|
|
|
ostrstream data;
|
1999-01-28 22:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
1998-10-26 18:07:14 +00:00
|
|
|
((nsHTMLContentSinkStream*)sink)->SetOutputStream(data);
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
parser->SetContentSink(sink);
|
|
|
|
|
|
|
|
nsIDTD* dtd = nsnull;
|
|
|
|
rv = NS_NewXIFDTD(&dtd);
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
parser->RegisterDTD(dtd);
|
1998-11-26 03:21:55 +00:00
|
|
|
//dtd->SetContentSink(sink);
|
|
|
|
//dtd->SetParser(parser);
|
1999-02-03 19:38:39 +00:00
|
|
|
parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE);
|
1998-10-26 18:07:14 +00:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(dtd);
|
|
|
|
NS_IF_RELEASE(sink);
|
1999-01-28 22:58:52 +00:00
|
|
|
#if defined(XP_MAC)
|
|
|
|
string theString = data.str();
|
|
|
|
PRInt32 len = theString.length();
|
|
|
|
const char* str = theString.data();
|
|
|
|
#else
|
|
|
|
PRInt32 len = data.pcount();
|
1998-10-26 18:07:14 +00:00
|
|
|
char* str = (char*)data.str();
|
1999-01-28 22:58:52 +00:00
|
|
|
#endif
|
1998-07-31 16:53:45 +00:00
|
|
|
|
|
|
|
#if defined(WIN32)
|
1998-10-26 18:07:14 +00:00
|
|
|
PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat);
|
|
|
|
PRUint32 cf_html = RegisterClipboardFormat(gsHTMLFormat);
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
OpenClipboard(NULL);
|
|
|
|
EmptyClipboard();
|
|
|
|
|
|
|
|
PlaceHTMLOnClipboard(cf_aol,str,len);
|
|
|
|
PlaceHTMLOnClipboard(cf_html,str,len);
|
|
|
|
PlaceHTMLOnClipboard(CF_TEXT,str,len);
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
// in ostrstreams if you cal the str() function
|
|
|
|
// then you are responsible for deleting the string
|
1999-01-28 22:58:52 +00:00
|
|
|
if (str) delete str;
|
1998-07-31 16:53:45 +00:00
|
|
|
#endif
|
1998-10-06 02:54:00 +00:00
|
|
|
|
|
|
|
#if defined(XP_MAC)
|
1999-01-28 22:58:52 +00:00
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
char * ptr = NS_CONST_CAST(char*,str);
|
|
|
|
for (PRInt32 plen = len; plen > 0; plen --, ptr ++)
|
|
|
|
if (*ptr == '\n')
|
|
|
|
*ptr = '\r';
|
|
|
|
|
|
|
|
OSErr err = ::ZeroScrap();
|
|
|
|
err = ::PutScrap(len, 'TEXT', str);
|
|
|
|
::TEFromScrap();
|
1998-10-26 18:07:14 +00:00
|
|
|
}
|
1998-10-06 02:54:00 +00:00
|
|
|
#endif
|
|
|
|
|
1998-10-26 18:07:14 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(parser);
|
1998-07-31 16:53:45 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-10-15 23:23:04 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
|
|
|
|
{
|
|
|
|
nsIContentViewer* cv = nsnull;
|
|
|
|
if (nsnull != mWebShell) {
|
1999-01-14 06:49:59 +00:00
|
|
|
if ((NS_OK == mWebShell->GetContentViewer(&cv)) && (nsnull != cv)) {
|
1998-10-15 23:23:04 +00:00
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
if (NS_OK == cv->QueryInterface(kIDocumentViewerIID, (void**)&docv)) {
|
1998-11-13 05:53:47 +00:00
|
|
|
nsIPresContext* printContext;
|
|
|
|
if (NS_OK == NS_NewPrintPreviewContext(&printContext)) {
|
|
|
|
// Prepare new printContext for print-preview
|
|
|
|
nsIDeviceContext* dc;
|
|
|
|
nsIPresContext* presContext;
|
|
|
|
docv->GetPresContext(presContext);
|
|
|
|
dc = presContext->GetDeviceContext();
|
|
|
|
printContext->Init(dc, mPrefs);
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
NS_RELEASE(dc);
|
|
|
|
|
|
|
|
// Make a window using that content viewer
|
|
|
|
// XXX Some piece of code needs to properly hold the reference to this
|
|
|
|
// browser window. For the time being the reference is released by the
|
|
|
|
// browser event handling code during processing of the NS_DESTROY event...
|
|
|
|
nsBrowserWindow* bw = new nsNativeBrowserWindow;
|
|
|
|
bw->SetApp(mApp);
|
|
|
|
bw->Init(mAppShell, mPrefs, nsRect(0, 0, 600, 400),
|
|
|
|
NS_CHROME_MENU_BAR_ON, PR_TRUE, docv, printContext);
|
|
|
|
bw->Show();
|
|
|
|
|
|
|
|
NS_RELEASE(printContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docv);
|
1998-10-15 23:23:04 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-14 01:58:34 +00:00
|
|
|
void nsBrowserWindow::DoPrint(void)
|
|
|
|
{
|
|
|
|
nsIContentViewer *viewer = nsnull;
|
|
|
|
|
1999-01-14 06:49:59 +00:00
|
|
|
mWebShell->GetContentViewer(&viewer);
|
1998-11-14 01:58:34 +00:00
|
|
|
|
|
|
|
if (nsnull != viewer)
|
|
|
|
{
|
|
|
|
viewer->Print();
|
|
|
|
NS_RELEASE(viewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-17 15:52:48 +00:00
|
|
|
//---------------------------------------------------------------
|
|
|
|
void nsBrowserWindow::DoPrintSetup()
|
|
|
|
{
|
|
|
|
if (mXPDialog) {
|
|
|
|
NS_RELEASE(mXPDialog);
|
|
|
|
//mXPDialog->SetVisible(PR_TRUE);
|
|
|
|
//return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString printHTML("resource:/res/samples/printsetup.html");
|
|
|
|
nsRect rect(0, 0, 375, 510);
|
|
|
|
nsString title("Print Setup");
|
|
|
|
|
|
|
|
nsXPBaseWindow * dialog = nsnull;
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
|
|
|
|
kIXPBaseWindowIID,
|
|
|
|
(void**) &dialog);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
dialog->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, printHTML, title, rect, PRUint32(~0), PR_FALSE);
|
|
|
|
dialog->SetVisible(PR_TRUE);
|
|
|
|
if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**) &mXPDialog)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrintSetupInfo.mPortrait = PR_TRUE;
|
|
|
|
mPrintSetupInfo.mBevelLines = PR_TRUE;
|
|
|
|
mPrintSetupInfo.mBlackText = PR_FALSE;
|
|
|
|
mPrintSetupInfo.mBlackLines = PR_FALSE;
|
|
|
|
mPrintSetupInfo.mLastPageFirst = PR_FALSE;
|
|
|
|
mPrintSetupInfo.mPrintBackgrounds = PR_FALSE;
|
|
|
|
mPrintSetupInfo.mTopMargin = 0.50;
|
|
|
|
mPrintSetupInfo.mBottomMargin = 0.50;
|
|
|
|
mPrintSetupInfo.mLeftMargin = 0.50;
|
|
|
|
mPrintSetupInfo.mRightMargin = 0.50;
|
|
|
|
|
|
|
|
mPrintSetupInfo.mDocTitle = PR_TRUE;
|
|
|
|
mPrintSetupInfo.mDocLocation = PR_TRUE;
|
|
|
|
|
|
|
|
mPrintSetupInfo.mHeaderText = "Header Text";
|
|
|
|
mPrintSetupInfo.mFooterText = "Footer Text";
|
|
|
|
|
|
|
|
mPrintSetupInfo.mPageNum = PR_TRUE;
|
|
|
|
mPrintSetupInfo.mPageTotal = PR_TRUE;
|
|
|
|
mPrintSetupInfo.mDatePrinted = PR_TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
nsPrintSetupDialog * printSetupDialog = new nsPrintSetupDialog(this);
|
|
|
|
if (nsnull != printSetupDialog) {
|
|
|
|
dialog->AddWindowListener(printSetupDialog);
|
|
|
|
}
|
|
|
|
printSetupDialog->SetSetupInfo(mPrintSetupInfo);
|
|
|
|
//NS_IF_RELEASE(dialog);
|
|
|
|
|
|
|
|
}
|
1999-01-06 21:59:17 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
nsIDOMDocument* nsBrowserWindow::GetDOMDocument(nsIWebShell *aWebShell)
|
|
|
|
{
|
|
|
|
nsIDOMDocument* domDoc = nsnull;
|
|
|
|
if (nsnull != aWebShell) {
|
|
|
|
nsIContentViewer* mCViewer;
|
1999-01-14 06:49:59 +00:00
|
|
|
aWebShell->GetContentViewer(&mCViewer);
|
1999-01-06 21:59:17 +00:00
|
|
|
if (nsnull != mCViewer) {
|
|
|
|
nsIDocumentViewer* mDViewer;
|
|
|
|
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer)) {
|
|
|
|
nsIDocument* mDoc;
|
|
|
|
mDViewer->GetDocument(mDoc);
|
|
|
|
if (nsnull != mDoc) {
|
|
|
|
if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &domDoc)) {
|
|
|
|
}
|
|
|
|
NS_RELEASE(mDoc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(mDViewer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(mCViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return domDoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
void nsBrowserWindow::DoTableInspector()
|
|
|
|
{
|
|
|
|
if (mTableInspectorDialog) {
|
|
|
|
mTableInspectorDialog->SetVisible(PR_TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIDOMDocument* domDoc = GetDOMDocument(mWebShell);
|
|
|
|
|
|
|
|
if (nsnull != domDoc) {
|
|
|
|
nsString printHTML("resource:/res/samples/printsetup.html");
|
|
|
|
nsRect rect(0, 0, 375, 510);
|
|
|
|
nsString title("Table Inspector");
|
|
|
|
|
|
|
|
nsXPBaseWindow * xpWin = nsnull;
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
|
|
|
|
kIXPBaseWindowIID,
|
|
|
|
(void**) &xpWin);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
xpWin->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, printHTML, title, rect, PRUint32(~0), PR_FALSE);
|
|
|
|
xpWin->SetVisible(PR_TRUE);
|
|
|
|
if (NS_OK == xpWin->QueryInterface(kIXPBaseWindowIID, (void**) &mTableInspectorDialog)) {
|
|
|
|
mTableInspector = new nsTableInspectorDialog(this, domDoc); // ref counts domDoc
|
|
|
|
if (nsnull != mTableInspector) {
|
|
|
|
xpWin->AddWindowListener(mTableInspector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(xpWin);
|
|
|
|
}
|
|
|
|
NS_RELEASE(domDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void nsBrowserWindow::DoImageInspector()
|
|
|
|
{
|
|
|
|
if (mImageInspectorDialog) {
|
|
|
|
mImageInspectorDialog->SetVisible(PR_TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMDocument* domDoc = GetDOMDocument(mWebShell);
|
|
|
|
|
|
|
|
if (nsnull != domDoc) {
|
|
|
|
nsString printHTML("resource:/res/samples/image_props.html");
|
|
|
|
nsRect rect(0, 0, 485, 124);
|
|
|
|
nsString title("Image Inspector");
|
|
|
|
|
|
|
|
nsXPBaseWindow * xpWin = nsnull;
|
|
|
|
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull, kIXPBaseWindowIID, (void**) &xpWin);
|
|
|
|
if (rv == NS_OK) {
|
|
|
|
xpWin->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, printHTML, title, rect, PRUint32(~0), PR_FALSE);
|
|
|
|
xpWin->SetVisible(PR_TRUE);
|
|
|
|
if (NS_OK == xpWin->QueryInterface(kIXPBaseWindowIID, (void**) &mImageInspectorDialog)) {
|
|
|
|
mImageInspector = new nsImageInspectorDialog(this, domDoc); // ref counts domDoc
|
|
|
|
if (nsnull != mImageInspector) {
|
|
|
|
xpWin->AddWindowListener(mImageInspector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(xpWin);
|
|
|
|
}
|
|
|
|
NS_RELEASE(domDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-10-15 23:23:04 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoJSConsole()
|
|
|
|
{
|
|
|
|
mApp->CreateJSConsole(this);
|
|
|
|
}
|
|
|
|
|
1998-09-22 00:57:54 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoPrefs()
|
|
|
|
{
|
|
|
|
mApp->DoPrefs(this);
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
void
|
1998-08-14 01:51:00 +00:00
|
|
|
nsBrowserWindow::DoEditorMode(nsIWebShell *aWebShell)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
1998-08-14 01:51:00 +00:00
|
|
|
PRInt32 i, n;
|
|
|
|
if (nsnull != aWebShell) {
|
|
|
|
nsIContentViewer* mCViewer;
|
1999-01-14 06:49:59 +00:00
|
|
|
aWebShell->GetContentViewer(&mCViewer);
|
1998-08-14 01:51:00 +00:00
|
|
|
if (nsnull != mCViewer) {
|
|
|
|
nsIDocumentViewer* mDViewer;
|
1999-01-14 18:52:16 +00:00
|
|
|
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer))
|
|
|
|
{
|
|
|
|
nsIDocument* mDoc;
|
|
|
|
mDViewer->GetDocument(mDoc);
|
|
|
|
if (nsnull != mDoc) {
|
|
|
|
nsIDOMDocument* mDOMDoc;
|
|
|
|
if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &mDOMDoc))
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShellFor(aWebShell);
|
|
|
|
NS_InitEditorMode(mDOMDoc, shell);
|
|
|
|
NS_RELEASE(mDOMDoc);
|
|
|
|
NS_IF_RELEASE(shell);
|
|
|
|
}
|
|
|
|
NS_RELEASE(mDoc);
|
|
|
|
}
|
|
|
|
NS_RELEASE(mDViewer);
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1998-08-14 01:51:00 +00:00
|
|
|
NS_RELEASE(mCViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
aWebShell->GetChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIWebShell* mChild;
|
|
|
|
aWebShell->ChildAt(i, mChild);
|
|
|
|
DoEditorMode(mChild);
|
|
|
|
NS_RELEASE(mChild);
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-31 16:53:45 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
|
|
|
|
|
1998-11-11 22:22:18 +00:00
|
|
|
static void DumpAWebShell(nsIWebShell* aShell, FILE* out, PRInt32 aIndent)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
PRUnichar *name;
|
|
|
|
nsAutoString str;
|
|
|
|
nsIWebShell* parent;
|
|
|
|
PRInt32 i, n;
|
|
|
|
|
|
|
|
for (i = aIndent; --i >= 0; ) fprintf(out, " ");
|
|
|
|
|
|
|
|
fprintf(out, "%p '", aShell);
|
|
|
|
aShell->GetName(&name);
|
|
|
|
aShell->GetParent(parent);
|
|
|
|
str = name;
|
|
|
|
fputs(str, out);
|
|
|
|
fprintf(out, "' parent=%p <\n", parent);
|
|
|
|
NS_IF_RELEASE(parent);
|
|
|
|
|
|
|
|
aIndent++;
|
|
|
|
aShell->GetChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIWebShell* child;
|
|
|
|
aShell->ChildAt(i, child);
|
|
|
|
if (nsnull != child) {
|
|
|
|
DumpAWebShell(child, out, aIndent);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-11 22:22:18 +00:00
|
|
|
aIndent--;
|
|
|
|
for (i = aIndent; --i >= 0; ) fprintf(out, " ");
|
|
|
|
fputs(">\n", out);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-11 22:22:18 +00:00
|
|
|
nsBrowserWindow::DumpWebShells(FILE* out)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
DumpAWebShell(mWebShell, out, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DumpMultipleWebShells(nsBrowserWindow& aBrowserWindow, nsIWebShell* aWebShell, FILE* aOut)
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
if (aWebShell) {
|
|
|
|
aWebShell->GetChildCount(count);
|
|
|
|
if (count > 0) {
|
|
|
|
fprintf(aOut, "webshells= \n");
|
|
|
|
aBrowserWindow.DumpWebShells(aOut);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-11 22:22:18 +00:00
|
|
|
DumpContentRecurse(nsIWebShell* aWebShell, FILE* out)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-07-27 05:59:37 +00:00
|
|
|
if (nsnull != aWebShell) {
|
1998-11-11 22:22:18 +00:00
|
|
|
fprintf(out, "webshell=%p \n", aWebShell);
|
|
|
|
nsIPresShell* shell = GetPresShellFor(aWebShell);
|
1998-07-27 05:59:37 +00:00
|
|
|
if (nsnull != shell) {
|
1998-11-11 22:22:18 +00:00
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
nsIContent* root = doc->GetRootContent();
|
|
|
|
if (nsnull != root) {
|
|
|
|
root->List(out);
|
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
NS_RELEASE(doc);
|
1998-07-27 05:59:37 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("null pres shell\n", out);
|
|
|
|
}
|
1998-11-11 22:22:18 +00:00
|
|
|
// dump the frames of the sub documents
|
1998-07-27 05:59:37 +00:00
|
|
|
PRInt32 i, n;
|
|
|
|
aWebShell->GetChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIWebShell* child;
|
|
|
|
aWebShell->ChildAt(i, child);
|
|
|
|
if (nsnull != child) {
|
1998-11-11 22:22:18 +00:00
|
|
|
DumpContentRecurse(child, out);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 05:59:37 +00:00
|
|
|
void
|
1998-11-11 22:22:18 +00:00
|
|
|
nsBrowserWindow::DumpContent(FILE* out)
|
1998-07-27 05:59:37 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
DumpContentRecurse(mWebShell, out);
|
|
|
|
DumpMultipleWebShells(*this, mWebShell, out);
|
1998-07-27 05:59:37 +00:00
|
|
|
}
|
|
|
|
|
1998-11-11 22:22:18 +00:00
|
|
|
void
|
|
|
|
DumpFramesRecurse(nsIWebShell* aWebShell, FILE* out, nsString *aFilterName)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
if (nsnull != aWebShell) {
|
|
|
|
fprintf(out, "webshell=%p \n", aWebShell);
|
|
|
|
nsIPresShell* shell = GetPresShellFor(aWebShell);
|
|
|
|
if (nsnull != shell) {
|
1998-12-29 04:45:18 +00:00
|
|
|
nsIFrame* root;
|
|
|
|
shell->GetRootFrame(root);
|
1998-11-11 22:22:18 +00:00
|
|
|
if (nsnull != root) {
|
1999-01-15 23:51:00 +00:00
|
|
|
root->List(out, 0);
|
1998-11-11 22:22:18 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("null pres shell\n", out);
|
|
|
|
}
|
|
|
|
// dump the frames of the sub documents
|
|
|
|
PRInt32 i, n;
|
|
|
|
aWebShell->GetChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIWebShell* child;
|
|
|
|
aWebShell->ChildAt(i, child);
|
|
|
|
if (nsnull != child) {
|
|
|
|
DumpFramesRecurse(child, out, aFilterName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-20 21:16:38 +00:00
|
|
|
|
1998-11-11 22:22:18 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DumpFrames(FILE* out, nsString *aFilterName)
|
|
|
|
{
|
|
|
|
DumpFramesRecurse(mWebShell, out, aFilterName);
|
|
|
|
DumpMultipleWebShells(*this, mWebShell, out);
|
|
|
|
}
|
1998-07-20 21:16:38 +00:00
|
|
|
|
1998-11-11 22:22:18 +00:00
|
|
|
void
|
|
|
|
DumpViewsRecurse(nsIWebShell* aWebShell, FILE* out)
|
|
|
|
{
|
|
|
|
if (nsnull != aWebShell) {
|
|
|
|
fprintf(out, "webshell=%p \n", aWebShell);
|
|
|
|
nsIPresShell* shell = GetPresShellFor(aWebShell);
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIViewManager* vm = shell->GetViewManager();
|
|
|
|
if (nsnull != vm) {
|
|
|
|
nsIView* root;
|
|
|
|
vm->GetRootView(root);
|
|
|
|
if (nsnull != root) {
|
|
|
|
root->List(out);
|
|
|
|
}
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("null pres shell\n", out);
|
|
|
|
}
|
|
|
|
// dump the views of the sub documents
|
|
|
|
PRInt32 i, n;
|
|
|
|
aWebShell->GetChildCount(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIWebShell* child;
|
|
|
|
aWebShell->ChildAt(i, child);
|
|
|
|
if (nsnull != child) {
|
|
|
|
DumpViewsRecurse(child, out);
|
|
|
|
}
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-11-11 22:22:18 +00:00
|
|
|
nsBrowserWindow::DumpViews(FILE* out)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
1998-11-11 22:22:18 +00:00
|
|
|
DumpViewsRecurse(mWebShell, out);
|
|
|
|
DumpMultipleWebShells(*this, mWebShell, out);
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DumpStyleSheets(FILE* out)
|
|
|
|
{
|
1998-07-21 00:48:35 +00:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
1998-07-20 21:16:38 +00:00
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIStyleSet* styleSet = shell->GetStyleSet();
|
|
|
|
if (nsnull == styleSet) {
|
|
|
|
fputs("null style set\n", out);
|
|
|
|
} else {
|
|
|
|
styleSet->List(out);
|
|
|
|
NS_RELEASE(styleSet);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("null pres shell\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DumpStyleContexts(FILE* out)
|
|
|
|
{
|
1998-07-21 00:48:35 +00:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
1998-07-20 21:16:38 +00:00
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIStyleSet* styleSet = shell->GetStyleSet();
|
|
|
|
if (nsnull == styleSet) {
|
|
|
|
fputs("null style set\n", out);
|
|
|
|
} else {
|
1998-12-29 04:45:18 +00:00
|
|
|
nsIFrame* root;
|
|
|
|
shell->GetRootFrame(root);
|
1998-07-20 21:16:38 +00:00
|
|
|
if (nsnull == root) {
|
1998-11-03 20:33:43 +00:00
|
|
|
fputs("null root frame\n", out);
|
|
|
|
} else {
|
|
|
|
nsIStyleContext* rootContext;
|
|
|
|
root->GetStyleContext(rootContext);
|
|
|
|
if (nsnull != rootContext) {
|
|
|
|
styleSet->ListContexts(rootContext, out);
|
|
|
|
NS_RELEASE(rootContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("null root context", out);
|
|
|
|
}
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(styleSet);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
} else {
|
|
|
|
fputs("null pres shell\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::ToggleFrameBorders()
|
|
|
|
{
|
|
|
|
PRBool showing = nsIFrame::GetShowFrameBorders();
|
|
|
|
nsIFrame::ShowFrameBorders(!showing);
|
|
|
|
ForceRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::ShowContentSize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::ShowFrameSize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::ShowStyleSize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-07-27 18:17:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PRBool GetSaveFileNameFromFileSelector(nsIWidget* aParentWindow,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsString& aFileName)
|
1998-07-27 18:17:07 +00:00
|
|
|
{
|
|
|
|
PRInt32 offset = aFileName.RFind('/');
|
|
|
|
if (offset != -1)
|
|
|
|
aFileName.Cut(0,offset+1);
|
|
|
|
|
|
|
|
PRBool selectedFileName = PR_FALSE;
|
|
|
|
nsIFileWidget *fileWidget;
|
|
|
|
nsString title("Save HTML");
|
1998-09-01 00:26:28 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kFileWidgetCID,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsnull,
|
|
|
|
kIFileWidgetIID,
|
|
|
|
(void**)&fileWidget);
|
1998-07-27 18:17:07 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsString titles[] = {"html","txt"};
|
|
|
|
nsString filters[] = {"*.html", "*.txt"};
|
|
|
|
fileWidget->SetFilterList(2, titles, filters);
|
|
|
|
fileWidget->Create(aParentWindow,
|
1998-10-26 18:07:14 +00:00
|
|
|
title,
|
|
|
|
eMode_save,
|
|
|
|
nsnull,
|
|
|
|
nsnull);
|
1998-07-27 18:17:07 +00:00
|
|
|
fileWidget->SetDefaultString(aFileName);
|
|
|
|
|
|
|
|
PRUint32 result = fileWidget->Show();
|
|
|
|
if (result) {
|
|
|
|
fileWidget->GetFile(aFileName);
|
|
|
|
selectedFileName = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(fileWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-07-20 22:22:13 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoDebugSave()
|
|
|
|
{
|
1998-07-27 18:17:07 +00:00
|
|
|
PRBool doSave = PR_FALSE;
|
|
|
|
nsString path;
|
|
|
|
|
1998-08-14 23:08:54 +00:00
|
|
|
PRUnichar *urlString;
|
|
|
|
mWebShell->GetURL(0,&urlString);
|
1998-07-27 18:17:07 +00:00
|
|
|
nsIURL* url;
|
|
|
|
nsresult rv = NS_NewURL(&url, urlString);
|
|
|
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
{
|
1998-12-16 05:40:20 +00:00
|
|
|
const char* name;
|
|
|
|
rv = url->GetFile(&name);
|
1998-07-27 18:17:07 +00:00
|
|
|
path = name;
|
|
|
|
|
|
|
|
doSave = GetSaveFileNameFromFileSelector(mWindow, path);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!doSave)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
nsIPresShell* shell = GetPresShell();
|
1998-07-20 22:22:13 +00:00
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
nsString buffer;
|
1998-07-27 18:17:07 +00:00
|
|
|
|
1999-01-21 21:51:21 +00:00
|
|
|
doc->CreateXIF(buffer);
|
1998-07-20 22:22:13 +00:00
|
|
|
|
|
|
|
nsIParser* parser;
|
1998-07-30 22:42:27 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
|
|
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
|
|
|
1998-09-01 00:26:28 +00:00
|
|
|
nsresult rv = nsRepository::CreateInstance(kCParserCID,
|
1998-10-26 18:07:14 +00:00
|
|
|
nsnull,
|
|
|
|
kCParserIID,
|
|
|
|
(void **)&parser);
|
1998-07-30 22:42:27 +00:00
|
|
|
|
1998-07-20 22:22:13 +00:00
|
|
|
if (NS_OK == rv) {
|
1998-10-26 18:07:14 +00:00
|
|
|
nsIHTMLContentSink* sink = nsnull;
|
1998-07-27 18:17:07 +00:00
|
|
|
|
1998-10-26 18:07:14 +00:00
|
|
|
rv = NS_New_HTML_ContentSinkStream(&sink);
|
|
|
|
|
1998-07-27 19:11:51 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#define BUFFER_SIZE MAX_PATH
|
|
|
|
#else
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
#endif
|
1998-10-26 18:07:14 +00:00
|
|
|
char filename[BUFFER_SIZE];
|
|
|
|
path.ToCString(filename,BUFFER_SIZE);
|
|
|
|
ofstream out(filename);
|
|
|
|
((nsHTMLContentSinkStream*)sink)->SetOutputStream(out);
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
parser->SetContentSink(sink);
|
|
|
|
|
|
|
|
nsIDTD* dtd = nsnull;
|
|
|
|
rv = NS_NewXIFDTD(&dtd);
|
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
parser->RegisterDTD(dtd);
|
1998-11-26 03:21:55 +00:00
|
|
|
//dtd->SetContentSink(sink);
|
|
|
|
//dtd->SetParser(parser);
|
1999-02-03 19:38:39 +00:00
|
|
|
parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE);
|
1998-10-26 18:07:14 +00:00
|
|
|
}
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
NS_IF_RELEASE(dtd);
|
|
|
|
NS_IF_RELEASE(sink);
|
|
|
|
}
|
|
|
|
NS_RELEASE(parser);
|
1998-07-20 22:22:13 +00:00
|
|
|
}
|
1998-07-31 18:35:19 +00:00
|
|
|
NS_RELEASE(doc);
|
1998-07-20 22:22:13 +00:00
|
|
|
}
|
1998-07-31 18:35:19 +00:00
|
|
|
NS_RELEASE(shell);
|
1998-07-20 22:22:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-27 18:17:07 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoToggleSelection()
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
PRBool current = doc->GetDisplaySelection();
|
|
|
|
doc->SetDisplaySelection(!current);
|
|
|
|
ForceRefresh();
|
1998-07-29 17:39:28 +00:00
|
|
|
NS_RELEASE(doc);
|
1998-07-27 18:17:07 +00:00
|
|
|
}
|
1998-07-29 17:39:28 +00:00
|
|
|
NS_RELEASE(shell);
|
1998-07-27 18:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
void
|
|
|
|
nsBrowserWindow::DoDebugRobot()
|
|
|
|
{
|
|
|
|
mApp->CreateRobot(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::DoSiteWalker()
|
|
|
|
{
|
|
|
|
mApp->CreateSiteWalker(this);
|
|
|
|
}
|
|
|
|
|
1998-07-20 21:16:38 +00:00
|
|
|
nsEventStatus
|
1998-07-20 22:13:11 +00:00
|
|
|
nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
|
1998-07-20 21:16:38 +00:00
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
1998-07-20 22:13:11 +00:00
|
|
|
switch(aID) {
|
1998-07-20 21:16:38 +00:00
|
|
|
case VIEWER_VISUAL_DEBUGGING:
|
|
|
|
ToggleFrameBorders();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DUMP_CONTENT:
|
|
|
|
DumpContent();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DUMP_FRAMES:
|
|
|
|
DumpFrames();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DUMP_VIEWS:
|
|
|
|
DumpViews();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DUMP_STYLE_SHEETS:
|
|
|
|
DumpStyleSheets();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_DUMP_STYLE_CONTEXTS:
|
|
|
|
DumpStyleContexts();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SHOW_CONTENT_SIZE:
|
|
|
|
ShowContentSize();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SHOW_FRAME_SIZE:
|
|
|
|
ShowFrameSize();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SHOW_STYLE_SIZE:
|
|
|
|
ShowStyleSize();
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SHOW_CONTENT_QUALITY:
|
|
|
|
#if XXX_fix_me
|
|
|
|
if ((nsnull != wd) && (nsnull != wd->observer)) {
|
|
|
|
nsIPresContext *px = wd->observer->mWebWidget->GetPresContext();
|
|
|
|
nsIPresShell *ps = px->GetShell();
|
|
|
|
nsIViewManager *vm = ps->GetViewManager();
|
|
|
|
|
|
|
|
vm->ShowQuality(!vm->GetShowQuality());
|
|
|
|
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
NS_RELEASE(ps);
|
|
|
|
NS_RELEASE(px);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
1998-07-20 22:22:13 +00:00
|
|
|
|
|
|
|
case VIEWER_DEBUGSAVE:
|
|
|
|
DoDebugSave();
|
|
|
|
break;
|
1998-07-21 00:48:35 +00:00
|
|
|
|
1998-07-27 18:17:07 +00:00
|
|
|
case VIEWER_TOGGLE_SELECTION:
|
|
|
|
DoToggleSelection();
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
1998-07-21 00:48:35 +00:00
|
|
|
case VIEWER_DEBUGROBOT:
|
|
|
|
DoDebugRobot();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_TOP100:
|
|
|
|
DoSiteWalker();
|
|
|
|
break;
|
1999-01-23 07:10:37 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NS_DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBrowserWindow::SetCompatibilityMode(PRBool aIsStandard)
|
|
|
|
{
|
|
|
|
if (nsnull != mPrefs) {
|
|
|
|
int32 prefInt = (aIsStandard) ? eCompatibility_Standard : eCompatibility_NavQuirks;
|
|
|
|
mPrefs->SetIntPref("nglayout.compatibility.mode", prefInt);
|
|
|
|
mPrefs->SavePrefFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsBrowserWindow::DispatchStyleMenu(PRInt32 aID)
|
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
switch(aID) {
|
|
|
|
case VIEWER_SELECT_STYLE_LIST:
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsAutoString defaultStyle;
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
nsIAtom* defStyleAtom = NS_NewAtom("DEFAULT-STYLE");
|
|
|
|
doc->GetHeaderData(defStyleAtom, defaultStyle);
|
|
|
|
NS_RELEASE(defStyleAtom);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStringArray titles;
|
|
|
|
shell->ListAlternateStyleSheets(titles);
|
|
|
|
nsAutoString current;
|
|
|
|
shell->GetActiveAlternateStyleSheet(current);
|
|
|
|
|
|
|
|
PRInt32 count = titles.Count();
|
|
|
|
fprintf(stdout, "There %s %d alternate style sheet%s\n",
|
|
|
|
((1 == count) ? "is" : "are"),
|
|
|
|
count,
|
|
|
|
((1 == count) ? "" : "s"));
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
fprintf(stdout, "%d: \"", index + 1);
|
|
|
|
nsAutoString title;
|
|
|
|
titles.StringAt(index, title);
|
|
|
|
fputs(title, stdout);
|
|
|
|
fprintf(stdout, "\" %s%s\n",
|
|
|
|
((title.EqualsIgnoreCase(current)) ? "<< current " : ""),
|
|
|
|
((title.EqualsIgnoreCase(defaultStyle)) ? "** default" : ""));
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SELECT_STYLE_DEFAULT:
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (nsnull != doc) {
|
|
|
|
nsAutoString defaultStyle;
|
|
|
|
nsIAtom* defStyleAtom = NS_NewAtom("DEFAULT-STYLE");
|
|
|
|
doc->GetHeaderData(defStyleAtom, defaultStyle);
|
|
|
|
NS_RELEASE(defStyleAtom);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
fputs("Selecting default style sheet \"", stdout);
|
|
|
|
fputs(defaultStyle, stdout);
|
|
|
|
fputs("\"\n", stdout);
|
|
|
|
shell->SelectAlternateStyleSheet(defaultStyle);
|
|
|
|
}
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEWER_SELECT_STYLE_ONE:
|
|
|
|
case VIEWER_SELECT_STYLE_TWO:
|
|
|
|
case VIEWER_SELECT_STYLE_THREE:
|
|
|
|
case VIEWER_SELECT_STYLE_FOUR:
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = GetPresShell();
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsStringArray titles;
|
|
|
|
shell->ListAlternateStyleSheets(titles);
|
|
|
|
nsAutoString title;
|
|
|
|
titles.StringAt(aID - VIEWER_SELECT_STYLE_ONE, title);
|
|
|
|
fputs("Selecting alternate style sheet \"", stdout);
|
|
|
|
fputs(title, stdout);
|
|
|
|
fputs("\"\n", stdout);
|
|
|
|
shell->SelectAlternateStyleSheet(title);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
1998-09-23 23:02:54 +00:00
|
|
|
|
|
|
|
case VIEWER_NAV_QUIRKS_MODE:
|
|
|
|
case VIEWER_STANDARD_MODE:
|
|
|
|
SetCompatibilityMode(VIEWER_STANDARD_MODE == aID);
|
1999-01-23 07:10:37 +00:00
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
1998-09-23 23:02:54 +00:00
|
|
|
break;
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
1999-01-23 07:10:37 +00:00
|
|
|
return result;
|
1998-07-20 21:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-20 16:19:22 +00:00
|
|
|
// Factory code for creating nsBrowserWindow's
|
|
|
|
|
|
|
|
class nsBrowserWindowFactory : public nsIFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsBrowserWindowFactory();
|
|
|
|
~nsBrowserWindowFactory();
|
|
|
|
|
|
|
|
// nsISupports methods
|
|
|
|
NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
|
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
1998-10-26 18:07:14 +00:00
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
1998-07-20 16:19:22 +00:00
|
|
|
|
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsrefcnt mRefCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsBrowserWindowFactory::nsBrowserWindowFactory()
|
|
|
|
{
|
|
|
|
mRefCnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserWindowFactory::~nsBrowserWindowFactory()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBrowserWindowFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aResult == NULL) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aResult = (void *)(nsISupports*)this;
|
|
|
|
} else if (aIID.Equals(kIFactoryIID)) {
|
|
|
|
*aResult = (void *)(nsIFactory*)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*aResult == NULL) {
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
1998-07-20 16:19:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt
|
|
|
|
nsBrowserWindowFactory::AddRef()
|
|
|
|
{
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt
|
|
|
|
nsBrowserWindowFactory::Release()
|
|
|
|
{
|
|
|
|
if (--mRefCnt == 0) {
|
|
|
|
delete this;
|
|
|
|
return 0; // Don't access mRefCnt after deleting!
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBrowserWindowFactory::CreateInstance(nsISupports *aOuter,
|
1998-10-26 18:07:14 +00:00
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
1998-07-20 16:19:22 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsBrowserWindow *inst;
|
|
|
|
|
|
|
|
if (aResult == NULL) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = NULL;
|
|
|
|
if (nsnull != aOuter) {
|
|
|
|
rv = NS_ERROR_NO_AGGREGATION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1998-09-15 00:16:12 +00:00
|
|
|
NS_NEWXPCOM(inst, nsNativeBrowserWindow);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (inst == NULL) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBrowserWindowFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
// Not implemented in simplest case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewBrowserWindowFactory(nsIFactory** aFactory)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1998-09-15 00:16:12 +00:00
|
|
|
nsBrowserWindowFactory* inst;
|
|
|
|
NS_NEWXPCOM(inst, nsBrowserWindowFactory);
|
1998-07-20 16:19:22 +00:00
|
|
|
if (nsnull == inst) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
}
|
|
|
|
*aFactory = inst;
|
|
|
|
return rv;
|
|
|
|
}
|