2014-11-02 15:04:12 +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:16:12 +03:00
|
|
|
#ifndef JoinNodeTransaction_h
|
|
|
|
#define JoinNodeTransaction_h
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "mozilla/EditTransactionBase.h" // for EditTransactionBase, etc.
|
2014-11-02 15:04:12 +03:00
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsID.h" // for REFNSIID
|
|
|
|
#include "nscore.h" // for NS_IMETHOD
|
|
|
|
|
|
|
|
class nsINode;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
class EditorBase;
|
|
|
|
|
2014-11-02 15:04:12 +03:00
|
|
|
/**
|
|
|
|
* A transaction that joins two nodes E1 (left node) and E2 (right node) into a
|
|
|
|
* single node E. The children of E are the children of E1 followed by the
|
|
|
|
* children of E2. After DoTransaction() and RedoTransaction(), E1 is removed
|
|
|
|
* from the content tree and E2 remains.
|
|
|
|
*/
|
2016-07-08 03:48:34 +03:00
|
|
|
class JoinNodeTransaction final : public EditTransactionBase
|
2014-11-02 15:04:12 +03:00
|
|
|
{
|
2017-12-15 15:53:08 +03:00
|
|
|
protected:
|
|
|
|
JoinNodeTransaction(EditorBase& aEditorBase,
|
|
|
|
nsINode& aLeftNode, nsINode& aRightNode);
|
|
|
|
|
2014-11-02 15:04:12 +03:00
|
|
|
public:
|
2016-07-07 10:16:12 +03:00
|
|
|
/**
|
2017-12-15 15:53:08 +03:00
|
|
|
* Creates a join node transaction. This returns nullptr if cannot join the
|
|
|
|
* nodes.
|
|
|
|
*
|
2016-07-08 07:10:13 +03:00
|
|
|
* @param aEditorBase The provider of core editing operations.
|
2016-07-07 10:16:12 +03:00
|
|
|
* @param aLeftNode The first of two nodes to join.
|
|
|
|
* @param aRightNode The second of two nodes to join.
|
|
|
|
*/
|
2017-12-15 15:53:08 +03:00
|
|
|
static already_AddRefed<JoinNodeTransaction>
|
|
|
|
MaybeCreate(EditorBase& aEditorBase, nsINode& aLeftNode, nsINode& aRightNode);
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-07 10:16:12 +03:00
|
|
|
/**
|
2017-03-10 07:46:27 +03:00
|
|
|
* CanDoIt() returns true if there are enough members and can join or
|
|
|
|
* restore the nodes. Otherwise, false.
|
2016-07-07 10:16:12 +03:00
|
|
|
*/
|
2017-03-10 07:46:27 +03:00
|
|
|
bool CanDoIt() const;
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
|
|
|
|
EditTransactionBase)
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_EDITTRANSACTIONBASE
|
2014-11-02 15:04:12 +03:00
|
|
|
|
|
|
|
protected:
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-07 10:16:12 +03:00
|
|
|
// The nodes to operate upon. After the merge, mRightNode remains and
|
|
|
|
// mLeftNode is removed from the content tree.
|
2014-11-02 15:04:12 +03:00
|
|
|
nsCOMPtr<nsINode> mLeftNode;
|
|
|
|
nsCOMPtr<nsINode> mRightNode;
|
|
|
|
|
2016-07-07 10:16:12 +03:00
|
|
|
// The offset into mNode where the children of mElement are split (for
|
|
|
|
// undo). mOffset is the index of the first child in the right node. -1
|
|
|
|
// means the left node had no children.
|
2014-11-02 15:04:12 +03:00
|
|
|
uint32_t mOffset;
|
|
|
|
|
2016-07-07 10:16:12 +03:00
|
|
|
// The parent node containing mLeftNode and mRightNode.
|
2014-11-02 15:04:12 +03:00
|
|
|
nsCOMPtr<nsINode> mParent;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2014-11-02 15:04:12 +03:00
|
|
|
|
2016-07-07 10:16:12 +03:00
|
|
|
#endif // #ifndef JoinNodeTransaction_h
|