Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLAllCollection.h
blob6179951175e628a5f38e53af8ccee819e9aba289
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"
16 #include <stdint.h>
18 class nsContentList;
19 class nsINode;
21 namespace mozilla::dom {
23 class Document;
24 class Element;
25 class OwningHTMLCollectionOrElement;
26 template <typename>
27 struct Nullable;
28 template <typename>
29 class Optional;
31 class HTMLAllCollection final : public nsISupports, public nsWrapperCache {
32 ~HTMLAllCollection();
34 public:
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;
44 uint32_t Length();
45 Element* IndexedGetter(uint32_t aIndex, bool& aFound) {
46 Element* result = Item(aIndex);
47 aFound = !!result;
48 return result;
51 void NamedItem(const nsAString& aName,
52 Nullable<OwningHTMLCollectionOrElement>& aResult) {
53 bool found = false;
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);
69 private:
70 nsContentList* Collection();
72 /**
73 * Returns the HTMLCollection for document.all[aID], or null if there isn't
74 * one.
76 nsContentList* GetDocumentAllList(const nsAString& aID);
78 /**
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