SplitNodeTransaction.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef SplitNodeTransaction_h
  6. #define SplitNodeTransaction_h
  7. #include "mozilla/EditTransactionBase.h" // for EditTxn, etc.
  8. #include "nsCOMPtr.h" // for nsCOMPtr
  9. #include "nsCycleCollectionParticipant.h"
  10. #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
  11. #include "nscore.h" // for NS_IMETHOD
  12. class nsIContent;
  13. class nsINode;
  14. namespace mozilla {
  15. class EditorBase;
  16. /**
  17. * A transaction that splits a node into two identical nodes, with the children
  18. * divided between the new nodes.
  19. */
  20. class SplitNodeTransaction final : public EditTransactionBase
  21. {
  22. public:
  23. /**
  24. * @param aEditorBase The provider of core editing operations
  25. * @param aNode The node to split
  26. * @param aOffset The location within aNode to do the split. aOffset may
  27. * refer to children of aNode, or content of aNode. The
  28. * left node will have child|content 0..aOffset-1.
  29. */
  30. SplitNodeTransaction(EditorBase& aEditorBase, nsIContent& aNode,
  31. int32_t aOffset);
  32. NS_DECL_ISUPPORTS_INHERITED
  33. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,
  34. EditTransactionBase)
  35. NS_DECL_EDITTRANSACTIONBASE
  36. NS_IMETHOD RedoTransaction() override;
  37. nsIContent* GetNewNode();
  38. protected:
  39. virtual ~SplitNodeTransaction();
  40. RefPtr<EditorBase> mEditorBase;
  41. // The node to operate upon.
  42. nsCOMPtr<nsIContent> mExistingRightNode;
  43. // The offset into mExistingRightNode where its children are split. mOffset
  44. // is the index of the first child in the right node. -1 means the new node
  45. // gets no children.
  46. int32_t mOffset;
  47. // The node we create when splitting mExistingRightNode.
  48. nsCOMPtr<nsIContent> mNewLeftNode;
  49. // The parent shared by mExistingRightNode and mNewLeftNode.
  50. nsCOMPtr<nsINode> mParent;
  51. };
  52. } // namespace mozilla
  53. #endif // #ifndef SplitNodeTransaction_h