Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / editor / libeditor / ChangeAttributeTransaction.h
blob6f4dddbb6015f4069ee5761bc8a265ca581118b8
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 "mozilla/Attributes.h" // override
10 #include "mozilla/EditTransactionBase.h" // base class
11 #include "nsCOMPtr.h" // nsCOMPtr members
12 #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED
13 #include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
14 #include "nsString.h" // nsString members
16 class nsAtom;
18 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 private:
65 virtual ~ChangeAttributeTransaction() = default;
67 // The element to operate upon
68 nsCOMPtr<dom::Element> mElement;
70 // The attribute to change
71 RefPtr<nsAtom> mAttribute;
73 // The value to set the attribute to (ignored if mRemoveAttribute==true)
74 nsString mValue;
76 // The value to set the attribute to for undo
77 nsString mUndoValue;
79 // True if the operation is to remove mAttribute from mElement
80 bool mRemoveAttribute;
82 // True if the mAttribute was set on mElement at the time of execution
83 bool mAttributeWasSet;
86 } // namespace mozilla
88 #endif // #ifndef ChangeAttributeTransaction_h