tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TransactionManager.h (3247B)


      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/EditorForwards.h"
     10 #include "mozilla/TransactionStack.h"
     11 
     12 #include "nsCOMArray.h"
     13 #include "nsCOMPtr.h"
     14 #include "nsCycleCollectionParticipant.h"
     15 #include "nsISupportsImpl.h"
     16 #include "nsITransactionManager.h"
     17 #include "nsWeakReference.h"
     18 #include "nscore.h"
     19 
     20 class nsITransaction;
     21 
     22 namespace mozilla {
     23 
     24 class TransactionManager final : public nsITransactionManager,
     25                                 public nsSupportsWeakReference {
     26 public:
     27  explicit TransactionManager(int32_t aMaxTransactionCount = -1);
     28 
     29  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     30  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TransactionManager,
     31                                           nsITransactionManager)
     32 
     33  NS_DECL_NSITRANSACTIONMANAGER
     34 
     35  already_AddRefed<nsITransaction> PeekUndoStack();
     36  already_AddRefed<nsITransaction> PeekRedoStack();
     37 
     38  MOZ_CAN_RUN_SCRIPT nsresult Undo();
     39  MOZ_CAN_RUN_SCRIPT nsresult Redo();
     40 
     41  size_t NumberOfUndoItems() const { return mUndoStack.GetSize(); }
     42  size_t NumberOfRedoItems() const { return mRedoStack.GetSize(); }
     43 
     44  int32_t NumberOfMaximumTransactions() const { return mMaxTransactionCount; }
     45 
     46  bool EnableUndoRedo(int32_t aMaxTransactionCount = -1);
     47  bool DisableUndoRedo() { return EnableUndoRedo(0); }
     48  bool ClearUndoRedo() {
     49    if (NS_WARN_IF(!mDoStack.IsEmpty())) {
     50      return false;
     51    }
     52    mUndoStack.Clear();
     53    mRedoStack.Clear();
     54    return true;
     55  }
     56 
     57  /**
     58   * Delete the last undoable transaction from the undo stack.  This does
     59   * nothing if there is a redoable transactions.
     60   */
     61  already_AddRefed<nsITransaction> PopUndoStack();
     62 
     63  void Attach(HTMLEditor& aHTMLEditor);
     64  void Detach(const HTMLEditor& aHTMLEditor);
     65 
     66  MOZ_CAN_RUN_SCRIPT void DidDoNotify(nsITransaction& aTransaction,
     67                                      nsresult aDoResult);
     68  MOZ_CAN_RUN_SCRIPT void DidUndoNotify(nsITransaction& aTransaction,
     69                                        nsresult aUndoResult);
     70  MOZ_CAN_RUN_SCRIPT void DidRedoNotify(nsITransaction& aTransaction,
     71                                        nsresult aRedoResult);
     72 
     73  /**
     74   * Exposing non-virtual methods of nsITransactionManager methods.
     75   */
     76  MOZ_CAN_RUN_SCRIPT nsresult BeginBatchInternal(nsISupports* aData);
     77  nsresult EndBatchInternal(bool aAllowEmpty);
     78 
     79 private:
     80  virtual ~TransactionManager() = default;
     81 
     82  MOZ_CAN_RUN_SCRIPT nsresult BeginTransaction(nsITransaction* aTransaction,
     83                                               nsISupports* aData);
     84  nsresult EndTransaction(bool aAllowEmpty);
     85 
     86  int32_t mMaxTransactionCount;
     87  TransactionStack mDoStack;
     88  TransactionStack mUndoStack;
     89  TransactionStack mRedoStack;
     90  RefPtr<HTMLEditor> mHTMLEditor;
     91 };
     92 
     93 }  // namespace mozilla
     94 
     95 mozilla::TransactionManager* nsITransactionManager::AsTransactionManager() {
     96  return static_cast<mozilla::TransactionManager*>(this);
     97 }
     98 
     99 #endif  // #ifndef mozilla_TransactionManager_h