michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "mozilla/dom/MutationEvent.h" michael@0: #include "mozilla/InternalMutationEvent.h" michael@0: michael@0: class nsPresContext; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: MutationEvent::MutationEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalMutationEvent* aEvent) michael@0: : Event(aOwner, aPresContext, michael@0: aEvent ? aEvent : new InternalMutationEvent(false, 0)) michael@0: { michael@0: mEventIsInternal = (aEvent == nullptr); michael@0: } michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(MutationEvent) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(Event) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(MutationEvent, Event) michael@0: NS_IMPL_RELEASE_INHERITED(MutationEvent, Event) michael@0: michael@0: already_AddRefed michael@0: MutationEvent::GetRelatedNode() michael@0: { michael@0: nsCOMPtr n = michael@0: do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode); michael@0: return n.forget(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) michael@0: { michael@0: nsCOMPtr relatedNode = GetRelatedNode(); michael@0: nsCOMPtr relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr; michael@0: relatedDOMNode.forget(aRelatedNode); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::GetPrevValue(nsAString& aPrevValue) michael@0: { michael@0: InternalMutationEvent* mutation = mEvent->AsMutationEvent(); michael@0: if (mutation->mPrevAttrValue) michael@0: mutation->mPrevAttrValue->ToString(aPrevValue); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::GetNewValue(nsAString& aNewValue) michael@0: { michael@0: InternalMutationEvent* mutation = mEvent->AsMutationEvent(); michael@0: if (mutation->mNewAttrValue) michael@0: mutation->mNewAttrValue->ToString(aNewValue); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::GetAttrName(nsAString& aAttrName) michael@0: { michael@0: InternalMutationEvent* mutation = mEvent->AsMutationEvent(); michael@0: if (mutation->mAttrName) michael@0: mutation->mAttrName->ToString(aAttrName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: uint16_t michael@0: MutationEvent::AttrChange() michael@0: { michael@0: return mEvent->AsMutationEvent()->mAttrChange; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::GetAttrChange(uint16_t* aAttrChange) michael@0: { michael@0: *aAttrChange = AttrChange(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: MutationEvent::InitMutationEvent(const nsAString& aTypeArg, michael@0: bool aCanBubbleArg, michael@0: bool aCancelableArg, michael@0: nsIDOMNode* aRelatedNodeArg, michael@0: const nsAString& aPrevValueArg, michael@0: const nsAString& aNewValueArg, michael@0: const nsAString& aAttrNameArg, michael@0: uint16_t aAttrChangeArg) michael@0: { michael@0: nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: InternalMutationEvent* mutation = mEvent->AsMutationEvent(); michael@0: mutation->mRelatedNode = aRelatedNodeArg; michael@0: if (!aPrevValueArg.IsEmpty()) michael@0: mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg); michael@0: if (!aNewValueArg.IsEmpty()) michael@0: mutation->mNewAttrValue = do_GetAtom(aNewValueArg); michael@0: if (!aAttrNameArg.IsEmpty()) { michael@0: mutation->mAttrName = do_GetAtom(aAttrNameArg); michael@0: } michael@0: mutation->mAttrChange = aAttrChangeArg; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: InternalMutationEvent* aEvent) michael@0: { michael@0: MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }