Added the "find" dialog as an XPDialog

This commit is contained in:
rods%netscape.com 1998-11-02 16:07:23 +00:00
Родитель c95e696782
Коммит 78342d7ce3
13 изменённых файлов: 1662 добавлений и 147 удалений

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

@ -17,6 +17,6 @@
DEPTH=..\..
DIRS=src
DIRS=public src
include <$(DEPTH)\layout\config\rules.mak>

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

@ -0,0 +1,30 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
MODULE=raptor
EXPORTS = \
nsIXPBaseWindow.h \
nsWindowListener.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,89 @@
/* -*- 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.
*/
#ifndef nsIXPBaseWindow_h___
#define nsIXPBaseWindow_h___
#include "nsweb.h"
#include "nsISupports.h"
class nsIAppShell;
class nsIPref;
class nsIFactory;
class nsIWebShell;
class nsString;
class nsIPresShell;
class nsIDocumentLoaderObserver;
class nsIDOMElement;
class nsIDOMNode;
class nsWindowListener;
struct nsRect;
#define NS_IXPBASE_WINDOW_IID \
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
#define NS_XPBASE_WINDOW_CID \
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
/**
* API to a "XP window"
*/
class nsIXPBaseWindow : public nsISupports {
public:
NS_IMETHOD Init(nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins = PR_TRUE) = 0;
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY) = 0;
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight) = 0;
NS_IMETHOD GetBounds(nsRect& aResult) = 0;
NS_IMETHOD GetWindowBounds(nsRect& aResult) = 0;
NS_IMETHOD SetVisible(PRBool aIsVisible) = 0;
NS_IMETHOD Close() = 0;
NS_IMETHOD SetTitle(const PRUnichar* aTitle) = 0;
NS_IMETHOD GetTitle(PRUnichar** aResult) = 0;
NS_IMETHOD GetWebShell(nsIWebShell*& aResult) = 0;
NS_IMETHOD LoadURL(const nsString &aURL) = 0;
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell) = 0;
NS_IMETHOD FindDOMElement(const nsString &aId, nsIDOMElement *& aElement) = 0;
NS_IMETHOD AddEventListener(nsIDOMNode * aNode) = 0;
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode) = 0;
NS_IMETHOD AddWindowListener(nsWindowListener * aWindowListener) = 0;
// XXX minimize, maximize
// XXX event control: enable/disable window close box, stick to glass, modal
};
#endif /* nsIXPBaseWindow_h___ */

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

@ -0,0 +1,63 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsWindowListener_h__
#define nsWindowListener_h__
class nsIDOMEvent;
class nsIXPBaseWindow;
/**
* Listens for window mouse events, key clicks etc.
* Also initializes the contents for form elements.
*/
class nsWindowListener {
public:
/**
* Method called when the user clicks the mouse.
* Clicks are only generated when the mouse-up event happens
* over a widget.
*
* @param aMouseEvent DOM event holding mouse click info.
* @param aWindow Window which generated the mouse click event
*/
virtual void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow) = 0;
/**
* Method called After the URL passed to the dialog box or window has
* completed loading. Usually it is used to set place the initial settings
* in form elements.
* @param aWindow the window to initialize form element settings for.
*/
virtual void Initialize(nsIXPBaseWindow * aWindow) = 0;
/**
* Method called when dialog box or window is no longer visibleg
* @param aWindow the window which is about to be destroyed
*/
virtual void Destroy(nsIXPBaseWindow * aWindow) = 0;
};
#endif // nsWindowListener_h__

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

@ -30,6 +30,8 @@ MISCDEP= \
OBJS = \
.\$(OBJDIR)\nsFindDialog.obj \
.\$(OBJDIR)\nsXPBaseWindow.obj \
.\$(OBJDIR)\nsBrowserWindow.obj \
.\$(OBJDIR)\nsSetupRegistry.obj \
.\$(OBJDIR)\nsViewerApp.obj \
@ -75,6 +77,7 @@ OS_CFLAGS = $(OS_CFLAGS) -DMOZ_NO_DEBUG_RTL
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
$(MAKE_INSTALL) resources\chrome\find.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) resources\throbber\LargeAnimation00.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) resources\throbber\LargeAnimation01.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) resources\throbber\LargeAnimation02.gif $(DIST)\bin\res\throbber
@ -178,6 +181,7 @@ install:: $(PROGRAM)
clobber::
rm -f $(DIST)\bin\xpviewer.exe
rm -f $(DIST)\bin\res\samples\find.html
rm -f $(DIST)\bin\res\samples\test0.html
rm -f $(DIST)\bin\res\samples\test1.html
rm -f $(DIST)\bin\res\samples\test2.html

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

