1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLAllCollection_h
8 #define mozilla_dom_HTMLAllCollection_h
10 #include "mozilla/dom/Document.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsISupportsImpl.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsWrapperCache.h"
21 namespace mozilla::dom
{
25 class OwningHTMLCollectionOrElement
;
31 class HTMLAllCollection final
: public nsISupports
, public nsWrapperCache
{
35 explicit HTMLAllCollection(mozilla::dom::Document
* aDocument
);
37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
38 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(HTMLAllCollection
)
40 virtual JSObject
* WrapObject(JSContext
* aCx
,
41 JS::Handle
<JSObject
*> aGivenProto
) override
;
42 nsINode
* GetParentObject() const;
45 Element
* IndexedGetter(uint32_t aIndex
, bool& aFound
) {
46 Element
* result
= Item(aIndex
);
51 void NamedItem(const nsAString
& aName
,
52 Nullable
<OwningHTMLCollectionOrElement
>& aResult
) {
54 NamedGetter(aName
, found
, aResult
);
56 void NamedGetter(const nsAString
& aName
, bool& aFound
,
57 Nullable
<OwningHTMLCollectionOrElement
>& aResult
);
58 void GetSupportedNames(nsTArray
<nsString
>& aNames
);
60 void Item(const Optional
<nsAString
>& aNameOrIndex
,
61 Nullable
<OwningHTMLCollectionOrElement
>& aResult
);
63 void LegacyCall(JS::Handle
<JS::Value
>,
64 const Optional
<nsAString
>& aNameOrIndex
,
65 Nullable
<OwningHTMLCollectionOrElement
>& aResult
) {
66 Item(aNameOrIndex
, aResult
);
70 nsContentList
* Collection();
73 * Returns the HTMLCollection for document.all[aID], or null if there isn't
76 nsContentList
* GetDocumentAllList(const nsAString
& aID
);
79 * Helper for indexed getter and spec Item() method.
81 Element
* Item(uint32_t aIndex
);
83 RefPtr
<mozilla::dom::Document
> mDocument
;
84 RefPtr
<nsContentList
> mCollection
;
85 nsRefPtrHashtable
<nsStringHashKey
, nsContentList
> mNamedMap
;
88 } // namespace mozilla::dom
90 #endif // mozilla_dom_HTMLAllCollection_h