Bug 1861305 - Renew data collection for audio_process_per_codec_name r=padenot
[gecko.git] / editor / libeditor / ChangeStyleTransaction.h
blob359cf3f255057cf6c3c43635319dd2741f87e5d3
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 ChangeStyleTransaction_h
7 #define ChangeStyleTransaction_h
9 #include "EditTransactionBase.h" // base class
11 #include "nsCOMPtr.h" // nsCOMPtr members
12 #include "nsCycleCollectionParticipant.h" // various macros
13 #include "nsString.h" // nsString members
15 class nsAtom;
16 class nsStyledElement;
18 namespace mozilla {
20 namespace dom {
21 class Element;
22 } // namespace dom
24 /**
25 * A transaction that changes the value of a CSS inline style of a content
26 * node. This transaction covers add, remove, and change a property's value.
28 class ChangeStyleTransaction final : public EditTransactionBase {
29 protected:
30 ChangeStyleTransaction(nsStyledElement& aStyledElement, nsAtom& aProperty,
31 const nsAString& aValue, bool aRemove);
33 public:
34 /**
35 * Creates a change style transaction. This never returns nullptr.
37 * @param aStyledElement The node whose style attribute will be changed.
38 * @param aProperty The name of the property to change.
39 * @param aValue New value for aProperty.
41 static already_AddRefed<ChangeStyleTransaction> Create(
42 nsStyledElement& aStyledElement, nsAtom& aProperty,
43 const nsAString& aValue);
45 /**
46 * Creates a change style transaction. This never returns nullptr.
48 * @param aStyledElement The node whose style attribute will be changed.
49 * @param aProperty The name of the property to change.
50 * @param aValue The value to remove from aProperty.
52 static already_AddRefed<ChangeStyleTransaction> CreateToRemove(
53 nsStyledElement& aStyledElement, nsAtom& aProperty,
54 const nsAString& aValue);
56 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTransaction,
57 EditTransactionBase)
59 NS_DECL_ISUPPORTS_INHERITED
61 NS_DECL_EDITTRANSACTIONBASE
62 NS_DECL_EDITTRANSACTIONBASE_GETASMETHODS_OVERRIDE(ChangeStyleTransaction)
64 MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
66 /**
67 * Returns true if the list of white-space separated values contains aValue
69 * @param aValueList [IN] a list of white-space separated values
70 * @param aValue [IN] the value to look for in the list
71 * @return true if the value is in the list of values
73 static bool ValueIncludes(const nsACString& aValueList,
74 const nsACString& aValue);
76 friend std::ostream& operator<<(std::ostream& aStream,
77 const ChangeStyleTransaction& aTransaction);
79 private:
80 virtual ~ChangeStyleTransaction() = default;
82 /**
83 * Build new text-decoration value to set/remove specific values to/from the
84 * rule which already has aCurrentValues.
86 void BuildTextDecorationValueToSet(const nsACString& aCurrentValues,
87 const nsACString& aAddingValues,
88 nsACString& aOutValues);
89 void BuildTextDecorationValueToRemove(const nsACString& aCurrentValues,
90 const nsACString& aRemovingValues,
91 nsACString& aOutValues);
93 /**
94 * Helper method for above methods.
96 void BuildTextDecorationValue(bool aUnderline, bool aOverline,
97 bool aLineThrough, nsACString& aOutValues);
99 /**
100 * If the boolean is true and if the value is not the empty string,
101 * set the property in the transaction to that value; if the value
102 * is empty, remove the property from element's styles. If the boolean
103 * is false, just remove the style attribute.
105 MOZ_CAN_RUN_SCRIPT nsresult SetStyle(bool aAttributeWasSet,
106 nsACString& aValue);
108 // The element to operate upon.
109 RefPtr<nsStyledElement> mStyledElement;
111 // The CSS property to change.
112 RefPtr<nsAtom> mProperty;
114 // The value to set the property to (ignored if mRemoveProperty==true).
115 nsCString mValue;
117 // The value to set the property to for undo.
118 nsCString mUndoValue;
119 // The value to set the property to for redo.
120 nsCString mRedoValue;
122 // true if the operation is to remove mProperty from mElement.
123 bool mRemoveProperty;
125 // True if the style attribute was present and not empty before DoTransaction.
126 bool mUndoAttributeWasSet;
127 // True if the style attribute is present and not empty after DoTransaction.
128 bool mRedoAttributeWasSet;
131 } // namespace mozilla
133 #endif // #ifndef ChangeStyleTransaction_h