2014-11-02 15:04:13 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-07-07 10:59:55 +03:00
|
|
|
#ifndef SplitNodeTransaction_h
|
|
|
|
#define SplitNodeTransaction_h
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2017-11-12 03:27:19 +03:00
|
|
|
#include "mozilla/EditorDOMPoint.h" // for RangeBoundary, EditorRawDOMPoint
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "mozilla/EditTransactionBase.h" // for EditTxn, etc.
|
2014-11-02 15:04:13 +03:00
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
#include "nscore.h" // for NS_IMETHOD
|
|
|
|
|
|
|
|
class nsIContent;
|
2014-12-02 08:06:55 +03:00
|
|
|
class nsINode;
|
2014-11-02 15:04:13 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
class EditorBase;
|
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
/**
|
|
|
|
* A transaction that splits a node into two identical nodes, with the children
|
|
|
|
* divided between the new nodes.
|
|
|
|
*/
|
2016-07-08 03:48:34 +03:00
|
|
|
class SplitNodeTransaction final : public EditTransactionBase
|
2014-11-02 15:04:13 +03:00
|
|
|
{
|
2017-12-15 15:37:23 +03:00
|
|
|
private:
|
2018-03-20 08:05:47 +03:00
|
|
|
template<typename PT, typename CT>
|
2017-12-15 15:37:23 +03:00
|
|
|
SplitNodeTransaction(EditorBase& aEditorBase,
|
2018-03-20 08:05:47 +03:00
|
|
|
const EditorDOMPointBase<PT, CT>& aStartOfRightNode);
|
2017-12-15 15:37:23 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
public:
|
2016-07-07 10:59:55 +03:00
|
|
|
/**
|
2017-12-15 15:37:23 +03:00
|
|
|
* Creates a transaction to create a new node (left node) identical to an
|
|
|
|
* existing node (right node), and split the contents between the same point
|
|
|
|
* in both nodes.
|
|
|
|
*
|
2017-11-12 03:27:19 +03:00
|
|
|
* @param aEditorBase The provider of core editing operations.
|
|
|
|
* @param aStartOfRightNode The point to split. Its container will be
|
|
|
|
* the right node, i.e., become the new node's
|
|
|
|
* next sibling. And the point will be start
|
|
|
|
* of the right node.
|
2016-07-07 10:59:55 +03:00
|
|
|
*/
|
2018-03-20 08:05:47 +03:00
|
|
|
template<typename PT, typename CT>
|
2017-12-15 15:37:23 +03:00
|
|
|
static already_AddRefed<SplitNodeTransaction>
|
|
|
|
Create(EditorBase& aEditorBase,
|
2018-03-20 08:05:47 +03:00
|
|
|
const EditorDOMPointBase<PT, CT>& aStartOfRightNode);
|
2014-11-02 15:04:13 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,
|
|
|
|
EditTransactionBase)
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_EDITTRANSACTIONBASE
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD RedoTransaction() override;
|
2014-11-02 15:04:13 +03:00
|
|
|
|
|
|
|
nsIContent* GetNewNode();
|
|
|
|
|
|
|
|
protected:
|
2016-07-07 10:59:55 +03:00
|
|
|
virtual ~SplitNodeTransaction();
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2017-11-12 03:27:19 +03:00
|
|
|
// The container is existing right node (will be split).
|
|
|
|
// The point referring this is start of the right node after it's split.
|
2017-11-28 11:13:15 +03:00
|
|
|
EditorDOMPoint mStartOfRightNode;
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2016-07-07 10:59:55 +03:00
|
|
|
// The node we create when splitting mExistingRightNode.
|
2014-11-02 15:04:13 +03:00
|
|
|
nsCOMPtr<nsIContent> mNewLeftNode;
|
|
|
|
|
2016-07-07 10:59:55 +03:00
|
|
|
// The parent shared by mExistingRightNode and mNewLeftNode.
|
2014-11-02 15:04:13 +03:00
|
|
|
nsCOMPtr<nsINode> mParent;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2016-07-07 10:59:55 +03:00
|
|
|
#endif // #ifndef SplitNodeTransaction_h
|