docshell/base/nsDocShellEnumerator.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/base/nsDocShellEnumerator.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsDocShellEnumerator_h___
    1.11 +#define nsDocShellEnumerator_h___
    1.12 +
    1.13 +#include "nsISimpleEnumerator.h"
    1.14 +#include "nsTArray.h"
    1.15 +#include "nsIWeakReferenceUtils.h"
    1.16 +
    1.17 +class nsIDocShellTreeItem;
    1.18 +
    1.19 +/*
    1.20 +// {13cbc281-35ae-11d5-be5b-bde0edece43c}
    1.21 +#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID  \
    1.22 +{ 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
    1.23 +
    1.24 +#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
    1.25 +"@mozilla.org/docshell/enumerator-forwards;1"
    1.26 +
    1.27 +// {13cbc282-35ae-11d5-be5b-bde0edece43c}
    1.28 +#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID  \
    1.29 +{ 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c } }
    1.30 +
    1.31 +#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
    1.32 +"@mozilla.org/docshell/enumerator-backwards;1"
    1.33 +*/
    1.34 +
    1.35 +class nsDocShellEnumerator : public nsISimpleEnumerator
    1.36 +{
    1.37 +protected:
    1.38 +
    1.39 +  enum {
    1.40 +    enumerateForwards,
    1.41 +    enumerateBackwards
    1.42 +  };
    1.43 +  
    1.44 +public:
    1.45 +
    1.46 +                              nsDocShellEnumerator(int32_t inEnumerationDirection);
    1.47 +  virtual                     ~nsDocShellEnumerator();
    1.48 +
    1.49 +  // nsISupports
    1.50 +  NS_DECL_ISUPPORTS
    1.51 +  
    1.52 +  // nsISimpleEnumerator
    1.53 +  NS_DECL_NSISIMPLEENUMERATOR
    1.54 +  
    1.55 +public:
    1.56 +
    1.57 +  nsresult                    GetEnumerationRootItem(nsIDocShellTreeItem * *aEnumerationRootItem);
    1.58 +  nsresult                    SetEnumerationRootItem(nsIDocShellTreeItem * aEnumerationRootItem);
    1.59 +  
    1.60 +  nsresult                    GetEnumDocShellType(int32_t *aEnumerationItemType);
    1.61 +  nsresult                    SetEnumDocShellType(int32_t aEnumerationItemType);
    1.62 +    
    1.63 +  nsresult                    First();
    1.64 +
    1.65 +protected:
    1.66 +
    1.67 +  nsresult                    EnsureDocShellArray();
    1.68 +  nsresult                    ClearState();
    1.69 +  
    1.70 +  nsresult                    BuildDocShellArray(nsTArray<nsWeakPtr>& inItemArray);
    1.71 +  virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray) = 0;
    1.72 +    
    1.73 +protected:
    1.74 +
    1.75 +  nsWeakPtr                   mRootItem;      // weak ref!
    1.76 +  
    1.77 +  nsTArray<nsWeakPtr>         mItemArray;     // flattened list of items with matching type
    1.78 +  uint32_t                    mCurIndex;
    1.79 +  
    1.80 +  int32_t                     mDocShellType;  // only want shells of this type
    1.81 +  bool                        mArrayValid;    // is mItemArray up to date?
    1.82 +
    1.83 +  const int8_t                mEnumerationDirection;
    1.84 +};
    1.85 +
    1.86 +
    1.87 +class nsDocShellForwardsEnumerator : public nsDocShellEnumerator
    1.88 +{
    1.89 +public:
    1.90 +
    1.91 +                              nsDocShellForwardsEnumerator()
    1.92 +                              : nsDocShellEnumerator(enumerateForwards)
    1.93 +                              {                              
    1.94 +                              }
    1.95 +
    1.96 +protected:
    1.97 +
    1.98 +  virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
    1.99 +
   1.100 +};
   1.101 +
   1.102 +class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator
   1.103 +{
   1.104 +public:
   1.105 +
   1.106 +                              nsDocShellBackwardsEnumerator()
   1.107 +                              : nsDocShellEnumerator(enumerateBackwards)
   1.108 +                              {                              
   1.109 +                              }
   1.110 +protected:
   1.111 +
   1.112 +  virtual nsresult            BuildArrayRecursive(nsIDocShellTreeItem* inItem, nsTArray<nsWeakPtr>& inItemArray);
   1.113 +};
   1.114 +
   1.115 +#endif // nsDocShellEnumerator_h___

mercurial