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
16 class nsStyledElement
;
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
{
30 ChangeStyleTransaction(nsStyledElement
& aStyledElement
, nsAtom
& aProperty
,
31 const nsAString
& aValue
, bool aRemove
);
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
);
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
,
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
;
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
);
80 virtual ~ChangeStyleTransaction() = default;
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
);
94 * Helper method for above methods.
96 void BuildTextDecorationValue(bool aUnderline
, bool aOverline
,
97 bool aLineThrough
, nsACString
& aOutValues
);
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
,
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).
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