Split plaintext methods off into nsIPlaintextEditor API. sr=sfraser, r=jfrancis

This commit is contained in:
akkana%netscape.com 2000-11-17 00:25:31 +00:00
parent 98e58dcf47
commit d20c260cc6
30 changed files with 325 additions and 528 deletions

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "TextEditorTest.h"
#include "nsISelection.h"
#include "nsIDOMCharacterData.h"
@ -70,15 +71,13 @@ nsresult TextEditorTest::RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsF
// shouldn't we just bail on error here?
// insert some simple text
nsString docContent; docContent.AssignWithConversion("1234567890abcdefghij1234567890");
result = mTextEditor->InsertText(docContent);
result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
TEST_RESULT(result);
(*outNumTests)++;
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
// insert some more text
nsString docContent2; docContent2.AssignWithConversion("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere");
result = mTextEditor->InsertText(docContent2);
result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere"));
TEST_RESULT(result);
(*outNumTests)++;
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
@ -122,13 +121,13 @@ nsresult TextEditorTest::TestInsertBreak()
selection->Collapse(anchor, 0);
// insert one break
printf("inserting a break\n");
result = mTextEditor->InsertBreak();
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
mEditor->DebugDumpContent();
// insert a second break adjacent to the first
printf("inserting a second break\n");
result = mTextEditor->InsertBreak();
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
mEditor->DebugDumpContent();
@ -166,17 +165,23 @@ nsresult TextEditorTest::TestTextProperties()
textData->GetLength(&length);
selection->Collapse(textNode, 0);
selection->Extend(textNode, length);
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
if (!htmlEditor)
return NS_ERROR_FAILURE;
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first=PR_FALSE;
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_FALSE==first, "first should be false");
NS_ASSERTION(PR_FALSE==any, "any should be false");
NS_ASSERTION(PR_FALSE==all, "all should be false");
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
@ -185,9 +190,9 @@ nsresult TextEditorTest::TestTextProperties()
// remove the bold we just set
printf("set the whole first text node to not bold\n");
result = mTextEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
result = htmlEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_FALSE==first, "first should be false");
NS_ASSERTION(PR_FALSE==any, "any should be false");
@ -198,23 +203,23 @@ nsresult TextEditorTest::TestTextProperties()
printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-1);
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
NS_ASSERTION(PR_TRUE==all, "all should be true");
mEditor->DebugDumpContent();
// make all that same text italic
result = mTextEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
NS_ASSERTION(PR_TRUE==all, "all should be true");
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
@ -235,9 +240,9 @@ nsresult TextEditorTest::TestTextProperties()
NS_ASSERTION(length==915, "wrong text node");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-2);
result = mTextEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");

View File

@ -27,7 +27,7 @@
#include "nsCOMPtr.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
class TextEditorTest
{
@ -48,7 +48,7 @@ protected:
nsresult TestTextProperties();
nsCOMPtr<nsIHTMLEditor> mTextEditor;
nsCOMPtr<nsIPlaintextEditor> mTextEditor;
nsCOMPtr<nsIEditor> mEditor;
};

View File

@ -21,6 +21,7 @@
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsEditorEventListeners.h"
#include "nsIPlaintextEditor.h"
#include "nsEditor.h"
#include "nsVoidArray.h"
#include "nsString.h"
@ -183,8 +184,9 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
else
return NS_ERROR_FAILURE; // Editor unable to handle this.
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (!htmlEditor) return NS_ERROR_NO_INTERFACE;
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor) return NS_ERROR_NO_INTERFACE;
// if there is no charCode, then it's a key that doesn't map to a character,
// so look for special keys using keyCode
@ -242,7 +244,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK; // let it be used for focus switching
// else we insert the tab straight through
htmlEditor->EditorKeyPress(keyEvent);
textEditor->HandleKeyPress(keyEvent);
ScrollSelectionIntoView(mEditor);
aKeyEvent->PreventDefault(); // consumed
return NS_OK;
@ -252,7 +254,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
if (!(flags & nsIHTMLEditor::eEditorSingleLineMask))
{
//htmlEditor->InsertBreak();
htmlEditor->EditorKeyPress(keyEvent);
textEditor->HandleKeyPress(keyEvent);
ScrollSelectionIntoView(mEditor);
aKeyEvent->PreventDefault(); // consumed
}
@ -260,7 +262,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
}
if (NS_SUCCEEDED(htmlEditor->EditorKeyPress(keyEvent)))
if (NS_SUCCEEDED(textEditor->HandleKeyPress(keyEvent)))
ScrollSelectionIntoView(mEditor);
return NS_OK; // we don't PreventDefault() here or keybindings like control-x won't work
@ -708,9 +710,8 @@ nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
if (NS_FAILED(rv) || !selection)
return rv?rv:NS_ERROR_FAILURE;
nsCOMPtr<nsIEditor> editor = do_QueryInterface(htmlEditor);
nsCOMPtr<nsIDOMDocument> domdoc;
rv = editor->GetDocument(getter_AddRefs(domdoc));
rv = mEditor->GetDocument(getter_AddRefs(domdoc));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMDocument> sourceDoc;

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include "nsEditorShell.h"
#include "nsIPlaintextEditor.h"
#include "nsIWebShell.h"
#include "nsIBaseWindow.h"
#include "nsIContentViewerFile.h"
@ -627,7 +628,9 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
//mContentWindow->Focus();
// Collapse the selection to the begining of the document
// (this also turns on the caret)
mEditor->SetCaretToDocumentStart();
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (textEditor)
textEditor->CollapseSelectionToStart();
}
// show the caret, if our window is focussed already
@ -1601,7 +1604,7 @@ nsEditorShell::UnregisterDocumentStateListener(nsIDocumentStateListener *docList
nsCOMPtr<nsISupports> iSupports = do_QueryInterface(docListener, &rv);
if (NS_FAILED(rv)) return rv;
PRBool removed = mDocStateListeners->RemoveElement(iSupports);
mDocStateListeners->RemoveElement(iSupports);
}
// if we have an editor already, remove it from there too
@ -2652,7 +2655,10 @@ nsEditorShell::Rewrap(PRBool aRespectNewlines)
rv = SelectAll();
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(wrapped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(wrapped.GetUnicode());
}
else // rewrap only the selection
{
@ -2670,7 +2676,10 @@ nsEditorShell::Rewrap(PRBool aRespectNewlines)
wrapped);
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(wrapped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(wrapped.GetUnicode());
}
return NS_OK;
}
@ -2716,7 +2725,10 @@ nsEditorShell::StripCites()
rv = SelectAll();
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(stripped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(stripped.GetUnicode());
}
else // rewrap only the selection
{
@ -2732,7 +2744,10 @@ nsEditorShell::StripCites()
rv = citer->StripCites(current, stripped);
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(stripped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(stripped.GetUnicode());
}
return NS_OK;
}
@ -2787,48 +2802,19 @@ nsEditorShell::DeleteSelection(PRInt32 action)
return err;
}
/* This routine should only be called when playing back a log */
NS_IMETHODIMP
nsEditorShell::TypedText(const PRUnichar *aTextToInsert, PRInt32 aAction)
{
nsresult err = NS_NOINTERFACE;
nsAutoString textToInsert(aTextToInsert);
switch (mEditorType)
{
case ePlainTextEditorType:
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->TypedText(textToInsert, aAction);
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorShell::InsertText(const PRUnichar *textToInsert)
{
nsresult err = NS_NOINTERFACE;
nsAutoString aTextToInsert(textToInsert);
switch (mEditorType)
{
case ePlainTextEditorType:
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->InsertText(aTextToInsert);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (textEditor)
err = textEditor->InsertText(textToInsert);
}
break;
@ -2919,12 +2905,11 @@ nsEditorShell::RebuildDocumentFromSource(const PRUnichar *aSource)
NS_IMETHODIMP
nsEditorShell::InsertBreak()
{
nsresult err = NS_NOINTERFACE;
if (mEditor)
err = mEditor->InsertBreak();
return err;
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertLineBreak();
}
// Both Find and FindNext call through here.
@ -3290,11 +3275,11 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
{
PRInt32 wc;
err = mailEditor->GetBodyWrapWidth(&wc);
err = textEditor->GetBodyWrapWidth(&wc);
if (NS_SUCCEEDED(err))
*aWrapColumn = (PRInt32)wc;
}
@ -3320,9 +3305,9 @@ nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
err = mailEditor->SetBodyWrapWidth(mWrapColumn);
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->SetBodyWrapWidth(mWrapColumn);
}
break;
default:
@ -3455,9 +3440,9 @@ nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable)
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentLength(aDocumentLength);
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
return textEditor->GetTextLength(aDocumentLength);
return NS_NOINTERFACE;
}

