editor/libeditor/base/ChangeCSSInlineStyleTxn.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:11c3b213576b
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
6 #ifndef ChangeCSSInlineStyleTxn_h__
7 #define ChangeCSSInlineStyleTxn_h__
8
9 #include "EditTxn.h"
10 #include "nsCOMPtr.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsID.h"
13 #include "nsIDOMElement.h"
14 #include "nsString.h"
15 #include "nscore.h"
16
17 class nsIAtom;
18 class nsIEditor;
19
20 /**
21 * A transaction that changes the value of a CSS inline style of a content node.
22 * This transaction covers add, remove, and change a property's value.
23 */
24 class ChangeCSSInlineStyleTxn : public EditTxn
25 {
26 public:
27 /** Initialize the transaction.
28 * @param aEditor [IN] the object providing core editing operations
29 * @param aNode [IN] the node whose style attribute will be changed
30 * @param aProperty [IN] the name of the property to change
31 * @param aValue [IN] the new value for aProperty, if aRemoveProperty is false
32 * @param aRemoveProperty [IN] if true, remove aProperty from style attribute
33 */
34 NS_IMETHOD Init(nsIEditor * aEditor,
35 nsIDOMElement * aElement,
36 nsIAtom * aProperty,
37 const nsAString & aValue,
38 bool aRemoveProperty);
39
40 /** returns true if the list of white-space separated values contains aValue
41 *
42 * @return true if the value is in the list of values
43 * @param aValueList [IN] a list of white-space separated values
44 * @param aValue [IN] the value to look for in the list
45 * @param aCaseSensitive [IN] a boolean being true if a case-sensitive search is needed
46 */
47 static bool ValueIncludes(const nsAString & aValueList, const nsAString & aValue, bool aCaseSensitive);
48
49 /** adds the value aNewValue to the list of white-space separated values aValues
50 *
51 * @param aValues [IN/OUT] a list of wite-space separated values
52 * @param aNewValue [IN] a value this code adds to aValues if it is not already in
53 */
54 NS_IMETHOD AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue);
55
56 ChangeCSSInlineStyleTxn();
57
58 private:
59 /** returns true if the property accepts more than one value
60 *
61 * @return true if the property accepts more than one value
62 * @param aCSSProperty [IN] the CSS property
63 */
64 bool AcceptsMoreThanOneValue(nsIAtom * aCSSProperty);
65
66 /** remove a value from a list of white-space separated values
67 * @param aValues [IN] a list of white-space separated values
68 * @param aRemoveValue [IN] the value to remove from the list
69 */
70 void RemoveValueFromListOfValues(nsAString & aValues, const nsAString & aRemoveValue);
71
72 /** If the boolean is true and if the value is not the empty string,
73 * set the property in the transaction to that value; if the value
74 * is empty, remove the property from element's styles. If the boolean
75 * is false, just remove the style attribute.
76 */
77 nsresult SetStyle(bool aAttributeWasSet, nsAString & aValue);
78
79 public:
80 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeCSSInlineStyleTxn, EditTxn)
81 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
82
83 NS_DECL_EDITTXN
84
85 NS_IMETHOD RedoTransaction();
86
87 protected:
88
89 /** the editor that created this transaction */
90 nsIEditor *mEditor;
91
92 /** the element to operate upon */
93 nsCOMPtr<nsIDOMElement> mElement;
94
95 /** the CSS property to change */
96 nsIAtom *mProperty;
97
98 /** the value to set the property to (ignored if mRemoveProperty==true) */
99 nsString mValue;
100
101 /** the value to set the property to for undo */
102 nsString mUndoValue;
103 /** the value to set the property to for redo */
104 nsString mRedoValue;
105 /** true if the style attribute was present and not empty before DoTransaction */
106 bool mUndoAttributeWasSet;
107 /** true if the style attribute is present and not empty after DoTransaction */
108 bool mRedoAttributeWasSet;
109
110 /** true if the operation is to remove mProperty from mElement */
111 bool mRemoveProperty;
112 };
113
114 #endif

mercurial