Bug 1247796. Use keyboardFocusIndicatorColor for ActiveBorder system color keyword...
[gecko.git] / editor / libeditor / ChangeAttributeTxn.cpp
blob496b419226692c0fd2f982707e0e0aefdaca8601
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ChangeAttributeTxn.h"
8 #include "mozilla/dom/Element.h" // for Element
10 #include "nsAString.h"
11 #include "nsError.h" // for NS_ERROR_NOT_INITIALIZED, etc
13 using namespace mozilla;
14 using namespace mozilla::dom;
16 ChangeAttributeTxn::ChangeAttributeTxn(Element& aElement, nsIAtom& aAttribute,
17 const nsAString* aValue)
18 : EditTxn()
19 , mElement(&aElement)
20 , mAttribute(&aAttribute)
21 , mValue(aValue ? *aValue : EmptyString())
22 , mRemoveAttribute(!aValue)
23 , mAttributeWasSet(false)
24 , mUndoValue()
28 ChangeAttributeTxn::~ChangeAttributeTxn()
32 NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeAttributeTxn, EditTxn,
33 mElement)
35 NS_IMPL_ADDREF_INHERITED(ChangeAttributeTxn, EditTxn)
36 NS_IMPL_RELEASE_INHERITED(ChangeAttributeTxn, EditTxn)
37 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeAttributeTxn)
38 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
40 NS_IMETHODIMP
41 ChangeAttributeTxn::DoTransaction()
43 // Need to get the current value of the attribute and save it, and set
44 // mAttributeWasSet
45 mAttributeWasSet = mElement->GetAttr(kNameSpaceID_None, mAttribute,
46 mUndoValue);
48 // XXX: hack until attribute-was-set code is implemented
49 if (!mUndoValue.IsEmpty()) {
50 mAttributeWasSet = true;
52 // XXX: end hack
54 // Now set the attribute to the new value
55 if (mRemoveAttribute) {
56 return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
59 return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true);
62 NS_IMETHODIMP
63 ChangeAttributeTxn::UndoTransaction()
65 if (mAttributeWasSet) {
66 return mElement->SetAttr(kNameSpaceID_None, mAttribute, mUndoValue, true);
68 return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
71 NS_IMETHODIMP
72 ChangeAttributeTxn::RedoTransaction()
74 if (mRemoveAttribute) {
75 return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
78 return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true);
81 NS_IMETHODIMP
82 ChangeAttributeTxn::GetTxnDescription(nsAString& aString)
84 aString.AssignLiteral("ChangeAttributeTxn: [mRemoveAttribute == ");
86 if (mRemoveAttribute) {
87 aString.AppendLiteral("true] ");
88 } else {
89 aString.AppendLiteral("false] ");
91 aString += nsDependentAtomString(mAttribute);
92 return NS_OK;