View File

@ -1664,7 +1664,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
PRUint32 len;
nodeAsText = do_QueryInterface(startNode);
nodeAsText->GetLength(&len);
if (len>startOffset)
if (len > (PRUint32)startOffset)
{
res = mEditor->DeleteText(nodeAsText,startOffset,len-startOffset);
if (NS_FAILED(res)) return res;
@ -5228,7 +5228,7 @@ nsHTMLEditRules::DoTextNodeWhitespace(nsIDOMCharacterData *aTextNode, PRInt32 aS
runStart = -1; // reset our run
}
j++; // next char please!
} while (j<tempString.Length());
} while ((PRUint32)j < tempString.Length());
return res;
}

View File

@ -45,14 +45,11 @@
#include "nsIDOMHTMLImageElement.h"
#include "nsISelectionController.h"
#include "nsIFrameSelection.h" // For TABLESELECTION_ defines
#include "nsIIndependentSelection.h" //domselections answer to frameselection
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIHTMLContentContainer.h"
#include "nsIStyleSet.h"
#include "nsIDocumentObserver.h"
#include "nsIDocumentStateListener.h"
@ -362,6 +359,11 @@ NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
*aInstancePtr = nsnull;
if (aIID.Equals(NS_GET_IID(nsIPlaintextEditor))) {
*aInstancePtr = NS_STATIC_CAST(nsIPlaintextEditor*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIHTMLEditor))) {
*aInstancePtr = NS_STATIC_CAST(nsIHTMLEditor*, this);
NS_ADDREF_THIS();
@ -699,7 +701,7 @@ PRBool nsHTMLEditor::IsModifiable()
#pragma mark -
#endif
NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
{
PRUint32 keyCode, character;
PRBool isShift, ctrlKey, altKey, metaKey;
@ -754,21 +756,21 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
else if (keyCode == nsIDOMKeyEvent::DOM_VK_RETURN
|| keyCode == nsIDOMKeyEvent::DOM_VK_ENTER)
{
nsAutoString empty;
nsString empty;
if (isShift && !(mFlags&eEditorPlaintextBit))
{
return TypedText(empty, eTypedBR); // only inserts a br node
return TypedText(empty.GetUnicode(), eTypedBR); // only inserts a br node
}
else
{
return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert
return TypedText(empty.GetUnicode(), eTypedBreak); // uses rules to figure out what to insert
}
}
else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE)
{
// pass escape keypresses through as empty strings: needed forime support
nsAutoString empty;
return TypedText(empty, eTypedText);
nsString empty;
return TypedText(empty.GetUnicode(), eTypedText);
}
// if we got here we either fell out of the tab case or have a normal character.
@ -776,7 +778,7 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
if (character && !altKey && !ctrlKey && !isShift && !metaKey)
{
nsAutoString key(character);
return TypedText(key, eTypedText);
return TypedText(key.GetUnicode(), eTypedText);
}
}
return NS_ERROR_FAILURE;
@ -788,7 +790,8 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
to TypedText() to determine what action to take, but without passing
an event.
*/
NS_IMETHODIMP nsHTMLEditor::TypedText(const nsString& aString, PRInt32 aAction)
NS_IMETHODIMP nsHTMLEditor::TypedText(const PRUnichar* aString,
PRInt32 aAction)
{
nsAutoPlaceHolderBatch batch(this, gTypingTxnName);
@ -805,7 +808,7 @@ NS_IMETHODIMP nsHTMLEditor::TypedText(const nsString& aString, PRInt32 aAction)
}
case eTypedBreak:
{
return InsertBreak(); // uses rules to figure out what to insert
return InsertLineBreak(); // uses rules to figure out what to insert
}
}
return NS_ERROR_FAILURE;
@ -2118,17 +2121,17 @@ nsresult nsHTMLEditor::GetTextSelectionOffsets(nsISelection *aSelection,
aOutStartOffset, aOutEndOffset);
}
// this is a complete ripoff from nsTextEditor::GetTextSelectionOffsetsForRange
// the two should use common code, or even just be one method
nsresult nsHTMLEditor::GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
PRInt32 aInStartOffset,
nsIDOMNode *aInEndNode,
PRInt32 aInEndOffset,
nsIDOMNode *aInCommonParentNode,
PRInt32 &aOutStartOffset,
PRInt32 &aOutEndOffset)
nsresult
nsHTMLEditor::GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
PRInt32 aInStartOffset,
nsIDOMNode *aInEndNode,
PRInt32 aInEndOffset,
nsIDOMNode *aInCommonParentNode,
PRInt32 &aOutStartOffset,
PRInt32 &aOutEndOffset)
{
if(!aInStartNode || !aInEndNode || !aInCommonParentNode) { return NS_ERROR_NULL_POINTER; }
if(!aInStartNode || !aInEndNode || !aInCommonParentNode)
return NS_ERROR_NULL_POINTER;
nsresult result;
// initialize out params
@ -2250,7 +2253,7 @@ nsHTMLEditor::GetDOMEventReceiver(nsIDOMEventReceiver **aEventReceiver)
}
NS_IMETHODIMP
nsHTMLEditor::SetCaretToDocumentStart()
nsHTMLEditor::CollapseSelectionToStart()
{
nsCOMPtr<nsIDOMElement> bodyElement;
nsresult res = nsEditor::GetRootElement(getter_AddRefs(bodyElement));
@ -2381,7 +2384,7 @@ NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::EDirection aAction)
return result;
}
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
NS_IMETHODIMP nsHTMLEditor::InsertText(const PRUnichar* aStringToInsert)
{
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
@ -2402,8 +2405,11 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
if (NS_FAILED(result)) return result;
if (!selection) return NS_ERROR_NULL_POINTER;
nsAutoString resultString;
// XXX can we trust instring to outlive ruleInfo,
// XXX and ruleInfo not to refer to instring in its dtor?
nsAutoString instring(aStringToInsert);
nsTextRulesInfo ruleInfo(theAction);
ruleInfo.inString = &aStringToInsert;
ruleInfo.inString = &instring;
ruleInfo.outString = &resultString;
ruleInfo.maxLength = mMaxTextLength;
@ -3144,7 +3150,7 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsString& aSourceString)
return CloneAttributes(bodyElement, child);
}
NS_IMETHODIMP nsHTMLEditor::InsertBreak()
NS_IMETHODIMP nsHTMLEditor::InsertLineBreak()
{
nsresult res;
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
@ -4005,7 +4011,7 @@ nsHTMLEditor::Indent(const nsString& aIndent)
nsCOMPtr<nsIDOMNode> parent = node;
nsCOMPtr<nsIDOMNode> topChild = node;
nsCOMPtr<nsIDOMNode> tmp;
nsAutoString bq; bq.AssignWithConversion("blockquote");
nsAutoString bq(NS_LITERAL_STRING("blockquote"));
while ( !CanContainTag(parent, bq))
{
parent->GetParentNode(getter_AddRefs(tmp));
@ -4028,8 +4034,7 @@ nsHTMLEditor::Indent(const nsString& aIndent)
// put a space in it so layout will draw the list item
res = selection->Collapse(newBQ,0);
if (NS_FAILED(res)) return res;
nsAutoString theText; theText.AssignWithConversion(" ");
res = InsertText(theText);
res = InsertText(NS_LITERAL_STRING(" "));
if (NS_FAILED(res)) return res;
// reposition selection to before the space character
res = GetStartNodeAndOffset(selection, &node, &offset);
@ -4625,54 +4630,6 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n
return res;
}
/*
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
*/
NS_IMETHODIMP
nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
@ -4685,9 +4642,8 @@ nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
return mRules->DocumentIsEmpty(aDocumentIsEmpty);
}
NS_IMETHODIMP
nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
nsHTMLEditor::GetTextLength(PRInt32 *aCount)
{
if (!aCount) { return NS_ERROR_NULL_POINTER; }
nsresult result;
@ -4737,15 +4693,19 @@ nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
return result;
}
NS_IMETHODIMP nsHTMLEditor::SetMaxTextLength(PRInt32 aMaxTextLength)
NS_IMETHODIMP
nsHTMLEditor::SetMaxTextLength(PRInt32 aMaxTextLength)
{
mMaxTextLength = aMaxTextLength;
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::GetMaxTextLength(PRInt32& aMaxTextLength)
NS_IMETHODIMP
nsHTMLEditor::GetMaxTextLength(PRInt32* aMaxTextLength)
{
aMaxTextLength = mMaxTextLength;
if (!aMaxTextLength)
return NS_ERROR_INVALID_POINTER;
*aMaxTextLength = mMaxTextLength;
return NS_OK;
}
@ -5325,7 +5285,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
nsAutoEditBatch beginBatching(this);
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
rv = InsertText(stuffToPaste);
rv = InsertText(stuffToPaste.GetUnicode());
if (text)
nsMemory::Free(text);
}
@ -6078,7 +6038,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedText,
selection->Collapse(preNode, 0);
}
rv = InsertText(quotedStuff);
rv = InsertText(quotedStuff.GetUnicode());
if (aNodeInserted && NS_SUCCEEDED(rv))
{
@ -6151,7 +6111,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
res = InsertHTMLWithCharset(aQuotedText, aCharset);
else
res = InsertText(aQuotedText); // XXX ignore charset
res = InsertText(aQuotedText.GetUnicode()); // XXX ignore charset
if (aNodeInserted)
{
@ -6604,7 +6564,7 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
mIMETextRangeList = aTextRangeList;
nsAutoPlaceHolderBatch batch(this, gIMETxnName);
result = InsertText(aCompositionString);
result = InsertText(aCompositionString.GetUnicode());
mIMEBufferLength = aCompositionString.Length();
@ -7164,9 +7124,11 @@ nsHTMLEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parent
}
// Here's where the new node was inserted
}
#ifdef DEBUG
else {
printf("InsertBreak into an empty document is not yet supported\n");
printf("InsertLineBreak into an empty document is not yet supported\n");
}
#endif
return result;
}

