2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-12 08:45:23 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-01-12 08:45:23 +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.
|
1999-01-12 08:45:23 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2005-06-01 13:46:20 +00:00
|
|
|
* Allan Beaufour <allan@beaufour.dk>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of 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"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-30 08:03:04 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-31 08:41:49 +00:00
|
|
|
* Implementation of the |attributes| property of DOM Core's nsIDOMNode object.
|
2006-03-30 08:03:04 +00:00
|
|
|
*/
|
|
|
|
|
1999-01-12 08:45:23 +00:00
|
|
|
#ifndef nsDOMAttributeMap_h___
|
|
|
|
#define nsDOMAttributeMap_h___
|
|
|
|
|
2005-06-01 13:46:20 +00:00
|
|
|
#include "nsIAtom.h"
|
1999-01-12 08:45:23 +00:00
|
|
|
#include "nsIDOMNamedNodeMap.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "plhash.h"
|
2005-06-01 13:46:20 +00:00
|
|
|
#include "nsInterfaceHashtable.h"
|
1999-01-12 08:45:23 +00:00
|
|
|
|
|
|
|
class nsIContent;
|
2005-06-01 13:46:20 +00:00
|
|
|
class nsDOMAttribute;
|
|
|
|
class nsINodeInfo;
|
2005-12-29 03:01:58 +00:00
|
|
|
class nsIDocument;
|
2005-06-01 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
2006-03-30 08:03:04 +00:00
|
|
|
* Structure used as a key for caching nsDOMAttributes in nsDOMAttributeMap's mAttributeCache.
|
2005-06-01 13:46:20 +00:00
|
|
|
*/
|
|
|
|
class nsAttrKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The namespace of the attribute
|
|
|
|
*/
|
|
|
|
PRInt32 mNamespaceID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The atom for attribute, weak ref. is fine as we only use it for the
|
|
|
|
* hashcode, we never dereference it.
|
|
|
|
*/
|
|
|
|
nsIAtom* mLocalName;
|
|
|
|
|
|
|
|
nsAttrKey(PRInt32 aNs, nsIAtom* aName)
|
|
|
|
: mNamespaceID(aNs), mLocalName(aName) {}
|
|
|
|
|
|
|
|
nsAttrKey(const nsAttrKey& aAttr)
|
|
|
|
: mNamespaceID(aAttr.mNamespaceID), mLocalName(aAttr.mLocalName) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PLDHashEntryHdr implementation for nsAttrKey.
|
|
|
|
*/
|
2005-06-01 14:50:34 +00:00
|
|
|
class nsAttrHashKey : public PLDHashEntryHdr
|
2005-06-01 13:46:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-06-09 20:17:40 +00:00
|
|
|
typedef const nsAttrKey& KeyType;
|
2005-06-01 13:46:20 +00:00
|
|
|
typedef const nsAttrKey* KeyTypePointer;
|
|
|
|
|
|
|
|
nsAttrHashKey(KeyTypePointer aKey) : mKey(*aKey) {}
|
|
|
|
nsAttrHashKey(const nsAttrHashKey& aCopy) : mKey(aCopy.mKey) {}
|
|
|
|
~nsAttrHashKey() {}
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mKey; }
|
|
|
|
KeyTypePointer GetKeyPointer() const { return &mKey; }
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const
|
|
|
|
{
|
|
|
|
return mKey.mLocalName == aKey->mLocalName &&
|
|
|
|
mKey.mNamespaceID == aKey->mNamespaceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
if (!aKey)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (aKey->mNamespaceID >> 28) ^
|
|
|
|
(aKey->mNamespaceID << 4) ^
|
|
|
|
NS_PTR_TO_INT32(aKey->mLocalName);
|
|
|
|
}
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
2005-06-09 20:17:40 +00:00
|
|
|
nsAttrKey mKey;
|
2005-06-01 13:46:20 +00:00
|
|
|
};
|
1999-01-12 08:45:23 +00:00
|
|
|
|
|
|
|
// Helper class that implements the nsIDOMNamedNodeMap interface.
|
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
|
|
|
class nsDOMAttributeMap : public nsIDOMNamedNodeMap
|
1999-01-12 08:45:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDOMAttributeMap(nsIContent* aContent);
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~nsDOMAttributeMap();
|
1999-01-12 08:45:23 +00:00
|
|
|
|
2005-06-01 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Initialize the map. Must be called before the map is used.
|
|
|
|
*/
|
|
|
|
PRBool Init();
|
|
|
|
|
1999-01-12 08:45:23 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMNamedNodeMap interface
|
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_DECL_NSIDOMNAMEDNODEMAP
|
1999-01-12 08:45:23 +00:00
|
|
|
|
|
|
|
void DropReference();
|
|
|
|
|
2005-06-01 13:46:20 +00:00
|
|
|
nsIContent* GetContent()
|
|
|
|
{
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
2005-12-29 03:01:58 +00:00
|
|
|
/**
|
|
|
|
* Called when mContent is moved into a new document.
|
|
|
|
* Updates the nodeinfos of all owned nodes.
|
|
|
|
*/
|
|
|
|
nsresult SetOwnerDocument(nsIDocument* aDocument);
|
|
|
|
|
2005-06-01 13:46:20 +00:00
|
|
|
/**
|
|
|
|
* Drop an attribute from the map's cache (does not remove the attribute
|
|
|
|
* from the node!)
|
|
|
|
*/
|
|
|
|
void DropAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName);
|
|
|
|
|
1999-01-12 08:45:23 +00:00
|
|
|
private:
|
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
|
|
|
nsIContent* mContent; // Weak reference
|
2005-06-01 13:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache of nsDOMAttributes.
|
|
|
|
*/
|
|
|
|
nsInterfaceHashtable<nsAttrHashKey, nsIDOMNode> mAttributeCache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetNamedItem() (aWithNS = PR_FALSE) and SetNamedItemNS() (aWithNS =
|
|
|
|
* PR_TRUE) implementation.
|
|
|
|
*/
|
|
|
|
nsresult SetNamedItemInternal(nsIDOMNode *aNode,
|
|
|
|
nsIDOMNode **aReturn,
|
|
|
|
PRBool aWithNS);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetNamedItemNS() implementation taking |aRemove| for GetAttribute(),
|
|
|
|
* which is used by RemoveNamedItemNS().
|
|
|
|
*/
|
|
|
|
nsresult GetNamedItemNSInternal(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName,
|
|
|
|
nsIDOMNode** aReturn,
|
|
|
|
PRBool aRemove = PR_FALSE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an attribute, either by retrieving it from the cache or by
|
|
|
|
* creating a new one.
|
|
|
|
*/
|
|
|
|
nsresult GetAttribute(nsINodeInfo* aNodeInfo,
|
|
|
|
nsIDOMNode** aReturn,
|
|
|
|
PRBool aRemove = PR_FALSE);
|
1999-01-12 08:45:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* nsDOMAttributeMap_h___ */
|