editor/libeditor/base/SplitElementTxn.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/base/SplitElementTxn.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef SplitElementTxn_h__
    1.10 +#define SplitElementTxn_h__
    1.11 +
    1.12 +#include "EditTxn.h"                    // for EditTxn, NS_DECL_EDITTXN
    1.13 +#include "nsCOMPtr.h"                   // for nsCOMPtr
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +#include "nsIDOMNode.h"                 // for nsIDOMNode
    1.16 +#include "nsISupportsImpl.h"            // for NS_DECL_ISUPPORTS_INHERITED
    1.17 +#include "nscore.h"                     // for NS_IMETHOD
    1.18 +
    1.19 +class nsEditor;
    1.20 +
    1.21 +/**
    1.22 + * A transaction that splits an element E into two identical nodes, E1 and E2
    1.23 + * with the children of E divided between E1 and E2.
    1.24 + */
    1.25 +class SplitElementTxn : public EditTxn
    1.26 +{
    1.27 +public:
    1.28 +  /** initialize the transaction.
    1.29 +    * @param aEditor  the provider of core editing operations
    1.30 +    * @param aNode    the node to split
    1.31 +    * @param aOffset  the location within aNode to do the split.
    1.32 +    *                 aOffset may refer to children of aNode, or content of aNode.
    1.33 +    *                 The left node will have child|content 0..aOffset-1.
    1.34 +    */
    1.35 +  NS_IMETHOD Init (nsEditor   *aEditor,
    1.36 +                   nsIDOMNode *aNode,
    1.37 +                   int32_t     aOffset);
    1.38 +
    1.39 +  SplitElementTxn();
    1.40 +
    1.41 +  NS_DECL_ISUPPORTS_INHERITED
    1.42 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitElementTxn, EditTxn)
    1.43 +
    1.44 +  NS_DECL_EDITTXN
    1.45 +
    1.46 +  NS_IMETHOD RedoTransaction(void);
    1.47 +
    1.48 +  NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
    1.49 +
    1.50 +protected:
    1.51 +  
    1.52 +  /** the element to operate upon */
    1.53 +  nsCOMPtr<nsIDOMNode> mExistingRightNode;
    1.54 +
    1.55 +  /** the offset into mElement where the children of mElement are split.<BR>
    1.56 +    * mOffset is the index of the first child in the right node. 
    1.57 +    * -1 means the new node gets no children.
    1.58 +    */
    1.59 +  int32_t  mOffset;
    1.60 +
    1.61 +  /** the element we create when splitting mElement */
    1.62 +  nsCOMPtr<nsIDOMNode> mNewLeftNode;
    1.63 +
    1.64 +  /** the parent shared by mExistingRightNode and mNewLeftNode */
    1.65 +  nsCOMPtr<nsIDOMNode> mParent;
    1.66 +  nsEditor*  mEditor;
    1.67 +};
    1.68 +
    1.69 +#endif

mercurial