1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/base/ChangeCSSInlineStyleTxn.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef ChangeCSSInlineStyleTxn_h__ 1.10 +#define ChangeCSSInlineStyleTxn_h__ 1.11 + 1.12 +#include "EditTxn.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsCycleCollectionParticipant.h" 1.15 +#include "nsID.h" 1.16 +#include "nsIDOMElement.h" 1.17 +#include "nsString.h" 1.18 +#include "nscore.h" 1.19 + 1.20 +class nsIAtom; 1.21 +class nsIEditor; 1.22 + 1.23 +/** 1.24 + * A transaction that changes the value of a CSS inline style of a content node. 1.25 + * This transaction covers add, remove, and change a property's value. 1.26 + */ 1.27 +class ChangeCSSInlineStyleTxn : public EditTxn 1.28 +{ 1.29 +public: 1.30 + /** Initialize the transaction. 1.31 + * @param aEditor [IN] the object providing core editing operations 1.32 + * @param aNode [IN] the node whose style attribute will be changed 1.33 + * @param aProperty [IN] the name of the property to change 1.34 + * @param aValue [IN] the new value for aProperty, if aRemoveProperty is false 1.35 + * @param aRemoveProperty [IN] if true, remove aProperty from style attribute 1.36 + */ 1.37 + NS_IMETHOD Init(nsIEditor * aEditor, 1.38 + nsIDOMElement * aElement, 1.39 + nsIAtom * aProperty, 1.40 + const nsAString & aValue, 1.41 + bool aRemoveProperty); 1.42 + 1.43 + /** returns true if the list of white-space separated values contains aValue 1.44 + * 1.45 + * @return true if the value is in the list of values 1.46 + * @param aValueList [IN] a list of white-space separated values 1.47 + * @param aValue [IN] the value to look for in the list 1.48 + * @param aCaseSensitive [IN] a boolean being true if a case-sensitive search is needed 1.49 + */ 1.50 + static bool ValueIncludes(const nsAString & aValueList, const nsAString & aValue, bool aCaseSensitive); 1.51 + 1.52 + /** adds the value aNewValue to the list of white-space separated values aValues 1.53 + * 1.54 + * @param aValues [IN/OUT] a list of wite-space separated values 1.55 + * @param aNewValue [IN] a value this code adds to aValues if it is not already in 1.56 + */ 1.57 + NS_IMETHOD AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue); 1.58 + 1.59 + ChangeCSSInlineStyleTxn(); 1.60 + 1.61 +private: 1.62 + /** returns true if the property accepts more than one value 1.63 + * 1.64 + * @return true if the property accepts more than one value 1.65 + * @param aCSSProperty [IN] the CSS property 1.66 + */ 1.67 + bool AcceptsMoreThanOneValue(nsIAtom * aCSSProperty); 1.68 + 1.69 + /** remove a value from a list of white-space separated values 1.70 + * @param aValues [IN] a list of white-space separated values 1.71 + * @param aRemoveValue [IN] the value to remove from the list 1.72 + */ 1.73 + void RemoveValueFromListOfValues(nsAString & aValues, const nsAString & aRemoveValue); 1.74 + 1.75 + /** If the boolean is true and if the value is not the empty string, 1.76 + * set the property in the transaction to that value; if the value 1.77 + * is empty, remove the property from element's styles. If the boolean 1.78 + * is false, just remove the style attribute. 1.79 + */ 1.80 + nsresult SetStyle(bool aAttributeWasSet, nsAString & aValue); 1.81 + 1.82 +public: 1.83 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeCSSInlineStyleTxn, EditTxn) 1.84 + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); 1.85 + 1.86 + NS_DECL_EDITTXN 1.87 + 1.88 + NS_IMETHOD RedoTransaction(); 1.89 + 1.90 +protected: 1.91 + 1.92 + /** the editor that created this transaction */ 1.93 + nsIEditor *mEditor; 1.94 + 1.95 + /** the element to operate upon */ 1.96 + nsCOMPtr<nsIDOMElement> mElement; 1.97 + 1.98 + /** the CSS property to change */ 1.99 + nsIAtom *mProperty; 1.100 + 1.101 + /** the value to set the property to (ignored if mRemoveProperty==true) */ 1.102 + nsString mValue; 1.103 + 1.104 + /** the value to set the property to for undo */ 1.105 + nsString mUndoValue; 1.106 + /** the value to set the property to for redo */ 1.107 + nsString mRedoValue; 1.108 + /** true if the style attribute was present and not empty before DoTransaction */ 1.109 + bool mUndoAttributeWasSet; 1.110 + /** true if the style attribute is present and not empty after DoTransaction */ 1.111 + bool mRedoAttributeWasSet; 1.112 + 1.113 + /** true if the operation is to remove mProperty from mElement */ 1.114 + bool mRemoveProperty; 1.115 +}; 1.116 + 1.117 +#endif