tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLAllCollection.h (2610B)


      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/. */
      6 
      7 #ifndef mozilla_dom_HTMLAllCollection_h
      8 #define mozilla_dom_HTMLAllCollection_h
      9 
     10 #include <stdint.h>
     11 
     12 #include "mozilla/dom/Document.h"
     13 #include "nsCycleCollectionParticipant.h"
     14 #include "nsISupportsImpl.h"
     15 #include "nsRefPtrHashtable.h"
     16 #include "nsWrapperCache.h"
     17 
     18 class nsContentList;
     19 class nsINode;
     20 
     21 namespace mozilla::dom {
     22 
     23 class Document;
     24 class Element;
     25 class OwningHTMLCollectionOrElement;
     26 template <typename>
     27 struct Nullable;
     28 template <typename>
     29 class Optional;
     30 
     31 class HTMLAllCollection final : public nsISupports, public nsWrapperCache {
     32  ~HTMLAllCollection();
     33 
     34 public:
     35  explicit HTMLAllCollection(mozilla::dom::Document* aDocument);
     36 
     37  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     38  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(HTMLAllCollection)
     39 
     40  virtual JSObject* WrapObject(JSContext* aCx,
     41                               JS::Handle<JSObject*> aGivenProto) override;
     42  nsINode* GetParentObject() const;
     43 
     44  uint32_t Length();
     45  Element* IndexedGetter(uint32_t aIndex, bool& aFound) {
     46    Element* result = Item(aIndex);
     47    aFound = !!result;
     48    return result;
     49  }
     50 
     51  void NamedItem(const nsAString& aName,
     52                 Nullable<OwningHTMLCollectionOrElement>& aResult) {
     53    bool found = false;
     54    NamedGetter(aName, found, aResult);
     55  }
     56  void NamedGetter(const nsAString& aName, bool& aFound,
     57                   Nullable<OwningHTMLCollectionOrElement>& aResult);
     58  void GetSupportedNames(nsTArray<nsString>& aNames);
     59 
     60  void Item(const Optional<nsAString>& aNameOrIndex,
     61            Nullable<OwningHTMLCollectionOrElement>& aResult);
     62 
     63  void LegacyCall(JS::Handle<JS::Value>,
     64                  const Optional<nsAString>& aNameOrIndex,
     65                  Nullable<OwningHTMLCollectionOrElement>& aResult) {
     66    Item(aNameOrIndex, aResult);
     67  }
     68 
     69 private:
     70  nsContentList* Collection();
     71 
     72  /**
     73   * Returns the HTMLCollection for document.all[aID], or null if there isn't
     74   * one.
     75   */
     76  nsContentList* GetDocumentAllList(const nsAString& aID);
     77 
     78  /**
     79   * Helper for indexed getter and spec Item() method.
     80   */
     81  Element* Item(uint32_t aIndex);
     82 
     83  RefPtr<mozilla::dom::Document> mDocument;
     84  RefPtr<nsContentList> mCollection;
     85  nsRefPtrHashtable<nsStringHashKey, nsContentList> mNamedMap;
     86 };
     87 
     88 }  // namespace mozilla::dom
     89 
     90 #endif  // mozilla_dom_HTMLAllCollection_h