|
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/. */ |
|
5 |
|
6 #include "nsCOMPtr.h" |
|
7 #include "mozilla/dom/MutationEvent.h" |
|
8 #include "mozilla/InternalMutationEvent.h" |
|
9 |
|
10 class nsPresContext; |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 MutationEvent::MutationEvent(EventTarget* aOwner, |
|
16 nsPresContext* aPresContext, |
|
17 InternalMutationEvent* aEvent) |
|
18 : Event(aOwner, aPresContext, |
|
19 aEvent ? aEvent : new InternalMutationEvent(false, 0)) |
|
20 { |
|
21 mEventIsInternal = (aEvent == nullptr); |
|
22 } |
|
23 |
|
24 NS_INTERFACE_MAP_BEGIN(MutationEvent) |
|
25 NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent) |
|
26 NS_INTERFACE_MAP_END_INHERITING(Event) |
|
27 |
|
28 NS_IMPL_ADDREF_INHERITED(MutationEvent, Event) |
|
29 NS_IMPL_RELEASE_INHERITED(MutationEvent, Event) |
|
30 |
|
31 already_AddRefed<nsINode> |
|
32 MutationEvent::GetRelatedNode() |
|
33 { |
|
34 nsCOMPtr<nsINode> n = |
|
35 do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode); |
|
36 return n.forget(); |
|
37 } |
|
38 |
|
39 NS_IMETHODIMP |
|
40 MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) |
|
41 { |
|
42 nsCOMPtr<nsINode> relatedNode = GetRelatedNode(); |
|
43 nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr; |
|
44 relatedDOMNode.forget(aRelatedNode); |
|
45 return NS_OK; |
|
46 } |
|
47 |
|
48 NS_IMETHODIMP |
|
49 MutationEvent::GetPrevValue(nsAString& aPrevValue) |
|
50 { |
|
51 InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
|
52 if (mutation->mPrevAttrValue) |
|
53 mutation->mPrevAttrValue->ToString(aPrevValue); |
|
54 return NS_OK; |
|
55 } |
|
56 |
|
57 NS_IMETHODIMP |
|
58 MutationEvent::GetNewValue(nsAString& aNewValue) |
|
59 { |
|
60 InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
|
61 if (mutation->mNewAttrValue) |
|
62 mutation->mNewAttrValue->ToString(aNewValue); |
|
63 return NS_OK; |
|
64 } |
|
65 |
|
66 NS_IMETHODIMP |
|
67 MutationEvent::GetAttrName(nsAString& aAttrName) |
|
68 { |
|
69 InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
|
70 if (mutation->mAttrName) |
|
71 mutation->mAttrName->ToString(aAttrName); |
|
72 return NS_OK; |
|
73 } |
|
74 |
|
75 uint16_t |
|
76 MutationEvent::AttrChange() |
|
77 { |
|
78 return mEvent->AsMutationEvent()->mAttrChange; |
|
79 } |
|
80 |
|
81 NS_IMETHODIMP |
|
82 MutationEvent::GetAttrChange(uint16_t* aAttrChange) |
|
83 { |
|
84 *aAttrChange = AttrChange(); |
|
85 return NS_OK; |
|
86 } |
|
87 |
|
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) |
|
97 { |
|
98 nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); |
|
99 NS_ENSURE_SUCCESS(rv, rv); |
|
100 |
|
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); |
|
109 } |
|
110 mutation->mAttrChange = aAttrChangeArg; |
|
111 |
|
112 return NS_OK; |
|
113 } |
|
114 |
|
115 } // namespace dom |
|
116 } // namespace mozilla |
|
117 |
|
118 using namespace mozilla; |
|
119 using namespace mozilla::dom; |
|
120 |
|
121 nsresult |
|
122 NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult, |
|
123 EventTarget* aOwner, |
|
124 nsPresContext* aPresContext, |
|
125 InternalMutationEvent* aEvent) |
|
126 { |
|
127 MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent); |
|
128 NS_ADDREF(it); |
|
129 *aInstancePtrResult = static_cast<Event*>(it); |
|
130 return NS_OK; |
|
131 } |