From f5aee941e2f11a29c2c08271c92f174d73674d7c Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Thu, 7 Jul 2016 14:23:25 +0900 Subject: [PATCH] Bug 1260651 part.18 Rename mozilla::dom::ChangeStyleTxn to mozilla::ChangeStyleTransaction (and their files too) r=mccr8 MozReview-Commit-ID: KQn4f35WjvT --HG-- rename : editor/libeditor/ChangeStyleTxn.cpp => editor/libeditor/ChangeStyleTransaction.cpp rename : editor/libeditor/ChangeStyleTxn.h => editor/libeditor/ChangeStyleTransaction.h --- ...tyleTxn.cpp => ChangeStyleTransaction.cpp} | 54 ++++---- editor/libeditor/ChangeStyleTransaction.h | 122 ++++++++++++++++++ editor/libeditor/ChangeStyleTxn.h | 112 ---------------- editor/libeditor/moz.build | 2 +- editor/libeditor/nsHTMLCSSUtils.cpp | 40 +++--- editor/libeditor/nsHTMLCSSUtils.h | 12 +- 6 files changed, 181 insertions(+), 161 deletions(-) rename editor/libeditor/{ChangeStyleTxn.cpp => ChangeStyleTransaction.cpp} (83%) create mode 100644 editor/libeditor/ChangeStyleTransaction.h delete mode 100644 editor/libeditor/ChangeStyleTxn.h diff --git a/editor/libeditor/ChangeStyleTxn.cpp b/editor/libeditor/ChangeStyleTransaction.cpp similarity index 83% rename from editor/libeditor/ChangeStyleTxn.cpp rename to editor/libeditor/ChangeStyleTransaction.cpp index 4305ad1db831..346503b9896d 100644 --- a/editor/libeditor/ChangeStyleTxn.cpp +++ b/editor/libeditor/ChangeStyleTransaction.cpp @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "ChangeStyleTxn.h" +#include "ChangeStyleTransaction.h" #include "mozilla/dom/Element.h" // for Element #include "nsAString.h" // for nsAString_internal::Append, etc @@ -18,28 +18,29 @@ #include "nsString.h" // for nsAutoString, nsString, etc #include "nsUnicharUtils.h" // for nsCaseInsensitiveStringComparator -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { + +using namespace dom; #define kNullCh (char16_t('\0')) -NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeStyleTxn, EditTxn, mElement) +NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeStyleTransaction, EditTxn, mElement) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeStyleTxn) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeStyleTransaction) NS_INTERFACE_MAP_END_INHERITING(EditTxn) -NS_IMPL_ADDREF_INHERITED(ChangeStyleTxn, EditTxn) -NS_IMPL_RELEASE_INHERITED(ChangeStyleTxn, EditTxn) +NS_IMPL_ADDREF_INHERITED(ChangeStyleTransaction, EditTxn) +NS_IMPL_RELEASE_INHERITED(ChangeStyleTransaction, EditTxn) -ChangeStyleTxn::~ChangeStyleTxn() +ChangeStyleTransaction::~ChangeStyleTransaction() { } // Answers true if aValue is in the string list of white-space separated values // aValueList. bool -ChangeStyleTxn::ValueIncludes(const nsAString &aValueList, - const nsAString &aValue) +ChangeStyleTransaction::ValueIncludes(const nsAString& aValueList, + const nsAString& aValue) { nsAutoString valueList(aValueList); bool result = false; @@ -81,8 +82,9 @@ ChangeStyleTxn::ValueIncludes(const nsAString &aValueList, // Removes the value aRemoveValue from the string list of white-space separated // values aValueList void -ChangeStyleTxn::RemoveValueFromListOfValues(nsAString& aValues, - const nsAString& aRemoveValue) +ChangeStyleTransaction::RemoveValueFromListOfValues( + nsAString& aValues, + const nsAString& aRemoveValue) { nsAutoString classStr(aValues); nsAutoString outString; @@ -116,9 +118,10 @@ ChangeStyleTxn::RemoveValueFromListOfValues(nsAString& aValues, aValues.Assign(outString); } -ChangeStyleTxn::ChangeStyleTxn(Element& aElement, nsIAtom& aProperty, - const nsAString& aValue, - EChangeType aChangeType) +ChangeStyleTransaction::ChangeStyleTransaction(Element& aElement, + nsIAtom& aProperty, + const nsAString& aValue, + EChangeType aChangeType) : EditTxn() , mElement(&aElement) , mProperty(&aProperty) @@ -132,7 +135,7 @@ ChangeStyleTxn::ChangeStyleTxn(Element& aElement, nsIAtom& aProperty, } NS_IMETHODIMP -ChangeStyleTxn::DoTransaction() +ChangeStyleTransaction::DoTransaction() { nsCOMPtr inlineStyles = do_QueryInterface(mElement); @@ -216,7 +219,8 @@ ChangeStyleTxn::DoTransaction() } nsresult -ChangeStyleTxn::SetStyle(bool aAttributeWasSet, nsAString& aValue) +ChangeStyleTransaction::SetStyle(bool aAttributeWasSet, + nsAString& aValue) { nsresult result = NS_OK; if (aAttributeWasSet) { @@ -251,21 +255,21 @@ ChangeStyleTxn::SetStyle(bool aAttributeWasSet, nsAString& aValue) } NS_IMETHODIMP -ChangeStyleTxn::UndoTransaction() +ChangeStyleTransaction::UndoTransaction() { return SetStyle(mUndoAttributeWasSet, mUndoValue); } NS_IMETHODIMP -ChangeStyleTxn::RedoTransaction() +ChangeStyleTransaction::RedoTransaction() { return SetStyle(mRedoAttributeWasSet, mRedoValue); } NS_IMETHODIMP -ChangeStyleTxn::GetTxnDescription(nsAString& aString) +ChangeStyleTransaction::GetTxnDescription(nsAString& aString) { - aString.AssignLiteral("ChangeStyleTxn: [mRemoveProperty == "); + aString.AssignLiteral("ChangeStyleTransaction: [mRemoveProperty == "); if (mRemoveProperty) { aString.AppendLiteral("true] "); @@ -278,15 +282,15 @@ ChangeStyleTxn::GetTxnDescription(nsAString& aString) // True if the CSS property accepts more than one value bool -ChangeStyleTxn::AcceptsMoreThanOneValue(nsIAtom& aCSSProperty) +ChangeStyleTransaction::AcceptsMoreThanOneValue(nsIAtom& aCSSProperty) { return &aCSSProperty == nsGkAtoms::text_decoration; } // Adds the value aNewValue to the list of white-space separated values aValues void -ChangeStyleTxn::AddValueToMultivalueProperty(nsAString& aValues, - const nsAString& aNewValue) +ChangeStyleTransaction::AddValueToMultivalueProperty(nsAString& aValues, + const nsAString& aNewValue) { if (aValues.IsEmpty() || aValues.LowerCaseEqualsLiteral("none")) { aValues.Assign(aNewValue); @@ -296,3 +300,5 @@ ChangeStyleTxn::AddValueToMultivalueProperty(nsAString& aValues, aValues.Append(aNewValue); } } + +} // namespace mozilla diff --git a/editor/libeditor/ChangeStyleTransaction.h b/editor/libeditor/ChangeStyleTransaction.h new file mode 100644 index 000000000000..0112d1101028 --- /dev/null +++ b/editor/libeditor/ChangeStyleTransaction.h @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef ChangeStyleTransaction_h +#define ChangeStyleTransaction_h + +#include "EditTxn.h" // base class +#include "nsCOMPtr.h" // nsCOMPtr members +#include "nsCycleCollectionParticipant.h" // various macros +#include "nsString.h" // nsString members + +class nsAString; +class nsIAtom; + +namespace mozilla { + +namespace dom { +class Element; +} // namespace dom + +/** + * A transaction that changes the value of a CSS inline style of a content + * node. This transaction covers add, remove, and change a property's value. + */ +class ChangeStyleTransaction final : public EditTxn +{ +public: + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTransaction, EditTxn) + + NS_DECL_ISUPPORTS_INHERITED + + NS_DECL_EDITTXN + + NS_IMETHOD RedoTransaction() override; + + enum EChangeType { eSet, eRemove }; + + /** + * @param aNode [IN] the node whose style attribute will be changed + * @param aProperty [IN] the name of the property to change + * @param aValue [IN] new value for aProperty, or value to remove + * @param aChangeType [IN] whether to set or remove + */ + ChangeStyleTransaction(dom::Element& aElement, + nsIAtom& aProperty, + const nsAString& aValue, + EChangeType aChangeType); + + /** + * Returns true if the list of white-space separated values contains aValue + * + * @param aValueList [IN] a list of white-space separated values + * @param aValue [IN] the value to look for in the list + * @return true if the value is in the list of values + */ + static bool ValueIncludes(const nsAString& aValueList, + const nsAString& aValue); + +private: + virtual ~ChangeStyleTransaction(); + + /* + * Adds the value aNewValue to list of white-space separated values aValues. + * + * @param aValues [IN/OUT] a list of wite-space separated values + * @param aNewValue [IN] a value this code adds to aValues if it is not + * already in + */ + void AddValueToMultivalueProperty(nsAString& aValues, + const nsAString& aNewValue); + + /** + * Returns true if the property accepts more than one value. + * + * @param aCSSProperty [IN] the CSS property + * @return true if the property accepts more than one value + */ + bool AcceptsMoreThanOneValue(nsIAtom& aCSSProperty); + + /** + * Remove a value from a list of white-space separated values. + * @param aValues [IN] a list of white-space separated values + * @param aRemoveValue [IN] the value to remove from the list + */ + void RemoveValueFromListOfValues(nsAString& aValues, + const nsAString& aRemoveValue); + + /** + * If the boolean is true and if the value is not the empty string, + * set the property in the transaction to that value; if the value + * is empty, remove the property from element's styles. If the boolean + * is false, just remove the style attribute. + */ + nsresult SetStyle(bool aAttributeWasSet, nsAString& aValue); + + // The element to operate upon. + nsCOMPtr mElement; + + // The CSS property to change. + nsCOMPtr mProperty; + + // The value to set the property to (ignored if mRemoveProperty==true). + nsString mValue; + + // true if the operation is to remove mProperty from mElement. + bool mRemoveProperty; + + // The value to set the property to for undo. + nsString mUndoValue; + // The value to set the property to for redo. + nsString mRedoValue; + // True if the style attribute was present and not empty before DoTransaction. + bool mUndoAttributeWasSet; + // True if the style attribute is present and not empty after DoTransaction. + bool mRedoAttributeWasSet; +}; + +} // namespace mozilla + +#endif // #ifndef ChangeStyleTransaction_h diff --git a/editor/libeditor/ChangeStyleTxn.h b/editor/libeditor/ChangeStyleTxn.h deleted file mode 100644 index 130a44e667a9..000000000000 --- a/editor/libeditor/ChangeStyleTxn.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef ChangeStyleTxn_h__ -#define ChangeStyleTxn_h__ - -#include "EditTxn.h" // base class -#include "nsCOMPtr.h" // nsCOMPtr members -#include "nsCycleCollectionParticipant.h" // various macros -#include "nsString.h" // nsString members - -class nsAString; -class nsIAtom; - -namespace mozilla { -namespace dom { -class Element; - -/** - * A transaction that changes the value of a CSS inline style of a content - * node. This transaction covers add, remove, and change a property's value. - */ -class ChangeStyleTxn : public EditTxn -{ -public: - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTxn, EditTxn) - - NS_DECL_ISUPPORTS_INHERITED - - NS_DECL_EDITTXN - - NS_IMETHOD RedoTransaction() override; - - enum EChangeType { eSet, eRemove }; - - /** @param aNode [IN] the node whose style attribute will be changed - * @param aProperty [IN] the name of the property to change - * @param aValue [IN] new value for aProperty, or value to remove - * @param aChangeType [IN] whether to set or remove - */ - ChangeStyleTxn(Element& aElement, nsIAtom& aProperty, - const nsAString& aValue, EChangeType aChangeType); - - /** Returns true if the list of white-space separated values contains aValue - * - * @return true if the value is in the list of values - * @param aValueList [IN] a list of white-space separated values - * @param aValue [IN] the value to look for in the list - */ - static bool ValueIncludes(const nsAString& aValueList, - const nsAString& aValue); - -private: - ~ChangeStyleTxn(); - - /** Adds the value aNewValue to list of white-space separated values aValues - * - * @param aValues [IN/OUT] a list of wite-space separated values - * @param aNewValue [IN] a value this code adds to aValues if it is not already in - */ - void AddValueToMultivalueProperty(nsAString& aValues, - const nsAString& aNewValue); - - /** Returns true if the property accepts more than one value - * - * @return true if the property accepts more than one value - * @param aCSSProperty [IN] the CSS property - */ - bool AcceptsMoreThanOneValue(nsIAtom& aCSSProperty); - - /** Remove a value from a list of white-space separated values - * @param aValues [IN] a list of white-space separated values - * @param aRemoveValue [IN] the value to remove from the list - */ - void RemoveValueFromListOfValues(nsAString& aValues, - const nsAString& aRemoveValue); - - /** If the boolean is true and if the value is not the empty string, - * set the property in the transaction to that value; if the value - * is empty, remove the property from element's styles. If the boolean - * is false, just remove the style attribute. - */ - nsresult SetStyle(bool aAttributeWasSet, nsAString& aValue); - - /** The element to operate upon */ - nsCOMPtr mElement; - - /** The CSS property to change */ - nsCOMPtr mProperty; - - /** The value to set the property to (ignored if mRemoveProperty==true) */ - nsString mValue; - - /** true if the operation is to remove mProperty from mElement */ - bool mRemoveProperty; - - /** The value to set the property to for undo */ - nsString mUndoValue; - /** The value to set the property to for redo */ - nsString mRedoValue; - /** True if the style attribute was present and not empty before DoTransaction */ - bool mUndoAttributeWasSet; - /** True if the style attribute is present and not empty after DoTransaction */ - bool mRedoAttributeWasSet; -}; - -} // namespace dom -} // namespace mozilla - -#endif diff --git a/editor/libeditor/moz.build b/editor/libeditor/moz.build index dfa9a105f0ae..6b8f2d51f713 100644 --- a/editor/libeditor/moz.build +++ b/editor/libeditor/moz.build @@ -15,7 +15,7 @@ BROWSER_CHROME_MANIFESTS += ['tests/browser.ini'] UNIFIED_SOURCES += [ 'ChangeAttributeTransaction.cpp', - 'ChangeStyleTxn.cpp', + 'ChangeStyleTransaction.cpp', 'CreateElementTxn.cpp', 'DeleteNodeTxn.cpp', 'DeleteRangeTxn.cpp', diff --git a/editor/libeditor/nsHTMLCSSUtils.cpp b/editor/libeditor/nsHTMLCSSUtils.cpp index 77a55ad3dafe..3aabb0a3a5bc 100644 --- a/editor/libeditor/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/nsHTMLCSSUtils.cpp @@ -5,7 +5,7 @@ #include "nsHTMLCSSUtils.h" -#include "ChangeStyleTxn.h" +#include "ChangeStyleTransaction.h" #include "EditTxn.h" #include "mozilla/Assertions.h" #include "mozilla/Preferences.h" @@ -434,12 +434,13 @@ nsresult nsHTMLCSSUtils::SetCSSProperty(Element& aElement, nsIAtom& aProperty, const nsAString& aValue, bool aSuppressTxn) { - RefPtr txn = - CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eSet); + RefPtr transaction = + CreateCSSPropertyTxn(aElement, aProperty, aValue, + ChangeStyleTransaction::eSet); if (aSuppressTxn) { - return txn->DoTransaction(); + return transaction->DoTransaction(); } - return mHTMLEditor->DoTransaction(txn); + return mHTMLEditor->DoTransaction(transaction); } nsresult @@ -459,22 +460,25 @@ nsresult nsHTMLCSSUtils::RemoveCSSProperty(Element& aElement, nsIAtom& aProperty, const nsAString& aValue, bool aSuppressTxn) { - RefPtr txn = - CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eRemove); + RefPtr transaction = + CreateCSSPropertyTxn(aElement, aProperty, aValue, + ChangeStyleTransaction::eRemove); if (aSuppressTxn) { - return txn->DoTransaction(); + return transaction->DoTransaction(); } - return mHTMLEditor->DoTransaction(txn); + return mHTMLEditor->DoTransaction(transaction); } -already_AddRefed -nsHTMLCSSUtils::CreateCSSPropertyTxn(Element& aElement, nsIAtom& aAttribute, - const nsAString& aValue, - ChangeStyleTxn::EChangeType aChangeType) +already_AddRefed +nsHTMLCSSUtils::CreateCSSPropertyTxn( + Element& aElement, + nsIAtom& aAttribute, + const nsAString& aValue, + ChangeStyleTransaction::EChangeType aChangeType) { - RefPtr txn = - new ChangeStyleTxn(aElement, aAttribute, aValue, aChangeType); - return txn.forget(); + RefPtr transaction = + new ChangeStyleTransaction(aElement, aAttribute, aValue, aChangeType); + return transaction.forget(); } nsresult @@ -1089,11 +1093,11 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode, } else if (nsGkAtoms::u == aHTMLProperty) { nsAutoString val; val.AssignLiteral("underline"); - aIsSet = ChangeStyleTxn::ValueIncludes(valueString, val); + aIsSet = ChangeStyleTransaction::ValueIncludes(valueString, val); } else if (nsGkAtoms::strike == aHTMLProperty) { nsAutoString val; val.AssignLiteral("line-through"); - aIsSet = ChangeStyleTxn::ValueIncludes(valueString, val); + aIsSet = ChangeStyleTransaction::ValueIncludes(valueString, val); } else if (aHTMLAttribute && ((nsGkAtoms::font == aHTMLProperty && aHTMLAttribute->EqualsLiteral("color")) || diff --git a/editor/libeditor/nsHTMLCSSUtils.h b/editor/libeditor/nsHTMLCSSUtils.h index dd50952e0f0a..0c405645e128 100644 --- a/editor/libeditor/nsHTMLCSSUtils.h +++ b/editor/libeditor/nsHTMLCSSUtils.h @@ -6,10 +6,10 @@ #ifndef nsHTMLCSSUtils_h__ #define nsHTMLCSSUtils_h__ -#include "ChangeStyleTxn.h" // for ChangeStyleTxn::EChangeType -#include "nsCOMPtr.h" // for already_AddRefed -#include "nsTArray.h" // for nsTArray -#include "nscore.h" // for nsAString, nsresult, nullptr +#include "ChangeStyleTransaction.h" // for ChangeStyleTransaction::EChangeType +#include "nsCOMPtr.h" // for already_AddRefed +#include "nsTArray.h" // for nsTArray +#include "nscore.h" // for nsAString, nsresult, nullptr class nsComputedDOMStyle; class nsIAtom; @@ -386,10 +386,10 @@ private: * @param aValue [IN] the value to set for this CSS property * @param aChangeType [IN] eSet to set, eRemove to remove */ - already_AddRefed + already_AddRefed CreateCSSPropertyTxn(mozilla::dom::Element& aElement, nsIAtom& aProperty, const nsAString& aValue, - mozilla::dom::ChangeStyleTxn::EChangeType aChangeType); + mozilla::ChangeStyleTransaction::EChangeType aChangeType); /** back-end for GetSpecifiedProperty and GetComputedProperty *