Back to index

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

A transaction that removes text from a content node. More...

#include <DeleteTextTxn.h>

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

List of all members.

Public Member Functions

NS_IMETHOD Init (nsIEditor *aEditor, nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aNumCharsToDelete, nsRangeUpdater *aRangeUpdater)
 initialize the transaction.
virtual ~DeleteTextTxn ()
NS_IMETHOD DoTransaction (void)
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
NS_IMETHOD GetTxnDescription (nsAString &aTxnDescription)
NS_IMETHOD RedoTransaction (void)
NS_IMETHOD GetIsTransient (PRBool *aIsTransient)
void doTransaction ()
 Executes the transaction.
void undoTransaction ()
 Restores the state to what it was before the transaction was executed.
void redoTransaction ()
 Executes the transaction again.
boolean merge (in nsITransaction aTransaction)
 Attempts to merge a transaction into "this" transaction.

Static Public Member Functions

static const nsIIDGetCID ()

Public Attributes

readonly attribute boolean isTransient
 The transaction's transient state.
readonly attribute DOMString txnDescription

Protected Attributes

nsIEditormEditor
 the provider of basic editing operations
nsCOMPtr< nsIDOMCharacterDatamElement
 the text element to operate upon
PRUint32 mOffset
 the offset into mElement where the deletion is to take place
PRUint32 mNumCharsToDelete
 the number of characters to delete
nsString mDeletedText
 the text that was deleted
nsRangeUpdatermRangeUpdater
 range updater object

Private Member Functions

 DeleteTextTxn ()

Friends

class TransactionFactory

Detailed Description

A transaction that removes text from a content node.

Definition at line 56 of file DeleteTextTxn.h.


Constructor & Destructor Documentation

Definition at line 47 of file DeleteTextTxn.cpp.

Definition at line 57 of file DeleteTextTxn.cpp.

{
}

Member Function Documentation

Executes the transaction.

Reimplemented from EditTxn.

Definition at line 84 of file DeleteTextTxn.cpp.

{
#ifdef NS_DEBUG
  if (gNoisy) { printf("Do Delete Text\n"); }
#endif

  NS_ASSERTION(mEditor && mElement, "bad state");
  if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
  // get the text that we're about to delete
  nsresult result = mElement->SubstringData(mOffset, mNumCharsToDelete, mDeletedText);
  NS_ASSERTION(NS_SUCCEEDED(result), "could not get text to delete.");
  result = mElement->DeleteData(mOffset, mNumCharsToDelete);
  if (NS_FAILED(result)) return result;

  if (mRangeUpdater) 
    mRangeUpdater->SelAdjDeleteText(mElement, mOffset, mNumCharsToDelete);

  // only set selection to deletion point if editor gives permission
  PRBool bAdjustSelection;
  mEditor->ShouldTxnSetSelection(&bAdjustSelection);
  if (bAdjustSelection)
  {
    nsCOMPtr<nsISelection> selection;
    result = mEditor->GetSelection(getter_AddRefs(selection));
    if (NS_FAILED(result)) return result;
    if (!selection) return NS_ERROR_NULL_POINTER;
    result = selection->Collapse(mElement, mOffset);
    NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of deletetext.");
  }
  else
  {
    // do nothing - dom range gravity will adjust selection
  }
  return result;
}

Here is the call graph for this function:

static const nsIID& DeleteTextTxn::GetCID ( ) [inline, static]

Reimplemented from EditTxn.

Definition at line 60 of file DeleteTextTxn.h.

{ static const nsIID iid = DELETE_TEXT_TXN_CID; return iid; }

Here is the caller graph for this function:

NS_IMETHODIMP EditTxn::GetIsTransient ( PRBool aIsTransient) [inherited]

Reimplemented in JoinElementTxn, SetDocTitleTxn, and EditAggregateTxn.

Definition at line 66 of file EditTxn.cpp.

{
  if (aIsTransient)
    *aIsTransient = PR_FALSE;
  return NS_OK;
}
NS_IMETHODIMP DeleteTextTxn::GetTxnDescription ( nsAString &  aTxnDescription)

Reimplemented from EditTxn.

Definition at line 141 of file DeleteTextTxn.cpp.

