2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
2000-05-08 14:29:44 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
2000-05-08 14:29:44 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-05-08 14:29:44 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-05-08 14:29:44 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2001-08-14 07:59:59 +00:00
|
|
|
#include "nscore.h"
|
2000-05-08 14:29:44 +00:00
|
|
|
#include "nsNodeInfo.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
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 16:46:42 +00:00
|
|
|
#include "domstubs.h" // for SetDOMStringToNull();
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2002-11-29 23:44:07 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
nsNodeInfo::nsNodeInfo()
|
2002-01-03 04:51:02 +00:00
|
|
|
: nsINodeInfo(), mOwnerManager(nsnull)
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2002-09-07 17:13:19 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsNodeInfo::~nsNodeInfo()
|
|
|
|
{
|
|
|
|
if (mOwnerManager) {
|
|
|
|
mOwnerManager->RemoveNodeInfo(this);
|
|
|
|
NS_RELEASE(mOwnerManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mInner.mName);
|
|
|
|
NS_IF_RELEASE(mInner.mPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNodeInfo::Init(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID,
|
|
|
|
nsNodeInfoManager *aOwnerManager)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(!mInner.mName && !mInner.mPrefix && !mOwnerManager,
|
|
|
|
NS_ERROR_ALREADY_INITIALIZED);
|
|
|
|
NS_ENSURE_ARG_POINTER(aName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aOwnerManager);
|
|
|
|
|
|
|
|
mInner.mName = aName;
|
|
|
|
NS_ADDREF(mInner.mName);
|
|
|
|
|
|
|
|
mInner.mPrefix = aPrefix;
|
|
|
|
NS_IF_ADDREF(mInner.mPrefix);
|
|
|
|
|
|
|
|
mInner.mNamespaceID = aNamespaceID;
|
|
|
|
|
|
|
|
mOwnerManager = aOwnerManager;
|
|
|
|
NS_ADDREF(mOwnerManager);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsNodeInfo, nsINodeInfo);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
// nsINodeInfo
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetQualifiedName(nsAString& aQualifiedName) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2000-08-31 00:36:31 +00:00
|
|
|
if (mInner.mPrefix) {
|
2000-05-08 14:29:44 +00:00
|
|
|
mInner.mPrefix->ToString(aQualifiedName);
|
|
|
|
|
2000-05-16 14:43:32 +00:00
|
|
|
aQualifiedName.Append(PRUnichar(':'));
|
2001-10-08 22:37:23 +00:00
|
|
|
} else {
|
|
|
|
aQualifiedName.Truncate();
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
2000-05-25 23:48:45 +00:00
|
|
|
const PRUnichar *name;
|
|
|
|
mInner.mName->GetUnicode(&name);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2000-05-25 23:48:45 +00:00
|
|
|
aQualifiedName.Append(name);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetLocalName(nsAString& aLocalName) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2000-05-16 02:17:14 +00:00
|
|
|
#ifdef STRICT_DOM_LEVEL2_LOCALNAME
|
2000-05-08 14:29:44 +00:00
|
|
|
if (mInner.mNamespaceID > 0) {
|
|
|
|
return mInner.mName->ToString(aLocalName);
|
|
|
|
}
|
|
|
|
|
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 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aLocalName);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-16 02:17:14 +00:00
|
|
|
#else
|
|
|
|
return mInner.mName->ToString(aLocalName);
|
|
|
|
#endif
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetNamespaceURI(nsAString& aNameSpaceURI) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mInner.mNamespaceID > 0) {
|
2002-11-29 23:44:07 +00:00
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceURI(mInner.mNamespaceID,
|
|
|
|
aNameSpaceURI);
|
2000-05-08 14:29:44 +00:00
|
|
|
} else {
|
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 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aNameSpaceURI);
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2002-01-03 04:51:02 +00:00
|
|
|
*aResult = mIDAttributeAtom;
|
2000-09-01 02:21:06 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
2000-08-30 00:35:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aID);
|
2002-01-03 04:51:02 +00:00
|
|
|
mIDAttributeAtom = aID;
|
2000-08-30 00:35:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
|
|
|
aNodeInfoManager = mOwnerManager;
|
|
|
|
|
|
|
|
NS_ADDREF(aNodeInfoManager);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-31 00:36:31 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::Equals(const nsAString& aName) const
|
2000-05-14 18:34:35 +00:00
|
|
|
{
|
|
|
|
const PRUnichar *name;
|
|
|
|
mInner.mName->GetUnicode(&name);
|
|
|
|
|
|
|
|
return aName.Equals(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2002-01-03 04:51:02 +00:00
|
|
|
const PRUnichar *name;
|
2000-05-14 18:34:35 +00:00
|
|
|
mInner.mName->GetUnicode(&name);
|
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
if (!aName.Equals(name)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
if (!mInner.mPrefix) {
|
|
|
|
return aPrefix.IsEmpty();
|
|
|
|
}
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
mInner.mPrefix->GetUnicode(&name);
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
return aPrefix.Equals(name);
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-14 18:34:35 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::Equals(const nsAString& aName, PRInt32 aNamespaceID) const
|
2000-05-14 18:34:35 +00:00
|
|
|
{
|
|
|
|
const PRUnichar *name;
|
|
|
|
mInner.mName->GetUnicode(&name);
|
|
|
|
|
|
|
|
return aName.Equals(name) && (mInner.mNamespaceID == aNamespaceID);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix,
|
|
|
|
PRInt32 aNamespaceID) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2002-01-03 04:51:02 +00:00
|
|
|
PRUnichar nullChar = '\0';
|
|
|
|
const PRUnichar *name, *prefix = &nullChar;
|
2000-05-14 18:34:35 +00:00
|
|
|
mInner.mName->GetUnicode(&name);
|
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
if (mInner.mPrefix) {
|
2000-05-14 18:34:35 +00:00
|
|
|
mInner.mPrefix->GetUnicode(&prefix);
|
2002-01-03 04:51:02 +00:00
|
|
|
}
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
return ((mInner.mNamespaceID == aNamespaceID) && aName.Equals(name) &&
|
|
|
|
aPrefix.Equals(prefix));
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-14 18:34:35 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
|
2000-05-14 18:34:35 +00:00
|
|
|
{
|
|
|
|
PRInt32 nsid;
|
2002-11-29 23:44:07 +00:00
|
|
|
nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI, nsid);
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
return nsINodeInfo::NamespaceEquals(nsid);
|
2000-05-14 18:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-31 00:36:31 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::QualifiedNameEquals(const nsAString& aQualifiedName) const
|
2000-08-31 00:36:31 +00:00
|
|
|
{
|
2002-01-03 04:51:02 +00:00
|
|
|
const PRUnichar *name;
|
|
|
|
mInner.mName->GetUnicode(&name);
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
if (!mInner.mPrefix) {
|
|
|
|
return aQualifiedName.Equals(name);
|
|
|
|
}
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
nsAString::const_iterator start;
|
|
|
|
aQualifiedName.BeginReading(start);
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
nsAString::const_iterator colon(start);
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
const PRUnichar *prefix;
|
|
|
|
mInner.mPrefix->GetUnicode(&prefix);
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
PRUint32 len = nsCRT::strlen(prefix);
|
|
|
|
|
|
|
|
if (len >= aQualifiedName.Length()) {
|
|
|
|
return PR_FALSE;
|
2000-08-31 00:36:31 +00:00
|
|
|
}
|
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
colon.advance(len);
|
|
|
|
|
|
|
|
// If the character at the prefix length index is not a colon,
|
|
|
|
// aQualifiedName is not equal to this string.
|
|
|
|
if (*colon != ':') {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
// Compare the prefix to the string from the start to the colon
|
|
|
|
if (!Substring(start, colon).Equals(prefix)) {
|
2000-08-31 00:36:31 +00:00
|
|
|
return PR_FALSE;
|
2002-01-03 04:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++colon; // Skip the ':'
|
2000-08-31 00:36:31 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
nsAString::const_iterator end;
|
|
|
|
aQualifiedName.EndReading(end);
|
|
|
|
|
|
|
|
// Compare the local name to the string between the colon and the
|
|
|
|
// end of aQualifiedName
|
|
|
|
return Substring(colon, end).Equals(name);
|
2000-08-31 00:36:31 +00:00
|
|
|
}
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNodeInfo::NameChanged(nsIAtom *aName, nsINodeInfo*& aResult)
|
|
|
|
{
|
|
|
|
return mOwnerManager->GetNodeInfo(aName, mInner.mPrefix, mInner.mNamespaceID,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNodeInfo::PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult)
|
|
|
|
{
|
|
|
|
return mOwnerManager->GetNodeInfo(mInner.mName, aPrefix, mInner.mNamespaceID,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
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 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfo::GetDocument(nsIDocument*& aDocument) const
|
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 16:46:42 +00:00
|
|
|
{
|
|
|
|
return mOwnerManager->GetDocument(aDocument);
|
|
|
|
}
|
|
|
|
|
2002-07-30 21:26:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNodeInfo::GetDocumentPrincipal(nsIPrincipal** aPrincipal) const
|
|
|
|
{
|
|
|
|
return mOwnerManager->GetDocumentPrincipal(aPrincipal);
|
|
|
|
}
|