docshell/base/nsDocShellEnumerator.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ffecd42f0101
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
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
36 enum {
37 enumerateForwards,
38 enumerateBackwards
39 };
40
41 public:
42
43 nsDocShellEnumerator(int32_t inEnumerationDirection);
44 virtual ~nsDocShellEnumerator();
45
46 // nsISupports
47 NS_DECL_ISUPPORTS
48
49 // nsISimpleEnumerator
50 NS_DECL_NSISIMPLEENUMERATOR
51
52 public:
53
54 nsresult GetEnumerationRootItem(nsIDocShellTreeItem * *aEnumerationRootItem);
55 nsresult SetEnumerationRootItem(nsIDocShellTreeItem * aEnumerationRootItem);
56
57 nsresult GetEnumDocShellType(int32_t *aEnumerationItemType);
58 nsresult SetEnumDocShellType(int32_t aEnumerationItemType);
59
60 nsresult First();
61
62 protected:
63
64 nsresult EnsureDocShellArray();
65 nsresult ClearState();
66
67 nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& inItemArray);
68 virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray) = 0;
69
70 protected:
71
72 nsWeakPtr mRootItem; // weak ref!
73
74 nsTArray<nsWeakPtr> mItemArray; // flattened list of items with matching type
75 uint32_t mCurIndex;
76
77 int32_t mDocShellType; // only want shells of this type
78 bool mArrayValid; // is mItemArray up to date?
79
80 const int8_t mEnumerationDirection;
81 };
82
83
84 class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
85 {
86 public:
87
88 nsDocShellForwardsEnumerator()
89 : nsDocShellEnumerator(enumerateForwards)
90 {
91 }
92
93 protected:
94
95 virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
96
97 };
98
99 class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
100 {
101 public:
102
103 nsDocShellBackwardsEnumerator()
104 : nsDocShellEnumerator(enumerateBackwards)
105 {
106 }
107 protected:
108
109 virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
110 };
111
112 #endif // nsDocShellEnumerator_h___

mercurial