2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDOMMutationEvent.h"
|
2013-03-14 06:23:28 -07:00
|
|
|
#include "nsMutationEvent.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsPresContext;
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMMutationEvent::nsDOMMutationEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMutationEvent* aEvent)
|
2013-03-09 03:34:29 -08:00
|
|
|
: nsDOMEvent(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new nsMutationEvent(false, 0))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mEventIsInternal = (aEvent == nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationEvent::~nsDOMMutationEvent()
|
|
|
|
{
|
|
|
|
if (mEventIsInternal) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete mutation;
|
2012-07-30 07:20:58 -07:00
|
|
|
mEvent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(MutationEvent, nsDOMMutationEvent)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMMutationEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MutationEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
|
|
|
|
{
|
2013-03-14 06:23:28 -07:00
|
|
|
*aRelatedNode = nullptr;
|
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
|
|
|
*aRelatedNode = mutation->mRelatedNode;
|
|
|
|
NS_IF_ADDREF(*aRelatedNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMMutationEvent::GetPrevValue(nsAString& aPrevValue)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mutation->mPrevAttrValue)
|
|
|
|
mutation->mPrevAttrValue->ToString(aPrevValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMMutationEvent::GetNewValue(nsAString& aNewValue)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mutation->mNewAttrValue)
|
|
|
|
mutation->mNewAttrValue->ToString(aNewValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMMutationEvent::GetAttrName(nsAString& aAttrName)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mutation->mAttrName)
|
|
|
|
mutation->mAttrName->ToString(aAttrName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMMutationEvent::GetAttrChange(uint16_t* aAttrChange)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-14 06:23:28 -07:00
|
|
|
*aAttrChange = 0;
|
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
|
|
|
if (mutation->mAttrChange)
|
|
|
|
*aAttrChange = mutation->mAttrChange;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, bool aCanBubbleArg, bool aCancelableArg, nsIDOMNode* aRelatedNodeArg, const nsAString& aPrevValueArg, const nsAString& aNewValueArg, const nsAString& aAttrNameArg, uint16_t aAttrChangeArg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
mutation->mRelatedNode = aRelatedNodeArg;
|
|
|
|
if (!aPrevValueArg.IsEmpty())
|
|
|
|
mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg);
|
|
|
|
if (!aNewValueArg.IsEmpty())
|
|
|
|
mutation->mNewAttrValue = do_GetAtom(aNewValueArg);
|
|
|
|
if (!aAttrNameArg.IsEmpty()) {
|
|
|
|
mutation->mAttrName = do_GetAtom(aAttrNameArg);
|
|
|
|
}
|
|
|
|
mutation->mAttrChange = aAttrChangeArg;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsMutationEvent *aEvent)
|
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMMutationEvent* it = new nsDOMMutationEvent(aOwner, aPresContext, aEvent);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == it) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|