Bumping manifests a=b2g-bump
[gecko.git] / editor / libeditor / ChangeStyleTxn.h
blobfd5e6271841e5fa25a20f6c788633281a432df4d
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 ChangeStyleTxn_h__
7 #define ChangeStyleTxn_h__
9 #include "EditTxn.h" // base class
10 #include "nsCOMPtr.h" // nsCOMPtr members
11 #include "nsCycleCollectionParticipant.h" // various macros
12 #include "nsString.h" // nsString members
14 class nsAString;
15 class nsIAtom;
17 namespace mozilla {
18 namespace dom {
19 class Element;
21 /**
22 * A transaction that changes the value of a CSS inline style of a content
23 * node. This transaction covers add, remove, and change a property's value.
25 class ChangeStyleTxn : public EditTxn
27 public:
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTxn, EditTxn)
30 NS_DECL_ISUPPORTS_INHERITED
32 NS_DECL_EDITTXN
34 NS_IMETHOD RedoTransaction() MOZ_OVERRIDE;
36 enum EChangeType { eSet, eRemove };
38 /** @param aNode [IN] the node whose style attribute will be changed
39 * @param aProperty [IN] the name of the property to change
40 * @param aValue [IN] new value for aProperty, or value to remove
41 * @param aChangeType [IN] whether to set or remove
43 ChangeStyleTxn(Element& aElement, nsIAtom& aProperty,
44 const nsAString& aValue, EChangeType aChangeType);
46 /** Returns true if the list of white-space separated values contains aValue
48 * @return true if the value is in the list of values
49 * @param aValueList [IN] a list of white-space separated values
50 * @param aValue [IN] the value to look for in the list
52 static bool ValueIncludes(const nsAString& aValueList,
53 const nsAString& aValue);
55 private:
56 ~ChangeStyleTxn();
58 /** Adds the value aNewValue to list of white-space separated values aValues
60 * @param aValues [IN/OUT] a list of wite-space separated values
61 * @param aNewValue [IN] a value this code adds to aValues if it is not already in
63 void AddValueToMultivalueProperty(nsAString& aValues,
64 const nsAString& aNewValue);
66 /** Returns true if the property accepts more than one value
68 * @return true if the property accepts more than one value
69 * @param aCSSProperty [IN] the CSS property
71 bool AcceptsMoreThanOneValue(nsIAtom& aCSSProperty);
73 /** Remove a value from a list of white-space separated values
74 * @param aValues [IN] a list of white-space separated values
75 * @param aRemoveValue [IN] the value to remove from the list
77 void RemoveValueFromListOfValues(nsAString& aValues,
78 const nsAString& aRemoveValue);
80 /** If the boolean is true and if the value is not the empty string,
81 * set the property in the transaction to that value; if the value
82 * is empty, remove the property from element's styles. If the boolean
83 * is false, just remove the style attribute.
85 nsresult SetStyle(bool aAttributeWasSet, nsAString& aValue);
87 /** The element to operate upon */
88 nsCOMPtr<Element> mElement;
90 /** The CSS property to change */
91 nsCOMPtr<nsIAtom> mProperty;
93 /** The value to set the property to (ignored if mRemoveProperty==true) */
94 nsString mValue;
96 /** true if the operation is to remove mProperty from mElement */
97 bool mRemoveProperty;
99 /** The value to set the property to for undo */
100 nsString mUndoValue;
101 /** The value to set the property to for redo */
102 nsString mRedoValue;
103 /** True if the style attribute was present and not empty before DoTransaction */
104 bool mUndoAttributeWasSet;
105 /** True if the style attribute is present and not empty after DoTransaction */
106 bool mRedoAttributeWasSet;
112 #endif