Back to index

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

A transaction that inserts text into a content node. More...

#include <IMETextTxn.h>

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

List of all members.

Public Member Functions

virtual ~IMETextTxn ()
NS_IMETHOD Init (nsIDOMCharacterData *aElement, PRUint32 aOffset, PRUint32 aReplaceLength, nsIPrivateTextRangeList *aTextRangeList, const nsAString &aString, nsWeakPtr aSelCon)
 initialize the transaction
NS_IMETHOD DoTransaction (void)
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
NS_IMETHOD GetTxnDescription (nsAString &aTxnDescription)
NS_IMETHOD MarkFixed (void)
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
NS_IMETHOD GetData (nsString &aResult, nsIPrivateTextRangeList **aTextRangeList)
 return the string data associated with this transaction
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 ()
static nsresult ClassInit ()
 must be called before any IMETextTxn is instantiated
static nsresult ClassShutdown ()
 must be called once we are guaranteed all IMETextTxn have completed

Public Attributes

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

Static Public Attributes

static nsIAtomgIMETextTxnName = nsnull
 used to name aggregate transactions that consist only of a single IMETextTxn, or a DeleteSelection followed by an IMETextTxn.

Protected Member Functions

NS_IMETHOD CollapseTextSelection (void)

Protected Attributes

nsCOMPtr< nsIDOMCharacterDatamElement
 the text element to operate upon
PRUint32 mOffset
 the offsets into mElement where the insertion should be placed
PRUint32 mReplaceLength
nsString mStringToInsert
 the text to insert into mElement at mOffset
nsCOMPtr< nsIPrivateTextRangeListmRangeList
 the range list
nsWeakPtr mSelConWeak
 the selection controller, which we'll need to get the selection
PRBool mFixed

Private Member Functions

 IMETextTxn ()

Friends

class TransactionFactory
class nsDerivedSafe< IMETextTxn >

Detailed Description

A transaction that inserts text into a content node.

Definition at line 61 of file IMETextTxn.h.


Constructor & Destructor Documentation

IMETextTxn::~IMETextTxn ( ) [virtual]

Definition at line 70 of file IMETextTxn.cpp.

Here is the call graph for this function:

IMETextTxn::IMETextTxn ( ) [private]

Definition at line 65 of file IMETextTxn.cpp.

  : EditTxn()
{
}

Member Function Documentation

must be called before any IMETextTxn is instantiated

Definition at line 52 of file IMETextTxn.cpp.

{
  if (!gIMETextTxnName)
    gIMETextTxnName = NS_NewAtom("NS_IMETextTxn");
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

must be called once we are guaranteed all IMETextTxn have completed

Definition at line 59 of file IMETextTxn.cpp.

Here is the caller graph for this function:

Definition at line 252 of file IMETextTxn.cpp.

{
    nsresult      result;
    PRUint16      i;

#ifdef DEBUG_IMETXN
    PRUint16 listlen,start,stop,type;
    result = mRangeList->GetLength(&listlen);
    printf("nsIPrivateTextRangeList[%p]\n",mRangeList);
    nsIPrivateTextRange* rangePtr;
    for (i=0;i<listlen;i++) {
      (void)mRangeList->Item(i,&rangePtr);
      rangePtr->GetRangeStart(&start);
      rangePtr->GetRangeEnd(&stop);
      rangePtr->GetRangeType(&type);
      printf("range[%d] start=%d end=%d type=",i,start,stop,type);
      if (type==nsIPrivateTextRange::TEXTRANGE_RAWINPUT)
                             printf("TEXTRANGE_RAWINPUT\n");
      else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT)
                                  printf("TEXTRANGE_SELECTEDRAWTEXT\n");
      else if (type==nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT)
                                  printf("TEXTRANGE_CONVERTEDTEXT\n");
      else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT)
                                  printf("TEXTRANGE_SELECTEDCONVERTEDTEXT\n");
      else if (type==nsIPrivateTextRange::TEXTRANGE_CARETPOSITION)
                                  printf("TEXTRANGE_CARETPOSITION\n");
      else printf("unknown constant\n");
    }