{
  aString.AssignLiteral("DeleteTextTxn: ");
  aString += mDeletedText;
  return NS_OK;
}
NS_IMETHODIMP DeleteTextTxn::Init ( nsIEditor aEditor,
nsIDOMCharacterData aElement,
PRUint32  aOffset,
PRUint32  aNumCharsToDelete,
nsRangeUpdater aRangeUpdater 
)

initialize the transaction.

Parameters:
aEditorthe provider of basic editing operations
aElementthe content node to remove text from
aOffsetthe location in aElement to begin the deletion
aNumCharsToDeletethe number of characters to delete. Not the number of bytes!

Definition at line 61 of file DeleteTextTxn.cpp.

{
  NS_ASSERTION(aEditor&&aElement, "bad arg");
  if (!aEditor || !aElement) { return NS_ERROR_NULL_POINTER; }

  mEditor = aEditor;
  mElement = do_QueryInterface(aElement);
  mOffset = aOffset;
  mNumCharsToDelete = aNumCharsToDelete;
  NS_ASSERTION(0!=aNumCharsToDelete, "bad arg, numCharsToDelete");
  PRUint32 count;
  aElement->GetLength(&count);
  NS_ASSERTION(count>=aNumCharsToDelete, "bad arg, numCharsToDelete.  Not enough characters in node");
  NS_ASSERTION(count>=aOffset+aNumCharsToDelete, "bad arg, numCharsToDelete.  Not enough characters in node");
  mDeletedText.Truncate();
  mRangeUpdater = aRangeUpdater;
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP DeleteTextTxn::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
)

Reimplemented from EditTxn.

Definition at line 134 of file DeleteTextTxn.cpp.

{
  if (aDidMerge)
    *aDidMerge = PR_FALSE;
  return NS_OK;
}
boolean nsITransaction::merge ( in nsITransaction  aTransaction) [inherited]

Attempts to merge a transaction into "this" transaction.

Both transactions must be in their undo state, doTransaction() methods already called. The transaction manager calls this method to coalesce a new transaction with the transaction on the top of the undo stack. This method returns a boolean value that indicates the merge result. A true value indicates that the transactions were merged successfully, a false value if the merge was not possible or failed. If true, the transaction manager will Release() the new transacton instead of pushing it on the undo stack.

Parameters:
aTransactionthe previously executed transaction to merge.

Executes the transaction again.

Can only be called on a transaction that was previously undone.

In most cases, the redoTransaction() method will actually call the doTransaction() method to execute the transaction again.

Restores the state to what it was before the transaction was executed.

Reimplemented from EditTxn.

Definition at line 122 of file DeleteTextTxn.cpp.

{
#ifdef NS_DEBUG
  if (gNoisy) { printf("Undo Delete Text\n"); }
#endif

  NS_ASSERTION(mEditor && mElement, "bad state");
  if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }

  return mElement->InsertData(mOffset, mDeletedText);
}

Friends And Related Function Documentation

friend class TransactionFactory [friend]

Definition at line 108 of file DeleteTextTxn.h.


Member Data Documentation

The transaction's transient state.

This attribute is checked by the transaction manager after the transaction's Execute() method is called. If the transient state is false, a reference to the transaction is held by the transaction manager so that the transactions' undoTransaction() and redoTransaction() methods can be called. If the transient state is true, the transaction manager returns immediately after the transaction's doTransaction() method is called, no references to the transaction are maintained. Transient transactions cannot be undone or redone by the transaction manager.

Definition at line 79 of file nsITransaction.idl.

the text that was deleted

Definition at line 103 of file DeleteTextTxn.h.

the provider of basic editing operations

Definition at line 91 of file DeleteTextTxn.h.

the text element to operate upon

Definition at line 94 of file DeleteTextTxn.h.

the number of characters to delete

Definition at line 100 of file DeleteTextTxn.h.

the offset into mElement where the deletion is to take place

Definition at line 97 of file DeleteTextTxn.h.

range updater object

Definition at line 106 of file DeleteTextTxn.h.

readonly attribute DOMString nsPIEditorTransaction::txnDescription [inherited]

Definition at line 50 of file nsPIEditorTransaction.idl.


The documentation for this class was generated from the following files: