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/. */
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
|
|
|
|
#include "nsNodeUtils.h"
|
2006-08-16 12:44:45 +04:00
|
|
|
|
#include "nsContentUtils.h"
|
2016-02-17 23:37:00 +03:00
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
|
#include "nsINode.h"
|
|
|
|
|
#include "nsIContent.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
|
#include "mozilla/dom/Element.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
|
#include "nsIMutationObserver.h"
|
|
|
|
|
#include "nsIDocument.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
|
#include "mozilla/EventListenerManager.h"
|
2006-09-05 14:22:54 +04:00
|
|
|
|
#include "nsIXPConnect.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
|
#include "PLDHashTable.h"
|
2006-09-05 14:22:54 +04:00
|
|
|
|
#include "nsIDOMAttr.h"
|
|
|
|
|
#include "nsCOMArray.h"
|
2007-02-01 01:54:24 +03:00
|
|
|
|
#include "nsPIDOMWindow.h"
|
2009-09-10 17:23:40 +04:00
|
|
|
|
#include "nsDocument.h"
|
2006-11-07 06:13:49 +03:00
|
|
|
|
#ifdef MOZ_XUL
|
2006-10-31 16:25:40 +03:00
|
|
|
|
#include "nsXULElement.h"
|
2006-11-07 06:13:49 +03:00
|
|
|
|
#endif
|
2008-09-05 19:45:03 +04:00
|
|
|
|
#include "nsBindingManager.h"
|
2009-10-01 02:56:50 +04:00
|
|
|
|
#include "nsGenericHTMLElement.h"
|
2016-04-28 18:22:43 +03:00
|
|
|
|
#include "mozilla/AnimationTarget.h"
|
2015-02-13 22:34:53 +03:00
|
|
|
|
#include "mozilla/Assertions.h"
|
2017-09-13 20:34:55 +03:00
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2015-04-21 04:22:09 +03:00
|
|
|
|
#include "mozilla/dom/Animation.h"
|
2013-06-18 16:53:23 +04:00
|
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2013-03-19 16:23:54 +04:00
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
|
#include "mozilla/dom/KeyframeEffectReadOnly.h"
|
2011-05-26 23:58:35 +04:00
|
|
|
|
#include "nsWrapperCacheInlines.h"
|
2012-02-01 01:55:54 +04:00
|
|
|
|
#include "nsObjectLoadingContent.h"
|
2012-03-31 20:30:13 +04:00
|
|
|
|
#include "nsDOMMutationObserver.h"
|
2012-09-26 18:17:46 +04:00
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-03-26 11:15:23 +04:00
|
|
|
|
#include "mozilla/dom/HTMLTemplateElement.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
|
using namespace mozilla::dom;
|
2013-04-08 21:24:21 +04:00
|
|
|
|
using mozilla::AutoJSContext;
|
2010-04-30 17:12:05 +04:00
|
|
|
|
|
2007-12-04 21:37:54 +03:00
|
|
|
|
// This macro expects the ownerDocument of content_ to be in scope as
|
|
|
|
|
// |nsIDocument* doc|
|
2006-08-16 02:41:58 +04:00
|
|
|
|
#define IMPL_MUTATION_NOTIFICATION(func_, content_, params_) \
|
|
|
|
|
PR_BEGIN_MACRO \
|
2012-03-31 20:30:13 +04:00
|
|
|
|
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
|
|
|
|
|
if (needsEnterLeave) { \
|
|
|
|
|
nsDOMMutationObserver::EnterMutationHandling(); \
|
|
|
|
|
} \
|
2006-07-02 11:23:10 +04:00
|
|
|
|
nsINode* node = content_; \
|
2012-03-31 20:30:13 +04:00
|
|
|
|
NS_ASSERTION(node->OwnerDoc() == doc, "Bogus document"); \
|
2007-12-04 21:37:54 +03:00
|
|
|
|
if (doc) { \
|
2012-10-26 18:48:29 +04:00
|
|
|
|
doc->BindingManager()->func_ params_; \
|
2007-12-04 21:37:54 +03:00
|
|
|
|
} \
|
2006-07-02 11:23:10 +04:00
|
|
|
|
do { \
|
|
|
|
|
nsINode::nsSlots* slots = node->GetExistingSlots(); \
|
|
|
|
|
if (slots && !slots->mMutationObservers.IsEmpty()) { \
|
|
|
|
|
/* No need to explicitly notify the first observer first \
|
|
|
|
|
since that'll happen anyway. */ \
|
2017-07-29 08:07:05 +03:00
|
|
|
|
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS( \
|
|
|
|
|
slots->mMutationObservers, nsIMutationObserver, 1, \
|
2006-08-16 02:41:58 +04:00
|
|
|
|
func_, params_); \
|
2006-07-02 11:23:10 +04:00
|
|
|
|
} \
|
2013-12-02 14:26:11 +04:00
|
|
|
|
ShadowRoot* shadow = ShadowRoot::FromNode(node); \
|
|
|
|
|
if (shadow) { \
|
2017-09-25 18:09:26 +03:00
|
|
|
|
node = shadow->GetHost(); \
|
2013-12-02 14:26:11 +04:00
|
|
|
|
} else { \
|
|
|
|
|
node = node->GetParentNode(); \
|
|
|
|
|
} \
|
2006-08-16 02:41:58 +04:00
|
|
|
|
} while (node); \
|
2012-03-31 20:30:13 +04:00
|
|
|
|
if (needsEnterLeave) { \
|
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling(); \
|
|
|
|
|
} \
|
2006-08-16 02:41:58 +04:00
|
|
|
|
PR_END_MACRO
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
|
#define IMPL_ANIMATION_NOTIFICATION(func_, content_, params_) \
|
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
|
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
|
|
|
|
|
if (needsEnterLeave) { \
|
|
|
|
|
nsDOMMutationObserver::EnterMutationHandling(); \
|
|
|
|
|
} \
|
|
|
|
|
nsINode* node = content_; \
|
|
|
|
|
do { \
|
|
|
|
|
nsINode::nsSlots* slots = node->GetExistingSlots(); \
|
|
|
|
|
if (slots && !slots->mMutationObservers.IsEmpty()) { \
|
|
|
|
|
/* No need to explicitly notify the first observer first \
|
|
|
|
|
since that'll happen anyway. */ \
|
2017-07-29 08:07:05 +03:00
|
|
|
|
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS_WITH_QI( \
|
|
|
|
|
slots->mMutationObservers, nsIMutationObserver, 1, \
|
2015-03-14 08:34:40 +03:00
|
|
|
|
nsIAnimationObserver, func_, params_); \
|
|
|
|
|
} \
|
|
|
|
|
ShadowRoot* shadow = ShadowRoot::FromNode(node); \
|
|
|
|
|
if (shadow) { \
|
2017-09-25 18:09:26 +03:00
|
|
|
|
node = shadow->GetHost(); \
|
2015-03-14 08:34:40 +03:00
|
|
|
|
} else { \
|
|
|
|
|
node = node->GetParentNode(); \
|
|
|
|
|
} \
|
|
|
|
|
} while (node); \
|
|
|
|
|
if (needsEnterLeave) { \
|
|
|
|
|
nsDOMMutationObserver::LeaveMutationHandling(); \
|
|
|
|
|
} \
|
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
2007-09-05 12:22:17 +04:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::CharacterDataWillChange(nsIContent* aContent,
|
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aContent->OwnerDoc();
|
2010-07-21 19:33:32 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(CharacterDataWillChange, aContent,
|
2007-09-05 12:22:17 +04:00
|
|
|
|
(doc, aContent, aInfo));
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
|
void
|
2006-11-04 00:51:01 +03:00
|
|
|
|
nsNodeUtils::CharacterDataChanged(nsIContent* aContent,
|
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aContent->OwnerDoc();
|
2010-07-21 19:33:32 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(CharacterDataChanged, aContent,
|
2006-11-04 00:51:01 +03:00
|
|
|
|
(doc, aContent, aInfo));
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-29 22:36:25 +04:00
|
|
|
|
void
|
2010-08-24 11:06:20 +04:00
|
|
|
|
nsNodeUtils::AttributeWillChange(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-22 06:53:35 +03:00
|
|
|
|
int32_t aModType,
|
|
|
|
|
const nsAttrValue* aNewValue)
|
2009-06-29 22:36:25 +04:00
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aElement->OwnerDoc();
|
2010-08-24 11:06:20 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(AttributeWillChange, aElement,
|
|
|
|
|
(doc, aElement, aNameSpaceID, aAttribute,
|
2015-07-25 09:05:19 +03:00
|
|
|
|
aModType, aNewValue));
|
2009-06-29 22:36:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
|
void
|
2010-08-24 11:06:07 +04:00
|
|
|
|
nsNodeUtils::AttributeChanged(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-21 07:13:53 +03:00
|
|
|
|
int32_t aModType,
|
|
|
|
|
const nsAttrValue* aOldValue)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aElement->OwnerDoc();
|
2010-08-24 11:05:56 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(AttributeChanged, aElement,
|
|
|
|
|
(doc, aElement, aNameSpaceID, aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
|
aModType, aOldValue));
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-15 14:06:01 +04:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::AttributeSetToCurrentValue(Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
|
nsAtom* aAttribute)
|
2012-08-15 14:06:01 +04:00
|
|
|
|
{
|
|
|
|
|
nsIDocument* doc = aElement->OwnerDoc();
|
|
|
|
|
IMPL_MUTATION_NOTIFICATION(AttributeSetToCurrentValue, aElement,
|
|
|
|
|
(doc, aElement, aNameSpaceID, aAttribute));
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::ContentAppended(nsIContent* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
|
nsIContent* aFirstNewContent)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aContainer->OwnerDoc();
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
2010-07-21 19:33:32 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(ContentAppended, aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
|
(doc, aContainer, aFirstNewContent));
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::NativeAnonymousChildListChange(nsIContent* aContent,
|
|
|
|
|
bool aIsRemove)
|
|
|
|
|
{
|
|
|
|
|
nsIDocument* doc = aContent->OwnerDoc();
|
|
|
|
|
IMPL_MUTATION_NOTIFICATION(NativeAnonymousChildListChange, aContent,
|
|
|
|
|
(doc, aContent, aIsRemove));
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::ContentInserted(nsINode* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
|
nsIContent* aChild)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
2017-10-25 18:19:11 +03:00
|
|
|
|
NS_PRECONDITION(aContainer->IsContent() ||
|
2006-07-02 11:23:10 +04:00
|
|
|
|
aContainer->IsNodeOfType(nsINode::eDOCUMENT),
|
|
|
|
|
"container must be an nsIContent or an nsIDocument");
|
|
|
|
|
nsIContent* container;
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aContainer->OwnerDoc();
|
2006-07-02 11:23:10 +04:00
|
|
|
|
nsIDocument* document;
|
2017-10-25 18:19:11 +03:00
|
|
|
|
if (aContainer->IsContent()) {
|
|
|
|
|
container = aContainer->AsContent();
|
2007-12-04 21:37:54 +03:00
|
|
|
|
document = doc;
|
2017-10-25 18:19:11 +03:00
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
container = nullptr;
|
2007-07-08 11:08:04 +04:00
|
|
|
|
document = static_cast<nsIDocument*>(aContainer);
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 19:33:32 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(ContentInserted, aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
|
(document, container, aChild));
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::ContentRemoved(nsINode* aContainer,
|
|
|
|
|
nsIContent* aChild,
|
2010-07-22 02:05:17 +04:00
|
|
|
|
nsIContent* aPreviousSibling)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
2017-10-25 18:19:11 +03:00
|
|
|
|
NS_PRECONDITION(aContainer->IsContent() ||
|
2006-07-02 11:23:10 +04:00
|
|
|
|
aContainer->IsNodeOfType(nsINode::eDOCUMENT),
|
|
|
|
|
"container must be an nsIContent or an nsIDocument");
|
|
|
|
|
nsIContent* container;
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* doc = aContainer->OwnerDoc();
|
2006-07-02 11:23:10 +04:00
|
|
|
|
nsIDocument* document;
|
2017-10-25 18:19:11 +03:00
|
|
|
|
if (aContainer->IsContent()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
|
container = static_cast<nsIContent*>(aContainer);
|
2007-12-04 21:37:54 +03:00
|
|
|
|
document = doc;
|
2017-10-25 18:19:11 +03:00
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
|
container = nullptr;
|
2007-07-08 11:08:04 +04:00
|
|
|
|
document = static_cast<nsIDocument*>(aContainer);
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 19:37:41 +04:00
|
|
|
|
IMPL_MUTATION_NOTIFICATION(ContentRemoved, aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
|
(document, container, aChild, aPreviousSibling));
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
|
Maybe<NonOwningAnimationTarget>
|
2015-10-22 09:16:18 +03:00
|
|
|
|
nsNodeUtils::GetTargetForAnimation(const Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
|
{
|
2016-07-25 11:56:34 +03:00
|
|
|
|
AnimationEffectReadOnly* effect = aAnimation->GetEffect();
|
|
|
|
|
if (!effect || !effect->AsKeyframeEffect()) {
|
|
|
|
|
return Nothing();
|
|
|
|
|
}
|
|
|
|
|
return effect->AsKeyframeEffect()->GetTarget();
|
2015-03-14 08:34:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-03-21 11:49:50 +03:00
|
|
|
|
nsNodeUtils::AnimationMutated(Animation* aAnimation,
|
|
|
|
|
AnimationMutationType aMutatedType)
|
2015-03-14 08:34:40 +03:00
|
|
|
|
{
|
2016-03-21 11:49:50 +03:00
|
|
|
|
Maybe<NonOwningAnimationTarget> target = GetTargetForAnimation(aAnimation);
|
2015-03-14 08:34:40 +03:00
|
|
|
|
if (!target) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
|
// A pseudo element and its parent element use the same owner doc.
|
|
|
|
|
nsIDocument* doc = target->mElement->OwnerDoc();
|
2015-03-14 08:34:40 +03:00
|
|
|
|
if (doc->MayHaveAnimationObservers()) {
|
2016-03-21 11:49:50 +03:00
|
|
|
|
// we use the its parent element as the subject in DOM Mutation Observer.
|
2016-03-21 11:49:50 +03:00
|
|
|
|
Element* elem = target->mElement;
|
|
|
|
|
switch (aMutatedType) {
|
|
|
|
|
case AnimationMutationType::Added:
|
|
|
|
|
IMPL_ANIMATION_NOTIFICATION(AnimationAdded, elem, (aAnimation));
|
|
|
|
|
break;
|
|
|
|
|
case AnimationMutationType::Changed:
|
|
|
|
|
IMPL_ANIMATION_NOTIFICATION(AnimationChanged, elem, (aAnimation));
|
|
|
|
|
break;
|
|
|
|
|
case AnimationMutationType::Removed:
|
|
|
|
|
IMPL_ANIMATION_NOTIFICATION(AnimationRemoved, elem, (aAnimation));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected mutation type");
|
|
|
|
|
}
|
2015-03-14 08:34:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-03-21 11:49:50 +03:00
|
|
|
|
nsNodeUtils::AnimationAdded(Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
|
{
|
2016-03-21 11:49:50 +03:00
|
|
|
|
AnimationMutated(aAnimation, AnimationMutationType::Added);
|
|
|
|
|
}
|
2015-03-14 08:34:40 +03:00
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::AnimationChanged(Animation* aAnimation)
|
|
|
|
|
{
|
|
|
|
|
AnimationMutated(aAnimation, AnimationMutationType::Changed);
|
2015-03-14 08:34:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
|
nsNodeUtils::AnimationRemoved(Animation* aAnimation)
|
2015-03-14 08:34:40 +03:00
|
|
|
|
{
|
2016-03-21 11:49:50 +03:00
|
|
|
|
AnimationMutated(aAnimation, AnimationMutationType::Removed);
|
2015-03-14 08:34:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
|
void
|
2007-05-12 19:36:28 +04:00
|
|
|
|
nsNodeUtils::LastRelease(nsINode* aNode)
|
2006-07-02 11:23:10 +04:00
|
|
|
|
{
|
|
|
|
|
nsINode::nsSlots* slots = aNode->GetExistingSlots();
|
2006-08-25 14:00:11 +04:00
|
|
|
|
if (slots) {
|
|
|
|
|
if (!slots->mMutationObservers.IsEmpty()) {
|
2017-07-29 08:07:05 +03:00
|
|
|
|
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
|
|
|
|
nsIMutationObserver, 1,
|
|
|
|
|
NodeWillBeDestroyed, (aNode));
|
2006-08-25 14:00:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-03 02:41:24 +03:00
|
|
|
|
delete slots;
|
2012-07-30 18:20:58 +04:00
|
|
|
|
aNode->mSlots = nullptr;
|
2006-07-02 11:23:10 +04:00
|
|
|
|
}
|
2006-08-16 12:44:45 +04:00
|
|
|
|
|
2006-09-02 17:21:05 +04:00
|
|
|
|
// Kill properties first since that may run external code, so we want to
|
|
|
|
|
// be in as complete state as possible at that time.
|
2007-05-12 19:36:28 +04:00
|
|
|
|
if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
|
|
|
|
|
// Delete all properties before tearing down the document. Some of the
|
|
|
|
|
// properties are bound to nsINode objects and the destructor functions of
|
|
|
|
|
// the properties may want to use the owner document of the nsINode.
|
2010-04-23 06:41:38 +04:00
|
|
|
|
static_cast<nsIDocument*>(aNode)->DeleteAllProperties();
|
2007-05-12 19:36:28 +04:00
|
|
|
|
}
|
2009-10-01 02:56:50 +04:00
|
|
|
|
else {
|
|
|
|
|
if (aNode->HasProperties()) {
|
2017-10-06 06:42:55 +03:00
|
|
|
|
if (aNode->IsElement()) {
|
|
|
|
|
Element* elem = aNode->AsElement();
|
|
|
|
|
elem->UnlinkIntersectionObservers();
|
|
|
|
|
elem->DeleteProperty(nsGkAtoms::intersectionobserverlist);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 02:56:50 +04:00
|
|
|
|
// Strong reference to the document so that deleting properties can't
|
|
|
|
|
// delete the document.
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsCOMPtr<nsIDocument> document = aNode->OwnerDoc();
|
2011-10-18 15:19:44 +04:00
|
|
|
|
document->DeleteAllPropertiesFor(aNode);
|
2009-10-01 02:56:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I wonder whether it's faster to do the HasFlag check first....
|
|
|
|
|
if (aNode->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) &&
|
|
|
|
|
aNode->HasFlag(ADDED_TO_FORM)) {
|
|
|
|
|
// Tell the form (if any) this node is going away. Don't
|
|
|
|
|
// notify, since we're being destroyed in any case.
|
2017-05-02 00:10:00 +03:00
|
|
|
|
static_cast<nsGenericHTMLFormElement*>(aNode)->ClearForm(true, true);
|
2006-08-16 12:44:45 +04:00
|
|
|
|
}
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (aNode->IsHTMLElement(nsGkAtoms::img) &&
|
2013-07-03 17:21:30 +04:00
|
|
|
|
aNode->HasFlag(ADDED_TO_FORM)) {
|
2013-06-18 16:53:23 +04:00
|
|
|
|
HTMLImageElement* imageElem = static_cast<HTMLImageElement*>(aNode);
|
|
|
|
|
imageElem->ClearForm(true);
|
|
|
|
|
}
|
2006-09-02 17:21:05 +04:00
|
|
|
|
}
|
2007-05-12 19:36:28 +04:00
|
|
|
|
aNode->UnsetFlags(NODE_HAS_PROPERTIES);
|
2006-09-02 17:21:05 +04:00
|
|
|
|
|
2012-02-27 18:03:15 +04:00
|
|
|
|
if (aNode->NodeType() != nsIDOMNode::DOCUMENT_NODE &&
|
|
|
|
|
aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
|
2006-09-02 17:21:05 +04:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (nsContentUtils::IsInitialized()) {
|
2014-03-17 10:56:53 +04:00
|
|
|
|
EventListenerManager* manager =
|
2013-10-23 03:32:04 +04:00
|
|
|
|
nsContentUtils::GetExistingListenerManagerForNode(aNode);
|
2006-09-02 17:21:05 +04:00
|
|
|
|
if (!manager) {
|
|
|
|
|
NS_ERROR("Huh, our bit says we have a listener manager list, "
|
|
|
|
|
"but there's nothing in the hash!?!!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
nsContentUtils::RemoveListenerManager(aNode);
|
|
|
|
|
aNode->UnsetFlags(NODE_HAS_LISTENERMANAGER);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
|
if (aNode->IsElement()) {
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* ownerDoc = aNode->OwnerDoc();
|
2010-05-27 02:39:13 +04:00
|
|
|
|
Element* elem = aNode->AsElement();
|
2011-10-18 15:19:44 +04:00
|
|
|
|
ownerDoc->ClearBoxObjectFor(elem);
|
2013-12-06 22:17:19 +04:00
|
|
|
|
|
2010-05-27 02:39:13 +04:00
|
|
|
|
NS_ASSERTION(aNode->HasFlag(NODE_FORCE_XBL_BINDINGS) ||
|
2013-07-17 20:05:03 +04:00
|
|
|
|
!elem->GetXBLBinding(),
|
2010-05-27 02:39:13 +04:00
|
|
|
|
"Non-forced node has binding on destruction");
|
|
|
|
|
|
|
|
|
|
// if NODE_FORCE_XBL_BINDINGS is set, the node might still have a binding
|
|
|
|
|
// attached
|
|
|
|
|
if (aNode->HasFlag(NODE_FORCE_XBL_BINDINGS) &&
|
2011-10-18 15:19:44 +04:00
|
|
|
|
ownerDoc->BindingManager()) {
|
2016-02-19 22:13:42 +03:00
|
|
|
|
ownerDoc->BindingManager()->RemovedFromDocument(elem, ownerDoc,
|
|
|
|
|
nsBindingManager::eRunDtor);
|
2008-02-14 23:45:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 11:04:01 +04:00
|
|
|
|
aNode->ReleaseWrapper(aNode);
|
2013-12-06 22:17:19 +04:00
|
|
|
|
|
|
|
|
|
FragmentOrElement::RemoveBlackMarkedNode(aNode);
|
2007-05-12 19:36:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-10-03 01:05:19 +03:00
|
|
|
|
NoteUserData(void *aObject, nsAtom *aKey, void *aXPCOMChild, void *aData)
|
2007-05-12 19:36:28 +04:00
|
|
|
|
{
|
|
|
|
|
nsCycleCollectionTraversalCallback* cb =
|
2007-07-08 11:08:04 +04:00
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aData);
|
2014-09-11 14:22:30 +04:00
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "[user data]");
|
2007-07-08 11:08:04 +04:00
|
|
|
|
cb->NoteXPCOMChild(static_cast<nsISupports*>(aXPCOMChild));
|
2007-05-12 19:36:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::TraverseUserData(nsINode* aNode,
|
|
|
|
|
nsCycleCollectionTraversalCallback &aCb)
|
|
|
|
|
{
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* ownerDoc = aNode->OwnerDoc();
|
2010-04-23 06:41:38 +04:00
|
|
|
|
ownerDoc->PropertyTable(DOM_USER_DATA)->Enumerate(aNode, NoteUserData, &aCb);
|
2007-05-12 19:36:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
|
/* static */
|
2017-09-13 20:34:55 +03:00
|
|
|
|
already_AddRefed<nsINode>
|
|
|
|
|
nsNodeUtils::CloneNodeImpl(nsINode *aNode, bool aDeep, ErrorResult& aError)
|
2006-09-05 14:22:54 +04:00
|
|
|
|
{
|
2017-09-13 20:34:55 +03:00
|
|
|
|
return Clone(aNode, aDeep, nullptr, nullptr, aError);
|
2006-09-05 14:22:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */
|
2017-09-13 20:34:55 +03:00
|
|
|
|
already_AddRefed<nsINode>
|
2011-09-29 10:19:26 +04:00
|
|
|
|
nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
|
2006-09-05 14:22:54 +04:00
|
|
|
|
nsNodeInfoManager *aNewNodeInfoManager,
|
2013-05-08 06:34:56 +04:00
|
|
|
|
JS::Handle<JSObject*> aReparentScope,
|
2017-06-21 21:55:04 +03:00
|
|
|
|
nsCOMArray<nsINode> *aNodesWithProperties,
|
2017-09-13 20:34:55 +03:00
|
|
|
|
nsINode* aParent, ErrorResult& aError)
|
2006-09-05 14:22:54 +04:00
|
|
|
|
{
|
2013-04-08 21:24:21 +04:00
|
|
|
|
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aReparentScope,
|
2006-09-05 14:22:54 +04:00
|
|
|
|
"If cloning or not getting a new nodeinfo we shouldn't "
|
|
|
|
|
"rewrap");
|
2017-10-25 18:19:11 +03:00
|
|
|
|
NS_PRECONDITION(!aParent || aNode->IsContent(),
|
2009-09-29 00:33:29 +04:00
|
|
|
|
"Can't insert document or attribute nodes into a parent");
|
2006-09-05 14:22:54 +04:00
|
|
|
|
|
|
|
|
|
// First deal with aNode and walk its attributes (and their children). Then,
|
2011-10-17 18:59:28 +04:00
|
|
|
|
// if aDeep is true, deal with aNode's children (and recurse into their
|
2006-09-05 14:22:54 +04:00
|
|
|
|
// attributes and children).
|
|
|
|
|
|
2015-01-06 04:00:27 +03:00
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2010-11-16 04:21:25 +03:00
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
|
nsNodeInfoManager *nodeInfoManager = aNewNodeInfoManager;
|
|
|
|
|
|
|
|
|
|
// aNode.
|
2014-06-20 06:01:40 +04:00
|
|
|
|
NodeInfo *nodeInfo = aNode->mNodeInfo;
|
2015-10-18 08:24:48 +03:00
|
|
|
|
RefPtr<NodeInfo> newNodeInfo;
|
2006-09-05 14:22:54 +04:00
|
|
|
|
if (nodeInfoManager) {
|
2008-10-13 20:12:26 +04:00
|
|
|
|
|
|
|
|
|
// Don't allow importing/adopting nodes from non-privileged "scriptable"
|
|
|
|
|
// documents to "non-scriptable" documents.
|
|
|
|
|
nsIDocument* newDoc = nodeInfoManager->GetDocument();
|
2017-09-13 20:34:55 +03:00
|
|
|
|
if (NS_WARN_IF(!newDoc)) {
|
|
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool hasHadScriptHandlingObject = false;
|
2008-10-13 20:12:26 +04:00
|
|
|
|
if (!newDoc->GetScriptHandlingObject(hasHadScriptHandlingObject) &&
|
|
|
|
|
!hasHadScriptHandlingObject) {
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* currentDoc = aNode->OwnerDoc();
|
2017-09-13 20:34:55 +03:00
|
|
|
|
if (NS_WARN_IF(!nsContentUtils::IsChromeDoc(currentDoc) &&
|
|
|
|
|
(currentDoc->GetScriptHandlingObject(hasHadScriptHandlingObject) ||
|
|
|
|
|
hasHadScriptHandlingObject))) {
|
|
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2008-10-13 20:12:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-13 02:32:18 +04:00
|
|
|
|
newNodeInfo = nodeInfoManager->GetNodeInfo(nodeInfo->NameAtom(),
|
|
|
|
|
nodeInfo->GetPrefixAtom(),
|
2011-06-14 11:56:49 +04:00
|
|
|
|
nodeInfo->NamespaceID(),
|
|
|
|
|
nodeInfo->NodeType(),
|
|
|
|
|
nodeInfo->GetExtraName());
|
2006-09-05 14:22:54 +04:00
|
|
|
|
|
|
|
|
|
nodeInfo = newNodeInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
|
Element *elem = aNode->IsElement() ? aNode->AsElement() : nullptr;
|
2006-10-07 14:27:45 +04:00
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
|
nsCOMPtr<nsINode> clone;
|
|
|
|
|
if (aClone) {
|
2017-09-13 20:34:55 +03:00
|
|
|
|
nsresult rv = aNode->Clone(nodeInfo, getter_AddRefs(clone), aDeep);
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
|
aError.Throw(rv);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2006-09-05 14:22:54 +04:00
|
|
|
|
|
2017-11-14 15:01:00 +03:00
|
|
|
|
if (CustomElementRegistry::IsCustomElementEnabled() &&
|
|
|
|
|
clone->IsHTMLElement()) {
|
2014-12-23 05:19:08 +03:00
|
|
|
|
// The cloned node may be a custom element that may require
|
2017-10-03 08:34:00 +03:00
|
|
|
|
// enqueing upgrade reaction.
|
2017-11-14 15:01:00 +03:00
|
|
|
|
Element* cloneElem = clone->AsElement();
|
2017-10-03 01:05:19 +03:00
|
|
|
|
RefPtr<nsAtom> tagAtom = nodeInfo->NameAtom();
|
2017-11-14 15:01:00 +03:00
|
|
|
|
CustomElementData* data = elem->GetCustomElementData();
|
|
|
|
|
|
|
|
|
|
// Check if node may be custom element by type extension.
|
|
|
|
|
// ex. <button is="x-button">
|
|
|
|
|
nsAutoString extension;
|
|
|
|
|
if (!data || data->GetCustomElementType() != tagAtom) {
|
|
|
|
|
cloneElem->GetAttr(kNameSpaceID_None, nsGkAtoms::is, extension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data || !extension.IsEmpty()) {
|
|
|
|
|
RefPtr<nsAtom> typeAtom = extension.IsEmpty() ? tagAtom : NS_Atomize(extension);
|
|
|
|
|
cloneElem->SetCustomElementData(new CustomElementData(typeAtom));
|
|
|
|
|
CustomElementDefinition* definition =
|
2017-10-03 08:34:00 +03:00
|
|
|
|
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
|
|
|
|
|
nodeInfo->LocalName(),
|
2017-11-14 15:01:00 +03:00
|
|
|
|
nodeInfo->NamespaceID(),
|
|
|
|
|
extension.IsEmpty() ? nullptr : &extension);
|
2017-10-03 08:34:00 +03:00
|
|
|
|
if (definition) {
|
2017-11-14 15:01:00 +03:00
|
|
|
|
nsContentUtils::EnqueueUpgradeReaction(cloneElem, definition);
|
2014-12-23 05:19:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
|
if (aParent) {
|
|
|
|
|
// If we're cloning we need to insert the cloned children into the cloned
|
|
|
|
|
// parent.
|
2009-09-29 00:33:29 +04:00
|
|
|
|
rv = aParent->AppendChildTo(static_cast<nsIContent*>(clone.get()),
|
2011-10-17 18:59:28 +04:00
|
|
|
|
false);
|
2017-09-13 20:34:55 +03:00
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
|
aError.Throw(rv);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2006-09-05 14:22:54 +04:00
|
|
|
|
}
|
|
|
|
|
else if (aDeep && clone->IsNodeOfType(nsINode::eDOCUMENT)) {
|
|
|
|
|
// After cloning the document itself, we want to clone the children into
|
|
|
|
|
// the cloned document (somewhat like cloning and importing them into the
|
|
|
|
|
// cloned document).
|
|
|
|
|
nodeInfoManager = clone->mNodeInfo->NodeInfoManager();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (nodeInfoManager) {
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* oldDoc = aNode->OwnerDoc();
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool wasRegistered = false;
|
2011-10-18 15:19:44 +04:00
|
|
|
|
if (aNode->IsElement()) {
|
2010-04-30 17:12:05 +04:00
|
|
|
|
Element* element = aNode->AsElement();
|
|
|
|
|
oldDoc->ClearBoxObjectFor(element);
|
2014-06-19 06:09:35 +04:00
|
|
|
|
wasRegistered = oldDoc->UnregisterActivityObserver(element);
|
2007-03-20 20:39:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
|
aNode->mNodeInfo.swap(newNodeInfo);
|
2010-09-02 02:48:24 +04:00
|
|
|
|
if (elem) {
|
2017-02-23 04:19:04 +03:00
|
|
|
|
elem->NodeInfoChanged(oldDoc);
|
2010-09-02 02:48:24 +04:00
|
|
|
|
}
|
2006-09-05 14:22:54 +04:00
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsIDocument* newDoc = aNode->OwnerDoc();
|
2007-03-20 20:39:25 +03:00
|
|
|
|
if (newDoc) {
|
2017-10-02 07:42:00 +03:00
|
|
|
|
if (CustomElementRegistry::IsCustomElementEnabled()) {
|
|
|
|
|
// Adopted callback must be enqueued whenever a node’s
|
|
|
|
|
// shadow-including inclusive descendants that is custom.
|
|
|
|
|
Element* element = aNode->IsElement() ? aNode->AsElement() : nullptr;
|
|
|
|
|
if (element) {
|
2017-11-02 21:52:00 +03:00
|
|
|
|
CustomElementData* data = element->GetCustomElementData();
|
2017-10-02 07:42:00 +03:00
|
|
|
|
if (data && data->mState == CustomElementData::State::eCustom) {
|
|
|
|
|
LifecycleAdoptedCallbackArgs args = {
|
|
|
|
|
oldDoc,
|
|
|
|
|
newDoc
|
|
|
|
|
};
|
|
|
|
|
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAdopted,
|
|
|
|
|
element, nullptr, &args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
|
// XXX what if oldDoc is null, we don't know if this should be
|
|
|
|
|
// registered or not! Can that really happen?
|
2009-05-08 05:32:32 +04:00
|
|
|
|
if (wasRegistered) {
|
2014-06-19 06:09:35 +04:00
|
|
|
|
newDoc->RegisterActivityObserver(aNode->AsElement());
|
2009-05-08 05:32:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
|
if (nsPIDOMWindowInner* window = newDoc->GetInnerWindow()) {
|
2014-03-17 10:56:53 +04:00
|
|
|
|
EventListenerManager* elm = aNode->GetExistingListenerManager();
|
2007-03-20 20:39:25 +03:00
|
|
|
|
if (elm) {
|
|
|
|
|
window->SetMutationListeners(elm->MutationListenerBits());
|
2008-10-16 01:06:32 +04:00
|
|
|
|
if (elm->MayHavePaintEventListener()) {
|
|
|
|
|
window->SetHasPaintEventListeners();
|
|
|
|
|
}
|
2015-04-03 03:45:50 +03:00
|
|
|
|
if (elm->MayHaveTouchEventListener()) {
|
|
|
|
|
window->SetHasTouchEventListeners();
|
|
|
|
|
}
|
2011-09-18 11:45:14 +04:00
|
|
|
|
if (elm->MayHaveMouseEnterLeaveEventListener()) {
|
|
|
|
|
window->SetHasMouseEnterLeaveEventListeners();
|
|
|
|
|
}
|
2014-02-11 10:33:29 +04:00
|
|
|
|
if (elm->MayHavePointerEnterLeaveEventListener()) {
|
|
|
|
|
window->SetHasPointerEnterLeaveEventListeners();
|
|
|
|
|
}
|
2017-06-22 21:01:27 +03:00
|
|
|
|
if (elm->MayHaveSelectionChangeEventListener()) {
|
|
|
|
|
window->SetHasSelectionChangeEventListeners();
|
|
|
|
|
}
|
2007-03-20 20:39:25 +03:00
|
|
|
|
}
|
2007-02-01 01:54:24 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-30 10:09:56 +04:00
|
|
|
|
if (wasRegistered && oldDoc != newDoc) {
|
2009-10-01 18:10:13 +04:00
|
|
|
|
nsCOMPtr<nsIDOMHTMLMediaElement> domMediaElem(do_QueryInterface(aNode));
|
|
|
|
|
if (domMediaElem) {
|
2013-03-19 16:23:54 +04:00
|
|
|
|
HTMLMediaElement* mediaElem = static_cast<HTMLMediaElement*>(aNode);
|
2009-10-01 18:10:13 +04:00
|
|
|
|
mediaElem->NotifyOwnerDocumentActivityChanged();
|
|
|
|
|
}
|
2012-02-01 01:55:54 +04:00
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objectLoadingContent(do_QueryInterface(aNode));
|
|
|
|
|
if (objectLoadingContent) {
|
|
|
|
|
nsObjectLoadingContent* olc = static_cast<nsObjectLoadingContent*>(objectLoadingContent.get());
|
|
|
|
|
olc->NotifyOwnerDocumentActivityChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-09 13:44:19 +04:00
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
|
if (oldDoc != newDoc && oldDoc->MayHaveDOMMutationObservers()) {
|
|
|
|
|
newDoc->SetMayHaveDOMMutationObservers();
|
2010-08-27 05:30:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 08:34:40 +03:00
|
|
|
|
if (oldDoc != newDoc && oldDoc->MayHaveAnimationObservers()) {
|
|
|
|
|
newDoc->SetMayHaveAnimationObservers();
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-07 14:27:45 +04:00
|
|
|
|
if (elem) {
|
|
|
|
|
elem->RecompileScriptEventListeners();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-19 23:57:15 +04:00
|
|
|
|
if (aReparentScope) {
|
2016-05-27 02:43:42 +03:00
|
|
|
|
AutoJSContext cx;
|
2013-04-19 23:57:15 +04:00
|
|
|
|
JS::Rooted<JSObject*> wrapper(cx);
|
|
|
|
|
if ((wrapper = aNode->GetWrapper())) {
|
2015-02-13 22:34:53 +03:00
|
|
|
|
MOZ_ASSERT(IsDOMObject(wrapper));
|
|
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
2017-09-13 20:34:55 +03:00
|
|
|
|
ReparentWrapper(cx, wrapper, aError);
|
|
|
|
|
if (aError.Failed()) {
|
2016-11-17 16:54:12 +03:00
|
|
|
|
if (wasRegistered) {
|
|
|
|
|
aNode->OwnerDoc()->UnregisterActivityObserver(aNode->AsElement());
|
|
|
|
|
}
|
2016-08-04 17:28:15 +03:00
|
|
|
|
aNode->mNodeInfo.swap(newNodeInfo);
|
2017-10-12 05:19:06 +03:00
|
|
|
|
if (elem) {
|
|
|
|
|
elem->NodeInfoChanged(newDoc);
|
|
|
|
|
}
|
2016-11-17 16:54:12 +03:00
|
|
|
|
if (wasRegistered) {
|
|
|
|
|
aNode->OwnerDoc()->RegisterActivityObserver(aNode->AsElement());
|
|
|
|
|
}
|
2017-09-13 20:34:55 +03:00
|
|
|
|
return nullptr;
|
2013-04-19 23:57:15 +04:00
|
|
|
|
}
|
2012-09-26 18:17:46 +04:00
|
|
|
|
}
|
2006-09-05 14:22:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 13:02:29 +03:00
|
|
|
|
if (aNodesWithProperties && aNode->HasProperties()) {
|
|
|
|
|
bool ok = aNodesWithProperties->AppendObject(aNode);
|
|
|
|
|
MOZ_RELEASE_ASSERT(ok, "Out of memory");
|
|
|
|
|
if (aClone) {
|
|
|
|
|
ok = aNodesWithProperties->AppendObject(clone);
|
|
|
|
|
MOZ_RELEASE_ASSERT(ok, "Out of memory");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 11:25:39 +04:00
|
|
|
|
if (aDeep && (!aClone || !aNode->IsNodeOfType(nsINode::eATTRIBUTE))) {
|
2006-09-05 14:22:54 +04:00
|
|
|
|
// aNode's children.
|
2011-09-27 11:54:58 +04:00
|
|
|
|
for (nsIContent* cloneChild = aNode->GetFirstChild();
|
|
|
|
|
cloneChild;
|
2012-04-03 11:25:39 +04:00
|
|
|
|
cloneChild = cloneChild->GetNextSibling()) {
|
2017-09-13 20:34:55 +03:00
|
|
|
|
nsCOMPtr<nsINode> child =
|
|
|
|
|
CloneAndAdopt(cloneChild, aClone, true, nodeInfoManager,
|
|
|
|
|
aReparentScope, aNodesWithProperties, clone,
|
|
|
|
|
aError);
|
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2006-09-05 14:22:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 20:33:10 +03:00
|
|
|
|
if (aDeep && !aClone && aNode->IsElement()) {
|
|
|
|
|
if (ShadowRoot* shadowRoot = aNode->AsElement()->GetShadowRoot()) {
|
|
|
|
|
nsCOMPtr<nsINode> child =
|
|
|
|
|
CloneAndAdopt(shadowRoot, aClone, aDeep, nodeInfoManager,
|
|
|
|
|
aReparentScope, aNodesWithProperties, clone,
|
|
|
|
|
aError);
|
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 11:15:23 +04:00
|
|
|
|
// Cloning template element.
|
|
|
|
|
if (aDeep && aClone && IsTemplateElement(aNode)) {
|
|
|
|
|
DocumentFragment* origContent =
|
|
|
|
|
static_cast<HTMLTemplateElement*>(aNode)->Content();
|
|
|
|
|
DocumentFragment* cloneContent =
|
|
|
|
|
static_cast<HTMLTemplateElement*>(clone.get())->Content();
|
|
|
|
|
|
|
|
|
|
// Clone the children into the clone's template content owner
|
|
|
|
|
// document's nodeinfo manager.
|
|
|
|
|
nsNodeInfoManager* ownerNodeInfoManager =
|
|
|
|
|
cloneContent->mNodeInfo->NodeInfoManager();
|
|
|
|
|
|
|
|
|
|
for (nsIContent* cloneChild = origContent->GetFirstChild();
|
|
|
|
|
cloneChild;
|
|
|
|
|
cloneChild = cloneChild->GetNextSibling()) {
|
2017-09-13 20:34:55 +03:00
|
|
|
|
nsCOMPtr<nsINode> child =
|
|
|
|
|
CloneAndAdopt(cloneChild, aClone, aDeep, ownerNodeInfoManager,
|
|
|
|
|
aReparentScope, aNodesWithProperties, cloneContent,
|
|
|
|
|
aError);
|
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2013-03-26 11:15:23 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-31 16:25:40 +03:00
|
|
|
|
// XXX setting document on some nodes not in a document so XBL will bind
|
|
|
|
|
// and chrome won't break. Make XBL bind to document-less nodes!
|
|
|
|
|
// XXXbz Once this is fixed, fix up the asserts in all implementations of
|
|
|
|
|
// BindToTree to assert what they would like to assert, and fix the
|
|
|
|
|
// ChangeDocumentFor() call in nsXULElement::BindToTree as well. Also,
|
|
|
|
|
// remove the UnbindFromTree call in ~nsXULElement, and add back in the
|
|
|
|
|
// precondition in nsXULElement::UnbindFromTree and remove the line in
|
|
|
|
|
// nsXULElement.h that makes nsNodeUtils a friend of nsXULElement.
|
|
|
|
|
// Note: Make sure to do this witchery _after_ we've done any deep
|
|
|
|
|
// cloning, so kids of the new node aren't confused about whether they're
|
|
|
|
|
// in a document.
|
2006-11-07 06:13:49 +03:00
|
|
|
|
#ifdef MOZ_XUL
|
2015-03-03 14:08:59 +03:00
|
|
|
|
if (aClone && !aParent && aNode->IsXULElement()) {
|
2012-07-19 12:31:47 +04:00
|
|
|
|
if (!aNode->OwnerDoc()->IsLoadedAsInteractiveData()) {
|
2007-05-16 05:13:47 +04:00
|
|
|
|
clone->SetFlags(NODE_FORCE_XBL_BINDINGS);
|
2006-10-31 16:25:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-11-07 06:13:49 +03:00
|
|
|
|
#endif
|
2006-10-31 16:25:40 +03:00
|
|
|
|
|
2017-09-13 20:34:55 +03:00
|
|
|
|
return clone.forget();
|
2006-09-05 14:22:54 +04:00
|
|
|
|
}
|
2007-05-12 19:36:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
void
|
|
|
|
|
nsNodeUtils::UnlinkUserData(nsINode *aNode)
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERTION(aNode->HasProperties(), "Call to UnlinkUserData not needed.");
|
|
|
|
|
|
|
|
|
|
// Strong reference to the document so that deleting properties can't
|
|
|
|
|
// delete the document.
|
2011-10-18 14:53:36 +04:00
|
|
|
|
nsCOMPtr<nsIDocument> document = aNode->OwnerDoc();
|
2011-10-18 15:19:44 +04:00
|
|
|
|
document->PropertyTable(DOM_USER_DATA)->DeleteAllPropertiesFor(aNode);
|
2007-05-12 19:36:28 +04:00
|
|
|
|
}
|
2013-03-26 11:15:23 +04:00
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsNodeUtils::IsTemplateElement(const nsINode *aNode)
|
|
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
|
return aNode->IsHTMLElement(nsGkAtoms::_template);
|
2013-03-26 11:15:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
|
nsNodeUtils::GetFirstChildOfTemplateOrNode(nsINode* aNode)
|
|
|
|
|
{
|
|
|
|
|
if (nsNodeUtils::IsTemplateElement(aNode)) {
|
|
|
|
|
DocumentFragment* frag =
|
|
|
|
|
static_cast<HTMLTemplateElement*>(aNode)->Content();
|
|
|
|
|
return frag->GetFirstChild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return aNode->GetFirstChild();
|
|
|
|
|
}
|
|
|
|
|
|