1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is the Mozilla browser.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications, Inc.
20 : * Portions created by the Initial Developer are Copyright (C) 1999
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Simon Fraser <sfraser@netscape.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 :
41 :
42 : #include "nsIEnumerator.h"
43 :
44 : #include "nsCOMPtr.h"
45 : #include "nsTArray.h"
46 : #include "nsIWeakReferenceUtils.h"
47 :
48 : class nsIDocShellTreeItem;
49 :
50 :
51 : /*
52 : // {13cbc281-35ae-11d5-be5b-bde0edece43c}
53 : #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID \
54 : { 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
55 :
56 : #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
57 : "@mozilla.org/docshell/enumerator-forwards;1"
58 :
59 : // {13cbc282-35ae-11d5-be5b-bde0edece43c}
60 : #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID \
61 : { 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
62 :
63 : #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
64 : "@mozilla.org/docshell/enumerator-backwards;1"
65 : */
66 :
67 : class nsDocShellEnumerator : public nsISimpleEnumerator
68 : {
69 : protected:
70 :
71 : enum {
72 : enumerateForwards,
73 : enumerateBackwards
74 : };
75 :
76 : public:
77 :
78 : nsDocShellEnumerator(PRInt32 inEnumerationDirection);
79 : virtual ~nsDocShellEnumerator();
80 :
81 : // nsISupports
82 : NS_DECL_ISUPPORTS
83 :
84 : // nsISimpleEnumerator
85 : NS_DECL_NSISIMPLEENUMERATOR
86 :
87 : public:
88 :
89 : nsresult GetEnumerationRootItem(nsIDocShellTreeItem * *aEnumerationRootItem);
90 : nsresult SetEnumerationRootItem(nsIDocShellTreeItem * aEnumerationRootItem);
91 :
92 : nsresult GetEnumDocShellType(PRInt32 *aEnumerationItemType);
93 : nsresult SetEnumDocShellType(PRInt32 aEnumerationItemType);
94 :
95 : nsresult First();
96 :
97 : protected:
98 :
99 : nsresult EnsureDocShellArray();
100 : nsresult ClearState();
101 :
102 : nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& inItemArray);
103 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray) = 0;
104 :
105 : protected:
106 :
107 : nsWeakPtr mRootItem; // weak ref!
108 :
109 : nsTArray<nsWeakPtr> mItemArray; // flattened list of items with matching type
110 : PRUint32 mCurIndex;
111 :
112 : PRInt32 mDocShellType; // only want shells of this type
113 : bool mArrayValid; // is mItemArray up to date?
114 :
115 : const PRInt8 mEnumerationDirection;
116 : };
117 :
118 :
119 : class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
120 0 : {
121 : public:
122 :
123 0 : nsDocShellForwardsEnumerator()
124 0 : : nsDocShellEnumerator(enumerateForwards)
125 : {
126 0 : }
127 :
128 : protected:
129 :
130 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
131 :
132 : };
133 :
134 : class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
135 0 : {
136 : public:
137 :
138 0 : nsDocShellBackwardsEnumerator()
139 0 : : nsDocShellEnumerator(enumerateBackwards)
140 : {
141 0 : }
142 : protected:
143 :
144 : virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
145 :
146 : };
|