Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef ChangeCSSInlineStyleTxn_h__ |
michael@0 | 7 | #define ChangeCSSInlineStyleTxn_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "EditTxn.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 12 | #include "nsID.h" |
michael@0 | 13 | #include "nsIDOMElement.h" |
michael@0 | 14 | #include "nsString.h" |
michael@0 | 15 | #include "nscore.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsIAtom; |
michael@0 | 18 | class nsIEditor; |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * A transaction that changes the value of a CSS inline style of a content node. |
michael@0 | 22 | * This transaction covers add, remove, and change a property's value. |
michael@0 | 23 | */ |
michael@0 | 24 | class ChangeCSSInlineStyleTxn : public EditTxn |
michael@0 | 25 | { |
michael@0 | 26 | public: |
michael@0 | 27 | /** Initialize the transaction. |
michael@0 | 28 | * @param aEditor [IN] the object providing core editing operations |
michael@0 | 29 | * @param aNode [IN] the node whose style attribute will be changed |
michael@0 | 30 | * @param aProperty [IN] the name of the property to change |
michael@0 | 31 | * @param aValue [IN] the new value for aProperty, if aRemoveProperty is false |
michael@0 | 32 | * @param aRemoveProperty [IN] if true, remove aProperty from style attribute |
michael@0 | 33 | */ |
michael@0 | 34 | NS_IMETHOD Init(nsIEditor * aEditor, |
michael@0 | 35 | nsIDOMElement * aElement, |
michael@0 | 36 | nsIAtom * aProperty, |
michael@0 | 37 | const nsAString & aValue, |
michael@0 | 38 | bool aRemoveProperty); |
michael@0 | 39 | |
michael@0 | 40 | /** returns true if the list of white-space separated values contains aValue |
michael@0 | 41 | * |
michael@0 | 42 | * @return true if the value is in the list of values |
michael@0 | 43 | * @param aValueList [IN] a list of white-space separated values |
michael@0 | 44 | * @param aValue [IN] the value to look for in the list |
michael@0 | 45 | * @param aCaseSensitive [IN] a boolean being true if a case-sensitive search is needed |
michael@0 | 46 | */ |
michael@0 | 47 | static bool ValueIncludes(const nsAString & aValueList, const nsAString & aValue, bool aCaseSensitive); |
michael@0 | 48 | |
michael@0 | 49 | /** adds the value aNewValue to the list of white-space separated values aValues |
michael@0 | 50 | * |
michael@0 | 51 | * @param aValues [IN/OUT] a list of wite-space separated values |
michael@0 | 52 | * @param aNewValue [IN] a value this code adds to aValues if it is not already in |
michael@0 | 53 | */ |
michael@0 | 54 | NS_IMETHOD AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue); |
michael@0 | 55 | |
michael@0 | 56 | ChangeCSSInlineStyleTxn(); |
michael@0 | 57 | |
michael@0 | 58 | private: |
michael@0 | 59 | /** returns true if the property accepts more than one value |
michael@0 | 60 | * |
michael@0 | 61 | * @return true if the property accepts more than one value |
michael@0 | 62 | * @param aCSSProperty [IN] the CSS property |
michael@0 | 63 | */ |
michael@0 | 64 | bool AcceptsMoreThanOneValue(nsIAtom * aCSSProperty); |
michael@0 | 65 | |
michael@0 | 66 | /** remove a value from a list of white-space separated values |
michael@0 | 67 | * @param aValues [IN] a list of white-space separated values |
michael@0 | 68 | * @param aRemoveValue [IN] the value to remove from the list |
michael@0 | 69 | */ |
michael@0 | 70 | void RemoveValueFromListOfValues(nsAString & aValues, const nsAString & aRemoveValue); |
michael@0 | 71 | |
michael@0 | 72 | /** If the boolean is true and if the value is not the empty string, |
michael@0 | 73 | * set the property in the transaction to that value; if the value |
michael@0 | 74 | * is empty, remove the property from element's styles. If the boolean |
michael@0 | 75 | * is false, just remove the style attribute. |
michael@0 | 76 | */ |
michael@0 | 77 | nsresult SetStyle(bool aAttributeWasSet, nsAString & aValue); |
michael@0 | 78 | |
michael@0 | 79 | public: |
michael@0 | 80 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeCSSInlineStyleTxn, EditTxn) |
michael@0 | 81 | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); |
michael@0 | 82 | |
michael@0 | 83 | NS_DECL_EDITTXN |
michael@0 | 84 | |
michael@0 | 85 | NS_IMETHOD RedoTransaction(); |
michael@0 | 86 | |
michael@0 | 87 | protected: |
michael@0 | 88 | |
michael@0 | 89 | /** the editor that created this transaction */ |
michael@0 | 90 | nsIEditor *mEditor; |
michael@0 | 91 | |
michael@0 | 92 | /** the element to operate upon */ |
michael@0 | 93 | nsCOMPtr<nsIDOMElement> mElement; |
michael@0 | 94 | |
michael@0 | 95 | /** the CSS property to change */ |
michael@0 | 96 | nsIAtom *mProperty; |
michael@0 | 97 | |
michael@0 | 98 | /** the value to set the property to (ignored if mRemoveProperty==true) */ |
michael@0 | 99 | nsString mValue; |
michael@0 | 100 | |
michael@0 | 101 | /** the value to set the property to for undo */ |
michael@0 | 102 | nsString mUndoValue; |
michael@0 | 103 | /** the value to set the property to for redo */ |
michael@0 | 104 | nsString mRedoValue; |
michael@0 | 105 | /** true if the style attribute was present and not empty before DoTransaction */ |
michael@0 | 106 | bool mUndoAttributeWasSet; |
michael@0 | 107 | /** true if the style attribute is present and not empty after DoTransaction */ |
michael@0 | 108 | bool mRedoAttributeWasSet; |
michael@0 | 109 | |
michael@0 | 110 | /** true if the operation is to remove mProperty from mElement */ |
michael@0 | 111 | bool mRemoveProperty; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | #endif |