@ -45,6 +45,9 @@
#include "nsRepository.h"
#include "nsParserCIID.h"
#include "nsIXPBaseWindow.h"
#include "nsXPBaseWindow.h"
#include "nsFindDialog.h"
#include "nsIDocument.h"
#include "nsIPresContext.h"
#include "nsIDocumentViewer.h"
@ -143,6 +146,7 @@ static NS_DEFINE_IID(kToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID);
static NS_DEFINE_IID(kToolbarItemCID, NS_TOOLBARITEM_CID);
static NS_DEFINE_IID(kPopUpMenuCID, NS_POPUPMENU_CID);
static NS_DEFINE_IID(kMenuButtonCID, NS_MENUBUTTON_CID);
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
@ -171,6 +175,7 @@ static NS_DEFINE_IID(kIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID);
static NS_DEFINE_IID(kIToolbarItemIID, NS_ITOOLBARITEM_IID);
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
static NS_DEFINE_IID(kIMenuButtonIID, NS_IMENUBUTTON_IID);
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
static const char* gsAOLFormat = "AOLMAIL";
static const char* gsHTMLFormat = "text/html";
@ -465,7 +470,8 @@ nsBrowserWindow::Init(nsIAppShell* aAppShell,
r.x = r.y = 0;
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
r.x, r.y, r.width, r.height,
nsScrollPreference_kAuto, aAllowPlugins);
nsScrollPreference_kAuto,
aAllowPlugins);
mWebShell->SetContainer((nsIWebShellContainer*) this);
mWebShell->SetObserver((nsIStreamObserver*)this);
mWebShell->SetPrefs(aPrefs);
@ -1006,133 +1012,80 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
return result;
}
//---------------------------------------------------------------
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 (!foundIt) {
// Display Dialog here
}
ForceRefresh();
NS_RELEASE(doc);
}
NS_RELEASE(shell);
}
return NS_OK;
}
//---------------------------------------------------------------
void
nsBrowserWindow::DoFind()
NS_IMETHODIMP nsBrowserWindow::ForceRefresh()
{
if (mDialog == nsnull) {
nscoord txtHeight = 24;
nscolor textBGColor = NS_RGB(0, 0, 0);
nscolor textFGColor = NS_RGB(255, 255, 255);
mWindow->Invalidate(PR_TRUE);
mWebShell->Repaint(PR_TRUE);
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;
}
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight);
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor);
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor);
NS_RELEASE(lookAndFeel);
//---------------------------------------------------------------
void nsBrowserWindow::DoFind()
{
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, 505, 170);
//nsRect rect(0, 0, 480, 150);
nsString title("Find");
nsIDeviceContext* dc = mWindow->GetDeviceContext();
float t2d;
dc->GetTwipsToDevUnits(t2d);
nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, 0,
nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE)));
NS_RELEASE(dc);
// create a Dialog
//
nsRect rect;
rect.SetRect(0, 0, 380, 110);
nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mDialog);
nsIWidget* widget = nsnull;
NS_CreateDialog(mWindow,mDialog,rect,HandleGUIEvent,&font);
if (NS_OK == mDialog->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
NS_RELEASE(widget);
}
mDialog->SetLabel("Find");
nscoord xx = 5;
// Create Label
rect.SetRect(xx, 8, 75, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mLabel);
NS_CreateLabel(mDialog,mLabel,rect,HandleGUIEvent,&font);
if (NS_OK == mLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mLabel->SetAlignment(eAlign_Right);
mLabel->SetLabel("Find what:");
NS_RELEASE(widget);
}
xx += 75 + 5;
// Create TextField
rect.SetRect(xx, 5, 200, txtHeight);
nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mTextField);
NS_CreateTextWidget(mDialog,mTextField,rect,HandleGUIEvent,&font);
if (NS_OK == mTextField->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetBackgroundColor(textBGColor);
widget->SetForegroundColor(textFGColor);
widget->SetClientData(this);
widget->SetFocus();
NS_RELEASE(widget);
}
xx += 200 + 5;
nscoord w = 65;
nscoord x = 205+80-w;
nscoord y = txtHeight + 10;
nscoord h = 19;
// Create Up RadioButton
rect.SetRect(x, y, w, h);
nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mUpRadioBtn);
NS_CreateRadioButton(mDialog,mUpRadioBtn,rect,HandleGUIEvent,&font);
if (NS_OK == mUpRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mUpRadioBtn->SetLabel("Up");
NS_RELEASE(widget);
}
y += h + 2;
// Create Up RadioButton
rect.SetRect(x, y, w, h);
nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mDwnRadioBtn);
NS_CreateRadioButton(mDialog,mDwnRadioBtn,rect,HandleGUIEvent,&font);
if (NS_OK == mDwnRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mDwnRadioBtn->SetLabel("Down");
NS_RELEASE(widget);
}
// Create Match CheckButton
rect.SetRect(5, y, 125, 24);
nsRepository::CreateInstance(kCheckButtonCID, nsnull, kICheckButtonIID, (void**)&mMatchCheckBtn);
NS_CreateCheckButton(mDialog,mMatchCheckBtn,rect,HandleGUIEvent,&font);
if (NS_OK == mMatchCheckBtn->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mMatchCheckBtn->SetLabel("Match Case");
NS_RELEASE(widget);
}
mUpRadioBtn->SetState(PR_FALSE);
mDwnRadioBtn->SetState(PR_TRUE);
// Create Find Next Button
rect.SetRect(xx, 5, 75, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mFindBtn);
NS_CreateButton(mDialog,mFindBtn,rect,HandleGUIEvent,&font);
if (NS_OK == mFindBtn->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mFindBtn->SetLabel("Find Next");
NS_RELEASE(widget);
}
// Create Cancel Button
rect.SetRect(xx, 35, 75, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mCancelBtn);
NS_CreateButton(mDialog,mCancelBtn,rect,HandleGUIEvent,&font);
if (NS_OK == mCancelBtn->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->SetClientData(this);
mCancelBtn->SetLabel("Cancel");
NS_RELEASE(widget);
nsXPBaseWindow * dialog = nsnull;
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
kIXPBaseWindowIID,
(void**) &dialog);
if (rv == NS_OK) {
dialog->Init(mAppShell, nsnull, findHTML, title, rect, PRUint32(~0), PR_FALSE);
dialog->SetVisible(PR_TRUE);
if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**) &mXPDialog)) {
}
}
mTextField->SelectAll();
nsFindDialog * findDialog = new nsFindDialog(this);
if (nsnull != findDialog) {
dialog->AddWindowListener(findDialog);
}
//NS_IF_RELEASE(dialog);
}
@ -1153,25 +1106,6 @@ nsBrowserWindow::DoSelectAll()
}
}
//---------------------------------------------------------------
void
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);
}
}
// XXX This sort of thing should be in a resource
#define TOOL_BAR_FONT "Helvetica"

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