View File

@ -25,6 +25,7 @@
#include "nsCOMPtr.h"
#include "nsIPlaintextEditor.h"
#include "nsIHTMLEditor.h"
#include "nsITableEditor.h"
#include "nsIEditorMailSupport.h"
@ -49,14 +50,13 @@ class nsIDOMEventReceiver;
* Use to edit HTML document represented as a DOM tree.
*/
class nsHTMLEditor : public nsEditor,
public nsIPlaintextEditor,
public nsIHTMLEditor,
public nsIEditorMailSupport,
public nsITableEditor,
public nsIEditorStyleSheets,
public nsICSSLoaderObserver
{
typedef enum {eNoOp, eReplaceParent=1, eInsertParent=2} BlockTransformationType;
public:
@ -87,16 +87,10 @@ public:
nsHTMLEditor();
virtual ~nsHTMLEditor();
/* ------------ nsIPlaintextEditor methods -------------- */
NS_DECL_NSIPLAINTEXTEDITOR
/* ------------ nsIHTMLEditor methods -------------- */
NS_IMETHOD EditorKeyPress(nsIDOMKeyEvent* aKeyEvent);
NS_IMETHOD TypedText(const nsString& aString, PRInt32 aAction);
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);
NS_IMETHOD SetInlineProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue);
@ -116,19 +110,15 @@ public:
NS_IMETHOD IncreaseFontSize();
NS_IMETHOD DecreaseFontSize();
NS_IMETHOD InsertBreak();
NS_IMETHOD InsertText(const nsString& aStringToInsert);
NS_IMETHOD InsertHTML(const nsString &aInputString);
NS_IMETHOD InsertHTMLWithCharset(const nsString& aInputString,
const nsString& aCharset);
NS_IMETHOD RebuildDocumentFromSource(const nsString& aSourceString);
NS_IMETHOD InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection);
NS_IMETHOD DeleteSelection(EDirection aAction);
NS_IMETHOD DeleteSelectionAndCreateNode(const nsString& aTag, nsIDOMNode ** aNewNode);
NS_IMETHOD SelectElement(nsIDOMElement* aElement);
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement);
NS_IMETHOD SetCaretToDocumentStart();
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
@ -175,8 +165,6 @@ public:
/* ------------ nsIEditorMailSupport methods -------------- */
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn);
NS_IMETHOD PasteAsQuotation(PRInt32 aSelectionType);
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText, nsIDOMNode **aNodeInserted);
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation,
@ -250,6 +238,10 @@ public:
/** prepare the editor for use */
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD DeleteSelection(EDirection aAction);
NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet);
/** we override this here to install event listeners */
@ -307,6 +299,7 @@ public:
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify);
/* ------------ Utility Routines, not part of public API -------------- */
NS_IMETHOD TypedText(const PRUnichar* aString, PRInt32 aAction);
nsresult InsertNodeAtPoint(nsIDOMNode *aNode,
nsIDOMNode *aParent,
PRInt32 aOffset,
@ -608,8 +601,10 @@ protected:
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mIsComposing;
PRInt32 mMaxTextLength;
// Used by nsIPlaintextEditor but not html editors -- factor me!
PRInt32 mMaxTextLength;
nsCOMPtr<nsIAtom> mBoldAtom;
nsCOMPtr<nsIAtom> mItalicAtom;
nsCOMPtr<nsIAtom> mUnderlineAtom;

View File

@ -160,28 +160,7 @@ nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction)
}
NS_IMETHODIMP
nsHTMLEditorLog::TypedText(const nsString& aStringToInsert, PRInt32 aAction)
{
nsAutoHTMLEditorLogLock logLock(this);
if (!mLocked && mFileSpec)
{
PrintSelection();
Write("window.editorShell.TypedText(\"");
PrintUnicode(aStringToInsert);
Write("\", ");
WriteInt("%d", aAction);
Write(");\n");
Flush();
}
return nsHTMLEditor::TypedText(aStringToInsert, aAction);
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
nsHTMLEditorLog::InsertText(const PRUnichar* aStringToInsert)
{
nsAutoHTMLEditorLogLock logLock(this);
@ -190,7 +169,8 @@ nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
PrintSelection();
Write("window.editorShell.InsertText(\"");
PrintUnicode(aStringToInsert);
nsAutoString str(aStringToInsert);
PrintUnicode(str);
Write("\");\n");
Flush();
@ -200,7 +180,7 @@ nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertBreak()
nsHTMLEditorLog::InsertLineBreak()
{
nsAutoHTMLEditorLogLock logLock(this);
@ -211,7 +191,7 @@ nsHTMLEditorLog::InsertBreak()
Flush();
}
return nsHTMLEditor::InsertBreak();
return nsHTMLEditor::InsertLineBreak();
}
NS_IMETHODIMP

View File

@ -58,9 +58,8 @@ public:
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute);
NS_IMETHOD DeleteSelection(nsIEditor::EDirection aAction);
NS_IMETHOD TypedText(const nsString& aString, PRInt32 aAction);
NS_IMETHOD InsertText(const nsString& aStringToInsert);
NS_IMETHOD InsertBreak();
NS_IMETHOD InsertText(const PRUnichar* aStringToInsert);
NS_IMETHOD InsertLineBreak();
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD BeginTransaction();

