michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_DOMStringList_h michael@0: #define mozilla_dom_DOMStringList_h michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsTArray.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsString.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class DOMStringList : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: DOMStringList() michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: virtual ~DOMStringList(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList) michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx); michael@0: nsISupports* GetParentObject() michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult) michael@0: { michael@0: EnsureFresh(); michael@0: if (aIndex < mNames.Length()) { michael@0: aFound = true; michael@0: aResult = mNames[aIndex]; michael@0: } else { michael@0: aFound = false; michael@0: } michael@0: } michael@0: michael@0: void Item(uint32_t aIndex, nsAString& aResult) michael@0: { michael@0: EnsureFresh(); michael@0: if (aIndex < mNames.Length()) { michael@0: aResult = mNames[aIndex]; michael@0: } else { michael@0: aResult.SetIsVoid(true); michael@0: } michael@0: } michael@0: michael@0: uint32_t Length() michael@0: { michael@0: EnsureFresh(); michael@0: return mNames.Length(); michael@0: } michael@0: michael@0: bool Contains(const nsAString& aString) michael@0: { michael@0: EnsureFresh(); michael@0: return mNames.Contains(aString); michael@0: } michael@0: michael@0: bool Add(const nsAString& aName) michael@0: { michael@0: // XXXbz mNames should really be a fallible array; otherwise this michael@0: // return value is meaningless. michael@0: return mNames.AppendElement(aName) != nullptr; michael@0: } michael@0: michael@0: void Clear() michael@0: { michael@0: mNames.Clear(); michael@0: } michael@0: michael@0: nsTArray& StringArray() michael@0: { michael@0: return mNames; michael@0: } michael@0: michael@0: void CopyList(nsTArray& aNames) michael@0: { michael@0: aNames = mNames; michael@0: } michael@0: michael@0: protected: michael@0: // A method that subclasses can override to modify mNames as needed michael@0: // before we index into it or return its length or whatnot. michael@0: virtual void EnsureFresh() michael@0: { michael@0: } michael@0: michael@0: // XXXbz we really want this to be a fallible array, but we end up passing it michael@0: // to consumers who declare themselves as taking and nsTArray. :( michael@0: nsTArray mNames; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_dom_DOMStringList_h */