Anchor Find off nsIWebShell rather than nsIDocument

This commit is contained in:
law%netscape.com 1999-04-27 04:21:12 +00:00
Родитель 1163aed6bc
Коммит 1693e3c00f
4 изменённых файлов: 57 добавлений и 35 удалений

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

@ -1644,8 +1644,7 @@ nsBrowserAppCore::InitializeSearch() {
if ( NS_SUCCEEDED( rv ) && !mSearchContext ) {
// Create the search context for this browser window.
nsCOMPtr<nsIDocument> document = getDocument( mContentAreaWebShell );
nsresult rv = mFindComponent->CreateContext( document, &mSearchContext );
nsresult rv = mFindComponent->CreateContext( mContentAreaWebShell, &mSearchContext );
if ( NS_FAILED( rv ) ) {
#ifdef NS_DEBUG
printf( "%s %d CreateContext failed, rv=0x%X\n",
@ -1655,13 +1654,13 @@ nsBrowserAppCore::InitializeSearch() {
}
}
//Obsolete, to be removed.
void
nsBrowserAppCore::ResetSearchContext() {
// Test if we've created the search context yet.
if ( mFindComponent && mSearchContext ) {
// OK, reset it.
nsCOMPtr<nsIDocument> document = getDocument( mContentAreaWebShell );
nsresult rv = mFindComponent->ResetContext( mSearchContext, document );
nsresult rv = mFindComponent->ResetContext( mSearchContext, mContentAreaWebShell );
if ( NS_FAILED( rv ) ) {
#ifdef NS_DEBUG
printf( "%s %d ResetContext failed, rv=0x%X\n",

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

@ -20,7 +20,7 @@
#include "nsIAppShellComponent.h"
class nsIDocument;
class nsIWebShell;
// a6cf90ee-15b3-11d2-932e-00805f8add32
#define NS_IFINDCOMPONENT_IID \
@ -47,7 +47,9 @@ class nsIDocument;
| in this manner: |
| 1. Hold a reference to the singleton "find component". |
| 2. On initial search, ask that component to create a search "context." |
| 3. Reset the context whenever the underlying document changes. |
| 3. Reset the context whenever the underlying web shell changes (but since |
| a browser will usually reuse a single web shell, this won't be of |
| concern except in obscure cases). |
| 4. Forward "find" and "find next" requests to the component, along |
| with the appropriate search context object. |
| 5. Release() the search context object and the find component when the |
@ -59,7 +61,7 @@ struct nsIFindComponent : public nsIAppShellComponent {
/*---------------------------- CreateContext -------------------------------
| Create a "search context" for the given document. Subsequent Find and |
| FindNext requests that provide the returned search context will find |
| the appropriate search string in aDocument. |
| the appropriate search string in aWebShell. |
| |
| The result is of the xpcom equivalent of an opaque type. It's true type |
| is defined by the implementation of this interface. Clients ought never |
@ -67,7 +69,7 @@ struct nsIFindComponent : public nsIAppShellComponent {
| Clients do have to call Release() when they're no longer interested in |
| this search context. |
--------------------------------------------------------------------------*/
NS_IMETHOD CreateContext( nsIDocument *aDocument,
NS_IMETHOD CreateContext( nsIWebShell *aWebShell,
nsISupports **aResult ) = 0;
/*--------------------------------- Find -----------------------------------
@ -93,20 +95,21 @@ struct nsIFindComponent : public nsIAppShellComponent {
NS_IMETHOD FindNext( nsISupports *aContext ) = 0;
/*----------------------------- ResetContext -------------------------------
| Reset the given search context to search a new document. This is |
| intended to be called when the user goes to a new page. |
| Reset the given search context to search a new web shell. Generally, |
| this will be the equivalent of calling Release() on the old context and |
| then creating a new one for aNewWebShell. |
--------------------------------------------------------------------------*/
NS_IMETHOD ResetContext( nsISupports *aContext,
nsIDocument *aDocument ) = 0;
nsIWebShell *aNewWebShell ) = 0;
}; // nsIFindComponent
#define NS_DECL_IFINDCOMPONENT \
NS_IMETHOD CreateContext( nsIDocument *aDocument, \
NS_IMETHOD CreateContext( nsIWebShell *aWebShell, \
nsISupports **aResult ); \
NS_IMETHOD Find( nsISupports *aContext ); \
NS_IMETHOD FindNext( nsISupports *aContext ); \
NS_IMETHOD ResetContext( nsISupports *aContext, \
nsIDocument *aDocument );
nsIWebShell *aNewWebShell );
#endif

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

@ -109,7 +109,7 @@ nsFindComponent::Initialize( nsIAppShellService *appShell,
}
NS_IMETHODIMP
nsFindComponent::CreateContext( nsIDocument *aDocument,
nsFindComponent::CreateContext( nsIWebShell *aWebShell,
nsISupports **aResult )
{
@ -124,7 +124,7 @@ nsFindComponent::CreateContext( nsIDocument *aDocument,
// Do the expected AddRef on behalf of caller.
newContext->AddRef();
nsresult rv = newContext->Init( aDocument,
nsresult rv = newContext->Init( aWebShell,
mLastSearchString,
mLastIgnoreCase,
mLastSearchBackwards,
@ -157,16 +157,14 @@ nsFindComponent::Context::~Context()
}
NS_IMETHODIMP
nsFindComponent::Context::Init( nsIDocument *aDocument,
nsFindComponent::Context::Init( nsIWebShell *aWebShell,
const nsString &lastSearchString,
const nsString &lastIgnoreCase,
const nsString &lastSearchBackward,
const nsString &lastWrapSearch)
{
if (!aDocument)
if (!aWebShell)
return NS_ERROR_INVALID_ARG;
mSearchString = lastSearchString;
@ -175,7 +173,7 @@ nsFindComponent::Context::Init( nsIDocument *aDocument,
mWrapSearch = PR_FALSE; //(lastWrapSearch == "true");
// Construct nsITextServicesDocument...
nsresult rv = MakeTSDocument(aDocument);
nsresult rv = MakeTSDocument(aWebShell);
return rv;
}
@ -186,9 +184,9 @@ static NS_DEFINE_IID(kITextServicesDocumentIID, NS_ITEXTSERVICESDOCUMENT_IID);
NS_IMETHODIMP
nsFindComponent::Context::MakeTSDocument(nsIDocument *aDocument)
nsFindComponent::Context::MakeTSDocument(nsIWebShell *aWebShell)
{
if (!aDocument)
if (!aWebShell)
return NS_ERROR_INVALID_ARG;
nsITextServicesDocument *textSvcDoc;
@ -201,10 +199,32 @@ nsFindComponent::Context::MakeTSDocument(nsIDocument *aDocument)
if (NS_FAILED(rv))
return rv;
nsIPresShell *aPresShell = aDocument->GetShellAt(0); // I have no idea if this is always valid
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
rv = textSvcDoc->InitWithDocument(domDoc, aPresShell);
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIPresShell> presShell;
// Get content viewer from the web shell.
nsCOMPtr<nsIContentViewer> contentViewer;
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
: NS_ERROR_NULL_POINTER;
if ( contentViewer ) {
// Up-cast to a document viewer.
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
if ( docViewer ) {
// Get the document and pres shell from the doc viewer.
rv = docViewer->GetDocument(*getter_AddRefs(document));
if ( document ) {
rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
}
}
}
if ( !document || !presShell ) {
return rv;
}
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(document);
rv = textSvcDoc->InitWithDocument(domDoc, presShell);
if (NS_FAILED(rv))
return rv;
@ -433,14 +453,14 @@ nsFindComponent::Context::DoFind()
NS_IMETHODIMP
nsFindComponent::Context::Reset( nsIDocument *aNewDocument )
nsFindComponent::Context::Reset( nsIWebShell *aNewWebShell )
{
if (!aNewDocument)
if (!aNewWebShell)
return NS_ERROR_INVALID_ARG;
// Reconstruct nsITextServicesDocument?...
return MakeTSDocument(aNewDocument);
return MakeTSDocument(aNewWebShell);
}
@ -518,12 +538,12 @@ nsFindComponent::FindNext(nsISupports *aContext)
NS_IMETHODIMP
nsFindComponent::ResetContext( nsISupports *aContext,
nsIDocument *aNewDocument ) {
nsIWebShell *aNewWebShell ) {
nsresult rv = NS_OK;
if ( aContext && aNewDocument ) {
if ( aContext && aNewWebShell ) {
// Pass on the new document to the context.
Context *context = (Context*)aContext;
context->Reset( aNewDocument );
context->Reset( aNewWebShell );
} else {
rv = NS_ERROR_NULL_POINTER;
}

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

@ -49,14 +49,14 @@ public:
Context();
virtual ~Context();
NS_IMETHOD Init( nsIDocument *aDocument,
NS_IMETHOD Init( nsIWebShell *aWebShell,
const nsString &lastSearchString,
const nsString &lastIgnoreCase,
const nsString &lastSearchBackwards,
const nsString &lastWrapSearch);
NS_IMETHOD MakeTSDocument( nsIDocument *aNewDocument );
NS_IMETHOD Reset( nsIDocument *aNewDocument );
NS_IMETHOD MakeTSDocument( nsIWebShell *aNewWebShell );
NS_IMETHOD Reset( nsIWebShell *aNewWebShell );
NS_IMETHOD DoFind();
// Maybe add Find/FindNext functions here?