tor-browser

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

ChangeAttributeTransaction.h (3249B)


      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 ChangeAttributeTransaction_h
      7 #define ChangeAttributeTransaction_h
      8 
      9 #include "EditTransactionBase.h"  // base class
     10 
     11 #include "EditorForwards.h"
     12 
     13 #include "mozilla/Attributes.h"            // override
     14 #include "nsCOMPtr.h"                      // nsCOMPtr members
     15 #include "nsCycleCollectionParticipant.h"  // NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED
     16 #include "nsISupportsImpl.h"               // NS_DECL_ISUPPORTS_INHERITED
     17 #include "nsString.h"                      // nsString members
     18 
     19 class nsAtom;
     20 
     21 namespace mozilla {
     22 namespace dom {
     23 class Element;
     24 }  // namespace dom
     25 
     26 /**
     27 * A transaction that changes an attribute of a content node.  This transaction
     28 * covers add, remove, and change attribute.
     29 */
     30 class ChangeAttributeTransaction final : public EditTransactionBase {
     31 protected:
     32  ChangeAttributeTransaction(EditorBase& aEditorBase, dom::Element& aElement,
     33                             nsAtom& aAttribute, const nsAString* aValue);
     34 
     35 public:
     36  /**
     37   * Creates a change attribute transaction to set an attribute to something.
     38   * This method never returns nullptr.
     39   *
     40   * @param aElement    The element whose attribute will be changed.
     41   * @param aAttribute  The name of the attribute to change.
     42   * @param aValue      The new value for aAttribute.
     43   */
     44  static already_AddRefed<ChangeAttributeTransaction> Create(
     45      EditorBase& aEditorBase, dom::Element& aElement, nsAtom& aAttribute,
     46      const nsAString& aValue);
     47 
     48  /**
     49   * Creates a change attribute transaction to remove an attribute.  This
     50   * method never returns nullptr.
     51   *
     52   * @param aElement    The element whose attribute will be changed.
     53   * @param aAttribute  The name of the attribute to remove.
     54   */
     55  static already_AddRefed<ChangeAttributeTransaction> CreateToRemove(
     56      EditorBase& aEditorBase, dom::Element& aElement, nsAtom& aAttribute);
     57 
     58  NS_DECL_ISUPPORTS_INHERITED
     59  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeAttributeTransaction,
     60                                           EditTransactionBase)
     61 
     62  NS_DECL_EDITTRANSACTIONBASE
     63  NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(ChangeAttributeTransaction)
     64 
     65  MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
     66 
     67  friend std::ostream& operator<<(
     68      std::ostream& aStream, const ChangeAttributeTransaction& aTransaction);
     69 
     70 private:
     71  virtual ~ChangeAttributeTransaction() = default;
     72 
     73  RefPtr<EditorBase> mEditorBase;
     74 
     75  // The element to operate upon
     76  nsCOMPtr<dom::Element> mElement;
     77 
     78  // The attribute to change
     79  RefPtr<nsAtom> mAttribute;
     80 
     81  // The value to set the attribute to (ignored if mRemoveAttribute==true)
     82  nsString mValue;
     83 
     84  // The value to set the attribute to for undo
     85  nsString mUndoValue;
     86 
     87  // True if the operation is to remove mAttribute from mElement
     88  bool mRemoveAttribute;
     89 
     90  // True if the mAttribute was set on mElement at the time of execution
     91  bool mAttributeWasSet;
     92 };
     93 
     94 }  // namespace mozilla
     95 
     96 #endif  // #ifndef ChangeAttributeTransaction_h