Fix the document state listener mechanism so that you can install listeners after the editor has been created, and still get their 'document creation' notification called.

This commit is contained in:
sfraser%netscape.com 1999-08-03 06:53:45 +00:00
parent 31272b88d1
commit bbeffd28f0
7 changed files with 37 additions and 5 deletions

View File

@ -596,12 +596,19 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell)
// Set the selection to the beginning:
BeginningOfDocument();
NS_POSTCONDITION(mDoc && mPresShell, "bad state");
return NS_OK;
}
NS_IMETHODIMP
nsEditor::PostCreate()
{
// update the UI with our state
NotifyDocumentListeners(eDocumentCreated);
NotifyDocumentListeners(eDocumentStateChanged);
NS_POSTCONDITION(mDoc && mPresShell, "bad state");
return NS_OK;
}

View File

@ -143,6 +143,8 @@ public:
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
NS_IMETHOD PostCreate();
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
NS_IMETHOD GetBodyElement(nsIDOMElement **aElement);

View File

@ -823,6 +823,10 @@ nsEditorShell::PrepareDocumentForEditing(nsIURI *aUrl)
rv = editor->AddDocumentStateListener(mStateMaintainer);
if (NS_FAILED(rv)) return rv;
// now all the listeners are set up, we can call PostCreate
rv = editor->PostCreate();
if (NS_FAILED(rv)) return rv;
#if 0
// get the URL of the page we are editing
// does not work currently, because file URL has /usr/local/bin crap in it.

View File

@ -823,6 +823,10 @@ nsEditorShell::PrepareDocumentForEditing(nsIURI *aUrl)
rv = editor->AddDocumentStateListener(mStateMaintainer);
if (NS_FAILED(rv)) return rv;
// now all the listeners are set up, we can call PostCreate
rv = editor->PostCreate();
if (NS_FAILED(rv)) return rv;
#if 0
// get the URL of the page we are editing
// does not work currently, because file URL has /usr/local/bin crap in it.

View File

@ -596,12 +596,19 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell)
// Set the selection to the beginning:
BeginningOfDocument();
NS_POSTCONDITION(mDoc && mPresShell, "bad state");
return NS_OK;
}
NS_IMETHODIMP
nsEditor::PostCreate()
{
// update the UI with our state
NotifyDocumentListeners(eDocumentCreated);
NotifyDocumentListeners(eDocumentStateChanged);
NS_POSTCONDITION(mDoc && mPresShell, "bad state");
return NS_OK;
}

View File

@ -143,6 +143,8 @@ public:
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
NS_IMETHOD PostCreate();
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
NS_IMETHOD GetBodyElement(nsIDOMElement **aElement);

View File

@ -82,7 +82,7 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IEDITOR_IID; return iid; }
/**
* Init tells is to tell the implementation of nsIEditor to begin its services
* Init is to tell the implementation of nsIEditor to begin its services
* @param aDoc The dom document interface being observed
* @param aPresShell TEMP: The presentation shell displaying the document
* once events can tell us from what pres shell they originated,
@ -91,6 +91,12 @@ public:
*/
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell )=0;
/**
* PostCreate should be called after Init, and is the time that the editor tells
* its documentStateObservers that the document has been created.
*/
NS_IMETHOD PostCreate()=0;
/**
* return the DOM Document this editor is associated with
*