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
|
|
|
|
|
|
|
#ifndef nsNodeUtils_h___
|
|
|
|
#define nsNodeUtils_h___
|
|
|
|
|
2016-03-21 11:49:50 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2012-08-06 16:02:08 +04:00
|
|
|
#include "nsIContent.h" // for use in inline function (ParentChainChanged)
|
|
|
|
#include "nsIMutationObserver.h" // for use in inline function (ParentChainChanged)
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2013-10-02 15:40:07 +04:00
|
|
|
#include "nsCOMArray.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
|
2010-04-19 19:40:15 +04:00
|
|
|
struct CharacterDataChangeInfo;
|
2006-09-05 14:22:54 +04:00
|
|
|
template<class E> class nsCOMArray;
|
2007-08-06 18:34:02 +04:00
|
|
|
class nsCycleCollectionTraversalCallback;
|
2015-03-14 08:34:40 +03:00
|
|
|
namespace mozilla {
|
2016-04-28 18:22:43 +03:00
|
|
|
struct NonOwningAnimationTarget;
|
2017-09-13 20:34:55 +03:00
|
|
|
class ErrorResult;
|
2015-03-14 08:34:40 +03:00
|
|
|
namespace dom {
|
2015-04-21 04:22:09 +03:00
|
|
|
class Animation;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
|
|
class nsNodeUtils
|
|
|
|
{
|
|
|
|
public:
|
2007-09-05 12:22:17 +04: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 11:23:10 +04:00
|
|
|
/**
|
|
|
|
* Send CharacterDataChanged notifications to nsIMutationObservers.
|
|
|
|
* @param aContent Node whose data changed
|
2006-11-04 00:51:01 +03:00
|
|
|
* @param aInfo Struct with information details about the change
|
2006-07-02 11:23:10 +04:00
|
|
|
* @see nsIMutationObserver::CharacterDataChanged
|
|
|
|
*/
|
2006-11-04 00:51:01 +03:00
|
|
|
static void CharacterDataChanged(nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo);
|
2006-07-02 11:23:10 +04:00
|
|
|
|
2009-06-29 22:36:25 +04:00
|
|
|
/**
|
|
|
|
* Send AttributeWillChange notifications to nsIMutationObservers.
|
2010-08-24 11:06:20 +04:00
|
|
|
* @param aElement Element whose data will change
|
2009-06-29 22:36:25 +04: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 06:53:35 +03:00
|
|
|
* @param aNewValue The parsed new value, but only if BeforeSetAttr
|
|
|
|
* preparsed it!!!
|
2009-06-29 22:36:25 +04:00
|
|
|
* @see nsIMutationObserver::AttributeWillChange
|
|
|
|
*/
|
2010-08-24 11:06:20 +04:00
|
|
|
static void 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-22 06:53:35 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue);
|
2009-06-29 22:36:25 +04:00
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
/**
|
|
|
|
* Send AttributeChanged notifications to nsIMutationObservers.
|
2010-08-24 11:06:07 +04:00
|
|
|
* @param aElement Element whose data changed
|
2006-07-02 11:23:10 +04: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 07:13:53 +03:00
|
|
|
* @param aOldValue If the old value was StoresOwnData() (or absent),
|
|
|
|
* that value, otherwise null
|
2006-07-02 11:23:10 +04:00
|
|
|
* @see nsIMutationObserver::AttributeChanged
|
|
|
|
*/
|
2010-08-24 11:06:07 +04:00
|
|
|
static void AttributeChanged(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-21 07:13:53 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue);
|
|
|
|
|
2012-08-15 14:06:01 +04: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 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute);
|
2006-07-02 11:23:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send ContentAppended notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node into which new child/children were added
|
2010-05-11 05:12:34 +04:00
|
|
|
* @param aFirstNewContent First new child
|
2006-07-02 11:23:10 +04:00
|
|
|
* @see nsIMutationObserver::ContentAppended
|
|
|
|
*/
|
|
|
|
static void ContentAppended(nsIContent* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
nsIContent* aFirstNewContent);
|
2006-07-02 11:23:10 +04:00
|
|
|
|
2015-09-24 18:23:32 +03: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 11:23:10 +04:00
|
|
|
/**
|
|
|
|
* Send ContentInserted notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node into which new child was inserted
|
|
|
|
* @param aChild Newly inserted child
|
|
|
|
* @see nsIMutationObserver::ContentInserted
|
|
|
|
*/
|
|
|
|
static void ContentInserted(nsINode* aContainer,
|
2017-07-27 16:49:52 +03:00
|
|
|
nsIContent* aChild);
|
2006-07-02 11:23:10 +04:00
|
|
|
/**
|
|
|
|
* Send ContentRemoved notifications to nsIMutationObservers
|
|
|
|
* @param aContainer Node from which child was removed
|
|
|
|
* @param aChild Removed child
|
2017-07-27 16:49:52 +03:00
|
|
|
* @param aPreviousSibling Previous sibling of the removed child
|
2006-07-02 11:23:10 +04:00
|
|
|
* @see nsIMutationObserver::ContentRemoved
|
|
|
|
*/
|
|
|
|
static void ContentRemoved(nsINode* aContainer,
|
|
|
|
nsIContent* aChild,
|
2010-07-22 02:05:17 +04:00
|
|
|
nsIContent* aPreviousSibling);
|
2007-03-10 16:49:43 +03:00
|
|
|
/**
|
|
|
|
* Send ParentChainChanged notifications to nsIMutationObservers
|
|
|
|
* @param aContent The piece of content that had its parent changed.
|
|
|
|
* @see nsIMutationObserver::ParentChainChanged
|
|
|
|
*/
|
2012-03-22 08:10:51 +04:00
|
|
|
static inline void ParentChainChanged(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
nsINode::nsSlots* slots = aContent->GetExistingSlots();
|
|
|
|
if (slots && !slots->mMutationObservers.IsEmpty()) {
|
2017-07-29 08:07:05 +03:00
|
|
|
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
|
|
|
nsIMutationObserver, 1,
|
|
|
|
ParentChainChanged,
|
|
|
|
(aContent));
|
2012-03-22 08:10:51 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-16 12:44:45 +04:00
|
|
|
|
2016-03-21 11:49:50 +03: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 09:16:18 +03:00
|
|
|
GetTargetForAnimation(const mozilla::dom::Animation* aAnimation);
|
2016-03-21 11:49:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify that an animation is added/changed/removed.
|
|
|
|
* @param aAnimation The animation we added/changed/removed.
|
|
|
|
*/
|
2015-04-21 04:22:10 +03: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 08:34:40 +03:00
|
|
|
|
2006-08-16 12:44:45 +04: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 19:36:28 +04:00
|
|
|
static void LastRelease(nsINode* aNode);
|
2006-09-05 14:22:54 +04:00
|
|
|
|
|
|
|
/**
|
2011-10-17 18:59:28 +04:00
|
|
|
* Clones aNode, its attributes and, if aDeep is true, its descendant nodes
|
2006-09-05 14:22:54 +04: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 18:59:28 +04:00
|
|
|
* @param aDeep If true the function will be called recursively on
|
2006-09-05 14:22:54 +04: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
|
2017-06-21 21:55:04 +03:00
|
|
|
* be followed by its clone. Null can be passed to
|
|
|
|
* prevent this from being used.
|
2017-09-13 20:34:55 +03:00
|
|
|
* @param aError The error, if any.
|
|
|
|
*
|
|
|
|
* @return The newly created node. Null in error conditions.
|
2006-09-05 14:22:54 +04:00
|
|
|
*/
|
2017-09-13 20:34:55 +03:00
|
|
|
static already_AddRefed<nsINode> Clone(nsINode *aNode, bool aDeep,
|
|
|
|
nsNodeInfoManager *aNewNodeInfoManager,
|
|
|
|
nsCOMArray<nsINode> *aNodesWithProperties,
|
|
|
|
mozilla::ErrorResult& aError)
|
2006-09-05 14:22:54 +04:00
|
|
|
{
|
2013-04-08 21:24:21 +04:00
|
|
|
return CloneAndAdopt(aNode, true, aDeep, aNewNodeInfoManager,
|
2017-09-13 20:34:55 +03:00
|
|
|
nullptr, aNodesWithProperties, nullptr, aError);
|
2012-11-01 22:18:08 +04:00
|
|
|
}
|
|
|
|
|
2006-09-05 14:22:54 +04: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 21:24:21 +04:00
|
|
|
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
|
2006-09-05 14:22:54 +04: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 21:24:21 +04:00
|
|
|
* @param aReparentScope New scope for the wrappers, or null if no reparenting
|
|
|
|
* should be done.
|
2006-09-05 14:22:54 +04:00
|
|
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
|
|
|
* descendants) with properties.
|
2017-09-13 20:34:55 +03:00
|
|
|
* @param aError The error, if any.
|
2006-09-05 14:22:54 +04:00
|
|
|
*/
|
2017-09-13 20:34:55 +03:00
|
|
|
static void Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
|
|
|
|
JS::Handle<JSObject*> aReparentScope,
|
|
|
|
nsCOMArray<nsINode>& aNodesWithProperties,
|
|
|
|
mozilla::ErrorResult& aError)
|
2006-09-05 14:22:54 +04:00
|
|
|
{
|
2017-09-13 20:34:55 +03:00
|
|
|
// Just need to store the return value of CloneAndAdopt in a
|
|
|
|
// temporary nsCOMPtr to make sure we release it.
|
|
|
|
nsCOMPtr<nsINode> node = CloneAndAdopt(aNode, false, true, aNewNodeInfoManager,
|
|
|
|
aReparentScope, &aNodesWithProperties,
|
|
|
|
nullptr, aError);
|
2010-03-18 23:03:52 +03:00
|
|
|
|
|
|
|
nsMutationGuard::DidMutate();
|
2006-09-05 14:22:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-11 14:22:30 +04:00
|
|
|
* Helper for the cycle collector to traverse the DOM UserData for aNode.
|
2006-09-05 14:22:54 +04:00
|
|
|
*
|
2014-09-11 14:22:30 +04:00
|
|
|
* @param aNode the node to traverse UserData for
|
2007-05-12 19:36:28 +04:00
|
|
|
* @param aCb the cycle collection callback
|
|
|
|
*/
|
|
|
|
static void TraverseUserData(nsINode* aNode,
|
|
|
|
nsCycleCollectionTraversalCallback &aCb);
|
|
|
|
|
2006-09-05 14:22:54 +04: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
|
2017-09-13 20:34:55 +03:00
|
|
|
* @param aError the error, if any.
|
|
|
|
*
|
|
|
|
* @return the clone, or null if an error occurs.
|
2006-09-05 14:22:54 +04:00
|
|
|
*/
|
2017-09-13 20:34:55 +03:00
|
|
|
static already_AddRefed<nsINode> CloneNodeImpl(nsINode *aNode, bool aDeep,
|
|
|
|
mozilla::ErrorResult& aError);
|
2006-09-05 14:22:54 +04:00
|
|
|
|
2007-05-12 19:36:28 +04:00
|
|
|
/**
|
2014-09-11 14:22:30 +04:00
|
|
|
* Release the UserData for aNode.
|
2007-05-12 19:36:28 +04:00
|
|
|
*
|
2014-09-11 14:22:30 +04:00
|
|
|
* @param aNode the node to release the UserData for
|
2007-05-12 19:36:28 +04:00
|
|
|
*/
|
|
|
|
static void UnlinkUserData(nsINode *aNode);
|
|
|
|
|
2013-03-26 11:15:23 +04: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 14:22:54 +04:00
|
|
|
private:
|
|
|
|
/**
|
2011-10-17 18:59:28 +04: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 14:22:54 +04:00
|
|
|
* not null, it is used to create new nodeinfos for the nodes. Also reparents
|
2013-04-08 21:24:21 +04:00
|
|
|
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
|
2006-09-05 14:22:54 +04:00
|
|
|
* aNodesWithProperties will be filled with all the nodes that have
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* @param aNode Node to adopt/clone.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aClone If true the node will be cloned and the cloned node will
|
2017-09-13 20:34:55 +03:00
|
|
|
* be returned.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aDeep If true the function will be called recursively on
|
2006-09-05 14:22:54 +04: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 21:24:21 +04:00
|
|
|
* @param aReparentScope Scope into which wrappers should be reparented, or
|
|
|
|
* null if no reparenting should be done.
|
2006-09-05 14:22:54 +04:00
|
|
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
|
|
|
* descendants) with properties. If aClone is
|
2011-10-17 18:59:28 +04:00
|
|
|
* true every node will be followed by its
|
2017-06-21 21:55:04 +03:00
|
|
|
* clone. Null can be passed to prevent this from
|
|
|
|
* being populated.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aParent If aClone is true the cloned node will be appended to
|
2009-09-29 00:33:29 +04:00
|
|
|
* aParent's children. May be null. If not null then aNode
|
|
|
|
* must be an nsIContent.
|
2017-09-13 20:34:55 +03:00
|
|
|
* @param aError The error, if any.
|
|
|
|
*
|
|
|
|
* @return If aClone is true then the cloned node will be returned,
|
|
|
|
* unless an error occurred. In error conditions, null
|
|
|
|
* will be returned.
|
2009-09-29 00:33:29 +04:00
|
|
|
*/
|
2017-09-13 20:34:55 +03:00
|
|
|
static already_AddRefed<nsINode>
|
|
|
|
CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
|
|
|
|
nsNodeInfoManager* aNewNodeInfoManager,
|
|
|
|
JS::Handle<JSObject*> aReparentScope,
|
|
|
|
nsCOMArray<nsINode>* aNodesWithProperties,
|
|
|
|
nsINode *aParent, mozilla::ErrorResult& aError);
|
2016-03-21 11:49:50 +03: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 11:23:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsNodeUtils_h___
|