1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef nsDocShellEnumerator_h___
8 #define nsDocShellEnumerator_h___
10 #include "nsISimpleEnumerator.h"
12 #include "nsIWeakReferenceUtils.h"
14 class nsIDocShellTreeItem
;
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 } }
21 #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
22 "@mozilla.org/docshell/enumerator-forwards;1"
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 } }
28 #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
29 "@mozilla.org/docshell/enumerator-backwards;1"
32 class nsDocShellEnumerator
: public nsISimpleEnumerator
41 virtual ~nsDocShellEnumerator();
45 explicit nsDocShellEnumerator(int32_t inEnumerationDirection
);
50 // nsISimpleEnumerator
51 NS_DECL_NSISIMPLEENUMERATOR
55 nsresult
GetEnumerationRootItem(nsIDocShellTreeItem
* *aEnumerationRootItem
);
56 nsresult
SetEnumerationRootItem(nsIDocShellTreeItem
* aEnumerationRootItem
);
58 nsresult
GetEnumDocShellType(int32_t *aEnumerationItemType
);
59 nsresult
SetEnumDocShellType(int32_t aEnumerationItemType
);
65 nsresult
EnsureDocShellArray();
66 nsresult
ClearState();
68 nsresult
BuildDocShellArray(nsTArray
<nsWeakPtr
>& inItemArray
);
69 virtual nsresult
BuildArrayRecursive(nsIDocShellTreeItem
* inItem
, nsTArray
<nsWeakPtr
>& inItemArray
) = 0;
73 nsWeakPtr mRootItem
; // weak ref!
75 nsTArray
<nsWeakPtr
> mItemArray
; // flattened list of items with matching type
78 int32_t mDocShellType
; // only want shells of this type
79 bool mArrayValid
; // is mItemArray up to date?
81 const int8_t mEnumerationDirection
;
85 class nsDocShellForwardsEnumerator
: public nsDocShellEnumerator
89 nsDocShellForwardsEnumerator()
90 : nsDocShellEnumerator(enumerateForwards
)
96 virtual nsresult
BuildArrayRecursive(nsIDocShellTreeItem
* inItem
, nsTArray
<nsWeakPtr
>& inItemArray
);
100 class nsDocShellBackwardsEnumerator
: public nsDocShellEnumerator
104 nsDocShellBackwardsEnumerator()
105 : nsDocShellEnumerator(enumerateBackwards
)
110 virtual nsresult
BuildArrayRecursive(nsIDocShellTreeItem
* inItem
, nsTArray
<nsWeakPtr
>& inItemArray
);
113 #endif // nsDocShellEnumerator_h___