2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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,
|
2015-08-29 02:58:26 +03:00
|
|
|
aEvent ? aEvent : new InternalMutationEvent(false, eVoidEvent))
|
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
|
|
|
{
|
2016-10-30 22:30:06 +03:00
|
|
|
NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK);
|
|
|
|
|
2015-11-13 03:09:42 +03:00
|
|
|
Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
|
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())
|
2016-03-29 02:09:43 +03:00
|
|
|
mutation->mPrevAttrValue = NS_Atomize(aPrevValueArg);
|
2004-08-20 22:09:19 +04:00
|
|
|
if (!aNewValueArg.IsEmpty())
|
2016-03-29 02:09:43 +03:00
|
|
|
mutation->mNewAttrValue = NS_Atomize(aNewValueArg);
|
2004-08-20 22:09:19 +04:00
|
|
|
if (!aAttrNameArg.IsEmpty()) {
|
2016-03-29 02:09:43 +03:00
|
|
|
mutation->mAttrName = NS_Atomize(aAttrNameArg);
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|
2004-08-20 22:09:19 +04:00
|
|
|
mutation->mAttrChange = aAttrChangeArg;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<MutationEvent>
|
|
|
|
NS_NewDOMMutationEvent(EventTarget* aOwner,
|
2014-02-27 14:51:16 +04:00
|
|
|
nsPresContext* aPresContext,
|
2017-07-06 15:00:35 +03:00
|
|
|
InternalMutationEvent* aEvent)
|
2014-02-27 14:51:16 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MutationEvent> it = new MutationEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|