View File

@ -1308,7 +1308,7 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsISelection *aSelection,
// If (resultingDocLength) + (length of input) > max,
// set aOutString to subset of inString so length = max
PRInt32 docLength;
res = mEditor->GetDocumentLength(&docLength);
res = mEditor->GetTextLength(&docLength);
if (NS_FAILED(res)) { return res; }
PRInt32 start, end;
res = mEditor->GetTextSelectionOffsets(aSelection, start, end);

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include "nsEditorShell.h"
#include "nsIPlaintextEditor.h"
#include "nsIWebShell.h"
#include "nsIBaseWindow.h"
#include "nsIContentViewerFile.h"
@ -627,7 +628,9 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
//mContentWindow->Focus();
// Collapse the selection to the begining of the document
// (this also turns on the caret)
mEditor->SetCaretToDocumentStart();
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (textEditor)
textEditor->CollapseSelectionToStart();
}
// show the caret, if our window is focussed already
@ -1601,7 +1604,7 @@ nsEditorShell::UnregisterDocumentStateListener(nsIDocumentStateListener *docList
nsCOMPtr<nsISupports> iSupports = do_QueryInterface(docListener, &rv);
if (NS_FAILED(rv)) return rv;
PRBool removed = mDocStateListeners->RemoveElement(iSupports);
mDocStateListeners->RemoveElement(iSupports);
}
// if we have an editor already, remove it from there too
@ -2652,7 +2655,10 @@ nsEditorShell::Rewrap(PRBool aRespectNewlines)
rv = SelectAll();
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(wrapped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(wrapped.GetUnicode());
}
else // rewrap only the selection
{
@ -2670,7 +2676,10 @@ nsEditorShell::Rewrap(PRBool aRespectNewlines)
wrapped);
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(wrapped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(wrapped.GetUnicode());
}
return NS_OK;
}
@ -2716,7 +2725,10 @@ nsEditorShell::StripCites()
rv = SelectAll();
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(stripped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(stripped.GetUnicode());
}
else // rewrap only the selection
{
@ -2732,7 +2744,10 @@ nsEditorShell::StripCites()
rv = citer->StripCites(current, stripped);
if (NS_FAILED(rv)) return rv;
return mEditor->InsertText(stripped);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertText(stripped.GetUnicode());
}
return NS_OK;
}
@ -2787,48 +2802,19 @@ nsEditorShell::DeleteSelection(PRInt32 action)
return err;
}
/* This routine should only be called when playing back a log */
NS_IMETHODIMP
nsEditorShell::TypedText(const PRUnichar *aTextToInsert, PRInt32 aAction)
{
nsresult err = NS_NOINTERFACE;
nsAutoString textToInsert(aTextToInsert);
switch (mEditorType)
{
case ePlainTextEditorType:
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->TypedText(textToInsert, aAction);
}
break;
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
return err;
}
NS_IMETHODIMP
nsEditorShell::InsertText(const PRUnichar *textToInsert)
{
nsresult err = NS_NOINTERFACE;
nsAutoString aTextToInsert(textToInsert);
switch (mEditorType)
{
case ePlainTextEditorType:
case eHTMLTextEditorType:
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
err = htmlEditor->InsertText(aTextToInsert);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (textEditor)
err = textEditor->InsertText(textToInsert);
}
break;
@ -2919,12 +2905,11 @@ nsEditorShell::RebuildDocumentFromSource(const PRUnichar *aSource)
NS_IMETHODIMP
nsEditorShell::InsertBreak()
{
nsresult err = NS_NOINTERFACE;
if (mEditor)
err = mEditor->InsertBreak();
return err;
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor)
return NS_NOINTERFACE;
return textEditor->InsertLineBreak();
}
// Both Find and FindNext call through here.
@ -3290,11 +3275,11 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
{
PRInt32 wc;
err = mailEditor->GetBodyWrapWidth(&wc);
err = textEditor->GetBodyWrapWidth(&wc);
if (NS_SUCCEEDED(err))
*aWrapColumn = (PRInt32)wc;
}
@ -3320,9 +3305,9 @@ nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
{
case ePlainTextEditorType:
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
err = mailEditor->SetBodyWrapWidth(mWrapColumn);
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->SetBodyWrapWidth(mWrapColumn);
}
break;
default:
@ -3455,9 +3440,9 @@ nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable)
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
if (editor)
return editor->GetDocumentLength(aDocumentLength);
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
return textEditor->GetTextLength(aDocumentLength);
return NS_NOINTERFACE;
}

View File

@ -20,6 +20,7 @@
# This is a list of local files which get copied to the mozilla:dist:editor directory
#
nsIPlaintextEditor.idl
nsIEditorShell.idl
nsIEditorSpellCheck.idl
nsIDocumentStateListener.idl

View File

@ -29,6 +29,7 @@ include $(DEPTH)/config/autoconf.mk
MODULE = editor
XPIDLSRCS = \
nsIPlaintextEditor.idl \
nsIEditorShell.idl \
nsIEditorSpellCheck.idl \
nsIDocumentStateListener.idl \

View File

@ -28,6 +28,7 @@ MODULE=editor
XPIDL_MODULE=editor
XPIDLSRCS = .\nsIEditorShell.idl \
.\nsIPlaintextEditor.idl \
.\nsIEditorSpellCheck.idl \
.\nsIDocumentStateListener.idl \
.\nsIEditorService.idl \

View File

