ChangeAttributeTransaction.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef ChangeAttributeTransaction_h
  6. #define ChangeAttributeTransaction_h
  7. #include "mozilla/Attributes.h" // override
  8. #include "mozilla/EditTransactionBase.h" // base class
  9. #include "nsCOMPtr.h" // nsCOMPtr members
  10. #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED
  11. #include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
  12. #include "nsString.h" // nsString members
  13. class nsIAtom;
  14. namespace mozilla {
  15. namespace dom {
  16. class Element;
  17. } // namespace dom
  18. /**
  19. * A transaction that changes an attribute of a content node. This transaction
  20. * covers add, remove, and change attribute.
  21. */
  22. class ChangeAttributeTransaction final : public EditTransactionBase
  23. {
  24. public:
  25. /**
  26. * @param aElement the element whose attribute will be changed
  27. * @param aAttribute the name of the attribute to change
  28. * @param aValue the new value for aAttribute, or null to remove
  29. */
  30. ChangeAttributeTransaction(dom::Element& aElement,
  31. nsIAtom& aAttribute,
  32. const nsAString* aValue);
  33. NS_DECL_ISUPPORTS_INHERITED
  34. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeAttributeTransaction,
  35. EditTransactionBase)
  36. NS_DECL_EDITTRANSACTIONBASE
  37. NS_IMETHOD RedoTransaction() override;
  38. private:
  39. virtual ~ChangeAttributeTransaction();
  40. // The element to operate upon
  41. nsCOMPtr<dom::Element> mElement;
  42. // The attribute to change
  43. nsCOMPtr<nsIAtom> mAttribute;
  44. // The value to set the attribute to (ignored if mRemoveAttribute==true)
  45. nsString mValue;
  46. // True if the operation is to remove mAttribute from mElement
  47. bool mRemoveAttribute;
  48. // True if the mAttribute was set on mElement at the time of execution
  49. bool mAttributeWasSet;
  50. // The value to set the attribute to for undo
  51. nsString mUndoValue;
  52. };
  53. } // namespace mozilla
  54. #endif // #ifndef ChangeAttributeTransaction_h