michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDocShellEnumerator_h___ michael@0: #define nsDocShellEnumerator_h___ michael@0: michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIWeakReferenceUtils.h" michael@0: michael@0: class nsIDocShellTreeItem; michael@0: michael@0: /* michael@0: // {13cbc281-35ae-11d5-be5b-bde0edece43c} michael@0: #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID \ michael@0: { 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } } michael@0: michael@0: #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \ michael@0: "@mozilla.org/docshell/enumerator-forwards;1" michael@0: michael@0: // {13cbc282-35ae-11d5-be5b-bde0edece43c} michael@0: #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID \ michael@0: { 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } } michael@0: michael@0: #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \ michael@0: "@mozilla.org/docshell/enumerator-backwards;1" michael@0: */ michael@0: michael@0: class nsDocShellEnumerator : public nsISimpleEnumerator michael@0: { michael@0: protected: michael@0: michael@0: enum { michael@0: enumerateForwards, michael@0: enumerateBackwards michael@0: }; michael@0: michael@0: public: michael@0: michael@0: nsDocShellEnumerator(int32_t inEnumerationDirection); michael@0: virtual ~nsDocShellEnumerator(); michael@0: michael@0: // nsISupports michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsISimpleEnumerator michael@0: NS_DECL_NSISIMPLEENUMERATOR michael@0: michael@0: public: michael@0: michael@0: nsresult GetEnumerationRootItem(nsIDocShellTreeItem * *aEnumerationRootItem); michael@0: nsresult SetEnumerationRootItem(nsIDocShellTreeItem * aEnumerationRootItem); michael@0: michael@0: nsresult GetEnumDocShellType(int32_t *aEnumerationItemType); michael@0: nsresult SetEnumDocShellType(int32_t aEnumerationItemType); michael@0: michael@0: nsresult First(); michael@0: michael@0: protected: michael@0: michael@0: nsresult EnsureDocShellArray(); michael@0: nsresult ClearState(); michael@0: michael@0: nsresult BuildDocShellArray(nsTArray& inItemArray); michael@0: virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray& inItemArray) = 0; michael@0: michael@0: protected: michael@0: michael@0: nsWeakPtr mRootItem; // weak ref! michael@0: michael@0: nsTArray mItemArray; // flattened list of items with matching type michael@0: uint32_t mCurIndex; michael@0: michael@0: int32_t mDocShellType; // only want shells of this type michael@0: bool mArrayValid; // is mItemArray up to date? michael@0: michael@0: const int8_t mEnumerationDirection; michael@0: }; michael@0: michael@0: michael@0: class nsDocShellForwardsEnumerator : public nsDocShellEnumerator michael@0: { michael@0: public: michael@0: michael@0: nsDocShellForwardsEnumerator() michael@0: : nsDocShellEnumerator(enumerateForwards) michael@0: { michael@0: } michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray& inItemArray); michael@0: michael@0: }; michael@0: michael@0: class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator michael@0: { michael@0: public: michael@0: michael@0: nsDocShellBackwardsEnumerator() michael@0: : nsDocShellEnumerator(enumerateBackwards) michael@0: { michael@0: } michael@0: protected: michael@0: michael@0: virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray& inItemArray); michael@0: }; michael@0: michael@0: #endif // nsDocShellEnumerator_h___