зеркало из https://github.com/mozilla/pjs.git
First Checked In.
This commit is contained in:
Родитель
059d6a8b9c
Коммит
d77d8a9c12
|
@ -0,0 +1,81 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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.
|
||||
*/
|
||||
|
||||
|
||||
class nsITextServicesDocument;
|
||||
|
||||
// {4AA267A0-F81D-11d2-8067-00600811A9C3}
|
||||
#define NS_FINDCOMPONENT_CID \
|
||||
{ 0x4aa267a0, 0xf81d, 0x11d2, { 0x80, 0x67, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3} }
|
||||
|
||||
class nsFindComponent : public nsIFindComponent
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_FINDCOMPONENT_CID );
|
||||
|
||||
// ctor/dtor
|
||||
nsFindComponent();
|
||||
virtual ~nsFindComponent();
|
||||
|
||||
// This class implements the nsISupports interface functions.
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// This class implements the nsIAppShellComponent interface functions.
|
||||
NS_DECL_IAPPSHELLCOMPONENT
|
||||
|
||||
// This class implements the nsIFindComponent interface functions.
|
||||
NS_DECL_IFINDCOMPONENT
|
||||
|
||||
// "Context" for this implementation.
|
||||
class Context : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
Context();
|
||||
virtual ~Context();
|
||||
NS_IMETHOD Init( nsIDocument *aDocument,
|
||||
const nsString &lastSearchString,
|
||||
const nsString &lastIgnoreCase,
|
||||
const nsString &lastSearchBackwards,
|
||||
const nsString &lastWrapSearch);
|
||||
|
||||
NS_IMETHOD MakeTSDocument( nsIDocument *aNewDocument );
|
||||
NS_IMETHOD Reset( nsIDocument *aNewDocument );
|
||||
NS_IMETHOD DoFind();
|
||||
|
||||
// Maybe add Find/FindNext functions here?
|
||||
nsCOMPtr<nsITextServicesDocument> mTextServicesDocument;
|
||||
nsString mSearchString;
|
||||
PRBool mIgnoreCase;
|
||||
PRBool mSearchBackwards;
|
||||
PRBool mWrapSearch;
|
||||
|
||||
PRUint32 mLastBlockOffset; // last offset within the cur block that we found something
|
||||
|
||||
}; // nsFindComponent::Context
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAppShellService> mAppShell;
|
||||
nsString mLastSearchString;
|
||||
|
||||
// should these really be strings?
|
||||
nsString mLastIgnoreCase;
|
||||
nsString mLastSearchBackwards;
|
||||
nsString mLastWrapSearch;
|
||||
}; // nsFindComponent
|
|
@ -0,0 +1,285 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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 "nsIFindComponent.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsITextServicesDocument.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
#include "nsFindComponent.h"
|
||||
#include "nsFindDialog.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
// Standard implementations of addref/release.
|
||||
NS_IMPL_ADDREF( nsFindDialog );
|
||||
NS_IMPL_RELEASE( nsFindDialog );
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFindDialog::QueryInterface( REFNSIID anIID, void **anInstancePtr)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if ( anInstancePtr ) {
|
||||
// Always NULL result, in case of failure
|
||||
*anInstancePtr = 0;
|
||||
|
||||
// Check for interfaces we support and cast this appropriately.
|
||||
if ( anIID.Equals( nsIXULWindowCallbacks::GetIID() ) ) {
|
||||
*anInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
|
||||
NS_ADDREF_THIS();
|
||||
} else if ( anIID.Equals( nsIDocumentObserver::GetIID() ) ) {
|
||||
*anInstancePtr = (void*) ((nsIDocumentObserver*)this);
|
||||
NS_ADDREF_THIS();
|
||||
} else if ( anIID.Equals( kISupportsIID ) ) {
|
||||
*anInstancePtr = (void*) ((nsISupports*)(nsIDocumentObserver*)this);
|
||||
NS_ADDREF_THIS();
|
||||
} else {
|
||||
// Not an interface we support.
|
||||
rv = NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// ctor
|
||||
nsFindDialog::nsFindDialog( nsIFindComponent *aComponent,
|
||||
nsFindComponent::Context *aContext )
|
||||
: mComponent( nsDontQueryInterface<nsIFindComponent>( aComponent ) ),
|
||||
mContext( aContext ),
|
||||
mWebShell(),
|
||||
mWindow() {
|
||||
// Initialize ref count.
|
||||
NS_INIT_REFCNT();
|
||||
mContext->AddRef();
|
||||
}
|
||||
|
||||
|
||||
// This is cribbed from nsBrowserAppCore.cpp also (and should be put somewhere once
|
||||
// and reused)...
|
||||
static int APP_DEBUG = 0;
|
||||
static nsresult setAttribute( nsIWebShell *shell,
|
||||
const char *id,
|
||||
const char *name,
|
||||
const nsString &value )
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = shell ? shell->GetContentViewer(getter_AddRefs(cv))
|
||||
: NS_ERROR_NULL_POINTER;
|
||||
if ( cv ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
if ( docv ) {
|
||||
// Get the document from the doc viewer.
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
rv = docv->GetDocument(*getter_AddRefs(doc));
|
||||
if ( doc ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );
|
||||
if ( xulDoc ) {
|
||||
// Find specified element.
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = xulDoc->GetElementById( id, getter_AddRefs(elem) );
|
||||
if ( elem ) {
|
||||
// Set the text attribute.
|
||||
rv = elem->SetAttribute( name, value );
|
||||
if ( rv != NS_OK ) {
|
||||
if (APP_DEBUG) printf("SetAttribute failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDOMXULDocument failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// Do startup stuff from C++ side.
|
||||
NS_IMETHODIMP
|
||||
nsFindDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Save web shell pointer.
|
||||
mWebShell = nsDontQueryInterface<nsIWebShell>( aWebShell );
|
||||
|
||||
// Store instance information into dialog's DOM.
|
||||
if ( mContext ) {
|
||||
setAttribute( mWebShell,
|
||||
"data.searchString",
|
||||
"value",
|
||||
mContext->mSearchString );
|
||||
setAttribute( mWebShell,
|
||||
"data.ignoreCase",
|
||||
"value",
|
||||
mContext->mIgnoreCase ? "true" : "false" );
|
||||
setAttribute( mWebShell,
|
||||
"data.searchBackward",
|
||||
"value",
|
||||
mContext->mSearchBackwards ? "true" : "false" );
|
||||
setAttribute( mWebShell,
|
||||
"data.wrap",
|
||||
"value",
|
||||
mContext->mWrapSearch ? "true" : "false" );
|
||||
}
|
||||
|
||||
// Add as observer of the xul document.
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = mWebShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if ( cv ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
if ( docv ) {
|
||||
// Get the document from the doc viewer.
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
rv = docv->GetDocument(*getter_AddRefs(doc));
|
||||
if ( doc ) {
|
||||
doc->AddObserver( this );
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Utility function to close a window given a root nsIWebShell.
|
||||
static void closeWindow( nsIWebShellWindow *aWebShellWindow ) {
|
||||
if ( aWebShellWindow ) {
|
||||
// crashes!
|
||||
aWebShellWindow->Close();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle attribute changing; we only care about the element "data.execute"
|
||||
// which is used to signal command execution from the UI.
|
||||
NS_IMETHODIMP
|
||||
nsFindDialog::AttributeChanged( nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint ) {
|
||||
nsresult rv = NS_OK;
|
||||
// Look for data.execute command changing.
|
||||
nsString id;
|
||||
nsCOMPtr<nsIAtom> atomId = nsDontQueryInterface<nsIAtom>( NS_NewAtom("id") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomId, id );
|
||||
if ( id == "data.execute" ) {
|
||||
nsString cmd;
|
||||
nsCOMPtr<nsIAtom> atomCommand = nsDontQueryInterface<nsIAtom>( NS_NewAtom("command") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomCommand, cmd );
|
||||
if ( cmd == "find" ) {
|
||||
OnFind( aContent );
|
||||
} else if ( cmd == "next" ) {
|
||||
OnNext();
|
||||
} else if ( cmd == "cancel" ) {
|
||||
OnCancel();
|
||||
} else {
|
||||
}
|
||||
// Reset command so we detect next request.
|
||||
aContent->SetAttribute( kNameSpaceID_None, atomCommand, "", PR_FALSE );
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// OnOK
|
||||
void
|
||||
nsFindDialog::OnFind( nsIContent *aContent )
|
||||
{
|
||||
if ( mWebShell && mContext )
|
||||
{
|
||||
nsAutoString valueStr;
|
||||
|
||||
// Get arguments and store into the search context.
|
||||
nsCOMPtr<nsIAtom> atomKey = nsDontQueryInterface<nsIAtom>( NS_NewAtom("key") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomKey, mContext->mSearchString );
|
||||
|
||||
nsCOMPtr<nsIAtom> atomIgnoreCase = nsDontQueryInterface<nsIAtom>( NS_NewAtom("ignoreCase") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomIgnoreCase, valueStr );
|
||||
mContext->mIgnoreCase = (valueStr == "true");
|
||||
|
||||
nsCOMPtr<nsIAtom> atomSearchBackwards = nsDontQueryInterface<nsIAtom>( NS_NewAtom("searchBackwards") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomSearchBackwards, valueStr );
|
||||
mContext->mSearchBackwards = (valueStr == "true");
|
||||
|
||||
nsCOMPtr<nsIAtom> atomWrapSearch = nsDontQueryInterface<nsIAtom>( NS_NewAtom("wrap") );
|
||||
aContent->GetAttribute( kNameSpaceID_None, atomWrapSearch, valueStr );
|
||||
mContext->mWrapSearch = (valueStr == "true");
|
||||
|
||||
// Search for next occurrence.
|
||||
if ( mComponent )
|
||||
{
|
||||
// Find next occurrence in this context.
|
||||
mComponent->FindNext(mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OnOK
|
||||
void
|
||||
nsFindDialog::OnNext()
|
||||
{
|
||||
if ( mContext && mComponent )
|
||||
{
|
||||
// Find next occurrence in this context.
|
||||
mComponent->FindNext(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsFindDialog::OnCancel()
|
||||
{
|
||||
// Close the window.
|
||||
closeWindow( mWindow );
|
||||
}
|
||||
|
||||
void
|
||||
nsFindDialog::SetWindow( nsIWebShellWindow *aWindow )
|
||||
{
|
||||
mWindow = nsDontQueryInterface<nsIWebShellWindow>(aWindow);
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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 "nsIXULWindowCallbacks.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
|
||||
|
||||
// Cribbed from nsFileDownloadDialog in nsBrowsrAppCore.cpp. I really must
|
||||
// figure out how to make this more reusable...
|
||||
class nsFindDialog : public nsIXULWindowCallbacks,
|
||||
nsIDocumentObserver
|
||||
{
|
||||
public:
|
||||
// Declare implementation of ISupports stuff.
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
// Declare implementations of nsIXULWindowCallbacks interface functions.
|
||||
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
|
||||
|
||||
// Declare implementations of nsIDocumentObserver functions.
|
||||
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsISupports* aSubContent) { return NS_OK; }
|
||||
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
|
||||
nsIContent* aContent1,
|
||||
nsIContent* aContent2) { return NS_OK; }
|
||||
// This one we care about; see implementation below.
|
||||
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint);
|
||||
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
PRInt32 aNewIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
||||
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
||||
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet,
|
||||
PRBool aDisabled) { return NS_OK; }
|
||||
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule,
|
||||
PRInt32 aHint) { return NS_OK; }
|
||||
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule) { return NS_OK; }
|
||||
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule) { return NS_OK; }
|
||||
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) { return NS_OK; }
|
||||
|
||||
// nsFindDialog stuff
|
||||
nsFindDialog( nsIFindComponent *aComponent,
|
||||
nsFindComponent::Context *aContext );
|
||||
virtual ~nsFindDialog() { NS_IF_RELEASE(mContext); }
|
||||
void OnFind( nsIContent *aContent );
|
||||
void OnNext();
|
||||
void OnCancel();
|
||||
void SetWindow( nsIWebShellWindow *aWindow );
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIFindComponent> mComponent;
|
||||
nsFindComponent::Context *mContext;
|
||||
nsCOMPtr<nsIWebShell> mWebShell;
|
||||
nsCOMPtr<nsIWebShellWindow> mWindow;
|
||||
}; // nsFindDialog
|
||||
|
Загрузка…
Ссылка в новой задаче