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-03-31 20:30:13 +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/. */
|
|
|
|
|
2013-09-10 11:03:37 +04:00
|
|
|
#include "nsDOMMutationObserver.h"
|
|
|
|
|
2016-05-18 14:49:32 +03:00
|
|
|
#include "mozilla/AnimationTarget.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2015-08-05 15:28:27 +03:00
|
|
|
#include "mozilla/OwningNonNull.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/Animation.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffectReadOnly.h"
|
2017-12-19 18:14:55 +03:00
|
|
|
#include "mozilla/dom/DocGroup.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
#include "nsContentUtils.h"
|
2016-05-18 14:49:32 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2012-03-31 20:30:13 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2015-08-06 15:45:21 +03:00
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2017-10-26 12:40:12 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-09-29 07:31:56 +03:00
|
|
|
using mozilla::dom::TreeOrderComparator;
|
2015-07-01 16:56:00 +03:00
|
|
|
using mozilla::dom::Animation;
|
2016-05-18 14:49:32 +03:00
|
|
|
using mozilla::dom::Element;
|
2015-07-01 16:56:00 +03:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<nsDOMMutationObserver>, 4>*
|
2012-07-30 18:20:58 +04:00
|
|
|
nsDOMMutationObserver::sScheduledMutationObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsDOMMutationObserver::sMutationLevel = 0;
|
|
|
|
uint64_t nsDOMMutationObserver::sCount = 0;
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<AutoTArray<RefPtr<nsDOMMutationObserver>, 4>, 4>*
|
2012-07-30 18:20:58 +04:00
|
|
|
nsDOMMutationObserver::sCurrentlyHandlingObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
nsINodeList*
|
|
|
|
nsDOMMutationRecord::AddedNodes()
|
|
|
|
{
|
|
|
|
if (!mAddedNodes) {
|
|
|
|
mAddedNodes = new nsSimpleContentList(mTarget);
|
|
|
|
}
|
|
|
|
return mAddedNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINodeList*
|
|
|
|
nsDOMMutationRecord::RemovedNodes()
|
|
|
|
{
|
|
|
|
if (!mRemovedNodes) {
|
|
|
|
mRemovedNodes = new nsSimpleContentList(mTarget);
|
|
|
|
}
|
|
|
|
return mRemovedNodes;
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMMutationRecord)
|
2012-12-18 18:50:52 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMMutationRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMMutationRecord)
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMMutationRecord,
|
|
|
|
mTarget,
|
|
|
|
mPreviousSibling, mNextSibling,
|
|
|
|
mAddedNodes, mRemovedNodes,
|
2015-03-14 08:34:40 +03:00
|
|
|
mAddedAnimations, mRemovedAnimations,
|
|
|
|
mChangedAnimations,
|
2014-04-29 12:57:00 +04:00
|
|
|
mNext, mOwner)
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
// Observer
|
|
|
|
|
2015-04-22 03:58:29 +03:00
|
|
|
bool
|
|
|
|
nsMutationReceiverBase::IsObservable(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
return !aContent->ChromeOnlyAccess() &&
|
|
|
|
(Observer()->IsChrome() || !aContent->IsInAnonymousSubtree());
|
|
|
|
}
|
|
|
|
|
2012-07-10 00:44:33 +04:00
|
|
|
NS_IMPL_ADDREF(nsMutationReceiver)
|
|
|
|
NS_IMPL_RELEASE(nsMutationReceiver)
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2012-07-10 00:44:33 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMutationReceiver)
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
nsMutationReceiver::nsMutationReceiver(nsINode* aTarget,
|
|
|
|
nsDOMMutationObserver* aObserver)
|
|
|
|
: nsMutationReceiverBase(aTarget, aObserver)
|
|
|
|
{
|
|
|
|
mTarget->BindObject(aObserver);
|
|
|
|
}
|
|
|
|
|
2012-04-04 21:36:40 +04:00
|
|
|
void
|
|
|
|
nsMutationReceiver::Disconnect(bool aRemoveFromObserver)
|
|
|
|
{
|
|
|
|
if (mRegisterTarget) {
|
|
|
|
mRegisterTarget->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mRegisterTarget = nullptr;
|
2012-04-04 21:36:40 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2012-04-04 21:36:40 +04:00
|
|
|
nsINode* target = mTarget;
|
2012-07-30 18:20:58 +04:00
|
|
|
mTarget = nullptr;
|
2012-12-18 18:50:52 +04:00
|
|
|
nsDOMMutationObserver* observer = mObserver;
|
2012-07-30 18:20:58 +04:00
|
|
|
mObserver = nullptr;
|
2012-04-04 21:36:40 +04:00
|
|
|
RemoveClones();
|
|
|
|
|
|
|
|
if (target && observer) {
|
|
|
|
if (aRemoveFromObserver) {
|
|
|
|
static_cast<nsDOMMutationObserver*>(observer)->RemoveReceiver(this);
|
|
|
|
}
|
|
|
|
// UnbindObject may delete 'this'!
|
|
|
|
target->UnbindObject(observer);
|
|
|
|
}
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::NativeAnonymousChildListChange(nsIContent* aContent,
|
2015-09-24 18:23:32 +03:00
|
|
|
bool aIsRemove) {
|
|
|
|
if (!NativeAnonymousChildList()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode* parent = aContent->GetParentNode();
|
|
|
|
if (!parent ||
|
|
|
|
(!Subtree() && Target() != parent) ||
|
|
|
|
(Subtree() && RegisterTarget()->SubtreeRoot() != parent->SubtreeRoot())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord* m =
|
|
|
|
Observer()->CurrentRecord(nsGkAtoms::nativeAnonymousChildList);
|
|
|
|
|
|
|
|
if (m->mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m->mTarget = parent;
|
|
|
|
|
|
|
|
if (aIsRemove) {
|
|
|
|
m->mRemovedNodes = new nsSimpleContentList(parent);
|
|
|
|
m->mRemovedNodes->AppendElement(aContent);
|
|
|
|
} else {
|
|
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
|
|
m->mAddedNodes->AppendElement(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::AttributeWillChange(mozilla::dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2015-07-25 09:05:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
|
|
|
if (nsAutoMutationBatch::IsBatching() ||
|
2015-04-22 03:58:29 +03:00
|
|
|
!ObservesAttr(RegisterTarget(), aElement, aNameSpaceID, aAttribute)) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord* m =
|
2014-02-26 04:45:08 +04:00
|
|
|
Observer()->CurrentRecord(nsGkAtoms::attributes);
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == aElement,
|
|
|
|
"Wrong target!");
|
2014-02-26 04:45:08 +04:00
|
|
|
NS_ASSERTION(!m->mAttrName || m->mAttrName == aAttribute,
|
2012-03-31 20:30:13 +04:00
|
|
|
"Wrong attribute!");
|
|
|
|
if (!m->mTarget) {
|
|
|
|
m->mTarget = aElement;
|
2014-02-26 04:45:08 +04:00
|
|
|
m->mAttrName = aAttribute;
|
2012-03-31 20:30:13 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
m->mAttrNamespace.SetIsVoid(true);
|
|
|
|
} else {
|
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID,
|
|
|
|
m->mAttrNamespace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AttributeOldValue() && m->mPrevValue.IsVoid()) {
|
|
|
|
if (!aElement->GetAttr(aNameSpaceID, aAttribute, m->mPrevValue)) {
|
|
|
|
m->mPrevValue.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::CharacterDataWillChange(nsIContent* aContent,
|
2018-02-27 17:30:27 +03:00
|
|
|
const CharacterDataChangeInfo&)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
|
|
|
if (nsAutoMutationBatch::IsBatching() ||
|
2015-04-22 03:58:29 +03:00
|
|
|
!CharacterData() ||
|
|
|
|
(!Subtree() && aContent != Target()) ||
|
|
|
|
(Subtree() && RegisterTarget()->SubtreeRoot() != aContent->SubtreeRoot()) ||
|
|
|
|
!IsObservable(aContent)) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-04-22 03:58:29 +03:00
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
nsDOMMutationRecord* m =
|
2014-02-26 04:45:08 +04:00
|
|
|
Observer()->CurrentRecord(nsGkAtoms::characterData);
|
2015-04-22 03:58:29 +03:00
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == aContent,
|
|
|
|
"Wrong target!");
|
|
|
|
|
|
|
|
if (!m->mTarget) {
|
|
|
|
m->mTarget = aContent;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
if (CharacterDataOldValue() && m->mPrevValue.IsVoid()) {
|
2012-03-31 20:30:13 +04:00
|
|
|
aContent->GetText()->AppendTo(m->mPrevValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::ContentAppended(nsIContent* aFirstNewContent)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2018-03-01 14:36:58 +03:00
|
|
|
nsINode* parent = aFirstNewContent->GetParentNode();
|
2015-04-22 03:58:29 +03:00
|
|
|
bool wantsChildList =
|
|
|
|
ChildList() &&
|
|
|
|
((Subtree() && RegisterTarget()->SubtreeRoot() == parent->SubtreeRoot()) ||
|
|
|
|
parent == Target());
|
|
|
|
if (!wantsChildList || !IsObservable(aFirstNewContent)) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
|
|
if (parent == nsAutoMutationBatch::GetBatchTarget()) {
|
|
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord* m =
|
2014-02-26 04:45:08 +04:00
|
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_ASSERTION(!m->mTarget || m->mTarget == parent,
|
|
|
|
"Wrong target!");
|
|
|
|
if (m->mTarget) {
|
|
|
|
// Already handled case.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m->mTarget = parent;
|
|
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
|
|
|
|
|
|
nsINode* n = aFirstNewContent;
|
|
|
|
while (n) {
|
|
|
|
m->mAddedNodes->AppendElement(static_cast<nsIContent*>(n));
|
|
|
|
n = n->GetNextSibling();
|
|
|
|
}
|
|
|
|
m->mPreviousSibling = aFirstNewContent->GetPreviousSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::ContentInserted(nsIContent* aChild)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2018-03-01 14:36:58 +03:00
|
|
|
nsINode* parent = aChild->GetParentNode();
|
2015-04-22 03:58:29 +03:00
|
|
|
bool wantsChildList =
|
|
|
|
ChildList() &&
|
|
|
|
((Subtree() && RegisterTarget()->SubtreeRoot() == parent->SubtreeRoot()) ||
|
|
|
|
parent == Target());
|
|
|
|
if (!wantsChildList || !IsObservable(aChild)) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
|
|
if (parent == nsAutoMutationBatch::GetBatchTarget()) {
|
|
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord* m =
|
2014-02-26 04:45:08 +04:00
|
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
2012-03-31 20:30:13 +04:00
|
|
|
if (m->mTarget) {
|
|
|
|
// Already handled case.
|
2017-07-06 15:00:35 +03:00
|
|
|
return;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
m->mTarget = parent;
|
|
|
|
m->mAddedNodes = new nsSimpleContentList(parent);
|
|
|
|
m->mAddedNodes->AppendElement(aChild);
|
|
|
|
m->mPreviousSibling = aChild->GetPreviousSibling();
|
|
|
|
m->mNextSibling = aChild->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-01 14:36:58 +03:00
|
|
|
nsMutationReceiver::ContentRemoved(nsIContent* aChild,
|
2012-03-31 20:30:13 +04:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
2015-04-22 03:58:29 +03:00
|
|
|
if (!IsObservable(aChild)) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
nsINode* parent = aChild->GetParentNode();
|
2015-04-22 03:58:29 +03:00
|
|
|
if (Subtree() && parent->SubtreeRoot() != RegisterTarget()->SubtreeRoot()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
if (nsAutoMutationBatch::IsBatching()) {
|
|
|
|
if (nsAutoMutationBatch::IsRemovalDone()) {
|
|
|
|
// This can happen for example if HTML parser parses to
|
|
|
|
// context node, but needs to move elements around.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nsAutoMutationBatch::GetBatchTarget() != parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wantsChildList = ChildList() && (Subtree() || parent == Target());
|
|
|
|
if (wantsChildList || Subtree()) {
|
|
|
|
nsAutoMutationBatch::NodeRemoved(aChild);
|
|
|
|
nsAutoMutationBatch::UpdateObserver(Observer(), wantsChildList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2015-04-22 03:58:29 +03:00
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
if (Subtree()) {
|
|
|
|
// Try to avoid creating transient observer if the node
|
|
|
|
// already has an observer observing the same set of nodes.
|
|
|
|
nsMutationReceiver* orig = GetParent() ? GetParent() : this;
|
2015-03-14 08:34:40 +03:00
|
|
|
if (Observer()->GetReceiverFor(aChild, false, false) != orig) {
|
2012-03-31 20:30:13 +04:00
|
|
|
bool transientExists = false;
|
2017-06-14 17:11:21 +03:00
|
|
|
bool isNewEntry = false;
|
|
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers =
|
|
|
|
Observer()->mTransientReceivers.LookupForAdd(aChild).OrInsert(
|
|
|
|
[&isNewEntry] () {
|
|
|
|
isNewEntry = true;
|
|
|
|
return new nsCOMArray<nsMutationReceiver>();
|
|
|
|
});
|
|
|
|
if (!isNewEntry) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < transientReceivers->Count(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
nsMutationReceiver* r = transientReceivers->ObjectAt(i);
|
|
|
|
if (r->GetParent() == orig) {
|
|
|
|
transientExists = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!transientExists) {
|
|
|
|
// Make sure the elements which are removed from the
|
|
|
|
// subtree are kept in the same observation set.
|
2015-03-14 08:34:40 +03:00
|
|
|
nsMutationReceiver* tr;
|
|
|
|
if (orig->Animations()) {
|
|
|
|
tr = nsAnimationReceiver::Create(aChild, orig);
|
|
|
|
} else {
|
|
|
|
tr = nsMutationReceiver::Create(aChild, orig);
|
|
|
|
}
|
|
|
|
transientReceivers->AppendObject(tr);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ChildList() && (Subtree() || parent == Target())) {
|
|
|
|
nsDOMMutationRecord* m =
|
2014-02-26 04:45:08 +04:00
|
|
|
Observer()->CurrentRecord(nsGkAtoms::childList);
|
2012-03-31 20:30:13 +04:00
|
|
|
if (m->mTarget) {
|
|
|
|
// Already handled case.
|
|
|
|
return;
|
|
|
|
}
|
2017-07-27 16:49:52 +03:00
|
|
|
MOZ_ASSERT(parent);
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
m->mTarget = parent;
|
|
|
|
m->mRemovedNodes = new nsSimpleContentList(parent);
|
|
|
|
m->mRemovedNodes->AppendElement(aChild);
|
|
|
|
m->mPreviousSibling = aPreviousSibling;
|
2017-07-27 16:49:52 +03:00
|
|
|
m->mNextSibling = aPreviousSibling ?
|
|
|
|
aPreviousSibling->GetNextSibling() : parent->GetFirstChild();
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
// We need to schedule always, so that after microtask mTransientReceivers
|
|
|
|
// can be cleared correctly.
|
|
|
|
Observer()->ScheduleForRun();
|
|
|
|
}
|
|
|
|
|
2012-04-06 13:12:59 +04:00
|
|
|
void nsMutationReceiver::NodeWillBeDestroyed(const nsINode *aNode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have mParent here!");
|
|
|
|
Disconnect(true);
|
|
|
|
}
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
nsAnimationReceiver::RecordAnimationMutation(Animation* aAnimation,
|
2015-03-14 08:34:40 +03:00
|
|
|
AnimationMutation aMutationType)
|
|
|
|
{
|
2016-07-25 11:56:34 +03:00
|
|
|
mozilla::dom::AnimationEffectReadOnly* effect = aAnimation->GetEffect();
|
2015-04-15 02:48:21 +03:00
|
|
|
if (!effect) {
|
2015-03-14 08:34:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-25 11:56:34 +03:00
|
|
|
mozilla::dom::KeyframeEffectReadOnly* keyframeEffect =
|
|
|
|
effect->AsKeyframeEffect();
|
|
|
|
if (!keyframeEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<NonOwningAnimationTarget> animationTarget = keyframeEffect->GetTarget();
|
2015-03-14 08:34:40 +03:00
|
|
|
if (!animationTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-18 14:49:32 +03:00
|
|
|
Element* elem = animationTarget->mElement;
|
2016-03-21 11:49:50 +03:00
|
|
|
if (!Animations() || !(Subtree() || elem == Target()) ||
|
|
|
|
elem->ChromeOnlyAccess()) {
|
2015-03-14 08:34:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
// Record animations targeting to a pseudo element only when subtree is true.
|
2016-05-18 14:49:32 +03:00
|
|
|
if (animationTarget->mPseudoType != mozilla::CSSPseudoElementType::NotPseudo &&
|
2016-03-21 11:49:50 +03:00
|
|
|
!Subtree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
if (nsAutoAnimationMutationBatch::IsBatching()) {
|
|
|
|
switch (aMutationType) {
|
|
|
|
case eAnimationMutation_Added:
|
2016-03-21 11:49:50 +03:00
|
|
|
nsAutoAnimationMutationBatch::AnimationAdded(aAnimation, elem);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
case eAnimationMutation_Changed:
|
2016-03-21 11:49:50 +03:00
|
|
|
nsAutoAnimationMutationBatch::AnimationChanged(aAnimation, elem);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
case eAnimationMutation_Removed:
|
2016-03-21 11:49:50 +03:00
|
|
|
nsAutoAnimationMutationBatch::AnimationRemoved(aAnimation, elem);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch::AddObserver(Observer());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord* m =
|
|
|
|
Observer()->CurrentRecord(nsGkAtoms::animations);
|
|
|
|
|
|
|
|
NS_ASSERTION(!m->mTarget, "Wrong target!");
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
m->mTarget = elem;
|
2015-03-14 08:34:40 +03:00
|
|
|
|
|
|
|
switch (aMutationType) {
|
|
|
|
case eAnimationMutation_Added:
|
2015-04-21 04:22:10 +03:00
|
|
|
m->mAddedAnimations.AppendElement(aAnimation);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
case eAnimationMutation_Changed:
|
2015-04-21 04:22:10 +03:00
|
|
|
m->mChangedAnimations.AppendElement(aAnimation);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
case eAnimationMutation_Removed:
|
2015-04-21 04:22:10 +03:00
|
|
|
m->mRemovedAnimations.AppendElement(aAnimation);
|
2015-03-14 08:34:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
nsAnimationReceiver::AnimationAdded(Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Added);
|
2015-03-14 08:34:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
nsAnimationReceiver::AnimationChanged(Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Changed);
|
2015-03-14 08:34:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
nsAnimationReceiver::AnimationRemoved(Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
RecordAnimationMutation(aAnimation, eAnimationMutation_Removed);
|
2015-03-14 08:34:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsAnimationReceiver, nsMutationReceiver,
|
|
|
|
nsIAnimationObserver)
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
// Observer
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMMutationObserver)
|
2012-08-28 19:25:19 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-12-18 18:50:52 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2013-09-11 23:43:01 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsDOMMutationObserver)
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMMutationObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMMutationObserver)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMMutationObserver)
|
|
|
|
|
2012-08-28 19:25:19 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMMutationObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMMutationObserver)
|
2012-08-28 19:25:19 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < tmp->mReceivers.Count(); ++i) {
|
2012-04-04 21:36:40 +04:00
|
|
|
tmp->mReceivers[i]->Disconnect(false);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
tmp->mReceivers.Clear();
|
2014-02-26 04:40:51 +04:00
|
|
|
tmp->ClearPendingRecords();
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
|
2012-03-31 20:30:13 +04:00
|
|
|
// No need to handle mTransientReceivers
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMMutationObserver)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReceivers)
|
2014-02-26 04:40:51 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFirstPendingMutation)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallback)
|
2012-03-31 20:30:13 +04:00
|
|
|
// No need to handle mTransientReceivers
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
nsMutationReceiver*
|
2015-03-14 08:34:40 +03:00
|
|
|
nsDOMMutationObserver::GetReceiverFor(nsINode* aNode, bool aMayCreate,
|
|
|
|
bool aWantsAnimations)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2015-03-14 08:34:40 +03:00
|
|
|
MOZ_ASSERT(aMayCreate || !aWantsAnimations,
|
|
|
|
"the value of aWantsAnimations doesn't matter when aMayCreate is "
|
|
|
|
"false, so just pass in false for it");
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
if (!aMayCreate && !aNode->MayHaveDOMMutationObserver()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
if (mReceivers[i]->Target() == aNode) {
|
|
|
|
return mReceivers[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aMayCreate) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
nsMutationReceiver* r;
|
|
|
|
if (aWantsAnimations) {
|
|
|
|
r = nsAnimationReceiver::Create(aNode, this);
|
|
|
|
} else {
|
|
|
|
r = nsMutationReceiver::Create(aNode, this);
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
mReceivers.AppendObject(r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-04-04 21:36:40 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::RemoveReceiver(nsMutationReceiver* aReceiver)
|
|
|
|
{
|
|
|
|
mReceivers.RemoveObject(aReceiver);
|
|
|
|
}
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::GetAllSubtreeObserversFor(nsINode* aNode,
|
|
|
|
nsTArray<nsMutationReceiver*>&
|
|
|
|
aReceivers)
|
|
|
|
{
|
|
|
|
nsINode* n = aNode;
|
|
|
|
while (n) {
|
|
|
|
if (n->MayHaveDOMMutationObserver()) {
|
2015-03-14 08:34:40 +03:00
|
|
|
nsMutationReceiver* r = GetReceiverFor(n, false, false);
|
2012-03-31 20:30:13 +04:00
|
|
|
if (r && r->Subtree() && !aReceivers.Contains(r)) {
|
|
|
|
aReceivers.AppendElement(r);
|
|
|
|
// If we've found all the receivers the observer has,
|
|
|
|
// no need to search for more.
|
2012-08-22 19:56:38 +04:00
|
|
|
if (mReceivers.Count() == int32_t(aReceivers.Length())) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
if (mTransientReceivers.Get(n, &transientReceivers) && transientReceivers) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < transientReceivers->Count(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
nsMutationReceiver* r = transientReceivers->ObjectAt(i);
|
|
|
|
nsMutationReceiver* parent = r->GetParent();
|
|
|
|
if (r->Subtree() && parent && !aReceivers.Contains(parent)) {
|
|
|
|
aReceivers.AppendElement(parent);
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
if (mReceivers.Count() == int32_t(aReceivers.Length())) {
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-09 16:31:24 +04:00
|
|
|
n = n->GetParentNode();
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMMutationObserver::ScheduleForRun()
|
|
|
|
{
|
2015-10-30 20:18:19 +03:00
|
|
|
nsDOMMutationObserver::AddCurrentlyHandlingObserver(this, sMutationLevel);
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
if (mWaitingForRun) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mWaitingForRun = true;
|
|
|
|
RescheduleForRun();
|
|
|
|
}
|
|
|
|
|
2017-10-11 15:31:38 +03:00
|
|
|
class MutationObserverMicroTask final : public MicroTaskRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Run(AutoSlowOperation& aAso) override
|
|
|
|
{
|
|
|
|
nsDOMMutationObserver::HandleMutations(aAso);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Suppressed() override
|
|
|
|
{
|
|
|
|
return nsDOMMutationObserver::AllScheduledMutationObserversAreSuppressed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-19 18:14:55 +03:00
|
|
|
/* static */ void
|
|
|
|
nsDOMMutationObserver::QueueMutationObserverMicroTask()
|
|
|
|
{
|
|
|
|
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
|
|
|
|
if (!ccjs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MutationObserverMicroTask> momt =
|
|
|
|
new MutationObserverMicroTask();
|
2018-03-01 17:29:02 +03:00
|
|
|
ccjs->DispatchMicroTaskRunnable(momt.forget());
|
2017-12-19 18:14:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMMutationObserver::HandleMutations(mozilla::AutoSlowOperation& aAso)
|
|
|
|
{
|
|
|
|
if (sScheduledMutationObservers ||
|
|
|
|
mozilla::dom::DocGroup::sPendingDocGroups) {
|
|
|
|
HandleMutationsInternal(aAso);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::RescheduleForRun()
|
|
|
|
{
|
|
|
|
if (!sScheduledMutationObservers) {
|
2017-10-11 15:31:38 +03:00
|
|
|
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
|
|
|
|
if (!ccjs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MutationObserverMicroTask> momt =
|
|
|
|
new MutationObserverMicroTask();
|
2018-03-01 17:29:02 +03:00
|
|
|
ccjs->DispatchMicroTaskRunnable(momt.forget());
|
2016-02-02 18:36:30 +03:00
|
|
|
sScheduledMutationObservers = new AutoTArray<RefPtr<nsDOMMutationObserver>, 4>;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool didInsert = false;
|
2012-12-18 18:50:52 +04:00
|
|
|
for (uint32_t i = 0; i < sScheduledMutationObservers->Length(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
if (static_cast<nsDOMMutationObserver*>((*sScheduledMutationObservers)[i])
|
|
|
|
->mId > mId) {
|
2012-12-18 18:50:52 +04:00
|
|
|
sScheduledMutationObservers->InsertElementAt(i, this);
|
2012-03-31 20:30:13 +04:00
|
|
|
didInsert = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!didInsert) {
|
2012-12-18 18:50:52 +04:00
|
|
|
sScheduledMutationObservers->AppendElement(this);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::Observe(nsINode& aTarget,
|
|
|
|
const mozilla::dom::MutationObserverInit& aOptions,
|
|
|
|
mozilla::ErrorResult& aRv)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
|
|
|
|
2014-10-23 15:11:40 +04:00
|
|
|
bool childList = aOptions.mChildList;
|
|
|
|
bool attributes =
|
|
|
|
aOptions.mAttributes.WasPassed() &&
|
|
|
|
aOptions.mAttributes.Value();
|
|
|
|
bool characterData =
|
|
|
|
aOptions.mCharacterData.WasPassed() &&
|
|
|
|
aOptions.mCharacterData.Value();
|
|
|
|
bool subtree = aOptions.mSubtree;
|
|
|
|
bool attributeOldValue =
|
|
|
|
aOptions.mAttributeOldValue.WasPassed() &&
|
|
|
|
aOptions.mAttributeOldValue.Value();
|
2016-06-02 22:55:30 +03:00
|
|
|
bool nativeAnonymousChildList = aOptions.mNativeAnonymousChildList;
|
2014-10-23 15:11:40 +04:00
|
|
|
bool characterDataOldValue =
|
|
|
|
aOptions.mCharacterDataOldValue.WasPassed() &&
|
|
|
|
aOptions.mCharacterDataOldValue.Value();
|
2016-06-02 22:55:30 +03:00
|
|
|
bool animations = aOptions.mAnimations;
|
2014-10-23 15:11:40 +04:00
|
|
|
|
|
|
|
if (!aOptions.mAttributes.WasPassed() &&
|
|
|
|
(aOptions.mAttributeOldValue.WasPassed() ||
|
|
|
|
aOptions.mAttributeFilter.WasPassed())) {
|
|
|
|
attributes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aOptions.mCharacterData.WasPassed() &&
|
|
|
|
aOptions.mCharacterDataOldValue.WasPassed()) {
|
|
|
|
characterData = true;
|
|
|
|
}
|
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
if (!(childList || attributes || characterData || animations ||
|
|
|
|
nativeAnonymousChildList)) {
|
2014-10-23 15:11:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
2012-12-18 18:50:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-10-23 15:11:40 +04:00
|
|
|
|
|
|
|
if (aOptions.mAttributeOldValue.WasPassed() &&
|
|
|
|
aOptions.mAttributeOldValue.Value() &&
|
|
|
|
aOptions.mAttributes.WasPassed() &&
|
|
|
|
!aOptions.mAttributes.Value()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.mAttributeFilter.WasPassed() &&
|
|
|
|
aOptions.mAttributes.WasPassed() &&
|
|
|
|
!aOptions.mAttributes.Value()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
2012-12-18 18:50:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-10-23 15:11:40 +04:00
|
|
|
|
|
|
|
if (aOptions.mCharacterDataOldValue.WasPassed() &&
|
|
|
|
aOptions.mCharacterDataOldValue.Value() &&
|
|
|
|
aOptions.mCharacterData.WasPassed() &&
|
|
|
|
!aOptions.mCharacterData.Value()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
2012-12-18 18:50:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> filters;
|
2012-03-31 20:30:13 +04:00
|
|
|
bool allAttrs = true;
|
2012-12-18 20:56:45 +04:00
|
|
|
if (aOptions.mAttributeFilter.WasPassed()) {
|
2012-03-31 20:30:13 +04:00
|
|
|
allAttrs = false;
|
2012-12-18 18:50:52 +04:00
|
|
|
const mozilla::dom::Sequence<nsString>& filtersAsString =
|
2012-12-18 20:56:45 +04:00
|
|
|
aOptions.mAttributeFilter.Value();
|
2012-12-18 18:50:52 +04:00
|
|
|
uint32_t len = filtersAsString.Length();
|
2013-04-01 00:06:18 +04:00
|
|
|
filters.SetCapacity(len);
|
2012-12-18 18:50:52 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2016-06-07 11:10:25 +03:00
|
|
|
filters.AppendElement(NS_Atomize(filtersAsString[i]));
|
2012-12-18 18:50:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
nsMutationReceiver* r = GetReceiverFor(&aTarget, true, animations);
|
2014-10-23 15:11:40 +04:00
|
|
|
r->SetChildList(childList);
|
|
|
|
r->SetAttributes(attributes);
|
|
|
|
r->SetCharacterData(characterData);
|
|
|
|
r->SetSubtree(subtree);
|
|
|
|
r->SetAttributeOldValue(attributeOldValue);
|
|
|
|
r->SetCharacterDataOldValue(characterDataOldValue);
|
2015-09-24 18:23:32 +03:00
|
|
|
r->SetNativeAnonymousChildList(nativeAnonymousChildList);
|
2016-06-07 11:10:25 +03:00
|
|
|
r->SetAttributeFilter(Move(filters));
|
2012-03-31 20:30:13 +04:00
|
|
|
r->SetAllAttributes(allAttrs);
|
2015-03-14 08:34:40 +03:00
|
|
|
r->SetAnimations(animations);
|
2012-03-31 20:30:13 +04:00
|
|
|
r->RemoveClones();
|
2012-04-04 21:36:40 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(mReceivers[i]->Target(),
|
|
|
|
"All the receivers should have a target!");
|
2012-04-04 21:36:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
void
|
2012-03-31 20:30:13 +04:00
|
|
|
nsDOMMutationObserver::Disconnect()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2012-04-04 21:36:40 +04:00
|
|
|
mReceivers[i]->Disconnect(false);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
mReceivers.Clear();
|
|
|
|
mCurrentMutations.Clear();
|
2014-02-26 04:40:51 +04:00
|
|
|
ClearPendingRecords();
|
2012-04-11 09:24:18 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::TakeRecords(
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsDOMMutationRecord> >& aRetVal)
|
2012-04-11 09:24:18 +04:00
|
|
|
{
|
2012-12-18 18:50:52 +04:00
|
|
|
aRetVal.Clear();
|
2014-02-26 04:40:51 +04:00
|
|
|
aRetVal.SetCapacity(mPendingMutationCount);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> current;
|
2014-02-26 04:40:51 +04:00
|
|
|
current.swap(mFirstPendingMutation);
|
|
|
|
for (uint32_t i = 0; i < mPendingMutationCount; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> next;
|
2014-02-26 04:40:51 +04:00
|
|
|
current->mNext.swap(next);
|
2015-07-30 00:23:47 +03:00
|
|
|
if (!mMergeAttributeRecords ||
|
|
|
|
!MergeableAttributeRecord(aRetVal.SafeLastElement(nullptr),
|
|
|
|
current)) {
|
|
|
|
*aRetVal.AppendElement() = current.forget();
|
|
|
|
}
|
2014-02-26 04:40:51 +04:00
|
|
|
current.swap(next);
|
|
|
|
}
|
|
|
|
ClearPendingRecords();
|
2012-04-11 09:24:18 +04:00
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2013-09-11 23:43:01 +04:00
|
|
|
void
|
2015-05-25 14:50:15 +03:00
|
|
|
nsDOMMutationObserver::GetObservingInfo(
|
|
|
|
nsTArray<Nullable<MutationObservingInfo>>& aResult,
|
|
|
|
mozilla::ErrorResult& aRv)
|
2013-09-11 23:43:01 +04:00
|
|
|
{
|
|
|
|
aResult.SetCapacity(mReceivers.Count());
|
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2013-10-09 20:05:22 +04:00
|
|
|
MutationObservingInfo& info = aResult.AppendElement()->SetValue();
|
2013-09-11 23:43:01 +04:00
|
|
|
nsMutationReceiver* mr = mReceivers[i];
|
|
|
|
info.mChildList = mr->ChildList();
|
2014-10-23 15:11:40 +04:00
|
|
|
info.mAttributes.Construct(mr->Attributes());
|
|
|
|
info.mCharacterData.Construct(mr->CharacterData());
|
2013-09-11 23:43:01 +04:00
|
|
|
info.mSubtree = mr->Subtree();
|
2014-10-23 15:11:40 +04:00
|
|
|
info.mAttributeOldValue.Construct(mr->AttributeOldValue());
|
|
|
|
info.mCharacterDataOldValue.Construct(mr->CharacterDataOldValue());
|
2015-09-24 18:23:32 +03:00
|
|
|
info.mNativeAnonymousChildList = mr->NativeAnonymousChildList();
|
2016-06-02 22:55:30 +03:00
|
|
|
info.mAnimations = mr->Animations();
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>>& filters = mr->AttributeFilter();
|
2017-09-26 01:33:21 +03:00
|
|
|
if (filters.Length()) {
|
2013-09-11 23:43:01 +04:00
|
|
|
info.mAttributeFilter.Construct();
|
|
|
|
mozilla::dom::Sequence<nsString>& filtersAsStrings =
|
|
|
|
info.mAttributeFilter.Value();
|
2017-09-26 01:33:21 +03:00
|
|
|
nsString* strings = filtersAsStrings.AppendElements(filters.Length(),
|
2015-11-18 20:38:34 +03:00
|
|
|
mozilla::fallible);
|
|
|
|
if (!strings) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-26 01:33:21 +03:00
|
|
|
for (size_t j = 0; j < filters.Length(); ++j) {
|
2015-11-18 20:38:34 +03:00
|
|
|
filters[j]->ToString(strings[j]);
|
2013-09-11 23:43:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
info.mObservedNode = mr->Target();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 18:50:52 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<nsDOMMutationObserver>
|
2012-12-03 20:07:49 +04:00
|
|
|
nsDOMMutationObserver::Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
2012-12-18 18:50:52 +04:00
|
|
|
mozilla::dom::MutationCallback& aCb,
|
|
|
|
mozilla::ErrorResult& aRv)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
|
2012-12-18 18:50:52 +04:00
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
2015-04-22 03:58:29 +03:00
|
|
|
bool isChrome = nsContentUtils::IsChromeDoc(window->GetExtantDoc());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationObserver> observer =
|
2015-04-22 03:58:29 +03:00
|
|
|
new nsDOMMutationObserver(window.forget(), aCb, isChrome);
|
2012-12-18 18:50:52 +04:00
|
|
|
return observer.forget();
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2015-07-30 00:23:47 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsDOMMutationObserver::MergeableAttributeRecord(nsDOMMutationRecord* aOldRecord,
|
|
|
|
nsDOMMutationRecord* aRecord)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMergeAttributeRecords);
|
|
|
|
return
|
|
|
|
aOldRecord &&
|
|
|
|
aOldRecord->mType == nsGkAtoms::attributes &&
|
|
|
|
aOldRecord->mType == aRecord->mType &&
|
|
|
|
aOldRecord->mTarget == aRecord->mTarget &&
|
|
|
|
aOldRecord->mAttrName == aRecord->mAttrName &&
|
|
|
|
aOldRecord->mAttrNamespace.Equals(aRecord->mAttrNamespace);
|
|
|
|
}
|
|
|
|
|
2012-03-31 20:30:13 +04:00
|
|
|
void
|
|
|
|
nsDOMMutationObserver::HandleMutation()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Whaat!");
|
2012-04-03 11:25:38 +04:00
|
|
|
NS_ASSERTION(mCurrentMutations.IsEmpty(),
|
2012-03-31 20:30:13 +04:00
|
|
|
"Still generating MutationRecords?");
|
|
|
|
|
|
|
|
mWaitingForRun = false;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
mReceivers[i]->RemoveClones();
|
|
|
|
}
|
|
|
|
mTransientReceivers.Clear();
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* outer = mOwner->GetOuterWindow();
|
2014-02-26 04:40:51 +04:00
|
|
|
if (!mPendingMutationCount || !outer ||
|
2012-03-31 20:30:13 +04:00
|
|
|
outer->GetCurrentInnerWindow() != mOwner) {
|
2014-02-26 04:40:51 +04:00
|
|
|
ClearPendingRecords();
|
2012-03-31 20:30:13 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-04-11 09:24:18 +04:00
|
|
|
|
2015-08-05 15:28:27 +03:00
|
|
|
mozilla::dom::Sequence<mozilla::OwningNonNull<nsDOMMutationRecord> >
|
2012-12-18 18:50:52 +04:00
|
|
|
mutations;
|
2015-05-18 23:50:34 +03:00
|
|
|
if (mutations.SetCapacity(mPendingMutationCount, mozilla::fallible)) {
|
2014-02-26 04:40:51 +04:00
|
|
|
// We can't use TakeRecords easily here, because it deals with a
|
|
|
|
// different type of array, and we want to optimize out any extra copying.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> current;
|
2014-02-26 04:40:51 +04:00
|
|
|
current.swap(mFirstPendingMutation);
|
|
|
|
for (uint32_t i = 0; i < mPendingMutationCount; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> next;
|
2014-02-26 04:40:51 +04:00
|
|
|
current->mNext.swap(next);
|
2015-07-30 00:23:47 +03:00
|
|
|
if (!mMergeAttributeRecords ||
|
|
|
|
!MergeableAttributeRecord(mutations.Length() ?
|
|
|
|
mutations.LastElement().get() : nullptr,
|
|
|
|
current)) {
|
|
|
|
*mutations.AppendElement(mozilla::fallible) = current;
|
|
|
|
}
|
2014-02-26 04:40:51 +04:00
|
|
|
current.swap(next);
|
|
|
|
}
|
2012-12-18 18:50:52 +04:00
|
|
|
}
|
2014-02-26 04:40:51 +04:00
|
|
|
ClearPendingRecords();
|
|
|
|
|
2015-12-01 06:04:09 +03:00
|
|
|
mCallback->Call(this, mutations, *this);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-10-11 15:31:38 +03:00
|
|
|
nsDOMMutationObserver::HandleMutationsInternal(AutoSlowOperation& aAso)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsDOMMutationObserver> >* suppressedObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
|
2017-12-19 18:14:55 +03:00
|
|
|
// Let signalList be a copy of unit of related similar-origin browsing
|
|
|
|
// contexts' signal slot list.
|
|
|
|
nsTArray<RefPtr<HTMLSlotElement>> signalList;
|
|
|
|
if (DocGroup::sPendingDocGroups) {
|
|
|
|
for (uint32_t i = 0; i < DocGroup::sPendingDocGroups->Length(); ++i) {
|
|
|
|
DocGroup* docGroup = DocGroup::sPendingDocGroups->ElementAt(i);
|
|
|
|
signalList.AppendElements(docGroup->SignalSlotList());
|
|
|
|
|
|
|
|
// Empty unit of related similar-origin browsing contexts' signal slot
|
|
|
|
// list.
|
|
|
|
docGroup->ClearSignalSlotList();
|
|
|
|
}
|
|
|
|
delete DocGroup::sPendingDocGroups;
|
|
|
|
DocGroup::sPendingDocGroups = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-19 18:16:33 +03:00
|
|
|
if (sScheduledMutationObservers) {
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<nsDOMMutationObserver>, 4>* observers =
|
2014-02-26 04:41:47 +04:00
|
|
|
sScheduledMutationObservers;
|
2012-07-30 18:20:58 +04:00
|
|
|
sScheduledMutationObservers = nullptr;
|
2012-12-18 18:50:52 +04:00
|
|
|
for (uint32_t i = 0; i < observers->Length(); ++i) {
|
2017-10-11 15:31:38 +03:00
|
|
|
RefPtr<nsDOMMutationObserver> currentObserver =
|
|
|
|
static_cast<nsDOMMutationObserver*>((*observers)[i]);
|
|
|
|
if (!currentObserver->Suppressed()) {
|
|
|
|
currentObserver->HandleMutation();
|
2012-03-31 20:30:13 +04:00
|
|
|
} else {
|
|
|
|
if (!suppressedObservers) {
|
2015-10-18 08:24:48 +03:00
|
|
|
suppressedObservers = new nsTArray<RefPtr<nsDOMMutationObserver> >;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
2017-10-11 15:31:38 +03:00
|
|
|
if (!suppressedObservers->Contains(currentObserver)) {
|
|
|
|
suppressedObservers->AppendElement(currentObserver);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete observers;
|
2017-10-11 15:31:38 +03:00
|
|
|
aAso.CheckForInterrupt();
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (suppressedObservers) {
|
2012-12-18 18:50:52 +04:00
|
|
|
for (uint32_t i = 0; i < suppressedObservers->Length(); ++i) {
|
|
|
|
static_cast<nsDOMMutationObserver*>(suppressedObservers->ElementAt(i))->
|
2012-03-31 20:30:13 +04:00
|
|
|
RescheduleForRun();
|
|
|
|
}
|
|
|
|
delete suppressedObservers;
|
2012-07-30 18:20:58 +04:00
|
|
|
suppressedObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
2017-12-19 18:14:55 +03:00
|
|
|
|
|
|
|
// Fire slotchange event for each slot in signalList.
|
|
|
|
for (uint32_t i = 0; i < signalList.Length(); ++i) {
|
|
|
|
signalList[i]->FireSlotChangeEvent();
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationRecord*
|
2017-10-03 01:05:19 +03:00
|
|
|
nsDOMMutationObserver::CurrentRecord(nsAtom* aType)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(sMutationLevel > 0, "Unexpected mutation level!");
|
|
|
|
|
|
|
|
while (mCurrentMutations.Length() < sMutationLevel) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentMutations.AppendElement(static_cast<nsDOMMutationRecord*>(nullptr));
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t last = sMutationLevel - 1;
|
2012-03-31 20:30:13 +04:00
|
|
|
if (!mCurrentMutations[last]) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> r = new nsDOMMutationRecord(aType, GetParentObject());
|
2012-03-31 20:30:13 +04:00
|
|
|
mCurrentMutations[last] = r;
|
2014-02-26 04:40:51 +04:00
|
|
|
AppendMutationRecord(r.forget());
|
2012-03-31 20:30:13 +04:00
|
|
|
ScheduleForRun();
|
|
|
|
}
|
|
|
|
|
2015-10-30 20:18:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(sCurrentlyHandlingObservers->Length() == sMutationLevel);
|
|
|
|
for (size_t i = 0; i < sCurrentlyHandlingObservers->Length(); ++i) {
|
|
|
|
MOZ_ASSERT(sCurrentlyHandlingObservers->ElementAt(i).Contains(this),
|
|
|
|
"MutationObserver should be added as an observer of all the "
|
|
|
|
"nested mutations!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-26 04:45:08 +04:00
|
|
|
NS_ASSERTION(mCurrentMutations[last]->mType == aType,
|
2012-03-31 20:30:13 +04:00
|
|
|
"Unexpected MutationRecord type!");
|
|
|
|
|
|
|
|
return mCurrentMutations[last];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMMutationObserver::~nsDOMMutationObserver()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mReceivers.Count(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
mReceivers[i]->RemoveClones();
|
|
|
|
}
|
2012-12-18 18:50:52 +04:00
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMMutationObserver::EnterMutationHandling()
|
|
|
|
{
|
|
|
|
++sMutationLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leave the current mutation level (there can be several levels if in case
|
|
|
|
// of nested calls to the nsIMutationObserver methods).
|
|
|
|
// The most recent mutation record is removed from mCurrentMutations, so
|
|
|
|
// that is doesn't get modified anymore by receivers.
|
|
|
|
void
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling()
|
|
|
|
{
|
|
|
|
if (sCurrentlyHandlingObservers &&
|
|
|
|
sCurrentlyHandlingObservers->Length() == sMutationLevel) {
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsDOMMutationObserver> >& obs =
|
2012-03-31 20:30:13 +04:00
|
|
|
sCurrentlyHandlingObservers->ElementAt(sMutationLevel - 1);
|
2012-12-18 18:50:52 +04:00
|
|
|
for (uint32_t i = 0; i < obs.Length(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
nsDOMMutationObserver* o =
|
|
|
|
static_cast<nsDOMMutationObserver*>(obs[i]);
|
|
|
|
if (o->mCurrentMutations.Length() == sMutationLevel) {
|
|
|
|
// It is already in pending mutations.
|
|
|
|
o->mCurrentMutations.RemoveElementAt(sMutationLevel - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sCurrentlyHandlingObservers->RemoveElementAt(sMutationLevel - 1);
|
|
|
|
}
|
|
|
|
--sMutationLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-30 20:18:19 +03:00
|
|
|
nsDOMMutationObserver::AddCurrentlyHandlingObserver(nsDOMMutationObserver* aObserver,
|
|
|
|
uint32_t aMutationLevel)
|
2012-03-31 20:30:13 +04:00
|
|
|
{
|
2015-10-30 20:18:19 +03:00
|
|
|
NS_ASSERTION(aMutationLevel > 0, "Unexpected mutation level!");
|
|
|
|
|
|
|
|
if (aMutationLevel > 1) {
|
|
|
|
// MutationObserver must be in the currently handling observer list
|
|
|
|
// in all the nested levels.
|
|
|
|
AddCurrentlyHandlingObserver(aObserver, aMutationLevel - 1);
|
|
|
|
}
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
if (!sCurrentlyHandlingObservers) {
|
|
|
|
sCurrentlyHandlingObservers =
|
2016-02-02 18:36:30 +03:00
|
|
|
new AutoTArray<AutoTArray<RefPtr<nsDOMMutationObserver>, 4>, 4>;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
2015-10-30 20:18:19 +03:00
|
|
|
while (sCurrentlyHandlingObservers->Length() < aMutationLevel) {
|
2012-03-31 20:30:13 +04:00
|
|
|
sCurrentlyHandlingObservers->InsertElementAt(
|
|
|
|
sCurrentlyHandlingObservers->Length());
|
|
|
|
}
|
|
|
|
|
2015-10-30 20:18:19 +03:00
|
|
|
uint32_t index = aMutationLevel - 1;
|
|
|
|
if (!sCurrentlyHandlingObservers->ElementAt(index).Contains(aObserver)) {
|
|
|
|
sCurrentlyHandlingObservers->ElementAt(index).AppendElement(aObserver);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMMutationObserver::Shutdown()
|
|
|
|
{
|
|
|
|
delete sCurrentlyHandlingObservers;
|
2012-07-30 18:20:58 +04:00
|
|
|
sCurrentlyHandlingObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
delete sScheduledMutationObservers;
|
2012-07-30 18:20:58 +04:00
|
|
|
sScheduledMutationObservers = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMutationBatch*
|
2012-07-30 18:20:58 +04:00
|
|
|
nsAutoMutationBatch::sCurrentBatch = nullptr;
|
2012-03-31 20:30:13 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsAutoMutationBatch::Done()
|
|
|
|
{
|
|
|
|
if (sCurrentBatch != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sCurrentBatch = mPreviousBatch;
|
|
|
|
if (mObservers.IsEmpty()) {
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mObservers.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
nsDOMMutationObserver* ob = mObservers[i].mObserver;
|
|
|
|
bool wantsChildList = mObservers[i].mWantsChildList;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSimpleContentList> removedList;
|
2012-03-31 20:30:13 +04:00
|
|
|
if (wantsChildList) {
|
|
|
|
removedList = new nsSimpleContentList(mBatchTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsMutationReceiver*> allObservers;
|
|
|
|
ob->GetAllSubtreeObserversFor(mBatchTarget, allObservers);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t j = mFromFirstToLast ? 0 : mRemovedNodes.Length() - 1;
|
|
|
|
int32_t end = mFromFirstToLast ? mRemovedNodes.Length() : -1;
|
2012-03-31 20:30:13 +04:00
|
|
|
for (; j != end; mFromFirstToLast ? ++j : --j) {
|
|
|
|
nsCOMPtr<nsIContent> removed = mRemovedNodes[j];
|
|
|
|
if (removedList) {
|
|
|
|
removedList->AppendElement(removed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allObservers.Length()) {
|
2017-06-14 17:11:21 +03:00
|
|
|
nsCOMArray<nsMutationReceiver>* transientReceivers =
|
|
|
|
ob->mTransientReceivers.LookupForAdd(removed).OrInsert(
|
|
|
|
[] () { return new nsCOMArray<nsMutationReceiver>(); });
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t k = 0; k < allObservers.Length(); ++k) {
|
2012-03-31 20:30:13 +04:00
|
|
|
nsMutationReceiver* r = allObservers[k];
|
|
|
|
nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r;
|
2015-03-14 08:34:40 +03:00
|
|
|
if (ob->GetReceiverFor(removed, false, false) != orig) {
|
2012-03-31 20:30:13 +04:00
|
|
|
// Make sure the elements which are removed from the
|
|
|
|
// subtree are kept in the same observation set.
|
2015-03-14 08:34:40 +03:00
|
|
|
nsMutationReceiver* tr;
|
|
|
|
if (orig->Animations()) {
|
|
|
|
tr = nsAnimationReceiver::Create(removed, orig);
|
|
|
|
} else {
|
|
|
|
tr = nsMutationReceiver::Create(removed, orig);
|
|
|
|
}
|
|
|
|
transientReceivers->AppendObject(tr);
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wantsChildList && (mRemovedNodes.Length() || mAddedNodes.Length())) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSimpleContentList> addedList =
|
2012-03-31 20:30:13 +04:00
|
|
|
new nsSimpleContentList(mBatchTarget);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mAddedNodes.Length(); ++i) {
|
2012-03-31 20:30:13 +04:00
|
|
|
addedList->AppendElement(mAddedNodes[i]);
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> m =
|
2014-02-26 04:45:08 +04:00
|
|
|
new nsDOMMutationRecord(nsGkAtoms::childList,
|
2012-12-18 18:50:52 +04:00
|
|
|
ob->GetParentObject());
|
2012-03-31 20:30:13 +04:00
|
|
|
m->mTarget = mBatchTarget;
|
|
|
|
m->mRemovedNodes = removedList;
|
|
|
|
m->mAddedNodes = addedList;
|
|
|
|
m->mPreviousSibling = mPrevSibling;
|
|
|
|
m->mNextSibling = mNextSibling;
|
2014-02-26 04:40:51 +04:00
|
|
|
ob->AppendMutationRecord(m.forget());
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
2012-04-04 10:22:16 +04:00
|
|
|
// Always schedule the observer so that transient receivers are
|
|
|
|
// removed correctly.
|
|
|
|
ob->ScheduleForRun();
|
2012-03-31 20:30:13 +04:00
|
|
|
}
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
|
|
}
|
2015-03-14 08:34:40 +03:00
|
|
|
|
|
|
|
nsAutoAnimationMutationBatch*
|
|
|
|
nsAutoAnimationMutationBatch::sCurrentBatch = nullptr;
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAutoAnimationMutationBatch::Done()
|
|
|
|
{
|
|
|
|
if (sCurrentBatch != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-31 10:21:49 +03:00
|
|
|
sCurrentBatch = nullptr;
|
2015-03-14 08:34:40 +03:00
|
|
|
if (mObservers.IsEmpty()) {
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-31 10:21:49 +03:00
|
|
|
mBatchTargets.Sort(TreeOrderComparator());
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
for (nsDOMMutationObserver* ob : mObservers) {
|
2015-08-31 10:21:49 +03:00
|
|
|
bool didAddRecords = false;
|
|
|
|
|
|
|
|
for (nsINode* target : mBatchTargets) {
|
|
|
|
EntryArray* entries = mEntryTable.Get(target);
|
|
|
|
MOZ_ASSERT(entries,
|
|
|
|
"Targets in entry table and targets list should match");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMMutationRecord> m =
|
2015-08-31 10:21:49 +03:00
|
|
|
new nsDOMMutationRecord(nsGkAtoms::animations, ob->GetParentObject());
|
|
|
|
m->mTarget = target;
|
|
|
|
|
|
|
|
for (const Entry& e : *entries) {
|
|
|
|
if (e.mState == eState_Added) {
|
|
|
|
m->mAddedAnimations.AppendElement(e.mAnimation);
|
|
|
|
} else if (e.mState == eState_Removed) {
|
|
|
|
m->mRemovedAnimations.AppendElement(e.mAnimation);
|
|
|
|
} else if (e.mState == eState_RemainedPresent && e.mChanged) {
|
|
|
|
m->mChangedAnimations.AppendElement(e.mAnimation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m->mAddedAnimations.IsEmpty() ||
|
|
|
|
!m->mChangedAnimations.IsEmpty() ||
|
|
|
|
!m->mRemovedAnimations.IsEmpty()) {
|
|
|
|
ob->AppendMutationRecord(m.forget());
|
|
|
|
didAddRecords = true;
|
2015-03-14 08:34:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 10:21:49 +03:00
|
|
|
if (didAddRecords) {
|
2015-03-14 08:34:40 +03:00
|
|
|
ob->ScheduleForRun();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling();
|
|
|
|
}
|