2013-03-01 06:53:49 +04: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/. */
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
2014-06-20 06:01:40 +04:00
|
|
|
* Class that represents a prefix/namespace/localName triple; a single
|
|
|
|
* nodeinfo is shared by all elements in a document that have that
|
|
|
|
* prefix, namespace, and localName.
|
2000-05-08 18:29:44 +04:00
|
|
|
*
|
2014-06-20 06:01:40 +04:00
|
|
|
* nsNodeInfoManagers are internal objects that manage a list of
|
|
|
|
* NodeInfos, every document object should hold a strong reference to
|
|
|
|
* a nsNodeInfoManager and every NodeInfo also holds a strong reference
|
|
|
|
* to their owning manager. When a NodeInfo is no longer used it will
|
2000-05-08 18:29:44 +04:00
|
|
|
* automatically remove itself from its owner manager, and when all
|
2014-06-20 06:01:40 +04:00
|
|
|
* NodeInfos have been removed from a nsNodeInfoManager and all external
|
2004-06-25 16:26:02 +04:00
|
|
|
* references are released the nsNodeInfoManager deletes itself.
|
2000-05-08 18:29:44 +04:00
|
|
|
*/
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
#ifndef mozilla_dom_NodeInfo_h___
|
|
|
|
#define mozilla_dom_NodeInfo_h___
|
2006-07-27 21:54:38 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "mozilla/dom/NameSpaceConstants.h"
|
|
|
|
#include "nsStringGlue.h"
|
2015-04-18 22:07:35 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
class nsIAtom;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class nsIDocument;
|
2012-08-06 16:02:08 +04:00
|
|
|
class nsNodeInfoManager;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2003-11-15 08:27:37 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class NodeInfo final
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(NodeInfo)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_NATIVE_CLASS_WITH_CUSTOM_DELETE(NodeInfo)
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
/*
|
|
|
|
* Get the name from this node as a string, this does not include the prefix.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return "body" and for the XML
|
|
|
|
* element "<html:body>" this will return "body".
|
|
|
|
*/
|
2014-06-20 06:01:40 +04:00
|
|
|
void GetName(nsAString& aName) const;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the name from this node as an atom, this does not include the prefix.
|
|
|
|
* This function never returns a null atom.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return the "body" atom and for
|
|
|
|
* the XML element "<html:body>" this will return the "body" atom.
|
|
|
|
*/
|
2003-11-15 08:27:37 +03:00
|
|
|
nsIAtom* NameAtom() const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
2003-06-14 00:10:01 +04:00
|
|
|
return mInner.mName;
|
2002-01-03 07:51:02 +03:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the qualified name from this node as a string, the qualified name
|
|
|
|
* includes the prefix, if one exists.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return "body" and for the XML
|
|
|
|
* element "<html:body>" this will return "html:body".
|
|
|
|
*/
|
2011-05-05 20:26:33 +04:00
|
|
|
const nsString& QualifiedName() const {
|
|
|
|
return mQualifiedName;
|
2011-05-05 20:26:32 +04:00
|
|
|
}
|
|
|
|
|
2011-06-14 11:56:49 +04:00
|
|
|
/*
|
|
|
|
* Returns the node's nodeName as defined in DOM Core
|
|
|
|
*/
|
|
|
|
const nsString& NodeName() const {
|
|
|
|
return mNodeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the node's localName as defined in DOM Core
|
|
|
|
*/
|
|
|
|
const nsString& LocalName() const {
|
|
|
|
return mLocalName;
|
|
|
|
}
|
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
/*
|
|
|
|
* Get the prefix from this node as a string.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return a null string and for
|
|
|
|
* the XML element "<html:body>" this will return the string "html".
|
|
|
|
*/
|
2014-06-20 06:01:40 +04:00
|
|
|
void GetPrefix(nsAString& aPrefix) const;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the prefix from this node as an atom.
|
|
|
|
*
|
|
|
|
* For the HTML element "<body>" this will return a null atom and for
|
|
|
|
* the XML element "<html:body>" this will return the "html" atom.
|
|
|
|
*/
|
2003-11-15 08:27:37 +03:00
|
|
|
nsIAtom* GetPrefixAtom() const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
2003-06-14 00:10:01 +04:00
|
|
|
return mInner.mPrefix;
|
2002-01-03 07:51:02 +03:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the namespace URI for a node, if the node has a namespace URI.
|
|
|
|
*/
|
2014-06-20 06:01:40 +04:00
|
|
|
void GetNamespaceURI(nsAString& aNameSpaceURI) const;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the namespace ID for a node if the node has a namespace, if not this
|
|
|
|
* returns kNameSpaceID_None.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t NamespaceID() const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
2003-06-14 00:10:01 +04:00
|
|
|
return mInner.mNamespaceID;
|
2002-01-03 07:51:02 +03:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2011-06-14 11:56:49 +04:00
|
|
|
/*
|
|
|
|
* Get the nodetype for the node. Returns the values specified in nsIDOMNode
|
|
|
|
* for nsIDOMNode.nodeType
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t NodeType() const
|
2011-06-14 11:56:49 +04:00
|
|
|
{
|
|
|
|
return mInner.mNodeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the extra name, used by PIs and DocTypes, for the node.
|
|
|
|
*/
|
|
|
|
nsIAtom* GetExtraName() const
|
|
|
|
{
|
|
|
|
return mInner.mExtraName;
|
|
|
|
}
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
/**
|
|
|
|
* Get the owning node info manager. Only to be used inside Gecko, you can't
|
|
|
|
* really do anything with the pointer outside Gecko anyway.
|
2000-05-08 18:29:44 +04:00
|
|
|
*/
|
2014-06-20 06:01:40 +04:00
|
|
|
nsNodeInfoManager* NodeInfoManager() const
|
2003-11-15 08:27:37 +03:00
|
|
|
{
|
|
|
|
return mOwnerManager;
|
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
/*
|
2000-08-30 04:35:43 +04:00
|
|
|
* Utility functions that can be used to check if a nodeinfo holds a specific
|
2000-05-08 18:29:44 +04:00
|
|
|
* name, name and prefix, name and prefix and namespace ID, or just
|
|
|
|
* namespace ID.
|
|
|
|
*/
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool Equals(NodeInfo* aNodeInfo) const;
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool NameAndNamespaceEquals(NodeInfo* aNodeInfo) const;
|
2002-03-27 03:13:57 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool Equals(nsIAtom* aNameAtom) const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
return mInner.mName == aNameAtom;
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool Equals(nsIAtom* aNameAtom, nsIAtom* aPrefixAtom) const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom);
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool Equals(nsIAtom* aNameAtom, int32_t aNamespaceID) const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
return ((mInner.mName == aNameAtom) &&
|
|
|
|
(mInner.mNamespaceID == aNamespaceID));
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool Equals(nsIAtom* aNameAtom, nsIAtom* aPrefixAtom, int32_t aNamespaceID) const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
return ((mInner.mName == aNameAtom) &&
|
|
|
|
(mInner.mPrefix == aPrefixAtom) &&
|
|
|
|
(mInner.mNamespaceID == aNamespaceID));
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool NamespaceEquals(int32_t aNamespaceID) const
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
return mInner.mNamespaceID == aNamespaceID;
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool Equals(const nsAString& aName) const;
|
2011-05-05 20:26:33 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool Equals(const nsAString& aName, const nsAString& aPrefix) const;
|
2011-05-05 20:26:33 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool Equals(const nsAString& aName, int32_t aNamespaceID) const;
|
2011-05-05 20:26:33 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool Equals(const nsAString& aName, const nsAString& aPrefix, int32_t aNamespaceID) const;
|
2006-04-26 01:21:49 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool NamespaceEquals(const nsAString& aNamespaceURI) const;
|
2006-04-26 01:21:49 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
inline bool QualifiedNameEquals(nsIAtom* aNameAtom) const;
|
2006-04-26 01:21:49 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool QualifiedNameEquals(const nsAString& aQualifiedName) const
|
2006-04-26 01:21:49 +04:00
|
|
|
{
|
2011-05-05 20:26:32 +04:00
|
|
|
return mQualifiedName == aQualifiedName;
|
2006-04-26 01:21:49 +04:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
/*
|
|
|
|
* Retrieve a pointer to the document that owns this node info.
|
|
|
|
*/
|
2005-09-24 22:43:15 +04:00
|
|
|
nsIDocument* GetDocument() const
|
|
|
|
{
|
2011-06-15 04:58:57 +04:00
|
|
|
return mDocument;
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
NodeInfo() = delete;
|
|
|
|
NodeInfo(const NodeInfo& aOther) = delete;
|
2014-06-20 06:01:40 +04:00
|
|
|
|
|
|
|
// NodeInfo is only constructed by nsNodeInfoManager which is a friend class.
|
|
|
|
// aName and aOwnerManager may not be null.
|
|
|
|
NodeInfo(nsIAtom* aName, nsIAtom* aPrefix, int32_t aNamespaceID,
|
|
|
|
uint16_t aNodeType, nsIAtom* aExtraName,
|
|
|
|
nsNodeInfoManager* aOwnerManager);
|
|
|
|
|
|
|
|
~NodeInfo();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool CanSkip();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method gets called by the cycle collector when it's time to delete
|
|
|
|
* this object.
|
|
|
|
*/
|
|
|
|
void DeleteCycleCollectable();
|
|
|
|
|
2002-01-03 07:51:02 +03:00
|
|
|
protected:
|
|
|
|
/*
|
2014-06-20 06:01:40 +04:00
|
|
|
* NodeInfoInner is used for two things:
|
2002-01-03 07:51:02 +03:00
|
|
|
*
|
|
|
|
* 1. as a member in nsNodeInfo for holding the name, prefix and
|
|
|
|
* namespace ID
|
|
|
|
* 2. as the hash key in the hash table in nsNodeInfoManager
|
|
|
|
*
|
2014-06-20 06:01:40 +04:00
|
|
|
* NodeInfoInner does not do any kind of reference counting,
|
|
|
|
* that's up to the user of this class. Since NodeInfoInner is
|
|
|
|
* typically used as a member of NodeInfo, the hash table doesn't
|
|
|
|
* need to delete the keys. When the value (NodeInfo) is deleted
|
2002-01-03 07:51:02 +03:00
|
|
|
* the key is automatically deleted.
|
|
|
|
*/
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
class NodeInfoInner
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfoInner()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mName(nullptr), mPrefix(nullptr), mNamespaceID(kNameSpaceID_Unknown),
|
|
|
|
mNodeType(0), mNameString(nullptr), mExtraName(nullptr)
|
2010-07-23 13:49:57 +04:00
|
|
|
{
|
|
|
|
}
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aNodeType, nsIAtom* aExtraName)
|
2010-07-23 13:49:57 +04:00
|
|
|
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNodeType(aNodeType), mNameString(nullptr), mExtraName(aExtraName)
|
2010-07-23 13:49:57 +04:00
|
|
|
{
|
|
|
|
}
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfoInner(const nsAString& aTmpName, nsIAtom *aPrefix,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mName(nullptr), mPrefix(aPrefix), mNamespaceID(aNamespaceID),
|
|
|
|
mNodeType(aNodeType), mNameString(&aTmpName), mExtraName(nullptr)
|
2002-01-03 07:51:02 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-18 22:07:35 +03:00
|
|
|
// These atoms hold pointers to nsGkAtoms members, and are therefore safe
|
|
|
|
// as a non-owning reference.
|
|
|
|
nsIAtom* MOZ_NON_OWNING_REF mName;
|
|
|
|
nsIAtom* MOZ_NON_OWNING_REF mPrefix;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNamespaceID;
|
|
|
|
uint16_t mNodeType; // As defined by nsIDOMNode.nodeType
|
2010-07-23 13:49:57 +04:00
|
|
|
const nsAString* mNameString;
|
2015-04-18 22:07:35 +03:00
|
|
|
nsIAtom* MOZ_NON_OWNING_REF mExtraName; // Only used by PIs and DocTypes
|
2002-01-03 07:51:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// nsNodeInfoManager needs to pass mInner to the hash table.
|
2014-06-20 06:01:40 +04:00
|
|
|
friend class ::nsNodeInfoManager;
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2011-06-15 04:58:57 +04:00
|
|
|
nsIDocument* mDocument; // Weak. Cache of mOwnerManager->mDocument
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfoInner mInner;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-04-10 18:05:20 +04:00
|
|
|
nsRefPtr<nsNodeInfoManager> mOwnerManager;
|
2011-05-05 20:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Members for various functions of mName+mPrefix that we can be
|
|
|
|
* asked to compute.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Qualified name
|
|
|
|
nsString mQualifiedName;
|
|
|
|
|
2011-06-14 11:56:49 +04:00
|
|
|
// nodeName for the node.
|
|
|
|
nsString mNodeName;
|
|
|
|
|
|
|
|
// localName for the node. This is either equal to mInner.mName, or a
|
|
|
|
// void string, depending on mInner.mNodeType.
|
|
|
|
nsString mLocalName;
|
2000-05-08 18:29:44 +04:00
|
|
|
};
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2005-11-11 17:36:26 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
#endif /* mozilla_dom_NodeInfo_h___ */
|