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 6 #ifndef SplitNodeTransaction_h 7 #define SplitNodeTransaction_h 8 9 #include "mozilla/EditorDOMPoint.h" // for RangeBoundary, EditorRawDOMPoint 10 #include "mozilla/EditTransactionBase.h" // for EditTxn, etc. 11 #include "nsCOMPtr.h" // for nsCOMPtr 12 #include "nsCycleCollectionParticipant.h" 13 #include "nsIContent.h" 14 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED 15 #include "nscore.h" // for NS_IMETHOD 16 17 namespace mozilla { 18 19 class HTMLEditor; 20 21 /** 22 * A transaction that splits a node into two identical nodes, with the children 23 * divided between the new nodes. 24 */ 25 class SplitNodeTransaction final : public EditTransactionBase { 26 private: 27 template <typename PT, typename CT> 28 SplitNodeTransaction(HTMLEditor& aHTMLEditor, 29 const EditorDOMPointBase<PT, CT>& aStartOfRightContent); 30 31 public: 32 /** 33 * Creates a transaction to create a new node (left node) identical to an 34 * existing node (right node), and split the contents between the same point 35 * in both nodes. 36 * 37 * @param aHTMLEditor The provider of core editing operations. 38 * @param aStartOfRightContent The point to split. Its container will be 39 * the right node, i.e., become the new node's 40 * next sibling. And the point will be start 41 * of the right node. 42 */ 43 template <typename PT, typename CT> 44 static already_AddRefed<SplitNodeTransaction> Create( 45 HTMLEditor& aHTMLEditor, 46 const EditorDOMPointBase<PT, CT>& aStartOfRightContent); 47 48 NS_DECL_ISUPPORTS_INHERITED 49 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction, 50 EditTransactionBase) 51 52 NS_DECL_EDITTRANSACTIONBASE 53 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(SplitNodeTransaction) 54 55 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override; 56 GetNewLeftContent()57 nsIContent* GetNewLeftContent() const { return mNewLeftContent; } 58 59 friend std::ostream& operator<<(std::ostream& aStream, 60 const SplitNodeTransaction& aTransaction); 61 62 protected: 63 virtual ~SplitNodeTransaction() = default; 64 65 RefPtr<HTMLEditor> mHTMLEditor; 66 67 // The container is existing right node (will be split). 68 // The point referring this is start of the right node after it's split. 69 EditorDOMPoint mStartOfRightContent; 70 71 // The node we create when splitting mExistingRightContent. 72 nsCOMPtr<nsIContent> mNewLeftContent; 73 74 // The parent shared by mExistingRightContent and mNewLeftContent. 75 nsCOMPtr<nsINode> mContainerParentNode; 76 }; 77 78 } // namespace mozilla 79 80 #endif // #ifndef SplitNodeTransaction_h 81