1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Original Author: Daniel Glazman <glazman@netscape.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef ChangeCSSInlineStyleTxn_h__
40 : #define ChangeCSSInlineStyleTxn_h__
41 :
42 : #include "EditTxn.h"
43 : #include "nsCOMPtr.h"
44 : #include "nsIDOMElement.h"
45 : #include "nsIEditor.h"
46 :
47 : /**
48 : * A transaction that changes the value of a CSS inline style of a content node.
49 : * This transaction covers add, remove, and change a property's value.
50 : */
51 : class ChangeCSSInlineStyleTxn : public EditTxn
52 0 : {
53 : public:
54 : /** Initialize the transaction.
55 : * @param aEditor [IN] the object providing core editing operations
56 : * @param aNode [IN] the node whose style attribute will be changed
57 : * @param aProperty [IN] the name of the property to change
58 : * @param aValue [IN] the new value for aProperty, if aRemoveProperty is false
59 : * @param aRemoveProperty [IN] if true, remove aProperty from style attribute
60 : */
61 : NS_IMETHOD Init(nsIEditor * aEditor,
62 : nsIDOMElement * aElement,
63 : nsIAtom * aProperty,
64 : const nsAString & aValue,
65 : bool aRemoveProperty);
66 :
67 : /** returns true if the list of white-space separated values contains aValue
68 : *
69 : * @return true if the value is in the list of values
70 : * @param aValueList [IN] a list of white-space separated values
71 : * @param aValue [IN] the value to look for in the list
72 : * @param aCaseSensitive [IN] a boolean being true if a case-sensitive search is needed
73 : */
74 : static bool ValueIncludes(const nsAString & aValueList, const nsAString & aValue, bool aCaseSensitive);
75 :
76 : /** adds the value aNewValue to the list of white-space separated values aValues
77 : *
78 : * @param aValues [IN/OUT] a list of wite-space separated values
79 : * @param aNewValue [IN] a value this code adds to aValues if it is not already in
80 : */
81 : NS_IMETHOD AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue);
82 :
83 : ChangeCSSInlineStyleTxn();
84 :
85 : private:
86 : /** returns true if the property accepts more than one value
87 : *
88 : * @return true if the property accepts more than one value
89 : * @param aCSSProperty [IN] the CSS property
90 : */
91 : bool AcceptsMoreThanOneValue(nsIAtom * aCSSProperty);
92 :
93 : /** remove a value from a list of white-space separated values
94 : * @param aValues [IN] a list of white-space separated values
95 : * @param aRemoveValue [IN] the value to remove from the list
96 : */
97 : void RemoveValueFromListOfValues(nsAString & aValues, const nsAString & aRemoveValue);
98 :
99 : /** If the boolean is true and if the value is not the empty string,
100 : * set the property in the transaction to that value; if the value
101 : * is empty, remove the property from element's styles. If the boolean
102 : * is false, just remove the style attribute.
103 : */
104 : nsresult SetStyle(bool aAttributeWasSet, nsAString & aValue);
105 :
106 : public:
107 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeCSSInlineStyleTxn, EditTxn)
108 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
109 :
110 : NS_DECL_EDITTXN
111 :
112 : NS_IMETHOD RedoTransaction();
113 :
114 : protected:
115 :
116 : /** the editor that created this transaction */
117 : nsIEditor *mEditor;
118 :
119 : /** the element to operate upon */
120 : nsCOMPtr<nsIDOMElement> mElement;
121 :
122 : /** the CSS property to change */
123 : nsIAtom *mProperty;
124 :
125 : /** the value to set the property to (ignored if mRemoveProperty==true) */
126 : nsString mValue;
127 :
128 : /** the value to set the property to for undo */
129 : nsString mUndoValue;
130 : /** the value to set the property to for redo */
131 : nsString mRedoValue;
132 : /** true if the style attribute was present and not empty before DoTransaction */
133 : bool mUndoAttributeWasSet;
134 : /** true if the style attribute is present and not empty after DoTransaction */
135 : bool mRedoAttributeWasSet;
136 :
137 : /** true if the operation is to remove mProperty from mElement */
138 : bool mRemoveProperty;
139 : };
140 :
141 : #endif
|