Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/TransactionManager.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef mozilla_TransactionManager_h
7
#define mozilla_TransactionManager_h
8
9
#include "mozilla/TransactionStack.h"
10
11
#include "nsCOMArray.h"
12
#include "nsCOMPtr.h"
13
#include "nsCycleCollectionParticipant.h"
14
#include "nsISupportsImpl.h"
15
#include "nsITransactionManager.h"
16
#include "nsWeakReference.h"
17
#include "nscore.h"
18
19
class nsITransaction;
20
class nsITransactionListener;
21
22
namespace mozilla {
23
24
class TransactionManager final : public nsITransactionManager
25
                               , public nsSupportsWeakReference
26
{
27
public:
28
  explicit TransactionManager(int32_t aMaxTransactionCount = -1);
29
30
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31
  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TransactionManager,
32
                                           nsITransactionManager)
33
34
  NS_DECL_NSITRANSACTIONMANAGER
35
36
  already_AddRefed<nsITransaction> PeekUndoStack();
37
  already_AddRefed<nsITransaction> PeekRedoStack();
38
39
  nsresult Undo();
40
  nsresult Redo();
41
42
  size_t NumberOfUndoItems() const
43
0
  {
44
0
    return mUndoStack.GetSize();
45
0
  }
46
  size_t NumberOfRedoItems() const
47
0
  {
48
0
    return mRedoStack.GetSize();
49
0
  }
50
51
0
  int32_t NumberOfMaximumTransactions() const { return mMaxTransactionCount; }
52
53
  bool EnableUndoRedo(int32_t aMaxTransactionCount = -1);
54
  bool DisableUndoRedo()
55
0
  {
56
0
    return EnableUndoRedo(0);
57
0
  }
58
  bool ClearUndoRedo()
59
0
  {
60
0
    if (NS_WARN_IF(!mDoStack.IsEmpty())) {
61
0
      return false;
62
0
    }
63
0
    mUndoStack.Clear();
64
0
    mRedoStack.Clear();
65
0
    return true;
66
0
  }
67
68
  bool AddTransactionListener(nsITransactionListener& aListener)
69
0
  {
70
0
    // XXX Shouldn't we check if aListener has already been in mListeners?
71
0
    return mListeners.AppendObject(&aListener);
72
0
  }
73
  bool RemoveTransactionListener(nsITransactionListener& aListener)
74
0
  {
75
0
    return mListeners.RemoveObject(&aListener);
76
0
  }
77
78
  nsresult WillDoNotify(nsITransaction* aTransaction, bool* aInterrupt);
79
  nsresult DidDoNotify(nsITransaction* aTransaction, nsresult aExecuteResult);
80
  nsresult WillUndoNotify(nsITransaction* aTransaction, bool* aInterrupt);
81
  nsresult DidUndoNotify(nsITransaction* aTransaction, nsresult aUndoResult);
82
  nsresult WillRedoNotify(nsITransaction* aTransaction, bool *aInterrupt);
83
  nsresult DidRedoNotify(nsITransaction* aTransaction, nsresult aRedoResult);
84
  nsresult WillBeginBatchNotify(bool* aInterrupt);
85
  nsresult DidBeginBatchNotify(nsresult aResult);
86
  nsresult WillEndBatchNotify(bool* aInterrupt);
87
  nsresult DidEndBatchNotify(nsresult aResult);
88
  nsresult WillMergeNotify(nsITransaction* aTop,
89
                           nsITransaction* aTransaction,
90
                           bool* aInterrupt);
91
  nsresult DidMergeNotify(nsITransaction* aTop,
92
                          nsITransaction* aTransaction,
93
                          bool aDidMerge,
94
                          nsresult aMergeResult);
95
96
  /**
97
   * Exposing non-virtual methods of nsITransactionManager methods.
98
   */
99
  nsresult BeginBatchInternal(nsISupports* aData);
100
  nsresult EndBatchInternal(bool aAllowEmpty);
101
102
private:
103
0
  virtual ~TransactionManager() = default;
104
105
  nsresult BeginTransaction(nsITransaction* aTransaction,
106
                            nsISupports* aData);
107
  nsresult EndTransaction(bool aAllowEmpty);
108
109
  int32_t                mMaxTransactionCount;
110
  TransactionStack mDoStack;
111
  TransactionStack mUndoStack;
112
  TransactionStack mRedoStack;
113
  nsCOMArray<nsITransactionListener> mListeners;
114
};
115
116
} // namespace mozilla
117
118
mozilla::TransactionManager*
119
nsITransactionManager::AsTransactionManager()
120
0
{
121
0
  return static_cast<mozilla::TransactionManager*>(this);
122
0
}
123
124
#endif // #ifndef mozilla_TransactionManager_h