2012-03-31 16:30:13 +00:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsDOMMutationObserver_h
|
|
|
|
#define nsDOMMutationObserver_h
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-03-31 16:30:13 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsNodeUtils.h"
|
2012-08-15 10:06:01 +00:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
2012-08-28 15:25:19 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2012-12-18 14:50:52 +00:00
|
|
|
#include "mozilla/dom/MutationObserverBinding.h"
|
2013-10-02 20:09:18 +00:00
|
|
|
#include "nsIDocument.h"
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
class nsDOMMutationObserver;
|
2013-10-09 16:05:22 +00:00
|
|
|
using mozilla::dom::MutationObservingInfo;
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
class nsDOMMutationRecord : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~nsDOMMutationRecord() {}
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
public:
|
2014-02-26 00:45:08 +00:00
|
|
|
nsDOMMutationRecord(nsIAtom* aType, nsISupports* aOwner)
|
2014-04-08 08:06:00 +00:00
|
|
|
: mType(aType), mAttrNamespace(NullString()), mPrevValue(NullString()), mOwner(aOwner)
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
|
|
|
}
|
2012-12-18 14:50:52 +00:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
|
2012-12-18 14:50:52 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return mozilla::dom::MutationRecordBinding::Wrap(aCx, this);
|
2012-12-18 14:50:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2012-12-18 14:50:52 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMMutationRecord)
|
|
|
|
|
2014-02-26 00:45:08 +00:00
|
|
|
void GetType(mozilla::dom::DOMString& aRetVal) const
|
2012-12-18 14:50:52 +00:00
|
|
|
{
|
2014-02-26 00:45:08 +00:00
|
|
|
aRetVal.SetOwnedAtom(mType, mozilla::dom::DOMString::eNullNotExpected);
|
2012-12-18 14:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsINode* GetTarget() const
|
|
|
|
{
|
|
|
|
return mTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINodeList* AddedNodes();
|
|
|
|
|
|
|
|
nsINodeList* RemovedNodes();
|
|
|
|
|
|
|
|
nsINode* GetPreviousSibling() const
|
|
|
|
{
|
|
|
|
return mPreviousSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode* GetNextSibling() const
|
|
|
|
{
|
|
|
|
return mNextSibling;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:45:08 +00:00
|
|
|
void GetAttributeName(mozilla::dom::DOMString& aRetVal) const
|
2012-12-18 14:50:52 +00:00
|
|
|
{
|
2014-02-26 00:45:08 +00:00
|
|
|
aRetVal.SetOwnedAtom(mAttrName, mozilla::dom::DOMString::eTreatNullAsNull);
|
2012-12-18 14:50:52 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 00:45:08 +00:00
|
|
|
void GetAttributeNamespace(mozilla::dom::DOMString& aRetVal) const
|
2012-12-18 14:50:52 +00:00
|
|
|
{
|
2014-02-26 00:45:08 +00:00
|
|
|
aRetVal.SetOwnedString(mAttrNamespace);
|
2012-12-18 14:50:52 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 00:45:08 +00:00
|
|
|
void GetOldValue(mozilla::dom::DOMString& aRetVal) const
|
2012-12-18 14:50:52 +00:00
|
|
|
{
|
2014-02-26 00:45:08 +00:00
|
|
|
aRetVal.SetOwnedString(mPrevValue);
|
2012-12-18 14:50:52 +00:00
|
|
|
}
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> mTarget;
|
2014-02-26 00:45:08 +00:00
|
|
|
nsCOMPtr<nsIAtom> mType;
|
|
|
|
nsCOMPtr<nsIAtom> mAttrName;
|
2012-03-31 16:30:13 +00:00
|
|
|
nsString mAttrNamespace;
|
|
|
|
nsString mPrevValue;
|
|
|
|
nsRefPtr<nsSimpleContentList> mAddedNodes;
|
|
|
|
nsRefPtr<nsSimpleContentList> mRemovedNodes;
|
|
|
|
nsCOMPtr<nsINode> mPreviousSibling;
|
|
|
|
nsCOMPtr<nsINode> mNextSibling;
|
2014-02-26 00:40:51 +00:00
|
|
|
|
|
|
|
nsRefPtr<nsDOMMutationRecord> mNext;
|
2012-12-18 14:50:52 +00:00
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
2012-03-31 16:30:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Base class just prevents direct access to
|
|
|
|
// members to make sure we go through getters/setters.
|
|
|
|
class nsMutationReceiverBase : public nsStubMutationObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~nsMutationReceiverBase() { }
|
|
|
|
|
|
|
|
nsDOMMutationObserver* Observer();
|
|
|
|
nsINode* Target() { return mParent ? mParent->Target() : mTarget; }
|
|
|
|
nsINode* RegisterTarget() { return mRegisterTarget; }
|
|
|
|
|
|
|
|
bool Subtree() { return mParent ? mParent->Subtree() : mSubtree; }
|
|
|
|
void SetSubtree(bool aSubtree)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mSubtree = aSubtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChildList() { return mParent ? mParent->ChildList() : mChildList; }
|
|
|
|
void SetChildList(bool aChildList)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mChildList = aChildList;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CharacterData()
|
|
|
|
{
|
|
|
|
return mParent ? mParent->CharacterData() : mCharacterData;
|
|
|
|
}
|
|
|
|
void SetCharacterData(bool aCharacterData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mCharacterData = aCharacterData;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CharacterDataOldValue()
|
|
|
|
{
|
|
|
|
return mParent ? mParent->CharacterDataOldValue() : mCharacterDataOldValue;
|
|
|
|
}
|
|
|
|
void SetCharacterDataOldValue(bool aOldValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mCharacterDataOldValue = aOldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Attributes() { return mParent ? mParent->Attributes() : mAttributes; }
|
|
|
|
void SetAttributes(bool aAttributes)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mAttributes = aAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AllAttributes()
|
|
|
|
{
|
|
|
|
return mParent ? mParent->AllAttributes()
|
|
|
|
: mAllAttributes;
|
|
|
|
}
|
|
|
|
void SetAllAttributes(bool aAll)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mAllAttributes = aAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeOldValue() {
|
|
|
|
return mParent ? mParent->AttributeOldValue()
|
|
|
|
: mAttributeOldValue;
|
|
|
|
}
|
|
|
|
void SetAttributeOldValue(bool aOldValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mAttributeOldValue = aOldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIAtom>& AttributeFilter() { return mAttributeFilter; }
|
|
|
|
void SetAttributeFilter(nsCOMArray<nsIAtom>& aFilter)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParent, "Shouldn't have parent");
|
|
|
|
mAttributeFilter.Clear();
|
|
|
|
mAttributeFilter.AppendObjects(aFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddClone(nsMutationReceiverBase* aClone)
|
|
|
|
{
|
|
|
|
mTransientReceivers.AppendObject(aClone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveClone(nsMutationReceiverBase* aClone)
|
|
|
|
{
|
|
|
|
mTransientReceivers.RemoveObject(aClone);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-12-18 14:50:52 +00:00
|
|
|
nsMutationReceiverBase(nsINode* aTarget, nsDOMMutationObserver* aObserver)
|
2012-03-31 16:30:13 +00:00
|
|
|
: mTarget(aTarget), mObserver(aObserver), mRegisterTarget(aTarget)
|
|
|
|
{
|
|
|
|
mRegisterTarget->AddMutationObserver(this);
|
|
|
|
mRegisterTarget->SetMayHaveDOMMutationObserver();
|
|
|
|
mRegisterTarget->OwnerDoc()->SetMayHaveDOMMutationObservers();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMutationReceiverBase(nsINode* aRegisterTarget,
|
|
|
|
nsMutationReceiverBase* aParent)
|
2012-07-30 14:20:58 +00:00
|
|
|
: mTarget(nullptr), mObserver(nullptr), mParent(aParent),
|
2012-04-10 19:01:14 +00:00
|
|
|
mRegisterTarget(aRegisterTarget), mKungFuDeathGrip(aParent->Target())
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mParent->Subtree(), "Should clone a non-subtree observer!");
|
|
|
|
mRegisterTarget->AddMutationObserver(this);
|
|
|
|
mRegisterTarget->SetMayHaveDOMMutationObserver();
|
|
|
|
mRegisterTarget->OwnerDoc()->SetMayHaveDOMMutationObservers();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObservesAttr(mozilla::dom::Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID,
|
2012-03-31 16:30:13 +00:00
|
|
|
nsIAtom* aAttr)
|
|
|
|
{
|
|
|
|
if (mParent) {
|
|
|
|
return mParent->ObservesAttr(aElement, aNameSpaceID, aAttr);
|
|
|
|
}
|
|
|
|
if (!Attributes() || (!Subtree() && aElement != Target())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (AllAttributes()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNameSpaceID != kNameSpaceID_None) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIAtom>& filters = AttributeFilter();
|
2012-12-18 14:50:52 +00:00
|
|
|
for (int32_t i = 0; i < filters.Count(); ++i) {
|
2012-03-31 16:30:13 +00:00
|
|
|
if (filters[i] == aAttr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The target for the MutationObserver.observe() method.
|
|
|
|
nsINode* mTarget;
|
2012-12-18 14:50:52 +00:00
|
|
|
nsDOMMutationObserver* mObserver;
|
2012-03-31 16:30:13 +00:00
|
|
|
nsRefPtr<nsMutationReceiverBase> mParent; // Cleared after microtask.
|
|
|
|
// The node to which Gecko-internal nsIMutationObserver was registered to.
|
|
|
|
// This is different than mTarget when dealing with transient observers.
|
|
|
|
nsINode* mRegisterTarget;
|
|
|
|
nsCOMArray<nsMutationReceiverBase> mTransientReceivers;
|
2012-04-10 19:01:14 +00:00
|
|
|
// While we have transient receivers, keep the original mutation receiver
|
|
|
|
// alive so it doesn't go away and disconnect all its transient receivers.
|
|
|
|
nsCOMPtr<nsINode> mKungFuDeathGrip;
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mSubtree;
|
|
|
|
bool mChildList;
|
|
|
|
bool mCharacterData;
|
|
|
|
bool mCharacterDataOldValue;
|
|
|
|
bool mAttributes;
|
|
|
|
bool mAllAttributes;
|
|
|
|
bool mAttributeOldValue;
|
|
|
|
nsCOMArray<nsIAtom> mAttributeFilter;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class nsMutationReceiver : public nsMutationReceiverBase
|
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
protected:
|
|
|
|
virtual ~nsMutationReceiver() { Disconnect(false); }
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
public:
|
2012-12-18 14:50:52 +00:00
|
|
|
nsMutationReceiver(nsINode* aTarget, nsDOMMutationObserver* aObserver);
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
nsMutationReceiver(nsINode* aRegisterTarget, nsMutationReceiverBase* aParent)
|
|
|
|
: nsMutationReceiverBase(aRegisterTarget, aParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!static_cast<nsMutationReceiver*>(aParent)->GetParent(),
|
|
|
|
"Shouldn't create deep observer hierarchies!");
|
|
|
|
aParent->AddClone(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMutationReceiver* GetParent()
|
|
|
|
{
|
|
|
|
return static_cast<nsMutationReceiver*>(mParent.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveClones()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = 0; i < mTransientReceivers.Count(); ++i) {
|
2012-03-31 16:30:13 +00:00
|
|
|
nsMutationReceiver* r =
|
|
|
|
static_cast<nsMutationReceiver*>(mTransientReceivers[i]);
|
2012-04-04 17:36:40 +00:00
|
|
|
r->DisconnectTransientReceiver();
|
2012-03-31 16:30:13 +00:00
|
|
|
}
|
|
|
|
mTransientReceivers.Clear();
|
|
|
|
}
|
|
|
|
|
2012-04-04 17:36:40 +00:00
|
|
|
void DisconnectTransientReceiver()
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
|
|
|
if (mRegisterTarget) {
|
|
|
|
mRegisterTarget->RemoveMutationObserver(this);
|
2012-07-30 14:20:58 +00:00
|
|
|
mRegisterTarget = nullptr;
|
2012-03-31 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mParent = nullptr;
|
2012-04-04 17:36:40 +00:00
|
|
|
NS_ASSERTION(!mTarget, "Should not have mTarget");
|
|
|
|
NS_ASSERTION(!mObserver, "Should not have mObserver");
|
2012-03-31 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 17:36:40 +00:00
|
|
|
void Disconnect(bool aRemoveFromObserver);
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
2012-07-09 20:44:33 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-04-06 09:12:59 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
2012-08-15 10:06:01 +00:00
|
|
|
|
|
|
|
virtual void AttributeSetToCurrentValue(nsIDocument* aDocument,
|
|
|
|
mozilla::dom::Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID,
|
2013-05-29 20:43:41 +00:00
|
|
|
nsIAtom* aAttribute) MOZ_OVERRIDE
|
2012-08-15 10:06:01 +00:00
|
|
|
{
|
|
|
|
// We can reuse AttributeWillChange implementation.
|
|
|
|
AttributeWillChange(aDocument, aElement, aNameSpaceID, aAttribute,
|
|
|
|
nsIDOMMutationEvent::MODIFICATION);
|
|
|
|
}
|
2012-03-31 16:30:13 +00:00
|
|
|
};
|
|
|
|
|
2013-09-11 19:43:01 +00:00
|
|
|
#define NS_DOM_MUTATION_OBSERVER_IID \
|
|
|
|
{ 0x0c3b91f8, 0xcc3b, 0x4b08, \
|
|
|
|
{ 0x9e, 0xab, 0x07, 0x47, 0xa9, 0xe4, 0x65, 0xb4 } }
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
class nsDOMMutationObserver : public nsISupports,
|
2012-08-28 15:25:19 +00:00
|
|
|
public nsWrapperCache
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-03-15 19:00:17 +00:00
|
|
|
nsDOMMutationObserver(already_AddRefed<nsPIDOMWindow>&& aOwner,
|
2012-12-18 14:50:52 +00:00
|
|
|
mozilla::dom::MutationCallback& aCb)
|
2014-02-26 00:40:51 +00:00
|
|
|
: mOwner(aOwner), mLastPendingMutation(nullptr), mPendingMutationCount(0),
|
|
|
|
mCallback(&aCb), mWaitingForRun(false), mId(++sCount)
|
2012-03-31 16:30:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2012-12-18 14:50:52 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMMutationObserver)
|
2013-09-11 19:43:01 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_MUTATION_OBSERVER_IID)
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
static already_AddRefed<nsDOMMutationObserver>
|
2012-12-03 16:07:49 +00:00
|
|
|
Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
|
|
mozilla::dom::MutationCallback& aCb,
|
2012-12-18 14:50:52 +00:00
|
|
|
mozilla::ErrorResult& aRv);
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
|
2012-08-28 15:25:19 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return mozilla::dom::MutationObserverBinding::Wrap(aCx, this);
|
2012-08-28 15:25:19 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
nsISupports* GetParentObject() const
|
2012-08-28 15:25:19 +00:00
|
|
|
{
|
2012-12-18 14:50:52 +00:00
|
|
|
return mOwner;
|
|
|
|
}
|
2012-08-28 15:25:19 +00:00
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
void Observe(nsINode& aTarget,
|
|
|
|
const mozilla::dom::MutationObserverInit& aOptions,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2012-08-28 15:25:19 +00:00
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
void TakeRecords(nsTArray<nsRefPtr<nsDOMMutationRecord> >& aRetVal);
|
2012-08-28 15:25:19 +00:00
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
void HandleMutation();
|
|
|
|
|
2013-10-09 16:05:22 +00:00
|
|
|
void GetObservingInfo(nsTArray<Nullable<MutationObservingInfo> >& aResult);
|
2013-09-11 19:43:01 +00:00
|
|
|
|
|
|
|
mozilla::dom::MutationCallback* MutationCallback() { return mCallback; }
|
|
|
|
|
2014-02-26 00:40:51 +00:00
|
|
|
void AppendMutationRecord(already_AddRefed<nsDOMMutationRecord> aRecord)
|
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
nsRefPtr<nsDOMMutationRecord> record = aRecord;
|
|
|
|
MOZ_ASSERT(record);
|
2014-02-26 00:40:51 +00:00
|
|
|
if (!mLastPendingMutation) {
|
|
|
|
MOZ_ASSERT(!mFirstPendingMutation);
|
2014-03-15 19:00:15 +00:00
|
|
|
mFirstPendingMutation = record.forget();
|
2014-02-26 00:40:51 +00:00
|
|
|
mLastPendingMutation = mFirstPendingMutation;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mFirstPendingMutation);
|
2014-03-15 19:00:15 +00:00
|
|
|
mLastPendingMutation->mNext = record.forget();
|
2014-02-26 00:40:51 +00:00
|
|
|
mLastPendingMutation = mLastPendingMutation->mNext;
|
|
|
|
}
|
|
|
|
++mPendingMutationCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPendingRecords()
|
|
|
|
{
|
|
|
|
mFirstPendingMutation = nullptr;
|
|
|
|
mLastPendingMutation = nullptr;
|
|
|
|
mPendingMutationCount = 0;
|
|
|
|
}
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
// static methods
|
|
|
|
static void HandleMutations()
|
|
|
|
{
|
|
|
|
if (sScheduledMutationObservers) {
|
|
|
|
HandleMutationsInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EnterMutationHandling();
|
|
|
|
static void LeaveMutationHandling();
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~nsDOMMutationObserver();
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
friend class nsMutationReceiver;
|
|
|
|
friend class nsAutoMutationBatch;
|
|
|
|
nsMutationReceiver* GetReceiverFor(nsINode* aNode, bool aMayCreate);
|
2012-04-04 17:36:40 +00:00
|
|
|
void RemoveReceiver(nsMutationReceiver* aReceiver);
|
|
|
|
|
2012-04-11 05:24:18 +00:00
|
|
|
already_AddRefed<nsIVariant> TakeRecords();
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
void GetAllSubtreeObserversFor(nsINode* aNode,
|
|
|
|
nsTArray<nsMutationReceiver*>& aObservers);
|
|
|
|
void ScheduleForRun();
|
|
|
|
void RescheduleForRun();
|
|
|
|
|
2014-02-26 00:45:08 +00:00
|
|
|
nsDOMMutationRecord* CurrentRecord(nsIAtom* aType);
|
2012-03-31 16:30:13 +00:00
|
|
|
bool HasCurrentRecord(const nsAString& aType);
|
|
|
|
|
|
|
|
bool Suppressed()
|
|
|
|
{
|
|
|
|
if (mOwner) {
|
2013-04-24 04:22:37 +00:00
|
|
|
nsCOMPtr<nsIDocument> d = mOwner->GetExtantDoc();
|
2012-03-31 16:30:13 +00:00
|
|
|
return d && d->IsInSyncOperation();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleMutationsInternal();
|
|
|
|
|
|
|
|
static void AddCurrentlyHandlingObserver(nsDOMMutationObserver* aObserver);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mOwner;
|
|
|
|
|
|
|
|
nsCOMArray<nsMutationReceiver> mReceivers;
|
|
|
|
nsClassHashtable<nsISupportsHashKey,
|
2012-12-18 14:50:52 +00:00
|
|
|
nsCOMArray<nsMutationReceiver> > mTransientReceivers;
|
2012-03-31 16:30:13 +00:00
|
|
|
// MutationRecords which are being constructed.
|
|
|
|
nsAutoTArray<nsDOMMutationRecord*, 4> mCurrentMutations;
|
|
|
|
// MutationRecords which will be handed to the callback at the end of
|
|
|
|
// the microtask.
|
2014-02-26 00:40:51 +00:00
|
|
|
nsRefPtr<nsDOMMutationRecord> mFirstPendingMutation;
|
|
|
|
nsDOMMutationRecord* mLastPendingMutation;
|
|
|
|
uint32_t mPendingMutationCount;
|
|
|
|
|
2012-12-18 14:50:52 +00:00
|
|
|
nsRefPtr<mozilla::dom::MutationCallback> mCallback;
|
2012-03-31 16:30:13 +00:00
|
|
|
|
|
|
|
bool mWaitingForRun;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t mId;
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint64_t sCount;
|
2014-02-26 00:41:47 +00:00
|
|
|
static nsAutoTArray<nsRefPtr<nsDOMMutationObserver>, 4>* sScheduledMutationObservers;
|
2012-12-18 14:50:52 +00:00
|
|
|
static nsDOMMutationObserver* sCurrentObserver;
|
2012-03-31 16:30:13 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sMutationLevel;
|
2014-02-26 00:41:47 +00:00
|
|
|
static nsAutoTArray<nsAutoTArray<nsRefPtr<nsDOMMutationObserver>, 4>, 4>*
|
2012-03-31 16:30:13 +00:00
|
|
|
sCurrentlyHandlingObservers;
|
|
|
|
};
|
|
|
|
|
2013-09-11 19:43:01 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMMutationObserver, NS_DOM_MUTATION_OBSERVER_IID)
|
|
|
|
|
2012-03-31 16:30:13 +00:00
|
|
|
class nsAutoMutationBatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAutoMutationBatch()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mPreviousBatch(nullptr), mBatchTarget(nullptr), mRemovalDone(false),
|
2012-03-31 16:30:13 +00:00
|
|
|
mFromFirstToLast(false), mAllowNestedBatches(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMutationBatch(nsINode* aTarget, bool aFromFirstToLast,
|
|
|
|
bool aAllowNestedBatches)
|
2012-07-30 14:20:58 +00:00
|
|
|
: mPreviousBatch(nullptr), mBatchTarget(nullptr), mRemovalDone(false),
|
2012-03-31 16:30:13 +00:00
|
|
|
mFromFirstToLast(false), mAllowNestedBatches(false)
|
|
|
|
{
|
|
|
|
Init(aTarget, aFromFirstToLast, aAllowNestedBatches);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(nsINode* aTarget, bool aFromFirstToLast, bool aAllowNestedBatches)
|
|
|
|
{
|
|
|
|
if (aTarget && aTarget->OwnerDoc()->MayHaveDOMMutationObservers()) {
|
|
|
|
if (sCurrentBatch && !sCurrentBatch->mAllowNestedBatches) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBatchTarget = aTarget;
|
|
|
|
mFromFirstToLast = aFromFirstToLast;
|
|
|
|
mAllowNestedBatches = aAllowNestedBatches;
|
|
|
|
mPreviousBatch = sCurrentBatch;
|
|
|
|
sCurrentBatch = this;
|
|
|
|
nsDOMMutationObserver::EnterMutationHandling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemovalDone() { mRemovalDone = true; }
|
|
|
|
static bool IsRemovalDone() { return sCurrentBatch->mRemovalDone; }
|
|
|
|
|
|
|
|
void SetPrevSibling(nsINode* aNode) { mPrevSibling = aNode; }
|
|
|
|
void SetNextSibling(nsINode* aNode) { mNextSibling = aNode; }
|
|
|
|
|
|
|
|
void Done();
|
|
|
|
|
|
|
|
~nsAutoMutationBatch() { NodesAdded(); }
|
|
|
|
|
|
|
|
static bool IsBatching()
|
|
|
|
{
|
|
|
|
return !!sCurrentBatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsAutoMutationBatch* GetCurrentBatch()
|
|
|
|
{
|
|
|
|
return sCurrentBatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateObserver(nsDOMMutationObserver* aObserver,
|
|
|
|
bool aWantsChildList)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t l = sCurrentBatch->mObservers.Length();
|
|
|
|
for (uint32_t i = 0; i < l; ++i) {
|
2012-03-31 16:30:13 +00:00
|
|
|
if (sCurrentBatch->mObservers[i].mObserver == aObserver) {
|
|
|
|
if (aWantsChildList) {
|
|
|
|
sCurrentBatch->mObservers[i].mWantsChildList = aWantsChildList;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BatchObserver* bo = sCurrentBatch->mObservers.AppendElement();
|
|
|
|
bo->mObserver = aObserver;
|
|
|
|
bo->mWantsChildList = aWantsChildList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static nsINode* GetBatchTarget() { return sCurrentBatch->mBatchTarget; }
|
|
|
|
|
|
|
|
// Mutation receivers notify the batch about removed child nodes.
|
|
|
|
static void NodeRemoved(nsIContent* aChild)
|
|
|
|
{
|
|
|
|
if (IsBatching() && !sCurrentBatch->mRemovalDone) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len = sCurrentBatch->mRemovedNodes.Length();
|
2012-03-31 16:30:13 +00:00
|
|
|
if (!len ||
|
|
|
|
sCurrentBatch->mRemovedNodes[len - 1] != aChild) {
|
|
|
|
sCurrentBatch->mRemovedNodes.AppendElement(aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called after new child nodes have been added to the batch target.
|
|
|
|
void NodesAdded()
|
|
|
|
{
|
|
|
|
if (sCurrentBatch != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* c =
|
|
|
|
mPrevSibling ? mPrevSibling->GetNextSibling() :
|
|
|
|
mBatchTarget->GetFirstChild();
|
|
|
|
for (; c != mNextSibling; c = c->GetNextSibling()) {
|
|
|
|
mAddedNodes.AppendElement(c);
|
|
|
|
}
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct BatchObserver
|
|
|
|
{
|
|
|
|
nsDOMMutationObserver* mObserver;
|
|
|
|
bool mWantsChildList;
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsAutoMutationBatch* sCurrentBatch;
|
|
|
|
nsAutoMutationBatch* mPreviousBatch;
|
|
|
|
nsAutoTArray<BatchObserver, 2> mObservers;
|
|
|
|
nsTArray<nsCOMPtr<nsIContent> > mRemovedNodes;
|
|
|
|
nsTArray<nsCOMPtr<nsIContent> > mAddedNodes;
|
|
|
|
nsINode* mBatchTarget;
|
|
|
|
bool mRemovalDone;
|
|
|
|
bool mFromFirstToLast;
|
|
|
|
bool mAllowNestedBatches;
|
|
|
|
nsCOMPtr<nsINode> mPrevSibling;
|
|
|
|
nsCOMPtr<nsINode> mNextSibling;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsDOMMutationObserver*
|
|
|
|
nsMutationReceiverBase::Observer()
|
|
|
|
{
|
|
|
|
return mParent ?
|
|
|
|
mParent->Observer() : static_cast<nsDOMMutationObserver*>(mObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|