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 nsDocShellEnumerator_h___
8 : #define nsDocShellEnumerator_h___
9 :
10 : #include "nsISimpleEnumerator.h"
11 : #include "nsTArray.h"
12 : #include "nsIWeakReferenceUtils.h"
13 :
14 : class nsIDocShellTreeItem;
15 :
16 : /*
17 : // {13cbc281-35ae-11d5-be5b-bde0edece43c}
18 : #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID \
19 : { 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
20 :
21 : #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
22 : "@mozilla.org/docshell/enumerator-forwards;1"
23 :
24 : // {13cbc282-35ae-11d5-be5b-bde0edece43c}
25 : #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID \
26 : { 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
27 :
28 : #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
29 : "@mozilla.org/docshell/enumerator-backwards;1"
30 : */
31 :
32 : class nsDocShellEnumerator : public nsISimpleEnumerator
33 : {
34 : protected:
35 : enum
36 : {
37 : enumerateForwards,
38 : enumerateBackwards
39 : };
40 :
41 : virtual ~nsDocShellEnumerator();
42 :
43 : public:
44 : explicit nsDocShellEnumerator(int32_t aEnumerationDirection);
45 :
46 : // nsISupports
47 : NS_DECL_ISUPPORTS
48 :
49 : // nsISimpleEnumerator
50 : NS_DECL_NSISIMPLEENUMERATOR
51 :
52 : public:
53 : nsresult GetEnumerationRootItem(nsIDocShellTreeItem** aEnumerationRootItem);
54 : nsresult SetEnumerationRootItem(nsIDocShellTreeItem* aEnumerationRootItem);
55 :
56 : nsresult GetEnumDocShellType(int32_t* aEnumerationItemType);
57 : nsresult SetEnumDocShellType(int32_t aEnumerationItemType);
58 :
59 : nsresult First();
60 :
61 : protected:
62 : nsresult EnsureDocShellArray();
63 : nsresult ClearState();
64 :
65 : nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& aItemArray);
66 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
67 : nsTArray<nsWeakPtr>& aItemArray) = 0;
68 :
69 : protected:
70 : nsWeakPtr mRootItem; // weak ref!
71 :
72 : nsTArray<nsWeakPtr> mItemArray; // flattened list of items with matching type
73 : uint32_t mCurIndex;
74 :
75 : int32_t mDocShellType; // only want shells of this type
76 : bool mArrayValid; // is mItemArray up to date?
77 :
78 : const int8_t mEnumerationDirection;
79 : };
80 :
81 0 : class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
82 : {
83 : public:
84 0 : nsDocShellForwardsEnumerator()
85 0 : : nsDocShellEnumerator(enumerateForwards)
86 : {
87 0 : }
88 :
89 : protected:
90 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
91 : nsTArray<nsWeakPtr>& aItemArray);
92 : };
93 :
94 0 : class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
95 : {
96 : public:
97 0 : nsDocShellBackwardsEnumerator()
98 0 : : nsDocShellEnumerator(enumerateBackwards)
99 : {
100 0 : }
101 :
102 : protected:
103 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
104 : nsTArray<nsWeakPtr>& aItemArray);
105 : };
106 :
107 : #endif // nsDocShellEnumerator_h___
|