@ -20,6 +20,7 @@
#define nsBrowserWindow_h___
#include "nsIBrowserWindow.h"
#include "nsIXPBaseWindow.h"
#include "nsIStreamListener.h"
#include "nsINetSupport.h"
#include "nsIWebShell.h"
@ -93,6 +94,9 @@ public:
NS_IMETHOD GetStatus(PRUnichar** aResult);
NS_IMETHOD SetProgress(PRInt32 aProgress, PRInt32 aProgressMax);
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
NS_IMETHOD ForceRefresh();
NS_IMETHOD HandleEvent(nsGUIEvent * anEvent);
// nsIStreamObserver
@ -147,8 +151,6 @@ public:
void DoFind();
void DoSelectAll();
void ForceRefresh();
void DoAppsDialog();
// nsIToolbarManager Listener Interface
@ -185,6 +187,7 @@ public:
static void CloseAllWindows();
nsViewerApp* mApp;
nsIXPBaseWindow* mXPDialog;
PRUint32 mChromeMask;
nsString mTitle;

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

@ -0,0 +1,105 @@
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFindDialog.h"
#include "nsIDOMEvent.h"
#include "nsIXPBaseWindow.h"
#include "nsIDOMHTMLInputElement.h"
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
//-------------------------------------------------------------------------
//
// nsFindDialog constructor
//
//-------------------------------------------------------------------------
//-----------------------------------------------------------------
nsFindDialog::nsFindDialog(nsBrowserWindow * aBrowserWindow) :
mBrowserWindow(aBrowserWindow),
mFindBtn(nsnull),
mCancelBtn(nsnull)
{
}
//-----------------------------------------------------------------
nsFindDialog::~nsFindDialog()
{
}
//---------------------------------------------------------------
void nsFindDialog::Initialize(nsIXPBaseWindow * aWindow)
{
aWindow->FindDOMElement("find", mFindBtn);
aWindow->FindDOMElement("cancel", mCancelBtn);
// XXX: Register event listening on each dom element. We should change this so
// all DOM events are automatically passed through.
aWindow->AddEventListener(mFindBtn);
aWindow->AddEventListener(mCancelBtn);
}
//-----------------------------------------------------------------
void nsFindDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow)
{
nsIDOMNode * node;
aMouseEvent->GetTarget(&node);
if (node == mFindBtn) {
DoFind(aWindow);
} else if (node == mCancelBtn) {
aWindow->SetVisible(PR_FALSE);
}
NS_RELEASE(node);
}
//-----------------------------------------------------------------
void nsFindDialog::Destroy(nsIXPBaseWindow * aWindow)
{
// Unregister event listeners that were registered in the
// Initialize here.
// XXX: Should change code in XPBaseWindow to automatically unregister
// all event listening, That way this code will not be necessary.
aWindow->RemoveEventListener(mFindBtn);
aWindow->RemoveEventListener(mCancelBtn);
}
//---------------------------------------------------------------
void
nsFindDialog::DoFind(nsIXPBaseWindow * aWindow)
{
// Now we have the content tree, lets find the
// widgets holding the info.
nsIDOMElement * textNode;
if (NS_OK == aWindow->FindDOMElement("query", textNode)) {
nsIDOMHTMLInputElement * element;
if (NS_OK == textNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
nsString str;
PRBool foundIt = PR_FALSE;
element->GetValue(str);
mBrowserWindow->FindNext(str, PR_FALSE, PR_TRUE, foundIt);
if (foundIt) {
mBrowserWindow->ForceRefresh();
}
NS_RELEASE(element);
}
NS_RELEASE(textNode);
}
}

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