@ -189,10 +189,8 @@ interface nsIEditorShell : nsISupports
/* Charset Menu */
wstring GetDocumentCharacterSet();
void SetDocumentCharacterSet(in wstring characterSet);
/* Structure change */
/* TypedText actionToTake param is an enum - values in nsIHTMLEditor.h */
void TypedText(in wstring textToInsert, in PRInt32 actionToTake);
void InsertText(in wstring textToInsert);
/* Insert HTML source at current location (replace current selection) */
void InsertSource(in wstring textToInsert);

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "TextEditorTest.h"
#include "nsISelection.h"
#include "nsIDOMCharacterData.h"
@ -70,15 +71,13 @@ nsresult TextEditorTest::RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsF
// shouldn't we just bail on error here?
// insert some simple text
nsString docContent; docContent.AssignWithConversion("1234567890abcdefghij1234567890");
result = mTextEditor->InsertText(docContent);
result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
TEST_RESULT(result);
(*outNumTests)++;
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
// insert some more text
nsString docContent2; docContent2.AssignWithConversion("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere");
result = mTextEditor->InsertText(docContent2);
result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere"));
TEST_RESULT(result);
(*outNumTests)++;
(*outNumTestsFailed) += (NS_FAILED(result) != NS_OK);
@ -122,13 +121,13 @@ nsresult TextEditorTest::TestInsertBreak()
selection->Collapse(anchor, 0);
// insert one break
printf("inserting a break\n");
result = mTextEditor->InsertBreak();
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
mEditor->DebugDumpContent();
// insert a second break adjacent to the first
printf("inserting a second break\n");
result = mTextEditor->InsertBreak();
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
mEditor->DebugDumpContent();
@ -166,17 +165,23 @@ nsresult TextEditorTest::TestTextProperties()
textData->GetLength(&length);
selection->Collapse(textNode, 0);
selection->Extend(textNode, length);
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
if (!htmlEditor)
return NS_ERROR_FAILURE;
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first=PR_FALSE;
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_FALSE==first, "first should be false");
NS_ASSERTION(PR_FALSE==any, "any should be false");
NS_ASSERTION(PR_FALSE==all, "all should be false");
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
@ -185,9 +190,9 @@ nsresult TextEditorTest::TestTextProperties()
// remove the bold we just set
printf("set the whole first text node to not bold\n");
result = mTextEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
result = htmlEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_FALSE==first, "first should be false");
NS_ASSERTION(PR_FALSE==any, "any should be false");
@ -198,23 +203,23 @@ nsresult TextEditorTest::TestTextProperties()
printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-1);
result = mTextEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
NS_ASSERTION(PR_TRUE==all, "all should be true");
mEditor->DebugDumpContent();
// make all that same text italic
result = mTextEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
NS_ASSERTION(PR_TRUE==all, "all should be true");
result = mTextEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");
@ -235,9 +240,9 @@ nsresult TextEditorTest::TestTextProperties()
NS_ASSERTION(length==915, "wrong text node");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-2);
result = mTextEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
result = htmlEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
TEST_RESULT(result);
result = mTextEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
result = htmlEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
TEST_RESULT(result);
NS_ASSERTION(PR_TRUE==first, "first should be true");
NS_ASSERTION(PR_TRUE==any, "any should be true");

View File

@ -27,7 +27,7 @@
#include "nsCOMPtr.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
class TextEditorTest
{
@ -48,7 +48,7 @@ protected:
nsresult TestTextProperties();
nsCOMPtr<nsIHTMLEditor> mTextEditor;
nsCOMPtr<nsIPlaintextEditor> mTextEditor;
nsCOMPtr<nsIEditor> mEditor;
};

View File

@ -1664,7 +1664,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
PRUint32 len;
nodeAsText = do_QueryInterface(startNode);
nodeAsText->GetLength(&len);
if (len>startOffset)
if (len > (PRUint32)startOffset)
{
res = mEditor->DeleteText(nodeAsText,startOffset,len-startOffset);
if (NS_FAILED(res)) return res;
@ -5228,7 +5228,7 @@ nsHTMLEditRules::DoTextNodeWhitespace(nsIDOMCharacterData *aTextNode, PRInt32 aS
runStart = -1; // reset our run
}
j++; // next char please!
} while (j<tempString.Length());
} while ((PRUint32)j < tempString.Length());
return res;
}

View File

