Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / events / MutationEvent.cpp
blobf1e91c10a5bc39f7c18c84ed5539489b37c25427
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/. */
7 #include "nsCOMPtr.h"
8 #include "mozilla/dom/MutationEvent.h"
9 #include "mozilla/InternalMutationEvent.h"
11 class nsPresContext;
13 namespace mozilla::dom {
15 MutationEvent::MutationEvent(EventTarget* aOwner, nsPresContext* aPresContext,
16 InternalMutationEvent* aEvent)
17 : Event(aOwner, aPresContext,
18 aEvent ? aEvent : new InternalMutationEvent(false, eVoidEvent)) {
19 mEventIsInternal = (aEvent == nullptr);
22 nsINode* MutationEvent::GetRelatedNode() {
23 return mEvent->AsMutationEvent()->mRelatedNode;
26 void MutationEvent::GetPrevValue(nsAString& aPrevValue) const {
27 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
28 if (mutation->mPrevAttrValue) mutation->mPrevAttrValue->ToString(aPrevValue);
31 void MutationEvent::GetNewValue(nsAString& aNewValue) const {
32 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
33 if (mutation->mNewAttrValue) mutation->mNewAttrValue->ToString(aNewValue);
36 void MutationEvent::GetAttrName(nsAString& aAttrName) const {
37 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
38 if (mutation->mAttrName) mutation->mAttrName->ToString(aAttrName);
41 uint16_t MutationEvent::AttrChange() {
42 return mEvent->AsMutationEvent()->mAttrChange;
45 void MutationEvent::InitMutationEvent(const nsAString& aType, bool aCanBubble,
46 bool aCancelable, nsINode* aRelatedNode,
47 const nsAString& aPrevValue,
48 const nsAString& aNewValue,
49 const nsAString& aAttrName,
50 uint16_t& aAttrChange, ErrorResult& aRv) {
51 NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
53 Event::InitEvent(aType, aCanBubble, aCancelable);
55 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
56 mutation->mRelatedNode = aRelatedNode;
57 if (!aPrevValue.IsEmpty()) mutation->mPrevAttrValue = NS_Atomize(aPrevValue);
58 if (!aNewValue.IsEmpty()) mutation->mNewAttrValue = NS_Atomize(aNewValue);
59 if (!aAttrName.IsEmpty()) {
60 mutation->mAttrName = NS_Atomize(aAttrName);
62 mutation->mAttrChange = aAttrChange;
65 } // namespace mozilla::dom
67 using namespace mozilla;
68 using namespace mozilla::dom;
70 already_AddRefed<MutationEvent> NS_NewDOMMutationEvent(
71 EventTarget* aOwner, nsPresContext* aPresContext,
72 InternalMutationEvent* aEvent) {
73 RefPtr<MutationEvent> it = new MutationEvent(aOwner, aPresContext, aEvent);
74 return it.forget();