@ -0,0 +1,53 @@
/* -*- 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.
*/
#ifndef nsFindDialog_h___
#define nsFindDialog_h___
#include "nsBrowserWindow.h"
#include "nsWindowListener.h"
#include "nsIDOMElement.h"
/**
* Implement Navigator Find Dialog
*/
class nsFindDialog : public nsWindowListener
{
public:
nsFindDialog(nsBrowserWindow * aBrowserWindow);
virtual ~nsFindDialog();
// nsWindowListener Methods
void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow);
void Initialize(nsIXPBaseWindow * aWindow);
void Destroy(nsIXPBaseWindow * aWindow);
// new methods
virtual void DoFind(nsIXPBaseWindow * aWindow);
protected:
nsBrowserWindow * mBrowserWindow;
nsIDOMElement * mFindBtn;
nsIDOMElement * mCancelBtn;
};
#endif /* nsFindDialog_h___ */

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

@ -22,6 +22,7 @@
#endif
#include "nsViewerApp.h"
#include "nsBrowserWindow.h"
#include "nsXPBaseWindow.h"
#include "nsWidgetsCID.h"
#include "nsIAppShell.h"
#include "nsIPref.h"
@ -59,13 +60,16 @@
#endif
extern nsresult NS_NewBrowserWindowFactory(nsIFactory** aFactory);
extern nsresult NS_NewXPBaseWindowFactory(nsIFactory** aFactory);
extern "C" void NS_SetupRegistry();
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID);
static NS_DEFINE_IID(kXPDialogWindowCID, NS_XPDIALOG_WINDOW_CID);
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
static NS_DEFINE_IID(kIXPDialogWindowIID, NS_IXPDIALOG_WINDOW_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -145,6 +149,9 @@ nsViewerApp::SetupRegistry()
NS_NewBrowserWindowFactory(&bwf);
nsRepository::RegisterFactory(kBrowserWindowCID, bwf, PR_FALSE);
NS_NewXPBaseWindowFactory(&bwf);
nsRepository::RegisterFactory(kXPDialogWindowCID, bwf, PR_FALSE);
return NS_OK;
}
@ -165,7 +172,6 @@ nsViewerApp::Initialize(int argc, char** argv)
return rv;
}
mAppShell->Create(&argc, argv);
//mAppShell->SetDispatchListener((nsDispatchListener*) this);
// Load preferences
rv = nsRepository::CreateInstance(kPrefCID, NULL, kIPrefIID,
@ -443,6 +449,21 @@ nsViewerApp::OpenWindow()
bw->SetApp(this);
bw->Init(mAppShell, mPrefs, nsRect(0, 0, 620, 400), PRUint32(~0), mAllowPlugins);
bw->Show();
// Create browser window
// 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...
/*nsXPDialogWindow* dialog = nsnull;
rv = nsRepository::CreateInstance(kXPDialogWindowCID, nsnull,
kIXPDialogWindowIID,
(void**) &dialog);
dialog->SetApp(this);
dialog->Init(mAppShell, mPrefs, nsRect(0, 0, 385, 175), PRUint32(~0), mAllowPlugins);
nsString findHTML("resource:/res/samples/find.html");
dialog->LoadURL(findHTML);
dialog->Show();*/
/*mCrawler->SetBrowserWindow(bw);
if (mDoPurify) {

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

@ -0,0 +1,947 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIPref.h"
#ifdef XP_MAC
#include "nsXPBaseWindow.h"
#define NS_IMPL_IDS
#else
#define NS_IMPL_IDS
#include "nsXPBaseWindow.h"
#endif
#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"
#include "nsIFileWidget.h"
#include "nsILookAndFeel.h"
#include "nsRepository.h"
#include "nsIFactory.h"
#include "nsCRT.h"
#include "nsWidgetsCID.h"
#include "nsViewerApp.h"
#include "prprf.h"
#include "nsRepository.h"
#include "nsParserCIID.h"
#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"
#include "nsIDocumentLoader.h"
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsWindowListener.h"
#if defined(WIN32)
#include <strstrea.h>
#else
#include <strstream.h>
#endif
// XXX For font setting below
#include "nsFont.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#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
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDocLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID);
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
//----------------------------------------------------------------------
nsXPBaseWindow::nsXPBaseWindow() :
mContentRoot(nsnull),
mPrefs(nsnull),
mAppShell(nsnull),
mDocIsLoaded(PR_FALSE)
{
}
//----------------------------------------------------------------------
nsXPBaseWindow::~nsXPBaseWindow()
{
NS_IF_RELEASE(mContentRoot);
NS_IF_RELEASE(mPrefs);
NS_IF_RELEASE(mAppShell);
}
//----------------------------------------------------------------------
NS_IMPL_ADDREF(nsXPBaseWindow)
NS_IMPL_RELEASE(nsXPBaseWindow)
//----------------------------------------------------------------------
nsresult nsXPBaseWindow::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtrResult = NULL;
if (aIID.Equals(kIXPBaseWindowIID)) {
*aInstancePtrResult = (void*) ((nsIXPBaseWindow*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStreamObserverIID)) {
*aInstancePtrResult = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIWebShellContainerIID)) {
*aInstancePtrResult = (void*) ((nsIWebShellContainer*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kINetSupportIID)) {
*aInstancePtrResult = (void*) ((nsINetSupport*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMMouseListenerIID)) {
NS_ADDREF_THIS(); // Increase reference count for caller
*aInstancePtrResult = (void *)((nsIDOMMouseListener*)this);
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
NS_ADDREF_THIS();
*aInstancePtrResult = (void*) ((nsISupports*)((nsIXPBaseWindow*)this));
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
static nsEventStatus PR_CALLBACK
HandleXPDialogEvent(nsGUIEvent *aEvent)
{
nsEventStatus result = nsEventStatus_eIgnore;
/*
nsXPBaseWindow* bw =
nsXPBaseWindow::FindBrowserFor(aEvent->widget, FIND_WINDOW);
if (nsnull != bw) {
nsSizeEvent* sizeEvent;
switch(aEvent->message) {
case NS_SIZE:
sizeEvent = (nsSizeEvent*)aEvent;
bw->Layout(sizeEvent->windowSize->width,
sizeEvent->windowSize->height);
result = nsEventStatus_eConsumeNoDefault;
break;
case NS_DESTROY:
{
nsViewerApp* app = bw->mApp;
result = nsEventStatus_eConsumeDoDefault;
bw->Close();
NS_RELEASE(bw);
// XXX Really shouldn't just exit, we should just notify somebody...
if (0 == nsXPBaseWindow::gBrowsers.Count()) {
app->Exit();
}
}
return result;
case NS_MENU_SELECTED:
result = bw->DispatchMenuItem(((nsMenuEvent*)aEvent)->mCommand);
break;
default:
break;
}
NS_RELEASE(bw);
}*/
return result;
}
//----------------------------------------------------------------------
nsresult nsXPBaseWindow::Init(nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
mAppShell = aAppShell;
NS_IF_ADDREF(mAppShell);
mPrefs = aPrefs;
NS_IF_ADDREF(mPrefs);
// Create top level window
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
(void**)&mWindow);
if (NS_OK != rv) {
return rv;
}
nsWidgetInitData initData;
initData.mBorderStyle = eBorderStyle_dialog;
nsRect r(0, 0, aBounds.width, aBounds.height);
mWindow->Create((nsIWidget*)NULL, r, HandleXPDialogEvent,
nsnull, aAppShell, nsnull, &initData);
mWindow->GetBounds(r);
// Create web shell
rv = nsRepository::CreateInstance(kWebShellCID, nsnull,
kIWebShellIID,
(void**)&mWebShell);
if (NS_OK != rv) {
return rv;
}
r.x = r.y = 0;
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
r.x, r.y, r.width, r.height,
nsScrollPreference_kNeverScroll, //nsScrollPreference_kAuto,
aAllowPlugins);
mWebShell->SetContainer((nsIWebShellContainer*) this);
mWebShell->SetObserver((nsIStreamObserver*)this);
mWebShell->SetPrefs(aPrefs);
mWebShell->Show();
// Now lay it all out
Layout(r.width, r.height);
// Load URL to Load GUI
mDialogURL = aDialogURL;
LoadURL(mDialogURL);
//SetVisible(PR_TRUE);
SetTitle(aTitle);
return NS_OK;
}
//----------------------------------------------------------------------
void nsXPBaseWindow::ForceRefresh()
{
nsIPresShell* shell;
GetPresShell(shell);
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_VMREFRESH_AUTO_DOUBLE_BUFFER);
}
NS_RELEASE(vm);
}
NS_RELEASE(shell);
}
}
//----------------------------------------------------------------------
void nsXPBaseWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
{
nsRect rr(0, 0, aWidth, aHeight);
// inset the web widget
/*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);
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetLocation(PRInt32 aX, PRInt32 aY)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mWindow->Move(aX, aY);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetDimensions(PRInt32 aWidth, PRInt32 aHeight)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
// XXX We want to do this in one shot
mWindow->Resize(aWidth, aHeight, PR_FALSE);
Layout(aWidth, aHeight);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetBounds(nsRect& aBounds)
{
mWindow->GetBounds(aBounds);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP
nsXPBaseWindow::GetWindowBounds(nsRect& aBounds)
{
//XXX This needs to be non-client bounds when it exists.
mWindow->GetBounds(aBounds);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetVisible(PRBool aIsVisible)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mWindow->Show(aIsVisible);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::Close()
{
if (nsnull != mWindowListener) {
mWindowListener->Destroy(this);
}
if (nsnull != mWebShell) {
mWebShell->Destroy();
NS_RELEASE(mWebShell);
}
if (nsnull != mWindow) {
nsIWidget* w = mWindow;
NS_RELEASE(w);
}
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetWebShell(nsIWebShell*& aResult)
{
aResult = mWebShell;
NS_IF_ADDREF(mWebShell);
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetTitle(const PRUnichar* aTitle)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mTitle = aTitle;
nsAutoString newTitle(aTitle);
mWindow->SetTitle(newTitle.GetUnicode());
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetTitle(PRUnichar** aResult)
{
*aResult = mTitle;
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::LoadURL(const nsString& aURL)
{
mWebShell->LoadURL(aURL, nsnull);
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus)
{
// Find the Root Conent Node for this Window
nsIPresShell* shell;
GetPresShell(shell);
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
mContentRoot = doc->GetRootContent();
mDocIsLoaded = PR_TRUE;
if (nsnull != mWindowListener) {
mWindowListener->Initialize(this);
}
NS_RELEASE(doc);
}
NS_RELEASE(shell);
}
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
{
aResult = nsnull;
nsString aNameStr(aName);
nsIWebShell *ws;
if (NS_OK == GetWebShell(ws)) {
PRUnichar *name;
if (NS_OK == ws->GetName(&name)) {
if (aNameStr.Equals(name)) {
aResult = ws;
NS_ADDREF(aResult);
return NS_OK;
}
}
}
if (NS_OK == ws->FindChildWithName(aName, aResult)) {
if (nsnull != aResult) {
return NS_OK;
}
}
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::AddEventListener(nsIDOMNode * aNode)
{
nsIDOMEventReceiver * receiver;
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
receiver->AddEventListener((nsIDOMMouseListener*)this, kIDOMMouseListenerIID);
NS_RELEASE(receiver);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::RemoveEventListener(nsIDOMNode * aNode)
{
nsIDOMEventReceiver * receiver;
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
receiver->RemoveEventListener(this, kIDOMMouseListenerIID);
NS_RELEASE(receiver);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::AddWindowListener(nsWindowListener * aWindowListener)
{
mWindowListener = aWindowListener;
if (mDocIsLoaded && nsnull != mWindowListener) {
mWindowListener->Initialize(this);
}
return NS_OK;
}
//-----------------------------------------------------
nsIDOMNode * nsXPBaseWindow::SearchTree(nsIDOMNode *aNode, const nsString &aId)
{
nsString idStr("id");
PRUint16 nodeType = 0;
aNode->GetNodeType(&nodeType);
if (nodeType == nsIDOMNode.ELEMENT_NODE) {
nsIDOMElement* nodeElement;
nsresult result = aNode->QueryInterface(kIDOMElementIID, (void**) &nodeElement);
if (NS_OK == result) {
nsString id;
if (NS_OK == nodeElement->GetDOMAttribute(idStr, id)) {
if (id == aId) {
NS_RELEASE(nodeElement);
return(aNode);
}
NS_RELEASE(nodeElement);
}
}
}
PRBool hasChildren;
aNode->HasChildNodes(&hasChildren);
if (hasChildren) {
nsIDOMNode * childNode;
aNode->GetFirstChild(&childNode);
while (childNode != nsnull) {
nsIDOMNode * node = SearchTree(childNode, aId);
if (node != nsnull) {
return node;
}
nsIDOMNode * oldChild = childNode;
oldChild->GetNextSibling(&childNode);
NS_RELEASE(oldChild);
}
}
return nsnull;
}
//-----------------------------------------------------
// Find a DOM Node in the tree
NS_IMETHODIMP nsXPBaseWindow::FindDOMElement(const nsString &aId, nsIDOMElement *& aElement)
{
aElement = nsnull;
nsIDOMNode* bodyContent = nsnull;
nsIDOMElement *root = nsnull;
nsresult rv = mContentRoot->QueryInterface(kIDOMElementIID,(void **)&root);
if (NS_OK != rv) {
return(nsnull);
}
nsString bodyStr("BODY");
nsIDOMNode * child;
root->GetFirstChild(&child);
while (child != nsnull) {
nsIDOMElement* domElement;
nsresult rv = child->QueryInterface(kIDOMElementIID,(void **)&domElement);
if (NS_OK == rv) {
nsString tagName;
domElement->GetTagName(tagName);
if (bodyStr.EqualsIgnoreCase(tagName)) {
bodyContent = child;
break;
}
NS_RELEASE(domElement);
}
nsIDOMNode * node = child;
NS_RELEASE(child);
node->GetNextSibling(&child);
}
if (bodyContent == nsnull) {
return NS_ERROR_FAILURE;
}
//printRefs(bodyContent, 0);
NS_ADDREF(bodyContent);
// Search the rest of the tree looking for a node with
// a matching id
nsIDOMNode* node = SearchTree(bodyContent, aId);
if (nsnull != node) {
nsIDOMElement* nodeElement;
nsresult result = node->QueryInterface(kIDOMElementIID, (void**) &nodeElement);
if (NS_OK == result) {
aElement = nodeElement;
return NS_OK;
}
}
return(nsnull);
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::NewWebShell(nsIWebShell*& aNewWebShell)
{
nsresult rv = NS_OK;
// Create new window. By default, the refcnt will be 1 because of
// the registration of the browser window in gBrowsers.
nsXPBaseWindow* dialogWindow;
NS_NEWXPCOM(dialogWindow, nsXPBaseWindow);
if (nsnull != dialogWindow) {
nsRect bounds;
GetBounds(bounds);
rv = dialogWindow->Init(mAppShell, mPrefs, mDialogURL, mTitle, bounds, 0, mAllowPlugins);
if (NS_OK == rv) {
dialogWindow->SetVisible(PR_TRUE);
nsIWebShell *shell;
rv = dialogWindow->GetWebShell(shell);
aNewWebShell = shell;
} else {
dialogWindow->Close();
}
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
//----------------------------------------
// Stream observer implementation
NS_IMETHODIMP
nsXPBaseWindow::OnProgress(nsIURL* aURL,
PRInt32 aProgress,
PRInt32 aProgressMax)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStatus(nsIURL* aURL, const nsString& aMsg)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStartBinding(nsIURL* aURL, const char *aContentType)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP_(void) nsXPBaseWindow::Alert(const nsString &aText)
{
nsAutoString str(aText);
printf("Browser Window Alert: %s\n", str);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::Confirm(const nsString &aText)
{
nsAutoString str(aText);
printf("Browser Window Confirm: %s (returning false)\n", str);
return PR_FALSE;
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult)
{
nsAutoString str(aText);
char buf[256];
printf("Browser Window: %s\n", str);
printf("Prompt: ");
scanf("%s", buf);
aResult = buf;
return (aResult.Length() > 0);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword)
{
nsAutoString str(aText);
char buf[256];
printf("Browser Window: %s\n", str);
printf("User: ");
scanf("%s", buf);
aUser = buf;
printf("Password: ");
scanf("%s", buf);
aPassword = buf;
return (aUser.Length() > 0);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::PromptPassword(const nsString &aText,
nsString &aPassword)
{
nsAutoString str(aText);
char buf[256];
printf("Browser Window: %s\n", str);
printf("Password: ");
scanf("%s", buf);
aPassword = buf;
return PR_TRUE;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetPresShell(nsIPresShell*& aPresShell)
{
aPresShell = nsnull;
nsIPresShell* shell = nsnull;
if (nsnull != mWebShell) {
nsIContentViewer* cv = nsnull;
mWebShell->GetContentViewer(cv);
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(); // does an add ref
aPresShell = shell;
NS_RELEASE(cx);
}
NS_RELEASE(docv);
}
NS_RELEASE(cv);
}
}
return NS_OK;
}
//-----------------------------------------------------------------
//-- nsIDOMMouseListener
//-----------------------------------------------------------------
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseUp(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseDown(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseClick(nsIDOMEvent* aMouseEvent)
{
if (nsnull != mWindowListener) {
mWindowListener->MouseClick(aMouseEvent, this);
}
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseDblClick(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseOut(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//----------------------------------------------------------------------
// Factory code for creating nsXPBaseWindow's
class nsXPBaseWindowFactory : public nsIFactory
{
public:
nsXPBaseWindowFactory();
~nsXPBaseWindowFactory();
// 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,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
private:
nsrefcnt mRefCnt;
};
nsXPBaseWindowFactory::nsXPBaseWindowFactory()
{
mRefCnt = 0;
}
nsXPBaseWindowFactory::~nsXPBaseWindowFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
nsresult
nsXPBaseWindowFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
if (aIID.Equals(kISupportsIID)) {
*aResult = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = (void *)(nsIFactory*)this;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
NS_ADDREF_THIS(); // Increase reference count for caller
return NS_OK;
}
nsrefcnt
nsXPBaseWindowFactory::AddRef()
{
return ++mRefCnt;
}
nsrefcnt
nsXPBaseWindowFactory::Release()
{
if (--mRefCnt == 0) {
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
nsresult
nsXPBaseWindowFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult rv;
nsXPBaseWindow *inst;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
if (nsnull != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
goto done;
}
NS_NEWXPCOM(inst, nsXPBaseWindow);
if (inst == NULL) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
done:
return rv;
}
nsresult
nsXPBaseWindowFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
nsresult
NS_NewXPBaseWindowFactory(nsIFactory** aFactory)
{
nsresult rv = NS_OK;
nsXPBaseWindowFactory* inst;
NS_NEWXPCOM(inst, nsXPBaseWindowFactory);
if (nsnull == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
NS_ADDREF(inst);
}
*aFactory = inst;
return rv;
}

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

@ -0,0 +1,194 @@
/* -*- 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.
*/
#ifndef nsXPBaseWindow_h___
#define nsXPBaseWindow_h___
#include "nsIXPBaseWindow.h"
#include "nsIStreamListener.h"
#include "nsINetSupport.h"
#include "nsIWebShell.h"
#include "nsIScriptContextOwner.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsCRT.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDocumentLoaderObserver.h"
#include "nsIDOMMouseListener.h"
//class nsILabel;
//class nsICheckButton;
//class nsIRadioButton;
//class nsIDialog;
//class nsITextWidget;
//class nsIButton;
//class nsIThrobber;
class nsViewerApp;
class nsIPresShell;
class nsIPref;
//class nsIImageButton;
//class nsIMenuButton;
//class nsIToolbar;
//class nsIToolbarManager;
#define SAMPLES_BASE_URL "resource:/res/samples"
/**
* Abstract base class for our test app's browser windows
*/
class nsXPBaseWindow : public nsIXPBaseWindow,
public nsIStreamObserver,
public nsINetSupport,
public nsIWebShellContainer,
public nsIDOMMouseListener
{
public:
void* operator new(size_t sz) {
void* rv = new char[sz];
nsCRT::zero(rv, sz);
return rv;
}
nsXPBaseWindow();
virtual ~nsXPBaseWindow();
// nsISupports
NS_DECL_ISUPPORTS
// nsIBrowserWindow
NS_IMETHOD Init(nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins = PR_TRUE);
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY);
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD GetWindowBounds(nsRect& aBounds);
NS_IMETHOD GetBounds(nsRect& aBounds);
NS_IMETHOD SetVisible(PRBool aIsVisible);
NS_IMETHOD Close();
NS_IMETHOD SetTitle(const PRUnichar* aTitle);
NS_IMETHOD GetTitle(PRUnichar** aResult);
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell);
//NS_IMETHOD HandleEvent(nsGUIEvent * anEvent);
NS_IMETHOD LoadURL(const nsString &aURL);
// nsIStreamObserver
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const nsString& aMsg);
NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString &aMsg);
// nsIWebShellContainer
NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason);
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL);
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus);
NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell);
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult);
// nsINetSupport
NS_IMETHOD_(void) Alert(const nsString &aText);
NS_IMETHOD_(PRBool) Confirm(const nsString &aText);
NS_IMETHOD_(PRBool) Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult);
NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword);
NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText,
nsString &aPassword);
void Layout(PRInt32 aWidth, PRInt32 aHeight);
void ForceRefresh();
//nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
void SetApp(nsViewerApp* aApp) {
mApp = aApp;
}
// DOM Element & Node Interfaces
NS_IMETHOD FindDOMElement(const nsString &aId, nsIDOMElement *& aElement);
NS_IMETHOD AddEventListener(nsIDOMNode * aNode);
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode);
NS_IMETHOD AddWindowListener(nsWindowListener * aWindowListener);
// nsIDOMEventListener
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
// nsIDOMMouseListener (is derived from nsIDOMEventListener)
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
protected:
void GetContentRoot(); //Gets the Root Content node after Doc is loaded
nsIDOMNode * SearchTree(nsIDOMNode *aNode, const nsString &aId);
nsIContent * mContentRoot; // Points at the Root Content Node
protected:
nsViewerApp* mApp;
nsString mTitle;
nsString mDialogURL;
nsIWidget* mWindow;
nsIWebShell* mWebShell;
nsWindowListener * mWindowListener; // XXX Someday this will be a list
PRBool mDocIsLoaded;
//for creating more instances
nsIAppShell* mAppShell; //not addref'ed!
nsIPref* mPrefs; //not addref'ed!
PRBool mAllowPlugins;
};
// XXX This is bad; because we can't hang a closure off of the event
// callback we have no way to store our This pointer; therefore we
// have to hunt to find the browswer that events belong too!!!
// aWhich for FindBrowserFor
#define FIND_WINDOW 0
#define FIND_BACK 1
#define FIND_FORWARD 2
#define FIND_LOCATION 3
#endif /* nsXPBaseWindow_h___ */

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