@ -45,14 +45,11 @@
#include "nsIDOMHTMLImageElement.h"
#include "nsISelectionController.h"
#include "nsIFrameSelection.h" // For TABLESELECTION_ defines
#include "nsIIndependentSelection.h" //domselections answer to frameselection
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIHTMLContentContainer.h"
#include "nsIStyleSet.h"
#include "nsIDocumentObserver.h"
#include "nsIDocumentStateListener.h"
@ -362,6 +359,11 @@ NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
*aInstancePtr = nsnull;
if (aIID.Equals(NS_GET_IID(nsIPlaintextEditor))) {
*aInstancePtr = NS_STATIC_CAST(nsIPlaintextEditor*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIHTMLEditor))) {
*aInstancePtr = NS_STATIC_CAST(nsIHTMLEditor*, this);
NS_ADDREF_THIS();
@ -699,7 +701,7 @@ PRBool nsHTMLEditor::IsModifiable()
#pragma mark -
#endif
NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
{
PRUint32 keyCode, character;
PRBool isShift, ctrlKey, altKey, metaKey;
@ -754,21 +756,21 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
else if (keyCode == nsIDOMKeyEvent::DOM_VK_RETURN
|| keyCode == nsIDOMKeyEvent::DOM_VK_ENTER)
{
nsAutoString empty;
nsString empty;
if (isShift && !(mFlags&eEditorPlaintextBit))
{
return TypedText(empty, eTypedBR); // only inserts a br node
return TypedText(empty.GetUnicode(), eTypedBR); // only inserts a br node
}
else
{
return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert
return TypedText(empty.GetUnicode(), eTypedBreak); // uses rules to figure out what to insert
}
}
else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE)
{
// pass escape keypresses through as empty strings: needed forime support
nsAutoString empty;
return TypedText(empty, eTypedText);
nsString empty;
return TypedText(empty.GetUnicode(), eTypedText);
}
// if we got here we either fell out of the tab case or have a normal character.
@ -776,7 +778,7 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
if (character && !altKey && !ctrlKey && !isShift && !metaKey)
{
nsAutoString key(character);
return TypedText(key, eTypedText);
return TypedText(key.GetUnicode(), eTypedText);
}
}
return NS_ERROR_FAILURE;
@ -788,7 +790,8 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
to TypedText() to determine what action to take, but without passing
an event.
*/
NS_IMETHODIMP nsHTMLEditor::TypedText(const nsString& aString, PRInt32 aAction)
NS_IMETHODIMP nsHTMLEditor::TypedText(const PRUnichar* aString,
PRInt32 aAction)
{
nsAutoPlaceHolderBatch batch(this, gTypingTxnName);
@ -805,7 +808,7 @@ NS_IMETHODIMP nsHTMLEditor::TypedText(const nsString& aString, PRInt32 aAction)
}
case eTypedBreak:
{
return InsertBreak(); // uses rules to figure out what to insert
return InsertLineBreak(); // uses rules to figure out what to insert
}
}
return NS_ERROR_FAILURE;
@ -2118,17 +2121,17 @@ nsresult nsHTMLEditor::GetTextSelectionOffsets(nsISelection *aSelection,
aOutStartOffset, aOutEndOffset);
}
// this is a complete ripoff from nsTextEditor::GetTextSelectionOffsetsForRange
// the two should use common code, or even just be one method
nsresult nsHTMLEditor::GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
PRInt32 aInStartOffset,
nsIDOMNode *aInEndNode,
PRInt32 aInEndOffset,
nsIDOMNode *aInCommonParentNode,
PRInt32 &aOutStartOffset,
PRInt32 &aOutEndOffset)
nsresult
nsHTMLEditor::GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
PRInt32 aInStartOffset,
nsIDOMNode *aInEndNode,
PRInt32 aInEndOffset,
nsIDOMNode *aInCommonParentNode,
PRInt32 &aOutStartOffset,
PRInt32 &aOutEndOffset)
{
if(!aInStartNode || !aInEndNode || !aInCommonParentNode) { return NS_ERROR_NULL_POINTER; }
if(!aInStartNode || !aInEndNode || !aInCommonParentNode)
return NS_ERROR_NULL_POINTER;
nsresult result;
// initialize out params
@ -2250,7 +2253,7 @@ nsHTMLEditor::GetDOMEventReceiver(nsIDOMEventReceiver **aEventReceiver)
}
NS_IMETHODIMP
nsHTMLEditor::SetCaretToDocumentStart()
nsHTMLEditor::CollapseSelectionToStart()
{
nsCOMPtr<nsIDOMElement> bodyElement;
nsresult res = nsEditor::GetRootElement(getter_AddRefs(bodyElement));
@ -2381,7 +2384,7 @@ NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::EDirection aAction)
return result;
}
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
NS_IMETHODIMP nsHTMLEditor::InsertText(const PRUnichar* aStringToInsert)
{
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
@ -2402,8 +2405,11 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
if (NS_FAILED(result)) return result;
if (!selection) return NS_ERROR_NULL_POINTER;
nsAutoString resultString;
// XXX can we trust instring to outlive ruleInfo,
// XXX and ruleInfo not to refer to instring in its dtor?
nsAutoString instring(aStringToInsert);
nsTextRulesInfo ruleInfo(theAction);
ruleInfo.inString = &aStringToInsert;
ruleInfo.inString = &instring;
ruleInfo.outString = &resultString;
ruleInfo.maxLength = mMaxTextLength;
@ -3144,7 +3150,7 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsString& aSourceString)
return CloneAttributes(bodyElement, child);
}
NS_IMETHODIMP nsHTMLEditor::InsertBreak()
NS_IMETHODIMP nsHTMLEditor::InsertLineBreak()
{
nsresult res;
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
@ -4005,7 +4011,7 @@ nsHTMLEditor::Indent(const nsString& aIndent)
nsCOMPtr<nsIDOMNode> parent = node;
nsCOMPtr<nsIDOMNode> topChild = node;
nsCOMPtr<nsIDOMNode> tmp;
nsAutoString bq; bq.AssignWithConversion("blockquote");
nsAutoString bq(NS_LITERAL_STRING("blockquote"));
while ( !CanContainTag(parent, bq))
{
parent->GetParentNode(getter_AddRefs(tmp));
@ -4028,8 +4034,7 @@ nsHTMLEditor::Indent(const nsString& aIndent)
// put a space in it so layout will draw the list item
res = selection->Collapse(newBQ,0);
if (NS_FAILED(res)) return res;
nsAutoString theText; theText.AssignWithConversion(" ");
res = InsertText(theText);
res = InsertText(NS_LITERAL_STRING(" "));
if (NS_FAILED(res)) return res;
// reposition selection to before the space character
res = GetStartNodeAndOffset(selection, &node, &offset);
@ -4625,54 +4630,6 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n
return res;
}
/*
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
*/
NS_IMETHODIMP
nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
{
@ -4685,9 +4642,8 @@ nsHTMLEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
return mRules->DocumentIsEmpty(aDocumentIsEmpty);
}
NS_IMETHODIMP
nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
nsHTMLEditor::GetTextLength(PRInt32 *aCount)
{
if (!aCount) { return NS_ERROR_NULL_POINTER; }
nsresult result;
@ -4737,15 +4693,19 @@ nsHTMLEditor::GetDocumentLength(PRInt32 *aCount)
return result;
}
NS_IMETHODIMP nsHTMLEditor::SetMaxTextLength(PRInt32 aMaxTextLength)
NS_IMETHODIMP
nsHTMLEditor::SetMaxTextLength(PRInt32 aMaxTextLength)
{
mMaxTextLength = aMaxTextLength;
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::GetMaxTextLength(PRInt32& aMaxTextLength)
NS_IMETHODIMP
nsHTMLEditor::GetMaxTextLength(PRInt32* aMaxTextLength)
{
aMaxTextLength = mMaxTextLength;
if (!aMaxTextLength)
return NS_ERROR_INVALID_POINTER;
*aMaxTextLength = mMaxTextLength;
return NS_OK;
}
@ -5325,7 +5285,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
nsAutoEditBatch beginBatching(this);
// pasting does not inherit local inline styles
RemoveAllInlineProperties();
rv = InsertText(stuffToPaste);
rv = InsertText(stuffToPaste.GetUnicode());
if (text)
nsMemory::Free(text);
}
@ -6078,7 +6038,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedText,
selection->Collapse(preNode, 0);
}
rv = InsertText(quotedStuff);
rv = InsertText(quotedStuff.GetUnicode());
if (aNodeInserted && NS_SUCCEEDED(rv))
{
@ -6151,7 +6111,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
res = InsertHTMLWithCharset(aQuotedText, aCharset);
else
res = InsertText(aQuotedText); // XXX ignore charset
res = InsertText(aQuotedText.GetUnicode()); // XXX ignore charset
if (aNodeInserted)
{
@ -6604,7 +6564,7 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
mIMETextRangeList = aTextRangeList;
nsAutoPlaceHolderBatch batch(this, gIMETxnName);
result = InsertText(aCompositionString);
result = InsertText(aCompositionString.GetUnicode());
mIMEBufferLength = aCompositionString.Length();
@ -7164,9 +7124,11 @@ nsHTMLEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parent
}
// Here's where the new node was inserted
}
#ifdef DEBUG
else {
printf("InsertBreak into an empty document is not yet supported\n");
printf("InsertLineBreak into an empty document is not yet supported\n");
}
#endif
return result;
}

View File

