tor-browser

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

DeleteNodeTransaction.h (2305B)


      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 DeleteNodeTransaction_h
      7 #define DeleteNodeTransaction_h
      8 
      9 #include "DeleteContentTransactionBase.h"
     10 
     11 #include "EditorForwards.h"
     12 
     13 #include "nsCOMPtr.h"
     14 #include "nsCycleCollectionParticipant.h"
     15 #include "nsIContent.h"
     16 #include "nsINode.h"
     17 #include "nsISupportsImpl.h"
     18 #include "nscore.h"
     19 
     20 namespace mozilla {
     21 
     22 /**
     23 * A transaction that deletes a single element
     24 */
     25 class DeleteNodeTransaction final : public DeleteContentTransactionBase {
     26 protected:
     27  DeleteNodeTransaction(EditorBase& aEditorBase, nsIContent& aContentToDelete);
     28 
     29 public:
     30  /**
     31   * Creates a delete node transaction instance.  This returns nullptr if
     32   * it cannot remove the node from its parent.
     33   *
     34   * @param aEditorBase         The editor.
     35   * @param aContentToDelete    The node to be removed from the DOM tree.
     36   */
     37  static already_AddRefed<DeleteNodeTransaction> MaybeCreate(
     38      EditorBase& aEditorBase, nsIContent& aContentToDelete);
     39 
     40  /**
     41   * CanDoIt() returns true if there are enough members and can modify the
     42   * parent.  Otherwise, false.
     43   */
     44  bool CanDoIt() const;
     45 
     46  NS_DECL_ISUPPORTS_INHERITED
     47  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction,
     48                                           DeleteContentTransactionBase)
     49 
     50  NS_DECL_EDITTRANSACTIONBASE
     51  NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(DeleteNodeTransaction)
     52 
     53  MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() final;
     54 
     55  EditorDOMPoint SuggestPointToPutCaret() const final;
     56 
     57  nsIContent* GetContent() const { return mContentToDelete; }
     58 
     59  friend std::ostream& operator<<(std::ostream& aStream,
     60                                  const DeleteNodeTransaction& aTransaction);
     61 
     62 protected:
     63  virtual ~DeleteNodeTransaction() = default;
     64 
     65  // The element to delete.
     66  nsCOMPtr<nsIContent> mContentToDelete;
     67 
     68  // Parent of node to delete.
     69  nsCOMPtr<nsINode> mParentNode;
     70 
     71  // Next sibling to remember for undo/redo purposes.
     72  nsCOMPtr<nsIContent> mRefContent;
     73 };
     74 
     75 }  // namespace mozilla
     76 
     77 #endif  // #ifndef DeleteNodeTransaction_h