Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / DOMStringList.h
blobd08345336d1a9fdf06bfdf11f72d9792bf4f9024
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/. */
7 #ifndef mozilla_dom_DOMStringList_h
8 #define mozilla_dom_DOMStringList_h
10 #include "nsISupports.h"
11 #include "nsTArray.h"
12 #include "nsWrapperCache.h"
13 #include "nsString.h"
15 namespace mozilla {
16 namespace dom {
18 class DOMStringList : public nsISupports, public nsWrapperCache {
19 protected:
20 virtual ~DOMStringList();
22 public:
23 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList)
26 virtual JSObject* WrapObject(JSContext* aCx,
27 JS::Handle<JSObject*> aGivenProto) override;
28 nsISupports* GetParentObject() { return nullptr; }
30 void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult) {
31 EnsureFresh();
32 if (aIndex < mNames.Length()) {
33 aFound = true;
34 aResult = mNames[aIndex];
35 } else {
36 aFound = false;
40 void Item(uint32_t aIndex, nsAString& aResult) {
41 EnsureFresh();
42 if (aIndex < mNames.Length()) {
43 aResult = mNames[aIndex];
44 } else {
45 aResult.SetIsVoid(true);
49 uint32_t Length() {
50 EnsureFresh();
51 return mNames.Length();
54 bool Contains(const nsAString& aString) {
55 EnsureFresh();
56 return mNames.Contains(aString);
59 bool Add(const nsAString& aName) {
60 // XXXbz mNames should really be a fallible array; otherwise this
61 // return value is meaningless.
62 return mNames.AppendElement(aName) != nullptr;
65 void Clear() { mNames.Clear(); }
67 nsTArray<nsString>& StringArray() { return mNames; }
69 void CopyList(nsTArray<nsString>& aNames) { aNames = mNames; }
71 protected:
72 // A method that subclasses can override to modify mNames as needed
73 // before we index into it or return its length or whatnot.
74 virtual void EnsureFresh() {}
76 // XXXbz we really want this to be a fallible array, but we end up passing it
77 // to consumers who declare themselves as taking and nsTArray. :(
78 nsTArray<nsString> mNames;
81 } // namespace dom
82 } // namespace mozilla
84 #endif /* mozilla_dom_DOMStringList_h */