2012-06-04 16:49:57 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef HTMLPropertiesCollection_h_
|
|
|
|
#define HTMLPropertiesCollection_h_
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-09 10:51:03 -07:00
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
2012-06-04 16:49:57 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsIMutationObserver.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
#include "nsBaseHashtable.h"
|
|
|
|
#include "nsINodeList.h"
|
|
|
|
#include "nsIHTMLCollection.h"
|
|
|
|
#include "nsHashKeys.h"
|
2012-10-16 04:51:00 -07:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2013-08-22 22:17:11 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsINode;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLPropertiesCollection;
|
|
|
|
class PropertyNodeList;
|
2012-11-14 14:10:07 -08:00
|
|
|
class Element;
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2013-07-09 10:51:03 -07:00
|
|
|
class PropertyStringList : public DOMStringList
|
2012-06-04 16:49:57 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit PropertyStringList(HTMLPropertiesCollection* aCollection);
|
2013-07-09 10:54:21 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PropertyStringList, DOMStringList)
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
bool ContainsInternal(const nsAString& aString);
|
|
|
|
|
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~PropertyStringList();
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
virtual void EnsureFresh() MOZ_OVERRIDE;
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
nsRefPtr<HTMLPropertiesCollection> mCollection;
|
|
|
|
};
|
|
|
|
|
2014-08-27 11:26:48 -07:00
|
|
|
class HTMLPropertiesCollection MOZ_FINAL : public nsIHTMLCollection,
|
|
|
|
public nsStubMutationObserver,
|
|
|
|
public nsWrapperCache
|
2012-06-04 16:49:57 -07:00
|
|
|
{
|
|
|
|
friend class PropertyNodeList;
|
|
|
|
friend class PropertyStringList;
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit HTMLPropertiesCollection(nsGenericHTMLElement* aRoot);
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2013-11-12 07:22:22 -08:00
|
|
|
// nsWrapperCache
|
2012-11-22 03:09:43 -08:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-12 07:22:22 -08:00
|
|
|
protected:
|
2014-06-24 19:09:15 -07:00
|
|
|
virtual ~HTMLPropertiesCollection();
|
|
|
|
|
2013-11-12 07:22:22 -08:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
|
|
|
public:
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex);
|
2012-10-13 05:50:24 -07:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void SetDocument(nsIDocument* aDocument);
|
2013-05-29 13:43:41 -07:00
|
|
|
nsINode* GetParentObject() MOZ_OVERRIDE;
|
2013-11-10 23:55:41 -08:00
|
|
|
|
|
|
|
virtual Element*
|
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
// HTMLPropertiesCollection.namedItem and the named getter call the
|
|
|
|
// NamedItem that returns a PropertyNodeList, calling
|
|
|
|
// HTMLCollection.namedItem doesn't make sense so this returns null.
|
|
|
|
aFound = false;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-09-05 13:49:53 -07:00
|
|
|
PropertyNodeList* NamedItem(const nsAString& aName);
|
|
|
|
PropertyNodeList* NamedGetter(const nsAString& aName, bool& aFound)
|
|
|
|
{
|
|
|
|
aFound = IsSupportedNamedProperty(aName);
|
|
|
|
return aFound ? NamedItem(aName) : nullptr;
|
|
|
|
}
|
2014-04-15 19:58:44 -07:00
|
|
|
bool NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-09 10:51:03 -07:00
|
|
|
DOMStringList* Names()
|
2012-09-05 13:49:53 -07:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames;
|
|
|
|
}
|
2014-04-15 19:58:44 -07:00
|
|
|
virtual void GetSupportedNames(unsigned,
|
|
|
|
nsTArray<nsString>& aNames) MOZ_OVERRIDE;
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2012-12-08 14:06:42 -08:00
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(HTMLPropertiesCollection,
|
|
|
|
nsIHTMLCollection)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Make sure this collection is up to date, in case the DOM has been mutated.
|
|
|
|
void EnsureFresh();
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// Crawl the properties of mRoot, following any itemRefs it may have
|
|
|
|
void CrawlProperties();
|
|
|
|
|
|
|
|
// Crawl startNode and its descendants, looking for items
|
|
|
|
void CrawlSubtree(Element* startNode);
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
bool IsSupportedNamedProperty(const nsAString& aName)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames->ContainsInternal(aName);
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// the items that make up this collection
|
2012-12-08 14:06:42 -08:00
|
|
|
nsTArray<nsRefPtr<nsGenericHTMLElement> > mProperties;
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// the itemprop attribute of the properties
|
2012-12-08 14:06:42 -08:00
|
|
|
nsRefPtr<PropertyStringList> mNames;
|
|
|
|
|
|
|
|
// The cached PropertyNodeLists that are NamedItems of this collection
|
2012-06-04 16:49:57 -07:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, PropertyNodeList> mNamedItemEntries;
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// The element this collection is rooted at
|
2013-08-07 13:23:08 -07:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mRoot;
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// The document mRoot is in, if any
|
|
|
|
nsCOMPtr<nsIDocument> mDoc;
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// True if there have been DOM modifications since the last EnsureFresh call.
|
|
|
|
bool mIsDirty;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PropertyNodeList : public nsINodeList,
|
|
|
|
public nsStubMutationObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PropertyNodeList(HTMLPropertiesCollection* aCollection,
|
|
|
|
nsIContent* aRoot, const nsAString& aName);
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
void SetDocument(nsIDocument* aDocument);
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
void GetValues(JSContext* aCx, nsTArray<JS::Value >& aResult,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual nsIContent* Item(uint32_t aIndex) MOZ_OVERRIDE;
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(PropertyNodeList,
|
|
|
|
nsINodeList)
|
2012-12-08 14:06:42 -08:00
|
|
|
NS_DECL_NSIDOMNODELIST
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
// nsINodeList interface
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) MOZ_OVERRIDE;
|
|
|
|
virtual nsINode* GetParentObject() MOZ_OVERRIDE;
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void AppendElement(nsGenericHTMLElement* aElement)
|
|
|
|
{
|
|
|
|
mElements.AppendElement(aElement);
|
|
|
|
}
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mElements.Clear();
|
|
|
|
}
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void SetDirty() { mIsDirty = true; }
|
2012-12-08 14:06:42 -08:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
protected:
|
2014-06-24 19:09:15 -07:00
|
|
|
virtual ~PropertyNodeList();
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
// Make sure this list is up to date, in case the DOM has been mutated.
|
|
|
|
void EnsureFresh();
|
|
|
|
|
2012-12-08 14:06:42 -08:00
|
|
|
// the the name that this list corresponds to
|
2012-06-04 16:49:57 -07:00
|
|
|
nsString mName;
|
|
|
|
|
|
|
|
// the document mParent is in, if any
|
|
|
|
nsCOMPtr<nsIDocument> mDoc;
|
|
|
|
|
|
|
|
// the collection that this list is a named item of
|
|
|
|
nsRefPtr<HTMLPropertiesCollection> mCollection;
|
|
|
|
|
|
|
|
// the node this list is rooted at
|
|
|
|
nsCOMPtr<nsINode> mParent;
|
|
|
|
|
|
|
|
// the properties that make up this list
|
|
|
|
nsTArray<nsRefPtr<nsGenericHTMLElement> > mElements;
|
|
|
|
|
|
|
|
// True if there have been DOM modifications since the last EnsureFresh call.
|
|
|
|
bool mIsDirty;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-12-08 14:06:42 -08:00
|
|
|
#endif // HTMLPropertiesCollection_h_
|