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-03-30 12:03:04 +04:00
|
|
|
|
|
|
|
/*
|
2013-03-10 12:00:33 +04:00
|
|
|
* Implementation of the |attributes| property of DOM Core's Element object.
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
2013-03-10 12:00:33 +04:00
|
|
|
#ifndef nsDOMAttributeMap_h
|
|
|
|
#define nsDOMAttributeMap_h
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-26 10:48:23 +04:00
|
|
|
#include "mozilla/dom/Attr.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-03-10 12:00:33 +04:00
|
|
|
#include "nsIDOMMozNamedAttrMap.h"
|
2010-04-19 19:41:39 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2013-09-23 21:25:00 +04:00
|
|
|
#include "nsString.h"
|
2013-04-26 10:48:27 +04:00
|
|
|
#include "nsWrapperCache.h"
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
class nsIAtom;
|
2005-12-29 06:01:58 +03:00
|
|
|
class nsIDocument;
|
2005-06-01 17:46:20 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-09 19:29:44 +04:00
|
|
|
* Structure used as a key for caching Attrs in nsDOMAttributeMap's mAttributeCache.
|
2005-06-01 17:46:20 +04:00
|
|
|
*/
|
|
|
|
class nsAttrKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The namespace of the attribute
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNamespaceID;
|
2005-06-01 17:46:20 +04:00
|
|
|
|
|
|
|
/**
|
2015-04-17 05:39:12 +03:00
|
|
|
* The atom for attribute, stored as void*, to make sure that we only use it
|
|
|
|
* for the hashcode, and we can never dereference it.
|
2005-06-01 17:46:20 +04:00
|
|
|
*/
|
2015-04-17 05:39:12 +03:00
|
|
|
void* mLocalName;
|
2005-06-01 17:46:20 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAttrKey(int32_t aNs, nsIAtom* aName)
|
2005-06-01 17:46:20 +04:00
|
|
|
: mNamespaceID(aNs), mLocalName(aName) {}
|
|
|
|
|
|
|
|
nsAttrKey(const nsAttrKey& aAttr)
|
|
|
|
: mNamespaceID(aAttr.mNamespaceID), mLocalName(aAttr.mLocalName) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PLDHashEntryHdr implementation for nsAttrKey.
|
|
|
|
*/
|
2005-06-01 18:50:34 +04:00
|
|
|
class nsAttrHashKey : public PLDHashEntryHdr
|
2005-06-01 17:46:20 +04:00
|
|
|
{
|
|
|
|
public:
|
2005-06-10 00:17:40 +04:00
|
|
|
typedef const nsAttrKey& KeyType;
|
2005-06-01 17:46:20 +04:00
|
|
|
typedef const nsAttrKey* KeyTypePointer;
|
|
|
|
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsAttrHashKey(KeyTypePointer aKey) : mKey(*aKey) {}
|
2005-06-01 17:46:20 +04:00
|
|
|
nsAttrHashKey(const nsAttrHashKey& aCopy) : mKey(aCopy.mKey) {}
|
|
|
|
~nsAttrHashKey() {}
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mKey; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyEquals(KeyTypePointer aKey) const
|
2005-06-01 17:46:20 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2012-03-13 02:53:18 +04:00
|
|
|
return mozilla::HashGeneric(aKey->mNamespaceID, aKey->mLocalName);
|
2005-06-01 17:46:20 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2005-06-01 17:46:20 +04:00
|
|
|
|
|
|
|
private:
|
2005-06-10 00:17:40 +04:00
|
|
|
nsAttrKey mKey;
|
2005-06-01 17:46:20 +04:00
|
|
|
};
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-03-10 12:00:33 +04:00
|
|
|
// Helper class that implements the nsIDOMMozNamedAttrMap interface.
|
2015-03-21 21:35:18 +03:00
|
|
|
class nsDOMAttributeMap final : public nsIDOMMozNamedAttrMap
|
|
|
|
, public nsWrapperCache
|
1999-01-12 11:45:23 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-04-26 10:48:19 +04:00
|
|
|
typedef mozilla::dom::Attr Attr;
|
2010-07-30 17:42:11 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
2013-04-26 10:48:19 +04:00
|
|
|
typedef mozilla::ErrorResult ErrorResult;
|
2010-07-30 17:42:11 +04:00
|
|
|
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit nsDOMAttributeMap(Element *aContent);
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-07 03:37:47 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMAttributeMap)
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-03-10 12:00:33 +04:00
|
|
|
// nsIDOMMozNamedAttrMap interface
|
|
|
|
NS_DECL_NSIDOMMOZNAMEDATTRMAP
|
1999-01-12 11:45:23 +03:00
|
|
|
|
|
|
|
void DropReference();
|
|
|
|
|
2010-07-30 17:42:11 +04:00
|
|
|
Element* GetContent()
|
2005-06-01 17:46:20 +04:00
|
|
|
{
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
2005-12-29 06:01:58 +03:00
|
|
|
/**
|
|
|
|
* Called when mContent is moved into a new document.
|
|
|
|
* Updates the nodeinfos of all owned nodes.
|
|
|
|
*/
|
|
|
|
nsresult SetOwnerDocument(nsIDocument* aDocument);
|
|
|
|
|
2005-06-01 17:46:20 +04:00
|
|
|
/**
|
|
|
|
* Drop an attribute from the map's cache (does not remove the attribute
|
|
|
|
* from the node!)
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
void DropAttribute(int32_t aNamespaceID, nsIAtom* aLocalName);
|
2005-06-01 17:46:20 +04:00
|
|
|
|
2006-07-29 20:02:11 +04:00
|
|
|
/**
|
|
|
|
* Returns the number of attribute nodes currently in the map.
|
|
|
|
* Note: this is just the number of cached attribute nodes, not the number of
|
|
|
|
* attributes in mContent.
|
|
|
|
*
|
|
|
|
* @return The number of attribute nodes in the map.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t Count() const;
|
2006-07-29 20:02:11 +04:00
|
|
|
|
2013-04-26 10:48:19 +04:00
|
|
|
typedef nsRefPtrHashtable<nsAttrHashKey, Attr> AttrCache;
|
2006-07-29 20:02:11 +04:00
|
|
|
|
2015-10-28 01:13:04 +03:00
|
|
|
static void BlastSubtreeToPieces(nsINode *aNode);
|
2006-07-29 20:02:11 +04:00
|
|
|
|
2013-04-26 10:48:27 +04:00
|
|
|
Element* GetParentObject() const
|
2013-04-26 10:48:23 +04:00
|
|
|
{
|
2013-04-26 10:48:27 +04:00
|
|
|
return mContent;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
// WebIDL
|
|
|
|
Attr* GetNamedItem(const nsAString& aAttrName);
|
|
|
|
Attr* NamedGetter(const nsAString& aAttrName, bool& aFound);
|
|
|
|
already_AddRefed<Attr>
|
2015-09-22 20:13:26 +03:00
|
|
|
RemoveNamedItem(mozilla::dom::NodeInfo* aNodeInfo, ErrorResult& aError);
|
|
|
|
already_AddRefed<Attr>
|
2013-04-26 10:48:23 +04:00
|
|
|
RemoveNamedItem(const nsAString& aName, ErrorResult& aError);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-04-26 10:48:23 +04:00
|
|
|
Attr* Item(uint32_t aIndex);
|
|
|
|
Attr* IndexedGetter(uint32_t aIndex, bool& aFound);
|
|
|
|
uint32_t Length() const;
|
|
|
|
|
2013-04-26 10:48:19 +04:00
|
|
|
Attr*
|
|
|
|
GetNamedItemNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName);
|
|
|
|
already_AddRefed<Attr>
|
2015-12-04 17:51:04 +03:00
|
|
|
SetNamedItemNS(Attr& aNode, ErrorResult& aError);
|
2013-04-26 10:48:23 +04:00
|
|
|
already_AddRefed<Attr>
|
|
|
|
RemoveNamedItemNS(const nsAString& aNamespaceURI, const nsAString& aLocalName,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2015-12-08 02:42:36 +03:00
|
|
|
void
|
2016-05-10 05:25:40 +03:00
|
|
|
GetSupportedNames(nsTArray<nsString>& aNames);
|
2012-10-16 15:51:00 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-09-30 20:43:47 +04:00
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDOMAttributeMap();
|
|
|
|
|
1999-01-12 11:45:23 +03:00
|
|
|
private:
|
2013-05-07 03:37:47 +04:00
|
|
|
nsCOMPtr<Element> mContent;
|
2005-06-01 17:46:20 +04:00
|
|
|
|
|
|
|
/**
|
2015-02-03 11:03:28 +03:00
|
|
|
* Cache of Attrs.
|
2005-06-01 17:46:20 +04:00
|
|
|
*/
|
2015-02-03 11:03:28 +03:00
|
|
|
AttrCache mAttributeCache;
|
2005-06-01 17:46:20 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>
|
2012-10-16 15:51:00 +04:00
|
|
|
GetAttrNodeInfo(const nsAString& aNamespaceURI,
|
2013-04-04 16:01:11 +04:00
|
|
|
const nsAString& aLocalName);
|
2005-06-01 17:46:20 +04:00
|
|
|
|
2016-01-11 21:01:33 +03:00
|
|
|
Attr* GetAttribute(mozilla::dom::NodeInfo* aNodeInfo);
|
1999-01-12 11:45:23 +03:00
|
|
|
};
|
|
|
|
|
2013-08-23 09:17:11 +04:00
|
|
|
// XXX khuey yes this is crazy. The bindings code needs to see this include,
|
|
|
|
// but if we pull it in at the top of the file we get a circular include
|
|
|
|
// problem.
|
|
|
|
#include "mozilla/dom/Element.h"
|
1999-01-12 11:45:23 +03:00
|
|
|
|
2013-03-10 12:00:33 +04:00
|
|
|
#endif /* nsDOMAttributeMap_h */
|