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/. */
7 #include "mozilla/dom/MutationEvent.h"
8 #include "mozilla/InternalMutationEvent.h"
15 MutationEvent::MutationEvent(EventTarget
* aOwner
,
16 nsPresContext
* aPresContext
,
17 InternalMutationEvent
* aEvent
)
18 : Event(aOwner
, aPresContext
,
19 aEvent
? aEvent
: new InternalMutationEvent(false, 0))
21 mEventIsInternal
= (aEvent
== nullptr);
24 NS_INTERFACE_MAP_BEGIN(MutationEvent
)
25 NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent
)
26 NS_INTERFACE_MAP_END_INHERITING(Event
)
28 NS_IMPL_ADDREF_INHERITED(MutationEvent
, Event
)
29 NS_IMPL_RELEASE_INHERITED(MutationEvent
, Event
)
31 already_AddRefed
<nsINode
>
32 MutationEvent::GetRelatedNode()
35 do_QueryInterface(mEvent
->AsMutationEvent()->mRelatedNode
);
40 MutationEvent::GetRelatedNode(nsIDOMNode
** aRelatedNode
)
42 nsCOMPtr
<nsINode
> relatedNode
= GetRelatedNode();
43 nsCOMPtr
<nsIDOMNode
> relatedDOMNode
= relatedNode
? relatedNode
->AsDOMNode() : nullptr;
44 relatedDOMNode
.forget(aRelatedNode
);
49 MutationEvent::GetPrevValue(nsAString
& aPrevValue
)
51 InternalMutationEvent
* mutation
= mEvent
->AsMutationEvent();
52 if (mutation
->mPrevAttrValue
)
53 mutation
->mPrevAttrValue
->ToString(aPrevValue
);
58 MutationEvent::GetNewValue(nsAString
& aNewValue
)
60 InternalMutationEvent
* mutation
= mEvent
->AsMutationEvent();
61 if (mutation
->mNewAttrValue
)
62 mutation
->mNewAttrValue
->ToString(aNewValue
);
67 MutationEvent::GetAttrName(nsAString
& aAttrName
)
69 InternalMutationEvent
* mutation
= mEvent
->AsMutationEvent();
70 if (mutation
->mAttrName
)
71 mutation
->mAttrName
->ToString(aAttrName
);
76 MutationEvent::AttrChange()
78 return mEvent
->AsMutationEvent()->mAttrChange
;
82 MutationEvent::GetAttrChange(uint16_t* aAttrChange
)
84 *aAttrChange
= AttrChange();
89 MutationEvent::InitMutationEvent(const nsAString
& aTypeArg
,
92 nsIDOMNode
* aRelatedNodeArg
,
93 const nsAString
& aPrevValueArg
,
94 const nsAString
& aNewValueArg
,
95 const nsAString
& aAttrNameArg
,
96 uint16_t aAttrChangeArg
)
98 nsresult rv
= Event::InitEvent(aTypeArg
, aCanBubbleArg
, aCancelableArg
);
99 NS_ENSURE_SUCCESS(rv
, rv
);
101 InternalMutationEvent
* mutation
= mEvent
->AsMutationEvent();
102 mutation
->mRelatedNode
= aRelatedNodeArg
;
103 if (!aPrevValueArg
.IsEmpty())
104 mutation
->mPrevAttrValue
= do_GetAtom(aPrevValueArg
);
105 if (!aNewValueArg
.IsEmpty())
106 mutation
->mNewAttrValue
= do_GetAtom(aNewValueArg
);
107 if (!aAttrNameArg
.IsEmpty()) {
108 mutation
->mAttrName
= do_GetAtom(aAttrNameArg
);
110 mutation
->mAttrChange
= aAttrChangeArg
;
116 } // namespace mozilla
118 using namespace mozilla
;
119 using namespace mozilla::dom
;
122 NS_NewDOMMutationEvent(nsIDOMEvent
** aInstancePtrResult
,
124 nsPresContext
* aPresContext
,
125 InternalMutationEvent
* aEvent
)
127 MutationEvent
* it
= new MutationEvent(aOwner
, aPresContext
, aEvent
);
129 *aInstancePtrResult
= static_cast<Event
*>(it
);