From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- editor/txmgr/TransactionStack.cpp | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 editor/txmgr/TransactionStack.cpp (limited to 'editor/txmgr/TransactionStack.cpp') diff --git a/editor/txmgr/TransactionStack.cpp b/editor/txmgr/TransactionStack.cpp new file mode 100644 index 0000000000..f0d9c7d455 --- /dev/null +++ b/editor/txmgr/TransactionStack.cpp @@ -0,0 +1,75 @@ +/* -*- 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/. */ + +#include "TransactionStack.h" + +#include "nsCycleCollectionParticipant.h" +#include "nsDebug.h" +#include "nsISupportsUtils.h" +#include "nscore.h" +#include "TransactionItem.h" + +namespace mozilla { + +TransactionStack::TransactionStack(Type aType) + : nsRefPtrDeque(), mType(aType) {} + +TransactionStack::~TransactionStack() { Clear(); } + +void TransactionStack::Push(TransactionItem* aTransactionItem) { + if (NS_WARN_IF(!aTransactionItem)) { + return; + } + nsRefPtrDeque::Push(aTransactionItem); +} + +void TransactionStack::Push( + already_AddRefed aTransactionItem) { + TransactionItem* transactionItem = aTransactionItem.take(); + if (NS_WARN_IF(!transactionItem)) { + return; + } + nsRefPtrDeque::Push(dont_AddRef(transactionItem)); +} + +already_AddRefed TransactionStack::Pop() { + return nsRefPtrDeque::Pop(); +} + +already_AddRefed TransactionStack::PopBottom() { + return nsRefPtrDeque::PopFront(); +} + +already_AddRefed TransactionStack::Peek() const { + RefPtr item = nsRefPtrDeque::Peek(); + return item.forget(); +} + +already_AddRefed TransactionStack::GetItemAt( + size_t aIndex) const { + RefPtr item = + nsRefPtrDeque::ObjectAt(aIndex); + return item.forget(); +} + +void TransactionStack::Clear() { + while (GetSize()) { + RefPtr item = mType == FOR_UNDO ? Pop() : PopBottom(); + } +} + +void TransactionStack::DoTraverse(nsCycleCollectionTraversalCallback& cb) { + size_t size = GetSize(); + for (size_t i = 0; i < size; ++i) { + auto* item = nsRefPtrDeque::ObjectAt(i); + if (item) { + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mDeque[i]"); + cb.NoteNativeChild(item, + NS_CYCLE_COLLECTION_PARTICIPANT(TransactionItem)); + } + } +} + +} // namespace mozilla -- cgit v1.2.3