2015-05-03 22:32:37 +03: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 15:12:37 +04: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 04:44:20 +04:00
|
|
|
|
2013-07-09 21:51:03 +04:00
|
|
|
#ifndef mozilla_dom_DOMStringList_h
|
|
|
|
#define mozilla_dom_DOMStringList_h
|
2003-10-16 04:44:20 +04:00
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
#include "nsISupports.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2013-07-09 21:54:21 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsString.h"
|
2003-10-16 04:44:20 +04:00
|
|
|
|
2013-07-09 21:51:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
class DOMStringList : public nsISupports, public nsWrapperCache {
|
2014-06-25 06:09:15 +04:00
|
|
|
protected:
|
|
|
|
virtual ~DOMStringList();
|
|
|
|
|
2003-10-16 04:44:20 +04:00
|
|
|
public:
|
2013-07-09 21:54:21 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-07-09 21:54:21 +04: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 04:44:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Add(const nsAString& aName) {
|
2020-04-24 16:31:14 +03:00
|
|
|
// XXXbz(Bug 1631374) mNames should really be a fallible array; otherwise
|
|
|
|
// this return value is meaningless. return mNames.AppendElement(aName) !=
|
|
|
|
// nullptr;
|
|
|
|
mNames.AppendElement(aName);
|
|
|
|
return true;
|
2003-10-16 04:44:20 +04:00
|
|
|
}
|
|
|
|
|
2012-06-05 03:49:57 +04:00
|
|
|
void Clear() { mNames.Clear(); }
|
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
nsTArray<nsString>& StringArray() { return mNames; }
|
|
|
|
|
2020-05-05 13:08:02 +03:00
|
|
|
void CopyList(nsTArray<nsString>& aNames) { aNames = mNames.Clone(); }
|
2012-11-05 20:58:03 +04:00
|
|
|
|
2013-07-09 21:54:21 +04: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 23:14:14 +03:00
|
|
|
nsTArray<nsString> mNames;
|
2003-10-16 04:44:20 +04:00
|
|
|
};
|
|
|
|
|
2013-07-09 21:51:03 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_DOMStringList_h */
|