diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /editor/libeditor/ChangeAttributeTransaction.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'editor/libeditor/ChangeAttributeTransaction.cpp')
-rw-r--r-- | editor/libeditor/ChangeAttributeTransaction.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/editor/libeditor/ChangeAttributeTransaction.cpp b/editor/libeditor/ChangeAttributeTransaction.cpp new file mode 100644 index 000000000..04f539856 --- /dev/null +++ b/editor/libeditor/ChangeAttributeTransaction.cpp @@ -0,0 +1,98 @@ +/* -*- 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 "ChangeAttributeTransaction.h" + +#include "mozilla/dom/Element.h" // for Element + +#include "nsAString.h" +#include "nsError.h" // for NS_ERROR_NOT_INITIALIZED, etc. + +namespace mozilla { + +using namespace dom; + +ChangeAttributeTransaction::ChangeAttributeTransaction(Element& aElement, + nsIAtom& aAttribute, + const nsAString* aValue) + : EditTransactionBase() + , mElement(&aElement) + , mAttribute(&aAttribute) + , mValue(aValue ? *aValue : EmptyString()) + , mRemoveAttribute(!aValue) + , mAttributeWasSet(false) + , mUndoValue() +{ +} + +ChangeAttributeTransaction::~ChangeAttributeTransaction() +{ +} + +NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeAttributeTransaction, + EditTransactionBase, + mElement) + +NS_IMPL_ADDREF_INHERITED(ChangeAttributeTransaction, EditTransactionBase) +NS_IMPL_RELEASE_INHERITED(ChangeAttributeTransaction, EditTransactionBase) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeAttributeTransaction) +NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase) + +NS_IMETHODIMP +ChangeAttributeTransaction::DoTransaction() +{ + // Need to get the current value of the attribute and save it, and set + // mAttributeWasSet + mAttributeWasSet = mElement->GetAttr(kNameSpaceID_None, mAttribute, + mUndoValue); + + // XXX: hack until attribute-was-set code is implemented + if (!mUndoValue.IsEmpty()) { + mAttributeWasSet = true; + } + // XXX: end hack + + // Now set the attribute to the new value + if (mRemoveAttribute) { + return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true); + } + + return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true); +} + +NS_IMETHODIMP +ChangeAttributeTransaction::UndoTransaction() +{ + if (mAttributeWasSet) { + return mElement->SetAttr(kNameSpaceID_None, mAttribute, mUndoValue, true); + } + return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true); +} + +NS_IMETHODIMP +ChangeAttributeTransaction::RedoTransaction() +{ + if (mRemoveAttribute) { + return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true); + } + + return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true); +} + +NS_IMETHODIMP +ChangeAttributeTransaction::GetTxnDescription(nsAString& aString) +{ + aString.AssignLiteral("ChangeAttributeTransaction: [mRemoveAttribute == "); + + if (mRemoveAttribute) { + aString.AppendLiteral("true] "); + } else { + aString.AppendLiteral("false] "); + } + aString += nsDependentAtomString(mAttribute); + return NS_OK; +} + +} // namespace mozilla |