#endif
        
    //
    // run through the text range list, if any
    //
    nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
    if (!selCon) return NS_ERROR_NOT_INITIALIZED;

    PRUint16      textRangeListLength,selectionStart,selectionEnd,
                  textRangeType;
    
    result = mRangeList->GetLength(&textRangeListLength);
    if(NS_FAILED(result))
        return result;
    nsCOMPtr<nsISelection> selection;
    result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
    if(NS_SUCCEEDED(result))
    {
      nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
      result = selPriv->StartBatchChanges();
      if (NS_SUCCEEDED(result))
      {
        nsCOMPtr<nsISelection> imeSel;
        for(PRInt8 selIdx = 0; selIdx < 4;selIdx++)
        {
          result = selCon->GetSelection(sel[selIdx], getter_AddRefs(imeSel));
          if (NS_SUCCEEDED(result))
          {
            result = imeSel->RemoveAllRanges();
            NS_ASSERTION(NS_SUCCEEDED(result), "Cannot ClearSelection");
            // we just ignore the result and clean up the next one here
          }
        }

        nsIPrivateTextRange*  textRange;
        PRBool setCaret=PR_FALSE;
        for(i=0;i<textRangeListLength;i++)
        {
          result = mRangeList->Item(i,&textRange);
          NS_ASSERTION(NS_SUCCEEDED(result), "cannot get item");
          if(NS_FAILED(result))
               break;

          result = textRange->GetRangeType(&textRangeType);
          NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range type");
          if(NS_FAILED(result))
               break;

          result = textRange->GetRangeStart(&selectionStart);
          NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range start");
          if(NS_FAILED(result))
               break;
          result = textRange->GetRangeEnd(&selectionEnd);
          NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range end");
          if(NS_FAILED(result))
               break;

          if(nsIPrivateTextRange::TEXTRANGE_CARETPOSITION == textRangeType)
          {
             // Set the caret....
             result = selection->Collapse(mElement,
                      mOffset+selectionStart);
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
             if(NS_SUCCEEDED(result))
             setCaret = PR_TRUE;
          } else {
             // NS_ASSERTION(selectionStart != selectionEnd, "end == start");
             if(selectionStart == selectionEnd)
                continue;

             result= selCon->GetSelection(TextRangeToSelection(textRangeType),
                     getter_AddRefs(imeSel));
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction");
             if(NS_FAILED(result))
                break;

             nsCOMPtr<nsIDOMRange> newRange = do_CreateInstance(
                                      "@mozilla.org/content/range;1", &result);
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot create new nsIDOMRange");
             if(NS_FAILED(result))
                break;

             newRange->SetStart(mElement,mOffset+selectionStart);
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetStart");
             if(NS_FAILED(result))
                break;

             newRange->SetEnd(mElement,mOffset+selectionEnd);
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetEnd");
             if(NS_FAILED(result))
                break;

             imeSel->AddRange(newRange);
             NS_ASSERTION(NS_SUCCEEDED(result), "Cannot AddRange");
             if(NS_FAILED(result))
                break;

          } // if GetRangeEnd
        } // for textRangeListLength
        if(! setCaret) {
          // set cursor
          result = selection->Collapse(mElement,mOffset+mStringToInsert.Length());
          NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
        }
        result = selPriv->EndBatchChanges();
        NS_ASSERTION(NS_SUCCEEDED(result), "Cannot EndBatchChanges");
      } // if StartBatchChanges
    } // if GetSelection

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Executes the transaction.

Reimplemented from EditTxn.

Definition at line 96 of file IMETextTxn.cpp.

{

#ifdef DEBUG_IMETXN
  printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length());
#endif

  nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
  if (!selCon) return NS_ERROR_NOT_INITIALIZED;

  // advance caret: This requires the presentation shell to get the selection.
  nsresult result;
  if (mReplaceLength == 0) {
    result = mElement->InsertData(mOffset, mStringToInsert);
  } else {
    result = mElement->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
  }
  if (NS_SUCCEEDED(result)) {
    result = CollapseTextSelection();
  }

  return result;
}

Here is the call graph for this function:

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

Reimplemented from EditTxn.

Definition at line 64 of file IMETextTxn.h.

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

Here is the caller graph for this function:

NS_IMETHODIMP IMETextTxn::GetData ( nsString aResult,
nsIPrivateTextRangeList **  aTextRangeList 
)

return the string data associated with this transaction

Definition at line 234 of file IMETextTxn.cpp.

{
  NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
  if (!aTextRangeList)
    return NS_ERROR_NULL_POINTER;
  aResult = mStringToInsert;
  *aTextRangeList = mRangeList;
  return NS_OK;
}
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 IMETextTxn::GetTxnDescription ( nsAString &  aTxnDescription)

Reimplemented from EditTxn.

Definition at line 192 of file IMETextTxn.cpp.

