summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/EditTransactionBase.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /editor/libeditor/EditTransactionBase.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/libeditor/EditTransactionBase.h')
-rw-r--r--editor/libeditor/EditTransactionBase.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/editor/libeditor/EditTransactionBase.h b/editor/libeditor/EditTransactionBase.h
new file mode 100644
index 0000000000..5fe968ea85
--- /dev/null
+++ b/editor/libeditor/EditTransactionBase.h
@@ -0,0 +1,94 @@
+/* -*- 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 mozilla_EditTransactionBase_h
+#define mozilla_EditTransactionBase_h
+
+#include "nsCycleCollectionParticipant.h"
+#include "nsISupportsImpl.h"
+#include "nsITransaction.h"
+#include "nscore.h"
+
+already_AddRefed<mozilla::EditTransactionBase>
+nsITransaction::GetAsEditTransactionBase() {
+ RefPtr<mozilla::EditTransactionBase> editTransactionBase;
+ return NS_SUCCEEDED(
+ GetAsEditTransactionBase(getter_AddRefs(editTransactionBase)))
+ ? editTransactionBase.forget()
+ : nullptr;
+}
+
+namespace mozilla {
+
+class ChangeAttributeTransaction;
+class ChangeStyleTransaction;
+class CompositionTransaction;
+class CreateElementTransaction;
+class DeleteNodeTransaction;
+class DeleteRangeTransaction;
+class DeleteTextTransaction;
+class EditAggregateTransaction;
+class InsertNodeTransaction;
+class InsertTextTransaction;
+class JoinNodeTransaction;
+class PlaceholderTransaction;
+class ReplaceTextTransaction;
+class SplitNodeTransaction;
+
+#define NS_DECL_GETASTRANSACTION_BASE(aClass) \
+ virtual aClass* GetAs##aClass(); \
+ virtual const aClass* GetAs##aClass() const;
+
+/**
+ * Base class for all document editing transactions.
+ */
+class EditTransactionBase : public nsITransaction {
+ public:
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+ NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EditTransactionBase, nsITransaction)
+
+ MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction(void) override;
+ NS_IMETHOD GetIsTransient(bool* aIsTransient) override;
+ NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
+ NS_IMETHOD GetAsEditTransactionBase(
+ EditTransactionBase** aEditTransactionBase) final {
+ MOZ_ASSERT(aEditTransactionBase);
+ MOZ_ASSERT(!*aEditTransactionBase);
+ *aEditTransactionBase = do_AddRef(this).take();
+ return NS_OK;
+ }
+
+ NS_DECL_GETASTRANSACTION_BASE(ChangeAttributeTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(ChangeStyleTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(CompositionTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(CreateElementTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(DeleteNodeTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(DeleteRangeTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(DeleteTextTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(EditAggregateTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(InsertNodeTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(InsertTextTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(JoinNodeTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(PlaceholderTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(ReplaceTextTransaction)
+ NS_DECL_GETASTRANSACTION_BASE(SplitNodeTransaction)
+
+ protected:
+ virtual ~EditTransactionBase() = default;
+};
+
+#undef NS_DECL_GETASTRANSACTION_BASE
+
+} // namespace mozilla
+
+#define NS_DECL_EDITTRANSACTIONBASE \
+ MOZ_CAN_RUN_SCRIPT NS_IMETHOD DoTransaction() override; \
+ MOZ_CAN_RUN_SCRIPT NS_IMETHOD UndoTransaction() override;
+
+#define NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(aClass) \
+ aClass* GetAs##aClass() final { return this; } \
+ const aClass* GetAs##aClass() const final { return this; }
+
+#endif // #ifndef mozilla_EditTransactionBase_h