Add DocumentIsEmpty to EditorShell.idl and nsIEditor, and modify length and content getters to do the right thing with an empty document (which contains the bogus text node).

git-svn-id: svn://10.0.0.236/trunk@46444 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sfraser%netscape.com
1999-09-08 23:32:04 +00:00
parent 3ecbeb8efc
commit 8a797c14a4
16 changed files with 196 additions and 22 deletions

View File

@@ -48,7 +48,7 @@ public:
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
NS_IMETHOD GetFlags(PRUint32 *aFlags)=0;
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
};
#endif //nsEditRules_h__

View File

@@ -121,6 +121,9 @@ public:
NS_IMETHOD BeginTransaction();
NS_IMETHOD EndTransaction();
// pure virtual, because the definition of 'empty' depends on the doc type
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
// file handling
NS_IMETHOD GetDocumentModified(PRBool *outDocModified);
NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet);

View File

@@ -2019,15 +2019,9 @@ nsEditorShell::GetEditorDocument(nsIDOMDocument** aEditorDocument)
NS_IMETHODIMP
nsEditorShell::GetEditorSelection(nsIDOMSelection** aEditorSelection)
{
if (mEditor)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetSelection(aEditorSelection);
}
}
return NS_NOINTERFACE;
}
@@ -2043,6 +2037,27 @@ nsEditorShell::GetDocumentModified(PRBool *aDocumentModified)
}
NS_IMETHODIMP
nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentIsEmpty(aDocumentIsEmpty);
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentLength(aDocumentLength);
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsEditorShell::InsertList(const PRUnichar *listType)
{

View File

@@ -2334,6 +2334,18 @@ NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
*/
NS_IMETHODIMP
nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
if (!aDocumentIsEmpty)
return NS_ERROR_NULL_POINTER;
if (!mRules)
return NS_ERROR_NOT_INITIALIZED;
return mRules->DocumentIsEmpty(aDocumentIsEmpty);
}
NS_IMETHODIMP
nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
@@ -2343,6 +2355,16 @@ nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
// initialize out params
*aCount = 0;
// special-case for empty document, to account for the bogus text node
PRBool docEmpty;
result = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(result)) return result;
if (docEmpty)
{
*aCount = 0;
return NS_OK;
}
nsCOMPtr<nsIDOMSelection> sel;
result = GetSelection(getter_AddRefs(sel));
if (NS_FAILED(result)) return result;
@@ -3017,6 +3039,24 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
// }
// else
// { // default processing
nsresult rv = NS_OK;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType == "text/plain")
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty) {
aOutputString = "";
return NS_OK;
}
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1);
if (! progid)
@@ -3025,7 +3065,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
char* type = aFormatType.ToNewCString();
strcat(progid, type);
nsCRT::free(type);
nsresult rv = nsComponentManager::CreateInstance(progid,
rv = nsComponentManager::CreateInstance(progid,
nsnull,
nsIDocumentEncoder::GetIID(),
getter_AddRefs(encoder));
@@ -3084,7 +3124,21 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString* aCharset,
PRUint32 aFlags)
{
nsresult rv;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType == "text/plain")
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty)
return NS_OK; // output nothing
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1);
if (! progid)

View File

@@ -60,6 +60,7 @@ public:
/* ------------ nsIHTMLEditor methods -------------- */
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);

View File