@ -25,6 +25,7 @@
#include "nsCOMPtr.h"
#include "nsIPlaintextEditor.h"
#include "nsIHTMLEditor.h"
#include "nsITableEditor.h"
#include "nsIEditorMailSupport.h"
@ -49,14 +50,13 @@ class nsIDOMEventReceiver;
* Use to edit HTML document represented as a DOM tree.
*/
class nsHTMLEditor : public nsEditor,
public nsIPlaintextEditor,
public nsIHTMLEditor,
public nsIEditorMailSupport,
public nsITableEditor,
public nsIEditorStyleSheets,
public nsICSSLoaderObserver
{
typedef enum {eNoOp, eReplaceParent=1, eInsertParent=2} BlockTransformationType;
public:
@ -87,16 +87,10 @@ public:
nsHTMLEditor();
virtual ~nsHTMLEditor();
/* ------------ nsIPlaintextEditor methods -------------- */
NS_DECL_NSIPLAINTEXTEDITOR
/* ------------ nsIHTMLEditor methods -------------- */
NS_IMETHOD EditorKeyPress(nsIDOMKeyEvent* aKeyEvent);
NS_IMETHOD TypedText(const nsString& aString, PRInt32 aAction);
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);
NS_IMETHOD SetInlineProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue);
@ -116,19 +110,15 @@ public:
NS_IMETHOD IncreaseFontSize();
NS_IMETHOD DecreaseFontSize();
NS_IMETHOD InsertBreak();
NS_IMETHOD InsertText(const nsString& aStringToInsert);
NS_IMETHOD InsertHTML(const nsString &aInputString);
NS_IMETHOD InsertHTMLWithCharset(const nsString& aInputString,
const nsString& aCharset);
NS_IMETHOD RebuildDocumentFromSource(const nsString& aSourceString);
NS_IMETHOD InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection);
NS_IMETHOD DeleteSelection(EDirection aAction);
NS_IMETHOD DeleteSelectionAndCreateNode(const nsString& aTag, nsIDOMNode ** aNewNode);
NS_IMETHOD SelectElement(nsIDOMElement* aElement);
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement);
NS_IMETHOD SetCaretToDocumentStart();
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
@ -175,8 +165,6 @@ public:
/* ------------ nsIEditorMailSupport methods -------------- */
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn);
NS_IMETHOD PasteAsQuotation(PRInt32 aSelectionType);
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText, nsIDOMNode **aNodeInserted);
NS_IMETHOD PasteAsCitedQuotation(const nsString& aCitation,
@ -250,6 +238,10 @@ public:
/** prepare the editor for use */
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD DeleteSelection(EDirection aAction);
NS_IMETHOD SetDocumentCharacterSet(const PRUnichar* characterSet);
/** we override this here to install event listeners */
@ -307,6 +299,7 @@ public:
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify);
/* ------------ Utility Routines, not part of public API -------------- */
NS_IMETHOD TypedText(const PRUnichar* aString, PRInt32 aAction);
nsresult InsertNodeAtPoint(nsIDOMNode *aNode,
nsIDOMNode *aParent,
PRInt32 aOffset,
@ -608,8 +601,10 @@ protected:
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mIsComposing;
PRInt32 mMaxTextLength;
// Used by nsIPlaintextEditor but not html editors -- factor me!
PRInt32 mMaxTextLength;
nsCOMPtr<nsIAtom> mBoldAtom;
nsCOMPtr<nsIAtom> mItalicAtom;
nsCOMPtr<nsIAtom> mUnderlineAtom;

View File

@ -160,28 +160,7 @@ nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction)
}
NS_IMETHODIMP
nsHTMLEditorLog::TypedText(const nsString& aStringToInsert, PRInt32 aAction)
{
nsAutoHTMLEditorLogLock logLock(this);
if (!mLocked && mFileSpec)
{
PrintSelection();
Write("window.editorShell.TypedText(\"");
PrintUnicode(aStringToInsert);
Write("\", ");
WriteInt("%d", aAction);
Write(");\n");
Flush();
}
return nsHTMLEditor::TypedText(aStringToInsert, aAction);
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
nsHTMLEditorLog::InsertText(const PRUnichar* aStringToInsert)
{
nsAutoHTMLEditorLogLock logLock(this);
@ -190,7 +169,8 @@ nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
PrintSelection();
Write("window.editorShell.InsertText(\"");
PrintUnicode(aStringToInsert);
nsAutoString str(aStringToInsert);
PrintUnicode(str);
Write("\");\n");
Flush();
@ -200,7 +180,7 @@ nsHTMLEditorLog::InsertText(const nsString& aStringToInsert)
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertBreak()
nsHTMLEditorLog::InsertLineBreak()
{
nsAutoHTMLEditorLogLock logLock(this);
@ -211,7 +191,7 @@ nsHTMLEditorLog::InsertBreak()
Flush();
}
return nsHTMLEditor::InsertBreak();
return nsHTMLEditor::InsertLineBreak();
}
NS_IMETHODIMP

View File

@ -58,9 +58,8 @@ public:
NS_IMETHOD SetParagraphFormat(const nsString& aParagraphFormat);
NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute);
NS_IMETHOD DeleteSelection(nsIEditor::EDirection aAction);
NS_IMETHOD TypedText(const nsString& aString, PRInt32 aAction);
NS_IMETHOD InsertText(const nsString& aStringToInsert);
NS_IMETHOD InsertBreak();
NS_IMETHOD InsertText(const PRUnichar* aStringToInsert);
NS_IMETHOD InsertLineBreak();
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD BeginTransaction();

View File

@ -21,6 +21,7 @@
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsEditorEventListeners.h"
#include "nsIPlaintextEditor.h"
#include "nsEditor.h"
#include "nsVoidArray.h"
#include "nsString.h"
@ -183,8 +184,9 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
else
return NS_ERROR_FAILURE; // Editor unable to handle this.
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (!htmlEditor) return NS_ERROR_NO_INTERFACE;
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
if (!textEditor) return NS_ERROR_NO_INTERFACE;
// if there is no charCode, then it's a key that doesn't map to a character,
// so look for special keys using keyCode
@ -242,7 +244,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK; // let it be used for focus switching
// else we insert the tab straight through
htmlEditor->EditorKeyPress(keyEvent);
textEditor->HandleKeyPress(keyEvent);
ScrollSelectionIntoView(mEditor);
aKeyEvent->PreventDefault(); // consumed
return NS_OK;
@ -252,7 +254,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
if (!(flags & nsIHTMLEditor::eEditorSingleLineMask))
{
//htmlEditor->InsertBreak();
htmlEditor->EditorKeyPress(keyEvent);
textEditor->HandleKeyPress(keyEvent);
ScrollSelectionIntoView(mEditor);
aKeyEvent->PreventDefault(); // consumed
}
@ -260,7 +262,7 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
}
if (NS_SUCCEEDED(htmlEditor->EditorKeyPress(keyEvent)))
if (NS_SUCCEEDED(textEditor->HandleKeyPress(keyEvent)))
ScrollSelectionIntoView(mEditor);
return NS_OK; // we don't PreventDefault() here or keybindings like control-x won't work
@ -708,9 +710,8 @@ nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
if (NS_FAILED(rv) || !selection)
return rv?rv:NS_ERROR_FAILURE;
nsCOMPtr<nsIEditor> editor = do_QueryInterface(htmlEditor);
nsCOMPtr<nsIDOMDocument> domdoc;
rv = editor->GetDocument(getter_AddRefs(domdoc));
rv = mEditor->GetDocument(getter_AddRefs(domdoc));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMDocument> sourceDoc;

View File

@ -1308,7 +1308,7 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsISelection *aSelection,
// If (resultingDocLength) + (length of input) > max,
// set aOutString to subset of inString so length = max
PRInt32 docLength;
res = mEditor->GetDocumentLength(&docLength);
res = mEditor->GetTextLength(&docLength);
if (NS_FAILED(res)) { return res; }
PRInt32 start, end;
res = mEditor->GetTextSelectionOffsets(aSelection, start, end);

View File

