Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsAutoPtr.h" |
michael@0 | 7 | #include "nsCOMPtr.h" |
michael@0 | 8 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 9 | #include "nsISupportsUtils.h" |
michael@0 | 10 | #include "nsTransactionItem.h" |
michael@0 | 11 | #include "nsTransactionStack.h" |
michael@0 | 12 | #include "nscore.h" |
michael@0 | 13 | |
michael@0 | 14 | nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType) |
michael@0 | 15 | : mType(aType) |
michael@0 | 16 | { |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | nsTransactionStack::~nsTransactionStack() |
michael@0 | 20 | { |
michael@0 | 21 | Clear(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | void |
michael@0 | 25 | nsTransactionStack::Push(nsTransactionItem *aTransaction) |
michael@0 | 26 | { |
michael@0 | 27 | if (!aTransaction) { |
michael@0 | 28 | return; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // The stack's bottom is the front of the deque, and the top is the back. |
michael@0 | 32 | mDeque.push_back(aTransaction); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | already_AddRefed<nsTransactionItem> |
michael@0 | 36 | nsTransactionStack::Pop() |
michael@0 | 37 | { |
michael@0 | 38 | if (mDeque.empty()) { |
michael@0 | 39 | return nullptr; |
michael@0 | 40 | } |
michael@0 | 41 | nsRefPtr<nsTransactionItem> ret = mDeque.back().forget(); |
michael@0 | 42 | mDeque.pop_back(); |
michael@0 | 43 | return ret.forget(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | already_AddRefed<nsTransactionItem> |
michael@0 | 47 | nsTransactionStack::PopBottom() |
michael@0 | 48 | { |
michael@0 | 49 | if (mDeque.empty()) { |
michael@0 | 50 | return nullptr; |
michael@0 | 51 | } |
michael@0 | 52 | nsRefPtr<nsTransactionItem> ret = mDeque.front().forget(); |
michael@0 | 53 | mDeque.pop_front(); |
michael@0 | 54 | return ret.forget(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | already_AddRefed<nsTransactionItem> |
michael@0 | 58 | nsTransactionStack::Peek() |
michael@0 | 59 | { |
michael@0 | 60 | if (mDeque.empty()) { |
michael@0 | 61 | return nullptr; |
michael@0 | 62 | } |
michael@0 | 63 | nsRefPtr<nsTransactionItem> ret = mDeque.back(); |
michael@0 | 64 | return ret.forget(); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | already_AddRefed<nsTransactionItem> |
michael@0 | 68 | nsTransactionStack::GetItem(int32_t aIndex) |
michael@0 | 69 | { |
michael@0 | 70 | if (aIndex < 0 || aIndex >= static_cast<int32_t>(mDeque.size())) { |
michael@0 | 71 | return nullptr; |
michael@0 | 72 | } |
michael@0 | 73 | nsRefPtr<nsTransactionItem> ret = mDeque[aIndex]; |
michael@0 | 74 | return ret.forget(); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | void |
michael@0 | 78 | nsTransactionStack::Clear() |
michael@0 | 79 | { |
michael@0 | 80 | while (!mDeque.empty()) { |
michael@0 | 81 | nsRefPtr<nsTransactionItem> tx = mType == FOR_UNDO ? Pop() : PopBottom(); |
michael@0 | 82 | }; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | void |
michael@0 | 86 | nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb) |
michael@0 | 87 | { |
michael@0 | 88 | int32_t size = mDeque.size(); |
michael@0 | 89 | for (int32_t i = 0; i < size; ++i) { |
michael@0 | 90 | nsTransactionItem* item = mDeque[i]; |
michael@0 | 91 | if (item) { |
michael@0 | 92 | NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mDeque[i]"); |
michael@0 | 93 | cb.NoteNativeChild(item, NS_CYCLE_COLLECTION_PARTICIPANT(nsTransactionItem)); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | } |