/src/mozilla-central/dom/events/MutationEvent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsCOMPtr.h" |
8 | | #include "mozilla/dom/MutationEvent.h" |
9 | | #include "mozilla/InternalMutationEvent.h" |
10 | | |
11 | | class nsPresContext; |
12 | | |
13 | | namespace mozilla { |
14 | | namespace dom { |
15 | | |
16 | | MutationEvent::MutationEvent(EventTarget* aOwner, |
17 | | nsPresContext* aPresContext, |
18 | | InternalMutationEvent* aEvent) |
19 | | : Event(aOwner, aPresContext, |
20 | | aEvent ? aEvent : new InternalMutationEvent(false, eVoidEvent)) |
21 | 0 | { |
22 | 0 | mEventIsInternal = (aEvent == nullptr); |
23 | 0 | } |
24 | | |
25 | | nsINode* |
26 | | MutationEvent::GetRelatedNode() |
27 | 0 | { |
28 | 0 | return mEvent->AsMutationEvent()->mRelatedNode; |
29 | 0 | } |
30 | | |
31 | | void |
32 | | MutationEvent::GetPrevValue(nsAString& aPrevValue) const |
33 | 0 | { |
34 | 0 | InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
35 | 0 | if (mutation->mPrevAttrValue) |
36 | 0 | mutation->mPrevAttrValue->ToString(aPrevValue); |
37 | 0 | } |
38 | | |
39 | | void |
40 | | MutationEvent::GetNewValue(nsAString& aNewValue) const |
41 | 0 | { |
42 | 0 | InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
43 | 0 | if (mutation->mNewAttrValue) |
44 | 0 | mutation->mNewAttrValue->ToString(aNewValue); |
45 | 0 | } |
46 | | |
47 | | void |
48 | | MutationEvent::GetAttrName(nsAString& aAttrName) const |
49 | 0 | { |
50 | 0 | InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
51 | 0 | if (mutation->mAttrName) |
52 | 0 | mutation->mAttrName->ToString(aAttrName); |
53 | 0 | } |
54 | | |
55 | | uint16_t |
56 | | MutationEvent::AttrChange() |
57 | 0 | { |
58 | 0 | return mEvent->AsMutationEvent()->mAttrChange; |
59 | 0 | } |
60 | | |
61 | | void |
62 | | MutationEvent::InitMutationEvent(const nsAString& aType, |
63 | | bool aCanBubble, bool aCancelable, |
64 | | nsINode* aRelatedNode, |
65 | | const nsAString& aPrevValue, |
66 | | const nsAString& aNewValue, |
67 | | const nsAString& aAttrName, |
68 | | uint16_t& aAttrChange, |
69 | | ErrorResult& aRv) |
70 | 0 | { |
71 | 0 | NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); |
72 | 0 |
|
73 | 0 | Event::InitEvent(aType, aCanBubble, aCancelable); |
74 | 0 |
|
75 | 0 | InternalMutationEvent* mutation = mEvent->AsMutationEvent(); |
76 | 0 | mutation->mRelatedNode = aRelatedNode; |
77 | 0 | if (!aPrevValue.IsEmpty()) |
78 | 0 | mutation->mPrevAttrValue = NS_Atomize(aPrevValue); |
79 | 0 | if (!aNewValue.IsEmpty()) |
80 | 0 | mutation->mNewAttrValue = NS_Atomize(aNewValue); |
81 | 0 | if (!aAttrName.IsEmpty()) { |
82 | 0 | mutation->mAttrName = NS_Atomize(aAttrName); |
83 | 0 | } |
84 | 0 | mutation->mAttrChange = aAttrChange; |
85 | 0 | } |
86 | | |
87 | | } // namespace dom |
88 | | } // namespace mozilla |
89 | | |
90 | | using namespace mozilla; |
91 | | using namespace mozilla::dom; |
92 | | |
93 | | already_AddRefed<MutationEvent> |
94 | | NS_NewDOMMutationEvent(EventTarget* aOwner, |
95 | | nsPresContext* aPresContext, |
96 | | InternalMutationEvent* aEvent) |
97 | 0 | { |
98 | 0 | RefPtr<MutationEvent> it = new MutationEvent(aOwner, aPresContext, aEvent); |
99 | 0 | return it.forget(); |
100 | 0 | } |