@ -0,0 +1,72 @@
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#C0C0C0">
<style type="text/css">
/* This style sheet should be in a seperate file */
BODY,TD {
font-family: Sans-Serif;
background-color: #C0C0C0;
}
BODY,TD,INPUT {
font-size: 9pt;
}
BODY {
margin: 0px 0px 0px 0px;
}
</style>
<FORM>
<table border="0" bgcolor="#C0C0C0">
<tr>
<td NOWRAP width="30" align="LEFT">
<div align="LEFT">
Find what:
</div>
</td>
<td width="134">
<input type="text" id="query">
</td>
<td width="137">
<input type="button" id="find" value="Find Next" style="width:100;">
</td>
</tr>
<tr>
<td NOWRAP width="30" align="LEFT">&nbsp;
<div align="RIGHT">
<table border="0" width="100%">
<tr>
<td width="27%">
<div align="LEFT">
<input type="checkbox" id="matchcase" value="checkbox" style="background-color: rgb(192,192,192);">
</div>
</td>
<td width="73%" NOWRAP>Match Case</td>
</tr>
</table>
</div>
</td>
<td width="134">&nbsp; <fieldset style="background-color: rgb(192, 192, 192); display: inline; border: 2px groove white; margin-left: 10px; padding: 10px;">
<legend style="background-color:rgb(192, 192, 192); border: none ; padding: 0px;" align=left>&nbsp;Direction
&nbsp;</legend>
<input type=radio id="Up" size=15 maxlength=80 style="margin-right:10px; background-color: rgb(190, 190, 190);">
<u>U</u>p
<input type=radio id="Down">
<u>D</u>own
<input type="HIDDEN" id="a" value="n">
</fieldset> </td>
<td width="137">
<input type="button" id="cancel" value="Cancel" style="width:100;">
</td>
</tr>
</table>
</FORM>
<p>&nbsp; </p>
</body>
</html>