Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_FileList_h
8 : #define mozilla_dom_FileList_h
9 :
10 : #include "mozilla/dom/BindingDeclarations.h"
11 : #include "mozilla/dom/UnionTypes.h"
12 : #include "nsCycleCollectionParticipant.h"
13 : #include "nsIDOMFileList.h"
14 : #include "nsWrapperCache.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class BlobImpls;
20 : class File;
21 :
22 : class FileList final : public nsIDOMFileList,
23 : public nsWrapperCache
24 : {
25 : public:
26 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList)
28 :
29 : NS_DECL_NSIDOMFILELIST
30 :
31 0 : explicit FileList(nsISupports* aParent)
32 0 : : mParent(aParent)
33 0 : {}
34 :
35 : virtual JSObject* WrapObject(JSContext* aCx,
36 : JS::Handle<JSObject*> aGivenProto) override;
37 :
38 0 : nsISupports* GetParentObject()
39 : {
40 0 : return mParent;
41 : }
42 :
43 0 : bool Append(File* aFile)
44 : {
45 0 : MOZ_ASSERT(aFile);
46 0 : return mFiles.AppendElement(aFile, fallible);
47 : }
48 :
49 : bool Remove(uint32_t aIndex)
50 : {
51 : if (aIndex < mFiles.Length()) {
52 : mFiles.RemoveElementAt(aIndex);
53 : return true;
54 : }
55 :
56 : return false;
57 : }
58 :
59 0 : void Clear()
60 : {
61 0 : return mFiles.Clear();
62 : }
63 :
64 : File* Item(uint32_t aIndex) const;
65 :
66 : File* IndexedGetter(uint32_t aIndex, bool& aFound) const;
67 :
68 0 : uint32_t Length() const
69 : {
70 0 : return mFiles.Length();
71 : }
72 :
73 : void ToSequence(Sequence<RefPtr<File>>& aSequence,
74 : ErrorResult& aRv) const;
75 :
76 : private:
77 0 : ~FileList() {}
78 :
79 : FallibleTArray<RefPtr<File>> mFiles;
80 : nsCOMPtr<nsISupports> mParent;
81 : };
82 :
83 : } // namespace dom
84 : } // namespace mozilla
85 :
86 : #endif // mozilla_dom_FileList_h
|