Back to index

lightning-sunbird  0.9+nobinonly
nsDocShellEnumerator.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Simon Fraser <sfraser@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 
00041 
00042 #include "nsIEnumerator.h"
00043 
00044 #include "nsCOMPtr.h"
00045 #include "nsVoidArray.h"
00046 
00047 class nsIDocShellTreeItem;
00048 
00049 
00050 /*
00051 // {13cbc281-35ae-11d5-be5b-bde0edece43c}
00052 #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID  \
00053 { 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
00054 
00055 #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
00056 "@mozilla.org/docshell/enumerator-forwards;1"
00057 
00058 // {13cbc282-35ae-11d5-be5b-bde0edece43c}
00059 #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID  \
00060 { 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
00061 
00062 #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
00063 "@mozilla.org/docshell/enumerator-backwards;1"
00064 */
00065 
00066 class nsDocShellEnumerator : public nsISimpleEnumerator
00067 {
00068 protected:
00069 
00070   enum {
00071     enumerateForwards,
00072     enumerateBackwards
00073   };
00074   
00075 public:
00076 
00077                               nsDocShellEnumerator(PRInt32 inEnumerationDirection);
00078   virtual                     ~nsDocShellEnumerator();
00079 
00080   // nsISupports
00081   NS_DECL_ISUPPORTS
00082   
00083   // nsISimpleEnumerator
00084   NS_DECL_NSISIMPLEENUMERATOR
00085   
00086 public:
00087 
00088   nsresult                    GetEnumerationRootItem(nsIDocShellTreeItem * *aEnumerationRootItem);
00089   nsresult                    SetEnumerationRootItem(nsIDocShellTreeItem * aEnumerationRootItem);
00090   
00091   nsresult                    GetEnumDocShellType(PRInt32 *aEnumerationItemType);
00092   nsresult                    SetEnumDocShellType(PRInt32 aEnumerationItemType);
00093     
00094   nsresult                    First();
00095 
00096 protected:
00097 
00098   nsresult                    EnsureDocShellArray();
00099   nsresult                    ClearState();
00100   
00101   nsresult                    BuildDocShellArray(nsVoidArray& inItemArray);
00102   virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsVoidArray& inItemArray) = 0;
00103     
00104 protected:
00105 
00106   nsIDocShellTreeItem*        mRootItem;      // weak ref!
00107   
00108   nsVoidArray*                mItemArray;     // flattened list of items with matching type
00109   PRInt32                     mCurIndex;
00110   
00111   PRInt32                     mDocShellType;  // only want shells of this type
00112 
00113   const PRInt8                mEnumerationDirection;
00114 };
00115 
00116 
00117 class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
00118 {
00119 public:
00120 
00121                               nsDocShellForwardsEnumerator()
00122                               : nsDocShellEnumerator(enumerateForwards)
00123                               {                              
00124                               }
00125 
00126 protected:
00127 
00128   virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsVoidArray& inItemArray);
00129 
00130 };
00131 
00132 class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
00133 {
00134 public:
00135 
00136                               nsDocShellBackwardsEnumerator()
00137                               : nsDocShellEnumerator(enumerateBackwards)
00138                               {                              
00139                               }
00140 protected:
00141 
00142   virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsVoidArray& inItemArray);
00143 
00144 };