Bug 1025824 - Fix mHwcLayerMap handling r=sushil
[gecko.git] / dom / events / MutationEvent.cpp
blob8b05b0d890fc294c7a7e9e7d1096d66d92d9311b
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 "nsCOMPtr.h"
7 #include "mozilla/dom/MutationEvent.h"
8 #include "mozilla/InternalMutationEvent.h"
10 class nsPresContext;
12 namespace mozilla {
13 namespace dom {
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()
34 nsCOMPtr<nsINode> n =
35 do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode);
36 return n.forget();
39 NS_IMETHODIMP
40 MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
42 nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
43 nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
44 relatedDOMNode.forget(aRelatedNode);
45 return NS_OK;
48 NS_IMETHODIMP
49 MutationEvent::GetPrevValue(nsAString& aPrevValue)
51 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
52 if (mutation->mPrevAttrValue)
53 mutation->mPrevAttrValue->ToString(aPrevValue);
54 return NS_OK;
57 NS_IMETHODIMP
58 MutationEvent::GetNewValue(nsAString& aNewValue)
60 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
61 if (mutation->mNewAttrValue)
62 mutation->mNewAttrValue->ToString(aNewValue);
63 return NS_OK;
66 NS_IMETHODIMP
67 MutationEvent::GetAttrName(nsAString& aAttrName)
69 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
70 if (mutation->mAttrName)
71 mutation->mAttrName->ToString(aAttrName);
72 return NS_OK;
75 uint16_t
76 MutationEvent::AttrChange()
78 return mEvent->AsMutationEvent()->mAttrChange;
81 NS_IMETHODIMP
82 MutationEvent::GetAttrChange(uint16_t* aAttrChange)
84 *aAttrChange = AttrChange();
85 return NS_OK;
88 NS_IMETHODIMP
89 MutationEvent::InitMutationEvent(const nsAString& aTypeArg,
90 bool aCanBubbleArg,
91 bool aCancelableArg,
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;
112 return NS_OK;
115 } // namespace dom
116 } // namespace mozilla
118 using namespace mozilla;
119 using namespace mozilla::dom;
121 nsresult
122 NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
123 EventTarget* aOwner,
124 nsPresContext* aPresContext,
125 InternalMutationEvent* aEvent)
127 MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent);
128 NS_ADDREF(it);
129 *aInstancePtrResult = static_cast<Event*>(it);
130 return NS_OK;