{
  aString.AssignLiteral("IMETextTxn: ");
  aString += mStringToInsert;
  return NS_OK;
}
NS_IMETHODIMP IMETextTxn::Init ( nsIDOMCharacterData aElement,
PRUint32  aOffset,
PRUint32  aReplaceLength,
nsIPrivateTextRangeList aTextRangeList,
const nsAString &  aString,
nsWeakPtr  aSelCon 
)

initialize the transaction

Parameters:
aElementthe text content node
aOffsetthe location in aElement to do the insertion
aReplaceLengththe length of text to replace (0 == no replacement)
aStringthe new text to insert
aSelConused to get and set the selection

Definition at line 75 of file IMETextTxn.cpp.

{
  NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
  NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
  if (!aElement || !aTextRangeList)
     return NS_ERROR_NULL_POINTER;
  mElement = do_QueryInterface(aElement);
  mOffset = aOffset;
  mReplaceLength = aReplaceLength;
  mStringToInsert = aStringToInsert;
  mSelConWeak = aSelConWeak;
  mRangeList = do_QueryInterface(aTextRangeList);
  mFixed = PR_FALSE;
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 186 of file IMETextTxn.cpp.

{
  mFixed = PR_TRUE;
  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.
NS_IMETHODIMP IMETextTxn::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
)

Reimplemented from EditTxn.

Definition at line 142 of file IMETextTxn.cpp.

{
  NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
  NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
  if (!aDidMerge || !aTransaction)
    return NS_ERROR_NULL_POINTER;
    
#ifdef DEBUG_IMETXN
  printf("Merge IME Text element = %p\n", mElement.get());
#endif

  // 
  // check to make sure we aren't fixed, if we are then nothing get's absorbed
  //
  if (mFixed) {
    *aDidMerge = PR_FALSE;
    return NS_OK;
  }

  //
  // if aTransaction is another IMETextTxn then absorb it
  //
  IMETextTxn*  otherTxn = nsnull;
  nsresult result = aTransaction->QueryInterface(IMETextTxn::GetCID(),(void**)&otherTxn);
  if (otherTxn && NS_SUCCEEDED(result))
  {
    //
    //  we absorb the next IME transaction by adopting its insert string as our own
    //
    nsIPrivateTextRangeList* newTextRangeList;
    otherTxn->GetData(mStringToInsert,&newTextRangeList);
    mRangeList = do_QueryInterface(newTextRangeList);
    *aDidMerge = PR_TRUE;
#ifdef DEBUG_IMETXN
    printf("IMETextTxn assimilated IMETextTxn:%p\n", aTransaction);
#endif
    NS_RELEASE(otherTxn);
    return NS_OK;
  }

  *aDidMerge = PR_FALSE;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP IMETextTxn::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)

Definition at line 202 of file IMETextTxn.cpp.

{
  if (nsnull == aInstancePtr) {
    return NS_ERROR_NULL_POINTER;
  }
  if (aIID.Equals(IMETextTxn::GetCID())) {
    *aInstancePtr = (void*)(IMETextTxn*)this;
    NS_ADDREF_THIS();
    return NS_OK;
  }
  return (EditTxn::QueryInterface(aIID, aInstancePtr));
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 120 of file IMETextTxn.cpp.

{
#ifdef DEBUG_IMETXN
  printf("Undo IME Text element = %p\n", mElement.get());
#endif

  nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
  if (!selCon) return NS_ERROR_NOT_INITIALIZED;

  nsresult result = mElement->DeleteData(mOffset, mStringToInsert.Length());
  if (NS_SUCCEEDED(result))
  { // set the selection to the insertion point where the string was removed
    nsCOMPtr<nsISelection> selection;
    result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
    if (NS_SUCCEEDED(result) && selection) {
      result = selection->Collapse(mElement, mOffset);
      NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert.");
    }
  }
  return result;
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class nsDerivedSafe< IMETextTxn > [friend]

Definition at line 142 of file IMETextTxn.h.

friend class TransactionFactory [friend]

Definition at line 140 of file IMETextTxn.h.


Member Data Documentation

used to name aggregate transactions that consist only of a single IMETextTxn, or a DeleteSelection followed by an IMETextTxn.

Definition at line 71 of file IMETextTxn.h.

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 element to operate upon

Definition at line 122 of file IMETextTxn.h.

Definition at line 138 of file IMETextTxn.h.

the offsets into mElement where the insertion should be placed

Definition at line 125 of file IMETextTxn.h.

the range list

Definition at line 133 of file IMETextTxn.h.

Definition at line 127 of file IMETextTxn.h.

the selection controller, which we'll need to get the selection

Definition at line 136 of file IMETextTxn.h.

the text to insert into mElement at mOffset

Definition at line 130 of file IMETextTxn.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: