mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1425412 - part 11: Create factory methods for ChangeStyleTransaction and remove CSSEditUtils::CreateCSSPropertyTxn() r=m_kato
This patch creates factory methods for ChangeStyleTransaction and removes CSSEditUtils::CreateCSSPropertyTxn(). MozReview-Commit-ID: 1h8ZAj2PP5O --HG-- extra : rebase_source : 3da3070ad179bac1aadbfc6984b4c2922a052ec0
This commit is contained in:
parent
bbbb83c937
commit
0dd5b5022a
@ -455,12 +455,15 @@ CSSEditUtils::SetCSSProperty(Element& aElement,
|
||||
bool aSuppressTxn)
|
||||
{
|
||||
RefPtr<ChangeStyleTransaction> transaction =
|
||||
CreateCSSPropertyTxn(aElement, aProperty, aValue,
|
||||
ChangeStyleTransaction::eSet);
|
||||
ChangeStyleTransaction::Create(aElement, aProperty, aValue);
|
||||
if (aSuppressTxn) {
|
||||
return transaction->DoTransaction();
|
||||
}
|
||||
return mHTMLEditor->DoTransaction(transaction);
|
||||
if (NS_WARN_IF(!mHTMLEditor)) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
|
||||
return htmlEditor->DoTransaction(transaction);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -484,24 +487,15 @@ CSSEditUtils::RemoveCSSProperty(Element& aElement,
|
||||
bool aSuppressTxn)
|
||||
{
|
||||
RefPtr<ChangeStyleTransaction> transaction =
|
||||
CreateCSSPropertyTxn(aElement, aProperty, aValue,
|
||||
ChangeStyleTransaction::eRemove);
|
||||
ChangeStyleTransaction::CreateToRemove(aElement, aProperty, aValue);
|
||||
if (aSuppressTxn) {
|
||||
return transaction->DoTransaction();
|
||||
}
|
||||
return mHTMLEditor->DoTransaction(transaction);
|
||||
}
|
||||
|
||||
already_AddRefed<ChangeStyleTransaction>
|
||||
CSSEditUtils::CreateCSSPropertyTxn(
|
||||
Element& aElement,
|
||||
nsAtom& aAttribute,
|
||||
const nsAString& aValue,
|
||||
ChangeStyleTransaction::EChangeType aChangeType)
|
||||
{
|
||||
RefPtr<ChangeStyleTransaction> transaction =
|
||||
new ChangeStyleTransaction(aElement, aAttribute, aValue, aChangeType);
|
||||
return transaction.forget();
|
||||
if (NS_WARN_IF(!mHTMLEditor)) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
|
||||
return htmlEditor->DoTransaction(transaction);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -458,20 +458,6 @@ private:
|
||||
nsTArray<nsString>& aValueArray,
|
||||
bool aGetOrRemoveRequest);
|
||||
|
||||
/**
|
||||
* 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<ChangeStyleTransaction>
|
||||
CreateCSSPropertyTxn(dom::Element& aElement,
|
||||
nsAtom& aProperty, const nsAString& aValue,
|
||||
ChangeStyleTransaction::EChangeType aChangeType);
|
||||
|
||||
/**
|
||||
* Back-end for GetSpecifiedProperty and GetComputedProperty.
|
||||
*
|
||||
|
@ -22,6 +22,44 @@ namespace mozilla {
|
||||
|
||||
using namespace dom;
|
||||
|
||||
// static
|
||||
already_AddRefed<ChangeStyleTransaction>
|
||||
ChangeStyleTransaction::Create(Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue)
|
||||
{
|
||||
RefPtr<ChangeStyleTransaction> transaction =
|
||||
new ChangeStyleTransaction(aElement, aProperty, aValue, false);
|
||||
return transaction.forget();
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<ChangeStyleTransaction>
|
||||
ChangeStyleTransaction::CreateToRemove(Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue)
|
||||
{
|
||||
RefPtr<ChangeStyleTransaction> transaction =
|
||||
new ChangeStyleTransaction(aElement, aProperty, aValue, true);
|
||||
return transaction.forget();
|
||||
}
|
||||
|
||||
ChangeStyleTransaction::ChangeStyleTransaction(Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue,
|
||||
bool aRemove)
|
||||
: EditTransactionBase()
|
||||
, mElement(&aElement)
|
||||
, mProperty(&aProperty)
|
||||
, mValue(aValue)
|
||||
, mRemoveProperty(aRemove)
|
||||
, mUndoValue()
|
||||
, mRedoValue()
|
||||
, mUndoAttributeWasSet(false)
|
||||
, mRedoAttributeWasSet(false)
|
||||
{
|
||||
}
|
||||
|
||||
#define kNullCh (char16_t('\0'))
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeStyleTransaction, EditTransactionBase,
|
||||
@ -119,22 +157,6 @@ ChangeStyleTransaction::RemoveValueFromListOfValues(
|
||||
aValues.Assign(outString);
|
||||
}
|
||||
|
||||
ChangeStyleTransaction::ChangeStyleTransaction(Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue,
|
||||
EChangeType aChangeType)
|
||||
: EditTransactionBase()
|
||||
, mElement(&aElement)
|
||||
, mProperty(&aProperty)
|
||||
, mValue(aValue)
|
||||
, mRemoveProperty(aChangeType == eRemove)
|
||||
, mUndoValue()
|
||||
, mRedoValue()
|
||||
, mUndoAttributeWasSet(false)
|
||||
, mRedoAttributeWasSet(false)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ChangeStyleTransaction::DoTransaction()
|
||||
{
|
||||
|
@ -25,7 +25,37 @@ class Element;
|
||||
*/
|
||||
class ChangeStyleTransaction final : public EditTransactionBase
|
||||
{
|
||||
protected:
|
||||
ChangeStyleTransaction(dom::Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue,
|
||||
bool aRemove);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a change style transaction. This never returns nullptr.
|
||||
*
|
||||
* @param aNode The node whose style attribute will be changed.
|
||||
* @param aProperty The name of the property to change.
|
||||
* @param aValue New value for aProperty.
|
||||
*/
|
||||
static already_AddRefed<ChangeStyleTransaction>
|
||||
Create(dom::Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue);
|
||||
|
||||
/**
|
||||
* Creates a change style transaction. This never returns nullptr.
|
||||
*
|
||||
* @param aNode The node whose style attribute will be changed.
|
||||
* @param aProperty The name of the property to change.
|
||||
* @param aValue The value to remove from aProperty.
|
||||
*/
|
||||
static already_AddRefed<ChangeStyleTransaction>
|
||||
CreateToRemove(dom::Element& aElement,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeStyleTransaction,
|
||||
EditTransactionBase)
|
||||
|
||||
@ -35,19 +65,6 @@ public:
|
||||
|
||||
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,
|
||||
nsAtom& aProperty,
|
||||
const nsAString& aValue,
|
||||
EChangeType aChangeType);
|
||||
|
||||
/**
|
||||
* Returns true if the list of white-space separated values contains aValue
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user