Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends
nsPlaintextEditor Class Reference

The text editor implementation. More...

#include <nsPlaintextEditor.h>

Inheritance diagram for nsPlaintextEditor:
Inheritance graph
[legend]
Collaboration diagram for nsPlaintextEditor:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { eTypedText, eTypedBR, eTypedBreak }
enum  IterDirection { kIterForward, kIterBackward }
enum  OperationID {
  kOpIgnore = -1, kOpNone = 0, kOpUndo, kOpRedo,
  kOpInsertNode, kOpCreateNode, kOpDeleteNode, kOpSplitNode,
  kOpJoinNode, kOpDeleteSelection, kOpInsertBreak = 1000, kOpInsertText = 1001,
  kOpInsertIMEText = 1002, kOpDeleteText = 1003
}
typedef short EDirection

Public Member Functions

 nsPlaintextEditor ()
virtual ~nsPlaintextEditor ()
NS_DECL_NSIPLAINTEXTEDITOR
NS_DECL_NSIEDITORMAILSUPPORT
NS_IMETHOD 
SetCompositionString (const nsAString &aCompositionString, nsIPrivateTextRangeList *aTextRange, nsTextEventReply *aReply)
NS_IMETHOD GetReconversionString (nsReconversionEventReply *aReply)
NS_IMETHOD BeginComposition (nsTextEventReply *aReply)
NS_IMETHOD SetAttributeOrEquivalent (nsIDOMElement *aElement, const nsAString &aAttribute, const nsAString &aValue, PRBool aSuppressTransaction)
NS_IMETHOD RemoveAttributeOrEquivalent (nsIDOMElement *aElement, const nsAString &aAttribute, PRBool aSuppressTransaction)
NS_IMETHOD Init (nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags)
 prepare the editor for use
NS_IMETHOD GetDocumentIsEmpty (PRBool *aDocumentIsEmpty)
NS_IMETHOD GetIsDocumentEditable (PRBool *aIsDocumentEditable)
NS_IMETHOD DeleteSelection (EDirection aAction)
NS_IMETHOD SetDocumentCharacterSet (const nsACString &characterSet)
NS_IMETHOD GetFlags (PRUint32 *aFlags)
NS_IMETHOD SetFlags (PRUint32 aFlags)
NS_IMETHOD Undo (PRUint32 aCount)
NS_IMETHOD Redo (PRUint32 aCount)
NS_IMETHOD Cut ()
NS_IMETHOD CanCut (PRBool *aCanCut)
NS_IMETHOD Copy ()
NS_IMETHOD CanCopy (PRBool *aCanCopy)
NS_IMETHOD Paste (PRInt32 aSelectionType)
NS_IMETHOD CanPaste (PRInt32 aSelectionType, PRBool *aCanPaste)
NS_IMETHOD CanDrag (nsIDOMEvent *aDragEvent, PRBool *aCanDrag)
NS_IMETHOD DoDrag (nsIDOMEvent *aDragEvent)
NS_IMETHOD InsertFromDrop (nsIDOMEvent *aDropEvent)
NS_IMETHOD OutputToString (const nsAString &aFormatType, PRUint32 aFlags, nsAString &aOutputString)
NS_IMETHOD OutputToStream (nsIOutputStream *aOutputStream, const nsAString &aFormatType, const nsACString &aCharsetOverride, PRUint32 aFlags)
NS_IMETHOD StartOperation (PRInt32 opID, nsIEditor::EDirection aDirection)
 All editor operations which alter the doc should be prefaced with a call to StartOperation, naming the action and direction.
NS_IMETHOD EndOperation ()
 All editor operations which alter the doc should be followed with a call to EndOperation.
NS_IMETHOD SelectEntireDocument (nsISelection *aSelection)
 make the given selection span the entire document
NS_IMETHOD TypedText (const nsAString &aString, PRInt32 aAction)
nsresult GetTextSelectionOffsets (nsISelection *aSelection, PRUint32 &aStartOffset, PRUint32 &aEndOffset)
 Returns the absolute position of the end points of aSelection in the document as a text stream.
nsresult InsertTextAt (const nsAString &aStringToInsert, nsIDOMNode *aDestinationNode, PRInt32 aDestOffset, PRBool aDoDeleteSelection)
NS_DECL_ISUPPORTS NS_IMETHOD GetPresShell (nsIPresShell **aPS)
void NotifyEditorObservers (void)
NS_IMETHOD InsertTextImpl (const nsAString &aStringToInsert, nsCOMPtr< nsIDOMNode > *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc)
NS_IMETHOD InsertTextIntoTextNodeImpl (const nsAString &aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRBool suppressIME=PR_FALSE)
NS_IMETHOD DeleteSelectionImpl (EDirection aAction)
NS_IMETHOD DeleteSelectionAndCreateNode (const nsAString &aTag, nsIDOMNode **aNewNode)
nsresult ReplaceContainer (nsIDOMNode *inNode, nsCOMPtr< nsIDOMNode > *outNode, const nsAString &aNodeType, const nsAString *aAttribute=nsnull, const nsAString *aValue=nsnull, PRBool aCloneAttributes=PR_FALSE)
nsresult RemoveContainer (nsIDOMNode *inNode)
nsresult InsertContainerAbove (nsIDOMNode *inNode, nsCOMPtr< nsIDOMNode > *outNode, const nsAString &aNodeType, const nsAString *aAttribute=nsnull, const nsAString *aValue=nsnull)
nsresult MoveNode (nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset)
nsresult CreateHTMLContent (const nsAString &aTag, nsIContent **aContent)
PRBool ArePreservingSelection ()
 routines for managing the preservation of selection across various editor actions
nsresult PreserveSelectionAcrossActions (nsISelection *aSel)
nsresult RestorePreservedSelection (nsISelection *aSel)
void StopPreservingSelection ()
nsresult SplitNodeImpl (nsIDOMNode *aExistingRightNode, PRInt32 aOffset, nsIDOMNode *aNewLeftNode, nsIDOMNode *aParent)
 SplitNode() creates a new node identical to an existing node, and split the contents between the two nodes.
nsresult JoinNodesImpl (nsIDOMNode *aNodeToKeep, nsIDOMNode *aNodeToJoin, nsIDOMNode *aParent, PRBool aNodeToKeepIsFirst)
 JoinNodes() takes 2 nodes and merge their content|children.
