2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2003-10-16 00:44:20 +00:00
|
|
|
|
2013-07-09 17:51:03 +00:00
|
|
|
#ifndef mozilla_dom_DOMStringList_h
|
|
|
|
#define mozilla_dom_DOMStringList_h
|
2003-10-16 00:44:20 +00:00
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
#include "nsISupports.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2013-07-09 17:54:21 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsString.h"
|
2003-10-16 00:44:20 +00:00
|
|
|
|
2013-07-09 17:51:03 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
class DOMStringList : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2003-10-16 00:44:20 +00:00
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
protected:
|
|
|
|
virtual ~DOMStringList();
|
|
|
|
|
2003-10-16 00:44:20 +00:00
|
|
|
public:
|
2013-07-09 17:54:21 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList)
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-07-09 17:54:21 +00: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);
|
|
|
|
}
|
2003-10-16 00:44:20 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Add(const nsAString& aName)
|
2003-10-16 00:44:20 +00:00
|
|
|
{
|
2013-07-09 17:54:21 +00:00
|
|
|
// XXXbz mNames should really be a fallible array; otherwise this
|
|
|
|
// return value is meaningless.
|
2012-07-30 14:20:58 +00:00
|
|
|
return mNames.AppendElement(aName) != nullptr;
|
2003-10-16 00:44:20 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mNames.Clear();
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:54:21 +00:00
|
|
|
nsTArray<nsString>& StringArray()
|
|
|
|
{
|
|
|
|
return mNames;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:58:03 +00:00
|
|
|
void CopyList(nsTArray<nsString>& aNames)
|
|
|
|
{
|
|
|
|
aNames = mNames;
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:54:21 +00: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 20:14:14 +00:00
|
|
|
nsTArray<nsString> mNames;
|
2003-10-16 00:44:20 +00:00
|
|
|
};
|
|
|
|
|
2013-07-09 17:51:03 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_DOMStringList_h */
|