Bug 1260651 part.18 Rename mozilla::dom::ChangeStyleTxn to mozilla::ChangeStyleTransaction (and their files too) r=mccr8
MozReview-Commit-ID: KQn4f35WjvT
rename from editor/libeditor/ChangeStyleTxn.cpp
rename to editor/libeditor/ChangeStyleTransaction.cpp
--- a/editor/libeditor/ChangeStyleTxn.cpp
+++ b/editor/libeditor/ChangeStyleTransaction.cpp
@@ -1,50 +1,51 @@
/* -*- 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/. */
-#include "ChangeStyleTxn.h"
+#include "ChangeStyleTransaction.h"
#include "mozilla/dom/Element.h" // for Element
#include "nsAString.h" // for nsAString_internal::Append, etc
#include "nsCRT.h" // for nsCRT::IsAsciiSpace
#include "nsDebug.h" // for NS_ENSURE_SUCCESS, etc
#include "nsError.h" // for NS_ERROR_NULL_POINTER, etc
#include "nsGkAtoms.h" // for nsGkAtoms, etc
#include "nsIDOMCSSStyleDeclaration.h" // for nsIDOMCSSStyleDeclaration
#include "nsIDOMElementCSSInlineStyle.h" // for nsIDOMElementCSSInlineStyle
#include "nsLiteralString.h" // for NS_LITERAL_STRING, etc
#include "nsReadableUtils.h" // for ToNewUnicode
#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;
// put an extra null at the end
valueList.Append(kNullCh);
char16_t* value = ToNewUnicode(aValue);
@@ -76,18 +77,19 @@ ChangeStyleTxn::ValueIncludes(const nsAS
}
free(value);
return result;
}
// 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;
// put an extra null at the end
classStr.Append(kNullCh);
char16_t* start = classStr.BeginWriting();
char16_t* end = start;
@@ -111,33 +113,34 @@ ChangeStyleTxn::RemoveValueFromListOfVal
outString.Append(char16_t(' '));
}
start = ++end;
}
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)
, mValue(aValue)
, mRemoveProperty(aChangeType == eRemove)
, mUndoValue()
, mRedoValue()
, mUndoAttributeWasSet(false)
, mRedoAttributeWasSet(false)
{
}
NS_IMETHODIMP
-ChangeStyleTxn::DoTransaction()
+ChangeStyleTransaction::DoTransaction()
{
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles =
do_QueryInterface(mElement);
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
nsresult result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
NS_ENSURE_SUCCESS(result, result);
@@ -211,17 +214,18 @@ ChangeStyleTxn::DoTransaction()
} else {
mRedoAttributeWasSet = true;
}
return cssDecl->GetPropertyValue(propertyNameString, mRedoValue);
}
nsresult
-ChangeStyleTxn::SetStyle(bool aAttributeWasSet, nsAString& aValue)
+ChangeStyleTransaction::SetStyle(bool aAttributeWasSet,
+ nsAString& aValue)
{
nsresult result = NS_OK;
if (aAttributeWasSet) {
// The style attribute was not empty, let's recreate the declaration
nsAutoString propertyNameString;
mProperty->ToString(propertyNameString);
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles =
@@ -246,53 +250,55 @@ ChangeStyleTxn::SetStyle(bool aAttribute
} else {
result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
}
return result;
}
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] ");
} else {
aString.AppendLiteral("false] ");
}
aString += nsDependentAtomString(mProperty);
return NS_OK;
}
// 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);
} else if (!ValueIncludes(aValues, aNewValue)) {
// We already have another value but not this one; add it
aValues.Append(char16_t(' '));
aValues.Append(aNewValue);
}
}
+
+} // namespace mozilla
rename from editor/libeditor/ChangeStyleTxn.h
rename to editor/libeditor/ChangeStyleTransaction.h
--- a/editor/libeditor/ChangeStyleTxn.h
+++ b/editor/libeditor/ChangeStyleTransaction.h
@@ -1,112 +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 ChangeStyleTxn_h__
-#define ChangeStyleTxn_h__
+#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 ChangeStyleTxn : public EditTxn
+class ChangeStyleTransaction final : public EditTxn
{
public:
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTxn, EditTxn)
+ 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
- */
- ChangeStyleTxn(Element& aElement, nsIAtom& aProperty,
- const nsAString& aValue, EChangeType aChangeType);
+ /**
+ * @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
- *
- * @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
- */
+ /**
+ * 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:
- ~ChangeStyleTxn();
+ 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
- */
+ /*
+ * 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
- */
+ /**
+ * 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
- */
+ /**
+ * 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.
- */
+ /**
+ * 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<Element> mElement;
+ // The element to operate upon.
+ nsCOMPtr<dom::Element> mElement;
- /** The CSS property to change */
+ // The CSS property to change.
nsCOMPtr<nsIAtom> mProperty;
- /** The value to set the property to (ignored if mRemoveProperty==true) */
+ // The value to set the property to (ignored if mRemoveProperty==true).
nsString mValue;
- /** true if the operation is to remove mProperty from mElement */
+ // true if the operation is to remove mProperty from mElement.
bool mRemoveProperty;
- /** The value to set the property to for undo */
+ // The value to set the property to for undo.
nsString mUndoValue;
- /** The value to set the property to for redo */
+ // The value to set the property to for redo.
nsString mRedoValue;
- /** True if the style attribute was present and not empty before DoTransaction */
+ // 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 */
+ // True if the style attribute is present and not empty after DoTransaction.
bool mRedoAttributeWasSet;
};
-} // namespace dom
} // namespace mozilla
-#endif
+#endif // #ifndef ChangeStyleTransaction_h
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -10,17 +10,17 @@ MOCHITEST_MANIFESTS += [
]
MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
UNIFIED_SOURCES += [
'ChangeAttributeTransaction.cpp',
- 'ChangeStyleTxn.cpp',
+ 'ChangeStyleTransaction.cpp',
'CreateElementTxn.cpp',
'DeleteNodeTxn.cpp',
'DeleteRangeTxn.cpp',
'DeleteTextTxn.cpp',
'EditAggregateTxn.cpp',
'EditorUtils.cpp',
'EditTxn.cpp',
'HTMLEditUtils.cpp',
--- a/editor/libeditor/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/nsHTMLCSSUtils.cpp
@@ -1,16 +1,16 @@
/* -*- 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/. */
#include "nsHTMLCSSUtils.h"
-#include "ChangeStyleTxn.h"
+#include "ChangeStyleTransaction.h"
#include "EditTxn.h"
#include "mozilla/Assertions.h"
#include "mozilla/Preferences.h"
#include "mozilla/css/Declaration.h"
#include "mozilla/css/StyleRule.h"
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
@@ -429,22 +429,23 @@ nsHTMLCSSUtils::IsCSSEditableProperty(ns
}
// The lowest level above the transaction; adds the CSS declaration
// "aProperty : aValue" to the inline styles carried by aElement
nsresult
nsHTMLCSSUtils::SetCSSProperty(Element& aElement, nsIAtom& aProperty,
const nsAString& aValue, bool aSuppressTxn)
{
- RefPtr<ChangeStyleTxn> txn =
- CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eSet);
+ RefPtr<ChangeStyleTransaction> transaction =
+ CreateCSSPropertyTxn(aElement, aProperty, aValue,
+ ChangeStyleTransaction::eSet);
if (aSuppressTxn) {
- return txn->DoTransaction();
+ return transaction->DoTransaction();
}
- return mHTMLEditor->DoTransaction(txn);
+ return mHTMLEditor->DoTransaction(transaction);
}
nsresult
nsHTMLCSSUtils::SetCSSPropertyPixels(Element& aElement, nsIAtom& aProperty,
int32_t aIntValue)
{
nsAutoString s;
s.AppendInt(aIntValue);
@@ -454,32 +455,35 @@ nsHTMLCSSUtils::SetCSSPropertyPixels(Ele
// The lowest level above the transaction; removes the value aValue from the
// list of values specified for the CSS property aProperty, or totally remove
// the declaration if this property accepts only one value
nsresult
nsHTMLCSSUtils::RemoveCSSProperty(Element& aElement, nsIAtom& aProperty,
const nsAString& aValue, bool aSuppressTxn)
{
- RefPtr<ChangeStyleTxn> txn =
- CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eRemove);
+ RefPtr<ChangeStyleTransaction> 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<ChangeStyleTxn>
-nsHTMLCSSUtils::CreateCSSPropertyTxn(Element& aElement, nsIAtom& aAttribute,
- const nsAString& aValue,
- ChangeStyleTxn::EChangeType aChangeType)
+already_AddRefed<ChangeStyleTransaction>
+nsHTMLCSSUtils::CreateCSSPropertyTxn(
+ Element& aElement,
+ nsIAtom& aAttribute,
+ const nsAString& aValue,
+ ChangeStyleTransaction::EChangeType aChangeType)
{
- RefPtr<ChangeStyleTxn> txn =
- new ChangeStyleTxn(aElement, aAttribute, aValue, aChangeType);
- return txn.forget();
+ RefPtr<ChangeStyleTransaction> transaction =
+ new ChangeStyleTransaction(aElement, aAttribute, aValue, aChangeType);
+ return transaction.forget();
}
nsresult
nsHTMLCSSUtils::GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
nsAString& aValue)
{
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eSpecified);
}
@@ -1084,21 +1088,21 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInl
} else if (nsGkAtoms::i == aHTMLProperty) {
if (valueString.EqualsLiteral("italic") ||
valueString.EqualsLiteral("oblique")) {
aIsSet = true;
}
} 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")) ||
aHTMLAttribute->EqualsLiteral("bgcolor"))) {
if (htmlValueString.IsEmpty()) {
aIsSet = true;
} else {
nscolor rgba;
--- a/editor/libeditor/nsHTMLCSSUtils.h
+++ b/editor/libeditor/nsHTMLCSSUtils.h
@@ -1,20 +1,20 @@
/* -*- 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 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;
class nsIContent;
class nsIDOMCSSStyleDeclaration;
class nsIDOMElement;
class nsIDOMNode;
class nsINode;
@@ -381,20 +381,20 @@ private:
/** Creates a Transaction for setting or removing a CSS property. Never
* returns null.
*
* @param aElement [IN] a DOM element
* @param aProperty [IN] a CSS property
* @param aValue [IN] the value to set for this CSS property
* @param aChangeType [IN] eSet to set, eRemove to remove
*/
- already_AddRefed<mozilla::dom::ChangeStyleTxn>
+ already_AddRefed<mozilla::ChangeStyleTransaction>
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
*
* @param aNode [IN] a DOM node
* @param aProperty [IN] a CSS property
* @param aValue [OUT] the retrieved value for this property
* @param aStyleType [IN] eSpecified or eComputed
*/