Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / editor / libeditor / ChangeAttributeTransaction.h
blobb21a64f221afc186cda38669183c4e73fc10072f
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/. */
6 #ifndef ChangeAttributeTransaction_h
7 #define ChangeAttributeTransaction_h
9 #include "EditTransactionBase.h" // base class
11 #include "mozilla/Attributes.h" // override
12 #include "nsCOMPtr.h" // nsCOMPtr members
13 #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED
14 #include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
15 #include "nsString.h" // nsString members
17 class nsAtom;
19 namespace mozilla {
20 namespace dom {
21 class Element;
22 } // namespace dom
24 /**
25 * A transaction that changes an attribute of a content node. This transaction
26 * covers add, remove, and change attribute.
28 class ChangeAttributeTransaction final : public EditTransactionBase {
29 protected:
30 ChangeAttributeTransaction(dom::Element& aElement, nsAtom& aAttribute,
31 const nsAString* aValue);
33 public:
34 /**
35 * Creates a change attribute transaction to set an attribute to something.
36 * This method never returns nullptr.
38 * @param aElement The element whose attribute will be changed.
39 * @param aAttribute The name of the attribute to change.
40 * @param aValue The new value for aAttribute.
42 static already_AddRefed<ChangeAttributeTransaction> Create(
43 dom::Element& aElement, nsAtom& aAttribute, const nsAString& aValue);
45 /**
46 * Creates a change attribute transaction to remove an attribute. This
47 * method never returns nullptr.
49 * @param aElement The element whose attribute will be changed.
50 * @param aAttribute The name of the attribute to remove.
52 static already_AddRefed<ChangeAttributeTransaction> CreateToRemove(
53 dom::Element& aElement, nsAtom& aAttribute);
55 NS_DECL_ISUPPORTS_INHERITED
56 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeAttributeTransaction,
57 EditTransactionBase)
59 NS_DECL_EDITTRANSACTIONBASE
60 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(ChangeAttributeTransaction)
62 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
64 friend std::ostream& operator<<(
65 std::ostream& aStream, const ChangeAttributeTransaction& aTransaction);
67 private:
68 virtual ~ChangeAttributeTransaction() = default;
70 // The element to operate upon
71 nsCOMPtr<dom::Element> mElement;
73 // The attribute to change
74 RefPtr<nsAtom> mAttribute;
76 // The value to set the attribute to (ignored if mRemoveAttribute==true)
77 nsString mValue;
79 // The value to set the attribute to for undo
80 nsString mUndoValue;
82 // True if the operation is to remove mAttribute from mElement
83 bool mRemoveAttribute;
85 // True if the mAttribute was set on mElement at the time of execution
86 bool mAttributeWasSet;
89 } // namespace mozilla
91 #endif // #ifndef ChangeAttributeTransaction_h