2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2000-11-27 07:55:20 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2014-02-27 10:51:16 +00:00
|
|
|
#include "mozilla/dom/MutationEvent.h"
|
2014-02-27 10:51:15 +00:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-24 10:04:16 +00:00
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
class nsPresContext;
|
2000-11-27 07:55:20 +00:00
|
|
|
|
2014-02-27 10:51:16 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
MutationEvent::MutationEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
InternalMutationEvent* aEvent)
|
2014-03-05 00:37:43 +00:00
|
|
|
: Event(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new InternalMutationEvent(false, 0))
|
2006-03-09 18:14:17 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mEventIsInternal = (aEvent == nullptr);
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 10:51:16 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(MutationEvent)
|
2000-11-27 07:55:20 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2000-11-27 07:55:20 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MutationEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MutationEvent, Event)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
already_AddRefed<nsINode>
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetRelatedNode()
|
2013-09-24 10:04:16 +00:00
|
|
|
{
|
2013-10-18 06:10:22 +00:00
|
|
|
nsCOMPtr<nsINode> n =
|
|
|
|
do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode);
|
2013-09-24 10:04:16 +00:00
|
|
|
return n.forget();
|
|
|
|
}
|
|
|
|
|
2000-11-27 07:55:20 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2013-03-14 21:18:20 +00:00
|
|
|
nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
|
|
|
|
nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
|
|
|
|
relatedDOMNode.forget(aRelatedNode);
|
2000-11-27 07:55:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetPrevValue(nsAString& aPrevValue)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2013-10-18 06:10:22 +00:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 18:09:19 +00:00
|
|
|
if (mutation->mPrevAttrValue)
|
|
|
|
mutation->mPrevAttrValue->ToString(aPrevValue);
|
2000-11-27 07:55:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetNewValue(nsAString& aNewValue)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2013-10-18 06:10:22 +00:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 18:09:19 +00:00
|
|
|
if (mutation->mNewAttrValue)
|
2000-11-27 07:55:20 +00:00
|
|
|
mutation->mNewAttrValue->ToString(aNewValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetAttrName(nsAString& aAttrName)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2013-10-18 06:10:22 +00:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 18:09:19 +00:00
|
|
|
if (mutation->mAttrName)
|
2000-11-27 07:55:20 +00:00
|
|
|
mutation->mAttrName->ToString(aAttrName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
uint16_t
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::AttrChange()
|
2013-09-24 10:04:16 +00:00
|
|
|
{
|
2013-10-18 06:10:22 +00:00
|
|
|
return mEvent->AsMutationEvent()->mAttrChange;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
2000-11-27 07:55:20 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::GetAttrChange(uint16_t* aAttrChange)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2013-03-14 21:18:20 +00:00
|
|
|
*aAttrChange = AttrChange();
|
2000-11-27 07:55:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 10:51:16 +00:00
|
|
|
MutationEvent::InitMutationEvent(const nsAString& aTypeArg,
|
|
|
|
bool aCanBubbleArg,
|
|
|
|
bool aCancelableArg,
|
|
|
|
nsIDOMNode* aRelatedNodeArg,
|
|
|
|
const nsAString& aPrevValueArg,
|
|
|
|
const nsAString& aNewValueArg,
|
|
|
|
const nsAString& aAttrNameArg,
|
|
|
|
uint16_t aAttrChangeArg)
|
2000-11-27 07:55:20 +00:00
|
|
|
{
|
2014-03-05 00:37:43 +00:00
|
|
|
nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
|
2004-08-20 18:09:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-10-18 06:10:22 +00:00
|
|
|
|
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 18:09:19 +00: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);
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|
2004-08-20 18:09:19 +00:00
|
|
|
mutation->mAttrChange = aAttrChangeArg;
|
2000-11-27 07:55:20 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2003-09-07 21:50:21 +00:00
|
|
|
}
|
2000-11-27 07:55:20 +00:00
|
|
|
|
2014-02-27 10:51:16 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2002-12-11 14:24:49 +00:00
|
|
|
|
2014-02-27 10:51:16 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
InternalMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent);
|
2014-03-17 20:00:11 +00:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|