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
This commit is contained in:
Masayuki Nakano 2016-07-07 14:23:25 +09:00
parent c191da4516
commit f5aee941e2
6 changed files with 181 additions and 161 deletions

View File

@ -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<nsIDOMElementCSSInlineStyle> 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

View File

@ -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<dom::Element> mElement;
// The CSS property to change.
nsCOMPtr<nsIAtom> 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

View File

@ -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<Element> mElement;
/** The CSS property to change */
nsCOMPtr<nsIAtom> 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

View File

@ -15,7 +15,7 @@ BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
UNIFIED_SOURCES += [
'ChangeAttributeTransaction.cpp',
'ChangeStyleTxn.cpp',
'ChangeStyleTransaction.cpp',
'CreateElementTxn.cpp',
'DeleteNodeTxn.cpp',
'DeleteRangeTxn.cpp',

View File

@ -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<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
@ -459,22 +460,25 @@ 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
@ -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")) ||

View File

@ -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<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
*