Back to index

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

A transaction that joins two elements E1 (left node) and E2 (right node) into a single node E. More...

#include <JoinElementTxn.h>

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

List of all members.

Public Member Functions

NS_IMETHOD Init (nsEditor *aEditor, nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode)
 initialize the transaction
virtual ~JoinElementTxn ()
NS_IMETHOD DoTransaction (void)
NS_IMETHOD UndoTransaction (void)
NS_IMETHOD GetIsTransient (PRBool *aIsTransient)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
NS_IMETHOD GetTxnDescription (nsAString &aTxnDescription)
NS_IMETHOD RedoTransaction (void)
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 Member Functions

 JoinElementTxn ()

Protected Attributes

nsCOMPtr< nsIDOMNodemLeftNode
 the elements to operate upon.
nsCOMPtr< nsIDOMNodemRightNode
PRUint32 mOffset
 the offset into mNode where the children of mElement are split (for undo).
nsCOMPtr< nsIDOMNodemParent
 the parent node containing mLeftNode and mRightNode
nsEditormEditor

Friends

class TransactionFactory

Detailed Description

A transaction that joins two elements E1 (left node) and E2 (right node) into a single node E.

The children of E are the children of E1 followed by the children of E2. After DoTransaction() and RedoTransaction(), E1 is removed from the content tree and E2 remains.

Definition at line 60 of file JoinElementTxn.h.


Constructor & Destructor Documentation

Definition at line 47 of file JoinElementTxn.cpp.

  : EditTxn()
{
}

Definition at line 65 of file JoinElementTxn.cpp.

{
}

Member Function Documentation

Executes the transaction.

Reimplemented from EditTxn.

Definition at line 70 of file JoinElementTxn.cpp.

{
#ifdef NS_DEBUG
  if (gNoisy) { printf("%p Do Join of %p and %p\n", this, mLeftNode.get(), mRightNode.get()); }
#endif

  NS_PRECONDITION((mEditor && mLeftNode && mRightNode), "null arg");
  if (!mEditor || !mLeftNode || !mRightNode) { return NS_ERROR_NOT_INITIALIZED; }

  // get the parent node
  nsCOMPtr<nsIDOMNode>leftParent;
  nsresult result = mLeftNode->GetParentNode(getter_AddRefs(leftParent));
  if (NS_FAILED(result)) return result;
  if (!leftParent) return NS_ERROR_NULL_POINTER;

  // verify that mLeftNode and mRightNode have the same parent
  nsCOMPtr<nsIDOMNode>rightParent;
  result = mRightNode->GetParentNode(getter_AddRefs(rightParent));
  if (NS_FAILED(result)) return result;
  if (!rightParent) return NS_ERROR_NULL_POINTER;

  if (leftParent==rightParent)
  {
    mParent= do_QueryInterface(leftParent); // set this instance mParent. 
                                            // Other methods will see a non-null mParent and know all is well
    nsCOMPtr<nsIDOMCharacterData> leftNodeAsText = do_QueryInterface(mLeftNode);
    if (leftNodeAsText) 
    {
      leftNodeAsText->GetLength(&mOffset);
    }
    else 
    {
      nsCOMPtr<nsIDOMNodeList> childNodes;
      result = mLeftNode->GetChildNodes(getter_AddRefs(childNodes));
      if (NS_FAILED(result)) return result;
      if (childNodes) 
      {
        childNodes->GetLength(&mOffset);
      }
    }
    result = mEditor->JoinNodesImpl(mRightNode, mLeftNode, mParent, PR_FALSE);
#ifdef NS_DEBUG
    if (NS_SUCCEEDED(result))
    {
      if (gNoisy) { printf("  left node = %p removed\n", mLeftNode.get()); }
    }
#endif
  }
  else 
  {
    NS_ASSERTION(PR_FALSE, "2 nodes do not have same parent");
    return NS_ERROR_INVALID_ARG;
  }
  return result;
}

Here is the call graph for this function:

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

Reimplemented from EditTxn.

Definition at line 64 of file JoinElementTxn.h.

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

Here is the caller graph for this function:

Reimplemented from EditTxn.

Definition at line 165 of file JoinElementTxn.cpp.

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

Reimplemented from EditTxn.

Definition at line 179 of file JoinElementTxn.cpp.

{
  aString.AssignLiteral("JoinElementTxn");
  return NS_OK;
}
NS_IMETHODIMP JoinElementTxn::Init ( nsEditor aEditor,
nsIDOMNode aLeftNode,
nsIDOMNode aRightNode 
)

initialize the transaction

Parameters:
aEditorthe provider of core editing operations
aLeftNodethe first of two nodes to join
aRightNodethe second of two nodes to join

Definition at line 52 of file JoinElementTxn.cpp.

{
  NS_PRECONDITION((aEditor && aLeftNode && aRightNode), "null arg");
  if (!aEditor || !aLeftNode || !aRightNode) { return NS_ERROR_NULL_POINTER; }
  mEditor = aEditor;
  mLeftNode = do_QueryInterface(aLeftNode);
  mRightNode = do_QueryInterface(aRightNode);
  mOffset=0;
  return NS_OK;
}

Here is the call graph for this function:

nsresult JoinElementTxn::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
)

Reimplemented from EditTxn.

Definition at line 172 of file JoinElementTxn.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 128 of file JoinElementTxn.cpp.

{
#ifdef NS_DEBUG
  if (gNoisy) { printf("%p Undo Join, right node = %p\n", this, mRightNode.get()); }
#endif

  NS_ASSERTION(mRightNode && mLeftNode && mParent, "bad state");
  if (!mRightNode || !mLeftNode || !mParent) { return NS_ERROR_NOT_INITIALIZED; }
  nsresult result;
  nsCOMPtr<nsIDOMNode>resultNode;
  // first, massage the existing node so it is in its post-split state
  nsCOMPtr<nsIDOMCharacterData>rightNodeAsText = do_QueryInterface(mRightNode);
  if (rightNodeAsText)
  {
    result = rightNodeAsText->DeleteData(0, mOffset);
  }
  else
  {
    nsCOMPtr<nsIDOMNode>child;
    result = mRightNode->GetFirstChild(getter_AddRefs(child));
    nsCOMPtr<nsIDOMNode>nextSibling;
    PRUint32 i;
    for (i=0; i<mOffset; i++)
    {
      if (NS_FAILED(result)) {return result;}
      if (!child) {return NS_ERROR_NULL_POINTER;}
      child->GetNextSibling(getter_AddRefs(nextSibling));
      result = mLeftNode->AppendChild(child, getter_AddRefs(resultNode));
      child = do_QueryInterface(nextSibling);
    }
  }
  // second, re-insert the left node into the tree 
  result = mParent->InsertBefore(mLeftNode, mRightNode, getter_AddRefs(resultNode));
  return result;

}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class TransactionFactory [friend]

Definition at line 111 of file JoinElementTxn.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.

Definition at line 109 of file JoinElementTxn.h.

the elements to operate upon.

After the merge, mRightNode remains and mLeftNode is removed from the content tree.

Definition at line 98 of file JoinElementTxn.h.

the offset into mNode where the children of mElement are split (for undo).


mOffset is the index of the first child in the right node. -1 means the left node had no children.

Definition at line 105 of file JoinElementTxn.h.

the parent node containing mLeftNode and mRightNode

Definition at line 108 of file JoinElementTxn.h.

Definition at line 99 of file JoinElementTxn.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: