2012-06-04 23:49:57 +00: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 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-09 17:51:03 +00:00
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
2012-06-04 23:49:57 +00: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 11:51:00 +00:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2013-08-23 05:17:11 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsINode;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class HTMLPropertiesCollection;
|
|
|
|
class PropertyNodeList;
|
2012-11-14 22:10:07 +00:00
|
|
|
class Element;
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2013-07-09 17:51:03 +00:00
|
|
|
class PropertyStringList : public DOMStringList
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit PropertyStringList(HTMLPropertiesCollection* aCollection);
|
2013-07-09 17:54:21 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PropertyStringList, DOMStringList)
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
bool ContainsInternal(const nsAString& aString);
|
|
|
|
|
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~PropertyStringList();
|
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
virtual void EnsureFresh() MOZ_OVERRIDE;
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
nsRefPtr<HTMLPropertiesCollection> mCollection;
|
|
|
|
};
|
|
|
|
|
2014-08-27 18:26:48 +00:00
|
|
|
class HTMLPropertiesCollection MOZ_FINAL : public nsIHTMLCollection,
|
|
|
|
public nsStubMutationObserver,
|
|
|
|
public nsWrapperCache
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
friend class PropertyNodeList;
|
|
|
|
friend class PropertyStringList;
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit HTMLPropertiesCollection(nsGenericHTMLElement* aRoot);
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2013-11-12 15:22:22 +00:00
|
|
|
// nsWrapperCache
|
2012-11-22 11:09:43 +00:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-12 15:22:22 +00:00
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~HTMLPropertiesCollection();
|
|
|
|
|
2013-11-12 15:22:22 +00:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
|
|
|
public:
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2015-01-06 20:13:36 +00:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex) MOZ_OVERRIDE;
|
2012-10-13 12:50:24 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void SetDocument(nsIDocument* aDocument);
|
2013-05-29 20:43:41 +00:00
|
|
|
nsINode* GetParentObject() MOZ_OVERRIDE;
|
2013-11-11 07:55:41 +00: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 20:49:53 +00:00
|
|
|
PropertyNodeList* NamedItem(const nsAString& aName);
|
|
|
|
PropertyNodeList* NamedGetter(const nsAString& aName, bool& aFound)
|
|
|
|
{
|
|
|
|
aFound = IsSupportedNamedProperty(aName);
|
|
|
|
return aFound ? NamedItem(aName) : nullptr;
|
|
|
|
}
|
2014-04-16 02:58:44 +00:00
|
|
|
bool NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-09 17:51:03 +00:00
|
|
|
DOMStringList* Names()
|
2012-09-05 20:49:53 +00:00
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames;
|
|
|
|
}
|
2014-04-16 02:58:44 +00:00
|
|
|
virtual void GetSupportedNames(unsigned,
|
|
|
|
nsTArray<nsString>& aNames) MOZ_OVERRIDE;
|
2012-06-04 23:49:57 +00:00
|
|
|
|
2012-12-08 22:06:42 +00:00
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
|
2012-06-04 23:49:57 +00: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 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00: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 20:49:53 +00:00
|
|
|
bool IsSupportedNamedProperty(const nsAString& aName)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames->ContainsInternal(aName);
|
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// the items that make up this collection
|
2012-12-08 22:06:42 +00:00
|
|
|
nsTArray<nsRefPtr<nsGenericHTMLElement> > mProperties;
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// the itemprop attribute of the properties
|
2012-12-08 22:06:42 +00:00
|
|
|
nsRefPtr<PropertyStringList> mNames;
|
|
|
|
|
|
|
|
// The cached PropertyNodeLists that are NamedItems of this collection
|
2012-06-04 23:49:57 +00:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, PropertyNodeList> mNamedItemEntries;
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// The element this collection is rooted at
|
2013-08-07 20:23:08 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mRoot;
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// The document mRoot is in, if any
|
|
|
|
nsCOMPtr<nsIDocument> mDoc;
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// True if there have been DOM modifications since the last EnsureFresh call.
|
|
|
|
bool mIsDirty;
|
|
|
|
};
|
|
|
|
|
2014-11-25 18:56:07 +00:00
|
|
|
class PropertyNodeList MOZ_FINAL : public nsINodeList,
|
|
|
|
public nsStubMutationObserver
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PropertyNodeList(HTMLPropertiesCollection* aCollection,
|
|
|
|
nsIContent* aRoot, const nsAString& aName);
|
|
|
|
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
void SetDocument(nsIDocument* aDocument);
|
|
|
|
|
2012-09-05 20:49:53 +00:00
|
|
|
void GetValues(JSContext* aCx, nsTArray<JS::Value >& aResult,
|
|
|
|
ErrorResult& aError);
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual nsIContent* Item(uint32_t aIndex) MOZ_OVERRIDE;
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(PropertyNodeList,
|
|
|
|
nsINodeList)
|
2012-12-08 22:06:42 +00:00
|
|
|
NS_DECL_NSIDOMNODELIST
|
2012-06-04 23:49:57 +00:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
// nsINodeList interface
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) MOZ_OVERRIDE;
|
|
|
|
virtual nsINode* GetParentObject() MOZ_OVERRIDE;
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void AppendElement(nsGenericHTMLElement* aElement)
|
|
|
|
{
|
|
|
|
mElements.AppendElement(aElement);
|
|
|
|
}
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mElements.Clear();
|
|
|
|
}
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void SetDirty() { mIsDirty = true; }
|
2012-12-08 22:06:42 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~PropertyNodeList();
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
// Make sure this list is up to date, in case the DOM has been mutated.
|
|
|
|
void EnsureFresh();
|
|
|
|
|
2012-12-08 22:06:42 +00:00
|
|
|
// the the name that this list corresponds to
|
2012-06-04 23:49:57 +00: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 22:06:42 +00:00
|
|
|
#endif // HTMLPropertiesCollection_h_
|