nsDocShellEnumerator.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsDocShellEnumerator_h___
  6. #define nsDocShellEnumerator_h___
  7. #include "nsISimpleEnumerator.h"
  8. #include "nsTArray.h"
  9. #include "nsIWeakReferenceUtils.h"
  10. class nsIDocShellTreeItem;
  11. /*
  12. // {13cbc281-35ae-11d5-be5b-bde0edece43c}
  13. #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID \
  14. { 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
  15. #define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
  16. "@mozilla.org/docshell/enumerator-forwards;1"
  17. // {13cbc282-35ae-11d5-be5b-bde0edece43c}
  18. #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID \
  19. { 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
  20. #define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
  21. "@mozilla.org/docshell/enumerator-backwards;1"
  22. */
  23. class nsDocShellEnumerator : public nsISimpleEnumerator
  24. {
  25. protected:
  26. enum
  27. {
  28. enumerateForwards,
  29. enumerateBackwards
  30. };
  31. virtual ~nsDocShellEnumerator();
  32. public:
  33. explicit nsDocShellEnumerator(int32_t aEnumerationDirection);
  34. // nsISupports
  35. NS_DECL_ISUPPORTS
  36. // nsISimpleEnumerator
  37. NS_DECL_NSISIMPLEENUMERATOR
  38. public:
  39. nsresult GetEnumerationRootItem(nsIDocShellTreeItem** aEnumerationRootItem);
  40. nsresult SetEnumerationRootItem(nsIDocShellTreeItem* aEnumerationRootItem);
  41. nsresult GetEnumDocShellType(int32_t* aEnumerationItemType);
  42. nsresult SetEnumDocShellType(int32_t aEnumerationItemType);
  43. nsresult First();
  44. protected:
  45. nsresult EnsureDocShellArray();
  46. nsresult ClearState();
  47. nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& aItemArray);
  48. virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
  49. nsTArray<nsWeakPtr>& aItemArray) = 0;
  50. protected:
  51. nsWeakPtr mRootItem; // weak ref!
  52. nsTArray<nsWeakPtr> mItemArray; // flattened list of items with matching type
  53. uint32_t mCurIndex;
  54. int32_t mDocShellType; // only want shells of this type
  55. bool mArrayValid; // is mItemArray up to date?
  56. const int8_t mEnumerationDirection;
  57. };
  58. class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
  59. {
  60. public:
  61. nsDocShellForwardsEnumerator()
  62. : nsDocShellEnumerator(enumerateForwards)
  63. {
  64. }
  65. protected:
  66. virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
  67. nsTArray<nsWeakPtr>& aItemArray);
  68. };
  69. class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
  70. {
  71. public:
  72. nsDocShellBackwardsEnumerator()
  73. : nsDocShellEnumerator(enumerateBackwards)
  74. {
  75. }
  76. protected:
  77. virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
  78. nsTArray<nsWeakPtr>& aItemArray);
  79. };
  80. #endif // nsDocShellEnumerator_h___