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)) {
|
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
|
|
|
nsINode* MutationEvent::GetRelatedNode() {
|
2018-05-30 05:58:49 +03:00
|
|
|
return mEvent->AsMutationEvent()->mRelatedNode;
|
2013-09-24 14:04:16 +04:00
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:10 +03:00
|
|
|
void MutationEvent::GetPrevValue(nsAString& aPrevValue) const {
|
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
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:10 +03:00
|
|
|
void MutationEvent::GetNewValue(nsAString& aNewValue) const {
|
2013-10-18 10:10:22 +04:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2000-11-27 10:55:20 +03:00
|
|
|
if (mutation->mNewAttrValue) mutation->mNewAttrValue->ToString(aNewValue);
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:10 +03:00
|
|
|
void MutationEvent::GetAttrName(nsAString& aAttrName) const {
|
2013-10-18 10:10:22 +04:00
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2000-11-27 10:55:20 +03:00
|
|
|
if (mutation->mAttrName) mutation->mAttrName->ToString(aAttrName);
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:16 +04:00
|
|
|
uint16_t MutationEvent::AttrChange() {
|
2013-10-18 10:10:22 +04:00
|
|
|
return mEvent->AsMutationEvent()->mAttrChange;
|
2013-09-24 14:04:16 +04:00
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:10 +03:00
|
|
|
void MutationEvent::InitMutationEvent(const nsAString& aType, bool aCanBubble,
|
|
|
|
bool aCancelable, nsINode* aRelatedNode,
|
|
|
|
const nsAString& aPrevValue,
|
|
|
|
const nsAString& aNewValue,
|
|
|
|
const nsAString& aAttrName,
|
|
|
|
uint16_t& aAttrChange, ErrorResult& aRv) {
|
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
2000-11-27 10:55:20 +03:00
|
|
|
|
2018-02-09 19:17:10 +03:00
|
|
|
Event::InitEvent(aType, aCanBubble, aCancelable);
|
2013-10-18 10:10:22 +04:00
|
|
|
|
|
|
|
InternalMutationEvent* mutation = mEvent->AsMutationEvent();
|
2018-05-30 05:58:49 +03:00
|
|
|
mutation->mRelatedNode = aRelatedNode;
|
2018-02-09 19:17:10 +03:00
|
|
|
if (!aPrevValue.IsEmpty()) mutation->mPrevAttrValue = NS_Atomize(aPrevValue);
|
|
|
|
if (!aNewValue.IsEmpty()) mutation->mNewAttrValue = NS_Atomize(aNewValue);
|
|
|
|
if (!aAttrName.IsEmpty()) {
|
|
|
|
mutation->mAttrName = NS_Atomize(aAttrName);
|
2000-11-27 10:55:20 +03:00
|
|
|
}
|
2018-02-09 19:17:10 +03:00
|
|
|
mutation->mAttrChange = aAttrChange;
|
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(
|
2014-02-27 14:51:16 +04:00
|
|
|
EventTarget* aOwner, nsPresContext* aPresContext,
|
2017-07-06 15:00:35 +03:00
|
|
|
InternalMutationEvent* aEvent) {
|
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
|
|
|
}
|