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/. */
6 #ifndef SplitNodeTransaction_h
7 #define SplitNodeTransaction_h
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
22 * A transaction that splits a node into two identical nodes, with the children
23 * divided between the new nodes.
25 class SplitNodeTransaction final
: public EditTransactionBase
{
27 template <typename PT
, typename CT
>
28 SplitNodeTransaction(HTMLEditor
& aHTMLEditor
,
29 const EditorDOMPointBase
<PT
, CT
>& aStartOfRightContent
);
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
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
43 template <typename PT
, typename CT
>
44 static already_AddRefed
<SplitNodeTransaction
> Create(
45 HTMLEditor
& aHTMLEditor
,
46 const EditorDOMPointBase
<PT
, CT
>& aStartOfRightContent
);
48 NS_DECL_ISUPPORTS_INHERITED
49 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction
,
52 NS_DECL_EDITTRANSACTIONBASE
53 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(SplitNodeTransaction
)
55 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
RedoTransaction() override
;
57 nsIContent
* GetNewLeftContent() const { return mNewLeftContent
; }
60 virtual ~SplitNodeTransaction() = default;
62 RefPtr
<HTMLEditor
> mHTMLEditor
;
64 // The container is existing right node (will be split).
65 // The point referring this is start of the right node after it's split.
66 EditorDOMPoint mStartOfRightContent
;
68 // The node we create when splitting mExistingRightContent.
69 nsCOMPtr
<nsIContent
> mNewLeftContent
;
71 // The parent shared by mExistingRightContent and mNewLeftContent.
72 nsCOMPtr
<nsINode
> mContainerParentNode
;
75 } // namespace mozilla
77 #endif // #ifndef SplitNodeTransaction_h