2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 10:55:20 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2014-02-27 14:51:16 +04:00
|
|
|
#include "mozilla/dom/MutationEvent.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-24 14:04:16 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
2000-11-27 10:55:20 +03:00
|
|
|
|
2014-02-27 14:51:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
MutationEvent::MutationEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
InternalMutationEvent* aEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
: Event(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new InternalMutationEvent(false, 0))
|
2006-03-09 21:14:17 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mEventIsInternal = (aEvent == nullptr);
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:16 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(MutationEvent)
|
2000-11-27 10:55:20 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2000-11-27 10:55:20 +03:00
|
|
|
|
2014-03-05 04:37:43 +04: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 20:46:42 +04:00
|
|
|
|
2013-09-24 14:04:16 +04:00
|
|
|
already_AddRefed<nsINode>
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetRelatedNode()
|
2013-09-24 14:04:16 +04:00
|
|
|
{
|
2013-10-18 10:10:22 +04:00
|
|
|
nsCOMPtr<nsINode> n =
|
|
|
|
do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode);
|
2013-09-24 14:04:16 +04:00
|
|
|
return n.forget();
|
|
|
|
}
|
|
|
|
|
2000-11-27 10:55:20 +03:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
|
2000-11-27 10:55:20 +03:00
|
|
|
{
|
2013-03-15 01:18:20 +04:00
|
|
|
nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
|
|
|
|
nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
|
|
|
|
relatedDOMNode.forget(aRelatedNode);
|
2000-11-27 10:55:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetPrevValue(nsAString& aPrevValue)
|
2000-11-27 10:55:20 +03:00
|
|
|
{
|
2013-10-18 10:10:22 +04:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 22:09:19 +04:00
|
|
|
if (mutation->mPrevAttrValue)
|
|
|
|
mutation->mPrevAttrValue->ToString(aPrevValue);
|
2000-11-27 10:55:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetNewValue(nsAString& aNewValue)
|
2000-11-27 10:55:20 +03:00
|
|
|
{
|
2013-10-18 10:10:22 +04:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 22:09:19 +04:00
|
|
|
if (mutation->mNewAttrValue)
|
2000-11-27 10:55:20 +03:00
|
|
|
mutation->mNewAttrValue->ToString(aNewValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetAttrName(nsAString& aAttrName)
|
2000-11-27 10:55:20 +03:00
|
|
|
{
|
2013-10-18 10:10:22 +04:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 22:09:19 +04:00
|
|
|
if (mutation->mAttrName)
|
2000-11-27 10:55:20 +03:00
|
|
|
mutation->mAttrName->ToString(aAttrName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:04:16 +04:00
|
|
|
uint16_t
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::AttrChange()
|
2013-09-24 14:04:16 +04:00
|
|
|
{
|
2013-10-18 10:10:22 +04:00
|
|
|
return mEvent->AsMutationEvent()->mAttrChange;
|
2013-09-24 14:04:16 +04:00
|
|
|
}
|
|
|
|
|
2000-11-27 10:55:20 +03:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04:00
|
|
|
MutationEvent::GetAttrChange(uint16_t* aAttrChange)
|
2000-11-27 10:55:20 +03:00
|
|
|
{
|
2013-03-15 01:18:20 +04:00
|
|
|
*aAttrChange = AttrChange();
|
2000-11-27 10:55:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:16 +04: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 10:55:20 +03:00
|
|
|
{
|
2014-03-05 04:37:43 +04:00
|
|
|
nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-10-18 10:10:22 +04:00
|
|
|
|
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2004-08-20 22:09:19 +04: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 10:55:20 +03:00
|
|
|
}
|
2004-08-20 22:09:19 +04:00
|
|
|
mutation->mAttrChange = aAttrChangeArg;
|
2000-11-27 10:55:20 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2003-09-08 01:50:21 +04:00
|
|
|
}
|
2000-11-27 10:55:20 +03:00
|
|
|
|
2014-02-27 14:51:16 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2002-12-11 17:24:49 +03:00
|
|
|
|
2014-02-27 14:51:16 +04: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-18 00:00:11 +04:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|