nsIHTMLCollection.h (2609B)
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 nsIHTMLCollection_h___ 8 #define nsIHTMLCollection_h___ 9 10 #include "js/TypeDecls.h" 11 #include "nsISupports.h" 12 #include "nsStringFwd.h" 13 #include "nsTArrayForwardDeclare.h" 14 #include "nsWrapperCache.h" 15 16 class nsINode; 17 18 namespace mozilla::dom { 19 class Element; 20 } // namespace mozilla::dom 21 22 // IID for the nsIHTMLCollection interface 23 #define NS_IHTMLCOLLECTION_IID \ 24 {0x4e169191, 0x5196, 0x4e17, {0xa4, 0x79, 0xd5, 0x35, 0x0b, 0x5b, 0x0a, 0xcd}} 25 26 /** 27 * An internal interface 28 */ 29 class nsIHTMLCollection : public nsISupports { 30 public: 31 NS_INLINE_DECL_STATIC_IID(NS_IHTMLCOLLECTION_IID) 32 33 /** 34 * Get the root node for this HTML collection. 35 */ 36 virtual nsINode* GetParentObject() = 0; 37 38 virtual uint32_t Length() = 0; 39 virtual mozilla::dom::Element* GetElementAt(uint32_t index) = 0; 40 mozilla::dom::Element* Item(uint32_t index) { return GetElementAt(index); } 41 mozilla::dom::Element* IndexedGetter(uint32_t index, bool& aFound) { 42 mozilla::dom::Element* item = Item(index); 43 aFound = !!item; 44 return item; 45 } 46 mozilla::dom::Element* NamedItem(const nsAString& aName) { 47 bool dummy; 48 return NamedGetter(aName, dummy); 49 } 50 mozilla::dom::Element* NamedGetter(const nsAString& aName, bool& aFound) { 51 return GetFirstNamedElement(aName, aFound); 52 } 53 virtual mozilla::dom::Element* GetFirstNamedElement(const nsAString& aName, 54 bool& aFound) = 0; 55 56 virtual void GetSupportedNames(nsTArray<nsString>& aNames) = 0; 57 58 JSObject* GetWrapperPreserveColor() { 59 return GetWrapperPreserveColorInternal(); 60 } 61 JSObject* GetWrapper() { 62 JSObject* obj = GetWrapperPreserveColor(); 63 if (obj) { 64 JS::ExposeObjectToActiveJS(obj); 65 } 66 return obj; 67 } 68 void PreserveWrapper(nsISupports* aScriptObjectHolder) { 69 PreserveWrapperInternal(aScriptObjectHolder); 70 } 71 virtual JSObject* WrapObject(JSContext* aCx, 72 JS::Handle<JSObject*> aGivenProto) = 0; 73 74 protected: 75 // Hook for calling nsWrapperCache::GetWrapperPreserveColor. 76 virtual JSObject* GetWrapperPreserveColorInternal() = 0; 77 // Hook for calling nsWrapperCache::PreserveWrapper. 78 virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) = 0; 79 }; 80 81 #endif /* nsIHTMLCollection_h___ */