@ -28,7 +28,7 @@
#include "nsIDOMNodeList.h"
#include "nsIDOMRange.h"
#include "nsISelection.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
#include "nsTextServicesDocument.h"
#include "nsIDOMElement.h"
@ -2072,9 +2072,9 @@ nsTextServicesDocument::InsertText(const nsString *aText)
return result;
}
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor, &result);
if (htmlEditor)
result = htmlEditor->InsertText(*aText);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor, &result));
if (textEditor)
result = textEditor->InsertText(aText->GetUnicode());
if (NS_FAILED(result))
{

View File

@ -39,19 +39,6 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IEDITORMAILSUPPORT_IID; return iid; }
/** Get and set the body wrap width
* @param aWrapColumn - the column to wrap at. This is set as a COLS attribute
* on a PRE block.
*
* Special values:
* 0 = wrap to window width
* -1 = no wrap at all
*
*/
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn)=0;
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn)=0;
/** paste the text in the OS clipboard at the cursor position
* as a quotation (whose representation is dependant on the editor type),
* replacing the selected text (if any)

View File

@ -39,9 +39,6 @@ class nsStringArray;
class nsIAtom;
class nsIDOMNode;
class nsIDOMElement;
class nsIDOMKeyEvent;
class nsIDOMEvent;
class nsIHTMLEditor : public nsISupports
{
@ -95,14 +92,6 @@ public:
eJustify
} EAlignment;
/* ------------ Document info methods -------------- */
/** get the length of the document in characters */
NS_IMETHOD GetDocumentLength(PRInt32 *aCount)=0;
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength)=0;
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength)=0;
/* ------------ Inline property methods -------------- */
@ -180,54 +169,27 @@ public:
*/
NS_IMETHOD DecreaseFontSize()=0;
/* ------------ HTML content methods -------------- */
/* ------------ Drag/Drop methods -------------- */
/**
* EditorKeyPress consumes a keyevent.
* @param aKeyEvent key event to consume
*/
NS_IMETHOD EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)=0;
/**
* TypedText responds to user typing. Provides a logging bottleneck for typing.
* @param aString string to type
* @param aAction action to take: insert text, insert BR, insert break
*/
NS_IMETHOD TypedText(const nsString& aString, PRInt32 aAction)=0;
/**
* CanDrag decides if a drag should be started (for example, based on the current selection and mousepoint).
* CanDrag decides if a drag should be started
* (for example, based on the current selection and mousepoint).
*/
NS_IMETHOD CanDrag(nsIDOMEvent *aEvent, PRBool &aCanDrag)=0;
/**
* DoDrag transfers the relevant data (as appropriate) to a transferable so it can later be dropped.
* DoDrag transfers the relevant data (as appropriate)
* to a transferable so it can later be dropped.
*/
NS_IMETHOD DoDrag(nsIDOMEvent *aEvent)=0;
/**
* InsertFromDrop looks for a dragsession and inserts the relevant data in response to a drop.
* InsertFromDrop looks for a dragsession and inserts the
* relevant data in response to a drop.
*/
NS_IMETHOD InsertFromDrop(nsIDOMEvent *aEvent)=0;
/**
* Insert a break into the content model.<br>
* The interpretation of a break is up to the rule system:
* it may enter a character, split a node in the tree, etc.
*/
NS_IMETHOD InsertBreak()=0;
/**
* InsertText() Inserts a string at the current location, given by the selection.
* If the selection is not collapsed, the selection is deleted and the insertion
* takes place at the resulting collapsed selection.
*
* NOTE: what happens if the string contains a CR?
*
* @param aString the string to be inserted
*/
NS_IMETHOD InsertText(const nsString& aStringToInsert)=0;
/* ------------ HTML content methods -------------- */
/**
* Insert some HTML source at the current location
@ -300,11 +262,6 @@ public:
*/
NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement)=0;
/**
* Set selection to start of document
*/
NS_IMETHOD SetCaretToDocumentStart()=0;
/**
* SetParagraphFormat Insert a block paragraph tag around selection
* @param aParagraphFormat "p", "h1" to "h6", "address", "pre", or "blockquote"

View File

@ -28,7 +28,7 @@
#include "nsIDOMNodeList.h"
#include "nsIDOMRange.h"
#include "nsISelection.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
#include "nsTextServicesDocument.h"
#include "nsIDOMElement.h"
@ -2072,9 +2072,9 @@ nsTextServicesDocument::InsertText(const nsString *aText)
return result;
}
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor, &result);
if (htmlEditor)
result = htmlEditor->InsertText(*aText);
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor, &result));
if (textEditor)
result = textEditor->InsertText(aText->GetUnicode());
if (NS_FAILED(result))
{

View File

@ -32,6 +32,7 @@
#include "nsIServiceManager.h"
#include "nsIFrameSelection.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
#include "nsFormControlHelper.h"
@ -56,7 +57,6 @@
#include "nsIDeviceContext.h" // to measure fonts
#include "nsIPresState.h" //for saving state
#include "nsLinebreakConverter.h" //to strip out carriage returns
#include "nsIEditorMailSupport.h"
#include "nsIContent.h"
#include "nsIAtom.h"
@ -1841,8 +1841,8 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext,
rv = NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEditorMailSupport> mailEditor(do_QueryInterface(mEditor));
if (mailEditor)
nsCOMPtr<nsIPlaintextEditor> textEditor(do_QueryInterface(mEditor));
if (textEditor)
{
nsHTMLValue colAttr;
nsresult colStatus;
@ -1876,21 +1876,16 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext,
col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
}
mailEditor->SetBodyWrapWidth(col);
textEditor->SetBodyWrapWidth(col);
delete spec;
}
}
// Set max text field length
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// Set max text field length
PRInt32 maxLength;
rv = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != rv)
{
htmlEditor->SetMaxTextLength(maxLength);
textEditor->SetMaxTextLength(maxLength);
}
}
@ -2657,16 +2652,16 @@ nsGfxTextControlFrame2::AttributeChanged(nsIPresContext* aPresContext,
PRInt32 maxLength;
nsresult rv = GetMaxLength(&maxLength);
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
{
if (NS_CONTENT_ATTR_NOT_THERE != rv)
{ // set the maxLength attribute
htmlEditor->SetMaxTextLength(maxLength);
textEditor->SetMaxTextLength(maxLength);
// if maxLength>docLength, we need to truncate the doc content
}
else { // unset the maxLength attribute
htmlEditor->SetMaxTextLength(-1);
textEditor->SetMaxTextLength(-1);
}
}
}
@ -3019,8 +3014,11 @@ nsGfxTextControlFrame2::SetTextControlFrameState(const nsAReadableString& aValue
mEditor->SetFlags(flags);
if (currentValue.Length() < 1)
mEditor->DeleteSelection(nsIEditor::eNone);
else
htmlEditor->InsertText(currentValue);
else {
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
textEditor->InsertText(currentValue.GetUnicode());
}
mEditor->SetFlags(savedFlags);
if (selPriv)
selPriv->EndBatchChanges();

View File

@ -54,7 +54,7 @@
#include "nsICharsetConverterManager.h"
#include "nsTextFormatter.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsIPlaintextEditor.h"
#include "nsEscape.h"
#include "plstr.h"
#include "nsIDocShell.h"
@ -312,8 +312,8 @@ nsresult nsMsgCompose::ConvertAndLoadComposeWindow(nsIEditorShell *aEditorShell,
// This should set the cursor after the body but before the sig
case 0 :
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
if (!htmlEditor)
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(editor);
if (!textEditor)
{
editor->BeginningOfDocument();
break;
@ -344,7 +344,7 @@ nsresult nsMsgCompose::ConvertAndLoadComposeWindow(nsIEditorShell *aEditorShell,
selection->Collapse(parent, offset+1);
// insert a break at current selection
htmlEditor->InsertBreak();
textEditor->InsertLineBreak();
// i'm not sure if you need to move the selection back to before the
// break. expirement.