2015-05-03 19:32:37 +00: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 11:12:37 +00: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 07:23:10 +00:00
|
|
|
|
|
|
|
#ifndef nsNodeUtils_h___
|
|
|
|
#define nsNodeUtils_h___
|
|
|
|
|
2016-03-21 08:49:50 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2012-08-06 12:02:08 +00:00
|
|
|
#include "nsIContent.h" // for use in inline function (ParentChainChanged)
|
|
|
|
#include "nsIMutationObserver.h" // for use in inline function (ParentChainChanged)
|
2013-08-28 02:59:14 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2013-10-02 11:40:07 +00:00
|
|
|
#include "nsCOMArray.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
|
2010-04-19 15:40:15 +00:00
|
|
|
struct CharacterDataChangeInfo;
|
2006-09-05 10:22:54 +00:00
|
|
|
template<class E> class nsCOMArray;
|
2007-08-06 14:34:02 +00:00
|
|
|
class nsCycleCollectionTraversalCallback;
|
2015-03-14 05:34:40 +00:00
|
|
|
namespace mozilla {
|
2016-04-28 15:22:43 +00:00
|
|
|
struct NonOwningAnimationTarget;
|
2015-03-14 05:34:40 +00:00
|
|
|
namespace dom {
|
2015-04-21 01:22:09 +00:00
|
|
|
class Animation;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2006-07-02 07:23:10 +00:00
|
|
|
|
|
|
|
class nsNodeUtils
|
|
|
|
{
|
|
|
|
public:
|
2007-09-05 08:22:17 +00:00
|
|
|
/**
|
|
|
|
* Send CharacterDataWillChange notifications to nsIMutationObservers.
|
|
|
|
* @param aContent Node whose data changed
|
|
|
|
* @param aInfo Struct with information details about the change
|
|
|
|
* @see nsIMutationObserver::CharacterDataWillChange
|
|
|
|
*/
|
|
|
|
static void CharacterDataWillChange(nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo);
|
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
/**
|
|
|
|
* Send CharacterDataChanged notifications to nsIMutationObservers.
|
|
|
|
* @param aContent Node whose data changed
|
2006-11-03 21:51:01 +00:00
|
|
|
* @param aInfo Struct with information details about the change
|
2006-07-02 07:23:10 +00:00
|
|
|
* @see nsIMutationObserver::CharacterDataChanged
|
|
|
|
*/
|
2006-11-03 21:51:01 +00:00
|
|
|
static void CharacterDataChanged(nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo);
|
2006-07-02 07:23:10 +00:00
|
|
|
|
2009-06-29 18:36:25 +00:00
|
|
|
/**
|
|
|
|
* Send AttributeWillChange notifications to nsIMutationObservers.
|
2010-08-24 07:06:20 +00:00
|
|
|
* @param aElement Element whose data will change
|
2009-06-29 18:36:25 +00:00
|
|
|
* @param aNameSpaceID Namespace of changing attribute
|
|
|
|
* @param aAttribute Local-name of changing attribute
|
|
|
|
* @param aModType Type of change (add/change/removal)
|
2015-07-22 03:53:35 +00:00
|
|
|
* @param aNewValue The parsed new value, but only if BeforeSetAttr
|
|
|
|
* preparsed it!!!
|
2009-06-29 18:36:25 +00:00
|
|
|
* @see nsIMutationObserver::AttributeWillChange
|
|
|
|
*/
|
2010-08-24 07:06:20 +00:00
|
|
|
static void AttributeWillChange(mozilla::dom::Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID,
|
2009-06-29 18:36:25 +00:00
|
|
|
nsIAtom* aAttribute,
|
2015-07-22 03:53:35 +00:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue);
|
2009-06-29 18:36:25 +00:00
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
/**
|
|
|
|
* Send AttributeChanged notifications to nsIMutationObservers.
|
2010-08-24 07:06:07 +00:00
|
|
|
* @param aElement Element whose data changed
|
2006-07-02 07:23:10 +00:00
|
|
|
* @param aNameSpaceID Namespace of changed attribute
|
|
|
|
* @param aAttribute Local-name of changed attribute
|
|
|
|
* @param aModType Type of change (add/change/removal)
|
2015-07-21 04:13:53 +00:00
|
|
|
* @param aOldValue If the old value was StoresOwnData() (or absent),
|
|
|
|
* that value, otherwise null
|
2006-07-02 07:23:10 +00:00
|
|
|
* @see nsIMutationObserver::AttributeChanged
|
|
|
|
*/
|
2010-08-24 07:06:07 +00:00
|
|
|
static void AttributeChanged(mozilla::dom::Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID,
|
2006-07-02 07:23:10 +00:00
|
|
|
nsIAtom* aAttribute,
|
2015-07-21 04:13:53 +00:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue);
|
|
|
|
|
2012-08-15 10:06:01 +00:00
|
|
|
/**
|
|
|
|
* Send AttributeSetToCurrentValue notifications to nsIMutationObservers.
|
|
|
|
* @param aElement Element whose data changed
|
|
|
|
* @param aNameSpaceID Namespace of the attribute
|
|
|
|
* @param aAttribute Local-name of the attribute
|
|
|
|
* @see nsIMutationObserver::AttributeSetToCurrentValue
|
|
|
|
*/
|
|
|
|
static void AttributeSetToCurrentValue(mozilla::dom::Element* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNameSpaceID,
|
2012-08-15 10:06:01 +00:00
|
|
|
nsIAtom* aAttribute);
|
2006-07-02 07:23:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send ContentAppended notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node into which new child/children were added
|
2010-05-11 01:12:34 +00:00
|
|
|
* @param aFirstNewContent First new child
|
2006-07-02 07:23:10 +00:00
|
|
|
* @param aNewIndexInContainer Index of first new child
|
|
|
|
* @see nsIMutationObserver::ContentAppended
|
|
|
|
*/
|
|
|
|
static void ContentAppended(nsIContent* aContainer,
|
2010-05-11 01:12:34 +00:00
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNewIndexInContainer);
|
2006-07-02 07:23:10 +00:00
|
|
|
|
2015-09-24 15:23:32 +00:00
|
|
|
/**
|
|
|
|
* Send NativeAnonymousChildList notifications to nsIMutationObservers
|
|
|
|
* @param aContent Anonymous node that's been added or removed
|
|
|
|
* @param aIsRemove True if it's a removal, false if an addition
|
|
|
|
* @see nsIMutationObserver::NativeAnonymousChildListChange
|
|
|
|
*/
|
|
|
|
static void NativeAnonymousChildListChange(nsIContent* aContent,
|
|
|
|
bool aIsRemove);
|
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
/**
|
|
|
|
* Send ContentInserted notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node into which new child was inserted
|
|
|
|
* @param aChild Newly inserted child
|
|
|
|
* @param aIndexInContainer Index of new child
|
|
|
|
* @see nsIMutationObserver::ContentInserted
|
|
|
|
*/
|
|
|
|
static void ContentInserted(nsINode* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer);
|
2006-07-02 07:23:10 +00:00
|
|
|
/**
|
|
|
|
* Send ContentRemoved notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node from which child was removed
|
|
|
|
* @param aChild Removed child
|
|
|
|
* @param aIndexInContainer Index of removed child
|
|
|
|
* @see nsIMutationObserver::ContentRemoved
|
|
|
|
*/
|
|
|
|
static void ContentRemoved(nsINode* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndexInContainer,
|
2010-07-21 22:05:17 +00:00
|
|
|
nsIContent* aPreviousSibling);
|
2007-03-10 13:49:43 +00:00
|
|
|
/**
|
|
|
|
* Send ParentChainChanged notifications to nsIMutationObservers
|
|
|
|
* @param aContent The piece of content that had its parent changed.
|
|
|
|
* @see nsIMutationObserver::ParentChainChanged
|
|
|
|
*/
|
2012-03-22 04:10:51 +00:00
|
|
|
static inline void ParentChainChanged(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
nsINode::nsSlots* slots = aContent->GetExistingSlots();
|
|
|
|
if (slots && !slots->mMutationObservers.IsEmpty()) {
|
|
|
|
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
|
|
|
nsIMutationObserver,
|
|
|
|
ParentChainChanged,
|
|
|
|
(aContent));
|
|
|
|
}
|
|
|
|
}
|
2006-08-16 08:44:45 +00:00
|
|
|
|
2016-03-21 08:49:50 +00:00
|
|
|
/**
|
|
|
|
* Utility function to get the target (pseudo-)element associated with an
|
|
|
|
* animation.
|
|
|
|
* @param aAnimation The animation whose target is what we want.
|
|
|
|
*/
|
|
|
|
static mozilla::Maybe<mozilla::NonOwningAnimationTarget>
|
2015-10-22 06:16:18 +00:00
|
|
|
GetTargetForAnimation(const mozilla::dom::Animation* aAnimation);
|
2016-03-21 08:49:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify that an animation is added/changed/removed.
|
|
|
|
* @param aAnimation The animation we added/changed/removed.
|
|
|
|
*/
|
2015-04-21 01:22:10 +00:00
|
|
|
static void AnimationAdded(mozilla::dom::Animation* aAnimation);
|
|
|
|
static void AnimationChanged(mozilla::dom::Animation* aAnimation);
|
|
|
|
static void AnimationRemoved(mozilla::dom::Animation* aAnimation);
|
2015-03-14 05:34:40 +00:00
|
|
|
|
2006-08-16 08:44:45 +00:00
|
|
|
/**
|
|
|
|
* To be called when reference count of aNode drops to zero.
|
|
|
|
* @param aNode The node which is going to be deleted.
|
|
|
|
*/
|
2007-05-12 15:36:28 +00:00
|
|
|
static void LastRelease(nsINode* aNode);
|
2006-09-05 10:22:54 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-17 14:59:28 +00:00
|
|
|
* Clones aNode, its attributes and, if aDeep is true, its descendant nodes
|
2006-09-05 10:22:54 +00:00
|
|
|
* If aNewNodeInfoManager is not null, it is used to create new nodeinfos for
|
|
|
|
* the clones. aNodesWithProperties will be filled with all the nodes that
|
|
|
|
* have properties, and every node in it will be followed by its clone.
|
|
|
|
*
|
|
|
|
* @param aNode Node to clone.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aDeep If true the function will be called recursively on
|
2006-09-05 10:22:54 +00:00
|
|
|
* descendants of the node
|
|
|
|
* @param aNewNodeInfoManager The nodeinfo manager to use to create new
|
|
|
|
* nodeinfos for aNode and its attributes and
|
|
|
|
* descendants. May be null if the nodeinfos
|
|
|
|
* shouldn't be changed.
|
|
|
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
|
|
|
* descendants) with properties. Every node will
|
|
|
|
* be followed by its clone.
|
|
|
|
* @param aResult *aResult will contain the cloned node.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static nsresult Clone(nsINode *aNode, bool aDeep,
|
2006-09-05 10:22:54 +00:00
|
|
|
nsNodeInfoManager *aNewNodeInfoManager,
|
|
|
|
nsCOMArray<nsINode> &aNodesWithProperties,
|
2012-10-09 12:31:24 +00:00
|
|
|
nsINode **aResult)
|
2006-09-05 10:22:54 +00:00
|
|
|
{
|
2013-04-08 17:24:21 +00:00
|
|
|
return CloneAndAdopt(aNode, true, aDeep, aNewNodeInfoManager,
|
2015-05-13 21:07:34 +00:00
|
|
|
nullptr, aNodesWithProperties, nullptr, aResult);
|
2006-09-05 10:22:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 18:18:08 +00:00
|
|
|
/**
|
|
|
|
* Clones aNode, its attributes and, if aDeep is true, its descendant nodes
|
|
|
|
*/
|
|
|
|
static nsresult Clone(nsINode *aNode, bool aDeep, nsINode **aResult)
|
|
|
|
{
|
|
|
|
nsCOMArray<nsINode> dummyNodeWithProperties;
|
2015-05-13 21:07:34 +00:00
|
|
|
return CloneAndAdopt(aNode, true, aDeep, nullptr, nullptr,
|
2012-11-01 18:18:08 +00:00
|
|
|
dummyNodeWithProperties, aNode->GetParent(), aResult);
|
|
|
|
}
|
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
/**
|
|
|
|
* Walks aNode, its attributes and descendant nodes. If aNewNodeInfoManager is
|
|
|
|
* not null, it is used to create new nodeinfos for the nodes. Also reparents
|
2013-04-08 17:24:21 +00:00
|
|
|
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
|
2006-09-05 10:22:54 +00:00
|
|
|
* aNodesWithProperties will be filled with all the nodes that have
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* @param aNode Node to adopt.
|
|
|
|
* @param aNewNodeInfoManager The nodeinfo manager to use to create new
|
|
|
|
* nodeinfos for aNode and its attributes and
|
|
|
|
* descendants. May be null if the nodeinfos
|
|
|
|
* shouldn't be changed.
|
2013-04-08 17:24:21 +00:00
|
|
|
* @param aReparentScope New scope for the wrappers, or null if no reparenting
|
|
|
|
* should be done.
|
2006-09-05 10:22:54 +00:00
|
|
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
|
|
|
* descendants) with properties.
|
|
|
|
*/
|
|
|
|
static nsresult Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
|
2013-05-08 02:34:56 +00:00
|
|
|
JS::Handle<JSObject*> aReparentScope,
|
2006-09-05 10:22:54 +00:00
|
|
|
nsCOMArray<nsINode> &aNodesWithProperties)
|
|
|
|
{
|
2012-10-09 12:31:24 +00:00
|
|
|
nsCOMPtr<nsINode> node;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsresult rv = CloneAndAdopt(aNode, false, true, aNewNodeInfoManager,
|
2013-04-08 17:24:21 +00:00
|
|
|
aReparentScope, aNodesWithProperties,
|
2012-10-09 12:31:24 +00:00
|
|
|
nullptr, getter_AddRefs(node));
|
2010-03-18 20:03:52 +00:00
|
|
|
|
|
|
|
nsMutationGuard::DidMutate();
|
2010-03-17 14:40:35 +00:00
|
|
|
|
|
|
|
return rv;
|
2006-09-05 10:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-11 10:22:30 +00:00
|
|
|
* Helper for the cycle collector to traverse the DOM UserData for aNode.
|
2006-09-05 10:22:54 +00:00
|
|
|
*
|
2014-09-11 10:22:30 +00:00
|
|
|
* @param aNode the node to traverse UserData for
|
2007-05-12 15:36:28 +00:00
|
|
|
* @param aCb the cycle collection callback
|
|
|
|
*/
|
|
|
|
static void TraverseUserData(nsINode* aNode,
|
|
|
|
nsCycleCollectionTraversalCallback &aCb);
|
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
/**
|
|
|
|
* A basic implementation of the DOM cloneNode method. Calls nsINode::Clone to
|
|
|
|
* do the actual cloning of the node.
|
|
|
|
*
|
|
|
|
* @param aNode the node to clone
|
|
|
|
* @param aDeep if true all descendants will be cloned too
|
|
|
|
* @param aResult the clone
|
|
|
|
*/
|
2014-09-11 10:22:30 +00:00
|
|
|
static nsresult CloneNodeImpl(nsINode *aNode, bool aDeep, nsINode **aResult);
|
2006-09-05 10:22:54 +00:00
|
|
|
|
2007-05-12 15:36:28 +00:00
|
|
|
/**
|
2014-09-11 10:22:30 +00:00
|
|
|
* Release the UserData for aNode.
|
2007-05-12 15:36:28 +00:00
|
|
|
*
|
2014-09-11 10:22:30 +00:00
|
|
|
* @param aNode the node to release the UserData for
|
2007-05-12 15:36:28 +00:00
|
|
|
*/
|
|
|
|
static void UnlinkUserData(nsINode *aNode);
|
|
|
|
|
2013-03-26 07:15:23 +00:00
|
|
|
/**
|
|
|
|
* Returns a true if the node is a HTMLTemplate element.
|
|
|
|
*
|
|
|
|
* @param aNode a node to test for HTMLTemplate elementness.
|
|
|
|
*/
|
|
|
|
static bool IsTemplateElement(const nsINode *aNode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the first child of a node or the first child of
|
|
|
|
* a template element's content if the provided node is a
|
|
|
|
* template element.
|
|
|
|
*
|
|
|
|
* @param aNode A node from which to retrieve the first child.
|
|
|
|
*/
|
|
|
|
static nsIContent* GetFirstChildOfTemplateOrNode(nsINode* aNode);
|
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
private:
|
|
|
|
/**
|
2011-10-17 14:59:28 +00:00
|
|
|
* Walks aNode, its attributes and, if aDeep is true, its descendant nodes.
|
|
|
|
* If aClone is true the nodes will be cloned. If aNewNodeInfoManager is
|
2006-09-05 10:22:54 +00:00
|
|
|
* not null, it is used to create new nodeinfos for the nodes. Also reparents
|
2013-04-08 17:24:21 +00:00
|
|
|
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
|
2006-09-05 10:22:54 +00:00
|
|
|
* aNodesWithProperties will be filled with all the nodes that have
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* @param aNode Node to adopt/clone.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aClone If true the node will be cloned and the cloned node will
|
2006-09-05 10:22:54 +00:00
|
|
|
* be in aResult.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aDeep If true the function will be called recursively on
|
2006-09-05 10:22:54 +00:00
|
|
|
* descendants of the node
|
|
|
|
* @param aNewNodeInfoManager The nodeinfo manager to use to create new
|
|
|
|
* nodeinfos for aNode and its attributes and
|
|
|
|
* descendants. May be null if the nodeinfos
|
|
|
|
* shouldn't be changed.
|
2013-04-08 17:24:21 +00:00
|
|
|
* @param aReparentScope Scope into which wrappers should be reparented, or
|
|
|
|
* null if no reparenting should be done.
|
2006-09-05 10:22:54 +00:00
|
|
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
|
|
|
* descendants) with properties. If aClone is
|
2011-10-17 14:59:28 +00:00
|
|
|
* true every node will be followed by its
|
2006-09-05 10:22:54 +00:00
|
|
|
* clone.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aParent If aClone is true the cloned node will be appended to
|
2009-09-28 20:33:29 +00:00
|
|
|
* aParent's children. May be null. If not null then aNode
|
|
|
|
* must be an nsIContent.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aResult If aClone is true then *aResult will contain the cloned
|
2009-10-16 14:00:38 +00:00
|
|
|
* node.
|
2009-09-28 20:33:29 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static nsresult CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
|
2009-09-28 20:33:29 +00:00
|
|
|
nsNodeInfoManager *aNewNodeInfoManager,
|
2013-05-08 02:34:56 +00:00
|
|
|
JS::Handle<JSObject*> aReparentScope,
|
2009-09-28 20:33:29 +00:00
|
|
|
nsCOMArray<nsINode> &aNodesWithProperties,
|
|
|
|
nsINode *aParent, nsINode **aResult);
|
2016-03-21 08:49:50 +00:00
|
|
|
|
|
|
|
enum class AnimationMutationType
|
|
|
|
{
|
|
|
|
Added,
|
|
|
|
Changed,
|
|
|
|
Removed
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Notify the observers of the target of an animation
|
|
|
|
* @param aAnimation The mutated animation.
|
|
|
|
* @param aMutationType The mutation type of this animation. It could be
|
|
|
|
* Added, Changed, or Removed.
|
|
|
|
*/
|
|
|
|
static void AnimationMutated(mozilla::dom::Animation* aAnimation,
|
|
|
|
AnimationMutationType aMutatedType);
|
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsNodeUtils_h___
|