@@ -194,7 +194,17 @@ nsTextEditRules::DidDoAction(nsIDOMSelection *aSelection,
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTextEditRules::DocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
if (!aDocumentIsEmpty)
return NS_ERROR_NULL_POINTER;
*aDocumentIsEmpty = (mBogusNode.get() != nsnull);
return NS_OK;
}
/********************************************************
* Protected methods

View File

@@ -54,6 +54,7 @@ public:
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty);
// nsTextEditRules action id's
enum

View File

@@ -2019,15 +2019,9 @@ nsEditorShell::GetEditorDocument(nsIDOMDocument** aEditorDocument)
NS_IMETHODIMP
nsEditorShell::GetEditorSelection(nsIDOMSelection** aEditorSelection)
{
if (mEditor)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetSelection(aEditorSelection);
}
}
return NS_NOINTERFACE;
}
@@ -2043,6 +2037,27 @@ nsEditorShell::GetDocumentModified(PRBool *aDocumentModified)
}
NS_IMETHODIMP
nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentIsEmpty(aDocumentIsEmpty);
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentLength(aDocumentLength);
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsEditorShell::InsertList(const PRUnichar *listType)
{

View File

@@ -47,9 +47,11 @@ interface nsIEditorShell : nsISupports
};
%}
readonly attribute boolean documentModified;
readonly attribute boolean documentIsEmpty;
readonly attribute long documentLength;
attribute wstring paragraphFormat;
attribute long wrapColumn;
attribute wstring paragraphFormat;
attribute long wrapColumn;
/* Setup */
void SetEditorType(in wstring editorType);

View File

@@ -48,7 +48,7 @@ public:
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
NS_IMETHOD GetFlags(PRUint32 *aFlags)=0;
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
};
#endif //nsEditRules_h__

View File

@@ -121,6 +121,9 @@ public:
NS_IMETHOD BeginTransaction();
NS_IMETHOD EndTransaction();
// pure virtual, because the definition of 'empty' depends on the doc type
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
// file handling
NS_IMETHOD GetDocumentModified(PRBool *outDocModified);
NS_IMETHOD GetDocumentCharacterSet(PRUnichar** characterSet);

View File

@@ -2334,6 +2334,18 @@ NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
*/
NS_IMETHODIMP
nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
if (!aDocumentIsEmpty)
return NS_ERROR_NULL_POINTER;
if (!mRules)
return NS_ERROR_NOT_INITIALIZED;
return mRules->DocumentIsEmpty(aDocumentIsEmpty);
}
NS_IMETHODIMP
nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
@@ -2343,6 +2355,16 @@ nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
// initialize out params
*aCount = 0;
// special-case for empty document, to account for the bogus text node
PRBool docEmpty;
result = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(result)) return result;
if (docEmpty)
{
*aCount = 0;
return NS_OK;
}
nsCOMPtr<nsIDOMSelection> sel;
result = GetSelection(getter_AddRefs(sel));
if (NS_FAILED(result)) return result;
@@ -3017,6 +3039,24 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
// }
// else
// { // default processing
nsresult rv = NS_OK;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType == "text/plain")
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty) {
aOutputString = "";
return NS_OK;
}
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1);
if (! progid)
@@ -3025,7 +3065,7 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
char* type = aFormatType.ToNewCString();
strcat(progid, type);
nsCRT::free(type);
nsresult rv = nsComponentManager::CreateInstance(progid,
rv = nsComponentManager::CreateInstance(progid,
nsnull,
nsIDocumentEncoder::GetIID(),
getter_AddRefs(encoder));
@@ -3084,7 +3124,21 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString* aCharset,
PRUint32 aFlags)
{
nsresult rv;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType == "text/plain")
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty)
return NS_OK; // output nothing
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* progid = (char *)nsAllocator::Alloc(strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1);
if (! progid)

View File

@@ -60,6 +60,7 @@ public:
/* ------------ nsIHTMLEditor methods -------------- */
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);

View File

@@ -194,7 +194,17 @@ nsTextEditRules::DidDoAction(nsIDOMSelection *aSelection,
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTextEditRules::DocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
if (!aDocumentIsEmpty)
return NS_ERROR_NULL_POINTER;
*aDocumentIsEmpty = (mBogusNode.get() != nsnull);
return NS_OK;
}
/********************************************************
* Protected methods

View File

@@ -54,6 +54,7 @@ public:
NS_IMETHOD DidDoAction(nsIDOMSelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty);
// nsTextEditRules action id's
enum

View File

@@ -109,6 +109,10 @@ public:
/* ------------ Document info and file methods -------------- */
/** Returns true if the document has no *meaningful* content */
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
/** Returns true if the document is modifed and needs saving */
NS_IMETHOD GetDocumentModified(PRBool *outDocModified)=0;