michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ChangeCSSInlineStyleTxn_h__ michael@0: #define ChangeCSSInlineStyleTxn_h__ michael@0: michael@0: #include "EditTxn.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsID.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsString.h" michael@0: #include "nscore.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIEditor; michael@0: michael@0: /** michael@0: * A transaction that changes the value of a CSS inline style of a content node. michael@0: * This transaction covers add, remove, and change a property's value. michael@0: */ michael@0: class ChangeCSSInlineStyleTxn : public EditTxn michael@0: { michael@0: public: michael@0: /** Initialize the transaction. michael@0: * @param aEditor [IN] the object providing core editing operations michael@0: * @param aNode [IN] the node whose style attribute will be changed michael@0: * @param aProperty [IN] the name of the property to change michael@0: * @param aValue [IN] the new value for aProperty, if aRemoveProperty is false michael@0: * @param aRemoveProperty [IN] if true, remove aProperty from style attribute michael@0: */ michael@0: NS_IMETHOD Init(nsIEditor * aEditor, michael@0: nsIDOMElement * aElement, michael@0: nsIAtom * aProperty, michael@0: const nsAString & aValue, michael@0: bool aRemoveProperty); michael@0: michael@0: /** returns true if the list of white-space separated values contains aValue michael@0: * michael@0: * @return true if the value is in the list of values michael@0: * @param aValueList [IN] a list of white-space separated values michael@0: * @param aValue [IN] the value to look for in the list michael@0: * @param aCaseSensitive [IN] a boolean being true if a case-sensitive search is needed michael@0: */ michael@0: static bool ValueIncludes(const nsAString & aValueList, const nsAString & aValue, bool aCaseSensitive); michael@0: michael@0: /** adds the value aNewValue to the list of white-space separated values aValues michael@0: * michael@0: * @param aValues [IN/OUT] a list of wite-space separated values michael@0: * @param aNewValue [IN] a value this code adds to aValues if it is not already in michael@0: */ michael@0: NS_IMETHOD AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue); michael@0: michael@0: ChangeCSSInlineStyleTxn(); michael@0: michael@0: private: michael@0: /** returns true if the property accepts more than one value michael@0: * michael@0: * @return true if the property accepts more than one value michael@0: * @param aCSSProperty [IN] the CSS property michael@0: */ michael@0: bool AcceptsMoreThanOneValue(nsIAtom * aCSSProperty); michael@0: michael@0: /** remove a value from a list of white-space separated values michael@0: * @param aValues [IN] a list of white-space separated values michael@0: * @param aRemoveValue [IN] the value to remove from the list michael@0: */ michael@0: void RemoveValueFromListOfValues(nsAString & aValues, const nsAString & aRemoveValue); michael@0: michael@0: /** If the boolean is true and if the value is not the empty string, michael@0: * set the property in the transaction to that value; if the value michael@0: * is empty, remove the property from element's styles. If the boolean michael@0: * is false, just remove the style attribute. michael@0: */ michael@0: nsresult SetStyle(bool aAttributeWasSet, nsAString & aValue); michael@0: michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeCSSInlineStyleTxn, EditTxn) michael@0: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); michael@0: michael@0: NS_DECL_EDITTXN michael@0: michael@0: NS_IMETHOD RedoTransaction(); michael@0: michael@0: protected: michael@0: michael@0: /** the editor that created this transaction */ michael@0: nsIEditor *mEditor; michael@0: michael@0: /** the element to operate upon */ michael@0: nsCOMPtr mElement; michael@0: michael@0: /** the CSS property to change */ michael@0: nsIAtom *mProperty; michael@0: michael@0: /** the value to set the property to (ignored if mRemoveProperty==true) */ michael@0: nsString mValue; michael@0: michael@0: /** the value to set the property to for undo */ michael@0: nsString mUndoValue; michael@0: /** the value to set the property to for redo */ michael@0: nsString mRedoValue; michael@0: /** true if the style attribute was present and not empty before DoTransaction */ michael@0: bool mUndoAttributeWasSet; michael@0: /** true if the style attribute is present and not empty after DoTransaction */ michael@0: bool mRedoAttributeWasSet; michael@0: michael@0: /** true if the operation is to remove mProperty from mElement */ michael@0: bool mRemoveProperty; michael@0: }; michael@0: michael@0: #endif