2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 10:51:03 -07:00
|
|
|
#ifndef mozilla_dom_DOMStringList_h
|
|
|
|
#define mozilla_dom_DOMStringList_h
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
#include "nsISupports.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2013-07-09 10:54:21 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsString.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 10:51:03 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
class DOMStringList : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-24 19:09:15 -07:00
|
|
|
protected:
|
|
|
|
virtual ~DOMStringList();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2013-07-09 10:54:21 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList)
|
|
|
|
|
2015-01-02 18:13:39 -08:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-09 10:54:21 -07:00
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
if (aIndex < mNames.Length()) {
|
|
|
|
aFound = true;
|
|
|
|
aResult = mNames[aIndex];
|
|
|
|
} else {
|
|
|
|
aFound = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item(uint32_t aIndex, nsAString& aResult)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
if (aIndex < mNames.Length()) {
|
|
|
|
aResult = mNames[aIndex];
|
|
|
|
} else {
|
|
|
|
aResult.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Length()
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Contains(const nsAString& aString)
|
|
|
|
{
|
|
|
|
EnsureFresh();
|
|
|
|
return mNames.Contains(aString);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Add(const nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 10:54:21 -07:00
|
|
|
// XXXbz mNames should really be a fallible array; otherwise this
|
|
|
|
// return value is meaningless.
|
2012-07-30 07:20:58 -07:00
|
|
|
return mNames.AppendElement(aName) != nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mNames.Clear();
|
|
|
|
}
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
nsTArray<nsString>& StringArray()
|
|
|
|
{
|
|
|
|
return mNames;
|
|
|
|
}
|
|
|
|
|
2012-11-05 08:58:03 -08:00
|
|
|
void CopyList(nsTArray<nsString>& aNames)
|
|
|
|
{
|
|
|
|
aNames = mNames;
|
|
|
|
}
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
protected:
|
|
|
|
// A method that subclasses can override to modify mNames as needed
|
|
|
|
// before we index into it or return its length or whatnot.
|
|
|
|
virtual void EnsureFresh()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbz we really want this to be a fallible array, but we end up passing it
|
|
|
|
// to consumers who declare themselves as taking and nsTArray. :(
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString> mNames;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2013-07-09 10:51:03 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_DOMStringList_h */
|