nsresult GetPriorNode (nsIDOMNode *aCurrentNode, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
 get the node immediately prior to aCurrentNode
nsresult GetPriorNode (nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
nsresult GetNextNode (nsIDOMNode *aCurrentNode, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
 get the node immediately after to aCurrentNode
nsresult GetNextNode (nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
nsCOMPtr< nsIDOMNodeGetRightmostChild (nsIDOMNode *aCurrentNode, PRBool bNoBlockCrossing=PR_FALSE)
 Get the rightmost child of aCurrentNode; return nsnull if aCurrentNode has no children.
nsCOMPtr< nsIDOMNodeGetLeftmostChild (nsIDOMNode *aCurrentNode, PRBool bNoBlockCrossing=PR_FALSE)
 Get the leftmost child of aCurrentNode; return nsnull if aCurrentNode has no children.
PRBool CanContainTag (nsIDOMNode *aParent, const nsAString &aTag)
 returns PR_TRUE if aParent can contain a child of type aTag
PRBool TagCanContain (const nsAString &aParentTag, nsIDOMNode *aChild)
virtual PRBool TagCanContainTag (const nsAString &aParentTag, const nsAString &aChildTag)
PRBool IsRootNode (nsIDOMNode *inNode)
 returns PR_TRUE if aNode is our root node
PRBool IsDescendantOfBody (nsIDOMNode *inNode)
 returns PR_TRUE if aNode is a descendant of our root node
PRBool IsContainer (nsIDOMNode *aNode)
 returns PR_TRUE if aNode is a container
PRBool IsEditable (nsIDOMNode *aNode)
 returns PR_TRUE if aNode is an editable node
virtual PRBool IsTextInDirtyFrameVisible (nsIDOMNode *aNode)
PRBool IsMozEditorBogusNode (nsIDOMNode *aNode)
 returns PR_TRUE if aNode is a MozEditorBogus node
PRBool IsEmptyTextContent (nsIContent *aContent)
 returns PR_TRUE if content is an merely formatting whitespacce
nsresult CountEditableChildren (nsIDOMNode *aNode, PRUint32 &outCount)
 counts number of editable child nodes
nsresult GetFirstEditableNode (nsIDOMNode *aRoot, nsCOMPtr< nsIDOMNode > *outFirstNode)
 Find the deep first and last children.
nsresult GetIMEBufferLength (PRInt32 *length)
PRBool IsIMEComposing ()
void SetIsIMEComposing ()
virtual PRBool NodesSameType (nsIDOMNode *aNode1, nsIDOMNode *aNode2)
nsresult CreateRange (nsIDOMNode *aStartParent, PRInt32 aStartOffset, nsIDOMNode *aEndParent, PRInt32 aEndOffset, nsIDOMRange **aRange)
nsresult AppendNodeToSelectionAsRange (nsIDOMNode *aNode)
nsresult ClearSelection ()
nsresult IsPreformatted (nsIDOMNode *aNode, PRBool *aResult)
nsresult SplitNodeDeep (nsIDOMNode *aNode, nsIDOMNode *aSplitPointParent, PRInt32 aSplitPointOffset, PRInt32 *outOffset, PRBool aNoEmptyContainers=PR_FALSE, nsCOMPtr< nsIDOMNode > *outLeftNode=0, nsCOMPtr< nsIDOMNode > *outRightNode=0)
nsresult JoinNodeDeep (nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsCOMPtr< nsIDOMNode > *aOutJoinNode, PRInt32 *outOffset)
nsresult GetString (const nsAString &name, nsAString &value)
nsresult BeginUpdateViewBatch (void)
virtual nsresult EndUpdateViewBatch (void)
PRBool GetShouldTxnSetSelection ()
nsresult HandleInlineSpellCheck (PRInt32 action, nsISelection *aSelection, nsIDOMNode *previousSelectedNode, PRInt32 previousSelectedOffset, nsIDOMNode *aStartNode, PRInt32 aStartOffset, nsIDOMNode *aEndNode, PRInt32 aEndOffset)
already_AddRefed
< nsIDOMEventReceiver
GetDOMEventReceiver ()
nsIDOMElementGetRoot ()
nsIInlineSpellChecker getInlineSpellCheckerOptionally (in boolean autoCreate)
 Returns the inline spell checker associated with this object.
void syncRealTimeSpell ()
 Resyncs spellchecking state (enabled/disabled).
void setSpellcheckUserOverride (in boolean enable)
 Called when the user manually overrides the spellchecking state for this editor.
void init (in nsIDOMDocument doc, in nsIPresShellPtr shell, in nsIContentPtr aRoot, in nsISelectionController aSelCon, in unsigned long aFlags)
 Init is to tell the implementation of nsIEditor to begin its services.
void setAttributeOrEquivalent (in nsIDOMElement element, in AString sourceAttrName, in AString sourceAttrValue, in boolean aSuppressTransaction)
void removeAttributeOrEquivalent (in nsIDOMElement element, in DOMString sourceAttrName, in boolean aSuppressTransaction)
void postCreate ()
 postCreate should be called after Init, and is the time that the editor tells its documentStateObservers that the document has been created.
void preDestroy ()
 preDestroy is called before the editor goes away, and gives the editor a chance to tell its documentStateObservers that the document is going away.
void deleteSelection (in short action)
 DeleteSelection removes all nodes in the current selection.
void resetModificationCount ()
 to be used ONLY when we need to override the doc's modification state (such as when it's saved).
long getModificationCount ()
 Gets the modification count of the document we are editing.
void incrementModificationCount (in long aModCount)
 called each time we modify the document.
void doTransaction (in nsITransaction txn)
 doTransaction() fires a transaction.
void enableUndo (in boolean enable)
 turn the undo system on or off
void undo (in unsigned long count)
 undo reverses the effects of the last Do operation, if Undo is enabled in the editor.
void canUndo (out boolean isEnabled, out boolean canUndo)
 returns state information about the undo system.
void redo (in unsigned long count)
 redo reverses the effects of the last Undo operation It is provided here so clients need no knowledge of whether the editor has a transaction manager or not.
void canRedo (out boolean isEnabled, out boolean canRedo)
 returns state information about the redo system.
void beginTransaction ()
 beginTransaction is a signal from the caller to the editor that the caller will execute multiple updates to the content tree that should be treated as a single logical operation, in the most efficient way possible.
void endTransaction ()
 endTransaction is a signal to the editor that the caller is finished updating the content model.
void beginPlaceHolderTransaction (in nsIAtom name)
void endPlaceHolderTransaction ()
boolean shouldTxnSetSelection ()
void setShouldTxnSetSelection (in boolean should)
 Set the flag that prevents insertElementTxn from changing the selection.
void cut ()
 cut the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?
boolean canCut ()
 Can we cut? True if the doc is modifiable, and we have a non- collapsed selection.
void copy ()
 copy the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?
boolean canCopy ()
 Can we copy? True if we have a non-collapsed selection.
void paste (in long aSelectionType)
 paste the text in the OS clipboard at the cursor position, replacing the selected text (if any)
boolean canPaste (in long aSelectionType)
 Can we paste? True if the doc is modifiable, and we have pasteable data in the clipboard.
void selectAll ()
 sets the document selection to the entire contents of the document
void beginningOfDocument ()
 sets the document selection to the beginning of the document
void endOfDocument ()
 sets the document selection to the end of the document
boolean canDrag (in nsIDOMEvent aEvent)
 canDrag decides if a drag should be started (for example, based on the current selection and mousepoint).
void doDrag (in nsIDOMEvent aEvent)
 doDrag transfers the relevant data (as appropriate) to a transferable so it can later be dropped.
void insertFromDrop (in nsIDOMEvent aEvent)
 insertFromDrop looks for a dragsession and inserts the relevant data in response to a drop.
void setAttribute (in nsIDOMElement aElement, in AString attributestr, in AString attvalue)
 setAttribute() sets the attribute of aElement.
boolean getAttributeValue (in nsIDOMElement aElement, in AString attributestr, out AString resultValue)
 getAttributeValue() retrieves the attribute's value for aElement.
void removeAttribute (in nsIDOMElement aElement, in AString aAttribute)
 removeAttribute() deletes aAttribute from the attribute list of aElement.
void cloneAttribute (in AString aAttribute, in nsIDOMNode aDestNode, in nsIDOMNode aSourceNode)
 cloneAttribute() copies the attribute from the source node to the destination node and delete those not in the source.
void cloneAttributes (in nsIDOMNode destNode, in nsIDOMNode sourceNode)
 cloneAttributes() is similar to nsIDOMNode::cloneNode(), it assures the attribute nodes of the destination are identical with the source node by copying all existing attributes from the source and deleting those not in the source.
nsIDOMNode createNode (in AString tag, in nsIDOMNode parent, in long position)
 createNode instantiates a new element of type aTag and inserts it into aParent at aPosition.
void insertNode (in nsIDOMNode node, in nsIDOMNode parent, in long aPosition)
 insertNode inserts aNode into aParent at aPosition.
void splitNode (in nsIDOMNode existingRightNode, in long offset, out nsIDOMNode newLeftNode)
 splitNode() creates a new node identical to an existing node, and split the contents between the two nodes
void joinNodes (in nsIDOMNode leftNode, in nsIDOMNode rightNode, in nsIDOMNode parent)
 joinNodes() takes 2 nodes and merge their content|children.
void deleteNode (in nsIDOMNode child)
 deleteNode removes aChild from aParent.
void markNodeDirty (in nsIDOMNode node)
 markNodeDirty() sets a special dirty attribute on the node.
void switchTextDirection ()
 Switches the editor element direction; from "Left-to-Right" to "Right-to-Left", and vice versa.
AString outputToString (in AString formatType, in unsigned long flags)
 Output methods: aFormatType is a mime type, like text/plain.
void outputToStream (in nsIOutputStream aStream, in AString formatType, in ACString charsetOverride, in unsigned long flags)
void addEditorObserver (in nsIEditorObserver observer)
 add an EditorObserver to the editors list of observers.
void removeEditorObserver (in nsIEditorObserver observer)
 Remove an EditorObserver from the editor's list of observers.
void addEditActionListener (in nsIEditActionListener listener)
 add an EditActionListener to the editors list of listeners.
void removeEditActionListener (in nsIEditActionListener listener)
 Remove an EditActionListener from the editor's list of listeners.
void addDocumentStateListener (in nsIDocumentStateListener listener)
 Add a DocumentStateListener to the editors list of doc state listeners.
void removeDocumentStateListener (in nsIDocumentStateListener listener)
 Remove a DocumentStateListener to the editors list of doc state listeners.
void dumpContentTree ()
 And a debug method -- show us what the tree looks like right now.
void debugDumpContent ()
 Dumps a text representation of the content tree to standard out.
void debugUnitTests (out long outNumTests, out long outNumTestsFailed)
void beginComposition (in nsTextEventReplyPtr aReply)
 beginComposition(nsTextEventReply* aReply) Handles the start of inline input composition.
void setCompositionString (in DOMString aCompositionString, in nsIPrivateTextRangeListPtr aTextRange, in nsTextEventReplyPtr aReply)
 setCompositionString() Sets the inline input composition string.
void endComposition ()
 endComposition() Handles the end of inline input composition.
void queryComposition (in nsTextEventReplyPtr aReply)
 queryComposition() Get the composition position
void forceCompositionEnd ()
 forceCompositionEnd() force the composition end
void getReconversionString (in nsReconversionEventReplyPtr aReply)
 getReconversionString() Get the reconvertion string
void notifyIMEOnFocus ()
 Notify for IME when the editor got focus.
void notifyIMEOnBlur ()
 Notify for IME when the editor lost focus.
void getQueryCaretRect (in nsQueryCaretRectEventReplyPtr aReply)
 getQueryCaretRect() Get the query caret rect
void handleKeyPress (in nsIDOMKeyEvent aKeyEvent)
 EditorKeyPress consumes a keyevent.
void insertText (in DOMString aStringToInsert)
 Inserts a string at the current location, given by the selection.
void insertLineBreak ()
 Insert a line break into the content model.
void pasteAsQuotation (in long aSelectionType)
 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).
nsIDOMNode insertAsQuotation (in AString aQuotedText)
 Insert a string as quoted text (whose representation is dependant on the editor type), replacing the selected text (if any).
void insertTextWithQuotations (in DOMString aStringToInsert)
 Inserts a plaintext string at the current location, with special processing for lines beginning with ">", which will be treated as mail quotes and inserted as plaintext quoted blocks.
void pasteAsCitedQuotation (in AString aCitation, in long aSelectionType)
 Paste a string as quoted text, whose representation is dependant on the editor type, replacing the selected text (if any)
nsIDOMNode insertAsCitedQuotation (in AString aQuotedText, in AString aCitation, in boolean aInsertHTML)
 Insert a string as quoted text (whose representation is dependant on the editor type), replacing the selected text (if any), including, if possible, a "cite" attribute.
void rewrap (in boolean aRespectNewlines)
 Rewrap the selected part of the document, re-quoting if necessary.
void stripCites ()
 Strip any citations in the selected part of the document.
nsISupportsArray getEmbeddedObjects ()
 Get a list of IMG and OBJECT tags in the current document.

Static Public Member Functions

static nsresult GetTextNodeTag (nsAString &aOutString)
 return the string that represents text nodes in the content tree
static nsresult GetChildOffset (nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
 Set aOffset to the offset of aChild in aParent.
static nsresult GetNodeLocation (nsIDOMNode *aChild, nsCOMPtr< nsIDOMNode > *aParent, PRInt32 *aOffset)
 Set aParent to the parent of aChild.
static nsresult GetLengthOfDOMNode (nsIDOMNode *aNode, PRUint32 &aCount)
 returns the number of things inside aNode in the out-param aCount.
static PRBool NodeIsType (nsIDOMNode *aNode, nsIAtom *aTag)
 returns PR_TRUE if aNode is of the type implied by aTag
static PRBool NodeIsTypeString (nsIDOMNode *aNode, const nsAString &aTag)
static nsresult GetTagString (nsIDOMNode *aNode, nsAString &outString)
 from html rules code - migration in progress
static nsIAtomGetTag (nsIDOMNode *aNode)
static PRBool IsTextOrElementNode (nsIDOMNode *aNode)
static PRBool IsTextNode (nsIDOMNode *aNode)
static PRInt32 GetIndexOf (nsIDOMNode *aParent, nsIDOMNode *aChild)
static nsCOMPtr< nsIDOMNodeGetChildAt (nsIDOMNode *aParent, PRInt32 aOffset)
static nsresult GetStartNodeAndOffset (nsISelection *aSelection, nsCOMPtr< nsIDOMNode > *outStartNode, PRInt32 *outStartOffset)
static nsresult GetEndNodeAndOffset (nsISelection *aSelection, nsCOMPtr< nsIDOMNode > *outEndNode, PRInt32 *outEndOffset)

Public Attributes

const short eNone = 0
const short eNext = 1
const short ePrevious = 2
const short eNextWord = 3
const short ePreviousWord = 4
const short eToBeginningOfLine = 5
const short eToEndOfLine = 6
readonly attribute nsISelection selection
attribute unsigned long flags
 edit flags for this editor.
attribute string contentsMIMEType
 the MimeType of the document
readonly attribute boolean isDocumentEditable
 Returns true if we have a document that is not marked read-only.
readonly attribute nsIDOMDocument document
 the DOM Document this editor is associated with, refcounted.
readonly attribute nsIDOMElement rootElement
 the body element, i.e.
readonly attribute
nsISelectionController 
selectionController
 the selection controller for the current presentation, refcounted.
readonly attribute boolean documentIsEmpty
 Returns true if the document has no meaningful content.
readonly attribute boolean documentModified
 Returns true if the document is modifed and needs saving.
attribute ACString documentCharacterSet
 Sets the current 'Save' document character set.
readonly attribute
nsITransactionManager 
transactionManager
 transactionManager Get the transaction manager the editor is using.
readonly attribute
nsIInlineSpellChecker 
inlineSpellChecker
readonly attribute DOMString phonetic
 phonetic get the phonetic value of the input text
const short eEditorPlaintextBit = 0
const short eEditorSingleLineBit = 1
const short eEditorPasswordBit = 2
const short eEditorReadonlyBit = 3
const short eEditorDisabledBit = 4
const short eEditorFilterInputBit = 5
const short eEditorMailBit = 6
const short eEditorUseAsyncUpdatesBit = 7
const short eEditorEnableWrapHackBit = 8
const short eEditorWidgetBit = 9
const short eEditorNoCSSBit = 10
const long eEditorPlaintextMask = 1
const long eEditorSingleLineMask = 2
const long eEditorPasswordMask = 4
const long eEditorReadonlyMask = 8
const long eEditorDisabledMask = 16
const long eEditorFilterInputMask = 32
const long eEditorMailMask = 64
const long eEditorUseAsyncUpdatesMask = 128
const long eEditorEnableWrapHackMask = 256
const long eEditorWidgetMask = 512
const long eEditorNoCSSMask = 1024
readonly attribute long textLength
 The length of the contents in characters.
attribute long maxTextLength
 The maximum number of characters allowed.
attribute long wrapWidth
 Get and set the body wrap width.

Static Public Attributes

static nsIAtomgTypingTxnName
static nsIAtomgIMETxnName
static nsIAtomgDeleteTxnName

Protected Types

enum  TDocumentListenerNotification { eDocumentCreated, eDocumentToBeDestroyed, eDocumentStateChanged }
enum  Tristate { eTriUnset, eTriFalse, eTriTrue }

Protected Member Functions

NS_IMETHOD InitRules ()
void BeginEditorInit ()
nsresult EndEditorInit ()
virtual nsresult CreateEventListeners ()
NS_IMETHOD GetLayoutObject (nsIDOMNode *aInNode, nsISupports **aOutLayoutObject)
 returns the layout object (nsIFrame in the real world) for aNode
NS_IMETHOD GetAndInitDocEncoder (const nsAString &aFormatType, PRUint32 aFlags, const nsACString &aCharset, nsIDocumentEncoder **encoder)
NS_IMETHOD CreateBR (nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr< nsIDOMNode > *outBRNode, EDirection aSelect=eNone)
NS_IMETHOD CreateBRImpl (nsCOMPtr< nsIDOMNode > *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr< nsIDOMNode > *outBRNode, EDirection aSelect)
NS_IMETHOD InsertBR (nsCOMPtr< nsIDOMNode > *outBRNode)
NS_IMETHOD PrepareTransferable (nsITransferable **transferable)
NS_IMETHOD InsertTextFromTransferable (nsITransferable *transferable, nsIDOMNode *aDestinationNode, PRInt32 aDestOffset, PRBool aDoDeleteSelection)
virtual nsresult SetupDocEncoder (nsIDocumentEncoder **aDocEncoder)
virtual nsresult PutDragDataInTransferable (nsITransferable **aTransferable)
nsresult SharedOutputString (PRUint32 aFlags, PRBool *aIsCollapsed, nsAString &aResult)
 shared outputstring; returns whether selection is collapsed and resulting string
PRBool IsModifiable ()
NS_IMETHOD IgnoreSpuriousDragEvent (PRBool aIgnoreSpuriousDragEvent)
NS_IMETHOD CreateTxnForSetAttribute (nsIDOMElement *aElement, const nsAString &aAttribute, const nsAString &aValue, ChangeAttributeTxn **aTxn)
 create a transaction for setting aAttribute to aValue on aElement
NS_IMETHOD CreateTxnForRemoveAttribute (nsIDOMElement *aElement, const nsAString &aAttribute, ChangeAttributeTxn **aTxn)
 create a transaction for removing aAttribute on aElement
NS_IMETHOD CreateTxnForCreateElement (const nsAString &aTag, nsIDOMNode *aParent, PRInt32 aPosition, CreateElementTxn **aTxn)
 create a transaction for creating a new child node of aParent of type aTag.
NS_IMETHOD CreateTxnForInsertElement (nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset, InsertElementTxn **aTxn)
 create a transaction for inserting aNode as a child of aParent.
NS_IMETHOD CreateTxnForDeleteElement (nsIDOMNode *aElement, DeleteElementTxn **aTxn)
 create a transaction for removing aElement from its parent.
NS_IMETHOD CreateTxnForDeleteSelection (EDirection aAction, EditAggregateTxn **aTxn)
NS_IMETHOD CreateTxnForDeleteInsertionPoint (nsIDOMRange *aRange, EDirection aAction, EditAggregateTxn *aTxn)
NS_IMETHOD CreateTxnForInsertText (const nsAString &aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset, InsertTextTxn **aTxn)
 create a transaction for inserting aStringToInsert into aTextNode if aTextNode is null, the string is inserted at the current selection.
NS_IMETHOD CreateTxnForIMEText (const nsAString &aStringToInsert, IMETextTxn **aTxn)
NS_IMETHOD CreateTxnForAddStyleSheet (nsICSSStyleSheet *aSheet, AddStyleSheetTxn **aTxn)
 create a transaction for adding a style sheet
NS_IMETHOD CreateTxnForRemoveStyleSheet (nsICSSStyleSheet *aSheet, RemoveStyleSheetTxn **aTxn)
 create a transaction for removing a style sheet
NS_IMETHOD DeleteText (nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aLength)
NS_IMETHOD CreateTxnForDeleteText (nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aLength, DeleteTextTxn **aTxn)
NS_IMETHOD CreateTxnForSplitNode (nsIDOMNode *aNode, PRUint32 aOffset, SplitElementTxn **aTxn)
NS_IMETHOD CreateTxnForJoinNode (nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, JoinElementTxn **aTxn)
NS_IMETHOD DeleteSelectionAndPrepareToCreateNode (nsCOMPtr< nsIDOMNode > &parentSelectedNode, PRInt32 &offsetOfNewNode)
NS_IMETHOD DoAfterDoTransaction (nsITransaction *aTxn)
NS_IMETHOD DoAfterUndoTransaction ()
NS_IMETHOD DoAfterRedoTransaction ()
NS_IMETHOD NotifyDocumentListeners (TDocumentListenerNotification aNotificationType)
NS_IMETHOD GetWrapWidth (PRInt32 *aWrapCol)
NS_IMETHOD ScrollSelectionIntoView (PRBool aScrollToAnchor)
 helper method for scrolling the selection into view after an edit operation.
virtual PRBool IsBlockNode (nsIDOMNode *aNode)
nsresult GetPriorNodeImpl (nsIDOMNode *aCurrentNode, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
nsresult GetNextNodeImpl (nsIDOMNode *aCurrentNode, PRBool aEditableNode, nsCOMPtr< nsIDOMNode > *aResultNode, PRBool bNoBlockCrossing=PR_FALSE)
nsresult GetKBStateControl (nsIKBStateControl **aKBSC)
nsresult InstallEventListeners ()
virtual void RemoveEventListeners ()
PRBool GetDesiredSpellCheckState ()
 Return true if spellchecking should be enabled for this editor.

Protected Attributes

PRBool mIgnoreSpuriousDragEvent
nsCOMPtr< nsIEditRulesmRules
PRBool mWrapToWindow
PRInt32 mWrapColumn
PRInt32 mMaxTextLength
PRInt32 mInitTriggerCounter
nsCString mContentMIMEType
PRUint32 mModCount
PRUint32 mFlags
nsWeakPtr mPresShellWeak
nsWeakPtr mSelConWeak
nsIViewManagermViewManager
PRInt32 mUpdateCount
enum nsEditor::Tristate mSpellcheckCheckboxState
nsCOMPtr< nsIInlineSpellCheckermInlineSpellChecker
nsCOMPtr< nsITransactionManagermTxnMgr
nsWeakPtr mPlaceHolderTxn
nsIAtommPlaceHolderName
PRInt32 mPlaceHolderBatch
nsSelectionStatemSelState
nsSelectionState mSavedSel
nsRangeUpdater mRangeUpdater
nsCOMPtr< nsIDOMElementmRootElement
PRInt32 mAction
EDirection mDirection
nsIPrivateTextRangeListmIMETextRangeList
nsCOMPtr< nsIDOMCharacterDatamIMETextNode
PRUint32 mIMETextOffset
PRUint32 mIMEBufferLength
PRPackedBool mInIMEMode
PRPackedBool mIsIMEComposing
PRPackedBool mNeedRecoverIMEOpenState
PRPackedBool mShouldTxnSetSelection
PRPackedBool mDidPreDestroy
nsVoidArraymActionListeners
nsVoidArraymEditorObservers
nsCOMPtr< nsISupportsArraymDocStateListeners
PRInt8 mDocDirtyState
nsWeakPtr mDocWeak
nsCOMPtr< nsIDOMEventReceivermDOMEventReceiver
nsCOMPtr< nsIDTDmDTD
nsStringmPhonetic
nsCOMPtr< nsIDOMEventListenermKeyListenerP
nsCOMPtr< nsIDOMEventListenermMouseListenerP
nsCOMPtr< nsIDOMEventListenermTextListenerP
nsCOMPtr< nsIDOMEventListenermCompositionListenerP
nsCOMPtr< nsIDOMEventListenermDragListenerP
nsCOMPtr< nsIDOMEventListenermFocusListenerP

Friends

class nsHTMLEditRules
class nsTextEditRules
class nsAutoEditInitRulesTrigger
class nsAutoTxnsConserveSelection
class nsAutoSelectionReset
class nsAutoRules
class nsRangeUpdater
PRBool NSCanUnload (nsISupports *serviceMgr)

Detailed Description

The text editor implementation.

Use to edit text document represented as a DOM tree.

Definition at line 61 of file nsPlaintextEditor.h.


Member Typedef Documentation

typedef short nsIEditor::EDirection [inherited]

Definition at line 71 of file nsIEditor.idl.


Member Enumeration Documentation

anonymous enum
Enumerator:
eTypedText 
eTypedBR 
eTypedBreak 

Definition at line 74 of file nsPlaintextEditor.h.

       {
    eTypedText,  /* user typed text */
    eTypedBR,    /* user typed shift-enter to get a br */
    eTypedBreak  /* user typed enter */
  };
enum nsEditor::IterDirection [inherited]
Enumerator:
kIterForward 
kIterBackward 

Definition at line 105 of file nsEditor.h.

enum nsEditor::OperationID [inherited]
Enumerator:
kOpIgnore 
kOpNone 
kOpUndo 
kOpRedo 
kOpInsertNode 
kOpCreateNode 
kOpDeleteNode 
kOpSplitNode 
kOpJoinNode 
kOpDeleteSelection 
kOpInsertBreak 
kOpInsertText 
kOpInsertIMEText 
kOpDeleteText 

Reimplemented in nsHTMLEditor.

Definition at line 111 of file nsEditor.h.

enum nsEditor::TDocumentListenerNotification [protected, inherited]
Enumerator:
eDocumentCreated 
eDocumentToBeDestroyed 
eDocumentStateChanged 

Definition at line 292 of file nsEditor.h.

enum nsEditor::Tristate [protected, inherited]
Enumerator:
eTriUnset 
eTriFalse 
eTriTrue 

Definition at line 601 of file nsEditor.h.


Constructor & Destructor Documentation

Definition at line 100 of file nsPlaintextEditor.cpp.

{
  // remove the rules as an action listener.  Else we get a bad ownership loop later on.
  // it's ok if the rules aren't a listener; we ignore the error.
  nsCOMPtr<nsIEditActionListener> mListener = do_QueryInterface(mRules);
  RemoveEditActionListener(mListener);
  
  // Remove event listeners. Note that if we had an HTML editor,
  //  it installed its own instead of these
  RemoveEventListeners();
}

Here is the call graph for this function:


Member Function Documentation

Add a DocumentStateListener to the editors list of doc state listeners.

add an EditActionListener to the editors list of listeners.

add an EditorObserver to the editors list of observers.

Definition at line 5437 of file nsEditor.cpp.

{
  if (!aNode) return NS_ERROR_NULL_POINTER;
  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
  if(!selection) return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDOMNode> parentNode;
  res = aNode->GetParentNode(getter_AddRefs(parentNode));
  if (NS_FAILED(res)) return res;
  if (!parentNode) return NS_ERROR_NULL_POINTER;
  
  PRInt32 offset;
  res = GetChildOffset(aNode, parentNode, offset);
  if (NS_FAILED(res)) return res;
  
  nsCOMPtr<nsIDOMRange> range;
  res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range));
  if (NS_FAILED(res)) return res;
  if (!range) return NS_ERROR_NULL_POINTER;

  return selection->AddRange(range);
}

Here is the call graph for this function:

Here is the caller graph for this function:

routines for managing the preservation of selection across various editor actions

Definition at line 2105 of file nsEditor.cpp.

{
  return !(mSavedSel.IsEmpty());
}

Here is the call graph for this function:

Here is the caller graph for this function:

beginComposition(nsTextEventReply* aReply) Handles the start of inline input composition.

Definition at line 826 of file nsPlaintextEditor.cpp.

Here is the call graph for this function:

Definition at line 144 of file nsPlaintextEditor.cpp.

Here is the caller graph for this function:

sets the document selection to the beginning of the document

beginTransaction is a signal from the caller to the editor that the caller will execute multiple updates to the content tree that should be treated as a single logical operation, in the most efficient way possible.


All transactions executed between a call to beginTransaction and endTransaction will be undoable as an atomic action.
endTransaction must be called after beginTransaction.
Calls to beginTransaction can be nested, as long as endTransaction is called once per beginUpdate.

Definition at line 4603 of file nsEditor.cpp.

{
  NS_PRECONDITION(mUpdateCount >= 0, "bad state");


  if (0 == mUpdateCount)
  {
    // Turn off selection updates and notifications.

    nsCOMPtr<nsISelection> selection;
    GetSelection(getter_AddRefs(selection));

    if (selection) 
    {
      nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
      selPrivate->StartBatchChanges();
    }

    // Turn off view updating.

    if (mViewManager)
      mViewManager->BeginUpdateViewBatch();

    // Turn off reflow.

    nsCOMPtr<nsIPresShell> presShell;
    GetPresShell(getter_AddRefs(presShell));

    if (presShell)
      presShell->BeginReflowBatching();
  }

  mUpdateCount++;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsEditor::CanContainTag ( nsIDOMNode aParent,
const nsAString &  aTag 
) [inherited]

returns PR_TRUE if aParent can contain a child of type aTag

Definition at line 3947 of file nsEditor.cpp.

{
  nsCOMPtr<nsIDOMElement> parentElement = do_QueryInterface(aParent);
  if (!parentElement) return PR_FALSE;
  
  nsAutoString parentStringTag;
  parentElement->GetTagName(parentStringTag);
  return TagCanContainTag(parentStringTag, aChildTag);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1107 of file nsPlaintextEditor.cpp.

{
  if (!aCanCopy)
    return NS_ERROR_NULL_POINTER;
  *aCanCopy = PR_FALSE;
  
  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
    
  PRBool isCollapsed;
  res = selection->GetIsCollapsed(&isCollapsed);
  if (NS_FAILED(res)) return res;

  *aCanCopy = !isCollapsed;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

boolean nsIEditor::canCopy ( ) [inherited]

Can we copy? True if we have a non-collapsed selection.

Definition at line 1090 of file nsPlaintextEditor.cpp.

{
  nsresult res = CanCopy(aCanCut);
  if (NS_FAILED(res)) return res;
    
  *aCanCut = *aCanCut && IsModifiable();
  return NS_OK;
}

Here is the call graph for this function:

boolean nsIEditor::canCut ( ) [inherited]

Can we cut? True if the doc is modifiable, and we have a non- collapsed selection.

NS_IMETHODIMP nsPlaintextEditor::CanDrag ( nsIDOMEvent aDragEvent,
PRBool aCanDrag 
)

Definition at line 308 of file nsPlaintextDataTransfer.cpp.

{
  if (!aCanDrag)
    return NS_ERROR_NULL_POINTER;
  /* we really should be checking the XY coordinates of the mouseevent and ensure that
   * that particular point is actually within the selection (not just that there is a selection)
   */
  *aCanDrag = PR_FALSE;
 
  // KLUDGE to work around bug 50703
  // After double click and object property editing, 
  //  we get a spurious drag event
  if (mIgnoreSpuriousDragEvent)
  {
    mIgnoreSpuriousDragEvent = PR_FALSE;
    return NS_OK;
  }
   
  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
    
  PRBool isCollapsed;
  res = selection->GetIsCollapsed(&isCollapsed);
  if (NS_FAILED(res)) return res;
  
  // if we are collapsed, we have no selection so nothing to drag
  if ( isCollapsed )
    return NS_OK;

  nsCOMPtr<nsIDOMEventTarget> eventTarget;

  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aDragEvent));
  if (nsevent) {
    res = nsevent->GetTmpRealOriginalTarget(getter_AddRefs(eventTarget));
    if (NS_FAILED(res)) return res;
  }

  if (eventTarget)
  {
    nsCOMPtr<nsIDOMNode> eventTargetDomNode = do_QueryInterface(eventTarget);
    if ( eventTargetDomNode )
    {
      PRBool isTargetedCorrectly = PR_FALSE;
      res = selection->ContainsNode(eventTargetDomNode, PR_FALSE, &isTargetedCorrectly);
      if (NS_FAILED(res)) return res;

      *aCanDrag = isTargetedCorrectly;
    }
  }

  if (NS_FAILED(res)) return res;
  if (!*aCanDrag) return NS_OK;

  nsCOMPtr<nsIDOMDocument> domdoc;
  GetDocument(getter_AddRefs(domdoc));
  *aCanDrag = nsEditorHookUtils::DoAllowDragHook(domdoc, aDragEvent);
  return NS_OK;
}

Here is the call graph for this function:

boolean nsIEditor::canDrag ( in nsIDOMEvent  aEvent) [inherited]

canDrag decides if a drag should be started (for example, based on the current selection and mousepoint).

NS_IMETHODIMP nsPlaintextEditor::CanPaste ( PRInt32  aSelectionType,
PRBool aCanPaste 
)

Reimplemented in nsHTMLEditor.

Definition at line 448 of file nsPlaintextDataTransfer.cpp.

{
  if (!aCanPaste)
    return NS_ERROR_NULL_POINTER;
  *aCanPaste = PR_FALSE;
  
  // can't paste if readonly
  if (!IsModifiable())
    return NS_OK;

  nsresult rv;
  nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
  if (NS_FAILED(rv)) return rv;
  
  // the flavors that we can deal with
  const char* const textEditorFlavors[] = { kUnicodeMime, nsnull };

  nsCOMPtr<nsISupportsArray> flavorsList = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);

  PRUint32 editorFlags;
  GetFlags(&editorFlags);
  
  // add the flavors for text editors
  for (const char* const* flavor = textEditorFlavors; *flavor; flavor++)
  {
    nsCOMPtr<nsISupportsCString> flavorString =
        do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID);
    if (flavorString)
    {
      flavorString->SetData(nsDependentCString(*flavor));
      flavorsList->AppendElement(flavorString);
    }
  }
  
  PRBool haveFlavors;
  rv = clipboard->HasDataMatchingFlavors(flavorsList, aSelectionType, &haveFlavors);
  if (NS_FAILED(rv)) return rv;
  
  *aCanPaste = haveFlavors;
  return NS_OK;
}

Here is the call graph for this function:

boolean nsIEditor::canPaste ( in long  aSelectionType) [inherited]

Can we paste? True if the doc is modifiable, and we have pasteable data in the clipboard.

void nsIEditor::canRedo ( out boolean  isEnabled,
out boolean  canRedo 
) [inherited]

returns state information about the redo system.

Parameters:
aIsEnabled[OUT] PR_TRUE if redo is enabled
aCanRedo[OUT] PR_TRUE if at least one transaction is currently ready to be redone.
void nsIEditor::canUndo ( out boolean  isEnabled,
out boolean  canUndo 
) [inherited]

returns state information about the undo system.

Parameters:
aIsEnabled[OUT] PR_TRUE if undo is enabled
aCanUndo[OUT] PR_TRUE if at least one transaction is currently ready to be undone.

Definition at line 5462 of file nsEditor.cpp.

{
  nsCOMPtr<nsISelection> selection;
  nsresult res = nsEditor::GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
  if (!selection) return NS_ERROR_FAILURE;
  return selection->RemoveAllRanges();  
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditor::cloneAttribute ( in AString  aAttribute,
in nsIDOMNode  aDestNode,
in nsIDOMNode  aSourceNode 
) [inherited]

cloneAttribute() copies the attribute from the source node to the destination node and delete those not in the source.

The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)

Parameters:
aAttributethe name of the attribute to copy
aDestNodethe destination element to operate on
aSourceNodethe source element to copy attributes from
Exceptions:
NS_ERROR_NULL_POINTERat least one of the nodes is null
NS_ERROR_NO_INTERFACEat least one of the nodes is not an element
void nsIEditor::cloneAttributes ( in nsIDOMNode  destNode,
in nsIDOMNode  sourceNode 
) [inherited]

cloneAttributes() is similar to nsIDOMNode::cloneNode(), it assures the attribute nodes of the destination are identical with the source node by copying all existing attributes from the source and deleting those not in the source.

This is used when the destination node (element) already exists

The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)

