2016-07-07 08:33:56 +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/. */
|
|
|
|
|
|
|
|
#ifndef CreateElementTransaction_h
|
|
|
|
#define CreateElementTransaction_h
|
|
|
|
|
2017-11-08 10:49:06 +03:00
|
|
|
#include "mozilla/EditorDOMPoint.h"
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/EditTransactionBase.h"
|
2016-07-07 08:33:56 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2016-07-07 08:33:56 +03:00
|
|
|
class nsIContent;
|
|
|
|
class nsINode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A transaction that creates a new node in the content tree.
|
|
|
|
*/
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
class EditorBase;
|
2016-07-07 08:33:56 +03:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
class CreateElementTransaction final : public EditTransactionBase {
|
2017-12-15 11:54:10 +03:00
|
|
|
protected:
|
2018-03-20 08:05:47 +03:00
|
|
|
template <typename PT, typename CT>
|
2017-12-15 11:54:10 +03:00
|
|
|
CreateElementTransaction(EditorBase& aEditorBase, nsAtom& aTag,
|
2018-03-20 08:05:47 +03:00
|
|
|
const EditorDOMPointBase<PT, CT>& aPointToInsert);
|
2017-12-15 11:54:10 +03:00
|
|
|
|
2016-07-07 08:33:56 +03:00
|
|
|
public:
|
|
|
|
/**
|
2017-12-15 11:54:10 +03:00
|
|
|
* Create a transaction for creating a new child node of the container of
|
|
|
|
* aPointToInsert of type aTag.
|
|
|
|
*
|
|
|
|
* @param aEditorBase The editor which manages the transaction.
|
2016-07-07 08:33:56 +03:00
|
|
|
* @param aTag The tag (P, HR, TABLE, etc.) for the new element.
|
2017-11-08 10:49:06 +03:00
|
|
|
* @param aPointToInsert The new node will be inserted before the child at
|
|
|
|
* aPointToInsert. If this refers end of the container
|
|
|
|
* or after, the new node will be appended to the
|
|
|
|
* container.
|
2016-07-07 08:33:56 +03:00
|
|
|
*/
|
2018-03-20 08:05:47 +03:00
|
|
|
template <typename PT, typename CT>
|
2017-12-15 11:54:10 +03:00
|
|
|
static already_AddRefed<CreateElementTransaction> Create(
|
|
|
|
EditorBase& aEditorBase, nsAtom& aTag,
|
2018-03-20 08:05:47 +03:00
|
|
|
const EditorDOMPointBase<PT, CT>& aPointToInsert);
|
2016-07-07 08:33:56 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,
|
|
|
|
EditTransactionBase)
|
2016-07-07 08:33:56 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_EDITTRANSACTIONBASE
|
2016-07-07 08:33:56 +03:00
|
|
|
|
|
|
|
NS_IMETHOD RedoTransaction() override;
|
|
|
|
|
|
|
|
already_AddRefed<dom::Element> GetNewNode();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CreateElementTransaction();
|
|
|
|
|
2017-11-08 10:49:06 +03:00
|
|
|
/**
|
|
|
|
* InsertNewNode() inserts mNewNode before the child node at mPointToInsert.
|
|
|
|
*/
|
|
|
|
void InsertNewNode(ErrorResult& aError);
|
|
|
|
|
2016-07-07 08:33:56 +03:00
|
|
|
// The document into which the new node will be inserted.
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2016-07-07 08:33:56 +03:00
|
|
|
|
|
|
|
// The tag (mapping to object type) for the new element.
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> mTag;
|
2016-07-07 08:33:56 +03:00
|
|
|
|
2017-11-08 10:49:06 +03:00
|
|
|
// The DOM point we will insert mNewNode.
|
2017-11-28 11:13:15 +03:00
|
|
|
EditorDOMPoint mPointToInsert;
|
2016-07-07 08:33:56 +03:00
|
|
|
|
|
|
|
// The new node to insert.
|
|
|
|
nsCOMPtr<dom::Element> mNewNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef CreateElementTransaction_h
|