Parameters:
aDestNodethe destination element to operate on
aSourceNodethe source element to copy attributes from

Reimplemented in nsHTMLEditorLog.

Definition at line 1099 of file nsPlaintextEditor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditor::copy ( ) [inherited]

copy the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?

nsresult nsEditor::CountEditableChildren ( nsIDOMNode aNode,
PRUint32 outCount 
) [inherited]

counts number of editable child nodes

Definition at line 4131 of file nsEditor.cpp.

{
  outCount = 0;
  if (!aNode) { return NS_ERROR_NULL_POINTER; }
  nsresult res=NS_OK;
  PRBool hasChildNodes;
  aNode->HasChildNodes(&hasChildNodes);
  if (hasChildNodes)
  {
    nsCOMPtr<nsIDOMNodeList>nodeList;
    res = aNode->GetChildNodes(getter_AddRefs(nodeList));
    if (NS_SUCCEEDED(res) && nodeList) 
    {
      PRUint32 i;
      PRUint32 len;
      nodeList->GetLength(&len);
      for (i=0 ; i<len; i++)
      {
        nsCOMPtr<nsIDOMNode> child;
        res = nodeList->Item((PRInt32)i, getter_AddRefs(child));
        if ((NS_SUCCEEDED(res)) && (child))
        {
          if (IsEditable(child))
          {
            outCount++;
          }
        }
      }
    }
    else if (!nodeList)
      res = NS_ERROR_NULL_POINTER;
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsPlaintextEditor::CreateBR ( nsIDOMNode aNode,
PRInt32  aOffset,
nsCOMPtr< nsIDOMNode > *  outBRNode,
EDirection  aSelect = eNone 
) [protected]

Reimplemented in nsHTMLEditor.

Definition at line 492 of file nsPlaintextEditor.cpp.

{
  nsCOMPtr<nsIDOMNode> parent = aNode;
  PRInt32 offset = aOffset;
  return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsPlaintextEditor::CreateBRImpl ( nsCOMPtr< nsIDOMNode > *  aInOutParent,
PRInt32 aInOutOffset,
nsCOMPtr< nsIDOMNode > *  outBRNode,
EDirection  aSelect 
) [protected]

Reimplemented in nsHTMLEditor.

Definition at line 413 of file nsPlaintextEditor.cpp.

{
  if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER;
  *outBRNode = nsnull;
  nsresult res;
  
  // we need to insert a br.  unfortunately, we may have to split a text node to do it.
  nsCOMPtr<nsIDOMNode> node = *aInOutParent;
  PRInt32 theOffset = *aInOutOffset;
  nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(node);
  NS_NAMED_LITERAL_STRING(brType, "br");
  nsCOMPtr<nsIDOMNode> brNode;
  if (nodeAsText)  
  {
    nsCOMPtr<nsIDOMNode> tmp;
    PRInt32 offset;
    PRUint32 len;
    nodeAsText->GetLength(&len);
    GetNodeLocation(node, address_of(tmp), &offset);
    if (!tmp) return NS_ERROR_FAILURE;
    if (!theOffset)
    {
      // we are already set to go
    }
    else if (theOffset == (PRInt32)len)
    {
      // update offset to point AFTER the text node
      offset++;
    }
    else
    {
      // split the text node
      res = SplitNode(node, theOffset, getter_AddRefs(tmp));
      if (NS_FAILED(res)) return res;
      res = GetNodeLocation(node, address_of(tmp), &offset);
      if (NS_FAILED(res)) return res;
    }
    // create br
    res = CreateNode(brType, tmp, offset, getter_AddRefs(brNode));
    if (NS_FAILED(res)) return res;
    *aInOutParent = tmp;
    *aInOutOffset = offset+1;
  }
  else
  {
    res = CreateNode(brType, node, theOffset, getter_AddRefs(brNode));
    if (NS_FAILED(res)) return res;
    (*aInOutOffset)++;
  }

  *outBRNode = brNode;
  if (*outBRNode && (aSelect != eNone))
  {
    nsCOMPtr<nsIDOMNode> parent;
    PRInt32 offset;
    res = GetNodeLocation(*outBRNode, address_of(parent), &offset);
    if (NS_FAILED(res)) return res;

    nsCOMPtr<nsISelection> selection;
    res = GetSelection(getter_AddRefs(selection));
    if (NS_FAILED(res)) return res;
    nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
    if (aSelect == eNext)
    {
      // position selection after br
      selPriv->SetInterlinePosition(PR_TRUE);
      res = selection->Collapse(parent, offset+1);
    }
    else if (aSelect == ePrevious)
    {
      // position selection before br
      selPriv->SetInterlinePosition(PR_TRUE);
      res = selection->Collapse(parent, offset);
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsEditor.

Reimplemented in nsHTMLEditor.

Definition at line 257 of file nsPlaintextEditor.cpp.

{
  nsresult rv = NS_OK;

  if (!mMouseListenerP) {
    // get a mouse listener
    rv |= NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this);
  }

  if (!mKeyListenerP) {
    // get a key listener
    rv |= NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this);
  }

  if (!mTextListenerP) {
    // get a text listener
    rv |= NS_NewEditorTextListener(getter_AddRefs(mTextListenerP), this);
  }

  if (!mCompositionListenerP) {
    // get a composition listener
    rv |=
      NS_NewEditorCompositionListener(getter_AddRefs(mCompositionListenerP),
                                      this);
  }

  if (!mDragListenerP) {
    // get a drag listener
    nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShellWeak);
    rv |= NS_NewEditorDragListener(getter_AddRefs(mDragListenerP), presShell,
                                   this);
  }

  if (!mFocusListenerP) {
    // get a focus listener
    rv |= NS_NewEditorFocusListener(getter_AddRefs(mFocusListenerP), this);
  }

  return rv;
}

Here is the call graph for this function:

nsresult nsEditor::CreateHTMLContent ( const nsAString &  aTag,
nsIContent **  aContent 
) [inherited]

Definition at line 5472 of file nsEditor.cpp.

{
  nsCOMPtr<nsIDOMDocument> tempDoc;
  GetDocument(getter_AddRefs(tempDoc));

  nsCOMPtr<nsIDocument> doc = do_QueryInterface(tempDoc);
  if (!doc)
    return NS_ERROR_FAILURE;

  // XXX Wallpaper over editor bug (editor tries to create elements with an
  //     empty nodename).
  if (aTag.IsEmpty()) {
    NS_ERROR("Don't pass an empty tag to nsEditor::CreateHTMLContent, "
             "check caller.");
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsIAtom> tag = do_GetAtom(aTag);
  if (!tag)
    return NS_ERROR_OUT_OF_MEMORY;

  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(tempDoc);
  if (htmlDoc) {
      return doc->CreateElem(tag, nsnull, doc->GetDefaultNamespaceID(),
                             PR_TRUE, aContent);
  }

  return doc->CreateElem(tag, nsnull, kNameSpaceID_XHTML, PR_FALSE, aContent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIDOMNode nsIEditor::createNode ( in AString  tag,
in nsIDOMNode  parent,
in long  position 
) [inherited]

createNode instantiates a new element of type aTag and inserts it into aParent at aPosition.

Parameters:
aTagThe type of object to create
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node
Returns:
The node created. Caller must release aNewNode.
nsresult nsEditor::CreateRange ( nsIDOMNode aStartParent,
PRInt32  aStartOffset,
nsIDOMNode aEndParent,
PRInt32  aEndOffset,
nsIDOMRange **  aRange 
) [inherited]

Definition at line 5411 of file nsEditor.cpp.

{
  nsresult result;
  result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
  if (NS_FAILED(result))
    return result;

  if (!*aRange)
    return NS_ERROR_NULL_POINTER;

  result = (*aRange)->SetStart(aStartParent, aStartOffset);

  if (NS_SUCCEEDED(result))
    result = (*aRange)->SetEnd(aEndParent, aEndOffset);

  if (NS_FAILED(result))
  {
    NS_RELEASE((*aRange));
    *aRange = 0;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForAddStyleSheet ( nsICSSStyleSheet aSheet,
AddStyleSheetTxn **  aTxn 
) [protected, inherited]

create a transaction for adding a style sheet

Definition at line 5127 of file nsEditor.cpp.

{
  nsresult rv = TransactionFactory::GetNewTransaction(AddStyleSheetTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_FAILED(rv))
    return rv;
    
  if (! *aTxn)
    return NS_ERROR_OUT_OF_MEMORY;

  return (*aTxn)->Init(this, aSheet);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForCreateElement ( const nsAString &  aTag,
nsIDOMNode aParent,
PRInt32  aPosition,
CreateElementTxn **  aTxn 
) [protected, inherited]

create a transaction for creating a new child node of aParent of type aTag.

Definition at line 5019 of file nsEditor.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (nsnull != aParent)
  {
    result = TransactionFactory::GetNewTransaction(CreateElementTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result))  {
      result = (*aTxn)->Init(this, aTag, aParent, aPosition);
    }
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement ( nsIDOMNode aElement,
DeleteElementTxn **  aTxn 
) [protected, inherited]

create a transaction for removing aElement from its parent.

Definition at line 5052 of file nsEditor.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (nsnull != aElement)
  {
    result = TransactionFactory::GetNewTransaction(DeleteElementTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result)) {
      result = (*aTxn)->Init(aElement, &mRangeUpdater);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 5233 of file nsEditor.cpp.

{
  // get the node and offset of the insertion point
  nsCOMPtr<nsIDOMNode> node;
  nsresult result = aRange->GetStartContainer(getter_AddRefs(node));
  if (NS_FAILED(result))
    return result;

  PRInt32 offset;
  result = aRange->GetStartOffset(&offset);
  if (NS_FAILED(result))
    return result;

  // determine if the insertion point is at the beginning, middle, or end of the node
  nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(node);

  PRUint32 count=0;

  if (nodeAsText)
    nodeAsText->GetLength(&count);
  else
  { 
    // get the child list and count
    nsCOMPtr<nsIDOMNodeList>childList;
    result = node->GetChildNodes(getter_AddRefs(childList));
    if ((NS_SUCCEEDED(result)) && childList)
      childList->GetLength(&count);
  }

  PRBool isFirst = (0 == offset);
  PRBool isLast  = (count == (PRUint32)offset);

  // XXX: if isFirst && isLast, then we'll need to delete the node 
  //      as well as the 1 child

  // build a transaction for deleting the appropriate data
  // XXX: this has to come from rule section
  if ((ePrevious==aAction) && (PR_TRUE==isFirst))
  { // we're backspacing from the beginning of the node.  Delete the first thing to our left
    nsCOMPtr<nsIDOMNode> priorNode;
    result = GetPriorNode(node, PR_TRUE, address_of(priorNode));
    if ((NS_SUCCEEDED(result)) && priorNode)
    { // there is a priorNode, so delete it's last child (if text content, delete the last char.)
      // if it has no children, delete it
      nsCOMPtr<nsIDOMCharacterData> priorNodeAsText = do_QueryInterface(priorNode);
      if (priorNodeAsText)
      {
        PRUint32 length=0;
        priorNodeAsText->GetLength(&length);
        if (0<length)
        {
          DeleteTextTxn *txn;
          result = CreateTxnForDeleteText(priorNodeAsText, length-1, 1, &txn);
          if (NS_SUCCEEDED(result)) {
            aTxn->AppendChild(txn);
            NS_RELEASE(txn);
          }
        }
        else
        { // XXX: can you have an empty text node?  If so, what do you do?
          printf("ERROR: found a text node with 0 characters\n");
          result = NS_ERROR_UNEXPECTED;
        }
      }
      else
      { // priorNode is not text, so tell it's parent to delete it
        DeleteElementTxn *txn;
        result = CreateTxnForDeleteElement(priorNode, &txn);
        if (NS_SUCCEEDED(result)) {
          aTxn->AppendChild(txn);
          NS_RELEASE(txn);
        }
      }
    }
  }
  else if ((nsIEditor::eNext==aAction) && (PR_TRUE==isLast))
  { // we're deleting from the end of the node.  Delete the first thing to our right
    nsCOMPtr<nsIDOMNode> nextNode;
    result = GetNextNode(node, PR_TRUE, address_of(nextNode));
    if ((NS_SUCCEEDED(result)) && nextNode)
    { // there is a nextNode, so delete it's first child (if text content, delete the first char.)
      // if it has no children, delete it
      nsCOMPtr<nsIDOMCharacterData> nextNodeAsText = do_QueryInterface(nextNode);
      if (nextNodeAsText)
      {
        PRUint32 length=0;
        nextNodeAsText->GetLength(&length);
        if (0<length)
        {
          DeleteTextTxn *txn;
          result = CreateTxnForDeleteText(nextNodeAsText, 0, 1, &txn);
          if (NS_SUCCEEDED(result)) {
            aTxn->AppendChild(txn);
            NS_RELEASE(txn);
          }
        }
        else
        { // XXX: can you have an empty text node?  If so, what do you do?
          printf("ERROR: found a text node with 0 characters\n");
          result = NS_ERROR_UNEXPECTED;
        }
      }
      else
      { // nextNode is not text, so tell it's parent to delete it
        DeleteElementTxn *txn;
        result = CreateTxnForDeleteElement(nextNode, &txn);
        if (NS_SUCCEEDED(result)) {
          aTxn->AppendChild(txn);
          NS_RELEASE(txn);
        }
      }
    }
  }
  else
  {
    if (nodeAsText)
    { // we have text, so delete a char at the proper offset
      if (nsIEditor::ePrevious==aAction) {
        offset --;
      }
      DeleteTextTxn *txn;
      result = CreateTxnForDeleteText(nodeAsText, offset, 1, &txn);
      if (NS_SUCCEEDED(result)) {
        aTxn->AppendChild(txn);
        NS_RELEASE(txn);
      }
    }
    else
    { // we're either deleting a node or some text, need to dig into the next/prev node to find out
      nsCOMPtr<nsIDOMNode> selectedNode;
      if (ePrevious==aAction)
      {
        result = GetPriorNode(node, offset, PR_TRUE, address_of(selectedNode));
      }
      else if (eNext==aAction)
      {
        result = GetNextNode(node, offset, PR_TRUE, address_of(selectedNode));
      }
      if (NS_FAILED(result)) { return result; }
      if (selectedNode) 
      {
        nsCOMPtr<nsIDOMCharacterData> selectedNodeAsText =
                                             do_QueryInterface(selectedNode);
        if (selectedNodeAsText)
        { // we are deleting from a text node, so do a text deletion
          PRInt32 begin = 0;    // default for forward delete
          if (ePrevious==aAction)
          {
            PRUint32 length=0;
            selectedNodeAsText->GetLength(&length);
            if (0<length)
              begin = length-1;
          }
          DeleteTextTxn *delTextTxn;
          result = CreateTxnForDeleteText(selectedNodeAsText, begin, 1, &delTextTxn);
          if (NS_FAILED(result))  { return result; }
          if (!delTextTxn) { return NS_ERROR_NULL_POINTER; }
          aTxn->AppendChild(delTextTxn);
          NS_RELEASE(delTextTxn);
        }
        else
        {
          DeleteElementTxn *delElementTxn;
          result = CreateTxnForDeleteElement(selectedNode, &delElementTxn);
          if (NS_FAILED(result))  { return result; }
          if (!delElementTxn) { return NS_ERROR_NULL_POINTER; }
          aTxn->AppendChild(delElementTxn);
          NS_RELEASE(delElementTxn);
        }
      }
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 5156 of file nsEditor.cpp.

{
  if (!aTxn)
    return NS_ERROR_NULL_POINTER;
  *aTxn = nsnull;

#ifdef DEBUG_akkana
  NS_ASSERTION(aAction != eNextWord && aAction != ePreviousWord && aAction != eToEndOfLine, "CreateTxnForDeleteSelection: unsupported action!");
#endif

  nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
  nsCOMPtr<nsISelection> selection;
  nsresult result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
                                         getter_AddRefs(selection));
  if ((NS_SUCCEEDED(result)) && selection)
  {
    // Check whether the selection is collapsed and we should do nothing:
    PRBool isCollapsed;
    result = (selection->GetIsCollapsed(&isCollapsed));
    if (NS_SUCCEEDED(result) && isCollapsed && aAction == eNone)
      return NS_OK;

    // allocate the out-param transaction
    result = TransactionFactory::GetNewTransaction(EditAggregateTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_FAILED(result)) {
      return result;
    }

    nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(selection));
    nsCOMPtr<nsIEnumerator> enumerator;
    result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
    if (NS_SUCCEEDED(result) && enumerator)
    {
      for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
      {
        nsCOMPtr<nsISupports> currentItem;
        result = enumerator->CurrentItem(getter_AddRefs(currentItem));
        if ((NS_SUCCEEDED(result)) && (currentItem))
        {
          nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
          range->GetCollapsed(&isCollapsed);
          if (!isCollapsed)
          {
            DeleteRangeTxn *txn;
            result = TransactionFactory::GetNewTransaction(DeleteRangeTxn::GetCID(), (EditTxn **)&txn);
            if (NS_SUCCEEDED(result) && txn)
            {
              txn->Init(this, range, &mRangeUpdater);
              (*aTxn)->AppendChild(txn);
              NS_RELEASE(txn);
            }
            else
              result = NS_ERROR_OUT_OF_MEMORY;
          }
          else
          { // we have an insertion point.  delete the thing in front of it or behind it, depending on aAction
            result = CreateTxnForDeleteInsertionPoint(range, aAction, *aTxn);
          }
        }
      }
    }
  }

  // if we didn't build the transaction correctly, destroy the out-param transaction so we don't leak it.
  if (NS_FAILED(result))
  {
    NS_IF_RELEASE(*aTxn);
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForDeleteText ( nsIDOMCharacterData aElement,
PRUint32  aOffset,
PRUint32  aLength,
DeleteTextTxn **  aTxn 
) [protected, inherited]

Definition at line 3106 of file nsEditor.cpp.

{
  if (!aElement)
    return NS_ERROR_NULL_POINTER;

  nsresult result = TransactionFactory::GetNewTransaction(DeleteTextTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_SUCCEEDED(result))  {
    result = (*aTxn)->Init(this, aElement, aOffset, aLength, &mRangeUpdater);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForIMEText ( const nsAString &  aStringToInsert,
IMETextTxn **  aTxn 
) [protected, inherited]

Definition at line 5107 of file nsEditor.cpp.

{
  NS_ASSERTION(aTxn, "illegal value- null ptr- aTxn");
  if(!aTxn) return NS_ERROR_NULL_POINTER;
     
  nsresult  result;

  result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn);
  if (nsnull!=*aTxn) {
    result = (*aTxn)->Init(mIMETextNode,mIMETextOffset,mIMEBufferLength,mIMETextRangeList,aStringToInsert,mSelConWeak);
  }
  else {
    result = NS_ERROR_OUT_OF_MEMORY;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForInsertElement ( nsIDOMNode aNode,
nsIDOMNode aParent,
PRInt32  aOffset,
InsertElementTxn **  aTxn 
) [protected, inherited]

create a transaction for inserting aNode as a child of aParent.

Definition at line 5036 of file nsEditor.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (aNode && aParent && aTxn)
  {
    result = TransactionFactory::GetNewTransaction(InsertElementTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result)) {
      result = (*aTxn)->Init(aNode, aParent, aPosition, this);
    }
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForInsertText ( const nsAString &  aStringToInsert,
nsIDOMCharacterData aTextNode,
PRInt32  aOffset,
InsertTextTxn **  aTxn 
) [protected, inherited]

create a transaction for inserting aStringToInsert into aTextNode if aTextNode is null, the string is inserted at the current selection.

Definition at line 3050 of file nsEditor.cpp.

{
  if (!aTextNode || !aTxn) return NS_ERROR_NULL_POINTER;
  nsresult result;

  result = TransactionFactory::GetNewTransaction(InsertTextTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_FAILED(result)) return result;
  if (!*aTxn) return NS_ERROR_OUT_OF_MEMORY;
  result = (*aTxn)->Init(aTextNode, aOffset, aStringToInsert, this);
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForJoinNode ( nsIDOMNode aLeftNode,
nsIDOMNode aRightNode,
JoinElementTxn **  aTxn 
) [protected, inherited]

Definition at line 3138 of file nsEditor.cpp.

{
  if (!aLeftNode || !aRightNode)
    return NS_ERROR_NULL_POINTER;

  nsresult result = TransactionFactory::GetNewTransaction(JoinElementTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_SUCCEEDED(result))  {
    result = (*aTxn)->Init(this, aLeftNode, aRightNode);
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForRemoveAttribute ( nsIDOMElement aElement,
const nsAString &  aAttribute,
ChangeAttributeTxn **  aTxn 
) [protected, inherited]

create a transaction for removing aAttribute on aElement

Definition at line 5001 of file nsEditor.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (nsnull != aElement)
  {
    result = TransactionFactory::GetNewTransaction(ChangeAttributeTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result))  
    {
      nsAutoString value;
      result = (*aTxn)->Init(this, aElement, aAttribute, value, PR_TRUE);
    }
  }
  return result;
}

Here is the call graph for this function:

create a transaction for removing a style sheet

Definition at line 5142 of file nsEditor.cpp.

{
  nsresult rv = TransactionFactory::GetNewTransaction(RemoveStyleSheetTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_FAILED(rv))
    return rv;
    
  if (! *aTxn)
    return NS_ERROR_OUT_OF_MEMORY;

  return (*aTxn)->Init(this, aSheet);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForSetAttribute ( nsIDOMElement aElement,
const nsAString &  aAttribute,
const nsAString &  aValue,
ChangeAttributeTxn **  aTxn 
) [protected, inherited]

create a transaction for setting aAttribute to aValue on aElement

Definition at line 4983 of file nsEditor.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (nsnull != aElement)
  {
    result = TransactionFactory::GetNewTransaction(ChangeAttributeTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result))  {
      result = (*aTxn)->Init(this, aElement, aAttribute, aValue, PR_FALSE);
    }
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEditor::CreateTxnForSplitNode ( nsIDOMNode aNode,
PRUint32  aOffset,
SplitElementTxn **  aTxn 
) [protected, inherited]

Definition at line 3124 of file nsEditor.cpp.

{
  if (!aNode)
    return NS_ERROR_NULL_POINTER;

  nsresult result = TransactionFactory::GetNewTransaction(SplitElementTxn::GetCID(), (EditTxn **)aTxn);
  if (NS_FAILED(result))
    return result;

  return (*aTxn)->Init(this, aNode, aOffset);
}

Here is the call graph for this function:

Reimplemented in nsHTMLEditorLog.

Definition at line 1073 of file nsPlaintextEditor.cpp.

{
  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res))
    return res;

  PRBool isCollapsed;
  if (NS_SUCCEEDED(selection->GetIsCollapsed(&isCollapsed)) && isCollapsed)
    return NS_OK;  // just return ok so no JS error is thrown

  res = Copy();
  if (NS_SUCCEEDED(res))
    res = DeleteSelection(eNone);
  return res;
}

Here is the call graph for this function:

void nsIEditor::cut ( ) [inherited]

cut the currently selected text, putting it into the OS clipboard What if no text is selected? What about mixed selections? What are the clipboard formats?

Dumps a text representation of the content tree to standard out.

void nsIEditor::debugUnitTests ( out long  outNumTests,
out long  outNumTestsFailed 
) [inherited]
void nsIEditor::deleteNode ( in nsIDOMNode  child) [inherited]

deleteNode removes aChild from aParent.

Parameters:
aChildThe node to delete

Reimplemented in nsHTMLEditorLog.

Definition at line 616 of file nsPlaintextEditor.cpp.

{
  if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }

  nsresult result;

  // delete placeholder txns merge.
  nsAutoPlaceHolderBatch batch(this, gDeleteTxnName);
  nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);

  // If it's one of these modes,
  // we have to extend the selection first.
  // This needs to happen inside selection batching,
  // otherwise the deleted text is autocopied to the clipboard.
  if (aAction == eNextWord || aAction == ePreviousWord
      || aAction == eToBeginningOfLine || aAction == eToEndOfLine)
  {
    if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
    nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
    if (!ps) return NS_ERROR_NOT_INITIALIZED;

    PRUint8 caretBidiLevel;
    result = ps->GetCaretBidiLevel(&caretBidiLevel);
    if (NS_FAILED(result)) return result;
    
    nsCOMPtr<nsISelectionController> selCont (do_QueryReferent(mSelConWeak));
    if (!selCont)
      return NS_ERROR_NO_INTERFACE;

    switch (aAction)
    {
        // if caret has odd Bidi level, i.e. text is right-to-left,
        // reverse the effect of ePreviousWord and eNextWord
        case eNextWord:
          result = (caretBidiLevel & 1) ?
                   selCont->WordMove(PR_FALSE, PR_TRUE) :
                   selCont->WordMove(PR_TRUE, PR_TRUE);
          // DeleteSelectionImpl doesn't handle these actions
          // because it's inside batching, so don't confuse it:
          aAction = eNone;
          break;
        case ePreviousWord:
          result = (caretBidiLevel & 1) ?
                   selCont->WordMove(PR_TRUE, PR_TRUE) :
                   selCont->WordMove(PR_FALSE, PR_TRUE);
          aAction = eNone;
          break;
        case eToBeginningOfLine:
          selCont->IntraLineMove(PR_TRUE, PR_FALSE);          // try to move to end
          result = selCont->IntraLineMove(PR_FALSE, PR_TRUE); // select to beginning
          aAction = eNone;
          break;
        case eToEndOfLine:
          result = selCont->IntraLineMove(PR_TRUE, PR_TRUE);
          aAction = eNext;
          break;
        default:       // avoid several compiler warnings
          result = NS_OK;
          break;
    }
    NS_ENSURE_SUCCESS(result, result);
  }

  // pre-process
  nsCOMPtr<nsISelection> selection;
  result = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(result)) return result;
  if (!selection) return NS_ERROR_NULL_POINTER;

  nsTextRulesInfo ruleInfo(nsTextEditRules::kDeleteSelection);
  ruleInfo.collapsedAction = aAction;
  PRBool cancel, handled;
  result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
  if (NS_FAILED(result)) return result;
  if (!cancel && !handled)
  {
    result = DeleteSelectionImpl(aAction);
  }
  if (!cancel)
  {
    // post-process 
    result = mRules->DidDoAction(selection, &ruleInfo, result);
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditor::deleteSelection ( in short  action) [inherited]

DeleteSelection removes all nodes in the current selection.

Parameters:
aDirif eNext, delete to the right (for example, the DEL key) if ePrevious, delete to the left (for example, the BACKSPACE key)

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::DeleteSelectionAndCreateNode ( const nsAString &  aTag,
nsIDOMNode **  aNewNode 
) [inherited]

Definition at line 4776 of file nsEditor.cpp.

{
  nsCOMPtr<nsIDOMNode> parentSelectedNode;
  PRInt32 offsetOfNewNode;
  nsresult result = DeleteSelectionAndPrepareToCreateNode(parentSelectedNode,
                                                          offsetOfNewNode);
  if (NS_FAILED(result))
    return result;

  nsCOMPtr<nsIDOMNode> newNode;
  result = CreateNode(aTag, parentSelectedNode, offsetOfNewNode,
                      getter_AddRefs(newNode));
  // XXX: ERROR_HANDLING  check result, and make sure aNewNode is set correctly in success/failure cases
  *aNewNode = newNode;
  NS_IF_ADDREF(*aNewNode);

  // we want the selection to be just after the new node
  nsCOMPtr<nsISelection> selection;
  result = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(result)) return result;
  if (!selection) return NS_ERROR_NULL_POINTER;
  return selection->Collapse(parentSelectedNode, offsetOfNewNode+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode ( nsCOMPtr< nsIDOMNode > &  parentSelectedNode,
PRInt32 offsetOfNewNode 
) [protected, inherited]

Definition at line 4848 of file nsEditor.cpp.

{
  nsresult result=NS_ERROR_NOT_INITIALIZED;
  nsCOMPtr<nsISelection> selection;
  result = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(result)) return result;
  if (!selection) return NS_ERROR_NULL_POINTER;

  PRBool collapsed;
  result = selection->GetIsCollapsed(&collapsed);
  if (NS_SUCCEEDED(result) && !collapsed) 
  {
    result = DeleteSelection(nsIEditor::eNone);
    if (NS_FAILED(result)) {
      return result;
    }
    // get the new selection
    result = GetSelection(getter_AddRefs(selection));
    if (NS_FAILED(result)) {
      return result;
    }
#ifdef NS_DEBUG
    nsCOMPtr<nsIDOMNode>testSelectedNode;
    nsresult debugResult = selection->GetAnchorNode(getter_AddRefs(testSelectedNode));
    // no selection is ok.
    // if there is a selection, it must be collapsed
    if (testSelectedNode)
    {
      PRBool testCollapsed;
      debugResult = selection->GetIsCollapsed(&testCollapsed);
      NS_ASSERTION((NS_SUCCEEDED(result)), "couldn't get a selection after deletion");
      NS_ASSERTION(testCollapsed, "selection not reset after deletion");
    }
#endif
  }
  // split the selected node
  PRInt32 offsetOfSelectedNode;
  result = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode));
  if (NS_SUCCEEDED(result) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetOfSelectedNode)) && parentSelectedNode)
  {
    nsCOMPtr<nsIDOMNode> selectedNode;
    PRUint32 selectedNodeContentCount=0;
    nsCOMPtr<nsIDOMCharacterData>selectedParentNodeAsText;
    selectedParentNodeAsText = do_QueryInterface(parentSelectedNode);

    offsetOfNewNode = offsetOfSelectedNode;
    
    /* if the selection is a text node, split the text node if necesary
       and compute where to put the new node
    */
    if (selectedParentNodeAsText) 
    { 
      PRInt32 indexOfTextNodeInParent;
      selectedNode = do_QueryInterface(parentSelectedNode);
      selectedNode->GetParentNode(getter_AddRefs(parentSelectedNode));
      selectedParentNodeAsText->GetLength(&selectedNodeContentCount);
      GetChildOffset(selectedNode, parentSelectedNode, indexOfTextNodeInParent);

      if ((offsetOfSelectedNode!=0) && (((PRUint32)offsetOfSelectedNode)!=selectedNodeContentCount))
      {
        nsCOMPtr<nsIDOMNode> newSiblingNode;
        result = SplitNode(selectedNode, offsetOfSelectedNode, getter_AddRefs(newSiblingNode));
        // now get the node's offset in it's parent, and insert the new tag there
        if (NS_SUCCEEDED(result)) {
          result = GetChildOffset(selectedNode, parentSelectedNode, offsetOfNewNode);
        }
      }
      else 
      { // determine where to insert the new node
        if (0==offsetOfSelectedNode) {
          offsetOfNewNode = indexOfTextNodeInParent; // insert new node as previous sibling to selection parent
        }
        else {                 // insert new node as last child
          GetChildOffset(selectedNode, parentSelectedNode, offsetOfNewNode);
          offsetOfNewNode++;    // offsets are 0-based, and we need the index of the new node
        }
      }
    }
    // Here's where the new node was inserted
  }
#ifdef DEBUG
  else {
    printf("InsertLineBreak into an empty document is not yet supported\n");
  }
#endif
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4734 of file nsEditor.cpp.

{
  nsCOMPtr<nsISelection>selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
  nsRefPtr<EditAggregateTxn> txn;
  res = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn));
  if (NS_FAILED(res)) return res;
  nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);

  PRInt32 i;
  nsIEditActionListener *listener;
  if (NS_SUCCEEDED(res))  
  {
    if (mActionListeners)
    {
      for (i = 0; i < mActionListeners->Count(); i++)
      {
        listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
        if (listener)
          listener->WillDeleteSelection(selection);
      }
    }

    res = DoTransaction(txn);  

    if (mActionListeners)
    {
      for (i = 0; i < mActionListeners->Count(); i++)
      {
        listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
        if (listener)
          listener->DidDeleteSelection(selection);
      }
    }
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::DeleteText ( nsIDOMCharacterData aElement,
PRUint32  aOffset,
PRUint32  aLength 
) [protected, inherited]

Reimplemented in nsHTMLEditor.

Definition at line 3066 of file nsEditor.cpp.

{
  nsRefPtr<DeleteTextTxn> txn;
  nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength,
                                           getter_AddRefs(txn));
  nsAutoRules beginRulesSniffing(this, kOpDeleteText, nsIEditor::ePrevious);
  if (NS_SUCCEEDED(result))  
  {
    // let listeners know whats up
    PRInt32 i;
    nsIEditActionListener *listener;
    if (mActionListeners)
    {
      for (i = 0; i < mActionListeners->Count(); i++)
      {
        listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
        if (listener)
          listener->WillDeleteText(aElement, aOffset, aLength);
      }
    }
    
    result = DoTransaction(txn); 
    
    // let listeners know what happened
    if (mActionListeners)
    {
      for (i = 0; i < mActionListeners->Count(); i++)
      {
        listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
        if (listener)
          listener->DidDeleteText(aElement, aOffset, aLength, result);
      }
    }
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsEditor::DoAfterDoTransaction ( nsITransaction aTxn) [protected, inherited]

Definition at line 4939 of file nsEditor.cpp.

{
  nsresult rv = NS_OK;
  
  PRBool  isTransientTransaction;
  rv = aTxn->GetIsTransient(&isTransientTransaction);
  if (NS_FAILED(rv))
    return rv;
  
  if (!isTransientTransaction)
  {
    // we need to deal here with the case where the user saved after some
    // edits, then undid one or more times. Then, the undo count is -ve,
    // but we can't let a do take it back to zero. So we flip it up to
    // a +ve number.
    PRInt32 modCount;
    GetModificationCount(&modCount);
    if (modCount < 0)
      modCount = -modCount;
        
    rv = IncrementModificationCount(1);    // don't count transient transactions
  }
  
  return rv;
}
NS_IMETHODIMP nsEditor::DoAfterRedoTransaction ( ) [protected, inherited]

Definition at line 4977 of file nsEditor.cpp.

{
  return IncrementModificationCount(1);    // all redoable transactions are non-transient
}
NS_IMETHODIMP nsEditor::DoAfterUndoTransaction ( ) [protected, inherited]

Definition at line 4967 of file nsEditor.cpp.

{
  nsresult rv = NS_OK;

  rv = IncrementModificationCount(-1);    // all undoable transactions are non-transient

  return rv;
}

Definition at line 368 of file nsPlaintextDataTransfer.cpp.

{
  nsresult rv;

  nsCOMPtr<nsITransferable> trans;
  rv = PutDragDataInTransferable(getter_AddRefs(trans));
  if (NS_FAILED(rv)) return rv;
  if (!trans) return NS_OK; // maybe there was nothing to copy?

 /* get the drag service */
  nsCOMPtr<nsIDragService> dragService = 
           do_GetService("@mozilla.org/widget/dragservice;1", &rv);
  if (NS_FAILED(rv)) return rv;

  /* create an array of transferables */
  nsCOMPtr<nsISupportsArray> transferableArray;
  NS_NewISupportsArray(getter_AddRefs(transferableArray));
  if (!transferableArray)
    return NS_ERROR_OUT_OF_MEMORY;

  /* add the transferable to the array */
  rv = transferableArray->AppendElement(trans);
  if (NS_FAILED(rv)) return rv;

  // check our transferable hooks (if any)
  nsCOMPtr<nsIDOMDocument> domdoc;
  GetDocument(getter_AddRefs(domdoc));
  if (!nsEditorHookUtils::DoDragHook(domdoc, aDragEvent, trans))
    return NS_OK;

  /* invoke drag */
  nsCOMPtr<nsIDOMEventTarget> eventTarget;
  rv = aDragEvent->GetTarget(getter_AddRefs(eventTarget));
  if (NS_FAILED(rv)) return rv;
  nsCOMPtr<nsIDOMNode> domnode = do_QueryInterface(eventTarget);

  unsigned int flags;
  // in some cases we'll want to cut rather than copy... hmmmmm...
  flags = nsIDragService::DRAGDROP_ACTION_COPY + nsIDragService::DRAGDROP_ACTION_MOVE;

  rv = dragService->InvokeDragSession(domnode, transferableArray, nsnull, flags);
  if (NS_FAILED(rv)) return rv;

  aDragEvent->StopPropagation();

  return rv;
}

Here is the call graph for this function:

void nsIEditor::doDrag ( in nsIDOMEvent  aEvent) [inherited]

doDrag transfers the relevant data (as appropriate) to a transferable so it can later be dropped.

doTransaction() fires a transaction.

It is provided here so clients can create their own transactions. If a transaction manager is present, it is used. Otherwise, the transaction is just executed directly.

Parameters:
aTxnthe transaction to execute

And a debug method -- show us what the tree looks like right now.

void nsIEditor::enableUndo ( in boolean  enable) [inherited]

turn the undo system on or off

Parameters:
aEnableif PR_TRUE, the undo system is turned on if available if PR_FALSE the undo system is turned off if it was previously on
Returns:
if aEnable is PR_TRUE, returns NS_OK if the undo system could be initialized properly if aEnable is PR_FALSE, returns NS_OK.

endComposition() Handles the end of inline input composition.

Definition at line 150 of file nsPlaintextEditor.cpp.

{
  nsresult res = NS_OK;
  NS_PRECONDITION(mInitTriggerCounter > 0, "ended editor init before we began?");
  mInitTriggerCounter--;
  if (mInitTriggerCounter == 0)
  {
    res = InitRules();
    if (NS_SUCCEEDED(res)) 
      EnableUndo(PR_TRUE);
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditor::endOfDocument ( ) [inherited]

sets the document selection to the end of the document

All editor operations which alter the doc should be followed with a call to EndOperation.

Reimplemented from nsEditor.

Reimplemented in nsHTMLEditor.

Definition at line 1673 of file nsPlaintextEditor.cpp.

{
  // post processing
  nsresult res = NS_OK;
  if (mRules) res = mRules->AfterEdit(mAction, mDirection);
  nsEditor::EndOperation();  // will clear mAction, mDirection
  return res;
}  

endTransaction is a signal to the editor that the caller is finished updating the content model.


beginUpdate must be called before endTransaction is called.
Calls to beginTransaction can be nested, as long as endTransaction is called once per beginTransaction.

nsresult nsEditor::EndUpdateViewBatch ( void  ) [virtual, inherited]

Reimplemented in nsHTMLEditor.

Definition at line 4641 of file nsEditor.cpp.

{
  NS_PRECONDITION(mUpdateCount > 0, "bad state");
  
  if (mUpdateCount <= 0)
  {
    mUpdateCount = 0;
    return NS_ERROR_FAILURE;
  }

  mUpdateCount--;

  if (0 == mUpdateCount)
  {
    // Hide the caret with an StCaretHider. By the time it goes out
    // of scope and tries to show the caret, reflow and selection changed
    // notifications should've happened so the caret should have enough info
    // to draw at the correct position.

    nsCOMPtr<nsICaret> caret;
    nsCOMPtr<nsIPresShell> presShell;
    GetPresShell(getter_AddRefs(presShell));

    if (presShell)
      presShell->GetCaret(getter_AddRefs(caret));

    StCaretHider caretHider(caret);
        
    PRUint32 flags = 0;

    GetFlags(&flags);

    // Turn reflow back on.
    //
    // Make sure we enable reflowing before we call
    // mViewManager->EndUpdateViewBatch().  This will make sure that any
    // new updates caused by a reflow, that may happen during the
    // EndReflowBatching(), get included if we force a refresh during
    // the mViewManager->EndUpdateViewBatch() call.

    if (presShell)
    {
      PRBool forceReflow = PR_TRUE;

      if (flags & nsIPlaintextEditor::eEditorUseAsyncUpdatesMask)
        forceReflow = PR_FALSE;

      presShell->EndReflowBatching(forceReflow);
    }

    // Turn view updating back on.

    if (mViewManager)
    {
      PRUint32 updateFlag = NS_VMREFRESH_IMMEDIATE;

      // If we're doing async updates, use NS_VMREFRESH_DEFERRED here, so that
      // the reflows we caused will get processed before the invalidates.
      if (flags & nsIPlaintextEditor::eEditorUseAsyncUpdatesMask)
        updateFlag = NS_VMREFRESH_DEFERRED;

      mViewManager->EndUpdateViewBatch(updateFlag);
    }

    // Turn selection updating and notifications back on.

    nsCOMPtr<nsISelection>selection;
    GetSelection(getter_AddRefs(selection));

    if (selection) {
      nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(selection));
      selPrivate->EndBatchChanges();
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

forceCompositionEnd() force the composition end

NS_IMETHODIMP nsPlaintextEditor::GetAndInitDocEncoder ( const nsAString &  aFormatType,
PRUint32  aFlags,
const nsACString &  aCharset,
nsIDocumentEncoder **  encoder 
) [protected]

Definition at line 1128 of file nsPlaintextEditor.cpp.

{
  nsCOMPtr<nsIPresShell> presShell;
  nsresult rv = GetPresShell(getter_AddRefs(presShell));
  if (NS_FAILED(rv)) return rv;
  if (!presShell) return NS_ERROR_FAILURE;

  nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
  formatType.AppendWithConversion(aFormatType);
  nsCOMPtr<nsIDocumentEncoder> docEncoder (do_CreateInstance(formatType.get(), &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsIDocument *doc = presShell->GetDocument();
  rv = docEncoder->Init(doc, aFormatType, aFlags);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!aCharset.IsEmpty()
    && !(aCharset.EqualsLiteral("null")))
    docEncoder->SetCharset(aCharset);

  PRInt32 wc;
  (void) GetWrapWidth(&wc);
  if (wc >= 0)
    (void) docEncoder->SetWrapColumn(wc);

  // Set the selection, if appropriate.
  // We do this either if the OutputSelectionOnly flag is set,
  // in which case we use our existing selection ...
  if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
  {
    nsCOMPtr<nsISelection> selection;
    rv = GetSelection(getter_AddRefs(selection));
    if (NS_SUCCEEDED(rv) && selection)
      rv = docEncoder->SetSelection(selection);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  // ... or if the root element is not a body,
  // in which case we set the selection to encompass the root.
  else
  {
    nsIDOMElement *rootElement = GetRoot();
    NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
    if (!nsTextEditUtils::IsBody(rootElement))
    {
      nsCOMPtr<nsIDOMRange> range (do_CreateInstance("@mozilla.org/content/range;1", &rv));
      NS_ENSURE_SUCCESS(rv, rv);

      rv = range->SelectNodeContents(rootElement);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = docEncoder->SetRange(range);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }

  NS_ADDREF(*encoder = docEncoder);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

boolean nsIEditor::getAttributeValue ( in nsIDOMElement  aElement,
in AString  attributestr,
out AString  resultValue 
) [inherited]

getAttributeValue() retrieves the attribute's value for aElement.

Parameters:
aElementthe content element to operate on
aAttributethe string representation of the attribute to get
aResultValue[OUT] the value of aAttribute. Only valid if aResultIsSet is PR_TRUE
Returns:
PR_TRUE if aAttribute is set on the current node, PR_FALSE if it is not.
nsCOMPtr< nsIDOMNode > nsEditor::GetChildAt ( nsIDOMNode aParent,
PRInt32  aOffset 
) [static, inherited]

Definition at line 4318 of file nsEditor.cpp.

{
  nsCOMPtr<nsIDOMNode> resultNode;
  
  nsCOMPtr<nsIContent> parent = do_QueryInterface(aParent);

  if (!parent) 
    return resultNode;

  resultNode = do_QueryInterface(parent->GetChildAt(aOffset));

  return resultNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetChildOffset ( nsIDOMNode aChild,
nsIDOMNode aParent,
PRInt32 aOffset 
) [static, inherited]

Set aOffset to the offset of aChild in aParent.

Returns an error if aChild is not an immediate child of aParent.

Definition at line 3501 of file nsEditor.cpp.

{
  NS_ASSERTION((aChild && aParent), "bad args");

  nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
  nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
  if (!cChild || !content)
    return NS_ERROR_NULL_POINTER;

  aOffset = content->IndexOf(cChild);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsEditor::GetDesiredSpellCheckState ( ) [protected, inherited]

Return true if spellchecking should be enabled for this editor.

Definition at line 489 of file nsEditor.cpp.

{
  // Check user override on this element
  if (mSpellcheckCheckboxState != eTriUnset) {
    return (mSpellcheckCheckboxState == eTriTrue);
  }

  // Check user preferences
  nsresult rv;
  nsCOMPtr<nsIPrefBranch> prefBranch =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
  PRInt32 spellcheckLevel = 1;
  if (NS_SUCCEEDED(rv) && prefBranch) {
    prefBranch->GetIntPref("layout.spellcheckDefault", &spellcheckLevel);
  }

  if (spellcheckLevel == 0) {
    return PR_FALSE;                    // Spellchecking forced off globally
  }

  // Check for password/readonly/disabled, which are not spellchecked
  // regardless of DOM
  PRUint32 flags;
  if (NS_SUCCEEDED(GetFlags(&flags)) &&
      flags & (nsIPlaintextEditor::eEditorPasswordMask |
               nsIPlaintextEditor::eEditorReadonlyMask |
               nsIPlaintextEditor::eEditorDisabledMask)) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIPresShell> presShell;
  rv = GetPresShell(getter_AddRefs(presShell));
  if (NS_SUCCEEDED(rv)) {
    nsPresContext* context = presShell->GetPresContext();
    if (context->Type() == nsPresContext::eContext_PrintPreview ||
        context->Type() == nsPresContext::eContext_Print) {
      return PR_FALSE;
    }
  }

  // Check DOM state
  nsCOMPtr<nsIContent> content = do_QueryInterface(GetRoot());
  if (!content) {
    return PR_FALSE;
  }

  if (content->IsNativeAnonymous()) {
    content = content->GetParent();
  }

  nsCOMPtr<nsIDOMNSHTMLElement_MOZILLA_1_8_BRANCH> element =
    do_QueryInterface(content);
  if (!element) {
    return PR_FALSE;
  }

  PRBool enable;
  element->GetSpellcheck(&enable);

  return enable;
}

Here is the call graph for this function:

Definition at line 845 of file nsPlaintextEditor.cpp.

{
  if (!aDocumentIsEmpty)
    return NS_ERROR_NULL_POINTER;
  
  if (!mRules)
    return NS_ERROR_NOT_INITIALIZED;
  
  return mRules->DocumentIsEmpty(aDocumentIsEmpty);
}

Here is the caller graph for this function:

Definition at line 5540 of file nsEditor.cpp.

{
  nsIDOMEventReceiver *erp = mDOMEventReceiver;
  if (erp)
  {
    NS_ADDREF(erp);
    return erp;
  }

  nsIDOMElement *rootElement = GetRoot();

  // Now hack to make sure we are not anonymous content.
  // If we are grab the parent of root element for our observer.

  nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement);

  if (content && content->IsNativeAnonymous())
  {
    mDOMEventReceiver = do_QueryInterface(content->GetParent());
    erp = mDOMEventReceiver;
    NS_IF_ADDREF(erp);
  }
  else
  {
    // Don't use getDocument here, because we have no way of knowing
    // if Init() was ever called.  So we need to get the document
    // ourselves, if it exists.
    if (mDocWeak)
    {
      CallQueryReferent(mDocWeak.get(), &erp);
    }
    else
    {
      NS_ERROR("not initialized yet");
    }
  }

  return erp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get a list of IMG and OBJECT tags in the current document.

nsresult nsEditor::GetEndNodeAndOffset ( nsISelection aSelection,
nsCOMPtr< nsIDOMNode > *  outEndNode,
PRInt32 outEndOffset 
) [static, inherited]

Definition at line 4376 of file nsEditor.cpp.

{
  if (!outEndNode || !outEndOffset) 
    return NS_ERROR_NULL_POINTER;
    
  nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
  nsCOMPtr<nsIEnumerator> enumerator;
  nsresult result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
  if (NS_FAILED(result) || !enumerator)
    return NS_ERROR_FAILURE;
    
  enumerator->First(); 
  nsCOMPtr<nsISupports> currentItem;
  if (NS_FAILED(enumerator->CurrentItem(getter_AddRefs(currentItem))))
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
  if (!range)
    return NS_ERROR_FAILURE;
    
  if (NS_FAILED(range->GetEndContainer(getter_AddRefs(*outEndNode))))
    return NS_ERROR_FAILURE;
    
  if (NS_FAILED(range->GetEndOffset(outEndOffset)))
    return NS_ERROR_FAILURE;
    
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetFirstEditableNode ( nsIDOMNode aRoot,
nsCOMPtr< nsIDOMNode > *  outFirstNode 
) [inherited]

Find the deep first and last children.

Returned nodes are AddReffed

Definition at line 2932 of file nsEditor.cpp.

{
  if (!aRoot || !outFirstNode) return NS_ERROR_NULL_POINTER;
  nsresult rv = NS_OK;
  *outFirstNode = nsnull;

  nsCOMPtr<nsIDOMNode> node = GetLeftmostChild(aRoot);
  if (node && !IsEditable(node))
  {
    nsCOMPtr<nsIDOMNode> next;
    rv = GetNextNode(node, PR_TRUE, address_of(next));
    node = next;
  }
  
  if (node != aRoot)
    *outFirstNode = node;

  return rv;
}

Here is the call graph for this function:

Reimplemented in nsHTMLEditor.

Definition at line 299 of file nsPlaintextEditor.cpp.

{
  if (!mRules || !aFlags) { return NS_ERROR_NULL_POINTER; }
  return mRules->GetFlags(aFlags);
}

Here is the caller graph for this function:

nsresult nsEditor::GetIMEBufferLength ( PRInt32 length) [inherited]

Definition at line 4805 of file nsEditor.cpp.

{
  *length = mIMEBufferLength;
  return NS_OK;
}

Here is the caller graph for this function:

PRInt32 nsEditor::GetIndexOf ( nsIDOMNode aParent,
nsIDOMNode aChild 
) [static, inherited]

Definition at line 4303 of file nsEditor.cpp.

{
  nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
  nsCOMPtr<nsIContent> cChild = do_QueryInterface(child);
  NS_PRECONDITION(content, "null content in nsEditor::GetIndexOf");
  NS_PRECONDITION(cChild, "null content in nsEditor::GetIndexOf");

  return content->IndexOf(cChild);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the inline spell checker associated with this object.

The spell checker is lazily created, so this function may create the object for you during this call.

Parameters:
autoCreateIf true, this will create a spell checker object if one does not exist yet for this editor. If false and the object has not been created, this function WILL RETURN NULL.

Reimplemented in nsHTMLEditor.

Definition at line 325 of file nsPlaintextEditor.cpp.

{
  NS_ENSURE_ARG_POINTER(aIsDocumentEditable);

  nsCOMPtr<nsIDOMDocument> doc;
  GetDocument(getter_AddRefs(doc));
  *aIsDocumentEditable = doc ? IsModifiable() : PR_FALSE;

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsEditor::GetKBStateControl ( nsIKBStateControl **  aKBSC) [protected, inherited]

Definition at line 2325 of file nsEditor.cpp.

{
  if (!aKBSC)
    return NS_ERROR_NULL_POINTER;
  *aKBSC = nsnull;
  nsCOMPtr<nsIPresShell> shell;
  nsresult res = GetPresShell(getter_AddRefs(shell));

  if (NS_FAILED(res))
    return res;

  if (!shell)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIWidget> widget;
  res = GetEditorContentWindow(shell, GetRoot(), getter_AddRefs(widget));
  if (NS_FAILED(res))
    return res;

  nsCOMPtr<nsIKBStateControl> kb = do_QueryInterface(widget);
  if (!kb)
    return NS_ERROR_NOT_INITIALIZED;

  NS_ADDREF(*aKBSC = kb);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsPlaintextEditor::GetLayoutObject ( nsIDOMNode aInNode,
nsISupports **  aOutLayoutObject 
) [protected]

returns the layout object (nsIFrame in the real world) for aNode

Parameters:
aNodethe content to get a frame for
aLayoutObjectthe "primary frame" for aNode, if one exists. May be null
Returns:
NS_OK whether a frame is found or not an error if some serious error occurs

Reimplemented in nsHTMLEditor.

Definition at line 1713 of file nsPlaintextEditor.cpp.

{
  nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
  if (!ps) return NS_ERROR_NOT_INITIALIZED;

  nsresult result = NS_ERROR_NULL_POINTER;
  if (aNode)
  { // get the content interface
    nsCOMPtr<nsIContent> nodeAsContent( do_QueryInterface(aNode) );
    if (nodeAsContent)
    { // get the frame from the content interface
      //Note: frames are not ref counted, so don't use an nsCOMPtr
      *aLayoutObject = nsnull;
      result = ps->GetLayoutObjectFor(nodeAsContent, aLayoutObject);
    }
  }

  return result;
}

Here is the call graph for this function:

nsCOMPtr< nsIDOMNode > nsEditor::GetLeftmostChild ( nsIDOMNode aCurrentNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

Get the leftmost child of aCurrentNode; return nsnull if aCurrentNode has no children.

Definition at line 3912 of file nsEditor.cpp.

{
  if (!aCurrentNode) return nsnull;
  nsCOMPtr<nsIDOMNode> resultNode, temp=aCurrentNode;
  PRBool hasChildren;
  aCurrentNode->HasChildNodes(&hasChildren);
  while (hasChildren)
  {
    temp->GetFirstChild(getter_AddRefs(resultNode));
    if (resultNode)
    {
      if (bNoBlockCrossing && IsBlockNode(resultNode))
         return resultNode;
      resultNode->HasChildNodes(&hasChildren);
      temp = resultNode;
    }
    else 
      hasChildren = PR_FALSE;
  }

  return resultNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetLengthOfDOMNode ( nsIDOMNode aNode,
PRUint32 aCount 
) [static, inherited]

returns the number of things inside aNode in the out-param aCount.

Parameters:
aNodeis the node to get the length of. If aNode is text, returns number of characters. If not, returns number of children nodes.
aCount[OUT] the result of the above calculation.

Definition at line 3534 of file nsEditor.cpp.

{
  aCount = 0;
  if (!aNode) { return NS_ERROR_NULL_POINTER; }
  nsresult result=NS_OK;
  nsCOMPtr<nsIDOMCharacterData>nodeAsChar = do_QueryInterface(aNode);
  if (nodeAsChar) {
    nodeAsChar->GetLength(&aCount);
  }
  else
  {
    PRBool hasChildNodes;
    aNode->HasChildNodes(&hasChildNodes);
    if (hasChildNodes)
    {
      nsCOMPtr<nsIDOMNodeList>nodeList;
      result = aNode->GetChildNodes(getter_AddRefs(nodeList));
      if (NS_SUCCEEDED(result) && nodeList) {
        nodeList->GetLength(&aCount);
      }
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the modification count of the document we are editing.

Returns:
the modification count of the document being edited. Zero means unchanged.
nsresult nsEditor::GetNextNode ( nsIDOMNode aCurrentNode,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

get the node immediately after to aCurrentNode

Parameters:
aCurrentNodethe node from which we start the search
aEditableNodeif PR_TRUE, only return an editable node
aResultNode[OUT] the node that occurs after aCurrentNode in the tree, skipping non-editable nodes if aEditableNode is PR_TRUE. If there is no prior node, aResultNode will be nsnull.

Definition at line 3773 of file nsEditor.cpp.

{
  if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
  
  *aResultNode = nsnull;  // init out-param

  if (IsRootNode(aCurrentNode))
  {
    // Don't allow traversal above the root node! This helps
    // prevent us from accidentally editing browser content
    // when the editor is in a text widget.

    return NS_OK;
  }

  nsCOMPtr<nsIDOMNode> candidate;
  nsresult result = GetNextNodeImpl(aCurrentNode, aEditableNode,
                                    address_of(candidate), bNoBlockCrossing);
  if (NS_FAILED(result)) return result;
  
  if (!candidate)
  {
    // we could not find a next node.  return null.
    *aResultNode = nsnull;
    return NS_OK;
  }
  else if (!aEditableNode) *aResultNode = candidate;
  else if (IsEditable(candidate)) *aResultNode = candidate;
  else 
  { // restart the search from the non-editable node we just found
    nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(candidate);
    return GetNextNode(notEditableNode, aEditableNode, aResultNode, bNoBlockCrossing);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetNextNode ( nsIDOMNode aParentNode,
PRInt32  aOffset,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

Definition at line 3601 of file nsEditor.cpp.

{
  // just another version of GetNextNode that takes a {parent, offset}
  // instead of a node
  if (!aParentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
  
  *aResultNode = nsnull;

  // if aParentNode is a text node, use it's location instead
  if (IsTextNode(aParentNode))
  {
    nsCOMPtr<nsIDOMNode> parent;
    nsEditor::GetNodeLocation(aParentNode, address_of(parent), &aOffset);
    aParentNode = parent;
    aOffset++;  // _after_ the text node
  }
  // look at the child at 'aOffset'
  nsCOMPtr<nsIDOMNode> child = GetChildAt(aParentNode, aOffset);
  if (child)
  {
    if (bNoBlockCrossing && IsBlockNode(child))
    {
      *aResultNode = child;  // return this block
      return NS_OK;
    }
    *aResultNode = GetLeftmostChild(child, bNoBlockCrossing);
    if (!*aResultNode) 
    {
      *aResultNode = child;
      return NS_OK;
    }
    if (!IsDescendantOfBody(*aResultNode))
    {
      *aResultNode = nsnull;
      return NS_OK;
    }

    if (!aEditableNode || IsEditable(*aResultNode))
      return NS_OK;

    // restart the search from the non-editable node we just found
    nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
    return GetNextNode(notEditableNode, aEditableNode, aResultNode, bNoBlockCrossing);
  }
    
  // unless there isn't one, in which case we are at the end of the node
  // and want the next one.
  if (bNoBlockCrossing && IsBlockNode(aParentNode))
  {
    // don't cross out of parent block
    return NS_OK;
  }
  return GetNextNode(aParentNode, aEditableNode, aResultNode, bNoBlockCrossing);
}

Here is the call graph for this function:

nsresult nsEditor::GetNextNodeImpl ( nsIDOMNode aCurrentNode,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [protected, inherited]

Definition at line 3814 of file nsEditor.cpp.

{
  // called only by GetNextNode so we don't need to check params.

  // if aCurrentNode has a right sibling, return that sibling's leftmost child (or itself if it has no children)
  nsCOMPtr<nsIDOMNode> nextSibling;
  nsresult result = aCurrentNode->GetNextSibling(getter_AddRefs(nextSibling));
  if ((NS_SUCCEEDED(result)) && nextSibling)
  {
    if (bNoBlockCrossing && IsBlockNode(nextSibling))
    {
      // next sibling is a block, do not step into it
      *aResultNode = nextSibling;
      return NS_OK;
    }
    *aResultNode = GetLeftmostChild(nextSibling, bNoBlockCrossing);
    if (!*aResultNode)
    { 
      *aResultNode = nextSibling;
      return NS_OK; 
    }
    if (!IsDescendantOfBody(*aResultNode))
    {
      *aResultNode = nsnull;
      return NS_OK;
    }
  }
  else
  {
    // otherwise, walk up the parent tree until there is a child that comes after 
    // the ancestor of aCurrentNode.  Then return that node's leftmost child
    nsCOMPtr<nsIDOMNode> parent(do_QueryInterface(aCurrentNode));
    nsCOMPtr<nsIDOMNode> node, notEditableNode;
    do {
      node = parent;
      result = node->GetParentNode(getter_AddRefs(parent));
      if ((NS_SUCCEEDED(result)) && parent)
      {
        if (!IsDescendantOfBody(parent))
        {
          *aResultNode = nsnull;
          return NS_OK;
        }
        if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent))
        {
          // we are at end of block or root, do not step out
          *aResultNode = nsnull;
          return NS_OK;
        }
        result = parent->GetNextSibling(getter_AddRefs(node));
        if ((NS_SUCCEEDED(result)) && node)
        {
          if (bNoBlockCrossing && IsBlockNode(node))
          {
            // next sibling is a block, do not step into it
            *aResultNode = node;
            return NS_OK;
          }
          *aResultNode = GetLeftmostChild(node, bNoBlockCrossing);
          if (!*aResultNode) *aResultNode = node;
          return NS_OK; 
        }
      }
    } while ((NS_SUCCEEDED(result)) && parent);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetNodeLocation ( nsIDOMNode aChild,
nsCOMPtr< nsIDOMNode > *  aParent,
PRInt32 aOffset 
) [static, inherited]

Set aParent to the parent of aChild.

Set aOffset to the offset of aChild in aParent.

Definition at line 3516 of file nsEditor.cpp.

{
  NS_ASSERTION((inChild && outParent && outOffset), "bad args");
  nsresult result = NS_ERROR_NULL_POINTER;
  if (inChild && outParent && outOffset)
  {
    result = inChild->GetParentNode(getter_AddRefs(*outParent));
    if ((NS_SUCCEEDED(result)) && (*outParent))
    {
      result = GetChildOffset(inChild, *outParent, *outOffset);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetPresShell ( nsIPresShell **  aPS) [inherited]

Definition at line 619 of file nsEditor.cpp.

{
  if (!aPS)
    return NS_ERROR_NULL_POINTER;
  *aPS = nsnull; // init out param
  NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak");
  nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
  if (!ps) return NS_ERROR_NOT_INITIALIZED;
  NS_ADDREF(*aPS = ps);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetPriorNode ( nsIDOMNode aCurrentNode,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

get the node immediately prior to aCurrentNode

Parameters:
aCurrentNodethe node from which we start the search
aEditableNodeif PR_TRUE, only return an editable node
aResultNode[OUT] the node that occurs before aCurrentNode in the tree, skipping non-editable nodes if aEditableNode is PR_TRUE. If there is no prior node, aResultNode will be nsnull.

Definition at line 3662 of file nsEditor.cpp.

{
  nsresult result;
  if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
  
  *aResultNode = nsnull;  // init out-param

  if (IsRootNode(aCurrentNode))
  {
    // Don't allow traversal above the root node! This helps
    // prevent us from accidentally editing browser content
    // when the editor is in a text widget.

    return NS_OK;
  }

  nsCOMPtr<nsIDOMNode> candidate;
  result = GetPriorNodeImpl(aCurrentNode, aEditableNode, address_of(candidate), bNoBlockCrossing);
  if (NS_FAILED(result)) return result;
  
  if (!candidate)
  {
    // we could not find a prior node.  return null.
    return NS_OK;
  }
  else if (!aEditableNode) *aResultNode = candidate;
  else if (IsEditable(candidate)) *aResultNode = candidate;
  else 
  { // restart the search from the non-editable node we just found
    nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(candidate);
    return GetPriorNode(notEditableNode, aEditableNode, aResultNode, bNoBlockCrossing);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetPriorNode ( nsIDOMNode aParentNode,
PRInt32  aOffset,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

Definition at line 3561 of file nsEditor.cpp.

{
  // just another version of GetPriorNode that takes a {parent, offset}
  // instead of a node
  if (!aParentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
  *aResultNode = nsnull;
  
  // if we are at beginning of node, or it is a textnode, then just look before it
  if (!aOffset || IsTextNode(aParentNode))
  {
    if (bNoBlockCrossing && IsBlockNode(aParentNode))
    {
      // if we aren't allowed to cross blocks, don't look before this block
      return NS_OK;
    }
    return GetPriorNode(aParentNode, aEditableNode, aResultNode, bNoBlockCrossing);
  }

  // else look before the child at 'aOffset'
  nsCOMPtr<nsIDOMNode> child = GetChildAt(aParentNode, aOffset);
  if (child)
    return GetPriorNode(child, aEditableNode, aResultNode, bNoBlockCrossing);

  // unless there isn't one, in which case we are at the end of the node
  // and want the deep-right child.
  *aResultNode = GetRightmostChild(aParentNode, bNoBlockCrossing);
  if (!*aResultNode || !aEditableNode || IsEditable(*aResultNode))
    return NS_OK;

  // restart the search from the non-editable node we just found
  nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
  return GetPriorNode(notEditableNode, aEditableNode, aResultNode, bNoBlockCrossing);
}

Here is the call graph for this function:

nsresult nsEditor::GetPriorNodeImpl ( nsIDOMNode aCurrentNode,
PRBool  aEditableNode,
nsCOMPtr< nsIDOMNode > *  aResultNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [protected, inherited]

Definition at line 3701 of file nsEditor.cpp.

{
  // called only by GetPriorNode so we don't need to check params.

  // if aCurrentNode has a left sibling, return that sibling's rightmost child (or itself if it has no children)
  nsCOMPtr<nsIDOMNode> prevSibling;
  nsresult result = aCurrentNode->GetPreviousSibling(getter_AddRefs(prevSibling));
  if ((NS_SUCCEEDED(result)) && prevSibling)
  {
    if (bNoBlockCrossing && IsBlockNode(prevSibling))
    {
      // don't look inside prevsib, since it is a block
      *aResultNode = prevSibling;
      return NS_OK;
    }
    *aResultNode = GetRightmostChild(prevSibling, bNoBlockCrossing);
    if (!*aResultNode) 
    { 
      *aResultNode = prevSibling;
      return NS_OK;
    }
    if (!IsDescendantOfBody(*aResultNode))
    {
      *aResultNode = nsnull;
      return NS_OK;
    }
  }
  else
  {
    // otherwise, walk up the parent tree until there is a child that comes before 
    // the ancestor of aCurrentNode.  Then return that node's rightmost child
    nsCOMPtr<nsIDOMNode> parent = do_QueryInterface(aCurrentNode);
    nsCOMPtr<nsIDOMNode> node, notEditableNode;
    do {
      node = parent;
      result = node->GetParentNode(getter_AddRefs(parent));
      if ((NS_SUCCEEDED(result)) && parent)
      {
        if (!IsDescendantOfBody(parent))
        {
          *aResultNode = nsnull;
          return NS_OK;
        }
        if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent))
        {
          // we are at front of block or root, do not step out
          *aResultNode = nsnull;
          return NS_OK;
        }
        result = parent->GetPreviousSibling(getter_AddRefs(node));
        if ((NS_SUCCEEDED(result)) && node)
        {
          if (bNoBlockCrossing && IsBlockNode(node))
          {
            // prev sibling is a block, do not step into it
            *aResultNode = node;
            return NS_OK;
          }
          *aResultNode = GetRightmostChild(node, bNoBlockCrossing);
          if (!*aResultNode)  *aResultNode = node;
          return NS_OK;
        }
      }
    } while ((NS_SUCCEEDED(result)) && parent && !*aResultNode);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

getQueryCaretRect() Get the query caret rect

Definition at line 1619 of file nsPlaintextEditor.cpp.

{
  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
  if (!selection) return NS_ERROR_FAILURE;

  // XXX get the first range in the selection.  Since it is
  // unclear what to do if reconversion happens with a 
  // multirange selection, we will ignore any additional ranges.
  
  nsCOMPtr<nsIDOMRange> range;
  res = selection->GetRangeAt(0, getter_AddRefs(range));
  if (NS_FAILED(res)) return res;
  if (!range) return NS_ERROR_FAILURE;
  
  nsAutoString textValue;
  res = range->ToString(textValue);
  if (NS_FAILED(res))
    return res;
  
  aReply->mReconversionString = (PRUnichar*) nsMemory::Clone(textValue.get(),
                                                                (textValue.Length() + 1) * sizeof(PRUnichar));
  if (!aReply->mReconversionString)
    return NS_ERROR_OUT_OF_MEMORY;

  if (textValue.IsEmpty())
    return NS_OK;

  // delete the selection
  return DeleteSelection(eNone);
}

Here is the call graph for this function:

getReconversionString() Get the reconvertion string

nsCOMPtr< nsIDOMNode > nsEditor::GetRightmostChild ( nsIDOMNode aCurrentNode,
PRBool  bNoBlockCrossing = PR_FALSE 
) [inherited]

Get the rightmost child of aCurrentNode; return nsnull if aCurrentNode has no children.

Definition at line 3887 of file nsEditor.cpp.

{
  if (!aCurrentNode) return nsnull;
  nsCOMPtr<nsIDOMNode> resultNode, temp=aCurrentNode;
  PRBool hasChildren;
  aCurrentNode->HasChildNodes(&hasChildren);
  while (hasChildren)
  {
    temp->GetLastChild(getter_AddRefs(resultNode));
    if (resultNode)
    {
      if (bNoBlockCrossing && IsBlockNode(resultNode))
         return resultNode;
      resultNode->HasChildNodes(&hasChildren);
      temp = resultNode;
    }
    else 
      hasChildren = PR_FALSE;
  }

  return resultNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIDOMElement * nsEditor::GetRoot ( ) [inherited]

Definition at line 5581 of file nsEditor.cpp.

{
  if (!mRootElement)
  {
    nsCOMPtr<nsIDOMElement> root;

    // Let GetRootElement() do the work
    GetRootElement(getter_AddRefs(root));
  }

  return mRootElement;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4720 of file nsEditor.cpp.

Here is the caller graph for this function:

nsresult nsEditor::GetStartNodeAndOffset ( nsISelection aSelection,
nsCOMPtr< nsIDOMNode > *  outStartNode,
PRInt32 outStartOffset 
) [static, inherited]

Definition at line 4338 of file nsEditor.cpp.

{
  if (!outStartNode || !outStartOffset || !aSelection) 
    return NS_ERROR_NULL_POINTER;

  // brade:  set outStartNode to null or ?

  nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
  nsCOMPtr<nsIEnumerator> enumerator;
  nsresult result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
  if (NS_FAILED(result) || !enumerator)
    return NS_ERROR_FAILURE;
    
  enumerator->First(); 
  nsCOMPtr<nsISupports> currentItem;
  if (NS_FAILED(enumerator->CurrentItem(getter_AddRefs(currentItem))))
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
  if (!range)
    return NS_ERROR_FAILURE;
    
  if (NS_FAILED(range->GetStartContainer(getter_AddRefs(*outStartNode))))
    return NS_ERROR_FAILURE;
    
  if (NS_FAILED(range->GetStartOffset(outStartOffset)))
    return NS_ERROR_FAILURE;
    
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsEditor::GetString ( const nsAString &  name,
nsAString &  value 
) [inherited]
nsIAtom * nsEditor::GetTag ( nsIDOMNode aNode) [static, inherited]

Definition at line 4209 of file nsEditor.cpp.

{
  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);

  if (!content) 
  {
    NS_ASSERTION(aNode, "null node passed to nsEditor::Tag()");

    return nsnull;
  }
  
  return content->Tag();
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetTagString ( nsIDOMNode aNode,
nsAString &  outString 
) [static, inherited]

from html rules code - migration in progress

Definition at line 4228 of file nsEditor.cpp.

{
  if (!aNode) 
  {
    NS_NOTREACHED("null node passed to nsEditor::GetTag()");
    return NS_ERROR_NULL_POINTER;
  }
  
  nsIAtom *atom = GetTag(aNode);
  if (!atom)
  {
    return NS_ERROR_FAILURE;
  }

  atom->ToString(outString);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::GetTextNodeTag ( nsAString &  aOutString) [static, inherited]

return the string that represents text nodes in the content tree

static helper method

Definition at line 2724 of file nsEditor.cpp.

{
  aOutString.Truncate();
  static nsString *gTextNodeTag=nsnull;
  if (!gTextNodeTag)
  {
    if ( (gTextNodeTag = new nsString) == 0 )
      return NS_ERROR_OUT_OF_MEMORY;
    gTextNodeTag->AssignLiteral("special text node tag");
  }
  aOutString = *gTextNodeTag;
  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsPlaintextEditor::GetTextSelectionOffsets ( nsISelection aSelection,
PRUint32 aStartOffset,
PRUint32 aEndOffset 
)

Returns the absolute position of the end points of aSelection in the document as a text stream.

Invariant: aStartOffset <= aEndOffset.

Definition at line 535 of file nsPlaintextEditor.cpp.

{
  NS_ASSERTION(aSelection, "null selection");

  nsresult rv;
  nsCOMPtr<nsIDOMNode> startNode, endNode;
  PRInt32 startNodeOffset, endNodeOffset;
  aSelection->GetAnchorNode(getter_AddRefs(startNode));
  aSelection->GetAnchorOffset(&startNodeOffset);
  aSelection->GetFocusNode(getter_AddRefs(endNode));
  aSelection->GetFocusOffset(&endNodeOffset);

  nsIDOMElement* rootNode = GetRoot();
  NS_ENSURE_TRUE(rootNode, NS_ERROR_NULL_POINTER);

  PRInt32 startOffset = -1;
  PRInt32 endOffset = -1;

  nsCOMPtr<nsIContentIterator> iter =
    do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);
    
#ifdef NS_DEBUG
  PRInt32 nodeCount = 0; // only needed for the assertions below
#endif
  PRUint32 totalLength = 0;
  nsCOMPtr<nsIContent> rootContent = do_QueryInterface(rootNode);
  iter->Init(rootContent);
  for (; !iter->IsDone() && (startOffset == -1 || endOffset == -1); iter->Next()) {
    nsCOMPtr<nsIDOMNode> currentNode = do_QueryInterface(iter->GetCurrentNode());
    nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(currentNode);
    if (textNode) {
      // Note that sometimes we have an empty #text-node as start/endNode,
      // which we regard as not editable because the frame width == 0,
      // see nsEditor::IsEditable().
      PRBool editable = IsEditable(currentNode);
      if (currentNode == startNode) {
        startOffset = totalLength + (editable ? startNodeOffset : 0);
      }
      if (currentNode == endNode) {
        endOffset = totalLength + (editable ? endNodeOffset : 0);
      }
      if (editable) {
        PRUint32 length;
        textNode->GetLength(&length);
        totalLength += length;
      }
    }
#ifdef NS_DEBUG
    ++nodeCount;
#endif
  }

  if (endOffset == -1) {
    NS_ASSERTION(endNode == rootNode, "failed to find the end node");
    NS_ASSERTION(endNodeOffset == nodeCount-1 || endNodeOffset == 0,
                 "invalid end node offset");
    endOffset = endNodeOffset == 0 ? 0 : totalLength;
  }
  if (startOffset == -1) {
    NS_ASSERTION(startNode == rootNode, "failed to find the start node");
    NS_ASSERTION(startNodeOffset == nodeCount-1 || startNodeOffset == 0,
                 "invalid start node offset");
    startOffset = startNodeOffset == 0 ? 0 : totalLength;
  }

  // Make sure aOutStartOffset <= aOutEndOffset.
  if (startOffset <= endOffset) {
    aOutStartOffset = startOffset;
    aOutEndOffset = endOffset;
  }
  else {
    aOutStartOffset = endOffset;
    aOutEndOffset = startOffset;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::GetWrapWidth ( PRInt32 aWrapCol) [protected, inherited]

Definition at line 1237 of file nsEditor.cpp.

{
  NS_ENSURE_ARG_POINTER(aWrapColumn);
  *aWrapColumn = 72;

  nsresult rv;
  nsCOMPtr<nsIPrefBranch> prefBranch =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv) && prefBranch)
    (void) prefBranch->GetIntPref("editor.htmlWrapColumn", aWrapColumn);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEditor::HandleInlineSpellCheck ( PRInt32  action,
nsISelection aSelection,
nsIDOMNode previousSelectedNode,
PRInt32  previousSelectedOffset,
nsIDOMNode aStartNode,
PRInt32  aStartOffset,
nsIDOMNode aEndNode,
PRInt32  aEndOffset 
) [inherited]

Definition at line 5520 of file nsEditor.cpp.

{
  return mInlineSpellChecker ? mInlineSpellChecker->SpellCheckAfterEditorChange(action,
                                                       aSelection,
                                                       previousSelectedNode,
                                                       previousSelectedOffset,
                                                       aStartNode,
                                                       aStartOffset,
                                                       aEndNode,
                                                       aEndOffset) : NS_OK;
}

Here is the caller graph for this function:

EditorKeyPress consumes a keyevent.

Parameters:
aKeyEventkey event to consume
NS_IMETHOD nsPlaintextEditor::IgnoreSpuriousDragEvent ( PRBool  aIgnoreSpuriousDragEvent) [inline, protected]

Definition at line 216 of file nsPlaintextEditor.h.

{mIgnoreSpuriousDragEvent = aIgnoreSpuriousDragEvent; return NS_OK;}
void nsIEditor::incrementModificationCount ( in long  aModCount) [inherited]

called each time we modify the document.

Increments the modification count of the document.

Parameters:
aModCountthe number of modifications by which to increase or decrease the count
void nsIEditor::init ( in nsIDOMDocument  doc,
in nsIPresShellPtr  shell,
in nsIContentPtr  aRoot,
in nsISelectionController  aSelCon,
in unsigned long  aFlags 
) [inherited]

Init is to tell the implementation of nsIEditor to begin its services.

Parameters:
aDocThe dom document interface being observed
aPresShellTEMP: The presentation shell displaying the document. Once events can tell us from what pres shell they originated, this will no longer be necessary, and the editor will no longer be linked to a single pres shell.
aRootThis is the root of the editable section of this document. If it is null then we get root from document body.
aSelConthis should be used to get the selection location
aFlagsA bitmask of flags for specifying the behavior of the editor.
NS_IMETHODIMP nsPlaintextEditor::Init ( nsIDOMDocument aDoc,
nsIPresShell aPresShell,
nsIContent aRoot,
nsISelectionController aSelCon,
PRUint32  aFlags 
)

prepare the editor for use

Reimplemented in nsHTMLEditor.

Definition at line 121 of file nsPlaintextEditor.cpp.

{
  NS_PRECONDITION(aDoc && aPresShell, "bad arg");
  if (!aDoc || !aPresShell)
    return NS_ERROR_NULL_POINTER;
  
  nsresult res = NS_OK, rulesRes = NS_OK;
  
  if (1)
  {
    // block to scope nsAutoEditInitRulesTrigger
    nsAutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
  
    // Init the base editor
    res = nsEditor::Init(aDoc, aPresShell, aRoot, aSelCon, aFlags);
  }
  
  if (NS_FAILED(rulesRes)) return rulesRes;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in nsHTMLEditor.

Definition at line 314 of file nsPlaintextEditor.cpp.

{
  // instantiate the rules for this text editor
  nsresult res = NS_NewTextEditRules(getter_AddRefs(mRules));
  if (NS_FAILED(res)) return res;
  if (!mRules) return NS_ERROR_UNEXPECTED;
  return mRules->Init(this, mFlags);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIDOMNode nsIEditorMailSupport::insertAsCitedQuotation ( in AString  aQuotedText,
in AString  aCitation,
in boolean  aInsertHTML 
) [inherited]

Insert a string as quoted text (whose representation is dependant on the editor type), replacing the selected text (if any), including, if possible, a "cite" attribute.

Parameters:
aQuotedTextThe actual text to be quoted
aCitationThe "mid" URL of the source message
aInsertHTMLInsert as html? (vs plaintext)
Returns:
The node which was inserted
nsIDOMNode nsIEditorMailSupport::insertAsQuotation ( in AString  aQuotedText) [inherited]

Insert a string as quoted text (whose representation is dependant on the editor type), replacing the selected text (if any).

Parameters:
aQuotedTextThe actual text to be quoted
Returns:
The node which was inserted

Reimplemented in nsHTMLEditor.

Definition at line 499 of file nsPlaintextEditor.cpp.

{
  if (!outBRNode) return NS_ERROR_NULL_POINTER;
  *outBRNode = nsnull;

  // calling it text insertion to trigger moz br treatment by rules
  nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);

  nsCOMPtr<nsISelection> selection;
  nsresult res = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(res)) return res;
  PRBool bCollapsed;
  res = selection->GetIsCollapsed(&bCollapsed);
  if (NS_FAILED(res)) return res;
  if (!bCollapsed)
  {
    res = DeleteSelection(nsIEditor::eNone);
    if (NS_FAILED(res)) return res;
  }
  nsCOMPtr<nsIDOMNode> selNode;
  PRInt32 selOffset;
  res = GetStartNodeAndOffset(selection, address_of(selNode), &selOffset);
  if (NS_FAILED(res)) return res;
  
  res = CreateBR(selNode, selOffset, outBRNode);
  if (NS_FAILED(res)) return res;
    
  // position selection after br
  res = GetNodeLocation(*outBRNode, address_of(selNode), &selOffset);
  if (NS_FAILED(res)) return res;
  nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
  selPriv->SetInterlinePosition(PR_TRUE);
  return selection->Collapse(selNode, selOffset+1);
}

Here is the call graph for this function:

nsresult nsEditor::InsertContainerAbove ( nsIDOMNode inNode,
nsCOMPtr< nsIDOMNode > *  outNode,
const nsAString &  aNodeType,
const nsAString *  aAttribute = nsnull,
const nsAString *  aValue = nsnull 
) [inherited]

Definition at line 1794 of file nsEditor.cpp.

{
  if (!inNode || !outNode)
    return NS_ERROR_NULL_POINTER;
  nsCOMPtr<nsIDOMNode> parent;
  PRInt32 offset;
  nsresult res = GetNodeLocation(inNode, address_of(parent), &offset);
  if (NS_FAILED(res)) return res;

  // create new container
  nsCOMPtr<nsIContent> newContent;

  //new call to use instead to get proper HTML element, bug# 39919
  res = CreateHTMLContent(aNodeType, getter_AddRefs(newContent));
  nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(newContent);
  if (NS_FAILED(res)) return res;
  *outNode = do_QueryInterface(elem);
  
  // set attribute if needed
  if (aAttribute && aValue && !aAttribute->IsEmpty())
  {
    res = elem->SetAttribute(*aAttribute, *aValue);
    if (NS_FAILED(res)) return res;
  }
  
  // notify our internal selection state listener
  nsAutoInsertContainerSelNotify selNotify(mRangeUpdater);
  
  // put inNode in new parent, outNode
  res = DeleteNode(inNode);
  if (NS_FAILED(res)) return res;
  res = InsertNode(inNode, *outNode, 0);
  if (NS_FAILED(res)) return res;
  
  // put new parent in doc
  return InsertNode(*outNode, parent, offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 143 of file nsPlaintextDataTransfer.cpp.

{
  ForceCompositionEnd();
  
  nsresult rv;
  nsCOMPtr<nsIDragService> dragService = 
           do_GetService("@mozilla.org/widget/dragservice;1", &rv);
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsIDragSession> dragSession;
  dragService->GetCurrentSession(getter_AddRefs(dragSession));
  if (!dragSession) return NS_OK;

  // Current doc is destination
  nsCOMPtr<nsIDOMDocument> destdomdoc; 
  rv = GetDocument(getter_AddRefs(destdomdoc)); 
  if (NS_FAILED(rv)) return rv;

  // transferable hooks
  if (!nsEditorHookUtils::DoAllowDropHook(destdomdoc, aDropEvent, dragSession))
    return NS_OK;

  // Get the nsITransferable interface for getting the data from the drop
  nsCOMPtr<nsITransferable> trans;
  rv = PrepareTransferable(getter_AddRefs(trans));
  if (NS_FAILED(rv)) return rv;
  if (!trans) return NS_OK;  // NS_ERROR_FAILURE; SHOULD WE FAIL?

  PRUint32 numItems = 0; 
  rv = dragSession->GetNumDropItems(&numItems);
  if (NS_FAILED(rv)) return rv;
  if (numItems < 1) return NS_ERROR_FAILURE;  // nothing to drop?

  // Combine any deletion and drop insertion into one transaction
  nsAutoEditBatch beginBatching(this);

  PRBool deleteSelection = PR_FALSE;

  // We have to figure out whether to delete and relocate caret only once
  // Parent and offset are under the mouse cursor
  nsCOMPtr<nsIDOMNSUIEvent> nsuiEvent (do_QueryInterface(aDropEvent));
  if (!nsuiEvent) return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDOMNode> newSelectionParent;
  rv = nsuiEvent->GetRangeParent(getter_AddRefs(newSelectionParent));
  if (NS_FAILED(rv)) return rv;
  if (!newSelectionParent) return NS_ERROR_FAILURE;

  PRInt32 newSelectionOffset;
  rv = nsuiEvent->GetRangeOffset(&newSelectionOffset);
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsISelection> selection;
  rv = GetSelection(getter_AddRefs(selection));
  if (NS_FAILED(rv)) return rv;
  if (!selection) return NS_ERROR_FAILURE;

  PRBool isCollapsed;
  rv = selection->GetIsCollapsed(&isCollapsed);
  if (NS_FAILED(rv)) return rv;

  // Check if mouse is in the selection
  // if so, jump through some hoops to determine if mouse is over selection (bail)
  // and whether user wants to copy selection or delete it
  if (!isCollapsed)
  {
    // We never have to delete if selection is already collapsed
    PRBool cursorIsInSelection = PR_FALSE;

    PRInt32 rangeCount;
    rv = selection->GetRangeCount(&rangeCount);
    if (NS_FAILED(rv)) return rv;

    for (PRInt32 j = 0; j < rangeCount; j++)
    {
      nsCOMPtr<nsIDOMRange> range;
      rv = selection->GetRangeAt(j, getter_AddRefs(range));
      nsCOMPtr<nsIDOMNSRange> nsrange(do_QueryInterface(range));
      if (NS_FAILED(rv) || !nsrange) 
        continue;  // don't bail yet, iterate through them all

      rv = nsrange->IsPointInRange(newSelectionParent, newSelectionOffset, &cursorIsInSelection);
      if (cursorIsInSelection)
        break;
    }

    // Source doc is null if source is *not* the current editor document
    // Current doc is destination (set earlier)
    nsCOMPtr<nsIDOMDocument> srcdomdoc;
    rv = dragSession->GetSourceDocument(getter_AddRefs(srcdomdoc));
    if (NS_FAILED(rv)) return rv;

    if (cursorIsInSelection)
    {
      // Dragging within same doc can't drop on itself -- leave!
      if (srcdomdoc == destdomdoc)
        return NS_OK;

      // Dragging from another window onto a selection
      // XXX Decision made to NOT do this,
      //     note that 4.x does replace if dropped on
      //deleteSelection = PR_TRUE;
    }
    else 
    {
      // We are NOT over the selection
      if (srcdomdoc == destdomdoc)
      {
        // Within the same doc: delete if user doesn't want to copy
 
        // check if the user pressed the key to force a copy rather than a move
        // if we run into problems here, we'll just assume the user doesn't want a copy
        PRBool userWantsCopy = PR_FALSE;

        nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aDropEvent) );
        if (mouseEvent)
#if defined(XP_MAC) || defined(XP_MACOSX)
          mouseEvent->GetAltKey(&userWantsCopy);
#else
          mouseEvent->GetCtrlKey(&userWantsCopy);
#endif

        deleteSelection = !userWantsCopy;
      }
      else
      {
        // Different source doc: Don't delete
        deleteSelection = PR_FALSE;
      }
    }
  }

  nsCOMPtr<nsIContent> newSelectionContent =
    do_QueryInterface(newSelectionParent);
  nsIContent *content = newSelectionContent;

  while (content) {
    nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(content));

    if (formControl && !formControl->AllowDrop()) {
      // Don't allow dropping into a form control that doesn't allow being
      // dropped into.

      return NS_OK;
    }

    content = content->GetParent();
  }

  PRUint32 i; 
  for (i = 0; i < numItems; ++i)
  {
    rv = dragSession->GetData(trans, i);
    if (NS_FAILED(rv)) return rv;
    if (!trans) return NS_OK; // NS_ERROR_FAILURE; Should we fail?

    if (!nsEditorHookUtils::DoInsertionHook(destdomdoc, aDropEvent, trans))
      return NS_OK;

    rv = InsertTextFromTransferable(trans, newSelectionParent, newSelectionOffset, deleteSelection);
  }

  return rv;
}

Here is the call graph for this function:

void nsIEditor::insertFromDrop ( in nsIDOMEvent  aEvent) [inherited]

insertFromDrop looks for a dragsession and inserts the relevant data in response to a drop.

Insert a line break into the content model.

The interpretation of a break is up to the implementation: it may enter a character, split a node in the tree, etc. This may be more efficient than calling InsertText with a newline.

void nsIEditor::insertNode ( in nsIDOMNode  node,
in nsIDOMNode  parent,
in long  aPosition 
) [inherited]

insertNode inserts aNode into aParent at aPosition.

No checking is done to verify the legality of the insertion. That is the responsibility of the caller.

Parameters:
aNodeThe DOM Node to insert.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
void nsIPlaintextEditor::insertText ( in DOMString  aStringToInsert) [inherited]

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.

Parameters:
aStringthe string to be inserted
nsresult nsPlaintextEditor::InsertTextAt ( const nsAString &  aStringToInsert,
nsIDOMNode aDestinationNode,
PRInt32  aDestOffset,
PRBool  aDoDeleteSelection 
)

Definition at line 80 of file nsPlaintextDataTransfer.cpp.

{
  if (aDestinationNode)
  {
    nsresult res;
    nsCOMPtr<nsISelection>selection;
    res = GetSelection(getter_AddRefs(selection));
    NS_ENSURE_SUCCESS(res, res);

    nsCOMPtr<nsIDOMNode> targetNode = aDestinationNode;
    PRInt32 targetOffset = aDestOffset;

    if (aDoDeleteSelection)
    {
      // Use an auto tracker so that our drop point is correctly
      // positioned after the delete.
      nsAutoTrackDOMPoint tracker(mRangeUpdater, &targetNode, &targetOffset);
      res = DeleteSelection(eNone);
      NS_ENSURE_SUCCESS(res, res);
    }

    res = selection->Collapse(targetNode, targetOffset);
    NS_ENSURE_SUCCESS(res, res);
  }

  return InsertText(aStringToInsert);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsPlaintextEditor::InsertTextFromTransferable ( nsITransferable transferable,
nsIDOMNode aDestinationNode,
PRInt32  aDestOffset,
PRBool  aDoDeleteSelection 
) [protected]

Definition at line 111 of file nsPlaintextDataTransfer.cpp.

{
  nsresult rv = NS_OK;
  char* bestFlavor = nsnull;
  nsCOMPtr<nsISupports> genericDataObj;
  PRUint32 len = 0;
  if (NS_SUCCEEDED(aTransferable->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len))
      && bestFlavor && 0 == nsCRT::strcmp(bestFlavor, kUnicodeMime))
  {
    nsAutoTxnsConserveSelection dontSpazMySelection(this);
    nsCOMPtr<nsISupportsString> textDataObj ( do_QueryInterface(genericDataObj) );
    if (textDataObj && len > 0)
    {
      nsAutoString stuffToPaste;
      textDataObj->GetData(stuffToPaste);
      NS_ASSERTION(stuffToPaste.Length() <= (len/2), "Invalid length!");
      nsAutoEditBatch beginBatching(this);
      rv = InsertTextAt(stuffToPaste, aDestinationNode, aDestOffset, aDoDeleteSelection);
    }
  }
  NS_Free(bestFlavor);
      
  // Try to scroll the selection into view if the paste/drop succeeded
  if (NS_SUCCEEDED(rv))
    ScrollSelectionIntoView(PR_FALSE);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::InsertTextImpl ( const nsAString &  aStringToInsert,
nsCOMPtr< nsIDOMNode > *  aInOutNode,
PRInt32 aInOutOffset,
nsIDOMDocument aDoc 
) [inherited]

Definition at line 2739 of file nsEditor.cpp.

{
  // NOTE: caller *must* have already used nsAutoTxnsConserveSelection stack-based
  // class to turn off txn selection updating.  Caller also turned on rules sniffing
  // if desired.
  
  if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER;
  if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK;
  nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(*aInOutNode);
  PRInt32 offset = *aInOutOffset;
  nsresult res;
  if (mInIMEMode)
  {
    if (!nodeAsText)
    {
      // create a text node
      res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
      if (NS_FAILED(res)) return res;
      if (!nodeAsText) return NS_ERROR_NULL_POINTER;
      nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
      // then we insert it into the dom tree
      res = InsertNode(newNode, *aInOutNode, offset);
      if (NS_FAILED(res)) return res;
      offset = 0;
    }
    res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
    if (NS_FAILED(res)) return res;
  }
  else
  {
    if (nodeAsText)
    {
      // we are inserting text into an existing text node.
      res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
      if (NS_FAILED(res)) return res;
      *aInOutOffset += aStringToInsert.Length();
    }
    else
    {
      // we are inserting text into a non-text node
      // first we have to create a textnode (this also populates it with the text)
      res = aDoc->CreateTextNode(aStringToInsert, getter_AddRefs(nodeAsText));
      if (NS_FAILED(res)) return res;
      if (!nodeAsText) return NS_ERROR_NULL_POINTER;
      nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
      // then we insert it into the dom tree
      res = InsertNode(newNode, *aInOutNode, offset);
      if (NS_FAILED(res)) return res;
      *aInOutNode = newNode;
      *aInOutOffset = aStringToInsert.Length();
    }
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl ( const nsAString &  aStringToInsert,
nsIDOMCharacterData aTextNode,
PRInt32  aOffset,
PRBool  suppressIME = PR_FALSE 
) [inherited]

Definition at line 2798 of file nsEditor.cpp.

{
  nsRefPtr<EditTxn> txn;
  nsresult result;
  // suppressIME s used when editor must insert text, yet this text is not
  // part of current ime operation.  example: adjusting whitespace around an ime insertion.
  if (mIMETextRangeList && mInIMEMode && !suppressIME)
  {
    if (!mIMETextNode)
    {
      mIMETextNode = aTextNode;
      mIMETextOffset = aOffset;
    }
    PRUint16 len ;
    result = mIMETextRangeList->GetLength(&len);
    if (NS_SUCCEEDED(result) && len > 0)
    {
      nsCOMPtr<nsIPrivateTextRange> range;
      for (PRUint16 i = 0; i < len; i++) 
      {
        result = mIMETextRangeList->Item(i, getter_AddRefs(range));
        if (NS_SUCCEEDED(result) && range)
        {
          PRUint16 type;
          result = range->GetRangeType(&type);
          if (NS_SUCCEEDED(result)) 
          {
            if (type == nsIPrivateTextRange::TEXTRANGE_RAWINPUT) 
            {
              PRUint16 start, end;
              result = range->GetRangeStart(&start);
              if (NS_SUCCEEDED(result)) 
              {
                result = range->GetRangeEnd(&end);
                if (NS_SUCCEEDED(result)) 
                {
                  if (!mPhonetic)
                    mPhonetic = new nsString();
                  if (mPhonetic)
                  {
                    nsAutoString tmp(aStringToInsert);                  
                    tmp.Mid(*mPhonetic, start, end-start);
                  }
                }
              }
            } // if
          }
        } // if
      } // for
    } // if

    nsRefPtr<IMETextTxn> imeTxn;
    result = CreateTxnForIMEText(aStringToInsert, getter_AddRefs(imeTxn));
    txn = imeTxn;
  }
  else
  {
    nsRefPtr<InsertTextTxn> insertTxn;
    result = CreateTxnForInsertText(aStringToInsert, aTextNode, aOffset,
                                    getter_AddRefs(insertTxn));
    txn = insertTxn;
  }
  if (NS_FAILED(result)) return result;

  // let listeners know whats up
  PRInt32 i;
  nsIEditActionListener *listener;
  if (mActionListeners)
  {
    for (i = 0; i < mActionListeners->Count(); i++)
    {
      listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
      if (listener)
        listener->WillInsertText(aTextNode, aOffset, aStringToInsert);
    }
  }
  
  // XXX we may not need these view batches anymore.  This is handled at a higher level now I believe
  BeginUpdateViewBatch();
  result = DoTransaction(txn);
  EndUpdateViewBatch();

  mRangeUpdater.SelAdjInsertText(aTextNode, aOffset, aStringToInsert);
  
  // let listeners know what happened
  if (mActionListeners)
  {
    for (i = 0; i < mActionListeners->Count(); i++)
    {
      listener = (nsIEditActionListener *)mActionListeners->ElementAt(i);
      if (listener)
        listener->DidInsertText(aTextNode, aOffset, aStringToInsert, result);
    }
  }

  // Added some cruft here for bug 43366.  Layout was crashing because we left an 
  // empty text node lying around in the document.  So I delete empty text nodes
  // caused by IME.  I have to mark the IME transaction as "fixed", which means
  // that furure ime txns won't merge with it.  This is because we don't want
  // future ime txns trying to put their text into a node that is no longer in
  // the document.  This does not break undo/redo, because all these txns are 
  // wrapped in a parent PlaceHolder txn, and placeholder txns are already 
  // savvy to having multiple ime txns inside them.
  
  // delete empty ime text node if there is one
  if (mInIMEMode && mIMETextNode)
  {
    PRUint32 len;
    mIMETextNode->GetLength(&len);
    if (!len)
    {
      DeleteNode(mIMETextNode);
      mIMETextNode = nsnull;
      ((IMETextTxn*)txn.get())->MarkFixed();  // mark the ime txn "fixed"
    }
  }
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIEditorMailSupport::insertTextWithQuotations ( in DOMString  aStringToInsert) [inherited]

Inserts a plaintext string at the current location, with special processing for lines beginning with ">", which will be treated as mail quotes and inserted as plaintext quoted blocks.

If the selection is not collapsed, the selection is deleted and the insertion takes place at the resulting collapsed selection.

Parameters:
aStringthe string to be inserted
nsresult nsEditor::InstallEventListeners ( ) [protected, inherited]

Definition at line 368 of file nsEditor.cpp.

{
  NS_ENSURE_TRUE(mDocWeak && mPresShellWeak && mKeyListenerP &&
                 mMouseListenerP && mFocusListenerP && mTextListenerP &&
                 mCompositionListenerP && mDragListenerP,
                 NS_ERROR_NOT_INITIALIZED);

  nsCOMPtr<nsIDOMEventReceiver> erP = GetDOMEventReceiver();

  if (!erP) {
    RemoveEventListeners();
    return NS_ERROR_FAILURE;
  }

  nsresult rv = NS_OK;

  // register the event listeners with the listener manager
  nsCOMPtr<nsIDOMEventGroup> sysGroup;
  erP->GetSystemEventGroup(getter_AddRefs(sysGroup));
  nsCOMPtr<nsIEventListenerManager> elmP;
  erP->GetListenerManager(getter_AddRefs(elmP));

  if (sysGroup && elmP)
  {
    rv = elmP->AddEventListenerByType(mKeyListenerP,
                                      NS_LITERAL_STRING("keypress"),
                                      NS_EVENT_FLAG_BUBBLE |
                                      NS_PRIV_EVENT_UNTRUSTED_PERMITTED,
                                      sysGroup);
    NS_ASSERTION(NS_SUCCEEDED(rv),
                 "failed to register key listener in system group");
  }

  rv |= erP->AddEventListenerByIID(mMouseListenerP,
                                   NS_GET_IID(nsIDOMMouseListener));

  rv |= erP->AddEventListenerByIID(mFocusListenerP,
                                   NS_GET_IID(nsIDOMFocusListener));

  rv |= erP->AddEventListenerByIID(mTextListenerP,
                                   NS_GET_IID(nsIDOMTextListener));

  rv |= erP->AddEventListenerByIID(mCompositionListenerP,
                                   NS_GET_IID(nsIDOMCompositionListener));

  rv |= erP->AddEventListenerByIID(mDragListenerP,
                                   NS_GET_IID(nsIDOMDragListener));

  if (NS_FAILED(rv))
  {
    NS_ERROR("failed to register some event listeners");

    RemoveEventListeners();
  }

  return rv;
}

Here is the call graph for this function:

PRBool nsEditor::IsBlockNode ( nsIDOMNode aNode) [protected, virtual, inherited]

Reimplemented in nsHTMLEditor.

Definition at line 3937 of file nsEditor.cpp.

{
  // stub to be overridden in nsHTMLEditor.
  // screwing around with the class heirarchy here in order
  // to not duplicate the code in GetNextNode/GetPrevNode
  // across both nsEditor/nsHTMLEditor.  
  return PR_FALSE;
}

Here is the caller graph for this function:

PRBool nsEditor::IsContainer ( nsIDOMNode aNode) [inherited]

returns PR_TRUE if aNode is a container

Definition at line 4033 of file nsEditor.cpp.

{
  if (!aNode) return PR_FALSE;
  nsAutoString stringTag;
  nsresult res = aNode->GetNodeName(stringTag);
  if (NS_FAILED(res)) return PR_FALSE;

  PRInt32 tagEnum;
  // XXX Should this handle #cdata-section too?
  if (stringTag.EqualsLiteral("#text")) {
    tagEnum = eHTMLTag_text;
  }
  else {
    tagEnum = sParserService->HTMLStringTagToId(stringTag);
  }

  return mDTD->IsContainer(tagEnum);
}

Here is the call graph for this function:

Here is the caller graph for this function: